GnuCash  5.6-150-g038405b370+
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. More...
 
void preview_update_file_format ()
 Event handler for clicking one of the format type radio buttons. More...
 
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_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. 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 ()
 

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.

Member Function Documentation

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

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

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

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

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

1084 {
1085  /* Set the parsing type correctly. */
1086  try
1087  {
1088  if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(csv_button)))
1089  {
1090  price_imp->file_format (GncImpFileFormat::CSV);
1091  g_signal_handlers_disconnect_by_func(G_OBJECT(treeview),
1092  (gpointer)csv_price_imp_preview_treeview_clicked_cb, (gpointer)this);
1093  gtk_widget_set_visible (separator_table, true);
1094  gtk_widget_set_visible (fw_instructions_hbox, false);
1095  }
1096  else
1097  {
1098  price_imp->file_format (GncImpFileFormat::FIXED_WIDTH);
1099  /* Enable context menu for adding/removing columns. */
1100  g_signal_connect (G_OBJECT(treeview), "button-press-event",
1101  G_CALLBACK(csv_price_imp_preview_treeview_clicked_cb), (gpointer)this);
1102  gtk_widget_set_visible (separator_table, false);
1103  gtk_widget_set_visible (fw_instructions_hbox, true);
1104 
1105  }
1106  price_imp->tokenize (false);
1107  preview_refresh_table ();
1108  }
1109  catch (std::range_error &e)
1110  {
1111  /* Parsing failed ... */
1112  gnc_error_dialog (GTK_WINDOW (csv_imp_asst), "%s", e.what());
1113  return;
1114  }
1115  catch (...)
1116  {
1117  // FIXME Handle file loading errors (possibly thrown by file_format above)
1118  PWARN("Got an error during file loading");
1119  }
1120 }
#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 1448 of file assistant-csv-price-import.cpp.

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

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

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

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

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

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