GnuCash c935c2f+
Loading...
Searching...
No Matches
Public Member Functions | Friends
CsvImpPriceAssist Class Reference

Public Member Functions

 CsvImpPriceAssist (const CsvImpPriceAssist &)=delete
 
CsvImpPriceAssistoperator= (const CsvImpPriceAssist &)=delete
 
 CsvImpPriceAssist (CsvImpPriceAssist &&)=delete
 
CsvImpPriceAssistoperator= (CsvImpPriceAssist &&)=delete
 
void assist_prepare_cb (GtkWidget *page)
 
void assist_file_page_prepare ()
 
void assist_preview_page_prepare ()
 
void assist_confirm_page_prepare ()
 
void assist_summary_page_prepare ()
 
void assist_finish ()
 
void assist_compmgr_close ()
 
void file_activated_cb ()
 
void file_selection_changed_cb ()
 
void preview_settings_delete ()
 
void preview_settings_save ()
 
void preview_settings_name (GtkEntry *entry)
 
void preview_settings_load ()
 
void preview_update_skipped_rows ()
 
void preview_over_write (bool over)
 
void preview_update_separators (GtkWidget *widget)
 Event handler for separator changes.
 
void preview_update_file_format ()
 Event handler for clicking one of the format type radio buttons.
 
void preview_update_encoding (const char *encoding)
 Event handler for a new encoding.
 
void preview_update_date_format ()
 
void preview_update_currency_format ()
 
void preview_update_currency ()
 
void preview_update_commodity ()
 
void preview_reparse_col_type (GncPricePropType type)
 
void preview_update_col_type (GtkComboBox *cbox)
 Event handler for the user selecting a new column type.
 
void preview_update_fw_columns (GtkTreeView *treeview, GdkEventButton *event)
 Event handler for clicking on column headers.
 
void preview_populate_settings_combo ()
 
void preview_handle_save_del_sensitivity (GtkComboBox *combo)
 
void preview_split_column (int col, int offset)
 
void preview_refresh_table ()
 
void preview_refresh ()
 
void preview_validate_settings ()
 

Friends

gboolean fixed_context_menu_handler_price (GnumericPopupMenuElement const *element, gpointer userdata)
 

Detailed Description

Definition at line 80 of file assistant-csv-price-import.cpp.

Constructor & Destructor Documentation

◆ CsvImpPriceAssist()

CsvImpPriceAssist::CsvImpPriceAssist ( )

Definition at line 520 of file assistant-csv-price-import.cpp.

521{
522 auto builder = gtk_builder_new();
523 gnc_builder_add_from_file (builder , "assistant-csv-price-import.glade", "start_row_adj");
524 gnc_builder_add_from_file (builder , "assistant-csv-price-import.glade", "end_row_adj");
525 gnc_builder_add_from_file (builder , "assistant-csv-price-import.glade", "liststore1");
526 gnc_builder_add_from_file (builder , "assistant-csv-price-import.glade", "liststore2");
527 gnc_builder_add_from_file (builder , "assistant-csv-price-import.glade", "CSV Price Assistant");
528 csv_imp_asst = GTK_ASSISTANT(gtk_builder_get_object (builder, "CSV Price Assistant"));
529
530 // Set the name for this assistant so it can be easily manipulated with css
531 gtk_widget_set_name (GTK_WIDGET(csv_imp_asst), "gnc-id-assistant-csv-price-import");
532 gnc_widget_style_context_add_class (GTK_WIDGET(csv_imp_asst), "gnc-class-imports");
533
534 /* Enable buttons on all page. */
535 gtk_assistant_set_page_complete (csv_imp_asst,
536 GTK_WIDGET(gtk_builder_get_object (builder, "start_page")),
537 true);
538 gtk_assistant_set_page_complete (csv_imp_asst,
539 GTK_WIDGET(gtk_builder_get_object (builder, "file_page")),
540 false);
541 gtk_assistant_set_page_complete (csv_imp_asst,
542 GTK_WIDGET(gtk_builder_get_object (builder, "preview_page")),
543 false);
544 gtk_assistant_set_page_complete (csv_imp_asst,
545 GTK_WIDGET(gtk_builder_get_object (builder, "confirm_page")),
546 true);
547 gtk_assistant_set_page_complete (csv_imp_asst,
548 GTK_WIDGET(gtk_builder_get_object (builder, "summary_page")),
549 true);
550
551 /* File chooser Page */
552 file_page = GTK_WIDGET(gtk_builder_get_object (builder, "file_page"));
553 file_chooser = gtk_file_chooser_widget_new (GTK_FILE_CHOOSER_ACTION_OPEN);
554
555 g_signal_connect (G_OBJECT(file_chooser), "selection-changed",
556 G_CALLBACK(csv_price_imp_file_selection_changed_cb), this);
557 g_signal_connect (G_OBJECT(file_chooser), "file-activated",
558 G_CALLBACK(csv_price_imp_file_activated_changed_cb), this);
559
560 auto box = GTK_WIDGET(gtk_builder_get_object (builder, "file_page"));
561 gtk_box_pack_start (GTK_BOX(box), file_chooser, TRUE, TRUE, 6);
562 gtk_widget_show (file_chooser);
563
564 /* Preview Settings Page */
565 {
566 preview_page = GTK_WIDGET(gtk_builder_get_object (builder, "preview_page"));
567
568 // Add Settings combo
569 auto settings_store = gtk_list_store_new (2, G_TYPE_POINTER, G_TYPE_STRING);
570 settings_combo = GTK_COMBO_BOX(gtk_combo_box_new_with_model_and_entry (GTK_TREE_MODEL(settings_store)));
571 g_object_unref (settings_store);
572
573 gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX(settings_combo), SET_NAME);
574 gtk_combo_box_set_active (GTK_COMBO_BOX(settings_combo), 0);
575
576 combo_hbox = GTK_WIDGET(gtk_builder_get_object (builder, "combo_hbox"));
577 gtk_box_pack_start (GTK_BOX(combo_hbox), GTK_WIDGET(settings_combo), true, true, 6);
578 gtk_widget_show (GTK_WIDGET(settings_combo));
579
580 g_signal_connect (G_OBJECT(settings_combo), "changed",
581 G_CALLBACK(csv_price_imp_preview_settings_sel_changed_cb), this);
582
583 // Additionally connect to the changed signal of the embedded GtkEntry
584 auto emb_entry = gtk_bin_get_child (GTK_BIN (settings_combo));
585 g_signal_connect (G_OBJECT(emb_entry), "changed",
586 G_CALLBACK(csv_price_imp_preview_settings_text_changed_cb), this);
587 g_signal_connect (G_OBJECT(emb_entry), "insert-text",
588 G_CALLBACK(csv_price_imp_preview_settings_text_inserted_cb), this);
589
590 // Add Save Settings button
591 save_button = GTK_WIDGET(gtk_builder_get_object (builder, "save_settings"));
592
593 // Add Delete Settings button
594 del_button = GTK_WIDGET(gtk_builder_get_object (builder, "delete_settings"));
595
596 /* The table containing the separator configuration widgets */
597 start_row_spin = GTK_SPIN_BUTTON(gtk_builder_get_object (builder, "start_row"));
598 end_row_spin = GTK_SPIN_BUTTON(gtk_builder_get_object (builder, "end_row"));
599 skip_alt_rows_button = GTK_WIDGET(gtk_builder_get_object (builder, "skip_rows"));
600 skip_errors_button = GTK_WIDGET(gtk_builder_get_object (builder, "skip_errors_button"));
601 over_write_cbutton = GTK_WIDGET(gtk_builder_get_object (builder, "over_write_button"));
602 separator_table = GTK_WIDGET(gtk_builder_get_object (builder, "separator_table"));
603 fw_instructions_hbox = GTK_WIDGET(gtk_builder_get_object (builder, "fw_instructions_hbox"));
604
605 /* Load the separator buttons from the glade builder file into the
606 * sep_buttons array. */
607 const char* sep_button_names[] = {
608 "space_cbutton",
609 "tab_cbutton",
610 "comma_cbutton",
611 "colon_cbutton",
612 "semicolon_cbutton",
613 "hyphen_cbutton"
614 };
615 for (int i = 0; i < SEP_NUM_OF_TYPES; i++)
616 sep_button[i]
617 = GTK_CHECK_BUTTON(gtk_builder_get_object (builder, sep_button_names[i]));
618
619 /* Load and connect the custom separator checkbutton in the same way
620 * as the other separator buttons. */
621 custom_cbutton
622 = GTK_CHECK_BUTTON(gtk_builder_get_object (builder, "custom_cbutton"));
623
624 /* Load the entry for the custom separator entry. Connect it to the
625 * sep_button_clicked event handler as well. */
626 custom_entry = GTK_ENTRY(gtk_builder_get_object (builder, "custom_entry"));
627
628 /* Load and connect the escape checkbutton in the same way
629 * as the other separator buttons. */
630 escape_cbutton
631 = GTK_CHECK_BUTTON(gtk_builder_get_object (builder, "escape_cbutton"));
632
633 /* Create the encoding selector widget and add it to the assistant */
634 encselector = GO_CHARMAP_SEL(go_charmap_sel_new(GO_CHARMAP_SEL_TO_UTF8));
635 /* Connect the selector to the encoding_selected event handler. */
636 g_signal_connect (G_OBJECT(encselector), "charmap_changed",
637 G_CALLBACK(csv_price_imp_preview_enc_sel_cb), this);
638
639 auto encoding_container = GTK_CONTAINER(gtk_builder_get_object (builder, "encoding_container"));
640 gtk_container_add (encoding_container, GTK_WIDGET(encselector));
641 gtk_widget_set_hexpand (GTK_WIDGET(encselector), true);
642 gtk_widget_show_all (GTK_WIDGET(encoding_container));
643
644 /* Add commodity selection widget */
645 commodity_selector = GTK_WIDGET(gtk_builder_get_object (builder, "commodity_cbox"));
646 gtk_combo_box_set_model (GTK_COMBO_BOX(commodity_selector), get_model (true));
647 gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX(commodity_selector),
648 separator_row_func, nullptr, nullptr);
649 g_signal_connect (G_OBJECT(commodity_selector), "changed",
650 G_CALLBACK(csv_price_imp_preview_commodity_sel_cb), this);
651
652 /* Add currency selection widget */
653 currency_selector = GTK_WIDGET(gtk_builder_get_object (builder, "currency_cbox"));
654 gtk_combo_box_set_model (GTK_COMBO_BOX(currency_selector), get_model (false));
655 g_signal_connect(G_OBJECT(currency_selector), "changed",
656 G_CALLBACK(csv_price_imp_preview_currency_sel_cb), this);
657
658 /* The instructions label and image */
659 instructions_label = GTK_LABEL(gtk_builder_get_object (builder, "instructions_label"));
660 instructions_image = GTK_IMAGE(gtk_builder_get_object (builder, "instructions_image"));
661
662 /* Add in the date format combo box and hook it up to an event handler. */
663 date_format_combo = GTK_COMBO_BOX_TEXT(gtk_combo_box_text_new());
664 for (auto& date_fmt : GncDate::c_formats)
665 gtk_combo_box_text_append_text (date_format_combo, _(date_fmt.m_fmt.c_str()));
666 gtk_combo_box_set_active (GTK_COMBO_BOX(date_format_combo), 0);
667 g_signal_connect (G_OBJECT(date_format_combo), "changed",
668 G_CALLBACK(csv_price_imp_preview_date_fmt_sel_cb), this);
669
670 /* Add it to the assistant. */
671 auto date_format_container = GTK_CONTAINER(gtk_builder_get_object (builder, "date_format_container"));
672 gtk_container_add (date_format_container, GTK_WIDGET(date_format_combo));
673 gtk_widget_set_hexpand (GTK_WIDGET(date_format_combo), true);
674 gtk_widget_show_all (GTK_WIDGET(date_format_container));
675
676 /* Add in the currency format combo box and hook it up to an event handler. */
677 currency_format_combo = GTK_COMBO_BOX_TEXT(gtk_combo_box_text_new());
678 for (int i = 0; i < num_currency_formats_price; i++)
679 {
680 gtk_combo_box_text_append_text (currency_format_combo, _(currency_format_user_price[i]));
681 }
682 /* Default will the locale */
683 gtk_combo_box_set_active (GTK_COMBO_BOX(currency_format_combo), 0);
684 g_signal_connect (G_OBJECT(currency_format_combo), "changed",
685 G_CALLBACK(csv_price_imp_preview_currency_fmt_sel_cb), this);
686
687 /* Add it to the assistant. */
688 auto currency_format_container = GTK_CONTAINER(gtk_builder_get_object (builder, "currency_format_container"));
689 gtk_container_add (currency_format_container, GTK_WIDGET(currency_format_combo));
690 gtk_widget_set_hexpand (GTK_WIDGET(currency_format_combo), true);
691 gtk_widget_show_all (GTK_WIDGET(currency_format_container));
692
693 /* Connect the CSV/Fixed-Width radio button event handler. */
694 csv_button = GTK_WIDGET(gtk_builder_get_object (builder, "csv_button"));
695 fixed_button = GTK_WIDGET(gtk_builder_get_object (builder, "fixed_button"));
696
697 /* Load the data treeview and connect it to its resizing event handler. */
698 treeview = GTK_TREE_VIEW(gtk_builder_get_object (builder, "treeview"));
699 gtk_tree_view_set_headers_clickable (treeview, true);
700
701 /* This is true only after encoding_selected is called, so we must
702 * set it initially to false. */
703 encoding_selected_called = false;
704 }
705
706 /* Confirm Page */
707 confirm_page = GTK_WIDGET(gtk_builder_get_object (builder, "confirm_page"));
708
709 /* Summary Page */
710 summary_page = GTK_WIDGET(gtk_builder_get_object (builder, "summary_page"));
711 summary_label = GTK_WIDGET(gtk_builder_get_object (builder, "summary_label"));
712
713 gnc_restore_window_size (GNC_PREFS_GROUP,
714 GTK_WINDOW(csv_imp_asst), gnc_ui_get_main_window(nullptr));
715
716 gtk_builder_connect_signals (builder, this);
717 g_object_unref (G_OBJECT(builder));
718
719 gtk_widget_show_all (GTK_WIDGET(csv_imp_asst));
720 gnc_window_adjust_for_screen (GTK_WINDOW(csv_imp_asst));
721}
GnuCash Date class.
GtkWindow * gnc_ui_get_main_window(GtkWidget *widget)
Get a pointer to the final GncMainWindow widget is rooted in.

◆ ~CsvImpPriceAssist()

CsvImpPriceAssist::~CsvImpPriceAssist ( )

Definition at line 726 of file assistant-csv-price-import.cpp.

727{
728 gtk_widget_destroy (GTK_WIDGET(csv_imp_asst));
729}

Member Function Documentation

◆ assist_compmgr_close()

void CsvImpPriceAssist::assist_compmgr_close ( )

Definition at line 2005 of file assistant-csv-price-import.cpp.

2006{
2007 gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(csv_imp_asst));
2008}

◆ assist_confirm_page_prepare()

void CsvImpPriceAssist::assist_confirm_page_prepare ( )

Definition at line 1928 of file assistant-csv-price-import.cpp.

1929{
1930 /* Confirm Page */
1931}

◆ assist_file_page_prepare()

void CsvImpPriceAssist::assist_file_page_prepare ( )

Definition at line 1852 of file assistant-csv-price-import.cpp.

1853{
1854 /* Disable the "Next" Assistant Button */
1855 gtk_assistant_set_page_complete (csv_imp_asst, file_page, false);
1856 gtk_assistant_set_page_complete (csv_imp_asst, preview_page, false);
1857
1858 /* Set the default directory */
1859 if (!m_final_file_name.empty())
1860 gtk_file_chooser_set_filename (GTK_FILE_CHOOSER(file_chooser),
1861 m_final_file_name.c_str());
1862 else
1863 {
1864 auto starting_dir = gnc_get_default_directory (GNC_PREFS_GROUP);
1865 if (starting_dir)
1866 {
1867 gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER(file_chooser), starting_dir);
1868 g_free (starting_dir);
1869 }
1870 }
1871}

◆ assist_finish()

void CsvImpPriceAssist::assist_finish ( )

Definition at line 1983 of file assistant-csv-price-import.cpp.

1984{
1985 /* Start the import */
1986 /* Create prices from the parsed data */
1987 try
1988 {
1989 price_imp->create_prices ();
1990 gnc_gui_refresh_all ();
1991 }
1992 catch (const std::invalid_argument& err)
1993 {
1994 /* Oops! This shouldn't happen when using the import assistant !
1995 * Inform the user and go back to the preview page.
1996 */
1997 gnc_error_dialog (GTK_WINDOW(csv_imp_asst),
1998 _("An unexpected error has occurred while creating prices. Please report this as a bug.\n\n"
1999 "Error message:\n%s"), err.what());
2000 gtk_assistant_set_current_page (csv_imp_asst, 2);
2001 }
2002}

◆ assist_prepare_cb()

void CsvImpPriceAssist::assist_prepare_cb ( GtkWidget *  page)

Definition at line 1970 of file assistant-csv-price-import.cpp.

1971{
1972 if (page == file_page)
1973 assist_file_page_prepare ();
1974 else if (page == preview_page)
1975 assist_preview_page_prepare ();
1976 else if (page == confirm_page)
1977 assist_confirm_page_prepare ();
1978 else if (page == summary_page)
1979 assist_summary_page_prepare ();
1980}

◆ assist_preview_page_prepare()

void CsvImpPriceAssist::assist_preview_page_prepare ( )

Definition at line 1874 of file assistant-csv-price-import.cpp.

1875{
1876 auto go_back = false;
1877
1878
1879 if (m_final_file_name != m_fc_file_name)
1880 {
1881 /* Load the file into parse_data. */
1882 price_imp = std::unique_ptr<GncPriceImport>(new GncPriceImport);
1883 /* Assume data is CSV. User can later override to Fixed Width if needed */
1884 try
1885 {
1886 price_imp->file_format (GncImpFileFormat::CSV);
1887 price_imp->load_file (m_fc_file_name);
1888 price_imp->tokenize (true);
1889
1890 /* Get settings store and populate */
1891 preview_populate_settings_combo();
1892 gtk_combo_box_set_active (settings_combo, 0);
1893
1894 // set over_write to false as default
1895 price_imp->over_write (false);
1896
1897 /* Disable the "Next" Assistant Button */
1898 gtk_assistant_set_page_complete (csv_imp_asst, preview_page, false);
1899 }
1900 catch (std::ifstream::failure& e)
1901 {
1902 /* File loading failed ... */
1903 gnc_error_dialog (GTK_WINDOW(csv_imp_asst), "%s", e.what());
1904 go_back = true;
1905 }
1906 catch (std::range_error &e)
1907 {
1908 /* Parsing failed ... */
1909 gnc_error_dialog (GTK_WINDOW(csv_imp_asst), "%s", _(e.what()));
1910 /* Stay in this step so user can override */
1911 go_back = false;
1912 }
1913 }
1914
1915 if (go_back)
1916 gtk_assistant_previous_page (csv_imp_asst);
1917 else
1918 {
1919 m_final_file_name = m_fc_file_name;
1920 preview_refresh ();
1921
1922 /* Load the data into the treeview. */
1923 g_idle_add ((GSourceFunc)csv_imp_preview_queue_rebuild_table, this);
1924 }
1925}
The actual PriceImport class It's intended to use in the following sequence of actions:

◆ assist_summary_page_prepare()

void CsvImpPriceAssist::assist_summary_page_prepare ( )

Definition at line 1934 of file assistant-csv-price-import.cpp.

1935{
1936 auto text = std::string("<span size=\"medium\"><b>");
1937 /* Translators: This is a ngettext(3) message, %d is the number of prices added */
1938 auto added_str = g_strdup_printf (ngettext ("%d added price",
1939 "%d added prices",
1940 price_imp->m_prices_added),
1941 price_imp->m_prices_added);
1942 /* Translators: This is a ngettext(3) message, %d is the number of duplicate prices */
1943 auto dupl_str = g_strdup_printf (ngettext ("%d duplicate price",
1944 "%d duplicate prices",
1945 price_imp->m_prices_duplicated),
1946 price_imp->m_prices_duplicated);
1947 /* Translators: This is a ngettext(3) message, %d is the number of replaced prices */
1948 auto repl_str = g_strdup_printf (ngettext ("%d replaced price",
1949 "%d replaced prices",
1950 price_imp->m_prices_replaced),
1951 price_imp->m_prices_replaced);
1952 auto msg = g_strdup_printf (
1953 _("The prices were imported from file '%s'.\n\n"
1954 "Import summary:\n"
1955 "- %s\n"
1956 "- %s\n"
1957 "- %s"),
1958 m_final_file_name.c_str(), added_str, dupl_str,repl_str);
1959 text += msg;
1960 text += "</b></span>";
1961
1962 g_free (added_str);
1963 g_free (dupl_str);
1964 g_free (repl_str);
1965
1966 gtk_label_set_markup (GTK_LABEL(summary_label), text.c_str());
1967}

◆ file_activated_cb()

void CsvImpPriceAssist::file_activated_cb ( )

Definition at line 768 of file assistant-csv-price-import.cpp.

769{
770 gtk_assistant_set_page_complete (csv_imp_asst, file_page, false);
771
772 /* Test for a valid filename and not a directory */
773 if (check_for_valid_filename ())
774 {
775 gtk_assistant_set_page_complete (csv_imp_asst, file_page, true);
776 gtk_assistant_next_page (csv_imp_asst);
777 }
778}

◆ file_selection_changed_cb()

void CsvImpPriceAssist::file_selection_changed_cb ( )

Definition at line 785 of file assistant-csv-price-import.cpp.

786{
787 /* Enable the "Next" button based on a valid filename */
788 gtk_assistant_set_page_complete (csv_imp_asst, file_page,
789 check_for_valid_filename ());
790}

◆ preview_handle_save_del_sensitivity()

void CsvImpPriceAssist::preview_handle_save_del_sensitivity ( GtkComboBox *  combo)

Definition at line 824 of file assistant-csv-price-import.cpp.

825{
826 GtkTreeIter iter;
827 auto can_delete = false;
828 auto can_save = false;
829 auto entry = gtk_bin_get_child (GTK_BIN(combo));
830 auto entry_text = gtk_entry_get_text (GTK_ENTRY(entry));
831 /* Handle sensitivity of the delete and save button */
832 if (gtk_combo_box_get_active_iter (combo, &iter))
833 {
834 CsvPriceImpSettings *preset;
835 GtkTreeModel *model = gtk_combo_box_get_model (combo);
836 gtk_tree_model_get (model, &iter, SET_GROUP, &preset, -1);
837
838 if (preset && !preset_is_reserved_name (preset->m_name))
839 {
840 /* Current preset is not read_only, so buttons can be enabled */
841 can_delete = true;
842 can_save = true;
843 }
844 }
845 else if (entry_text && (strlen (entry_text) > 0) &&
846 !preset_is_reserved_name (std::string(entry_text)))
847 can_save = true;
848
849 gtk_widget_set_sensitive (save_button, can_save);
850 gtk_widget_set_sensitive (del_button, can_delete);
851}
bool preset_is_reserved_name(const std::string &name)
Check whether name can be used as a preset name.

◆ preview_over_write()

void CsvImpPriceAssist::preview_over_write ( bool  over)

Definition at line 1010 of file assistant-csv-price-import.cpp.

1011{
1012 price_imp->over_write (over);
1013}

◆ preview_populate_settings_combo()

void CsvImpPriceAssist::preview_populate_settings_combo ( )

Definition at line 799 of file assistant-csv-price-import.cpp.

800{
801 // Clear the list store
802 auto model = gtk_combo_box_get_model (settings_combo);
803 gtk_list_store_clear (GTK_LIST_STORE(model));
804
805 // Append the default entry
806 auto presets = get_import_presets_price ();
807 for (const auto& preset : presets)
808 {
809 GtkTreeIter iter;
810 gtk_list_store_append (GTK_LIST_STORE(model), &iter);
811 /* FIXME we store the raw pointer to the preset, while it's
812 * managed by a shared pointer. This is dangerous because
813 * when the shared pointer goes out of scope, our pointer will dangle.
814 * For now this is safe, because the shared pointers in this case are
815 * long-lived, but this may need refactoring.
816 */
817 gtk_list_store_set (GTK_LIST_STORE(model), &iter, SET_GROUP, preset.get(), SET_NAME, _(preset->m_name.c_str()), -1);
818 }
819}
const preset_vec_price & get_import_presets_price(void)
Creates a vector of CsvPriceImpSettings which combines.

◆ preview_refresh()

void CsvImpPriceAssist::preview_refresh ( )

Definition at line 1732 of file assistant-csv-price-import.cpp.

1733{
1734 // Cache skip settings. Updating the widgets one by one
1735 // triggers a callback that transfers all skip widgets'
1736 // values to settings. So by the time the next widget value
1737 // is to be set, that widget's 'new' setting has already been
1738 // replaced by its old setting preveneting us from using it
1739 // here sensibly.
1740
1741 auto skip_start_lines = price_imp->skip_start_lines();
1742 auto skip_end_lines = price_imp->skip_end_lines();
1743 auto skip_alt_lines = price_imp->skip_alt_lines();
1744
1745 // Set start row
1746 auto adj = gtk_spin_button_get_adjustment (start_row_spin);
1747 gtk_adjustment_set_upper (adj, price_imp->m_parsed_lines.size());
1748 gtk_spin_button_set_value (start_row_spin, skip_start_lines);
1749
1750 // Set end row
1751 adj = gtk_spin_button_get_adjustment (end_row_spin);
1752 gtk_adjustment_set_upper (adj, price_imp->m_parsed_lines.size());
1753 gtk_spin_button_set_value (end_row_spin, skip_end_lines);
1754
1755 // Set Alternate rows
1756 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(skip_alt_rows_button),
1757 skip_alt_lines);
1758
1759 // Set over-write indicator
1760 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(over_write_cbutton),
1761 price_imp->over_write());
1762
1763 // Set Import Format
1764 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(csv_button),
1765 (price_imp->file_format() == GncImpFileFormat::CSV));
1766 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(fixed_button),
1767 (price_imp->file_format() != GncImpFileFormat::CSV));
1768
1769 // This section deals with the combo's and character encoding
1770 gtk_combo_box_set_active (GTK_COMBO_BOX(date_format_combo),
1771 price_imp->date_format());
1772 gtk_combo_box_set_active (GTK_COMBO_BOX(currency_format_combo),
1773 price_imp->currency_format());
1774 go_charmap_sel_set_encoding (encselector, price_imp->encoding().c_str());
1775
1776 // Set the commodity and currency combos
1777 set_commodity_for_combo(GTK_COMBO_BOX(commodity_selector),
1778 price_imp->from_commodity());
1779
1780 set_commodity_for_combo(GTK_COMBO_BOX(currency_selector),
1781 price_imp->to_currency());
1782
1783 // Handle separator checkboxes and custom field, only relevant if the file format is csv
1784 // Note we defer the change signal until all buttons have been updated
1785 // An early update may result in an incomplete tokenize run that would
1786 // cause our list of saved column types to be truncated
1787 if (price_imp->file_format() == GncImpFileFormat::CSV)
1788 {
1789 auto separators = price_imp->separators();
1790 auto escape = price_imp->enable_escape();
1791 const auto stock_sep_chars = std::string (" \t,:;-");
1792
1793 for (int i = 0; i < SEP_NUM_OF_TYPES; i++)
1794 {
1795 g_signal_handlers_block_by_func (sep_button[i], (gpointer) csv_price_imp_preview_sep_button_cb, this);
1796 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(sep_button[i]),
1797 separators.find (stock_sep_chars[i]) != std::string::npos);
1798 g_signal_handlers_unblock_by_func (sep_button[i], (gpointer) csv_price_imp_preview_sep_button_cb, this);
1799 }
1800
1801 // If there are any other separators in the separators string,
1802 // add them as custom separators
1803 auto pos = separators.find_first_of (stock_sep_chars);
1804 while (!separators.empty() && pos != std::string::npos)
1805 {
1806 separators.erase(pos);
1807 pos = separators.find_first_of (stock_sep_chars);
1808 }
1809 g_signal_handlers_block_by_func (escape_cbutton, (gpointer) csv_price_imp_preview_sep_button_cb, this);
1810 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(escape_cbutton),
1811 escape);
1812 g_signal_handlers_unblock_by_func (escape_cbutton, (gpointer) csv_price_imp_preview_sep_button_cb, this);
1813
1814 g_signal_handlers_block_by_func (custom_cbutton, (gpointer) csv_price_imp_preview_sep_button_cb, this);
1815 g_signal_handlers_block_by_func (custom_entry, (gpointer) csv_price_imp_preview_sep_button_cb, this);
1816
1817 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(custom_cbutton),
1818 !separators.empty());
1819 gtk_entry_set_text (GTK_ENTRY(custom_entry), separators.c_str());
1820
1821 g_signal_handlers_unblock_by_func (custom_cbutton, (gpointer) csv_price_imp_preview_sep_button_cb, this);
1822 g_signal_handlers_unblock_by_func (custom_entry, (gpointer) csv_price_imp_preview_sep_button_cb, this);
1823 try
1824 {
1825 price_imp->tokenize (false);
1826 }
1827 catch (std::range_error& err)
1828 {
1829 PERR ("CSV Tokenization Failed: %s", err.what ());
1830 }
1831 }
1832 // Repopulate the parsed data table
1833 g_idle_add ((GSourceFunc)csv_imp_preview_queue_rebuild_table, this);
1834}
#define PERR(format, args...)
Log a serious error.
Definition qoflog.h:244

◆ preview_refresh_table()

void CsvImpPriceAssist::preview_refresh_table ( )

Definition at line 1613 of file assistant-csv-price-import.cpp.

1614{
1615 preview_validate_settings ();
1616
1617 /* Create a new liststore to hold status and data from the file being imported.
1618 The first columns hold status information (row-color, row-errors, row-error-icon,...
1619 All following columns represent the tokenized data as strings. */
1620 auto ncols = PREV_N_FIXED_COLS + price_imp->column_types_price().size();
1621 auto model_col_types = g_new (GType, ncols);
1622 model_col_types[PREV_COL_FCOLOR] = G_TYPE_STRING;
1623 model_col_types[PREV_COL_BCOLOR] = G_TYPE_STRING;
1624 model_col_types[PREV_COL_ERROR] = G_TYPE_STRING;
1625 model_col_types[PREV_COL_ERR_ICON] = G_TYPE_STRING;
1626 model_col_types[PREV_COL_STRIKE] = G_TYPE_BOOLEAN;
1627 for (guint i = PREV_N_FIXED_COLS; i < ncols; i++)
1628 model_col_types[i] = G_TYPE_STRING;
1629 auto store = gtk_list_store_newv (ncols, model_col_types);
1630 g_free (model_col_types);
1631
1632 /* Fill the data liststore with data from importer object. */
1633 for (auto parse_line : price_imp->m_parsed_lines)
1634 {
1635 /* Fill the state cells */
1636 GtkTreeIter iter;
1637 gtk_list_store_append (store, &iter);
1638 preview_row_fill_state_cells (store, &iter,
1639 std::get<PL_ERROR>(parse_line), std::get<PL_SKIP>(parse_line));
1640
1641 /* Fill the data cells. */
1642 for (auto cell_str_it = std::get<PL_INPUT>(parse_line).cbegin(); cell_str_it != std::get<PL_INPUT>(parse_line).cend(); cell_str_it++)
1643 {
1644 uint32_t pos = PREV_N_FIXED_COLS + cell_str_it - std::get<PL_INPUT>(parse_line).cbegin();
1645 gtk_list_store_set (store, &iter, pos, cell_str_it->c_str(), -1);
1646 }
1647 }
1648 gtk_tree_view_set_model (treeview, GTK_TREE_MODEL(store));
1649 gtk_tree_view_set_tooltip_column (treeview, PREV_COL_ERROR);
1650
1651 /* Adjust treeview to go with the just created model. This consists of adding
1652 * or removing columns and resetting any parameters related to how
1653 * the columns and data should be rendered.
1654 */
1655
1656 /* Start with counting the current number of columns (ntcols)
1657 * we have in the treeview */
1658 auto ntcols = gtk_tree_view_get_n_columns (treeview);
1659
1660 /* Drop redundant columns if the model has less data columns than the new model
1661 * ntcols = n° of columns in treeview (1 error column + x data columns)
1662 * ncols = n° of columns in model (fixed state columns + x data columns)
1663 */
1664 while (ntcols > ncols - PREV_N_FIXED_COLS + 1)
1665 {
1666 auto col = gtk_tree_view_get_column (treeview, ntcols - 1);
1667 gtk_tree_view_column_clear (col);
1668 ntcols = gtk_tree_view_remove_column(treeview, col);
1669 }
1670
1671 /* Insert columns if the model has more data columns than the treeview. */
1672 while (ntcols < ncols - PREV_N_FIXED_COLS + 1)
1673 {
1674 /* Default cell renderer is text, except for the first (error)
1675 column uses an icon */
1676 auto renderer = (ntcols == 0) ? gtk_cell_renderer_pixbuf_new () : gtk_cell_renderer_text_new ();
1677 auto col = gtk_tree_view_column_new ();
1678 gtk_tree_view_column_pack_start (col, renderer, false);
1679 ntcols = gtk_tree_view_append_column (treeview, col);
1680 }
1681
1682 /* Reset column attributes as they are undefined after recreating the model */
1683 auto combostore = make_column_header_model_price ();
1684 for (uint32_t i = 0; i < ntcols; i++)
1685 preview_style_column (i, combostore);
1686
1687 auto column_types = price_imp->column_types_price();
1688 auto any_of_type = [](std::vector<GncPricePropType>& column_types,
1689 GncPricePropType req_column_type) -> bool
1690 {
1691 return std::any_of (column_types.begin(), column_types.end(),
1692 [&req_column_type](GncPricePropType column_type) -> bool
1693 { return column_type == req_column_type; });
1694 };
1695
1696 // look for a namespace column, clear the commodity combo
1697 if (any_of_type (column_types, GncPricePropType::FROM_NAMESPACE))
1698 {
1699 g_signal_handlers_block_by_func (commodity_selector, (gpointer) csv_price_imp_preview_commodity_sel_cb, this);
1700 set_commodity_for_combo (GTK_COMBO_BOX(commodity_selector), nullptr);
1701 g_signal_handlers_unblock_by_func (commodity_selector, (gpointer) csv_price_imp_preview_commodity_sel_cb, this);
1702 }
1703
1704 // look for a symbol column, clear the commodity combo
1705 if (any_of_type (column_types, GncPricePropType::FROM_SYMBOL))
1706 {
1707 g_signal_handlers_block_by_func (commodity_selector, (gpointer) csv_price_imp_preview_commodity_sel_cb, this);
1708 set_commodity_for_combo (GTK_COMBO_BOX(commodity_selector), nullptr);
1709 g_signal_handlers_unblock_by_func (commodity_selector, (gpointer) csv_price_imp_preview_commodity_sel_cb, this);
1710 }
1711
1712 // look for a currency column, clear the currency combo
1713 if (any_of_type (column_types, GncPricePropType::TO_CURRENCY))
1714 {
1715 g_signal_handlers_block_by_func (currency_selector, (gpointer) csv_price_imp_preview_currency_sel_cb, this);
1716 set_commodity_for_combo (GTK_COMBO_BOX(currency_selector), nullptr);
1717 g_signal_handlers_unblock_by_func (currency_selector, (gpointer) csv_price_imp_preview_currency_sel_cb, this);
1718 }
1719
1720 /* Release our reference for the stores to allow proper memory management. */
1721 g_object_unref (store);
1722 g_object_unref (combostore);
1723
1724 /* Make the things actually appear. */
1725 gtk_widget_show_all (GTK_WIDGET(treeview));
1726}

◆ preview_reparse_col_type()

void CsvImpPriceAssist::preview_reparse_col_type ( GncPricePropType  type)

Definition at line 1216 of file assistant-csv-price-import.cpp.

1217{
1218 auto column_types = price_imp->column_types_price();
1219
1220 // look for column type and force a reparse
1221 auto col_type = std::find (column_types.begin(),
1222 column_types.end(), type);
1223 if (col_type != column_types.end())
1224 {
1225 price_imp->set_column_type_price (col_type -column_types.begin(),
1226 type, true);
1227 }
1228}

◆ preview_settings_delete()

void CsvImpPriceAssist::preview_settings_delete ( )

Definition at line 897 of file assistant-csv-price-import.cpp.

898{
899 // Get the Active Selection
900 GtkTreeIter iter;
901 if (!gtk_combo_box_get_active_iter (settings_combo, &iter))
902 return;
903
904 CsvPriceImpSettings *preset = nullptr;
905 auto model = gtk_combo_box_get_model (settings_combo);
906 gtk_tree_model_get (model, &iter, SET_GROUP, &preset, -1);
907
908 auto response = gnc_ok_cancel_dialog (GTK_WINDOW(csv_imp_asst),
909 GTK_RESPONSE_CANCEL,
910 "%s", _("Delete the Import Settings."));
911 if (response == GTK_RESPONSE_OK)
912 {
913 preset->remove();
914 preview_populate_settings_combo();
915 gtk_combo_box_set_active (settings_combo, 0); // Default
916 preview_refresh (); // Reset the widgets
917 }
918}
void remove(void)
Remove the preset from the state file.

◆ preview_settings_load()

void CsvImpPriceAssist::preview_settings_load ( )

Definition at line 870 of file assistant-csv-price-import.cpp.

871{
872 // Get the Active Selection
873 GtkTreeIter iter;
874 if (!gtk_combo_box_get_active_iter (settings_combo, &iter))
875 return;
876
877 CsvPriceImpSettings *preset = nullptr;
878 auto model = gtk_combo_box_get_model (settings_combo);
879 gtk_tree_model_get (model, &iter, SET_GROUP, &preset, -1);
880
881 if (!preset)
882 return;
883
884 price_imp->settings (*preset);
885 if (preset->m_load_error)
886 gnc_error_dialog (GTK_WINDOW(csv_imp_asst),
887 "%s", _("There were problems reading some saved settings, continuing to load.\n"
888 "Please review and save again."));
889
890 preview_refresh ();
891 preview_handle_save_del_sensitivity (settings_combo);
892}

◆ preview_settings_name()

void CsvImpPriceAssist::preview_settings_name ( GtkEntry *  entry)

Definition at line 854 of file assistant-csv-price-import.cpp.

855{
856 auto text = gtk_entry_get_text (entry);
857 if (text)
858 price_imp->settings_name(text);
859
860 auto box = gtk_widget_get_parent (GTK_WIDGET(entry));
861 auto combo = gtk_widget_get_parent (GTK_WIDGET(box));
862
863 preview_handle_save_del_sensitivity (GTK_COMBO_BOX(combo));
864}

◆ preview_settings_save()

void CsvImpPriceAssist::preview_settings_save ( )

Definition at line 923 of file assistant-csv-price-import.cpp.

924{
925 auto new_name = price_imp->settings_name();
926
927 /* Check if the entry text matches an already existing preset */
928 GtkTreeIter iter;
929 if (!gtk_combo_box_get_active_iter (settings_combo, &iter))
930 {
931
932 auto model = gtk_combo_box_get_model (settings_combo);
933 bool valid = gtk_tree_model_get_iter_first (model, &iter);
934 while (valid)
935 {
936 // Walk through the list, reading each row
937 CsvPriceImpSettings *preset;
938 gtk_tree_model_get (model, &iter, SET_GROUP, &preset, -1);
939
940 if (preset && (preset->m_name == std::string(new_name)))
941 {
942 auto response = gnc_ok_cancel_dialog (GTK_WINDOW(csv_imp_asst),
943 GTK_RESPONSE_OK,
944 "%s", _("Setting name already exists, overwrite?"));
945 if (response != GTK_RESPONSE_OK)
946 return;
947
948 break;
949 }
950 valid = gtk_tree_model_iter_next (model, &iter);
951 }
952 }
953
954 /* All checks passed, let's save this preset */
955 if (!price_imp->save_settings())
956 {
957 gnc_info_dialog (GTK_WINDOW(csv_imp_asst),
958 "%s", _("The settings have been saved."));
959
960 // Update the settings store
961 preview_populate_settings_combo();
962 auto model = gtk_combo_box_get_model (settings_combo);
963
964 // Get the first entry in model
965 GtkTreeIter iter;
966 bool valid = gtk_tree_model_get_iter_first (model, &iter);
967 while (valid)
968 {
969 // Walk through the list, reading each row
970 gchar *name = nullptr;
971 gtk_tree_model_get (model, &iter, SET_NAME, &name, -1);
972
973 if (g_strcmp0 (name, new_name.c_str()) == 0) // Set Active, the one Saved.
974 gtk_combo_box_set_active_iter (settings_combo, &iter);
975
976 g_free (name);
977
978 valid = gtk_tree_model_iter_next (model, &iter);
979 }
980 }
981 else
982 gnc_error_dialog (GTK_WINDOW(csv_imp_asst),
983 "%s", _("There was a problem saving the settings, please try again."));
984}

◆ preview_split_column()

void CsvImpPriceAssist::preview_split_column ( int  col,
int  offset 
)

Definition at line 1429 of file assistant-csv-price-import.cpp.

1430{
1431 auto fwtok = dynamic_cast<GncFwTokenizer*>(price_imp->m_tokenizer.get());
1432 fwtok->col_split (col, offset);
1433 try
1434 {
1435 price_imp->tokenize (false);
1436 }
1437 catch (std::range_error& e)
1438 {
1439 gnc_error_dialog (GTK_WINDOW (csv_imp_asst), "%s", e.what());
1440 return;
1441 }
1442 preview_refresh_table();
1443}

◆ preview_update_col_type()

void CsvImpPriceAssist::preview_update_col_type ( GtkComboBox *  cbox)

Event handler for the user selecting a new column type.

When the user selects a new column type, that column's text must be changed to the selection, and any other columns containing that selection must be changed to "None" because we don't allow duplicates.

Parameters
rendererThe renderer of the column the user changed
pathThere is only 1 row in info->ctreeview, so this is always 0.
new_textThe text the user selected
infoThe display of the data being imported

Definition at line 1239 of file assistant-csv-price-import.cpp.

1240{
1241 /* Get the new text */
1242 GtkTreeIter iter;
1243 auto model = gtk_combo_box_get_model (cbox);
1244 gtk_combo_box_get_active_iter (cbox, &iter);
1245 auto new_col_type = GncPricePropType::NONE;
1246 gtk_tree_model_get (model, &iter, COL_TYPE_ID, &new_col_type, -1);
1247
1248 auto col_num = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT(cbox), "col-num"));
1249
1250 auto column_types = price_imp->column_types_price();
1251 auto old_col_type = column_types.at(col_num);
1252
1253 price_imp->set_column_type_price (col_num, new_col_type);
1254
1255 // if old_col_type is TO_CURRENCY, force a reparse of commodity
1256 if (old_col_type == GncPricePropType::TO_CURRENCY)
1257 {
1258 // look for a from_commodity column to reparse
1259 preview_reparse_col_type (GncPricePropType::FROM_SYMBOL);
1260 preview_reparse_col_type (GncPricePropType::FROM_NAMESPACE);
1261 }
1262
1263 // if old_col_type is FROM_SYMBOL, or FROM_NAMESPACE force a reparse of currency
1264 if ((old_col_type == GncPricePropType::FROM_SYMBOL) ||
1265 (old_col_type == GncPricePropType::FROM_NAMESPACE))
1266 {
1267 // look for a to_currency column to reparse
1268 preview_reparse_col_type (GncPricePropType::TO_CURRENCY);
1269 }
1270
1271 /* Delay rebuilding our data table to avoid critical warnings due to
1272 * pending events still acting on them after this event is processed.
1273 */
1274 g_idle_add ((GSourceFunc)csv_imp_preview_queue_rebuild_table, this);
1275}

◆ preview_update_commodity()

void CsvImpPriceAssist::preview_update_commodity ( )

Definition at line 1185 of file assistant-csv-price-import.cpp.

1186{
1187 gnc_commodity *comm = get_commodity_from_combo (GTK_COMBO_BOX(commodity_selector));
1188 price_imp->from_commodity (comm);
1189 preview_refresh_table ();
1190}

◆ preview_update_currency()

void CsvImpPriceAssist::preview_update_currency ( )

Definition at line 1177 of file assistant-csv-price-import.cpp.

1178{
1179 gnc_commodity *comm = get_commodity_from_combo (GTK_COMBO_BOX(currency_selector));
1180 price_imp->to_currency (comm);
1181 preview_refresh_table ();
1182}

◆ preview_update_currency_format()

void CsvImpPriceAssist::preview_update_currency_format ( )

Definition at line 1170 of file assistant-csv-price-import.cpp.

1171{
1172 price_imp->currency_format (gtk_combo_box_get_active (GTK_COMBO_BOX(currency_format_combo)));
1173 preview_refresh_table ();
1174}

◆ preview_update_date_format()

void CsvImpPriceAssist::preview_update_date_format ( )

Definition at line 1163 of file assistant-csv-price-import.cpp.

1164{
1165 price_imp->date_format (gtk_combo_box_get_active (GTK_COMBO_BOX(date_format_combo)));
1166 preview_refresh_table ();
1167}

◆ preview_update_encoding()

void CsvImpPriceAssist::preview_update_encoding ( const char *  encoding)

Event handler for a new encoding.

This is called when the user selects a new encoding; the data is reparsed and shown to the user.

Parameters
selectorThe widget the user uses to select a new encoding
encodingThe encoding that the user selected

Definition at line 1136 of file assistant-csv-price-import.cpp.

1137{
1138 /* This gets called twice every time a new encoding is selected. The
1139 * second call actually passes the correct data; thus, we only do
1140 * something the second time this is called. */
1141
1142 /* If this is the second time the function is called ... */
1143 if (encoding_selected_called)
1144 {
1145 std::string previous_encoding = price_imp->m_tokenizer->encoding();
1146 /* Try converting the new encoding and reparsing. */
1147 try
1148 {
1149 price_imp->encoding (encoding);
1150 preview_refresh_table ();
1151 }
1152 catch (...)
1153 {
1154 /* If it fails, change back to the old encoding. */
1155 gnc_error_dialog (GTK_WINDOW (csv_imp_asst), "%s", _("Invalid encoding selected"));
1156 go_charmap_sel_set_encoding (encselector, previous_encoding.c_str());
1157 }
1158 }
1159 encoding_selected_called = !encoding_selected_called;
1160}

◆ preview_update_file_format()

void CsvImpPriceAssist::preview_update_file_format ( )

Event handler for clicking one of the format type radio buttons.

This occurs if the format (Fixed-Width or CSV) is changed.

Parameters
csv_buttonThe "Separated" radio button
infoThe display of the data being imported

Definition at line 1090 of file assistant-csv-price-import.cpp.

1091{
1092 /* Set the parsing type correctly. */
1093 try
1094 {
1095 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(csv_button)))
1096 {
1097 price_imp->file_format (GncImpFileFormat::CSV);
1098 g_signal_handlers_disconnect_by_func(G_OBJECT(treeview),
1099 (gpointer)csv_price_imp_preview_treeview_clicked_cb, (gpointer)this);
1100 gtk_widget_set_visible (separator_table, true);
1101 gtk_widget_set_visible (fw_instructions_hbox, false);
1102 }
1103 else
1104 {
1105 price_imp->file_format (GncImpFileFormat::FIXED_WIDTH);
1106 /* Enable context menu for adding/removing columns. */
1107 g_signal_connect (G_OBJECT(treeview), "button-press-event",
1108 G_CALLBACK(csv_price_imp_preview_treeview_clicked_cb), (gpointer)this);
1109 gtk_widget_set_visible (separator_table, false);
1110 gtk_widget_set_visible (fw_instructions_hbox, true);
1111
1112 }
1113 price_imp->tokenize (false);
1114 preview_refresh_table ();
1115 }
1116 catch (std::range_error &e)
1117 {
1118 /* Parsing failed ... */
1119 gnc_error_dialog (GTK_WINDOW (csv_imp_asst), "%s", e.what());
1120 return;
1121 }
1122 catch (...)
1123 {
1124 // FIXME Handle file loading errors (possibly thrown by file_format above)
1125 PWARN("Got an error during file loading");
1126 }
1127}
#define PWARN(format, args...)
Log a warning.
Definition qoflog.h:250

◆ preview_update_fw_columns()

void CsvImpPriceAssist::preview_update_fw_columns ( GtkTreeView *  treeview,
GdkEventButton *  event 
)

Event handler for clicking on column headers.

This function is called whenever the user clicks on column headers in preview->treeview to modify columns when in fixed-width mode.

Parameters
buttonThe button at the top of a column of the treeview
eventThe event that happened (where the user clicked)
infoThe data being configured
Returns
true if further processing of this even should stop, false if other event handlers can have a go at this as well

Definition at line 1455 of file assistant-csv-price-import.cpp.

1456{
1457 /* Nothing to do if this was not triggered on our treeview body */
1458 if (event->window != gtk_tree_view_get_bin_window (treeview))
1459 return;
1460
1461 /* Find the column that was clicked. */
1462 GtkTreeViewColumn *tcol = nullptr;
1463 int cell_x = 0;
1464 auto success = gtk_tree_view_get_path_at_pos (treeview,
1465 (int)event->x, (int)event->y,
1466 nullptr, &tcol, &cell_x, nullptr);
1467 if (!success)
1468 return;
1469
1470 /* Stop if no column found in this treeview (-1) or
1471 * if column is the error messages column (0) */
1472 auto tcol_list = gtk_tree_view_get_columns(treeview);
1473 auto tcol_num = g_list_index (tcol_list, tcol);
1474 g_list_free (tcol_list);
1475 if (tcol_num <= 0)
1476 return;
1477
1478 /* Data columns in the treeview are offset by one
1479 * because the first column is the error column
1480 */
1481 auto dcol = tcol_num - 1;
1482 auto offset = get_new_col_rel_pos (tcol, cell_x);
1483 if (event->type == GDK_2BUTTON_PRESS && event->button == 1)
1484 /* Double clicks can split columns. */
1485 preview_split_column (dcol, offset);
1486 else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
1487 /* Right clicking brings up a context menu. */
1488 fixed_context_menu (event, dcol, offset);
1489}

◆ preview_update_separators()

void CsvImpPriceAssist::preview_update_separators ( GtkWidget *  widget)

Event handler for separator changes.

This function is called whenever one of the widgets for configuring the separators (the separator checkbuttons, the escape checkbutton or the custom separator entry) is changed.

Parameters
widgetThe widget that was changed
infoThe data that is being configured

Definition at line 1022 of file assistant-csv-price-import.cpp.

1023{
1024 /* Only manipulate separator characters if the currently open file is
1025 * csv separated. */
1026 if (price_imp->file_format() != GncImpFileFormat::CSV)
1027 return;
1028
1029 /* Add the corresponding characters to checked_separators for each
1030 * button that is checked. */
1031 auto checked_separators = std::string();
1032 const auto stock_sep_chars = std::string (" \t,:;-");
1033 for (int i = 0; i < SEP_NUM_OF_TYPES; i++)
1034 {
1035 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(sep_button[i])))
1036 checked_separators += stock_sep_chars[i];
1037 }
1038
1039 /* Add the custom separator if the user checked its button. */
1040 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(custom_cbutton)))
1041 {
1042 auto custom_sep = gtk_entry_get_text (custom_entry);
1043 if (custom_sep[0] != '\0') /* Don't add a blank separator (bad things will happen!). */
1044 checked_separators += custom_sep;
1045 }
1046
1047 /* Set the parse options using the checked_separators list. */
1048 price_imp->separators (checked_separators);
1049 price_imp->enable_escape (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(escape_cbutton)));
1050
1051 /* if there are no separators, there will only be one column
1052 * so make sure column header is NONE */
1053 if (checked_separators.empty())
1054 price_imp->set_column_type_price (0, GncPricePropType::NONE);
1055
1056 /* Parse the data using the new options. We don't want to reguess
1057 * the column types because we want to leave the user's
1058 * configurations intact. */
1059 try
1060 {
1061 price_imp->tokenize (false);
1062 preview_refresh_table ();
1063 }
1064 catch (std::range_error &e)
1065 {
1066 /* Warn the user there was a problem and try to undo what caused
1067 * the error. (This will cause a reparsing and ideally a usable
1068 * configuration.) */
1069 gnc_error_dialog (GTK_WINDOW(csv_imp_asst), "Error in parsing");
1070 /* If we're here because the user changed the file format, we should just wait for the user
1071 * to update the configuration */
1072 if (!widget)
1073 return;
1074 /* If the user changed the custom separator, erase that custom separator. */
1075 if (widget == GTK_WIDGET(custom_entry))
1076 gtk_entry_set_text (GTK_ENTRY(widget), "");
1077 /* If the user checked a checkbutton, toggle that checkbutton back. */
1078 else
1079 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(widget),
1080 !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget)));
1081 return;
1082 }
1083}

◆ preview_update_skipped_rows()

void CsvImpPriceAssist::preview_update_skipped_rows ( )

Definition at line 988 of file assistant-csv-price-import.cpp.

989{
990 /* Update skip rows in the parser */
991 price_imp->update_skipped_lines (gtk_spin_button_get_value_as_int (start_row_spin),
992 gtk_spin_button_get_value_as_int (end_row_spin),
993 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(skip_alt_rows_button)),
994 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(skip_errors_button)));
995
996 /* And adjust maximum number of lines that can be skipped at each end accordingly */
997 auto adj = gtk_spin_button_get_adjustment (end_row_spin);
998 gtk_adjustment_set_upper (adj, price_imp->m_parsed_lines.size()
999 - price_imp->skip_start_lines() -1);
1000
1001 adj = gtk_spin_button_get_adjustment (start_row_spin);
1002 gtk_adjustment_set_upper (adj, price_imp->m_parsed_lines.size()
1003 - price_imp->skip_end_lines() - 1);
1004
1005 preview_refresh_table ();
1006}

◆ preview_validate_settings()

void CsvImpPriceAssist::preview_validate_settings ( )

Definition at line 1838 of file assistant-csv-price-import.cpp.

1839{
1840 /* Allow the user to proceed only if there are no inconsistencies in the settings */
1841 auto error_msg = price_imp->verify();
1842 gtk_assistant_set_page_complete (csv_imp_asst, preview_page, error_msg.empty());
1843 gtk_label_set_markup(GTK_LABEL(instructions_label), error_msg.c_str());
1844 gtk_widget_set_visible (GTK_WIDGET(instructions_image), !error_msg.empty());
1845}

Friends And Related Symbol Documentation

◆ fixed_context_menu_handler_price

gboolean fixed_context_menu_handler_price ( GnumericPopupMenuElement const *  element,
gpointer  userdata 
)
friend

Definition at line 1361 of file assistant-csv-price-import.cpp.

1363{
1364 auto info = (CsvImpPriceAssist*)userdata;
1365 auto fwtok = dynamic_cast<GncFwTokenizer*>(info->price_imp->m_tokenizer.get());
1366
1367 switch (element->index)
1368 {
1369 case CONTEXT_STF_IMPORT_MERGE_LEFT:
1370 fwtok->col_delete (info->fixed_context_col - 1);
1371 break;
1372 case CONTEXT_STF_IMPORT_MERGE_RIGHT:
1373 fwtok->col_delete (info->fixed_context_col);
1374 break;
1375 case CONTEXT_STF_IMPORT_SPLIT:
1376 fwtok->col_split (info->fixed_context_col, info->fixed_context_offset);
1377 break;
1378 case CONTEXT_STF_IMPORT_WIDEN:
1379 fwtok->col_widen (info->fixed_context_col);
1380 break;
1381 case CONTEXT_STF_IMPORT_NARROW:
1382 fwtok->col_narrow (info->fixed_context_col);
1383 break;
1384 default:
1385 ; /* Nothing */
1386 }
1387
1388 try
1389 {
1390 info->price_imp->tokenize (false);
1391 }
1392 catch(std::range_error& e)
1393 {
1394 gnc_error_dialog (GTK_WINDOW (info->csv_imp_asst), "%s", e.what());
1395 return false;
1396 }
1397 info->preview_refresh_table ();
1398 return true;
1399}

The documentation for this class was generated from the following file: