34 #include <glib/gi18n.h> 38 #include "dialog-utils.h" 46 static QofLogModule log_module = GNC_MOD_IMPORT;
48 #define STATE_SECTION "dialogs/import/generic_matcher/account_matcher" 50 #define GNC_PREFS_GROUP "dialogs.import.generic.account-picker" 56 const char* online_id;
69 static gpointer test_acct_online_id_match(
Account *acct, gpointer data)
73 int acct_len, match_len;
75 if (acct_online_id == NULL || match->online_id == NULL)
78 acct_len = strlen(acct_online_id);
79 match_len = strlen(match->online_id);
81 if (acct_online_id[acct_len - 1] ==
' ')
83 if (match->online_id[match_len - 1] ==
' ')
86 if (strncmp (acct_online_id, match->online_id, acct_len) == 0)
88 if (strncmp(acct_online_id, match->online_id, match_len) == 0)
89 return (gpointer *) acct;
90 if (match->partial_match == NULL)
92 match->partial_match = acct;
97 const char *partial_online_id =
99 int partial_len = strlen(partial_online_id);
100 if (partial_online_id[partial_len - 1] ==
' ')
107 if (partial_len < acct_len)
109 match->partial_match = acct;
117 else if (partial_len == acct_len)
119 gchar *name1, *name2;
123 PERR(
"Accounts %s and %s have the same online-id %s",
124 name1, name2, partial_online_id);
143 GtkTreeView *account_tree;
144 GtkTreeViewColumn *col;
149 picker->account_tree = GNC_TREE_VIEW_ACCOUNT(account_tree);
150 gtk_tree_view_set_headers_visible (account_tree, TRUE);
152 g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
156 _(
"Account ID"),
"online-id");
157 g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
162 gtk_container_add(GTK_CONTAINER(picker->account_tree_sw),
163 GTK_WIDGET(picker->account_tree));
167 g_object_set(account_tree,
168 "state-section", STATE_SECTION,
169 "show-column-menu", TRUE,
182 Account *selected_account, *new_account;
183 GList * valid_types = NULL;
184 GtkWindow *parent = NULL;
186 if (picker->dialog != NULL)
187 parent = GTK_WINDOW (picker->dialog);
193 valid_types = g_list_prepend(valid_types, GINT_TO_POINTER(picker->new_account_default_type));
197 picker->account_human_description,
199 picker->new_account_default_commodity,
201 g_list_free(valid_types);
214 gtk_label_set_text (GTK_LABEL(picker->warning), text);
215 gnc_label_set_alignment (picker->warning, 0.0, 0.5);
216 gtk_widget_show_all (GTK_WIDGET(picker->whbox));
219 gtk_widget_set_sensitive (picker->ok_button, FALSE);
231 gchar *text = g_strdup_printf (_(
"The account '%s' is a placeholder account and does not allow " 232 "transactions. Please choose a different account."), name);
234 show_warning (picker, text);
244 account_tree_row_changed_cb (GtkTreeSelection *selection,
250 gtk_widget_hide (GTK_WIDGET(picker->whbox));
251 gtk_widget_set_sensitive (picker->ok_button, (sel_account != NULL));
257 show_placeholder_warning (picker, retval_name);
262 account_tree_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
265 if (event->length == 0)
268 switch (event->keyval)
272 case GDK_KEY_asterisk:
275 case GDK_KEY_KP_Subtract:
276 case GDK_KEY_KP_Multiply:
277 case GDK_KEY_KP_Divide:
281 case GDK_KEY_KP_Down:
283 case GDK_KEY_KP_Home:
286 case GDK_KEY_Page_Up:
287 case GDK_KEY_KP_Page_Up:
288 case GDK_KEY_Page_Down:
289 case GDK_KEY_KP_Page_Down:
292 case GDK_KEY_KP_Right:
293 case GDK_KEY_KP_Left:
295 case GDK_KEY_KP_Space:
296 case GDK_KEY_backslash:
298 case GDK_KEY_ISO_Enter:
299 case GDK_KEY_KP_Enter:
303 gtk_tree_view_expand_all (GTK_TREE_VIEW(user_data));
316 account_tree_row_activated_cb(GtkTreeView *view, GtkTreePath *path,
317 GtkTreeViewColumn *column,
320 gtk_dialog_response(GTK_DIALOG(picker->dialog), GTK_RESPONSE_OK);
330 const gchar * account_online_id_value,
331 gboolean prompt_on_no_match,
332 const gchar * account_human_description,
333 const gnc_commodity * new_account_default_commodity,
336 gboolean * ok_pressed)
338 #define ACCOUNT_DESCRIPTION_MAX_SIZE 255 342 const gchar *retval_name = NULL;
344 GtkTreeSelection *selection;
345 GtkWidget * online_id_label;
346 gchar account_description_text[ACCOUNT_DESCRIPTION_MAX_SIZE + 1] =
"";
347 gboolean ok_pressed_retval = FALSE;
353 picker->account_human_description = account_human_description;
354 picker->new_account_default_commodity = new_account_default_commodity;
355 picker->new_account_default_type = new_account_default_type;
358 if (account_online_id_value)
362 test_acct_online_id_match,
364 if (!retval && match.count == 1 &&
366 retval = match.partial_match;
368 if (!retval && prompt_on_no_match)
371 builder = gtk_builder_new();
372 gnc_builder_add_from_file (builder,
"dialog-import.glade",
"account_new_icon");
373 gnc_builder_add_from_file (builder,
"dialog-import.glade",
"account_picker_dialog");
377 PERR(
"Error opening the glade builder interface");
379 picker->dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"account_picker_dialog"));
380 picker->whbox = GTK_WIDGET(gtk_builder_get_object (builder,
"warning_hbox"));
381 picker->warning = GTK_WIDGET(gtk_builder_get_object (builder,
"warning_label"));
382 picker->ok_button = GTK_WIDGET(gtk_builder_get_object (builder,
"okbutton"));
385 gtk_widget_set_name (GTK_WIDGET(picker->dialog),
"gnc-id-import-account-picker");
386 gnc_widget_style_context_add_class (GTK_WIDGET(picker->dialog),
"gnc-class-imports");
389 gtk_window_set_transient_for (GTK_WINDOW (picker->dialog),
390 GTK_WINDOW (parent));
392 gnc_restore_window_size (GNC_PREFS_GROUP,
393 GTK_WINDOW(picker->dialog), GTK_WINDOW (parent));
395 picker->account_tree_sw = GTK_WIDGET(gtk_builder_get_object (builder,
"account_tree_sw"));
396 online_id_label = GTK_WIDGET(gtk_builder_get_object (builder,
"online_id_label"));
400 if (account_human_description != NULL)
402 strncat(account_description_text, account_human_description,
403 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
404 strncat(account_description_text,
"\n",
405 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
407 if (account_online_id_value != NULL)
409 strncat(account_description_text, _(
"(Full account ID: "),
410 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
411 strncat(account_description_text, account_online_id_value,
412 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
413 strncat(account_description_text,
")",
414 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
416 gtk_label_set_text((GtkLabel*)online_id_label, account_description_text);
417 build_acct_tree(picker);
418 gtk_window_set_modal(GTK_WINDOW(picker->dialog), TRUE);
419 g_signal_connect(picker->account_tree,
"row-activated",
420 G_CALLBACK(account_tree_row_activated_cb), picker);
424 g_signal_connect (picker->account_tree,
"key-press-event", G_CALLBACK (account_tree_key_press_cb), picker->account_tree);
426 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(picker->account_tree));
427 g_signal_connect(selection,
"changed",
428 G_CALLBACK(account_tree_row_changed_cb), picker);
434 response = gtk_dialog_run(GTK_DIALOG(picker->dialog));
437 case GNC_RESPONSE_NEW:
438 gnc_import_add_account(NULL, picker);
439 response = GTK_RESPONSE_OK;
442 case GTK_RESPONSE_OK:
446 response = GNC_RESPONSE_NEW;
450 DEBUG(
"Selected account %p, %s", retval, retval_name ? retval_name :
"(null)");
455 show_placeholder_warning (picker, retval_name);
456 response = GNC_RESPONSE_NEW;
460 if (account_online_id_value)
464 ok_pressed_retval = TRUE;
468 ok_pressed_retval = FALSE;
472 while (response == GNC_RESPONSE_NEW);
474 g_object_unref(G_OBJECT(builder));
475 gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(picker->dialog));
476 gtk_widget_destroy(picker->dialog);
481 ok_pressed_retval = TRUE;
486 if (ok_pressed != NULL)
488 *ok_pressed = ok_pressed_retval;
490 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...
const char * xaccAccountGetOnlineID(const Account *acc)
Get the account's online_id (see xaccAccountSetOnlineID).
#define DEBUG(format, args...)
Print a debugging message.
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...
void xaccAccountSetOnlineID(Account *acc, const char *id)
Set the account's online_id, the identifier (e.g.
Account * gnc_import_select_account(GtkWidget *parent, const gchar *account_online_id_value, gboolean prompt_on_no_match, 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.
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...
#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.