32 #include <glib/gi18n.h> 37 #include "dialog-utils.h" 44 #define GNC_PREFS_GROUP "dialogs.import.generic.match-picker" 45 #define GNC_PREF_DISPLAY_RECONCILED "display-reconciled" 49 DOWNLOADED_COL_ACCOUNT = 0,
51 DOWNLOADED_COL_AMOUNT,
52 DOWNLOADED_COL_DESCRIPTION,
54 DOWNLOADED_COL_BALANCED,
55 DOWNLOADED_COL_INFO_PTR,
61 MATCHER_COL_CONFIDENCE = 0,
62 MATCHER_COL_CONFIDENCE_PIXBUF,
65 MATCHER_COL_DESCRIPTION,
67 MATCHER_COL_RECONCILED,
82 GtkWidget * transaction_matcher;
83 GtkTreeView * downloaded_view;
84 GtkTreeView * match_view;
85 GtkCheckButton * reconciled_chk;
86 GNCImportSettings * user_settings;
89 GNCImportPendingMatches * pending_matches;
95 downloaded_transaction_append(GNCImportMatchPicker * matcher,
96 GNCImportTransInfo * transaction_info)
98 g_return_if_fail (matcher);
99 g_return_if_fail (transaction_info);
102 auto store = GTK_LIST_STORE(gtk_tree_view_get_model(matcher->downloaded_view));
108 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter))
112 GNCImportTransInfo *local_info;
113 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
114 DOWNLOADED_COL_INFO_PTR, &local_info,
116 if (local_info == transaction_info)
122 while (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter));
125 gtk_list_store_append(store, &iter);
140 gtk_list_store_set (store, &iter,
141 DOWNLOADED_COL_ACCOUNT, account,
142 DOWNLOADED_COL_DATE, date,
143 DOWNLOADED_COL_AMOUNT, amount,
144 DOWNLOADED_COL_DESCRIPTION, desc,
145 DOWNLOADED_COL_MEMO, memo,
146 DOWNLOADED_COL_BALANCED, imbalance,
147 DOWNLOADED_COL_INFO_PTR, transaction_info,
150 gtk_tree_selection_select_iter (gtk_tree_view_get_selection(matcher->downloaded_view), &iter);
158 match_update_match_model (GNCImportMatchPicker *matcher)
160 g_return_if_fail (matcher);
162 auto show_reconciled = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(matcher->reconciled_chk));
165 auto match_store = GTK_LIST_STORE(gtk_tree_view_get_model(matcher->match_view));
166 gtk_list_store_clear(match_store);
175 if (show_reconciled == FALSE && reconciled !=
NREC)
180 auto match_type = gnc_import_PendingMatches_get_match_type (matcher->pending_matches, match_info);
183 auto confidence = g_strdup_printf (
"%d", probability);
189 GTK_WIDGET(matcher->match_view)) : nullptr;
190 auto pending_str = (match_type == GNCImportPending_MANUAL || match_type == GNCImportPending_AUTO)
191 ? g_strdup_printf (
"%s (%s)", gnc_get_reconcile_str (
CREC), gnc_import_PendingMatches_get_type_str (match_type))
195 gtk_list_store_append (match_store, &iter);
196 gtk_list_store_set (match_store, &iter,
197 MATCHER_COL_DATE, date,
198 MATCHER_COL_CONFIDENCE, confidence,
199 MATCHER_COL_CONFIDENCE_PIXBUF, pixbuf,
200 MATCHER_COL_AMOUNT, amount,
201 MATCHER_COL_DESCRIPTION, description,
202 MATCHER_COL_MEMO, memo,
203 MATCHER_COL_RECONCILED, gnc_get_reconcile_str (reconciled),
204 MATCHER_COL_INFO_PTR, match_info,
205 MATCHER_COL_PENDING, pending_str,
209 gtk_tree_selection_select_iter (gtk_tree_view_get_selection (matcher->match_view), &iter);
213 g_free (pending_str);
224 downloaded_transaction_changed_cb (GtkTreeSelection *selection,
225 GNCImportMatchPicker *matcher)
227 GtkTreeModel *dl_model;
232 if (!gtk_tree_selection_get_selected(selection, &dl_model, &iter))
234 matcher->selected_trans_info = NULL;
237 gtk_tree_model_get(dl_model, &iter,
238 DOWNLOADED_COL_INFO_PTR, &matcher->selected_trans_info,
241 match_update_match_model (matcher);
245 match_show_reconciled_changed_cb (GtkCheckButton* checkbox,
246 GNCImportMatchPicker *matcher)
248 match_update_match_model (matcher);
252 match_transaction_changed_cb (GtkTreeSelection *selection,
253 GNCImportMatchPicker *matcher)
258 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
260 matcher->selected_match_info = NULL;
264 gtk_tree_model_get(model, &iter,
265 MATCHER_COL_INFO_PTR, &matcher->selected_match_info,
270 match_transaction_row_activated_cb (GtkTreeView *view, GtkTreePath *path,
271 GtkTreeViewColumn *column,
272 GNCImportMatchPicker *matcher)
274 g_return_if_fail (matcher && matcher->transaction_matcher);
276 gtk_dialog_response (GTK_DIALOG (matcher->transaction_matcher),
281 add_column(GtkTreeView *view,
const gchar *title,
int col_num)
283 GtkCellRenderer *renderer;
284 GtkTreeViewColumn *column;
286 renderer = gtk_cell_renderer_text_new();
287 column = gtk_tree_view_column_new_with_attributes(title, renderer,
290 gtk_tree_view_append_column(view, column);
291 g_object_set(G_OBJECT(column),
298 gnc_import_match_picker_init_downloaded_view (GNCImportMatchPicker * matcher)
302 GtkTreeSelection *selection;
304 view = matcher->downloaded_view;
305 store = gtk_list_store_new(NUM_DOWNLOADED_COLS,
306 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
307 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
309 gtk_tree_view_set_model(view, GTK_TREE_MODEL(store));
310 g_object_unref(store);
312 add_column(view, _(
"Account"), DOWNLOADED_COL_ACCOUNT);
313 add_column(view, _(
"Date"), DOWNLOADED_COL_DATE);
314 add_column(view, _(
"Amount"), DOWNLOADED_COL_AMOUNT);
315 add_column(view, _(
"Description"), DOWNLOADED_COL_DESCRIPTION);
316 add_column(view, _(
"Memo"), DOWNLOADED_COL_MEMO);
317 add_column(view, _(
"Balanced"), DOWNLOADED_COL_BALANCED);
319 selection = gtk_tree_view_get_selection(view);
320 g_signal_connect(selection,
"changed",
321 G_CALLBACK(downloaded_transaction_changed_cb), matcher);
325 gnc_import_match_picker_init_match_view (GNCImportMatchPicker * matcher)
329 GtkCellRenderer *renderer;
330 GtkTreeViewColumn *column;
331 GtkTreeSelection *selection;
333 view = matcher->match_view;
334 store = gtk_list_store_new(NUM_MATCHER_COLS,
335 G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING,
336 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
337 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
338 gtk_tree_view_set_model(view, GTK_TREE_MODEL(store));
339 g_object_unref(store);
341 renderer = gtk_cell_renderer_pixbuf_new();
342 g_object_set(renderer,
"xalign", 0.0, NULL);
343 column = gtk_tree_view_column_new_with_attributes(_(
"Confidence"), renderer,
344 "pixbuf", MATCHER_COL_CONFIDENCE_PIXBUF,
346 renderer = gtk_cell_renderer_text_new();
347 gtk_tree_view_column_pack_start(column, renderer, TRUE);
348 gtk_tree_view_column_set_attributes(column, renderer,
349 "text", MATCHER_COL_CONFIDENCE,
351 gtk_tree_view_append_column(view, column);
353 add_column(view, _(
"Date"), MATCHER_COL_DATE);
354 add_column(view, _(
"Amount"), MATCHER_COL_AMOUNT);
355 add_column(view, _(
"Description"), MATCHER_COL_DESCRIPTION);
356 add_column(view, _(
"Memo"), MATCHER_COL_MEMO);
357 add_column(view, _(
"Reconciled"), MATCHER_COL_RECONCILED);
358 add_column(view, _(
"Pending Action"), MATCHER_COL_PENDING);
360 selection = gtk_tree_view_get_selection(view);
361 g_signal_connect(selection,
"changed",
362 G_CALLBACK(match_transaction_changed_cb), matcher);
363 g_signal_connect(view,
"row-activated",
364 G_CALLBACK(match_transaction_row_activated_cb), matcher);
372 init_match_picker_gui(GtkWidget *parent, GNCImportMatchPicker * matcher)
382 builder = gtk_builder_new();
383 gnc_builder_add_from_file (builder,
"dialog-import.glade",
"match_picker_dialog");
384 g_return_if_fail (builder != NULL);
386 matcher->transaction_matcher = GTK_WIDGET(gtk_builder_get_object (builder,
"match_picker_dialog"));
387 matcher->downloaded_view = (GtkTreeView *)GTK_WIDGET(gtk_builder_get_object (builder,
"download_view"));
388 matcher->match_view = (GtkTreeView *)GTK_WIDGET(gtk_builder_get_object (builder,
"matched_view"));
389 matcher->reconciled_chk = (GtkCheckButton *)GTK_WIDGET(gtk_builder_get_object(builder,
"hide_reconciled_check1"));
392 gtk_widget_set_name (GTK_WIDGET(matcher->transaction_matcher),
"gnc-id-import-matcher-picker");
393 gnc_widget_style_context_add_class (GTK_WIDGET(matcher->transaction_matcher),
"gnc-class-imports");
395 gtk_window_set_transient_for (GTK_WINDOW (matcher->transaction_matcher), GTK_WINDOW(parent));
397 gnc_prefs_bind (GNC_PREFS_GROUP, GNC_PREF_DISPLAY_RECONCILED,
nullptr,
398 matcher->reconciled_chk,
"active");
400 gnc_import_match_picker_init_downloaded_view(matcher);
401 gnc_import_match_picker_init_match_view(matcher);
412 g_signal_connect ((GObject *)matcher->reconciled_chk,
"toggled",
413 G_CALLBACK(match_show_reconciled_changed_cb), matcher);
416 g_signal_connect((GObject *)matcher->reconciled_chk,
"toggled", G_CALLBACK(match_show_reconciled_changed_cb), matcher);
418 gnc_restore_window_size(GNC_PREFS_GROUP,
419 GTK_WINDOW (matcher->transaction_matcher), GTK_WINDOW(parent));
420 gtk_widget_show(matcher->transaction_matcher);
422 g_object_unref(G_OBJECT(builder));
433 GNCImportPendingMatches *pending_matches)
435 GNCImportMatchPicker *matcher;
438 gboolean old_selected_manually;
439 g_assert (transaction_info);
443 matcher = g_new0(GNCImportMatchPicker, 1);
445 matcher->pending_matches = pending_matches;
448 init_match_picker_gui(parent, matcher);
451 downloaded_transaction_append(matcher, transaction_info);
454 old_selected_manually =
459 gtk_window_set_modal(GTK_WINDOW(matcher->transaction_matcher), TRUE);
460 response = gtk_dialog_run (GTK_DIALOG (matcher->transaction_matcher));
462 gnc_save_window_size(GNC_PREFS_GROUP,
463 GTK_WINDOW (matcher->transaction_matcher));
464 gtk_widget_destroy (matcher->transaction_matcher);
467 if (response == GTK_RESPONSE_OK && matcher->selected_match_info != old)
471 matcher->selected_match_info,
474 gnc_import_PendingMatches_remove_match (pending_matches,
476 old_selected_manually);
477 gnc_import_PendingMatches_add_match (pending_matches,
478 matcher->selected_match_info,
time64 xaccTransGetDate(const Transaction *trans)
Retrieve the posted date of the transaction.
void gnc_import_TransInfo_set_selected_match_info(GNCImportTransInfo *info, GNCImportMatchInfo *match, gboolean selected_manually)
Sets the currently selected match in this TransInfo.
utility functions for the GnuCash UI
GNCImportSettings * gnc_import_Settings_new(void)
Allocates a new GNCImportSettings object, and initialize it with the appropriate user prefs...
GdkPixbuf * gen_probability_pixbuf(gint score_original, GNCImportSettings *settings, GtkWidget *widget)
This function generates a new pixmap representing a match score.
void gnc_import_Settings_delete(GNCImportSettings *settings)
Destructor.
char xaccSplitGetReconcile(const Split *split)
Returns the value of the reconcile flag.
const char * xaccPrintAmount(gnc_numeric val, GNCPrintAmountInfo info)
Make a string representation of a gnc_numeric.
Split * gnc_import_TransInfo_get_fsplit(const GNCImportTransInfo *info)
Returns the first split of the transaction of this TransInfo.
Transaction * gnc_import_TransInfo_get_trans(const GNCImportTransInfo *info)
Returns the transaction of this TransInfo.
Transaction * xaccSplitGetParent(const Split *split)
Returns the parent transaction of the split.
Split * gnc_import_MatchInfo_get_split(const GNCImportMatchInfo *info)
Get the split ('this-side split') of this MatchInfo.
char * qof_print_date(time64 secs)
Convenience; calls through to qof_print_date_dmy_buff().
gint gnc_import_MatchInfo_get_probability(const GNCImportMatchInfo *info)
Get the probability (confidence level) of this MatchInfo.
The transaction match picker dialog interface.
gnc_numeric xaccTransGetImbalanceValue(const Transaction *trans)
The xaccTransGetImbalanceValue() method returns the total value of the transaction.
const char * xaccTransGetDescription(const Transaction *trans)
Gets the transaction Description.
void gnc_prefs_bind(const gchar *group, const gchar *pref_name, const gchar *pref_value, gpointer object, const gchar *property)
Bind a setting to a g_object property.
#define CREC
The Split has been cleared.
Generic api to store and retrieve preferences.
gboolean gnc_import_TransInfo_get_match_selected_manually(const GNCImportTransInfo *info)
Returns if the currently selected match was selected by the user.
void gnc_import_match_picker_run_and_close(GtkWidget *parent, GNCImportTransInfo *transaction_info, GNCImportPendingMatches *pending_matches)
Run a match_picker dialog so that the selected-MatchInfo in the given trans_info is updated according...
Account * xaccSplitGetAccount(const Split *split)
Returns the account of this split, which was set through xaccAccountInsertSplit().
gnc_commodity * xaccTransGetCurrency(const Transaction *trans)
Returns the valuation commodity of this transaction.
const char * xaccSplitGetMemo(const Split *split)
Returns the memo string.
GList * gnc_import_TransInfo_get_match_list(const GNCImportTransInfo *info)
Returns the stored list of possible matches.
GNCImportMatchInfo * gnc_import_TransInfo_get_selected_match(const GNCImportTransInfo *info)
Returns the currently selected match in this TransInfo.
const char * xaccAccountGetName(const Account *acc)
Get the account's name.
#define NREC
not reconciled or cleared
gnc_numeric xaccSplitGetAmount(const Split *split)
Returns the amount of the split in the account's commodity.