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 1188 of file assistant-csv-trans-import.cpp.

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

◆ 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 1117 of file assistant-csv-trans-import.cpp.

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

◆ 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 1062 of file assistant-csv-trans-import.cpp.

1063 {
1064  /* Set the parsing type correctly. */
1065  try
1066  {
1067  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(csv_button)))
1068  {
1069  tx_imp->file_format (GncImpFileFormat::CSV);
1070  g_signal_handlers_disconnect_by_func(G_OBJECT(treeview),
1071  (gpointer)csv_tximp_preview_treeview_clicked_cb, (gpointer)this);
1072  gtk_widget_set_visible (separator_table, true);
1073  gtk_widget_set_visible (fw_instructions_hbox, false);
1074  }
1075  else
1076  {
1077  tx_imp->file_format (GncImpFileFormat::FIXED_WIDTH);
1078  /* Enable context menu for adding/removing columns. */
1079  g_signal_connect (G_OBJECT(treeview), "button-press-event",
1080  G_CALLBACK(csv_tximp_preview_treeview_clicked_cb), (gpointer)this);
1081  gtk_widget_set_visible (separator_table, false);
1082  gtk_widget_set_visible (fw_instructions_hbox, true);
1083 
1084  }
1085 
1086  tx_imp->tokenize (false);
1087  preview_refresh_table ();
1088  }
1089  catch (std::range_error &e)
1090  {
1091  /* Parsing failed ... */
1092  gnc_error_dialog (GTK_WINDOW (csv_imp_asst), "%s", e.what());
1093  return;
1094  }
1095  catch (...)
1096  {
1097  // FIXME Handle file loading errors (possibly thrown by file_format above)
1098  PWARN("Got an error during file loading");
1099  }
1100 }
#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 1382 of file assistant-csv-trans-import.cpp.

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

◆ 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, the escape checkbutton or the custom separator entry) is changed.

Parameters
widgetThe widget that was changed

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

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

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