28 #include <glib/gi18n.h> 38 #include "dialog-utils.h" 39 #include "gnc-amount-edit.h" 40 #include "gnc-general-select.h" 42 #include "gnc-commodity-edit.h" 43 #include "gnc-component-manager.h" 44 #include "gnc-date-edit.h" 46 #include "gnc-gui-query.h" 47 #include "gnc-session.h" 52 #include <gnc-locale-tax.h> 54 #define DIALOG_NEW_ACCOUNT_CM_CLASS "dialog-new-account" 55 #define DIALOG_EDIT_ACCOUNT_CM_CLASS "dialog-edit-account" 56 #define GNC_PREFS_GROUP "dialogs.account" 57 #define DEFAULT_COLOR "rgb(237,236,235)" 61 ACCOUNT_COL_FULLNAME = 0,
62 ACCOUNT_COL_FIELDNAME,
63 ACCOUNT_COL_OLD_VALUE,
64 ACCOUNT_COL_NEW_VALUE,
74 typedef struct _AccountWindow
80 AccountDialogType dialog_type;
85 gchar **subaccount_names;
92 GtkWidget *name_entry;
93 GtkWidget *description_entry;
94 GtkWidget *color_entry_button;
95 GtkWidget *color_default_button;
96 GtkWidget *code_entry;
97 GtkTextBuffer *notes_text_buffer;
99 GtkWidget *commodity_edit;
101 GtkWidget *account_scu;
105 GtkWidget *type_combo;
106 GtkTreeView *parent_tree;
107 GtkWidget *parent_scroll;
109 GtkWidget *more_properties_page;
111 GtkWidget *balance_grid;
112 GtkWidget *higher_balance_limit_edit;
113 GtkWidget *lower_balance_limit_edit;
114 GtkWidget *include_balance_sub_accts;
115 gboolean balance_is_reversed;
117 GtkWidget *opening_balance_button;
118 GtkWidget *opening_balance_edit;
119 GtkWidget *opening_balance_date_edit;
120 GtkWidget *opening_balance_page;
122 GtkWidget *opening_equity_radio;
123 GtkWidget *transfer_account_scroll;
124 GtkWidget *transfer_tree;
126 GtkWidget *tax_related_button;
127 GtkWidget *placeholder_button;
128 GtkWidget *hidden_button;
129 GtkWidget *auto_interest_button;
137 typedef struct _RenumberDialog
151 static QofLogModule log_module = GNC_MOD_GUI;
155 static GList *ac_destroy_cb_list = NULL;
160 void gnc_account_renumber_prefix_changed_cb (GtkEditable *editable,
RenumberDialog *data);
161 void gnc_account_renumber_interval_changed_cb (GtkSpinButton *spinbutton,
RenumberDialog *data);
162 void gnc_account_renumber_digits_changed_cb (GtkSpinButton *spinbutton,
RenumberDialog *data);
163 void gnc_account_renumber_response_cb (GtkDialog *dialog, gint response,
RenumberDialog *data);
165 void gnc_account_window_destroy_cb (GtkWidget *
object, gpointer data);
166 void opening_equity_cb (GtkWidget *w, gpointer data);
167 static void gnc_account_parent_changed_cb (GObject *selection, gpointer data);
168 void gnc_account_name_changed_cb (GtkWidget *widget, gpointer data);
169 void gnc_account_color_default_cb (GtkWidget *widget, gpointer data);
170 void gnc_account_name_insert_text_cb (GtkWidget *entry,
176 static gboolean account_commodity_filter (GtkTreeSelection* selection,
177 GtkTreeModel* unused_model,
179 gboolean path_currently_selected,
185 aw_call_destroy_callbacks (
Account* acc)
190 for (node = ac_destroy_cb_list; node; node = node->next)
209 if (aw->selection && aw->handler_id)
210 g_signal_handler_disconnect (aw->selection, aw->handler_id);
211 aw->selection = NULL;
218 aw_clear_selection_handler (aw);
219 aw->selection = G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW(aw->parent_tree)));
220 aw->handler_id = g_signal_connect (G_OBJECT(aw->selection),
"changed",
221 G_CALLBACK(gnc_account_parent_changed_cb),
226 gnc_account_commodity_from_type (
AccountWindow * aw, gboolean update)
237 if (update && (new_mode != aw->commodity_mode))
239 gnc_general_select_set_selected (GNC_GENERAL_SELECT(aw->commodity_edit),
242 aw->commodity_mode = new_mode;
246 gnc_account_opening_balance_button_update (
AccountWindow *aw, gnc_commodity *commodity)
248 Account *account = aw_get_account (aw);
250 gboolean has_splits = (xaccAccountGetSplitsSize (account) != 0);
254 gtk_widget_set_sensitive (aw->opening_balance_button, FALSE);
262 if (!gnc_using_equity_type_opening_balance_account (gnc_get_current_book()))
265 switch (aw->dialog_type)
268 gtk_widget_set_sensitive (aw->opening_balance_button, (ob_account == NULL ||
269 ob_account == account) &&
273 gtk_widget_set_sensitive (aw->opening_balance_button, ob_account == NULL);
283 gnc_commodity * commodity;
286 gboolean flag, nonstd_scu;
288 gnc_numeric balance_limit;
289 gboolean balance_limit_valid;
292 account = aw_get_account (aw);
302 gtk_entry_set_text (GTK_ENTRY(aw->name_entry),
string);
307 gtk_entry_set_text (GTK_ENTRY(aw->description_entry),
string);
312 string = DEFAULT_COLOR;
314 if (!gdk_rgba_parse (&color,
string))
315 gdk_rgba_parse (&color, DEFAULT_COLOR);
317 gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER(aw->color_entry_button), &color);
320 gnc_general_select_set_selected (GNC_GENERAL_SELECT(aw->commodity_edit),
322 gnc_account_commodity_from_type (aw, FALSE);
328 index = log10 (index) + 1;
334 gtk_combo_box_set_active (GTK_COMBO_BOX(aw->account_scu), index);
339 gtk_entry_set_text (GTK_ENTRY(aw->code_entry),
string);
345 gtk_text_buffer_set_text (aw->notes_text_buffer,
string, strlen(
string));
347 gnc_account_opening_balance_button_update (aw, commodity);
350 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(aw->opening_balance_button),
354 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(aw->tax_related_button),
358 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(aw->placeholder_button),
362 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(aw->hidden_button),
365 aw->balance_is_reversed = gnc_reverse_balance (account);
369 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(aw->include_balance_sub_accts),
373 if (balance_limit_valid)
375 if (aw->balance_is_reversed)
378 gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(aw->lower_balance_limit_edit),
382 gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(aw->higher_balance_limit_edit),
387 if (balance_limit_valid)
389 if (aw->balance_is_reversed)
392 gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(aw->higher_balance_limit_edit),
396 gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(aw->lower_balance_limit_edit),
400 set_auto_interest_box (aw);
405 gnc_account_create_transfer_balance (QofBook *book,
417 g_return_val_if_fail (account != NULL, FALSE);
418 g_return_val_if_fail (transfer != NULL, FALSE);
461 gnc_commodity *commodity;
463 const char *old_string;
468 gnc_numeric balance_limit;
469 gint higher_balance_limit_valid;
470 gint lower_balance_limit_valid;
471 gboolean use_equity, nonstd;
473 gint index, old_scu, new_scu;
474 GtkTextIter start, end;
476 account = aw_get_account (aw);
483 if (aw->dialog_type == EDIT_ACCOUNT
487 aw_call_destroy_callbacks (account);
495 last_used_account_type = aw->type;
497 string = gtk_entry_get_text (GTK_ENTRY(aw->name_entry));
499 if (g_strcmp0 (
string, old_string) != 0)
502 string = gtk_entry_get_text (GTK_ENTRY(aw->description_entry));
504 if (g_strcmp0 (
string, old_string) != 0)
507 gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER(aw->color_entry_button), &color);
508 string = gdk_rgba_to_string (&color);
510 if (g_strcmp0 (
string, DEFAULT_COLOR) == 0)
515 if (!
string && old_string)
519 if (g_strcmp0 (
string, old_string) != 0)
523 commodity = (gnc_commodity *)
524 gnc_general_select_get_selected (GNC_GENERAL_SELECT(aw->commodity_edit));
536 index = gtk_combo_box_get_active (GTK_COMBO_BOX(aw->account_scu));
537 nonstd = (index != 0);
541 if (old_scu != new_scu)
544 string = gtk_entry_get_text (GTK_ENTRY(aw->code_entry));
546 if (g_strcmp0 (
string, old_string) != 0)
549 gtk_text_buffer_get_start_iter (aw->notes_text_buffer, &start);
550 gtk_text_buffer_get_end_iter (aw->notes_text_buffer, &end);
551 char *new_string = gtk_text_buffer_get_text (aw->notes_text_buffer, &start, &end, FALSE);
553 if (g_strcmp0 (new_string, old_string))
557 flag = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(aw->opening_balance_button));
561 flag = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(aw->tax_related_button));
565 flag = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(aw->placeholder_button));
569 flag = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(aw->hidden_button));
573 flag = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(aw->auto_interest_button));
579 if (parent_account == NULL)
580 parent_account = gnc_book_get_root_account (aw->book);
584 flag = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(
585 aw->include_balance_sub_accts));
589 higher_balance_limit_valid = gnc_amount_edit_expr_is_valid (GNC_AMOUNT_EDIT(
590 aw->higher_balance_limit_edit),
591 &balance_limit, TRUE, NULL);
593 if (higher_balance_limit_valid == 0)
595 if (aw->balance_is_reversed)
604 if (higher_balance_limit_valid == -1)
606 if (aw->balance_is_reversed)
612 lower_balance_limit_valid = gnc_amount_edit_expr_is_valid (GNC_AMOUNT_EDIT(
613 aw->lower_balance_limit_edit),
614 &balance_limit, TRUE, NULL);
616 if (lower_balance_limit_valid == 0)
618 if (aw->balance_is_reversed)
627 if (lower_balance_limit_valid == -1)
629 if (aw->balance_is_reversed)
635 if ((higher_balance_limit_valid == -1) && (lower_balance_limit_valid == -1))
640 balance = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT(aw->opening_balance_edit));
644 LEAVE(
"zero balance");
648 if (gnc_reverse_balance (account))
651 date = gnc_date_edit_get_date (GNC_DATE_EDIT(aw->opening_balance_date_edit));
653 use_equity = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(aw->opening_equity_radio));
657 if (!gnc_account_create_opening_balance (account, balance, date, aw->book))
659 const char *message = _(
"Could not create opening balance.");
660 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
670 LEAVE(
"no transfer account");
674 gnc_account_create_transfer_balance (aw->book, account, transfer, balance, date);
682 GList *children, *iter;
685 if (children == NULL)
688 for (iter = children; iter; iter = iter->next)
690 account = iter->data;
695 aw_call_destroy_callbacks (account);
701 set_children_types (account, type);
703 g_list_free (children);
711 g_return_if_fail (aw);
713 if (aw->dialog_type == NEW_ACCOUNT)
716 account = aw_get_account (aw);
717 g_return_if_fail (account);
722 set_children_types (account, aw->type);
729 gnc_suspend_gui_refresh ();
732 make_children_compatible (aw);
733 gnc_ui_to_account (aw);
735 gnc_resume_gui_refresh ();
738 if ((aw->dialog_type == NEW_ACCOUNT) && aw->next_name && *aw->next_name)
740 gnc_commodity *commodity;
745 gtk_container_remove (GTK_CONTAINER(aw->parent_scroll), GTK_WIDGET(aw->parent_tree));
747 gtk_container_add (GTK_CONTAINER(aw->parent_scroll), GTK_WIDGET(aw->parent_tree));
748 gtk_widget_show (GTK_WIDGET(aw->parent_tree));
750 aw_connect_selection_changed (aw);
751 gnc_suspend_gui_refresh ();
753 parent = aw_get_account (aw);
761 gnc_account_to_ui (aw);
763 gnc_account_window_set_name (aw);
766 gnc_general_select_set_selected (GNC_GENERAL_SELECT(aw->commodity_edit),
768 gnc_account_commodity_from_type (aw, FALSE);
774 gnc_resume_gui_refresh ();
780 aw->created_account = aw_get_account (aw);
785 gnc_close_gui_component (aw->component_id);
790 add_children_to_expander (GObject *
object, GParamSpec *param_spec, gpointer data)
792 GtkExpander *expander = GTK_EXPANDER(
object);
794 GtkWidget *scrolled_window;
797 if (gtk_expander_get_expanded (expander) &&
798 !gtk_bin_get_child (GTK_BIN(expander)))
802 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
803 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(scrolled_window),
804 GTK_POLICY_AUTOMATIC,
805 GTK_POLICY_AUTOMATIC);
806 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(scrolled_window),
808 gtk_container_add (GTK_CONTAINER(scrolled_window), GTK_WIDGET(view));
810 gtk_container_add (GTK_CONTAINER(expander), scrolled_window);
811 gtk_widget_set_vexpand (GTK_WIDGET(scrolled_window), TRUE);
812 gtk_widget_show_all (scrolled_window);
823 GtkWidget *dialog, *vbox, *hbox, *label, *expander;
830 account = aw_get_account (aw);
840 dialog = gtk_dialog_new_with_buttons (
"",
841 GTK_WINDOW(aw->dialog),
842 GTK_DIALOG_DESTROY_WITH_PARENT |
844 _(
"_Cancel"), GTK_RESPONSE_CANCEL,
845 _(
"_OK"), GTK_RESPONSE_OK,
848 gtk_window_set_skip_taskbar_hint (GTK_WINDOW(dialog), TRUE);
850 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
851 gtk_box_set_homogeneous (GTK_BOX(hbox), FALSE);
852 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
853 gtk_box_set_homogeneous (GTK_BOX(vbox), FALSE);
855 gtk_box_pack_start (GTK_BOX(hbox),
856 gtk_image_new_from_icon_name (
"dialog-information",
857 GTK_ICON_SIZE_DIALOG), FALSE, FALSE, 0);
860 label = gtk_label_new (_(
"Give the children the same type?"));
861 gtk_label_set_line_wrap (GTK_LABEL(label), TRUE);
862 gtk_label_set_selectable (GTK_LABEL(label), TRUE);
863 gnc_label_set_alignment (label, 0.0, 0.0);
866 gnc_widget_style_context_add_class (GTK_WIDGET(label),
"gnc-class-title");
868 gtk_box_pack_start (GTK_BOX(vbox), label, FALSE, FALSE, 0);
871 str = g_strdup_printf (_(
"The children of the edited account have to be " 872 "changed to type \"%s\" to make them compatible."),
874 label = gtk_label_new (str);
876 gtk_label_set_line_wrap (GTK_LABEL(label), TRUE);
877 gtk_label_set_selectable (GTK_LABEL(label), TRUE);
878 gnc_label_set_alignment (label, 0.0, 0.0);
879 gtk_box_pack_start (GTK_BOX(vbox), label, FALSE, FALSE, 0);
882 expander = gtk_expander_new_with_mnemonic (_(
"_Show children accounts"));
883 gtk_expander_set_spacing (GTK_EXPANDER(expander), 6);
884 g_signal_connect (G_OBJECT(expander),
"notify::expanded",
885 G_CALLBACK(add_children_to_expander), account);
886 gtk_box_pack_start (GTK_BOX(vbox), expander, TRUE, TRUE, 0);
888 gtk_box_pack_start (GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
890 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area (GTK_DIALOG(dialog))),
891 hbox, TRUE, TRUE, 0);
894 gtk_container_set_border_width (GTK_CONTAINER(dialog), 5);
895 gtk_container_set_border_width (GTK_CONTAINER(hbox), 5);
896 gtk_box_set_spacing (GTK_BOX(gtk_dialog_get_content_area (GTK_DIALOG(dialog))), 14);
898 gtk_widget_show_all (hbox);
900 gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_OK);
902 result = (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_OK);
904 gtk_widget_destroy (dialog);
910 gnc_filter_parent_accounts (
Account *account, gpointer data)
913 Account *aw_account = aw_get_account (aw);
918 if (aw_account == NULL)
924 if (account == aw_account)
936 Account *root, *account, *parent;
937 gnc_commodity * commodity;
938 gchar *fullname, *fullname_parent;
939 const gchar *name, *separator;
940 gboolean higher_limit_valid;
941 gnc_numeric higher_balance_limit;
942 gboolean lower_limit_valid;
943 gnc_numeric lower_balance_limit;
946 root = gnc_book_get_root_account (aw->book);
951 name = gtk_entry_get_text (GTK_ENTRY(aw->name_entry));
952 if (g_strcmp0 (name,
"") == 0)
954 const char *message = _(
"The account must be given a name.");
955 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
962 (GNC_TREE_VIEW_ACCOUNT(aw->parent_tree));
970 fullname = g_strconcat (fullname_parent, separator, name, NULL);
974 g_free (fullname_parent);
977 if ((account != NULL) &&
980 const char *message = _(
"There is already an account with that name.");
981 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
982 LEAVE(
"duplicate name");
987 if (!gnc_filter_parent_accounts (parent, aw))
989 const char *message = _(
"You must choose a valid parent account.");
990 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
991 LEAVE(
"invalid parent");
998 const char *message = _(
"You must select an account type.");
999 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
1000 LEAVE(
"invalid type");
1007 const char *message = _(
"The selected account type is incompatible with " 1008 "the one of the selected parent.");
1009 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
1010 LEAVE(
"incompatible types");
1015 commodity = (gnc_commodity *)
1016 gnc_general_select_get_selected (GNC_GENERAL_SELECT(aw->commodity_edit));
1019 const char *message = _(
"You must choose a commodity.");
1020 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
1021 LEAVE(
"invalid commodity");
1026 higher_limit_valid = gnc_amount_edit_expr_is_valid (GNC_AMOUNT_EDIT(aw->higher_balance_limit_edit),
1027 &higher_balance_limit, TRUE, NULL);
1029 lower_limit_valid = gnc_amount_edit_expr_is_valid (GNC_AMOUNT_EDIT(aw->lower_balance_limit_edit),
1030 &lower_balance_limit, TRUE, NULL);
1032 if ((lower_limit_valid == 0) && (higher_limit_valid == 0))
1035 lower_balance_limit);
1039 const char *message = _(
"Balance limits must be different unless they are both zero.");
1040 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
1041 LEAVE(
"invalid balance limit, both the same but not zero");
1044 else if (compare == -1)
1046 const char *message = _(
"The lower balance limit must be less than the higher limit.");
1047 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
1048 LEAVE(
"invalid balance limit, lower limit not less than upper");
1064 account = aw_get_account (aw);
1071 if (!gnc_common_ok (aw))
1077 if (!verify_children_compatible (aw))
1090 gnc_numeric balance;
1094 if (!gnc_common_ok (aw))
1100 if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT(aw->opening_balance_edit), NULL))
1102 const char *message = _(
"You must enter a valid opening balance " 1103 "or leave it blank.");
1104 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
1109 balance = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT(aw->opening_balance_edit));
1113 gboolean use_equity;
1115 use_equity = gtk_toggle_button_get_active
1116 (GTK_TOGGLE_BUTTON(aw->opening_equity_radio));
1123 aw->transfer_tree));
1126 const char *message = _(
"You must select a transfer account or choose" 1127 " the opening balances equity account.");
1128 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
1140 gnc_account_window_response_cb (GtkDialog *dialog,
1146 ENTER(
"dialog %p, response %d, aw %p", dialog, response, aw);
1149 case GTK_RESPONSE_OK:
1150 switch (aw->dialog_type)
1153 DEBUG(
"new acct dialog, OK");
1154 gnc_new_account_ok (aw);
1157 DEBUG(
"edit acct dialog, OK");
1158 gnc_edit_account_ok (aw);
1161 g_assert_not_reached ();
1165 case GTK_RESPONSE_HELP:
1166 switch (aw->dialog_type)
1169 DEBUG(
"new acct dialog, HELP");
1173 DEBUG(
"edit acct dialog, HELP");
1177 g_assert_not_reached ();
1181 case GTK_RESPONSE_CANCEL:
1184 gnc_close_gui_component (aw->component_id);
1191 gnc_account_window_destroy_cb (GtkWidget *
object, gpointer data)
1196 ENTER(
"object %p, aw %p",
object, aw);
1197 account = aw_get_account (aw);
1199 aw_clear_selection_handler (aw);
1200 gnc_suspend_gui_refresh ();
1202 switch (aw->dialog_type)
1205 if (account != NULL)
1212 DEBUG (
"account add window destroyed\n");
1219 PERR (
"unexpected dialog type\n");
1220 gnc_resume_gui_refresh ();
1225 gnc_unregister_gui_component (aw->component_id);
1227 gnc_resume_gui_refresh ();
1229 if (aw->subaccount_names)
1231 g_strfreev (aw->subaccount_names);
1232 aw->subaccount_names = NULL;
1233 aw->next_name = NULL;
1241 gnc_account_parent_changed_cb (GObject *selection, gpointer data)
1245 guint32 types, old_types;
1246 GtkTreeModelSort *s_model;
1247 GtkTreeModel *type_model;
1248 gboolean combo_set = FALSE;
1250 g_return_if_fail (aw);
1251 g_return_if_fail (selection == aw->selection);
1254 GNC_TREE_VIEW_ACCOUNT(aw->parent_tree));
1255 if (!parent_account)
1260 types = aw->valid_types;
1264 types = aw->valid_types &
1267 s_model = GTK_TREE_MODEL_SORT(gtk_combo_box_get_model (GTK_COMBO_BOX(aw->type_combo)));
1268 type_model = gtk_tree_model_sort_get_model (s_model);
1272 if (aw->type != aw->preferred_account_type &&
1273 (types & (1 << aw->preferred_account_type)) != 0)
1276 aw->type = aw->preferred_account_type;
1279 else if ((types & (1 << aw->type)) == 0)
1287 old_types = gnc_tree_model_account_types_get_mask (type_model);
1288 if (old_types != types)
1292 gnc_tree_model_account_types_set_mask (type_model, types);
1295 gnc_tree_model_account_types_set_active_combo (GTK_COMBO_BOX(aw->type_combo),
1298 gnc_account_window_set_name (aw);
1304 Account* account = aw_get_account (aw);
1305 gboolean type_ok = account_type_has_auto_interest_xfer (aw->type);
1307 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(aw->auto_interest_button),
1308 type_ok && pref_set);
1309 gtk_widget_set_sensitive (GTK_WIDGET(aw->auto_interest_button), type_ok);
1313 gnc_account_type_combo_changed_cb (GtkComboBox *combo, gpointer data)
1319 g_return_if_fail (aw != NULL);
1323 type_id = gnc_tree_model_account_types_get_active_combo (combo);
1332 aw->preferred_account_type = type_id;
1334 gnc_account_commodity_from_type (aw, TRUE);
1343 gtk_widget_set_sensitive (aw->opening_balance_page, sensitive);
1347 gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(aw->opening_balance_edit),
1348 gnc_numeric_zero ());
1350 set_auto_interest_box (aw);
1354 gnc_account_type_view_create (
AccountWindow *aw, guint32 compat_types)
1356 GtkTreeModel *fmodel, *smodel;
1357 GtkCellRenderer *renderer;
1359 aw->valid_types &= compat_types;
1360 if (aw->valid_types == 0)
1363 aw->valid_types = compat_types | (1 << aw->type);
1364 aw->preferred_account_type = aw->type;
1366 else if ((aw->valid_types & (1 << aw->type)) != 0)
1369 aw->preferred_account_type = aw->type;
1371 else if ((aw->valid_types & (1 << last_used_account_type)) != 0)
1374 aw->type = last_used_account_type;
1375 aw->preferred_account_type = last_used_account_type;
1381 aw->preferred_account_type = aw->type;
1383 for (i = 0; i < 32; i++)
1384 if ((aw->valid_types & (1 << i)) != 0)
1391 fmodel = gnc_tree_model_account_types_filter_using_mask (aw->valid_types);
1393 smodel = gtk_tree_model_sort_new_with_model (fmodel);
1395 gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE(smodel),
1396 GNC_TREE_MODEL_ACCOUNT_TYPES_COL_NAME,
1397 GTK_SORT_ASCENDING);
1399 gtk_combo_box_set_model (GTK_COMBO_BOX(aw->type_combo), smodel);
1401 renderer = gtk_cell_renderer_text_new ();
1402 gtk_cell_layout_pack_start (GTK_CELL_LAYOUT(aw->type_combo), renderer, TRUE);
1403 gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT(aw->type_combo), renderer,
1404 "text", GNC_TREE_MODEL_ACCOUNT_TYPES_COL_NAME, NULL);
1406 g_signal_connect (G_OBJECT(aw->type_combo),
"changed",
1407 G_CALLBACK(gnc_account_type_combo_changed_cb), aw);
1409 g_object_unref (G_OBJECT(fmodel));
1411 gnc_tree_model_account_types_set_active_combo (GTK_COMBO_BOX(aw->type_combo),
1416 gnc_account_name_insert_text_cb (GtkWidget *entry,
1422 GtkEditable *editable = GTK_EDITABLE(entry);
1423 const gchar *separator = NULL;
1427 strsplit = g_strsplit (text, separator, 0);
1428 if (strsplit[1] != NULL)
1430 gchar *result = g_strjoinv (NULL, strsplit);
1431 g_signal_handlers_block_by_func (G_OBJECT(editable),
1432 G_CALLBACK(gnc_account_name_insert_text_cb),
1434 gtk_editable_insert_text (editable, result, g_utf8_strlen (result, -1), position);
1435 g_signal_handlers_unblock_by_func (G_OBJECT(editable),
1436 G_CALLBACK(gnc_account_name_insert_text_cb),
1438 g_signal_stop_emission_by_name (G_OBJECT(editable),
"insert_text");
1442 g_strfreev (strsplit);
1446 gnc_account_name_changed_cb (GtkWidget *widget, gpointer data)
1450 gnc_account_window_set_name (aw);
1454 gnc_account_color_default_cb (GtkWidget *widget, gpointer data)
1459 gdk_rgba_parse (&color, DEFAULT_COLOR);
1460 gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER(aw->color_entry_button), &color);
1468 gnc_commodity *currency;
1469 GtkTreeSelection *selection;
1470 Account *account = aw_get_account (aw);
1472 currency = (gnc_commodity *) gnc_general_select_get_selected (gsl);
1479 if (ob_account != account)
1481 gchar *dialog_msg = _(
"An account with opening balance already exists for the desired currency.");
1482 gchar *dialog_title = _(
"Cannot change currency");
1487 "%s", dialog_title);
1488 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(dialog),
1490 gtk_dialog_run (GTK_DIALOG(dialog));
1491 gtk_widget_destroy (dialog);
1492 g_signal_handlers_block_by_func (gsl, commodity_changed_cb, data);
1494 g_signal_handlers_unblock_by_func (gsl, commodity_changed_cb, data);
1499 gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT(aw->opening_balance_edit),
1501 gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT(aw->opening_balance_edit),
1502 gnc_commodity_print_info (currency, FALSE));
1504 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(aw->transfer_tree));
1505 gtk_tree_selection_unselect_all (selection);
1506 gnc_account_opening_balance_button_update (aw, currency);
1510 account_commodity_filter (GtkTreeSelection *selection,
1511 GtkTreeModel *unused_model,
1512 GtkTreePath *s_path,
1513 gboolean path_currently_selected,
1516 gnc_commodity *commodity;
1520 g_return_val_if_fail (GTK_IS_TREE_SELECTION(selection), FALSE);
1524 if (path_currently_selected)
1536 commodity = (gnc_commodity *)
1537 gnc_general_select_get_selected (GNC_GENERAL_SELECT(aw->commodity_edit));
1543 opening_equity_cb (GtkWidget *w, gpointer data)
1546 gboolean use_equity;
1548 use_equity = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(w));
1550 gtk_widget_set_sensitive (aw->transfer_account_scroll, !use_equity);
1562 gnc_account_window_create (GtkWindow *parent,
AccountWindow *aw)
1565 GtkWidget *date_edit;
1569 GtkBuilder *builder;
1570 GtkTreeSelection *selection;
1571 const gchar *tt = _(
"This Account contains Transactions.\nChanging this option is not possible.");
1574 ENTER(
"aw %p, modal %d", aw, aw->modal);
1575 builder = gtk_builder_new ();
1576 gnc_builder_add_from_file (builder,
"dialog-account.glade",
"fraction_liststore");
1577 gnc_builder_add_from_file (builder,
"dialog-account.glade",
"account_dialog");
1579 aw->dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"account_dialog"));
1580 awo = G_OBJECT(aw->dialog);
1583 gtk_window_set_transient_for (GTK_WINDOW(aw->dialog), parent);
1586 gtk_widget_set_name (GTK_WIDGET(aw->dialog),
"gnc-id-account");
1587 gnc_widget_style_context_add_class (GTK_WIDGET(aw->dialog),
"gnc-class-account");
1590 g_object_set_data (awo,
"dialog_info", aw);
1593 g_signal_connect (awo,
"response",
1594 G_CALLBACK(gnc_account_window_response_cb), aw);
1596 gtk_window_set_modal (GTK_WINDOW(aw->dialog), TRUE);
1598 aw->notebook = GTK_WIDGET(gtk_builder_get_object (builder,
"account_notebook"));
1599 aw->name_entry = GTK_WIDGET(gtk_builder_get_object (builder,
"name_entry"));
1600 aw->description_entry = GTK_WIDGET(gtk_builder_get_object (builder,
"description_entry"));
1601 aw->color_entry_button = GTK_WIDGET(gtk_builder_get_object (builder,
"color_entry_button"));
1602 aw->color_default_button = GTK_WIDGET(gtk_builder_get_object (builder,
"color_default_button"));
1603 aw->code_entry = GTK_WIDGET(gtk_builder_get_object (builder,
"code_entry"));
1604 aw->notes_text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(GTK_WIDGET(
1605 gtk_builder_get_object (builder,
1608 box = GTK_WIDGET(gtk_builder_get_object (builder,
"commodity_hbox"));
1609 aw->commodity_edit = gnc_general_select_new (GNC_GENERAL_SELECT_TYPE_SELECT,
1610 gnc_commodity_edit_get_string,
1611 gnc_commodity_edit_new_select,
1612 &aw->commodity_mode);
1614 gtk_box_pack_start (GTK_BOX(box), aw->commodity_edit, TRUE, TRUE, 0);
1615 gtk_widget_show (aw->commodity_edit);
1617 if (xaccAccountGetSplitsSize (aw_get_account (aw)) != 0)
1619 gtk_widget_set_tooltip_text (aw->commodity_edit, tt);
1620 gtk_widget_set_sensitive (aw->commodity_edit, FALSE);
1623 label = GTK_WIDGET(gtk_builder_get_object (builder,
"security_label"));
1624 gnc_general_select_make_mnemonic_target (GNC_GENERAL_SELECT(aw->commodity_edit), label);
1626 g_signal_connect (G_OBJECT(aw->commodity_edit),
"changed",
1627 G_CALLBACK(commodity_changed_cb), aw);
1629 aw->account_scu = GTK_WIDGET(gtk_builder_get_object (builder,
"account_scu"));
1631 aw->parent_scroll = GTK_WIDGET(gtk_builder_get_object (builder,
"parent_scroll"));
1634 gtk_container_add (GTK_CONTAINER(aw->parent_scroll), GTK_WIDGET(aw->parent_tree));
1635 gtk_widget_show (GTK_WIDGET(aw->parent_tree));
1636 aw_connect_selection_changed (aw);
1638 aw->balance_grid = GTK_WIDGET(gtk_builder_get_object (builder,
"balance_grid"));
1640 box = GTK_WIDGET(gtk_builder_get_object (builder,
"higher_balance_limit_hbox"));
1641 aw->higher_balance_limit_edit = gnc_amount_edit_new ();
1642 gtk_box_pack_start (GTK_BOX(box), aw->higher_balance_limit_edit, TRUE, TRUE, 0);
1643 gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT(aw->higher_balance_limit_edit), TRUE);
1644 gnc_amount_edit_set_validate_on_change (GNC_AMOUNT_EDIT(aw->higher_balance_limit_edit), TRUE);
1645 gnc_amount_edit_show_warning_symbol (GNC_AMOUNT_EDIT(aw->higher_balance_limit_edit), TRUE);
1646 gtk_widget_show (aw->higher_balance_limit_edit);
1648 box = GTK_WIDGET(gtk_builder_get_object (builder,
"lower_balance_limit_hbox"));
1649 aw->lower_balance_limit_edit = gnc_amount_edit_new ();
1650 gtk_box_pack_start (GTK_BOX(box), aw->lower_balance_limit_edit, TRUE, TRUE, 0);
1651 gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT(aw->lower_balance_limit_edit), TRUE);
1652 gnc_amount_edit_set_validate_on_change (GNC_AMOUNT_EDIT(aw->lower_balance_limit_edit), TRUE);
1653 gnc_amount_edit_show_warning_symbol (GNC_AMOUNT_EDIT(aw->lower_balance_limit_edit), TRUE);
1654 gtk_widget_show (aw->lower_balance_limit_edit);
1656 aw->include_balance_sub_accts = GTK_WIDGET(gtk_builder_get_object (builder,
"include_sub_accts_tb"));
1658 aw->more_properties_page =
1659 gtk_notebook_get_nth_page (GTK_NOTEBOOK(aw->notebook), 1);
1661 aw->opening_balance_button = GTK_WIDGET(gtk_builder_get_object (builder,
"opening_balance_button"));
1662 aw->tax_related_button = GTK_WIDGET(gtk_builder_get_object (builder,
"tax_related_button"));
1663 aw->placeholder_button = GTK_WIDGET(gtk_builder_get_object (builder,
"placeholder_button"));
1664 aw->hidden_button = GTK_WIDGET(gtk_builder_get_object (builder,
"hidden_button"));
1665 aw->auto_interest_button = GTK_WIDGET(gtk_builder_get_object (builder,
"auto_interest_button"));
1666 set_auto_interest_box (aw);
1669 box = GTK_WIDGET(gtk_builder_get_object (builder,
"opening_balance_box"));
1670 amount = gnc_amount_edit_new ();
1671 aw->opening_balance_edit = amount;
1672 gtk_box_pack_start (GTK_BOX(box), amount, TRUE, TRUE, 0);
1673 gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT(amount), TRUE);
1674 gtk_widget_show (amount);
1676 label = GTK_WIDGET(gtk_builder_get_object (builder,
"balance_label"));
1677 gnc_amount_edit_make_mnemonic_target (GNC_AMOUNT_EDIT(amount), label);
1679 box = GTK_WIDGET(gtk_builder_get_object (builder,
"opening_balance_date_box"));
1680 label = GTK_WIDGET(gtk_builder_get_object (builder,
"date_label"));
1681 date_edit = gnc_date_edit_new (
gnc_time (NULL), 0, 0);
1682 gnc_date_make_mnemonic_target (GNC_DATE_EDIT(date_edit), label);
1683 aw->opening_balance_date_edit = date_edit;
1684 gtk_box_pack_start (GTK_BOX(box), date_edit, TRUE, TRUE, 0);
1685 gtk_widget_show (date_edit);
1687 aw->opening_balance_page =
1688 gtk_notebook_get_nth_page (GTK_NOTEBOOK(aw->notebook), 2);
1690 aw->opening_equity_radio = GTK_WIDGET(gtk_builder_get_object (builder,
1691 "opening_equity_radio"));
1693 box = GTK_WIDGET(gtk_builder_get_object (builder,
"transfer_account_scroll"));
1694 aw->transfer_account_scroll = box;
1697 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(aw->transfer_tree));
1698 gtk_tree_selection_set_select_function (selection, account_commodity_filter, aw, NULL);
1700 gtk_container_add (GTK_CONTAINER(box), GTK_WIDGET(aw->transfer_tree));
1701 gtk_widget_show (GTK_WIDGET(aw->transfer_tree));
1703 label = GTK_WIDGET(gtk_builder_get_object (builder,
"parent_label"));
1704 gtk_label_set_mnemonic_widget (GTK_LABEL(label), GTK_WIDGET(aw->parent_tree));
1707 aw->type_combo = GTK_WIDGET(gtk_builder_get_object (builder,
"account_type_combo"));
1717 if (xaccAccountGetSplitsSize (aw_get_account (aw)) != 0)
1724 gnc_account_type_view_create (aw, compat_types);
1726 gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(aw->dialog), parent);
1728 gtk_widget_grab_focus (GTK_WIDGET(aw->name_entry));
1730 gtk_builder_connect_signals (builder, aw);
1731 g_object_unref (G_OBJECT(builder));
1743 name = gtk_entry_get_text (GTK_ENTRY(aw->name_entry));
1744 if (!name || *name ==
'\0')
1745 name = _(
"<No name>");
1754 fullname = g_strconcat (parent_name, separator, name, NULL);
1755 g_free (parent_name);
1758 fullname = g_strdup (name);
1769 if (!aw || !aw->parent_tree)
1772 fullname = get_ui_fullname (aw);
1774 if (aw->dialog_type == EDIT_ACCOUNT)
1775 title = g_strconcat(_(
"Edit Account"),
" - ", fullname, NULL);
1776 else if (aw->next_name && (g_strv_length (aw->next_name) > 0))
1778 const char *format = _(
"(%d) New Accounts");
1779 char *prefix = g_strdup_printf (format,
1780 g_strv_length (aw->next_name) + 1);
1782 title = g_strconcat (prefix,
" - ", fullname,
" …", NULL);
1786 title = g_strconcat (_(
"New Account"),
" - ", fullname, NULL);
1788 gtk_window_set_title (GTK_WINDOW(aw->dialog), title);
1795 close_handler (gpointer user_data)
1799 ENTER(
"aw %p, modal %d", aw, aw->modal);
1800 gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(aw->dialog));
1802 gtk_widget_destroy (GTK_WIDGET(aw->dialog));
1821 gnc_account_window_set_name (aw);
1825 refresh_handler (GHashTable *changes, gpointer user_data)
1830 account = aw_get_account (aw);
1833 gnc_close_gui_component (aw->component_id);
1839 const EventInfo *info = gnc_gui_get_entity_events (changes, &aw->account);
1840 if (info && (info->event_mask & QOF_EVENT_DESTROY))
1842 gnc_close_gui_component (aw->component_id);
1846 gnc_ui_refresh_account_window (aw);
1850 gnc_ui_new_account_window_internal (GtkWindow *parent,
1853 gchar **subaccount_names,
1855 const gnc_commodity * default_commodity,
1858 const gnc_commodity *commodity, *parent_commodity;
1863 g_return_val_if_fail(book, NULL);
1869 aw->dialog_type = NEW_ACCOUNT;
1871 aw->valid_types = 0;
1872 for (list = valid_types; list; list = list->next)
1873 aw->valid_types |= (1 << GPOINTER_TO_INT (list->data));
1885 aw->type = last_used_account_type;
1889 gnc_suspend_gui_refresh ();
1891 if (subaccount_names && *subaccount_names)
1894 aw->subaccount_names = subaccount_names;
1895 aw->next_name = subaccount_names + 1;
1898 gnc_account_window_create (parent, aw);
1899 gnc_account_to_ui (aw);
1901 gnc_resume_gui_refresh ();
1903 if (default_commodity != NULL)
1905 commodity = default_commodity;
1908 gtk_entry_set_text (GTK_ENTRY(aw->name_entry),
1910 gtk_entry_set_text (GTK_ENTRY(aw->description_entry),
1916 commodity = parent_commodity;
1922 gnc_general_select_set_selected (GNC_GENERAL_SELECT(aw->commodity_edit),
1923 (gpointer) commodity);
1924 gnc_account_commodity_from_type (aw, FALSE);
1926 if (base_account == NULL)
1928 base_account = gnc_book_get_root_account (book);
1931 gtk_tree_view_collapse_all (aw->parent_tree);
1936 gtk_widget_show (aw->dialog);
1938 gnc_window_adjust_for_screen (GTK_WINDOW(aw->dialog));
1940 gnc_account_window_set_name (aw);
1942 aw->component_id = gnc_register_gui_component (DIALOG_NEW_ACCOUNT_CM_CLASS,
1944 modal ? NULL : close_handler,
1947 gnc_gui_component_set_session (aw->component_id, gnc_get_current_session());
1948 gnc_gui_component_watch_entity_type (aw->component_id,
1950 QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
1955 gnc_split_account_name (QofBook *book,
const char *in_name,
Account **base_account)
1958 gchar **names, **ptr, **out_names;
1961 root = gnc_book_get_root_account (book);
1965 for (ptr = names; *ptr; ptr++)
1972 for (node = list; node; node = g_list_next (node))
1974 account = node->data;
1979 *base_account = account;
1992 out_names = g_strdupv (ptr);
2014 const gnc_commodity * default_commodity,
2020 Account *created_account = NULL;
2021 gchar ** subaccount_names;
2023 gboolean done = FALSE;
2025 ENTER(
"name %s, valid %p, commodity %p, account %p",
2026 name, valid_types, default_commodity, parent_acct);
2027 book = gnc_get_current_book ();
2028 if (!name || *name ==
'\0')
2030 subaccount_names = NULL;
2031 base_account = NULL;
2034 subaccount_names = gnc_split_account_name (book, name, &base_account);
2036 if (parent_acct != NULL)
2038 base_account = parent_acct;
2040 aw = gnc_ui_new_account_window_internal (parent, book, base_account,
2048 response = gtk_dialog_run (GTK_DIALOG(aw->dialog));
2051 gnc_account_window_response_cb (GTK_DIALOG(aw->dialog), response, (gpointer)aw);
2055 case GTK_RESPONSE_OK:
2056 created_account = aw->created_account;
2057 done = (created_account != NULL);
2060 case GTK_RESPONSE_HELP:
2072 return created_account;
2080 find_by_account (gpointer
find_data, gpointer user_data)
2103 if (account == NULL)
2106 aw = gnc_find_first_gui_component (DIALOG_EDIT_ACCOUNT_CM_CLASS,
2107 find_by_account, account);
2110 gtk_window_present (GTK_WINDOW(aw->dialog));
2116 aw->book = gnc_account_get_book (account);
2118 aw->dialog_type = EDIT_ACCOUNT;
2120 aw->subaccount_names = NULL;
2123 gnc_suspend_gui_refresh ();
2125 gnc_account_window_create (parent, aw);
2126 gnc_account_to_ui (aw);
2128 gnc_resume_gui_refresh ();
2130 gtk_widget_show_all (aw->dialog);
2131 if (xaccAccountGetSplitsSize (account) != 0)
2132 gtk_widget_hide (aw->opening_balance_page);
2135 if (parent_acct == NULL)
2136 parent_acct = account;
2138 gtk_tree_view_collapse_all (aw->parent_tree);
2143 gnc_account_window_set_name (aw);
2145 gnc_window_adjust_for_screen (GTK_WINDOW(aw->dialog));
2147 aw->component_id = gnc_register_gui_component (DIALOG_EDIT_ACCOUNT_CM_CLASS,
2151 gnc_gui_component_set_session (aw->component_id, gnc_get_current_session ());
2152 gnc_gui_component_watch_entity_type (aw->component_id,
2154 QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
2156 gtk_window_present (GTK_WINDOW(aw->dialog));
2161 gnc_commodity *default_commodity)
2163 gnc_ui_new_account_window_internal (parent, book, NULL, NULL,
2164 valid_types, default_commodity, FALSE);
2177 g_return_if_fail(book != NULL);
2178 if (parent_acct && book)
2179 g_return_if_fail(gnc_account_get_book (parent_acct) == book);
2181 gnc_ui_new_account_window_internal (parent, book, parent_acct, NULL, NULL,
2196 gnc_ui_register_account_destroy_callback (
void (*cb)(
Account *))
2201 if (g_list_index (ac_destroy_cb_list, cb) == -1)
2202 ac_destroy_cb_list = g_list_append (ac_destroy_cb_list, cb);
2215 unsigned int num_digits = 1;
2217 g_return_if_fail (data->num_children > 0);
2219 const gchar *prefix = gtk_entry_get_text (GTK_ENTRY(data->prefix));
2220 interval = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(data->interval));
2221 digits = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(data->digits));
2226 num_digits = (
unsigned int)log10((
double)(data->num_children * interval)) + 1;
2228 if (digits <= num_digits)
2230 g_signal_handlers_block_by_func (GTK_SPIN_BUTTON(data->digits),
2231 (gpointer)gnc_account_renumber_digits_changed_cb,
2233 gtk_spin_button_set_value (GTK_SPIN_BUTTON(data->digits), num_digits);
2234 g_signal_handlers_unblock_by_func (GTK_SPIN_BUTTON(data->digits),
2235 (gpointer)gnc_account_renumber_digits_changed_cb,
2239 num_digits = digits;
2241 if (prefix && *prefix)
2242 str = g_strdup_printf (
"%s-%0*d", prefix, num_digits, interval);
2244 str = g_strdup_printf (
"%0*d", num_digits, interval);
2246 gtk_label_set_text (GTK_LABEL(data->example1), str);
2249 if (prefix && *prefix)
2250 str = g_strdup_printf (
"%s-%0*d", prefix, num_digits,
2251 interval * data->num_children);
2253 str = g_strdup_printf (
"%0*d", num_digits,
2254 interval * data->num_children);
2256 gtk_label_set_text (GTK_LABEL(data->example2), str);
2262 gnc_account_renumber_prefix_changed_cb (GtkEditable *editable,
2265 gnc_account_renumber_update_examples (data);
2269 gnc_account_renumber_interval_changed_cb (GtkSpinButton *spinbutton,
2272 gnc_account_renumber_update_examples (data);
2276 gnc_account_renumber_digits_changed_cb (GtkSpinButton *spinbutton,
2279 gnc_account_renumber_update_examples (data);
2283 gnc_account_renumber_response_cb (GtkDialog *dialog,
2287 if (response == GTK_RESPONSE_OK)
2292 unsigned int num_digits, i;
2294 gtk_widget_hide (data->dialog);
2296 if (children == NULL)
2298 PWARN(
"Can't renumber children of an account with no children!");
2302 const gchar *prefix = gtk_entry_get_text (GTK_ENTRY(data->prefix));
2303 interval = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(data->interval));
2304 num_digits = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(data->digits));
2306 gnc_set_busy_cursor (NULL, TRUE);
2307 for (tmp = children, i = 1; tmp; tmp = g_list_next (tmp), i += 1)
2310 if (prefix && *prefix)
2311 str = g_strdup_printf (
"%s-%0*d", prefix,
2312 num_digits, interval * i);
2314 str = g_strdup_printf (
"%0*d", num_digits, interval * i);
2319 gnc_unset_busy_cursor (NULL);
2320 g_list_free (children);
2322 gtk_widget_destroy (data->dialog);
2327 gnc_account_renumber_create_dialog (GtkWidget *window,
Account *account)
2330 GtkBuilder *builder;
2332 gchar *string, *fullname;
2340 data->parent = account;
2343 builder = gtk_builder_new ();
2344 gnc_builder_add_from_file (builder,
"dialog-account.glade",
"interval_adjustment");
2345 gnc_builder_add_from_file (builder,
"dialog-account.glade",
"digit_spin_adjustment");
2346 gnc_builder_add_from_file (builder,
"dialog-account.glade",
"account_renumber_dialog");
2347 data->dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"account_renumber_dialog"));
2348 gtk_window_set_transient_for (GTK_WINDOW(data->dialog), GTK_WINDOW(window));
2350 g_object_set_data_full (G_OBJECT(data->dialog),
"builder", builder,
2353 widget = GTK_WIDGET(gtk_builder_get_object (builder,
"header_label"));
2355 string = g_strdup_printf (_(
"Renumber the immediate sub-accounts of '%s'?"),
2357 gtk_label_set_text (GTK_LABEL(widget),
string);
2361 data->prefix = GTK_WIDGET(gtk_builder_get_object (builder,
"prefix_entry"));
2362 data->interval = GTK_WIDGET(gtk_builder_get_object (builder,
"interval_spin"));
2363 data->digits = GTK_WIDGET(gtk_builder_get_object (builder,
"digit_spin"));
2364 data->example1 = GTK_WIDGET(gtk_builder_get_object (builder,
"example1_label"));
2365 data->example2 = GTK_WIDGET(gtk_builder_get_object (builder,
"example2_label"));
2368 gnc_account_renumber_update_examples (data);
2370 gtk_builder_connect_signals (builder, data);
2372 gtk_widget_show_all (data->dialog);
2376 default_color_button_cb (GtkButton *button, gpointer user_data)
2380 if (gdk_rgba_parse (&color, DEFAULT_COLOR))
2381 gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER(user_data), &color);
2385 update_account_color (
Account *acc,
const gchar *old_color,
const gchar *new_color, gboolean replace)
2387 PINFO(
"Account is '%s', old_color is '%s', new_color is '%s', replace is %d",
2393 if (!old_color || replace)
2396 if (g_strcmp0 (new_color, old_color) != 0)
2402 if (old_color && replace)
2408 enable_box_cb (GtkToggleButton *toggle_button, gpointer user_data)
2410 gboolean sensitive = FALSE;
2412 if (gtk_toggle_button_get_active (toggle_button))
2415 gtk_widget_set_sensitive (GTK_WIDGET(user_data), sensitive);
2419 gnc_account_cascade_properties_dialog (GtkWidget *window,
Account *account)
2422 GtkBuilder *builder;
2424 GtkWidget *color_button, *over_write, *color_button_default;
2425 GtkWidget *enable_color, *enable_placeholder, *enable_hidden;
2426 GtkWidget *color_box, *placeholder_box, *hidden_box;
2427 GtkWidget *placeholder_button, *hidden_button;
2429 gchar *string, *fullname;
2430 const char *color_string;
2431 gchar *old_color_string = NULL;
2438 builder = gtk_builder_new ();
2439 gnc_builder_add_from_file (builder,
"dialog-account.glade",
"account_cascade_dialog");
2440 dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"account_cascade_dialog"));
2441 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(window));
2444 enable_color = GTK_WIDGET(gtk_builder_get_object (builder,
"enable_cascade_color"));
2445 color_box = GTK_WIDGET(gtk_builder_get_object (builder,
"color_box"));
2447 label = GTK_WIDGET(gtk_builder_get_object (builder,
"color_label"));
2448 over_write = GTK_WIDGET(gtk_builder_get_object (builder,
"replace_check"));
2449 color_button = GTK_WIDGET(gtk_builder_get_object (builder,
"color_button"));
2450 color_button_default = GTK_WIDGET(gtk_builder_get_object (builder,
"color_button_default"));
2452 gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER(color_button), FALSE);
2454 g_signal_connect (G_OBJECT(enable_color),
"toggled",
2455 G_CALLBACK(enable_box_cb), (gpointer)color_box);
2457 g_signal_connect (G_OBJECT(color_button_default),
"clicked",
2458 G_CALLBACK(default_color_button_cb), (gpointer)color_button);
2461 string = g_strdup_printf (_(
"Set the account color for account '%s' " 2462 "including all sub-accounts to the selected color"),
2464 gtk_label_set_text (GTK_LABEL(label),
string);
2470 color_string = DEFAULT_COLOR;
2472 old_color_string = g_strdup (color_string);
2474 if (!gdk_rgba_parse (&color, color_string))
2475 gdk_rgba_parse (&color, DEFAULT_COLOR);
2478 gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER(color_button), &color);
2481 enable_placeholder = GTK_WIDGET(gtk_builder_get_object (builder,
"enable_cascade_placeholder"));
2482 placeholder_box = GTK_WIDGET(gtk_builder_get_object (builder,
"placeholder_box"));
2483 label = GTK_WIDGET(gtk_builder_get_object (builder,
"placeholder_label"));
2484 placeholder_button = GTK_WIDGET(gtk_builder_get_object (builder,
"placeholder_check_button"));
2485 g_signal_connect (G_OBJECT(enable_placeholder),
"toggled",
2486 G_CALLBACK(enable_box_cb), (gpointer)placeholder_box);
2488 string = g_strdup_printf (_(
"Set the account placeholder value for account '%s' " 2489 "including all sub-accounts"),
2491 gtk_label_set_text (GTK_LABEL(label),
string);
2495 enable_hidden = GTK_WIDGET(gtk_builder_get_object (builder,
"enable_cascade_hidden"));
2496 hidden_box = GTK_WIDGET(gtk_builder_get_object (builder,
"hidden_box"));
2497 label = GTK_WIDGET(gtk_builder_get_object (builder,
"hidden_label"));
2498 hidden_button = GTK_WIDGET(gtk_builder_get_object (builder,
"hidden_check_button"));
2499 g_signal_connect (G_OBJECT(enable_hidden),
"toggled",
2500 G_CALLBACK(enable_box_cb), (gpointer)hidden_box);
2502 string = g_strdup_printf (_(
"Set the account hidden value for account '%s' " 2503 "including all sub-accounts"),
2505 gtk_label_set_text (GTK_LABEL(label),
string);
2510 gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);
2512 gtk_builder_connect_signals (builder, dialog);
2513 g_object_unref (G_OBJECT(builder));
2515 gtk_widget_show_all (dialog);
2517 response = gtk_dialog_run (GTK_DIALOG(dialog));
2519 if (response == GTK_RESPONSE_OK)
2523 const gchar *new_color_string = NULL;
2524 gboolean color_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(enable_color));
2525 gboolean placeholder_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(enable_placeholder));
2526 gboolean hidden_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(enable_hidden));
2527 gboolean replace = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(over_write));
2528 gboolean placeholder = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(placeholder_button));
2529 gboolean hidden = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(hidden_button));
2534 gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER(color_button), &new_color);
2535 new_color_string = gdk_rgba_to_string (&new_color);
2537 if (g_strcmp0 (new_color_string, DEFAULT_COLOR) == 0)
2538 new_color_string = NULL;
2541 update_account_color (account, old_color_string, new_color_string, replace);
2545 if (placeholder_active)
2555 for (GList *acct = accounts; acct; acct = g_list_next(acct))
2561 update_account_color (acct->data,
string, new_color_string, replace);
2564 if (placeholder_active)
2571 g_list_free (accounts);
2573 if (old_color_string)
2574 g_free (old_color_string);
2576 gtk_widget_destroy (dialog);
void xaccAccountSetType(Account *acc, GNCAccountType tip)
Set the account's type.
void xaccSplitSetValue(Split *split, gnc_numeric val)
The xaccSplitSetValue() method sets the value of this split in the transaction's commodity.
Account * gnc_account_get_parent(const Account *acc)
This routine returns a pointer to the parent of the specified account.
#define xaccTransAppendSplit(t, s)
Add a split to the transaction.
Transaction * xaccMallocTransaction(QofBook *book)
The xaccMallocTransaction() will malloc memory and initialize it.
gboolean xaccAccountGetAutoInterest(const Account *acc)
Get the "auto interest" flag for an account.
void xaccTransSetDatePostedSecsNormalized(Transaction *trans, time64 time)
This function sets the posted date of the transaction, specified by a time64 (see ctime(3))...
Dialog box should only allow selection of a currency.
int gnc_commodity_get_fraction(const gnc_commodity *cm)
Retrieve the fraction for the specified commodity.
Account * gnc_ui_new_accounts_from_name_window(GtkWindow *parent, const char *name)
Display a modal window for creating a new account.
guint32 xaccAccountTypesCompatibleWith(GNCAccountType type)
Return the bitmask of account types compatible with a given type.
void gnc_account_append_child(Account *new_parent, Account *child)
This function will remove from the child account any pre-existing parent relationship, and will then add the account as a child of the new parent.
gboolean gnc_account_is_root(const Account *account)
This routine indicates whether the specified account is the root node of an account tree...
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
Retrieve the mnemonic for the specified commodity.
int xaccAccountGetCommoditySCUi(const Account *acc)
Return the 'internal' SCU setting.
gboolean xaccAccountGetNonStdSCU(const Account *acc)
Return boolean, indicating whether this account uses a non-standard SCU.
This file contains the functions to present a gui to the user for creating a new account or editing a...
void xaccAccountSetNotes(Account *acc, const char *str)
Set the account's notes.
GtkWindow * gnc_ui_get_main_window(GtkWidget *widget)
Get a pointer to the final GncMainWindow widget is rooted in.
utility functions for the GnuCash UI
#define PINFO(format, args...)
Print an informational note.
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
int xaccAccountGetCommoditySCU(const Account *acc)
Return the SCU for the account.
const char * xaccAccountGetCode(const Account *acc)
Get the account's accounting code.
gnc_numeric gnc_numeric_neg(gnc_numeric a)
Returns a newly created gnc_numeric that is the negative of the given gnc_numeric value...
void xaccAccountSetTaxRelated(Account *acc, gboolean tax_related)
DOCUMENT ME!
#define DEBUG(format, args...)
Print a debugging message.
Mutual Fund accounts will typically be shown in registers which show three columns: price...
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.
void xaccAccountSetCode(Account *acc, const char *str)
Set the account's accounting code.
void xaccTransSetDescription(Transaction *trans, const char *desc)
Sets the transaction Description.
guint32 xaccAccountTypesValid(void)
Returns the bitmask of the account type enums that are valid.
gboolean gnc_numeric_zero_p(gnc_numeric a)
Returns 1 if the given gnc_numeric is 0 (zero), else returns 0.
void xaccAccountSetHigherBalanceLimit(Account *acc, gnc_numeric balance)
Set the higher balance limit for the account.
int gnc_numeric_compare(gnc_numeric a, gnc_numeric b)
Returns 1 if a>b, -1 if b>a, 0 if a == b.
#define PERR(format, args...)
Log a serious error.
#define ENTER(format, args...)
Print a function entry debugging message.
void gnc_ui_edit_account_window(GtkWindow *parent, Account *account)
Display a window for editing the attributes of an existing account.
void xaccTransSetCurrency(Transaction *trans, gnc_commodity *curr)
Set a new currency on a transaction.
gnc_commodity * gnc_default_currency(void)
Return the default currency set by the user.
Account used to record multiple commodity transactions.
Dialog box should allow selection of anything.
gboolean xaccAccountGetLowerBalanceLimit(const Account *acc, gnc_numeric *balance)
Get the lower balance limit for the account.
void xaccAccountDestroy(Account *acc)
The xaccAccountDestroy() routine can be used to get rid of an account.
#define PWARN(format, args...)
Log a warning.
Stock accounts will typically be shown in registers which show three columns: price, number of shares, and value.
const char * xaccAccountGetColor(const Account *acc)
Get the account's color.
#define xaccAccountGetGUID(X)
void xaccSplitSetAmount(Split *split, gnc_numeric amt)
The xaccSplitSetAmount() method sets the amount in the account's commodity that the split should have...
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...
void xaccAccountSetPlaceholder(Account *acc, gboolean val)
Set the "placeholder" flag for an account.
gboolean xaccAccountTypesCompatible(GNCAccountType parent_type, GNCAccountType child_type)
Return TRUE if accounts of type parent_type can have accounts of type child_type as children...
void xaccAccountClearLowerBalanceLimit(Account *acc)
Clear the lower balance limit for the account.
void xaccAccountSetColor(Account *acc, const char *str)
Set the account's Color.
void xaccAccountSetIncludeSubAccountBalances(Account *acc, gboolean inc_sub)
Set whether to include balances of sub accounts.
GtkTreeView implementation for gnucash account tree.
void gnc_gnome_help(GtkWindow *parent, const char *file_name, const char *anchor)
Launch the systems default help browser, gnome's yelp for linux, and open to a given link within a gi...
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
Given two GUIDs, return TRUE if they are non-NULL and equal.
GtkTreeView * gnc_tree_view_account_new_with_root(Account *root, gboolean show_root)
Create a new account tree view.
Dialog box should allow selection of anything but a currency and should include the "ALL" namespace t...
const char * xaccAccountGetDescription(const Account *acc)
Get the account's description.
GtkTreeView * gnc_tree_view_account_new(gboolean show_root)
Create a new account tree view.
GList * gnc_account_get_children_sorted(const Account *account)
This routine returns a GList of all children accounts of the specified account, ordered by xaccAccoun...
The bank account type denotes a savings or checking account held at a bank.
dialog_commodity_mode
The dialog commodity types are used to determine what commodity namespaces the currency dialog will p...
const char * gnc_commodity_get_fullname(const gnc_commodity *cm)
Retrieve the full name for the specified commodity.
Account * gnc_account_lookup_by_full_name(const Account *any_acc, const gchar *name)
The gnc_account_lookup_full_name() subroutine works like gnc_account_lookup_by_name, but uses fully-qualified names using the given separator.
Account * gnc_tree_view_account_get_account_from_path(GncTreeViewAccount *view, GtkTreePath *s_path)
This function returns the account associated with the specified path.
void xaccTransCommitEdit(Transaction *trans)
The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are com...
void xaccAccountSetIsOpeningBalance(Account *acc, gboolean val)
Set the "opening-balance" flag for an account.
gboolean xaccAccountGetTaxRelated(const Account *acc)
DOCUMENT ME!
void xaccTransBeginEdit(Transaction *trans)
The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of...
gint gnc_account_n_children(const Account *account)
Return the number of children of the specified account.
All type declarations for the whole Gnucash engine.
void gnc_ui_new_account_window(GtkWindow *parent, QofBook *book, Account *parent_acct)
Display a window for creating a new account.
The currency account type indicates that the account is a currency trading account.
void xaccAccountSetCommoditySCU(Account *acc, int scu)
Set the SCU for the account.
GNCAccountType
The account types are used to determine how the transaction data in the account is displayed...
gboolean xaccAccountGetHidden(const Account *acc)
Get the "hidden" flag for an account.
GtkTreeModel implementation to display account types in a GtkTreeView.
Split * xaccMallocSplit(QofBook *book)
Constructor.
GList * gnc_account_get_descendants(const Account *account)
This routine returns a flat list of all of the accounts that are descendants of the specified account...
void xaccAccountSetAutoInterest(Account *acc, gboolean val)
Set the "auto interest" flag for an account.
gnc_commodity * gnc_account_or_default_currency(const Account *account, gboolean *currency_from_account_found)
Returns a gnc_commodity that is a currency, suitable for being a Transaction's currency.
gboolean xaccAccountGetIsOpeningBalance(const Account *acc)
Get the "opening-balance" flag for an account.
guint32 xaccParentAccountTypesCompatibleWith(GNCAccountType type)
Return the bitmask of parent account types compatible with a given type.
gboolean xaccAccountGetIncludeSubAccountBalances(const Account *acc)
Get whether to include balances of sub accounts.
void gnc_tree_view_account_set_selected_account(GncTreeViewAccount *view, Account *account)
This function selects an account in the account tree view.
GList * gnc_account_get_children(const Account *account)
This routine returns a GList of all children accounts of the specified account.
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.
void xaccAccountSetHidden(Account *acc, gboolean val)
Set the "hidden" flag for an account.
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
gboolean xaccAccountHasAncestor(const Account *acc, const Account *ancestor)
Returns true if the account is 'ancestor' or has 'ancestor' as an ancestor.
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
Get the account's commodity.
const GncGUID * guid_null(void)
Returns a GncGUID which is guaranteed to never reference any entity.
#define xaccAccountInsertSplit(acc, s)
The xaccAccountInsertSplit() method will insert the indicated split into the indicated 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.
void xaccAccountSetLowerBalanceLimit(Account *acc, gnc_numeric balance)
Set the lower balance limit for the account.
gboolean xaccAccountGetHigherBalanceLimit(const Account *acc, gnc_numeric *balance)
Get the higher balance limit for the account.
Account * xaccMallocAccount(QofBook *book)
Constructor.
time64 gnc_time(time64 *tbuf)
get the current time
gint64 time64
Most systems that are currently maintained, including Microsoft Windows, BSD-derived Unixes and Linux...
void xaccAccountSetDescription(Account *acc, const char *str)
Set the account's description.
void xaccAccountSetNonStdSCU(Account *acc, gboolean flag)
Set the flag indicating that this account uses a non-standard SCU.
Account * gnc_account_lookup_by_opening_balance(Account *account, gnc_commodity *commodity)
Find the opening balance account for the currency.
void xaccAccountClearHigherBalanceLimit(Account *acc)
Clear the higher balance limit for the account.
const char * xaccAccountGetName(const Account *acc)
Get the account's name.
Equity account is used to balance the balance sheet.
const char * xaccAccountGetTypeStr(GNCAccountType type)
The xaccAccountGetTypeStr() routine returns a string suitable for use in the GUI/Interface.
API for Transactions and Splits (journal entries)
The type used to store guids in C.
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
void xaccAccountSetName(Account *acc, const char *str)
Set the account's name.
"select" and "new" commodity windows
Commodity handling public routines.
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
This routine returns TRUE if the two commodities are equivalent.
const gchar * gnc_get_account_separator_string(void)
Returns the account separation character chosen by the user.
void xaccAccountSetCommodity(Account *acc, gnc_commodity *com)
Set the account's commodity.
const char * xaccAccountGetNotes(const Account *acc)
Get the account's notes.
Account * xaccAccountLookup(const GncGUID *guid, QofBook *book)
The xaccAccountLookup() subroutine will return the account associated with the given id...