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 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_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 }

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