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;
70 static gpointer test_acct_online_id_match(
Account *acct, gpointer data)
73 char *acct_online_id = gnc_import_get_acc_online_id(acct);
74 int acct_len, match_len;
76 if (acct_online_id == NULL || match->online_id == NULL)
79 g_free (acct_online_id);
83 acct_len = strlen(acct_online_id);
84 match_len = strlen(match->online_id);
86 if (acct_online_id[acct_len - 1] ==
' ')
88 if (match->online_id[match_len - 1] ==
' ')
91 if (strncmp (acct_online_id, match->online_id, acct_len) == 0)
93 if (strncmp(acct_online_id, match->online_id, match_len) == 0)
95 g_free (acct_online_id);
96 return (gpointer *) acct;
98 if (match->partial_match == NULL)
100 match->partial_match = acct;
105 char *partial_online_id =
106 gnc_import_get_acc_online_id(match->partial_match);
107 int partial_len = strlen(partial_online_id);
108 if (partial_online_id[partial_len - 1] ==
' ')
115 if (partial_len < acct_len)
117 match->partial_match = acct;
125 else if (partial_len == acct_len)
127 gchar *name1, *name2;
131 PERR(
"Accounts %s and %s have the same online-id %s",
132 name1, name2, partial_online_id);
136 g_free (partial_online_id);
140 g_free (acct_online_id);
153 GtkTreeView *account_tree;
154 GtkTreeViewColumn *col;
159 picker->account_tree = GNC_TREE_VIEW_ACCOUNT(account_tree);
160 gtk_tree_view_set_headers_visible (account_tree, TRUE);
162 g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
166 _(
"Account ID"),
"online-id");
167 g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
172 gtk_container_add(GTK_CONTAINER(picker->account_tree_sw),
173 GTK_WIDGET(picker->account_tree));
177 g_object_set(account_tree,
178 "state-section", STATE_SECTION,
179 "show-column-menu", TRUE,
192 Account *selected_account, *new_account;
193 GList * valid_types = NULL;
194 GtkWindow *parent = NULL;
196 if (picker->dialog != NULL)
197 parent = GTK_WINDOW (picker->dialog);
203 valid_types = g_list_prepend(valid_types, GINT_TO_POINTER(picker->new_account_default_type));
207 picker->account_human_description,
209 picker->new_account_default_commodity,
211 g_list_free(valid_types);
224 gtk_label_set_text (GTK_LABEL(picker->warning), text);
225 gnc_label_set_alignment (picker->warning, 0.0, 0.5);
226 gtk_widget_show_all (GTK_WIDGET(picker->whbox));
229 gtk_widget_set_sensitive (picker->ok_button, FALSE);
241 gchar *text = g_strdup_printf (_(
"The account '%s' is a placeholder account and does not allow " 242 "transactions. Please choose a different account."), name);
244 show_warning (picker, text);
254 account_tree_row_changed_cb (GtkTreeSelection *selection,
260 gtk_widget_hide (GTK_WIDGET(picker->whbox));
261 gtk_widget_set_sensitive (picker->ok_button, (sel_account != NULL));
267 show_placeholder_warning (picker, retval_name);
272 account_tree_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer user_data)
275 if (event->length == 0)
278 switch (event->keyval)
282 case GDK_KEY_asterisk:
285 case GDK_KEY_KP_Subtract:
286 case GDK_KEY_KP_Multiply:
287 case GDK_KEY_KP_Divide:
291 case GDK_KEY_KP_Down:
293 case GDK_KEY_KP_Home:
296 case GDK_KEY_Page_Up:
297 case GDK_KEY_KP_Page_Up:
298 case GDK_KEY_Page_Down:
299 case GDK_KEY_KP_Page_Down:
302 case GDK_KEY_KP_Right:
303 case GDK_KEY_KP_Left:
305 case GDK_KEY_KP_Space:
306 case GDK_KEY_backslash:
308 case GDK_KEY_ISO_Enter:
309 case GDK_KEY_KP_Enter:
313 gtk_tree_view_expand_all (GTK_TREE_VIEW(user_data));
326 account_tree_row_activated_cb(GtkTreeView *view, GtkTreePath *path,
327 GtkTreeViewColumn *column,
330 gtk_dialog_response(GTK_DIALOG(picker->dialog), GTK_RESPONSE_OK);
340 const gchar * account_online_id_value,
341 gboolean prompt_on_no_match,
342 const gchar * account_human_description,
343 const gnc_commodity * new_account_default_commodity,
346 gboolean * ok_pressed)
348 #define ACCOUNT_DESCRIPTION_MAX_SIZE 255 352 const gchar *retval_name = NULL;
354 GtkTreeSelection *selection;
355 GtkWidget * online_id_label;
356 gchar account_description_text[ACCOUNT_DESCRIPTION_MAX_SIZE + 1] =
"";
357 gboolean ok_pressed_retval = FALSE;
363 picker->account_human_description = account_human_description;
364 picker->new_account_default_commodity = new_account_default_commodity;
365 picker->new_account_default_type = new_account_default_type;
368 if (account_online_id_value)
372 test_acct_online_id_match,
374 if (!retval && match.count == 1 &&
376 retval = match.partial_match;
378 if (!retval && prompt_on_no_match)
381 builder = gtk_builder_new();
382 gnc_builder_add_from_file (builder,
"dialog-import.glade",
"account_new_icon");
383 gnc_builder_add_from_file (builder,
"dialog-import.glade",
"account_picker_dialog");
387 PERR(
"Error opening the glade builder interface");
389 picker->dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"account_picker_dialog"));
390 picker->whbox = GTK_WIDGET(gtk_builder_get_object (builder,
"warning_hbox"));
391 picker->warning = GTK_WIDGET(gtk_builder_get_object (builder,
"warning_label"));
392 picker->ok_button = GTK_WIDGET(gtk_builder_get_object (builder,
"okbutton"));
395 gtk_widget_set_name (GTK_WIDGET(picker->dialog),
"gnc-id-import-account-picker");
396 gnc_widget_style_context_add_class (GTK_WIDGET(picker->dialog),
"gnc-class-imports");
399 gtk_window_set_transient_for (GTK_WINDOW (picker->dialog),
400 GTK_WINDOW (parent));
402 gnc_restore_window_size (GNC_PREFS_GROUP,
403 GTK_WINDOW(picker->dialog), GTK_WINDOW (parent));
405 picker->account_tree_sw = GTK_WIDGET(gtk_builder_get_object (builder,
"account_tree_sw"));
406 online_id_label = GTK_WIDGET(gtk_builder_get_object (builder,
"online_id_label"));
410 if (account_human_description != NULL)
412 strncat(account_description_text, account_human_description,
413 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
414 strncat(account_description_text,
"\n",
415 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
417 if (account_online_id_value != NULL)
419 strncat(account_description_text, _(
"(Full account ID: "),
420 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
421 strncat(account_description_text, account_online_id_value,
422 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
423 strncat(account_description_text,
")",
424 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
426 gtk_label_set_text((GtkLabel*)online_id_label, account_description_text);
427 build_acct_tree(picker);
428 gtk_window_set_modal(GTK_WINDOW(picker->dialog), TRUE);
429 g_signal_connect(picker->account_tree,
"row-activated",
430 G_CALLBACK(account_tree_row_activated_cb), picker);
434 g_signal_connect (picker->account_tree,
"key-press-event", G_CALLBACK (account_tree_key_press_cb), picker->account_tree);
436 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(picker->account_tree));
437 g_signal_connect(selection,
"changed",
438 G_CALLBACK(account_tree_row_changed_cb), picker);
444 response = gtk_dialog_run(GTK_DIALOG(picker->dialog));
447 case GNC_RESPONSE_NEW:
448 gnc_import_add_account(NULL, picker);
449 response = GTK_RESPONSE_OK;
452 case GTK_RESPONSE_OK:
456 response = GNC_RESPONSE_NEW;
460 DEBUG(
"Selected account %p, %s", retval, retval_name ? retval_name :
"(null)");
465 show_placeholder_warning (picker, retval_name);
466 response = GNC_RESPONSE_NEW;
470 if (account_online_id_value)
472 gnc_import_set_acc_online_id(retval, account_online_id_value);
474 ok_pressed_retval = TRUE;
478 ok_pressed_retval = FALSE;
482 while (response == GNC_RESPONSE_NEW);
484 g_object_unref(G_OBJECT(builder));
485 gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(picker->dialog));
486 gtk_widget_destroy(picker->dialog);
491 ok_pressed_retval = TRUE;
496 if (ok_pressed != NULL)
498 *ok_pressed = ok_pressed_retval;
500 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.
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 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...
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.