34 #include <glib/gi18n.h> 39 #include "dialog-utils.h" 47 static QofLogModule log_module = GNC_MOD_IMPORT;
49 #define STATE_SECTION "dialogs/import/generic_matcher/account_matcher" 51 #define GNC_PREFS_GROUP "dialogs.import.generic.account-picker" 57 const char* online_id;
63 if (match->partial_match && match->count == 1)
64 return match->partial_match;
66 PERR(
"Online ID %s partially matches %d accounts and fully matches none",
67 match->online_id, match->count);
81 picker->dialog = NULL;
82 picker->account_tree = NULL;
83 picker->account_tree_sw = NULL;
84 picker->auto_create = TRUE;
85 picker->account_human_description = NULL;
86 picker->account_online_id_value = NULL;
87 picker->account_online_id_label = NULL;
88 picker->new_account_default_commodity = NULL;
89 picker->new_account_default_type = 0;
90 picker->default_account = NULL;
91 picker->retAccount = NULL;
101 static gpointer test_acct_online_id_match(
Account *acct, gpointer data)
104 const char *acct_online_id = gnc_import_get_acc_online_id(acct);
105 int acct_len, match_len;
107 if (acct_online_id == NULL || match->online_id == NULL)
110 acct_len = strlen(acct_online_id);
111 match_len = strlen(match->online_id);
113 if (acct_online_id[acct_len - 1] ==
' ')
115 if (match->online_id[match_len - 1] ==
' ')
118 if (strncmp (acct_online_id, match->online_id, acct_len) == 0)
120 if (strncmp(acct_online_id, match->online_id, match_len) == 0)
121 return (gpointer *) acct;
122 if (match->partial_match == NULL)
124 match->partial_match = acct;
129 const char *partial_online_id =
130 gnc_import_get_acc_online_id(match->partial_match);
131 int partial_len = strlen(partial_online_id);
132 if (partial_online_id[partial_len - 1] ==
' ')
139 if (partial_len < acct_len)
141 match->partial_match = acct;
149 else if (partial_len == acct_len)
151 gchar *name1, *name2;
155 PERR(
"Accounts %s and %s have the same online-id %s",
156 name1, name2, partial_online_id);
175 GtkTreeView *account_tree;
176 GtkTreeViewColumn *col;
181 picker->account_tree = GNC_TREE_VIEW_ACCOUNT(account_tree);
182 gtk_tree_view_set_headers_visible (account_tree, TRUE);
184 g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
188 _(
"Account ID"),
"online-id");
189 g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
194 gtk_container_add(GTK_CONTAINER(picker->account_tree_sw),
195 GTK_WIDGET(picker->account_tree));
199 g_object_set(account_tree,
200 "state-section", STATE_SECTION,
201 "show-column-menu", TRUE,
214 Account *selected_account, *new_account;
215 GList * valid_types = NULL;
216 GtkWindow *parent = NULL;
218 if (picker->dialog != NULL)
219 parent = GTK_WINDOW (picker->dialog);
225 valid_types = g_list_prepend(valid_types, GINT_TO_POINTER(picker->new_account_default_type));
229 picker->account_human_description,
231 picker->new_account_default_commodity,
233 g_list_free(valid_types);
246 gtk_label_set_text (GTK_LABEL(picker->warning), text);
247 gnc_label_set_alignment (picker->warning, 0.0, 0.5);
248 gtk_widget_show_all (GTK_WIDGET(picker->whbox));
251 gtk_widget_set_sensitive (picker->ok_button, FALSE);
263 gchar *text = g_strdup_printf (_(
"The account '%s' is a placeholder account and does not allow " 264 "transactions. Please choose a different account."), name);
266 show_warning (picker, text);
280 gchar *text = g_strdup_printf (_(
"The account '%s' has a different commodity to the " 281 "one required, '%s'. Please choose a different account."),
284 show_warning (picker, text);
294 account_tree_row_changed_cb (GtkTreeSelection *selection,
301 gtk_widget_hide (GTK_WIDGET(picker->whbox));
302 gtk_widget_set_sensitive (picker->ok_button, FALSE);
306 gtk_widget_set_sensitive (picker->ok_button, TRUE);
313 show_placeholder_warning (picker, retval_name);
315 else if (picker->new_account_default_commodity &&
317 picker->new_account_default_commodity)))
320 show_commodity_warning (picker, retval_name);
323 gtk_widget_hide (GTK_WIDGET(picker->whbox));
327 account_tree_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
330 if (event->length == 0)
333 switch (event->keyval)
337 case GDK_KEY_asterisk:
340 case GDK_KEY_KP_Subtract:
341 case GDK_KEY_KP_Multiply:
342 case GDK_KEY_KP_Divide:
346 case GDK_KEY_KP_Down:
348 case GDK_KEY_KP_Home:
351 case GDK_KEY_Page_Up:
352 case GDK_KEY_KP_Page_Up:
353 case GDK_KEY_Page_Down:
354 case GDK_KEY_KP_Page_Down:
357 case GDK_KEY_KP_Right:
358 case GDK_KEY_KP_Left:
360 case GDK_KEY_KP_Space:
361 case GDK_KEY_backslash:
363 case GDK_KEY_ISO_Enter:
364 case GDK_KEY_KP_Enter:
368 gtk_tree_view_expand_all (GTK_TREE_VIEW(user_data));
381 account_tree_row_activated_cb(GtkTreeView *view, GtkTreePath *path,
382 GtkTreeViewColumn *column,
385 gtk_dialog_response(GTK_DIALOG(picker->dialog), GTK_RESPONSE_OK);
395 const gchar * account_online_id_value,
396 gboolean auto_create,
397 const gchar * account_human_description,
398 const gnc_commodity * new_account_default_commodity,
401 gboolean * ok_pressed)
403 #define ACCOUNT_DESCRIPTION_MAX_SIZE 255 407 const gchar *retval_name = NULL;
409 GtkTreeSelection *selection;
410 GtkWidget * online_id_label;
411 gchar account_description_text[ACCOUNT_DESCRIPTION_MAX_SIZE + 1] =
"";
412 gboolean ok_pressed_retval = FALSE;
418 picker->account_online_id_value = account_online_id_value;
419 picker->account_human_description = account_human_description;
420 picker->new_account_default_commodity = new_account_default_commodity;
421 picker->new_account_default_type = new_account_default_type;
424 if (account_online_id_value != NULL)
429 test_acct_online_id_match,
431 if (!retval && match.count == 1 &&
433 retval = match.partial_match;
435 if (retval == NULL && auto_create != 0)
438 builder = gtk_builder_new();
439 gnc_builder_add_from_file (builder,
"dialog-import.glade",
"account_new_icon");
440 gnc_builder_add_from_file (builder,
"dialog-import.glade",
"account_picker_dialog");
444 PERR(
"Error opening the glade builder interface");
446 picker->dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"account_picker_dialog"));
447 picker->whbox = GTK_WIDGET(gtk_builder_get_object (builder,
"warning_hbox"));
448 picker->warning = GTK_WIDGET(gtk_builder_get_object (builder,
"warning_label"));
449 picker->ok_button = GTK_WIDGET(gtk_builder_get_object (builder,
"okbutton"));
452 gtk_window_set_transient_for (GTK_WINDOW (picker->dialog),
453 GTK_WINDOW (parent));
455 gnc_restore_window_size (GNC_PREFS_GROUP,
456 GTK_WINDOW(picker->dialog), GTK_WINDOW (parent));
458 picker->account_tree_sw = GTK_WIDGET(gtk_builder_get_object (builder,
"account_tree_sw"));
459 online_id_label = GTK_WIDGET(gtk_builder_get_object (builder,
"online_id_label"));
463 if (account_human_description != NULL)
465 strncat(account_description_text, account_human_description,
466 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
467 strncat(account_description_text,
"\n",
468 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
470 if (account_online_id_value != NULL)
472 strncat(account_description_text, _(
"(Full account ID: "),
473 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
474 strncat(account_description_text, account_online_id_value,
475 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
476 strncat(account_description_text,
")",
477 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
479 gtk_label_set_text((GtkLabel*)online_id_label, account_description_text);
480 build_acct_tree(picker);
481 gtk_window_set_modal(GTK_WINDOW(picker->dialog), TRUE);
482 g_signal_connect(picker->account_tree,
"row-activated",
483 G_CALLBACK(account_tree_row_activated_cb), picker);
487 g_signal_connect (picker->account_tree,
"key-press-event", G_CALLBACK (account_tree_key_press_cb), picker->account_tree);
489 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(picker->account_tree));
490 g_signal_connect(selection,
"changed",
491 G_CALLBACK(account_tree_row_changed_cb), picker);
497 response = gtk_dialog_run(GTK_DIALOG(picker->dialog));
500 case GNC_RESPONSE_NEW:
501 gnc_import_add_account(NULL, picker);
502 response = GTK_RESPONSE_OK;
505 case GTK_RESPONSE_OK:
509 response = GNC_RESPONSE_NEW;
515 retval_name =
"(null)";
516 DEBUG(
"Selected account %p, %s", retval, retval_name);
521 show_placeholder_warning (picker, retval_name);
522 response = GNC_RESPONSE_NEW;
525 else if (picker->new_account_default_commodity &&
527 picker->new_account_default_commodity)))
529 show_commodity_warning (picker, retval_name);
530 response = GNC_RESPONSE_NEW;
534 if ( account_online_id_value != NULL)
536 gnc_import_set_acc_online_id(retval, account_online_id_value);
538 ok_pressed_retval = TRUE;
542 ok_pressed_retval = FALSE;
546 while (response == GNC_RESPONSE_NEW);
548 g_object_unref(G_OBJECT(builder));
549 gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(picker->dialog));
550 gtk_widget_destroy(picker->dialog);
555 ok_pressed_retval = TRUE;
560 if (ok_pressed != NULL)
562 *ok_pressed = ok_pressed_retval;
564 LEAVE(
"Selected account %p, %s", retval, retval_name ? retval_name :
"(null)");
GtkTreeViewColumn * gnc_tree_view_account_add_property_column(GncTreeViewAccount *view, const gchar *column_title, const gchar *propname)
Add a new column to the set of columns in an account tree view.
This file contains the functions to present a gui to the user for creating a new account or editing a...
#define DEBUG(format, args...)
Print a debugging message.
gboolean gnc_commodity_equal(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equal.
gpointer gnc_account_foreach_descendant_until(const Account *acc, AccountCb2 thunk, gpointer user_data)
This method will traverse all children of this accounts and their descendants, calling 'func' on each...
Account * gnc_import_select_account(GtkWidget *parent, const gchar *account_online_id_value, gboolean auto_create, const gchar *account_human_description, const gnc_commodity *new_account_default_commodity, GNCAccountType new_account_default_type, Account *default_selection, gboolean *ok_pressed)
Must be called with a string containing a unique identifier for the account.
Generic and very flexible account matcher/picker.
#define PERR(format, args...)
Log a serious error.
GtkTreeViewColumn * gnc_tree_view_find_column_by_name(GncTreeView *view, const gchar *wanted)
Find a tree column given the "pref name" used with saved state.
#define ENTER(format, args...)
Print a function entry debugging message.
gchar * gnc_account_get_full_name(const Account *account)
The gnc_account_get_full_name routine returns the fully qualified name of the account using the given...
GtkTreeView implementation for gnucash account tree.
GtkTreeView * gnc_tree_view_account_new(gboolean show_root)
Create a new account tree view.
void gnc_tree_view_configure_columns(GncTreeView *view)
Make all the correct columns visible, respecting their default visibility setting, their "always" visibility setting, and the last saved state if available.
const char * gnc_commodity_get_fullname(const gnc_commodity *cm)
Retrieve the full name for the specified commodity.
All type declarations for the whole Gnucash engine.
GNCAccountType
The account types are used to determine how the transaction data in the account is displayed...
Generic api to store and retrieve preferences.
void gnc_tree_view_account_set_selected_account(GncTreeViewAccount *view, Account *account)
This function selects an account in the account tree view.
Account * gnc_ui_new_accounts_from_name_with_defaults(GtkWindow *parent, const char *name, GList *valid_types, const gnc_commodity *default_commodity, Account *parent_acct)
Display a modal window for creating a new account.
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity.
gboolean xaccAccountGetPlaceholder(const Account *acc)
Get the "placeholder" flag for an account.
Account * gnc_tree_view_account_get_selected_account(GncTreeViewAccount *view)
This function returns the account associated with the selected item in the account tree view...
Utility functions for writing import modules.
#define LEAVE(format, args...)
Print a function exit debugging message.
const char * xaccAccountGetName(const Account *acc)
Get the account's name.
const char * xaccAccountGetTypeStr(GNCAccountType type)
The xaccAccountGetTypeStr() routine returns a string suitable for use in the GUI/Interface.
Commodity handling public routines.