30 #include <glib/gi18n.h> 34 #include "gnc-account-sel.h" 39 #include "gnc-session.h" 40 #include "dialog-utils.h" 42 #define QKEY "gas_shared_quickfill" 66 GList *acctTypeFilters;
67 GList *acctCommodityFilters;
68 GList *acctExcludeList;
69 gnc_commodity *default_new_commodity;
73 GtkWidget *newAccountButton;
74 GtkTreeRowReference *saved_account_ref;
75 gulong row_changed_id;
76 gulong row_deleted_id;
78 char sep_key_prefix[BUFLEN];
79 gboolean hide_placeholder;
86 PROP_HIDE_PLACEHOLDER,
88 PROP_HORIZONTAL_EXPAND,
89 PROP_COMBO_ENTRY_WIDTH,
92 static guint account_sel_signals [LAST_SIGNAL] = { 0 };
94 static void gnc_account_sel_finalize (GObject *
object);
95 static void gnc_account_sel_dispose (GObject *
object);
97 static void gas_set_property (GObject *
object,
102 static void gas_get_property (GObject *
object,
107 static void gas_new_account_click (GtkButton *b, gpointer ud);
109 #define GNC_ACCOUNT_SEL_PATH "gnc-account-sel-path" 111 G_DEFINE_TYPE (GNCAccountSel, gnc_account_sel, GTK_TYPE_BOX)
114 gas_set_property (GObject *
object, guint param_id,
115 const GValue *value, GParamSpec *pspec)
119 g_return_if_fail (
object != NULL);
120 g_return_if_fail (GNC_IS_ACCOUNT_SEL(
object));
122 gas = GNC_ACCOUNT_SEL(
object);
126 case PROP_HIDE_PLACEHOLDER:
127 gas->hide_placeholder = g_value_get_boolean (value);
130 case PROP_HIDE_HIDDEN:
131 gas->hide_hidden = g_value_get_boolean (value);
134 case PROP_HORIZONTAL_EXPAND:
135 gtk_widget_set_hexpand (GTK_WIDGET(gas), g_value_get_boolean (value));
136 gtk_widget_set_hexpand (GTK_WIDGET(gas->combo), g_value_get_boolean (value));
139 case PROP_COMBO_ENTRY_WIDTH:
141 GtkEntry *entry = GTK_ENTRY(gtk_bin_get_child (GTK_BIN(gas->combo)));
142 gboolean expand = FALSE;
143 gint width = g_value_get_int (value);
148 gtk_widget_set_hexpand (GTK_WIDGET(gas), expand);
149 gtk_widget_set_hexpand (GTK_WIDGET(gas->combo), expand);
151 gtk_entry_set_width_chars (entry, width);
152 gtk_widget_queue_resize (GTK_WIDGET(gas));
157 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, param_id, pspec);
163 gas_get_property (GObject *
object, guint param_id,
164 GValue *value, GParamSpec *pspec)
168 g_return_if_fail (
object != NULL);
169 g_return_if_fail (GNC_IS_ACCOUNT_SEL(
object));
171 gas = GNC_ACCOUNT_SEL(
object);
175 case PROP_HIDE_PLACEHOLDER:
176 g_value_set_boolean (value, gas->hide_placeholder);
179 case PROP_HIDE_HIDDEN:
180 g_value_set_boolean (value, gas->hide_hidden);
183 case PROP_HORIZONTAL_EXPAND:
184 g_value_set_boolean (value, gtk_widget_get_hexpand (GTK_WIDGET(gas)));
187 case PROP_COMBO_ENTRY_WIDTH:
189 GtkEntry *entry = GTK_ENTRY(gtk_bin_get_child (GTK_BIN(gas->combo)));
190 g_value_set_int (value, gtk_entry_get_width_chars (entry));
195 G_OBJECT_WARN_INVALID_PROPERTY_ID(
object, param_id, pspec);
201 gnc_account_sel_class_init (GNCAccountSelClass *klass)
203 GObjectClass *object_class = G_OBJECT_CLASS(klass);
205 object_class->finalize = gnc_account_sel_finalize;
206 object_class->dispose = gnc_account_sel_dispose;
208 object_class->set_property = gas_set_property;
209 object_class->get_property = gas_get_property;
211 g_object_class_install_property (
212 object_class, PROP_HIDE_PLACEHOLDER,
213 g_param_spec_boolean(
"hide-placeholder",
"Hide Placeholder",
214 "Placeholder accounts are hidden", TRUE,
217 g_object_class_install_property (
218 object_class, PROP_HIDE_HIDDEN,
219 g_param_spec_boolean(
"hide-hidden",
"Hide Hidden",
220 "Hidden accounts are hidden", TRUE,
223 g_object_class_install_property (
224 object_class, PROP_HIDE_HIDDEN,
225 g_param_spec_boolean(
"horizontal-expand",
"Horizontal Expand",
226 "Should GAS take all horizontal space", TRUE,
229 g_object_class_install_property (
230 object_class, PROP_COMBO_ENTRY_WIDTH,
231 g_param_spec_int(
"entry-width",
"Number of Charactors",
232 "Set the width of the combo entry",
233 -1, 100, -1, G_PARAM_READWRITE));
235 account_sel_signals [ACCOUNT_SEL_CHANGED] =
236 g_signal_new (
"account_sel_changed",
237 G_OBJECT_CLASS_TYPE (object_class),
242 g_cclosure_marshal_VOID__VOID,
248 combo_changed_cb (GNCAccountSel *gas, gpointer combo)
250 GtkTreeModel *fmodel;
253 GtkTreePath *path = NULL;
254 GtkTreePath *saved_account_path = NULL;
255 gboolean emit_signal = TRUE;
257 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX(gas->combo), &fiter))
260 fmodel = gtk_combo_box_get_model (GTK_COMBO_BOX(gas->combo));
261 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER(fmodel),
264 path = gtk_tree_model_get_path (GTK_TREE_MODEL(gas->store), &iter);
266 if (gas->saved_account_ref)
268 saved_account_path = gtk_tree_row_reference_get_path (gas->saved_account_ref);
269 gtk_tree_row_reference_free (gas->saved_account_ref);
271 gas->saved_account_ref = gtk_tree_row_reference_new (GTK_TREE_MODEL(gas->store), path);
273 if (saved_account_path)
275 if (gtk_tree_path_compare (path, saved_account_path) == 0)
278 gtk_tree_path_free (saved_account_path);
279 gtk_tree_path_free (path);
282 g_signal_emit_by_name (gas,
"account_sel_changed");
286 normalize_and_fold (
char* utf8_string)
288 char *normalized, *folded;
289 g_return_val_if_fail (utf8_string && *utf8_string, NULL);
291 normalized = g_utf8_normalize (utf8_string, -1, G_NORMALIZE_NFC);
294 folded = g_utf8_casefold (normalized, -1);
300 completion_function (GtkEntryCompletion *completion,
const char *key,
301 GtkTreeIter *iter, gpointer user_data)
303 GNCAccountSel *gas = GNC_ACCOUNT_SEL(user_data);
304 GtkTreeModel *fmodel = gtk_combo_box_get_model (GTK_COMBO_BOX(gas->combo));
305 gchar *full_name = NULL;
306 gboolean ret = FALSE;
308 gtk_tree_model_get (fmodel, iter, ACCT_COL_NAME, &full_name, -1);
310 if (full_name && *full_name)
312 gchar *full_name_folded = normalize_and_fold (full_name);
315 if (g_strrstr (full_name_folded, key) != NULL)
318 g_free (full_name_folded);
325 normalize_and_lower (
const char* utf8_string)
327 char *normalized, *lowered;
328 g_return_val_if_fail (utf8_string && *utf8_string, NULL);
330 normalized = g_utf8_normalize (utf8_string, -1, G_NORMALIZE_NFC);
333 lowered = g_utf8_strdown (normalized, -1);
342 set_prefix_from_account_name (GNCAccountSel *gas,
char* account_full_name,
343 gint item_offset_to_sep_char,
344 gint *sep_key_prefix_len)
346 if (item_offset_to_sep_char < *sep_key_prefix_len)
348 *sep_key_prefix_len = item_offset_to_sep_char;
349 memset (gas->sep_key_prefix, 0, BUFLEN);
350 g_utf8_strncpy (gas->sep_key_prefix, account_full_name, *sep_key_prefix_len);
353 if (item_offset_to_sep_char == *sep_key_prefix_len)
355 char tmp_prefix[BUFLEN];
357 memset (tmp_prefix, 0, BUFLEN);
358 g_utf8_strncpy (tmp_prefix, account_full_name, *sep_key_prefix_len);
360 if (g_strcmp0 (gas->sep_key_prefix, tmp_prefix) != 0)
364 gchar *tmp = g_strdup (gas->sep_key_prefix);
365 (*sep_key_prefix_len)--;
367 memset (tmp_prefix, 0, BUFLEN);
368 g_utf8_strncpy (tmp_prefix, account_full_name, *sep_key_prefix_len);
369 memset (gas->sep_key_prefix, 0, BUFLEN);
370 g_utf8_strncpy (gas->sep_key_prefix, tmp, *sep_key_prefix_len);
373 }
while (g_strcmp0 (gas->sep_key_prefix, tmp_prefix) != 0);
378 static inline gboolean
379 find_next_separator (
char* account_full_name,
380 gint *item_offset_to_sep_char,
381 gunichar sep_unichar)
385 gboolean found = FALSE;
387 c = g_utf8_offset_to_pointer (account_full_name, *item_offset_to_sep_char);
388 (*item_offset_to_sep_char)++;
392 uc = g_utf8_get_char (c);
393 if (uc == sep_unichar)
398 c = g_utf8_next_char (c);
399 (*item_offset_to_sep_char)++;
406 entry_insert_text_cb (GtkEntry *entry,
const gchar *text, gint length,
407 gint *position, gpointer user_data)
409 GNCAccountSel *gas = GNC_ACCOUNT_SEL(user_data);
410 GtkTreeModel *fmodel = gtk_combo_box_get_model (GTK_COMBO_BOX(gas->combo));
412 gchar *lower_entered_text;
414 gunichar sep_unichar;
415 gint sep_key_prefix_len = G_MAXINT;
419 if (g_strcmp0 (text, sep_char) != 0)
422 memset (gas->sep_key_prefix, 0, BUFLEN);
424 const gchar *entered_text = gtk_entry_get_text (entry);
426 if (!(entered_text && *entered_text))
429 lower_entered_text = normalize_and_lower (entered_text);
430 entered_len = g_utf8_strlen (lower_entered_text, -1);
431 sep_unichar = gnc_get_account_separator ();
434 valid = gtk_tree_model_get_iter_first (fmodel, &iter);
439 gchar *account_full_name;
441 gtk_tree_model_get (fmodel, &iter, ACCT_COL_NAME, &account_full_name, -1);
443 if (account_full_name && *account_full_name)
445 gchar *lower_account_full_name = normalize_and_lower (account_full_name);
447 if (g_str_has_prefix (lower_account_full_name, lower_entered_text))
449 gint item_offset_to_sep_char = entered_len;
450 gboolean found = find_next_separator (account_full_name,
451 &item_offset_to_sep_char,
455 set_prefix_from_account_name (gas, account_full_name,
456 item_offset_to_sep_char,
457 &sep_key_prefix_len);
459 g_free (lower_account_full_name);
461 g_free (account_full_name);
462 valid = gtk_tree_model_iter_next (fmodel, &iter);
464 if (gas->sep_key_prefix[0] == 0)
465 g_utf8_strncpy (gas->sep_key_prefix, entered_text, entered_len);
467 g_free (lower_entered_text);
469 if (gas->sep_key_prefix[0] != 0)
471 g_signal_handlers_block_by_func (GTK_EDITABLE(entry), (gpointer) entry_insert_text_cb, user_data);
472 gtk_editable_delete_text (GTK_EDITABLE(entry), 0, -1);
473 gtk_editable_set_position (GTK_EDITABLE(entry), 0);
474 gtk_editable_insert_text (GTK_EDITABLE(entry), gas->sep_key_prefix, -1, position);
475 g_signal_handlers_unblock_by_func (GTK_EDITABLE(entry), (gpointer) entry_insert_text_cb, user_data);
476 g_signal_stop_emission_by_name (GTK_EDITABLE(entry),
"insert_text");
481 update_entry_and_refilter (GNCAccountSel *gas)
483 GtkEntry *entry = GTK_ENTRY(gtk_bin_get_child (GTK_BIN(gas->combo)));
484 GtkTreeModel *fmodel = gtk_combo_box_get_model (GTK_COMBO_BOX(gas->combo));
486 gtk_editable_delete_text (GTK_EDITABLE(entry), 0, -1);
487 if (gas->saved_account_ref)
488 gtk_tree_row_reference_free (gas->saved_account_ref);
489 gas->saved_account_ref = NULL;
490 gtk_combo_box_set_active (GTK_COMBO_BOX(gas->combo), -1);
491 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER(fmodel));
495 toggle_placeholder_cb (GtkWidget *widget, gpointer user_data)
497 GNCAccountSel *gas = GNC_ACCOUNT_SEL(user_data);
498 gas->hide_placeholder = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM(widget));
499 update_entry_and_refilter (gas);
503 toggle_hidden_cb (GtkWidget *widget, gpointer user_data)
505 GNCAccountSel *gas = GNC_ACCOUNT_SEL(user_data);
506 gas->hide_hidden = gtk_check_menu_item_get_active (GTK_CHECK_MENU_ITEM(widget));
507 update_entry_and_refilter (gas);
511 icon_release_cb (GtkEntry *entry, GtkEntryIconPosition icon_pos,
512 GdkEvent* event, gpointer user_data)
514 GNCAccountSel *gas = GNC_ACCOUNT_SEL(user_data);
515 GtkWidget *menu, *h_placeholder, *h_hidden;
517 if (icon_pos != GTK_ENTRY_ICON_SECONDARY)
520 menu = gtk_menu_new ();
521 h_placeholder = gtk_check_menu_item_new_with_mnemonic (_(
"Hide _Placeholder Accounts"));
522 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(h_placeholder), gas->hide_placeholder);
523 h_hidden = gtk_check_menu_item_new_with_mnemonic (_(
"Hide _Hidden Accounts"));
524 gtk_check_menu_item_set_active (GTK_CHECK_MENU_ITEM(h_hidden), gas->hide_hidden);
525 gtk_menu_attach_to_widget (GTK_MENU(menu), GTK_WIDGET(gas), NULL);
526 gtk_menu_shell_append (GTK_MENU_SHELL(menu), h_placeholder);
527 gtk_menu_shell_append (GTK_MENU_SHELL(menu), h_hidden);
528 gtk_widget_show_all (menu);
530 g_signal_connect (G_OBJECT(h_placeholder),
"toggled",
531 G_CALLBACK(toggle_placeholder_cb), gas);
532 g_signal_connect (G_OBJECT(h_hidden),
"toggled",
533 G_CALLBACK(toggle_hidden_cb), gas);
535 gtk_menu_popup_at_pointer (GTK_MENU(menu), (GdkEvent *)event);
545 account_is_included (GNCAccountSel *gas,
Account *acc)
547 if (gas->acctExcludeList && g_list_find (gas->acctExcludeList, acc))
551 if (gas->acctTypeFilters && !g_list_find (gas->acctTypeFilters, GINT_TO_POINTER (
xaccAccountGetType (acc))))
561 account_is_visible_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer user_data)
563 GNCAccountSel *gas = GNC_ACCOUNT_SEL(user_data);
566 gtk_tree_model_get (GTK_TREE_MODEL(gas->store), iter, ACCT_COL_PTR, &acc, -1);
571 if (!account_is_included (gas, acc))
584 row_has_been_deleted_in_store_cb (GtkTreeModel *model, GtkTreePath *path, gpointer user_data)
586 GNCAccountSel *gas = GNC_ACCOUNT_SEL(user_data);
587 GtkTreePath *saved_account_path;
589 if (!gas->saved_account_ref)
592 saved_account_path = gtk_tree_row_reference_get_path (gas->saved_account_ref);
594 if (saved_account_path == NULL)
596 GtkEntry *entry = GTK_ENTRY(gtk_bin_get_child (GTK_BIN(gas->combo)));
598 g_signal_handlers_block_by_func (gas->combo, combo_changed_cb , gas);
599 gtk_combo_box_set_active (GTK_COMBO_BOX(gas->combo), -1);
600 gtk_editable_delete_text (GTK_EDITABLE(entry), 0, -1);
601 gtk_tree_row_reference_free (gas->saved_account_ref);
602 gas->saved_account_ref = NULL;
603 g_signal_emit_by_name (gas,
"account_sel_changed");
604 g_signal_handlers_unblock_by_func (gas->combo, combo_changed_cb , gas);
606 gtk_tree_path_free (saved_account_path);
610 row_has_been_changed_in_store_cb (GtkTreeModel *model, GtkTreePath *path,
611 GtkTreeIter *iter, gpointer user_data)
613 GNCAccountSel *gas = GNC_ACCOUNT_SEL(user_data);
614 GtkTreePath *saved_account_path;
616 if (!gas->saved_account_ref)
619 saved_account_path = gtk_tree_row_reference_get_path (gas->saved_account_ref);
621 if (gtk_tree_path_compare (path, saved_account_path) == 0)
623 GtkEntry *entry = GTK_ENTRY(gtk_bin_get_child (GTK_BIN(gas->combo)));
624 gchar *account_full_name = NULL;
627 g_signal_handlers_block_by_func (gas->combo, combo_changed_cb , gas);
629 gtk_tree_model_get (model, iter, ACCT_COL_NAME, &account_full_name, -1);
631 gtk_editable_delete_text (GTK_EDITABLE(entry), 0, -1);
632 gtk_editable_insert_text (GTK_EDITABLE(entry), account_full_name, -1, &position);
633 gtk_editable_set_position (GTK_EDITABLE(entry), -1);
634 g_free (account_full_name);
636 g_signal_handlers_unblock_by_func (gas->combo, combo_changed_cb , gas);
639 if (!account_is_visible_func (model, iter, gas))
640 update_entry_and_refilter (gas);
642 gtk_tree_path_free (saved_account_path);
647 gnc_account_sel_init (GNCAccountSel *gas)
651 GtkEntryCompletion *completion;
652 Account *root = gnc_get_current_root_account ();
653 GtkTreeModel *filter_model;
655 gtk_orientable_set_orientation (GTK_ORIENTABLE(gas), GTK_ORIENTATION_HORIZONTAL);
657 gas->default_new_commodity = NULL;
658 gas->acctTypeFilters = NULL;
659 gas->acctCommodityFilters = NULL;
660 gas->acctExcludeList = NULL;
661 gas->newAccountButton = NULL;
662 gas->hide_placeholder = TRUE;
663 gas->hide_hidden = TRUE;
664 gas->saved_account_ref = NULL;
665 gas->row_changed_id = 0;
666 gas->row_deleted_id = 0;
668 g_object_set (gas,
"spacing", 2, (gchar*)NULL);
671 gtk_widget_set_name (GTK_WIDGET(gas),
"gnc-id-account-select");
674 gas->store = gnc_get_shared_account_name_list_store (root, QKEY, NULL, NULL);
677 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(gas->store),
678 ACCT_COL_NAME, GTK_SORT_ASCENDING);
681 filter_model = gtk_tree_model_filter_new (GTK_TREE_MODEL(gas->store), NULL);
682 gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER(filter_model),
683 account_is_visible_func, gas, NULL);
685 widget = gtk_combo_box_new_with_model_and_entry (GTK_TREE_MODEL(filter_model));
686 g_object_unref (G_OBJECT(filter_model));
687 gas->combo = GTK_COMBO_BOX(widget);
688 gtk_combo_box_set_entry_text_column (GTK_COMBO_BOX(widget), ACCT_COL_NAME);
690 gtk_container_add (GTK_CONTAINER(gas), widget);
693 gtk_widget_set_hexpand (GTK_WIDGET(gas), TRUE);
694 gtk_widget_set_hexpand (GTK_WIDGET(gas->combo), TRUE);
696 entry = gtk_bin_get_child (GTK_BIN(gas->combo));
697 gtk_entry_set_icon_from_icon_name (GTK_ENTRY(entry), GTK_ENTRY_ICON_SECONDARY,
698 "preferences-system-symbolic");
699 gtk_entry_set_icon_tooltip_text (GTK_ENTRY(entry), GTK_ENTRY_ICON_SECONDARY,
700 _(
"Set the visibility of placeholder and hidden accounts."));
701 g_signal_connect (G_OBJECT(entry),
"icon-release",
702 G_CALLBACK(icon_release_cb), gas);
703 g_signal_connect (G_OBJECT(entry),
"insert_text",
704 G_CALLBACK(entry_insert_text_cb), gas);
707 gnc_cbwe_require_list_item (GTK_COMBO_BOX(widget));
708 completion = gtk_entry_get_completion (GTK_ENTRY(entry));
709 gtk_entry_completion_set_match_func (completion,
710 (GtkEntryCompletionMatchFunc)completion_function,
714 gtk_combo_box_set_active (GTK_COMBO_BOX(gas->combo), -1);
715 gtk_editable_delete_text (GTK_EDITABLE(entry), 0, -1);
717 gas->row_deleted_id = g_signal_connect (G_OBJECT(gas->store),
"row-deleted",
718 G_CALLBACK(row_has_been_deleted_in_store_cb), gas);
720 gas->row_changed_id = g_signal_connect (G_OBJECT(gas->store),
"row-changed",
721 G_CALLBACK(row_has_been_changed_in_store_cb), gas);
723 g_signal_connect_swapped (gas->combo,
"changed",
724 G_CALLBACK(combo_changed_cb), gas);
728 gnc_account_sel_new (
void)
730 GNCAccountSel *gas = g_object_new (GNC_TYPE_ACCOUNT_SEL, NULL);
732 return GTK_WIDGET(gas);
742 gnc_account_sel_find_account (GtkTreeModel *fmodel,
749 gtk_tree_model_get (fmodel, iter, ACCT_COL_PTR, &model_acc, -1);
750 if (data->acct != model_acc)
753 gtk_combo_box_set_active_iter (GTK_COMBO_BOX(data->gas->combo), iter);
761 check_account_can_be_seen (GNCAccountSel *gas, GtkTreeModel *fmodel,
Account *acct)
763 gboolean changed = FALSE;
764 gboolean included = account_is_included (gas, acct);
770 if (test && gas->hide_placeholder == test)
772 gas->hide_placeholder = !test;
777 if (test && gas->hide_hidden == test)
779 gas->hide_hidden = !test;
783 gtk_tree_model_filter_refilter (GTK_TREE_MODEL_FILTER(fmodel));
788 gnc_account_sel_set_account (GNCAccountSel *gas,
Account *acct,
789 gboolean set_default_acct)
791 GtkTreeModel *fmodel;
794 g_return_if_fail (gas != NULL);
795 g_return_if_fail (GNC_IS_ACCOUNT_SEL(gas));
797 fmodel = gtk_combo_box_get_model (GTK_COMBO_BOX(gas->combo));
800 check_account_can_be_seen (gas, fmodel, acct);
802 if (set_default_acct)
804 gtk_combo_box_set_active (GTK_COMBO_BOX(gas->combo), 0);
810 gtk_combo_box_set_active (GTK_COMBO_BOX(gas->combo), -1);
813 GtkEntry *entry = GTK_ENTRY(gtk_bin_get_child (GTK_BIN(gas->combo)));
814 gtk_editable_delete_text (GTK_EDITABLE(entry), 0, -1);
820 gtk_tree_model_foreach (GTK_TREE_MODEL(fmodel),
821 (GtkTreeModelForeachFunc)gnc_account_sel_find_account,
826 gnc_account_sel_get_account (GNCAccountSel *gas)
828 GtkTreeModel *fmodel;
833 g_return_val_if_fail (gas != NULL, NULL);
834 g_return_val_if_fail (GNC_IS_ACCOUNT_SEL(gas), NULL);
836 if (!gtk_combo_box_get_active_iter (GTK_COMBO_BOX(gas->combo), &fiter))
839 fmodel = gtk_combo_box_get_model (GTK_COMBO_BOX(gas->combo));
841 gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER(fmodel),
844 gtk_tree_model_get (GTK_TREE_MODEL(gas->store), &iter,
845 ACCT_COL_PTR, &acc, -1);
850 gnc_account_sel_set_acct_filters (GNCAccountSel *gas, GList *typeFilters,
851 GList *commodityFilters)
853 g_return_if_fail (gas != NULL);
854 g_return_if_fail (GNC_IS_ACCOUNT_SEL(gas));
856 if (gas->acctTypeFilters != NULL)
858 g_list_free (gas->acctTypeFilters);
859 gas->acctTypeFilters = NULL;
862 if (gas->acctCommodityFilters != NULL)
864 g_list_free (gas->acctCommodityFilters);
865 gas->acctCommodityFilters = NULL;
871 gas->acctTypeFilters = g_list_copy (typeFilters);
874 if (commodityFilters)
875 gas->acctCommodityFilters = g_list_copy (commodityFilters);
877 update_entry_and_refilter (gas);
882 gnc_account_sel_set_acct_exclude_filter (GNCAccountSel *gas,
883 GList *excludeFilter)
885 g_return_if_fail (gas != NULL);
886 g_return_if_fail (GNC_IS_ACCOUNT_SEL(gas));
888 if (gas->acctExcludeList != NULL)
890 g_list_free (gas->acctExcludeList);
891 gas->acctExcludeList = NULL;
895 gas->acctExcludeList = g_list_copy (excludeFilter);
897 update_entry_and_refilter (gas);
901 gnc_account_sel_set_default_new_commodity (GNCAccountSel *gas, gnc_commodity *new_commodity)
903 g_return_if_fail (gas);
904 g_return_if_fail (GNC_IS_COMMODITY (new_commodity));
905 gas->default_new_commodity = new_commodity;
909 gnc_account_sel_finalize (GObject *
object)
913 g_return_if_fail (
object != NULL);
914 g_return_if_fail (GNC_IS_ACCOUNT_SEL(
object));
916 gas = GNC_ACCOUNT_SEL(
object);
918 if (gas->acctTypeFilters)
919 g_list_free (gas->acctTypeFilters);
921 if (gas->acctCommodityFilters)
922 g_list_free (gas->acctCommodityFilters);
924 if (gas->acctExcludeList)
925 g_list_free (gas->acctExcludeList);
927 G_OBJECT_CLASS (gnc_account_sel_parent_class)->finalize (
object);
931 gnc_account_sel_dispose (GObject *
object)
935 g_return_if_fail (
object != NULL);
936 g_return_if_fail (GNC_IS_ACCOUNT_SEL(
object));
938 gas = GNC_ACCOUNT_SEL(
object);
940 if (gas->row_changed_id > 0)
941 g_signal_handler_disconnect (G_OBJECT(gas->store), gas->row_changed_id);
942 gas->row_changed_id = 0;
944 if (gas->row_deleted_id > 0)
945 g_signal_handler_disconnect (G_OBJECT(gas->store), gas->row_deleted_id);
946 gas->row_deleted_id = 0;
948 if (gas->saved_account_ref)
949 gtk_tree_row_reference_free (gas->saved_account_ref);
950 gas->saved_account_ref = NULL;
952 G_OBJECT_CLASS (gnc_account_sel_parent_class)->dispose (
object);
956 gnc_account_sel_set_new_account_ability (GNCAccountSel *gas,
959 g_return_if_fail (gas != NULL);
960 g_return_if_fail (GNC_IS_ACCOUNT_SEL(gas));
962 if (state == (gas->newAccountButton != NULL))
968 if (gas->newAccountButton)
970 g_assert (state == TRUE);
972 gtk_container_remove (GTK_CONTAINER(gas), gas->newAccountButton);
973 gtk_widget_destroy (gas->newAccountButton);
974 gas->newAccountButton = NULL;
982 gas->newAccountButton = gtk_button_new_with_label (_(
"New…"));
983 g_signal_connect (gas->newAccountButton,
985 G_CALLBACK(gas_new_account_click),
988 gtk_box_pack_start (GTK_BOX(gas), gas->newAccountButton,
993 gnc_account_sel_set_new_account_modal (GNCAccountSel *gas,
996 g_return_if_fail (gas != NULL);
997 g_return_if_fail (GNC_IS_ACCOUNT_SEL(gas));
999 gas->isModal = state;
1003 gas_new_account_click (GtkButton *b, gpointer user_data)
1005 GNCAccountSel *gas = (GNCAccountSel*)user_data;
1006 GtkWindow *parent = GTK_WINDOW(gtk_widget_get_toplevel (GTK_WIDGET(gas)));
1011 gas->default_new_commodity, NULL);
1013 gnc_account_sel_set_account (gas, account, FALSE);
1017 gas->acctTypeFilters, gas->default_new_commodity);
1021 gnc_account_sel_get_visible_account_num (GNCAccountSel *gas)
1023 GtkTreeModel *fmodel;
1025 g_return_val_if_fail (gas != NULL, 0);
1026 g_return_val_if_fail (GNC_IS_ACCOUNT_SEL(gas), 0);
1028 fmodel = gtk_combo_box_get_model (GTK_COMBO_BOX(gas->combo));
1030 return gtk_tree_model_iter_n_children (fmodel, NULL);
This file contains the functions to present a gui to the user for creating a new account or editing a...
utility functions for the GnuCash UI
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
void gnc_ui_new_account_with_types_and_commodity(GtkWindow *parent, QofBook *book, GList *valid_types, gnc_commodity *default_commodity)
Display a window for creating a new account.
Create an account-name quick-fill.
gboolean xaccAccountIsHidden(const Account *acc)
Should this account be "hidden".
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.
Commodity handling public routines.
const gchar * gnc_get_account_separator_string(void)
Returns the account separation character chosen by the user.