34 #include <glib/gi18n.h>
39 #include "dialog-utils.h"
48 #define STATE_SECTION "dialogs/import/generic_matcher/account_matcher"
60 picker->dialog = NULL;
61 picker->assistant = NULL;
62 picker->account_tree = NULL;
63 picker->account_tree_sw = NULL;
64 picker->auto_create = TRUE;
65 picker->account_human_description = NULL;
66 picker->account_online_id_value = NULL;
67 picker->account_online_id_label = NULL;
68 picker->new_account_default_commodity = NULL;
69 picker->new_account_default_type = 0;
70 picker->default_account = NULL;
71 picker->retAccount = NULL;
81 static gpointer test_acct_online_id_match(
Account *acct, gpointer param_online_id)
83 const gchar * current_online_id = gnc_import_get_acc_online_id(acct);
84 if ( (current_online_id != NULL
85 && param_online_id != NULL )
86 && strcmp( current_online_id, param_online_id ) == 0 )
88 return (gpointer *) acct;
105 GtkTreeView *account_tree;
106 GtkTreeViewColumn *col;
111 picker->account_tree = GNC_TREE_VIEW_ACCOUNT(account_tree);
112 gtk_tree_view_set_headers_visible (account_tree, TRUE);
114 g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
118 _(
"Account ID"),
"online-id");
119 g_object_set_data(G_OBJECT(col), DEFAULT_VISIBLE, GINT_TO_POINTER(1));
121 gtk_container_add(GTK_CONTAINER(picker->account_tree_sw),
122 GTK_WIDGET(picker->account_tree));
126 g_object_set(account_tree,
127 "state-section", STATE_SECTION,
128 "show-column-menu", TRUE,
141 Account *selected_account, *new_account;
142 GList * valid_types = NULL;
147 valid_types = g_list_prepend(valid_types, GINT_TO_POINTER(picker->new_account_default_type));
152 picker->new_account_default_commodity,
154 g_list_free(valid_types);
165 account_tree_row_activated_cb(GtkTreeView *view, GtkTreePath *path,
166 GtkTreeViewColumn *column,
169 const gchar *retval_name = NULL;
173 if (picker->dialog == NULL)
175 GtkAssistant *assistant = GTK_ASSISTANT(picker->assistant);
176 gint num = gtk_assistant_get_current_page (assistant);
177 GtkWidget *page = gtk_assistant_get_nth_page (assistant, num);
180 if (picker->retAccount)
183 retval_name =
"(null)";
184 DEBUG(
"Selected account %p, %s", picker->retAccount, retval_name);
189 gnc_error_dialog (picker->dialog,
190 _(
"The account %s is a placeholder account and does not allow "
191 "transactions. Please choose a different account."),
194 else if ( picker->account_online_id_value != NULL)
199 test_acct_online_id_match,
201 (
void*)picker->account_online_id_value);
203 if (old_id_acc != NULL)
204 gnc_import_set_acc_online_id(old_id_acc,
"");
206 gnc_import_set_acc_online_id(picker->retAccount, picker->account_online_id_value);
207 gtk_assistant_set_page_complete (assistant, page, TRUE);
210 gtk_assistant_set_page_complete (assistant, page, TRUE);
214 gtk_dialog_response(GTK_DIALOG(picker->dialog), GTK_RESPONSE_OK);
225 const gchar * account_online_id_value,
226 gboolean auto_create,
227 const gchar * account_human_description,
231 gboolean * ok_pressed)
233 #define ACCOUNT_DESCRIPTION_MAX_SIZE 255
237 const gchar *retval_name = NULL;
239 GtkWidget * online_id_label, *button, *box, *pbox;
240 gchar account_description_text[ACCOUNT_DESCRIPTION_MAX_SIZE] =
"";
241 gboolean ok_pressed_retval = FALSE;
247 picker->account_online_id_value = account_online_id_value;
248 picker->account_human_description = account_human_description;
249 picker->new_account_default_commodity = new_account_default_commodity;
250 picker->new_account_default_type = new_account_default_type;
253 if (account_online_id_value != NULL)
257 test_acct_online_id_match,
259 (
void*)account_online_id_value);
275 if ((retval == NULL) && g_str_has_suffix(account_online_id_value,
" "))
277 gchar *trimmed = g_strndup(account_online_id_value, strlen(account_online_id_value) - 1);
281 gnc_get_current_root_account (),
282 test_acct_online_id_match,
289 if (retval == NULL && auto_create != 0)
292 builder = gtk_builder_new();
293 gnc_builder_add_from_file (builder,
"dialog-import.glade",
"account_picker");
294 gnc_builder_add_from_file (builder,
"dialog-import.glade",
"account_picker_content");
298 PERR(
"Error opening the glade builder interface");
300 picker->dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"account_picker"));
302 gtk_window_set_transient_for (GTK_WINDOW (picker->dialog),
303 GTK_WINDOW (parent));
306 pbox = GTK_WIDGET(gtk_builder_get_object (builder,
"account_picker_vbox"));
307 box = GTK_WIDGET(gtk_builder_get_object (builder,
"account_picker_content"));
308 gtk_box_pack_start( GTK_BOX(pbox), box, TRUE, TRUE, 0);
310 picker->account_tree_sw = GTK_WIDGET(gtk_builder_get_object (builder,
"account_tree_sw"));
311 online_id_label = GTK_WIDGET(gtk_builder_get_object (builder,
"online_id_label"));
312 button = GTK_WIDGET(gtk_builder_get_object (builder,
"newbutton"));
313 gtk_button_set_use_stock (GTK_BUTTON(button), TRUE);
317 if (account_human_description != NULL)
319 strncat(account_description_text, account_human_description,
320 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
321 strncat(account_description_text,
"\n",
322 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
324 if (account_online_id_value != NULL)
326 strncat(account_description_text, _(
"(Full account ID: "),
327 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
328 strncat(account_description_text, account_online_id_value,
329 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
330 strncat(account_description_text,
")",
331 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
333 gtk_label_set_text((GtkLabel*)online_id_label, account_description_text);
334 build_acct_tree(picker);
337 gtk_window_set_modal(GTK_WINDOW(picker->dialog), TRUE);
338 g_signal_connect(picker->account_tree,
"row-activated",
339 G_CALLBACK(account_tree_row_activated_cb), picker);
342 response = gtk_dialog_run(GTK_DIALOG(picker->dialog));
345 case GTK_RESPONSE_OK:
350 retval_name =
"(null)";
351 DEBUG(
"Selected account %p, %s", retval, retval_name);
358 _(
"The account %s is a placeholder account and does not allow "
359 "transactions. Please choose a different account."),
361 response = GNC_RESPONSE_NEW;
365 if ( account_online_id_value != NULL)
367 gnc_import_set_acc_online_id(retval, account_online_id_value);
369 ok_pressed_retval = TRUE;
371 case GNC_RESPONSE_NEW:
372 gnc_import_add_account(NULL, picker);
373 ok_pressed_retval = TRUE;
376 ok_pressed_retval = FALSE;
380 while (response == GNC_RESPONSE_NEW);
382 g_object_unref(G_OBJECT(builder));
383 gtk_widget_destroy(picker->dialog);
388 ok_pressed_retval = TRUE;
393 if (ok_pressed != NULL)
395 *ok_pressed = ok_pressed_retval;
397 LEAVE(
"Selected account %p, %s", retval, retval_name ? retval_name :
"(null)");
415 GtkWidget *button, *box, *h_box;
418 picker = gnc_import_new_account_picker();
421 builder = gtk_builder_new();
422 gnc_builder_add_from_file (builder,
"dialog-import.glade",
"account_picker_content");
426 PERR(
"Error opening the glade builder interface");
429 picker->assistant = gtk_widget_get_parent(parent);
431 box = GTK_WIDGET(gtk_builder_get_object (builder,
"account_picker_content"));
432 gtk_box_pack_start( GTK_BOX(parent), box, TRUE, TRUE, 6);
434 picker->account_tree_sw = GTK_WIDGET(gtk_builder_get_object (builder,
"account_tree_sw"));
435 picker->account_online_id_label = GTK_WIDGET(gtk_builder_get_object (builder,
"online_id_label"));
438 button = gtk_button_new_with_mnemonic (
"_New Account");
439 h_box = gtk_hbox_new(TRUE, 0);
440 gtk_box_pack_start(GTK_BOX(h_box), button, FALSE, FALSE, 0);
441 gtk_box_pack_start( GTK_BOX(box), h_box, FALSE, FALSE, 6);
442 gtk_button_set_use_stock (GTK_BUTTON(button), TRUE);
443 gtk_widget_show (button);
444 g_signal_connect(button,
"clicked",
445 G_CALLBACK(gnc_import_add_account), picker);
447 build_acct_tree(picker);
449 g_signal_connect(picker->account_tree,
"row-activated",
450 G_CALLBACK(account_tree_row_activated_cb), picker);
452 g_object_unref(G_OBJECT(builder));
464 #define ACCOUNT_DESCRIPTION_MAX_SIZE 255
466 const gchar *retval_name = NULL;
467 gchar account_description_text[ACCOUNT_DESCRIPTION_MAX_SIZE] =
"";
473 if (picker->account_online_id_value != NULL)
477 test_acct_online_id_match,
479 (
void*)picker->account_online_id_value);
482 if (picker->account_human_description != NULL)
484 strncat(account_description_text, picker->account_human_description,
485 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
486 strncat(account_description_text,
"\n",
487 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
489 if (picker->account_online_id_value != NULL)
491 strncat(account_description_text, _(
"(Full account ID: "),
492 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
493 strncat(account_description_text, picker->account_online_id_value,
494 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
495 strncat(account_description_text,
")",
496 ACCOUNT_DESCRIPTION_MAX_SIZE - strlen(account_description_text));
498 gtk_label_set_text(GTK_LABEL( picker->account_online_id_label), account_description_text);
500 if (picker->default_account == NULL)
509 LEAVE(
"Selected account %p, %s", picker->retAccount, retval_name ? retval_name :
"(null)");
510 return picker->retAccount;
GtkTreeViewColumn * gnc_tree_view_account_add_property_column(GncTreeViewAccount *view, const gchar *column_title, const gchar *propname)
Dialog for create/edit an account.
#define DEBUG(format, args...)
gpointer gnc_account_foreach_descendant_until(const Account *acc, AccountCb2 thunk, gpointer user_data)
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)
Generic and very flexible account matcher/picker.
#define PERR(format, args...)
GtkTreeViewColumn * gnc_tree_view_find_column_by_name(GncTreeView *view, const gchar *wanted)
#define ENTER(format, args...)
GtkTreeView implementation for gnucash account tree.
GtkTreeView * gnc_tree_view_account_new(gboolean show_root)
void gnc_tree_view_configure_columns(GncTreeView *view)
const char * gnc_commodity_get_fullname(const gnc_commodity *cm)
All type declarations for the whole Gnucash engine.
void gnc_tree_view_account_set_selected_account(GncTreeViewAccount *view, Account *account)
AccountPickerDialog * gnc_import_account_assist_setup(GtkWidget *parent)
gboolean xaccAccountGetPlaceholder(const Account *acc)
Account * gnc_tree_view_account_get_selected_account(GncTreeViewAccount *view)
Utility functions for writing import modules.
#define LEAVE(format, args...)
Account * gnc_ui_new_accounts_from_name_with_defaults(const char *name, GList *valid_types, const gnc_commodity *default_commodity, Account *parent)
const char * xaccAccountGetName(const Account *acc)
Account * gnc_import_account_assist_update(AccountPickerDialog *picker)
const char * xaccAccountGetTypeStr(GNCAccountType type)
Commodity handling public routines.
const gchar * QofLogModule