GnuCash  5.6-150-g038405b370+
Public Member Functions | Friends
CsvImpTransAssist Class Reference

Public Member Functions

 CsvImpTransAssist (const CsvImpTransAssist &)=delete
 
CsvImpTransAssistoperator= (const CsvImpTransAssist &)=delete
 
 CsvImpTransAssist (CsvImpTransAssist &&)=delete
 
CsvImpTransAssistoperator= (CsvImpTransAssist &&)=delete
 
void assist_prepare_cb (GtkWidget *page)
 
void assist_file_page_prepare ()
 
void assist_preview_page_prepare ()
 
void assist_account_match_page_prepare ()
 
void assist_doc_page_prepare ()
 
void assist_match_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_multi_split (bool multi)
 
void preview_update_separators (GtkWidget *widget)
 Event handler for separator changes. More...
 
void preview_update_file_format ()
 Event handler for clicking one of the format type radio buttons. More...
 
void preview_update_account ()
 
void preview_update_encoding (const char *encoding)
 Event handler for a new encoding. More...
 
void preview_update_date_format ()
 
void preview_update_currency_format ()
 
void preview_update_col_type (GtkComboBox *cbox)
 Event handler for the user selecting a new column type. More...
 
void preview_update_fw_columns (GtkTreeView *treeview, GdkEventButton *event)
 Event handler for clicking on column headers. More...
 
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 ()
 
void acct_match_via_button ()
 
bool acct_match_via_view_dblclick (GdkEventButton *event)
 
void acct_match_select (GtkTreeModel *model, GtkTreeIter *iter)
 
void acct_match_set_accounts ()
 

Friends

gboolean fixed_context_menu_handler (GnumericPopupMenuElement const *element, gpointer userdata)
 

Detailed Description

Definition at line 152 of file assistant-csv-trans-import.cpp.

Member Function Documentation

◆ preview_update_col_type()

void CsvImpTransAssist::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
cboxThe combo box the user just clicked to make a change

Definition at line 1181 of file assistant-csv-trans-import.cpp.

1182 {
1183  /* Get the new text */
1184  GtkTreeIter iter;
1185  auto model = gtk_combo_box_get_model (cbox);
1186  gtk_combo_box_get_active_iter (cbox, &iter);
1187  auto new_col_type = GncTransPropType::NONE;
1188  gtk_tree_model_get (model, &iter, COL_TYPE_ID, &new_col_type, -1);
1189 
1190  auto col_num = GPOINTER_TO_UINT (g_object_get_data (G_OBJECT(cbox), "col-num"));
1191  tx_imp->set_column_type (col_num, new_col_type);
1192 
1193  /* Delay rebuilding our data table to avoid critical warnings due to
1194  * pending events still acting on them after this event is processed.
1195  */
1196  g_idle_add ((GSourceFunc)csv_imp_preview_queue_rebuild_table, this);
1197 
1198 }

◆ preview_update_encoding()

void CsvImpTransAssist::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
encodingThe encoding that the user selected

Definition at line 1110 of file assistant-csv-trans-import.cpp.

1111 {
1112  /* This gets called twice every time a new encoding is selected. The
1113  * second call actually passes the correct data; thus, we only do
1114  * something the second time this is called. */
1115 
1116  /* If this is the second time the function is called ... */
1117  if (encoding_selected_called)
1118  {
1119  std::string previous_encoding = tx_imp->m_tokenizer->encoding();
1120  /* Try converting the new encoding and reparsing. */
1121  try
1122  {
1123  tx_imp->encoding (encoding);
1124  preview_refresh_table ();
1125  }
1126  catch (...)
1127  {
1128  /* If it fails, change back to the old encoding. */
1129  gnc_error_dialog (GTK_WINDOW (csv_imp_asst), "%s", _("Invalid encoding selected"));
1130  go_charmap_sel_set_encoding (encselector, previous_encoding.c_str());
1131  }
1132  }
1133 
1134  encoding_selected_called = !encoding_selected_called;
1135 }

◆ preview_update_file_format()

void CsvImpTransAssist::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.

Definition at line 1055 of file assistant-csv-trans-import.cpp.

1056 {
1057  /* Set the parsing type correctly. */
1058  try
1059  {
1060  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(csv_button)))
1061  {
1062  tx_imp->file_format (GncImpFileFormat::CSV);
1063  g_signal_handlers_disconnect_by_func(G_OBJECT(treeview),
1064  (gpointer)csv_tximp_preview_treeview_clicked_cb, (gpointer)this);
1065  gtk_widget_set_visible (separator_table, true);
1066  gtk_widget_set_visible (fw_instructions_hbox, false);
1067  }
1068  else
1069  {
1070  tx_imp->file_format (GncImpFileFormat::FIXED_WIDTH);
1071  /* Enable context menu for adding/removing columns. */
1072  g_signal_connect (G_OBJECT(treeview), "button-press-event",
1073  G_CALLBACK(csv_tximp_preview_treeview_clicked_cb), (gpointer)this);
1074  gtk_widget_set_visible (separator_table, false);
1075  gtk_widget_set_visible (fw_instructions_hbox, true);
1076 
1077  }
1078 
1079  tx_imp->tokenize (false);
1080  preview_refresh_table ();
1081  }
1082  catch (std::range_error &e)
1083  {
1084  /* Parsing failed ... */
1085  gnc_error_dialog (GTK_WINDOW (csv_imp_asst), "%s", e.what());
1086  return;
1087  }
1088  catch (...)
1089  {
1090  // FIXME Handle file loading errors (possibly thrown by file_format above)
1091  PWARN("Got an error during file loading");
1092  }
1093 }
#define PWARN(format, args...)
Log a warning.
Definition: qoflog.h:250

◆ preview_update_fw_columns()

void CsvImpTransAssist::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
eventThe event that happened (where the user clicked)

Definition at line 1375 of file assistant-csv-trans-import.cpp.

1376 {
1377  /* Nothing to do if this was not triggered on our treeview body */
1378  if (event->window != gtk_tree_view_get_bin_window (treeview))
1379  return;
1380 
1381  /* Find the column that was clicked. */
1382  GtkTreeViewColumn *tcol = nullptr;
1383  int cell_x = 0;
1384  auto success = gtk_tree_view_get_path_at_pos (treeview,
1385  (int)event->x, (int)event->y,
1386  nullptr, &tcol, &cell_x, nullptr);
1387  if (!success)
1388  return;
1389 
1390  /* Stop if no column found in this treeview (-1) or
1391  * if column is the error messages column (0) */
1392  auto tcol_list = gtk_tree_view_get_columns(treeview);
1393  auto tcol_num = g_list_index (tcol_list, tcol);
1394  g_list_free (tcol_list);
1395  if (tcol_num <= 0)
1396  return;
1397 
1398  /* Data columns in the treeview are offset by one
1399  * because the first column is the error column
1400  */
1401  auto dcol = tcol_num - 1;
1402  auto offset = get_new_col_rel_pos (tcol, cell_x);
1403  if (event->type == GDK_2BUTTON_PRESS && event->button == 1)
1404  /* Double clicks can split columns. */
1405  preview_split_column (dcol, offset);
1406  else if (event->type == GDK_BUTTON_PRESS && event->button == 3)
1407  /* Right clicking brings up a context menu. */
1408  fixed_context_menu (event, dcol, offset);
1409 }

◆ preview_update_separators()

void CsvImpTransAssist::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 or the custom separator entry) is changed.

Parameters
widgetThe widget that was changed

Definition at line 993 of file assistant-csv-trans-import.cpp.

994 {
995 
996  /* Only manipulate separator characters if the currently open file is
997  * csv separated. */
998  if (tx_imp->file_format() != GncImpFileFormat::CSV)
999  return;
1000 
1001  /* Add the corresponding characters to checked_separators for each
1002  * button that is checked. */
1003  auto checked_separators = std::string();
1004  const auto stock_sep_chars = std::string (" \t,:;-");
1005  for (int i = 0; i < SEP_NUM_OF_TYPES; i++)
1006  {
1007  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(sep_button[i])))
1008  checked_separators += stock_sep_chars[i];
1009  }
1010 
1011  /* Add the custom separator if the user checked its button. */
1012  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(custom_cbutton)))
1013  {
1014  auto custom_sep = gtk_entry_get_text (custom_entry);
1015  if (custom_sep[0] != '\0') /* Don't add a blank separator (bad things will happen!). */
1016  checked_separators += custom_sep;
1017  }
1018 
1019  /* Set the parse options using the checked_separators list. */
1020  tx_imp->separators (checked_separators);
1021 
1022  /* Parse the data using the new options. We don't want to reguess
1023  * the column types because we want to leave the user's
1024  * configurations intact. */
1025  try
1026  {
1027  tx_imp->tokenize (false);
1028  preview_refresh_table ();
1029  }
1030  catch (std::range_error &e)
1031  {
1032  /* Warn the user there was a problem and try to undo what caused
1033  * the error. (This will cause a reparsing and ideally a usable
1034  * configuration.) */
1035  gnc_error_dialog (GTK_WINDOW (csv_imp_asst), "Error in parsing");
1036  /* If we're here because the user changed the file format, we should just wait for the user
1037  * to update the configuration */
1038  if (!widget)
1039  return;
1040  /* If the user changed the custom separator, erase that custom separator. */
1041  if (widget == GTK_WIDGET(custom_entry))
1042  gtk_entry_set_text (GTK_ENTRY(widget), "");
1043  /* If the user checked a checkbutton, toggle that checkbutton back. */
1044  else
1045  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(widget),
1046  !gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(widget)));
1047  return;
1048  }
1049 }

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