32 #include <glib/gi18n.h> 40 #include "dialog-utils.h" 47 #define GNC_PREFS_GROUP "dialogs.import.generic.match-picker" 48 #define GNC_PREF_DISPLAY_RECONCILED "display-reconciled" 52 DOWNLOADED_COL_ACCOUNT = 0,
54 DOWNLOADED_COL_AMOUNT,
55 DOWNLOADED_COL_DESCRIPTION,
57 DOWNLOADED_COL_BALANCED,
58 DOWNLOADED_COL_INFO_PTR,
64 MATCHER_COL_CONFIDENCE = 0,
65 MATCHER_COL_CONFIDENCE_PIXBUF,
68 MATCHER_COL_DESCRIPTION,
70 MATCHER_COL_RECONCILED,
83 static const int SHOW_NUMERIC_SCORE = FALSE;
91 GtkWidget * transaction_matcher;
92 GtkTreeView * downloaded_view;
93 GtkTreeView * match_view;
94 GtkCheckButton * reconciled_chk;
95 GNCImportSettings * user_settings;
98 GNCImportPendingMatches * pending_matches;
104 downloaded_transaction_append(GNCImportMatchPicker * matcher,
105 GNCImportTransInfo * transaction_info)
109 GtkTreeSelection *selection;
113 const gchar *ro_text;
114 gboolean found = FALSE;
115 GNCImportTransInfo *local_info;
118 g_assert(transaction_info);
123 store = GTK_LIST_STORE(gtk_tree_view_get_model(matcher->downloaded_view));
124 if (gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter))
128 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter,
129 DOWNLOADED_COL_INFO_PTR, &local_info,
131 if (local_info == transaction_info)
137 while (gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter));
140 gtk_list_store_append(store, &iter);
147 gtk_list_store_set(store, &iter, DOWNLOADED_COL_ACCOUNT, ro_text, -1);
151 gtk_list_store_set(store, &iter, DOWNLOADED_COL_DATE, text, -1);
156 gnc_split_amount_print_info(split, TRUE));
157 gtk_list_store_set(store, &iter, DOWNLOADED_COL_AMOUNT, ro_text, -1);
161 gtk_list_store_set(store, &iter, DOWNLOADED_COL_DESCRIPTION, ro_text, -1);
165 gtk_list_store_set(store, &iter, DOWNLOADED_COL_MEMO, ro_text, -1);
173 gtk_list_store_set(store, &iter, DOWNLOADED_COL_BALANCED, ro_text, -1);
175 gtk_list_store_set(store, &iter, DOWNLOADED_COL_INFO_PTR,
176 transaction_info, -1);
178 selection = gtk_tree_view_get_selection(matcher->downloaded_view);
179 gtk_tree_selection_select_iter(selection, &iter);
183 match_update_match_model (GNCImportMatchPicker *matcher)
187 gboolean show_reconciled;
189 GtkListStore *match_store;
190 GList * list_element;
192 const gchar *ro_text;
193 GNCImportPendingMatchType pending_match_type;
195 show_reconciled = gtk_toggle_button_get_active
196 (GTK_TOGGLE_BUTTON(matcher->reconciled_chk));
199 match_store = GTK_LIST_STORE(gtk_tree_view_get_model(matcher->match_view));
200 gtk_list_store_clear(match_store);
202 (matcher->selected_trans_info));
203 while (list_element != NULL)
205 match_info = list_element->data;
210 if (show_reconciled == FALSE && reconciled !=
NREC)
212 list_element = g_list_next (list_element);
216 gtk_list_store_append(match_store, &iter);
222 gtk_list_store_set(match_store, &iter, MATCHER_COL_CONFIDENCE, text, -1);
231 gtk_list_store_set(match_store, &iter, MATCHER_COL_DATE, text, -1);
239 gtk_list_store_set(match_store, &iter, MATCHER_COL_AMOUNT, ro_text, -1);
244 gtk_list_store_set(match_store, &iter, MATCHER_COL_DESCRIPTION, ro_text, -1);
248 gtk_list_store_set(match_store, &iter, MATCHER_COL_MEMO, ro_text, -1);
251 ro_text = gnc_get_reconcile_str (reconciled);
252 gtk_list_store_set (match_store, &iter, MATCHER_COL_RECONCILED, ro_text,
256 pending_match_type = gnc_import_PendingMatches_get_match_type
257 (matcher->pending_matches, match_info);
260 if (pending_match_type == GNCImportPending_MANUAL ||
261 pending_match_type == GNCImportPending_AUTO)
263 ro_text = gnc_get_reconcile_str (
CREC);
264 text = g_strdup_printf(
"%s (%s)",
266 gnc_import_PendingMatches_get_type_str
267 (pending_match_type));
269 gtk_list_store_set (match_store, &iter, MATCHER_COL_PENDING, text, -1);
273 gtk_list_store_set(match_store, &iter, MATCHER_COL_INFO_PTR, match_info, -1);
276 gtk_list_store_set(match_store, &iter,
277 MATCHER_COL_CONFIDENCE_PIXBUF,
279 matcher->user_settings,
280 GTK_WIDGET(matcher->match_view)),
287 GtkTreeSelection *selection;
289 selection = gtk_tree_view_get_selection(matcher->match_view);
290 gtk_tree_selection_select_iter(selection, &iter);
293 list_element = g_list_next(list_element);
304 downloaded_transaction_changed_cb (GtkTreeSelection *selection,
305 GNCImportMatchPicker *matcher)
307 GtkTreeModel *dl_model;
312 if (!gtk_tree_selection_get_selected(selection, &dl_model, &iter))
314 matcher->selected_trans_info = NULL;
317 gtk_tree_model_get(dl_model, &iter,
318 DOWNLOADED_COL_INFO_PTR, &matcher->selected_trans_info,
321 match_update_match_model (matcher);
325 match_show_reconciled_changed_cb (GtkCheckButton* checkbox,
326 GNCImportMatchPicker *matcher)
328 match_update_match_model (matcher);
332 match_transaction_changed_cb (GtkTreeSelection *selection,
333 GNCImportMatchPicker *matcher)
338 if (!gtk_tree_selection_get_selected (selection, &model, &iter))
340 matcher->selected_match_info = NULL;
344 gtk_tree_model_get(model, &iter,
345 MATCHER_COL_INFO_PTR, &matcher->selected_match_info,
350 match_transaction_row_activated_cb (GtkTreeView *view, GtkTreePath *path,
351 GtkTreeViewColumn *column,
352 GNCImportMatchPicker *matcher)
354 g_return_if_fail (matcher && matcher->transaction_matcher);
356 gtk_dialog_response (GTK_DIALOG (matcher->transaction_matcher),
361 add_column(GtkTreeView *view,
const gchar *title,
int col_num)
363 GtkCellRenderer *renderer;
364 GtkTreeViewColumn *column;
366 renderer = gtk_cell_renderer_text_new();
367 column = gtk_tree_view_column_new_with_attributes(title, renderer,
370 gtk_tree_view_append_column(view, column);
371 g_object_set(G_OBJECT(column),
378 gnc_import_match_picker_init_downloaded_view (GNCImportMatchPicker * matcher)
382 GtkTreeSelection *selection;
384 view = matcher->downloaded_view;
385 store = gtk_list_store_new(NUM_DOWNLOADED_COLS,
386 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
387 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
389 gtk_tree_view_set_model(view, GTK_TREE_MODEL(store));
390 g_object_unref(store);
392 add_column(view, _(
"Account"), DOWNLOADED_COL_ACCOUNT);
393 add_column(view, _(
"Date"), DOWNLOADED_COL_DATE);
394 add_column(view, _(
"Amount"), DOWNLOADED_COL_AMOUNT);
395 add_column(view, _(
"Description"), DOWNLOADED_COL_DESCRIPTION);
396 add_column(view, _(
"Memo"), DOWNLOADED_COL_MEMO);
397 add_column(view, _(
"Balanced"), DOWNLOADED_COL_BALANCED);
399 selection = gtk_tree_view_get_selection(view);
400 g_signal_connect(selection,
"changed",
401 G_CALLBACK(downloaded_transaction_changed_cb), matcher);
405 gnc_import_match_picker_init_match_view (GNCImportMatchPicker * matcher)
409 GtkCellRenderer *renderer;
410 GtkTreeViewColumn *column;
411 GtkTreeSelection *selection;
413 view = matcher->match_view;
414 store = gtk_list_store_new(NUM_MATCHER_COLS,
415 G_TYPE_STRING, GDK_TYPE_PIXBUF, G_TYPE_STRING,
416 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
417 G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER);
418 gtk_tree_view_set_model(view, GTK_TREE_MODEL(store));
419 g_object_unref(store);
421 renderer = gtk_cell_renderer_pixbuf_new();
422 g_object_set(renderer,
"xalign", 0.0, NULL);
423 column = gtk_tree_view_column_new_with_attributes(_(
"Confidence"), renderer,
424 "pixbuf", MATCHER_COL_CONFIDENCE_PIXBUF,
426 renderer = gtk_cell_renderer_text_new();
427 gtk_tree_view_column_pack_start(column, renderer, TRUE);
428 gtk_tree_view_column_set_attributes(column, renderer,
429 "text", MATCHER_COL_CONFIDENCE,
431 gtk_tree_view_append_column(view, column);
433 add_column(view, _(
"Date"), MATCHER_COL_DATE);
434 add_column(view, _(
"Amount"), MATCHER_COL_AMOUNT);
435 add_column(view, _(
"Description"), MATCHER_COL_DESCRIPTION);
436 add_column(view, _(
"Memo"), MATCHER_COL_MEMO);
437 add_column(view, _(
"Reconciled"), MATCHER_COL_RECONCILED);
438 add_column(view, _(
"Pending Action"), MATCHER_COL_PENDING);
440 selection = gtk_tree_view_get_selection(view);
441 g_signal_connect(selection,
"changed",
442 G_CALLBACK(match_transaction_changed_cb), matcher);
443 g_signal_connect(view,
"row-activated",
444 G_CALLBACK(match_transaction_row_activated_cb), matcher);
452 init_match_picker_gui(GtkWidget *parent, GNCImportMatchPicker * matcher)
462 builder = gtk_builder_new();
463 gnc_builder_add_from_file (builder,
"dialog-import.glade",
"match_picker_dialog");
464 g_return_if_fail (builder != NULL);
466 matcher->transaction_matcher = GTK_WIDGET(gtk_builder_get_object (builder,
"match_picker_dialog"));
467 matcher->downloaded_view = (GtkTreeView *)GTK_WIDGET(gtk_builder_get_object (builder,
"download_view"));
468 matcher->match_view = (GtkTreeView *)GTK_WIDGET(gtk_builder_get_object (builder,
"matched_view"));
469 matcher->reconciled_chk = (GtkCheckButton *)GTK_WIDGET(gtk_builder_get_object(builder,
"hide_reconciled_check1"));
471 gtk_window_set_transient_for (GTK_WINDOW (matcher->transaction_matcher), GTK_WINDOW(parent));
474 matcher->reconciled_chk,
"active");
476 gnc_import_match_picker_init_downloaded_view(matcher);
477 gnc_import_match_picker_init_match_view(matcher);
488 g_signal_connect ((GObject *)matcher->reconciled_chk,
"toggled",
489 G_CALLBACK(match_show_reconciled_changed_cb), matcher);
492 g_signal_connect((GObject *)matcher->reconciled_chk,
"toggled", G_CALLBACK(match_show_reconciled_changed_cb), matcher);
494 gnc_restore_window_size(GNC_PREFS_GROUP,
495 GTK_WINDOW (matcher->transaction_matcher), GTK_WINDOW(parent));
496 gtk_widget_show(matcher->transaction_matcher);
498 g_object_unref(G_OBJECT(builder));
509 GNCImportPendingMatches *pending_matches)
511 GNCImportMatchPicker *matcher;
514 gboolean old_selected_manually;
515 g_assert (transaction_info);
519 matcher = g_new0(GNCImportMatchPicker, 1);
521 matcher->pending_matches = pending_matches;
524 init_match_picker_gui(parent, matcher);
527 downloaded_transaction_append(matcher, transaction_info);
530 old_selected_manually =
535 gtk_window_set_modal(GTK_WINDOW(matcher->transaction_matcher), TRUE);
536 response = gtk_dialog_run (GTK_DIALOG (matcher->transaction_matcher));
538 gnc_save_window_size(GNC_PREFS_GROUP,
539 GTK_WINDOW (matcher->transaction_matcher));
540 gtk_widget_destroy (matcher->transaction_matcher);
543 if (response == GTK_RESPONSE_OK && matcher->selected_match_info != old)
547 matcher->selected_match_info,
550 gnc_import_PendingMatches_remove_match (pending_matches,
552 old_selected_manually);
553 gnc_import_PendingMatches_add_match (pending_matches,
554 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.
Tracking container for pending match status.
Generic importer backend interface.
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.
void gnc_prefs_bind(const gchar *group, const gchar *pref_name, gpointer object, const gchar *property)
Bind a setting to a g_object property.
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.
#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.