Skip to content

Commit

Permalink
[import-main-matcher.cpp] refactor common code into gen_trans_common_…
Browse files Browse the repository at this point in the history
…toggled_cb

these callbacks handle the checkboxes being toggled.
  • Loading branch information
christopherlam committed Jul 27, 2023
1 parent 91869d0 commit d6a025e
Showing 1 changed file with 21 additions and 51 deletions.
72 changes: 21 additions & 51 deletions gnucash/import-export/import-main-matcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -673,76 +673,46 @@ run_match_dialog (GNCImportMainMatcher *info,
trans_info, info->pending_matches);
}

static void
gen_trans_common_toggled_cb (GtkCellRendererToggle *cell_renderer, gchar *path,
GNCImportMainMatcher *gui, GNCImportAction action)
{
auto model = gtk_tree_view_get_model (gui->view);
GtkTreeIter tree_iter;
g_return_if_fail (gtk_tree_model_get_iter_from_string (model, &tree_iter, path));

GNCImportTransInfo *transaction_info;
gtk_tree_model_get (model, &tree_iter, DOWNLOADED_COL_DATA, &transaction_info, -1);
if (gnc_import_TransInfo_get_action (transaction_info) == action &&
gnc_import_Settings_get_action_skip_enabled (gui->user_settings))
gnc_import_TransInfo_set_action (transaction_info, GNCImport_SKIP);
else
gnc_import_TransInfo_set_action (transaction_info, action);
refresh_model_row (gui, model, &tree_iter, transaction_info);
}

static void
gnc_gen_trans_add_toggled_cb (GtkCellRendererToggle *cell_renderer,
gchar *path,
GNCImportMainMatcher *gui)
{
ENTER("");

GtkTreeModel *model = gtk_tree_view_get_model (gui->view);
GtkTreeIter iter;
if (!gtk_tree_model_get_iter_from_string (model, &iter, path))
return;

GNCImportTransInfo *trans_info;
gtk_tree_model_get (model, &iter, DOWNLOADED_COL_DATA, &trans_info, -1);

if (gnc_import_TransInfo_get_action (trans_info) == GNCImport_ADD &&
gnc_import_Settings_get_action_skip_enabled (gui->user_settings))
gnc_import_TransInfo_set_action (trans_info, GNCImport_SKIP);
else
gnc_import_TransInfo_set_action (trans_info, GNCImport_ADD);
refresh_model_row (gui, model, &iter, trans_info);
LEAVE("");
gen_trans_common_toggled_cb (cell_renderer, path, gui, GNCImport_ADD);
}

static void
gnc_gen_trans_clear_toggled_cb (GtkCellRendererToggle *cell_renderer,
gchar *path,
GNCImportMainMatcher *gui)
{
ENTER("");

GtkTreeModel *model = gtk_tree_view_get_model (gui->view);
GtkTreeIter iter;
if (!gtk_tree_model_get_iter_from_string (model, &iter, path))
return;

GNCImportTransInfo *trans_info;
gtk_tree_model_get (model, &iter, DOWNLOADED_COL_DATA, &trans_info, -1);

if (gnc_import_TransInfo_get_action (trans_info) == GNCImport_CLEAR &&
gnc_import_Settings_get_action_skip_enabled (gui->user_settings))
gnc_import_TransInfo_set_action (trans_info, GNCImport_SKIP);
else
gnc_import_TransInfo_set_action (trans_info, GNCImport_CLEAR);
refresh_model_row (gui, model, &iter, trans_info);
LEAVE("");
gen_trans_common_toggled_cb (cell_renderer, path, gui, GNCImport_CLEAR);
}

static void
gnc_gen_trans_update_toggled_cb (GtkCellRendererToggle *cell_renderer,
gchar *path,
GNCImportMainMatcher *gui)
{
ENTER("");

GtkTreeModel *model = gtk_tree_view_get_model (gui->view);
GtkTreeIter iter;
if (!gtk_tree_model_get_iter_from_string (model, &iter, path))
return;

GNCImportTransInfo *trans_info;
gtk_tree_model_get (model, &iter, DOWNLOADED_COL_DATA, &trans_info, -1);

if (gnc_import_TransInfo_get_action (trans_info) == GNCImport_UPDATE &&
gnc_import_Settings_get_action_skip_enabled (gui->user_settings))
gnc_import_TransInfo_set_action (trans_info, GNCImport_SKIP);
else
gnc_import_TransInfo_set_action (trans_info, GNCImport_UPDATE);
refresh_model_row (gui, model, &iter, trans_info);
LEAVE("");
gen_trans_common_toggled_cb (cell_renderer, path, gui, GNCImport_UPDATE);
}

static void
Expand Down

0 comments on commit d6a025e

Please sign in to comment.