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"
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 "#ededececebeb"
61 ACCOUNT_COL_FULLNAME = 0,
62 ACCOUNT_COL_FIELDNAME,
63 ACCOUNT_COL_OLD_VALUE,
64 ACCOUNT_COL_NEW_VALUE,
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_view;
106 GtkTreeView * parent_tree;
108 GtkWidget * opening_balance_edit;
109 GtkWidget * opening_balance_date_edit;
110 GtkWidget * opening_balance_page;
112 GtkWidget * opening_equity_radio;
113 GtkWidget * transfer_account_scroll;
114 GtkWidget * transfer_tree;
116 GtkWidget * tax_related_button;
117 GtkWidget * placeholder_button;
118 GtkWidget * hidden_button;
140 static GList *ac_destroy_cb_list = NULL;
145 void gnc_account_renumber_prefix_changed_cb (GtkEditable *editable,
RenumberDialog *data);
146 void gnc_account_renumber_interval_changed_cb (GtkSpinButton *spinbutton,
RenumberDialog *data);
147 void gnc_account_renumber_response_cb (GtkDialog *dialog, gint response,
RenumberDialog *data);
149 void gnc_account_window_destroy_cb (GtkObject *
object, gpointer data);
150 void opening_equity_cb (GtkWidget *w, gpointer data);
151 void gnc_account_name_changed_cb(GtkWidget *widget, gpointer data);
152 void gnc_account_color_default_cb(GtkWidget *widget, gpointer data);
153 void gnc_account_name_insert_text_cb (GtkWidget *entry,
162 aw_call_destroy_callbacks (
Account* acc)
167 for (node = ac_destroy_cb_list; node; node = node->next)
184 gnc_account_commodity_from_type (
AccountWindow * aw, gboolean update)
195 if (update && (new_mode != aw->commodity_mode))
197 gnc_general_select_set_selected(GNC_GENERAL_SELECT (aw->commodity_edit),
201 aw->commodity_mode = new_mode;
212 gboolean flag, nonstd_scu;
216 account = aw_get_account (aw);
224 if (
string == NULL)
string =
"";
225 gtk_entry_set_text(GTK_ENTRY(aw->name_entry),
string);
228 if (
string == NULL)
string =
"";
229 gtk_entry_set_text(GTK_ENTRY(aw->description_entry),
string);
232 if (
string == NULL)
string =
"";
233 if (gdk_color_parse(
string, &color))
235 gtk_color_button_set_color(GTK_COLOR_BUTTON(aw->color_entry_button), &color);
239 gnc_general_select_set_selected (GNC_GENERAL_SELECT (aw->commodity_edit),
241 gnc_account_commodity_from_type (aw, FALSE);
247 index = log10(index) + 1;
253 gtk_combo_box_set_active(GTK_COMBO_BOX(aw->account_scu), index);
256 if (
string == NULL)
string =
"";
257 gtk_entry_set_text(GTK_ENTRY(aw->code_entry),
string);
260 if (
string == NULL)
string =
"";
262 gtk_text_buffer_set_text (aw->notes_text_buffer,
string, strlen(
string));
265 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (aw->tax_related_button),
269 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (aw->placeholder_button),
273 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (aw->hidden_button),
280 gnc_account_create_transfer_balance (
QofBook *book,
292 g_return_val_if_fail (account != NULL, FALSE);
293 g_return_val_if_fail (transfer != NULL, FALSE);
338 const char *old_string;
343 gboolean use_equity, nonstd;
345 gint index, old_scu, new_scu;
346 GtkTextIter start, end;
348 account = aw_get_account (aw);
355 if (aw->dialog_type == EDIT_ACCOUNT
359 aw_call_destroy_callbacks (account);
367 last_used_account_type = aw->type;
369 string = gtk_entry_get_text (GTK_ENTRY(aw->name_entry));
371 if (g_strcmp0 (
string, old_string) != 0)
374 string = gtk_entry_get_text (GTK_ENTRY(aw->description_entry));
376 if (g_strcmp0 (
string, old_string) != 0)
379 gtk_color_button_get_color(GTK_COLOR_BUTTON(aw->color_entry_button), &color );
380 string = gdk_color_to_string(&color);
381 if (g_strcmp0 (
string, DEFAULT_COLOR) == 0)
385 if (g_strcmp0 (
string, old_string) != 0)
389 gnc_general_select_get_selected (GNC_GENERAL_SELECT (aw->commodity_edit));
401 index = gtk_combo_box_get_active(GTK_COMBO_BOX(aw->account_scu));
402 nonstd = (index != 0);
406 if (old_scu != new_scu)
409 string = gtk_entry_get_text (GTK_ENTRY(aw->code_entry));
411 if (g_strcmp0 (
string, old_string) != 0)
414 gtk_text_buffer_get_start_iter (aw->notes_text_buffer, &start);
415 gtk_text_buffer_get_end_iter (aw->notes_text_buffer, &end);
416 string = gtk_text_buffer_get_text (aw->notes_text_buffer, &start, &end, FALSE);
422 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (aw->tax_related_button));
427 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (aw->placeholder_button));
432 gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (aw->hidden_button));
438 if (parent_account == NULL)
439 parent_account = gnc_book_get_root_account(aw->book);
445 balance = gnc_amount_edit_get_amount
446 (GNC_AMOUNT_EDIT (aw->opening_balance_edit));
450 LEAVE(
"zero balance");
454 if (gnc_reverse_balance (account))
457 date = gnc_date_edit_get_date (
458 GNC_DATE_EDIT (aw->opening_balance_date_edit));
460 use_equity = gtk_toggle_button_get_active
461 (GTK_TOGGLE_BUTTON (aw->opening_equity_radio));
465 if (!gnc_account_create_opening_balance (account, balance, date, aw->book))
467 const char *message = _(
"Could not create opening balance.");
468 gnc_error_dialog(aw->dialog,
"%s", message);
478 LEAVE(
"no transfer account");
482 gnc_account_create_transfer_balance (aw->book, account, transfer, balance, date);
491 GList *children, *iter;
494 if (children == NULL)
497 for (iter = children; iter; iter = iter->next)
499 account = iter->data;
504 aw_call_destroy_callbacks (account);
510 set_children_types (account, type);
512 g_list_free(children);
520 g_return_if_fail (aw);
522 if (aw->dialog_type == NEW_ACCOUNT)
525 account = aw_get_account (aw);
526 g_return_if_fail (account);
531 set_children_types (account, aw->type);
539 gnc_suspend_gui_refresh ();
542 make_children_compatible (aw);
543 gnc_ui_to_account (aw);
545 gnc_resume_gui_refresh ();
548 if ((aw->dialog_type == NEW_ACCOUNT) && aw->next_name && *aw->next_name)
554 gnc_suspend_gui_refresh ();
556 parent = aw_get_account (aw);
564 gnc_account_to_ui (aw);
566 gnc_account_window_set_name (aw);
569 gnc_general_select_set_selected (GNC_GENERAL_SELECT (aw->commodity_edit),
571 gnc_account_commodity_from_type (aw, FALSE);
574 GNC_TREE_VIEW_ACCOUNT (aw->parent_tree), parent);
576 gnc_resume_gui_refresh ();
582 aw->created_account = aw_get_account (aw);
587 gnc_close_gui_component (aw->component_id);
593 add_children_to_expander (GObject *
object, GParamSpec *param_spec, gpointer data)
595 GtkExpander *expander = GTK_EXPANDER (
object);
597 GtkWidget *scrolled_window;
600 if (gtk_expander_get_expanded (expander) &&
601 !gtk_bin_get_child (GTK_BIN (expander)))
606 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
607 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window),
608 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
609 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW (scrolled_window),
611 gtk_container_add (GTK_CONTAINER (scrolled_window), GTK_WIDGET (view));
613 gtk_container_add (GTK_CONTAINER (expander), scrolled_window);
614 gtk_widget_show_all (scrolled_window);
625 GtkWidget *dialog, *vbox, *hbox, *label, *expander;
632 account = aw_get_account (aw);
642 dialog = gtk_dialog_new_with_buttons (
"",
643 GTK_WINDOW(aw->dialog),
644 GTK_DIALOG_DESTROY_WITH_PARENT |
646 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
647 GTK_STOCK_OK, GTK_RESPONSE_OK,
650 gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dialog), TRUE);
652 hbox = gtk_hbox_new (FALSE, 12);
653 vbox = gtk_vbox_new (FALSE, 12);
657 gtk_image_new_from_stock (GTK_STOCK_DIALOG_INFO, GTK_ICON_SIZE_DIALOG),
661 label = gtk_label_new (_(
"Give the children the same type?"));
662 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
663 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
664 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
667 PangoFontDescription *font_desc;
669 size = pango_font_description_get_size (label->style->font_desc);
670 font_desc = pango_font_description_new ();
671 pango_font_description_set_weight (font_desc, PANGO_WEIGHT_BOLD);
672 pango_font_description_set_size (font_desc, size * PANGO_SCALE_LARGE);
673 gtk_widget_modify_font (label, font_desc);
674 pango_font_description_free (font_desc);
676 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
679 str = g_strdup_printf (_(
"The children of the edited account have to be "
680 "changed to type \"%s\" to make them compatible."),
682 label = gtk_label_new (str);
684 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
685 gtk_label_set_selectable (GTK_LABEL (label), TRUE);
686 gtk_misc_set_alignment (GTK_MISC (label), 0.0, 0.0);
687 gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
690 expander = gtk_expander_new_with_mnemonic (_(
"_Show children accounts"));
691 gtk_expander_set_spacing (GTK_EXPANDER (expander), 6);
692 g_signal_connect (G_OBJECT (expander),
"notify::expanded",
693 G_CALLBACK (add_children_to_expander), account);
694 gtk_box_pack_start (GTK_BOX (vbox), expander, TRUE, TRUE, 0);
696 gtk_box_pack_start (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);
698 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (dialog)->vbox), hbox,
702 gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
703 gtk_container_set_border_width (GTK_CONTAINER (hbox), 5);
704 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->vbox), 14);
705 gtk_container_set_border_width (
706 GTK_CONTAINER (GTK_DIALOG (dialog)->action_area), 5);
707 gtk_box_set_spacing (GTK_BOX (GTK_DIALOG (dialog)->action_area), 6);
709 gtk_widget_show_all (hbox);
711 gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
713 result = (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK);
715 gtk_widget_destroy(dialog);
722 gnc_filter_parent_accounts (
Account *account, gpointer data)
725 Account *aw_account = aw_get_account (aw);
730 if (aw_account == NULL)
736 if (account == aw_account)
749 Account *root, *account, *parent;
751 gchar *fullname, *fullname_parent;
752 const gchar *name, *separator;
755 root = gnc_book_get_root_account (aw->book);
760 name = gtk_entry_get_text(GTK_ENTRY(aw->name_entry));
761 if (g_strcmp0(name,
"") == 0)
763 const char *message = _(
"The account must be given a name.");
764 gnc_error_dialog(aw->dialog,
"%s", message);
771 (GNC_TREE_VIEW_ACCOUNT (aw->parent_tree));
779 fullname = g_strconcat(fullname_parent, separator, name, NULL);
783 g_free(fullname_parent);
786 if ((account != NULL) &&
789 const char *message = _(
"There is already an account with that name.");
790 gnc_error_dialog(aw->dialog,
"%s", message);
791 LEAVE(
"duplicate name");
796 if (!gnc_filter_parent_accounts(parent, aw))
798 const char *message = _(
"You must choose a valid parent account.");
799 gnc_error_dialog(aw->dialog,
"%s", message);
800 LEAVE(
"invalid parent");
807 const char *message = _(
"You must select an account type.");
808 gnc_error_dialog(aw->dialog,
"%s", message);
809 LEAVE(
"invalid type");
816 const char *message = _(
"The selected account type is incompatible with "
817 "the one of the selected parent.");
818 gnc_error_dialog(aw->dialog,
"%s", message);
819 LEAVE(
"incompatible types");
825 gnc_general_select_get_selected (GNC_GENERAL_SELECT (aw->commodity_edit));
828 const char *message = _(
"You must choose a commodity.");
829 gnc_error_dialog(aw->dialog,
"%s", message);
830 LEAVE(
"invalid commodity");
845 account = aw_get_account (aw);
852 if (!gnc_common_ok(aw))
858 if (!verify_children_compatible (aw))
876 if (!gnc_common_ok(aw))
882 if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT (aw->opening_balance_edit)))
884 const char *message = _(
"You must enter a valid opening balance "
885 "or leave it blank.");
886 gnc_error_dialog(aw->dialog,
"%s", message);
891 balance = gnc_amount_edit_get_amount
892 (GNC_AMOUNT_EDIT (aw->opening_balance_edit));
898 use_equity = gtk_toggle_button_get_active
899 (GTK_TOGGLE_BUTTON (aw->opening_equity_radio));
908 const char *message = _(
"You must select a transfer account or choose"
909 " the opening balances equity account.");
910 gnc_error_dialog(aw->dialog,
"%s", message);
922 gnc_account_window_response_cb (GtkDialog *dialog,
928 ENTER(
"dialog %p, response %d, aw %p", dialog, response, aw);
931 case GTK_RESPONSE_OK:
932 switch (aw->dialog_type)
935 DEBUG(
"new acct dialog, OK");
936 gnc_new_account_ok (aw);
939 DEBUG(
"edit acct dialog, OK");
940 gnc_edit_account_ok (aw);
943 g_assert_not_reached ();
947 case GTK_RESPONSE_HELP:
948 switch (aw->dialog_type)
951 DEBUG(
"new acct dialog, HELP");
955 DEBUG(
"edit acct dialog, HELP");
959 g_assert_not_reached ();
963 case GTK_RESPONSE_CANCEL:
966 gnc_close_gui_component (aw->component_id);
973 gnc_account_window_destroy_cb (GtkObject *
object, gpointer data)
978 ENTER(
"object %p, aw %p",
object, aw);
979 account = aw_get_account (aw);
981 gnc_suspend_gui_refresh ();
983 switch (aw->dialog_type)
993 DEBUG (
"account add window destroyed\n");
1000 PERR (
"unexpected dialog type\n");
1001 gnc_resume_gui_refresh ();
1006 gnc_unregister_gui_component (aw->component_id);
1008 gnc_resume_gui_refresh ();
1010 if (aw->subaccount_names)
1012 g_strfreev(aw->subaccount_names);
1013 aw->subaccount_names = NULL;
1014 aw->next_name = NULL;
1022 gnc_account_parent_changed_cb (GtkTreeSelection *selection, gpointer data)
1026 guint32 types, old_types;
1027 GtkTreeModel *type_model;
1028 GtkTreeSelection *type_selection;
1029 gboolean scroll_to = FALSE;
1031 g_return_if_fail (aw);
1034 GNC_TREE_VIEW_ACCOUNT (aw->parent_tree));
1035 if (!parent_account)
1040 types = aw->valid_types;
1044 types = aw->valid_types &
1048 type_model = gtk_tree_view_get_model (GTK_TREE_VIEW (aw->type_view));
1052 if (aw->type != aw->preferred_account_type &&
1053 (types & (1 << aw->preferred_account_type)) != 0)
1056 aw->type = aw->preferred_account_type;
1059 else if ((types & (1 << aw->type)) == 0)
1067 old_types = gnc_tree_model_account_types_get_mask (type_model);
1068 if (old_types != types)
1072 gnc_tree_model_account_types_set_mask (type_model, types);
1076 type_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (aw->type_view));
1077 gnc_tree_model_account_types_set_selection(type_selection, 1 << aw->type);
1080 gnc_account_window_set_name(aw);
1084 gnc_account_type_changed_cb (GtkTreeSelection *selection, gpointer data)
1090 g_return_if_fail (aw != NULL);
1094 type_id = gnc_tree_model_account_types_get_selection_single(selection);
1102 aw->preferred_account_type = type_id;
1104 gnc_account_commodity_from_type (aw, TRUE);
1113 gtk_widget_set_sensitive (aw->opening_balance_page, sensitive);
1117 gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT (aw->opening_balance_edit),
1118 gnc_numeric_zero ());
1125 GtkTreeModel *model;
1126 GtkTreeSelection *selection;
1127 GtkCellRenderer *renderer;
1130 if (aw->valid_types == 0)
1134 aw->preferred_account_type = aw->type;
1136 else if ((aw->valid_types & (1 << aw->type)) != 0)
1139 aw->preferred_account_type = aw->type;
1141 else if ((aw->valid_types & (1 << last_used_account_type)) != 0)
1144 aw->type = last_used_account_type;
1145 aw->preferred_account_type = last_used_account_type;
1151 aw->preferred_account_type = aw->type;
1153 for (i = 0; i < 32; i++)
1154 if ((aw->valid_types & (1 << i)) != 0)
1161 model = gnc_tree_model_account_types_filter_using_mask (aw->valid_types);
1163 view = GTK_TREE_VIEW (aw->type_view);
1164 gtk_tree_view_set_model (view, model);
1165 g_object_unref (G_OBJECT (model));
1167 renderer = gtk_cell_renderer_text_new ();
1168 gtk_tree_view_insert_column_with_attributes (
1169 view, -1, NULL, renderer,
1170 "text", GNC_TREE_MODEL_ACCOUNT_TYPES_COL_NAME,
1172 gtk_tree_view_set_search_column (view, GNC_TREE_MODEL_ACCOUNT_TYPES_COL_NAME);
1174 selection = gtk_tree_view_get_selection (view);
1175 g_signal_connect (G_OBJECT (selection),
"changed",
1176 G_CALLBACK (gnc_account_type_changed_cb), aw);
1178 gnc_tree_model_account_types_set_selection(selection, 1 << aw->type);
1182 gnc_account_name_insert_text_cb (GtkWidget *entry,
1188 GtkEditable *editable = GTK_EDITABLE( entry );
1189 const gchar *separator = NULL;
1193 strsplit = g_strsplit ( text, separator, 0 );
1194 if ( strsplit[1] != NULL )
1196 gchar *result = g_strjoinv ( NULL, strsplit );
1197 g_signal_handlers_block_by_func ( G_OBJECT ( editable ),
1198 G_CALLBACK ( gnc_account_name_insert_text_cb ),
1200 gtk_editable_insert_text ( editable, result, g_utf8_strlen ( result, -1 ), position );
1201 g_signal_handlers_unblock_by_func ( G_OBJECT ( editable ),
1202 G_CALLBACK ( gnc_account_name_insert_text_cb ),
1204 g_signal_stop_emission_by_name (G_OBJECT ( editable ),
"insert_text");
1208 g_strfreev ( strsplit );
1212 gnc_account_name_changed_cb(GtkWidget *widget, gpointer data)
1216 gnc_account_window_set_name (aw);
1220 gnc_account_color_default_cb(GtkWidget *widget, gpointer data)
1225 gdk_color_parse( DEFAULT_COLOR, &color);
1226 gtk_color_button_set_color(GTK_COLOR_BUTTON(aw->color_entry_button), &color);
1235 GtkTreeSelection *selection;
1237 currency = (
gnc_commodity *) gnc_general_select_get_selected (gsl);
1241 gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT (aw->opening_balance_edit),
1243 gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT (aw->opening_balance_edit),
1244 gnc_commodity_print_info (currency, FALSE));
1246 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (aw->transfer_tree));
1247 gtk_tree_selection_unselect_all (selection);
1251 account_commodity_filter (GtkTreeSelection *selection,
1252 GtkTreeModel *unused_model,
1253 GtkTreePath *s_path,
1254 gboolean path_currently_selected,
1261 g_return_val_if_fail (GTK_IS_TREE_SELECTION (selection), FALSE);
1265 if (path_currently_selected)
1278 gnc_general_select_get_selected (GNC_GENERAL_SELECT (aw->commodity_edit));
1284 opening_equity_cb (GtkWidget *w, gpointer data)
1287 gboolean use_equity;
1289 use_equity = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (w));
1291 gtk_widget_set_sensitive (aw->transfer_account_scroll, !use_equity);
1305 GtkWidget *date_edit;
1309 GtkBuilder *builder;
1310 GtkTreeSelection *selection;
1312 ENTER(
"aw %p, modal %d", aw, aw->modal);
1313 builder = gtk_builder_new();
1314 gnc_builder_add_from_file (builder,
"dialog-account.glade",
"fraction_liststore");
1315 gnc_builder_add_from_file (builder,
"dialog-account.glade",
"Account Dialog");
1317 aw->dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"Account Dialog"));
1318 awo = G_OBJECT (aw->dialog);
1320 g_object_set_data (awo,
"dialog_info", aw);
1323 g_signal_connect (awo,
"response",
1324 G_CALLBACK (gnc_account_window_response_cb), aw);
1326 gtk_window_set_modal (GTK_WINDOW (aw->dialog), TRUE);
1328 aw->notebook = GTK_WIDGET(gtk_builder_get_object (builder,
"account_notebook"));
1329 aw->name_entry = GTK_WIDGET(gtk_builder_get_object (builder,
"name_entry"));
1330 aw->description_entry = GTK_WIDGET(gtk_builder_get_object (builder,
"description_entry"));
1331 aw->color_entry_button = GTK_WIDGET(gtk_builder_get_object (builder,
"color_entry_button"));
1332 aw->color_default_button = GTK_WIDGET(gtk_builder_get_object (builder,
"color_default_button"));
1333 aw->code_entry = GTK_WIDGET(gtk_builder_get_object (builder,
"code_entry"));
1334 aw->notes_text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (GTK_WIDGET(gtk_builder_get_object (builder,
"notes_text"))));
1336 box = GTK_WIDGET(gtk_builder_get_object (builder,
"commodity_hbox"));
1337 aw->commodity_edit = gnc_general_select_new (GNC_GENERAL_SELECT_TYPE_SELECT,
1338 gnc_commodity_edit_get_string,
1339 gnc_commodity_edit_new_select,
1340 &aw->commodity_mode);
1341 gtk_box_pack_start(GTK_BOX(box), aw->commodity_edit, TRUE, TRUE, 0);
1342 gtk_widget_show (aw->commodity_edit);
1344 label = GTK_WIDGET(gtk_builder_get_object (builder,
"security_label"));
1345 gnc_general_select_make_mnemonic_target (GNC_GENERAL_SELECT(aw->commodity_edit), label);
1347 g_signal_connect (G_OBJECT (aw->commodity_edit),
"changed",
1348 G_CALLBACK (commodity_changed_cb), aw);
1350 aw->account_scu = GTK_WIDGET(gtk_builder_get_object (builder,
"account_scu"));
1352 box = GTK_WIDGET(gtk_builder_get_object (builder,
"parent_scroll"));
1355 gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(aw->parent_tree));
1356 gtk_widget_show(GTK_WIDGET(aw->parent_tree));
1357 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (aw->parent_tree));
1358 g_signal_connect (G_OBJECT (selection),
"changed",
1359 G_CALLBACK (gnc_account_parent_changed_cb), aw);
1361 aw->tax_related_button = GTK_WIDGET(gtk_builder_get_object (builder,
"tax_related_button"));
1362 aw->placeholder_button = GTK_WIDGET(gtk_builder_get_object (builder,
"placeholder_button"));
1363 aw->hidden_button = GTK_WIDGET(gtk_builder_get_object (builder,
"hidden_button"));
1365 box = GTK_WIDGET(gtk_builder_get_object (builder,
"opening_balance_box"));
1366 amount = gnc_amount_edit_new ();
1367 aw->opening_balance_edit = amount;
1368 gtk_box_pack_start(GTK_BOX(box), amount, TRUE, TRUE, 0);
1369 gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT (amount), TRUE);
1370 gtk_widget_show (amount);
1372 label = GTK_WIDGET(gtk_builder_get_object (builder,
"balance_label"));
1373 gtk_label_set_mnemonic_widget (GTK_LABEL(label), amount);
1375 box = GTK_WIDGET(gtk_builder_get_object (builder,
"opening_balance_date_box"));
1376 date_edit = gnc_date_edit_new (
gnc_time (NULL), 1, 1);
1377 aw->opening_balance_date_edit = date_edit;
1378 gtk_box_pack_start(GTK_BOX(box), date_edit, TRUE, TRUE, 0);
1379 gtk_widget_show (date_edit);
1381 aw->opening_balance_page =
1382 gtk_notebook_get_nth_page (GTK_NOTEBOOK (aw->notebook), 1);
1384 aw->opening_equity_radio = GTK_WIDGET(gtk_builder_get_object (builder,
1385 "opening_equity_radio"));
1387 box = GTK_WIDGET(gtk_builder_get_object (builder,
"transfer_account_scroll"));
1388 aw->transfer_account_scroll = box;
1391 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(aw->transfer_tree));
1392 gtk_tree_selection_set_select_function(selection, account_commodity_filter, aw, NULL);
1394 gtk_container_add(GTK_CONTAINER(box), GTK_WIDGET(aw->transfer_tree));
1395 gtk_widget_show (GTK_WIDGET(aw->transfer_tree));
1397 label = GTK_WIDGET(gtk_builder_get_object (builder,
"parent_label"));
1398 gtk_label_set_mnemonic_widget (GTK_LABEL(label), GTK_WIDGET(aw->parent_tree));
1401 aw->type_view = GTK_WIDGET(gtk_builder_get_object (builder,
"type_view"));
1402 gnc_account_type_view_create (aw);
1404 gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(aw->dialog));
1406 gtk_widget_grab_focus(GTK_WIDGET(aw->name_entry));
1408 gtk_builder_connect_signals(builder, aw);
1409 g_object_unref(G_OBJECT(builder));
1422 name = gtk_entry_get_text (GTK_ENTRY(aw->name_entry));
1423 if (!name || *name ==
'\0')
1424 name = _(
"<No name>");
1431 const gchar *separator;
1436 fullname = g_strconcat (parent_name, separator, name, NULL);
1438 g_free (parent_name);
1441 fullname = g_strdup (name);
1452 if (!aw || !aw->parent_tree)
1455 fullname = get_ui_fullname (aw);
1457 if (aw->dialog_type == EDIT_ACCOUNT)
1458 title = g_strconcat(_(
"Edit Account"),
" - ", fullname, NULL);
1459 else if (aw->next_name && (g_strv_length(aw->next_name) > 0))
1461 const char *format = _(
"(%d) New Accounts");
1464 prefix = g_strdup_printf (format, g_strv_length(aw->next_name) + 1);
1466 title = g_strconcat (prefix,
" - ", fullname,
" ...", NULL);
1471 title = g_strconcat (_(
"New Account"),
" - ", fullname, NULL);
1473 gtk_window_set_title (GTK_WINDOW(aw->dialog), title);
1481 close_handler (gpointer user_data)
1485 ENTER(
"aw %p, modal %d", aw, aw->modal);
1486 gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(aw->dialog));
1488 gtk_widget_destroy (GTK_WIDGET (aw->dialog));
1508 gnc_account_window_set_name (aw);
1513 refresh_handler (GHashTable *changes, gpointer user_data)
1519 account = aw_get_account (aw);
1522 gnc_close_gui_component (aw->component_id);
1528 info = gnc_gui_get_entity_events (changes, &aw->account);
1529 if (info && (info->event_mask & QOF_EVENT_DESTROY))
1531 gnc_close_gui_component (aw->component_id);
1536 gnc_ui_refresh_account_window (aw);
1541 gnc_ui_new_account_window_internal (
QofBook *book,
1543 gchar **subaccount_names,
1553 g_return_val_if_fail(book, NULL);
1559 aw->dialog_type = NEW_ACCOUNT;
1561 aw->valid_types = 0;
1562 for (list = valid_types; list; list = list->next)
1563 aw->valid_types |= (1 << GPOINTER_TO_INT (list->data));
1575 aw->type = last_used_account_type;
1579 gnc_suspend_gui_refresh ();
1581 if (subaccount_names && *subaccount_names)
1584 aw->subaccount_names = subaccount_names;
1585 aw->next_name = subaccount_names + 1;
1588 gnc_account_window_create (aw);
1589 gnc_account_to_ui (aw);
1591 gnc_resume_gui_refresh ();
1593 if (default_commodity != NULL)
1595 commodity = default_commodity;
1598 gtk_entry_set_text(GTK_ENTRY(aw->name_entry),
1600 gtk_entry_set_text(GTK_ENTRY(aw->description_entry),
1606 commodity = parent_commodity;
1612 gnc_general_select_set_selected (GNC_GENERAL_SELECT (aw->commodity_edit),
1613 (gpointer) commodity);
1614 gnc_account_commodity_from_type (aw, FALSE);
1616 if (base_account == NULL)
1618 base_account = gnc_book_get_root_account(book);
1621 gtk_tree_view_collapse_all (aw->parent_tree);
1623 GNC_TREE_VIEW_ACCOUNT (aw->parent_tree), base_account);
1625 gtk_widget_show (aw->dialog);
1627 gnc_window_adjust_for_screen (GTK_WINDOW(aw->dialog));
1629 gnc_account_window_set_name (aw);
1631 aw->component_id = gnc_register_gui_component (DIALOG_NEW_ACCOUNT_CM_CLASS,
1633 modal ? NULL : close_handler,
1636 gnc_gui_component_set_session (aw->component_id, gnc_get_current_session());
1637 gnc_gui_component_watch_entity_type (aw->component_id,
1639 QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
1645 gnc_split_account_name (
QofBook *book,
const char *in_name,
Account **base_account)
1648 gchar **names, **ptr, **out_names;
1651 root = gnc_book_get_root_account (book);
1655 for (ptr = names; *ptr; ptr++)
1662 for (node = list; node; node = g_list_next(node))
1664 account = node->data;
1669 *base_account = account;
1682 out_names = g_strdupv(ptr);
1716 Account *created_account = NULL;
1717 gchar ** subaccount_names;
1719 gboolean done = FALSE;
1721 ENTER(
"name %s, valid %p, commodity %p, account %p",
1722 name, valid_types, default_commodity, parent);
1723 book = gnc_get_current_book();
1724 if (!name || *name ==
'\0')
1726 subaccount_names = NULL;
1727 base_account = NULL;
1730 subaccount_names = gnc_split_account_name (book, name, &base_account);
1734 base_account = parent;
1736 aw = gnc_ui_new_account_window_internal (book, base_account, subaccount_names,
1737 valid_types, default_commodity,
1742 response = gtk_dialog_run (GTK_DIALOG(aw->dialog));
1745 gnc_account_window_response_cb (GTK_DIALOG(aw->dialog), response, (gpointer)aw);
1749 case GTK_RESPONSE_OK:
1750 created_account = aw->created_account;
1751 done = (created_account != NULL);
1754 case GTK_RESPONSE_HELP:
1766 return created_account;
1774 find_by_account (gpointer
find_data, gpointer user_data)
1797 if (account == NULL)
1800 aw = gnc_find_first_gui_component (DIALOG_EDIT_ACCOUNT_CM_CLASS,
1801 find_by_account, account);
1804 gtk_window_present(GTK_WINDOW(aw->dialog));
1810 aw->book = gnc_account_get_book(account);
1812 aw->dialog_type = EDIT_ACCOUNT;
1814 aw->subaccount_names = NULL;
1817 gnc_suspend_gui_refresh ();
1819 gnc_account_window_create (aw);
1820 gnc_account_to_ui (aw);
1822 gnc_resume_gui_refresh ();
1824 gtk_widget_show_all (aw->dialog);
1825 gtk_widget_hide (aw->opening_balance_page);
1831 gtk_tree_view_collapse_all (aw->parent_tree);
1833 GNC_TREE_VIEW_ACCOUNT(aw->parent_tree), parent);
1835 gnc_account_window_set_name (aw);
1837 gnc_window_adjust_for_screen(GTK_WINDOW(aw->dialog));
1839 aw->component_id = gnc_register_gui_component (DIALOG_EDIT_ACCOUNT_CM_CLASS,
1843 gnc_gui_component_set_session (aw->component_id, gnc_get_current_session());
1844 gnc_gui_component_watch_entity_type (aw->component_id,
1846 QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
1848 gtk_window_present(GTK_WINDOW(aw->dialog));
1861 g_return_if_fail(book != NULL);
1863 g_return_if_fail(gnc_account_get_book(parent) == book);
1865 gnc_ui_new_account_window_internal (book, parent, NULL, NULL, NULL, FALSE);
1870 GList *valid_types )
1872 gnc_ui_new_account_window_internal( book, NULL, NULL, valid_types, NULL, FALSE );
1886 gnc_ui_register_account_destroy_callback (
void (*cb)(
Account *))
1891 if (g_list_index (ac_destroy_cb_list, cb) == -1)
1892 ac_destroy_cb_list = g_list_append (ac_destroy_cb_list, cb);
1905 unsigned int num_digits = 1;
1907 g_return_if_fail (data->num_children > 0);
1908 prefix = gtk_editable_get_chars(GTK_EDITABLE(data->prefix), 0, -1);
1909 interval = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(data->interval));
1912 num_digits = (
unsigned int)log10((
double)(data->num_children * interval)) + 1;
1914 if (strlen (prefix))
1915 str = g_strdup_printf(
"%s-%0*d", prefix, num_digits, interval);
1917 str = g_strdup_printf(
"%0*d", num_digits, interval);
1919 gtk_label_set_text(GTK_LABEL(data->example1), str);
1922 if (strlen (prefix))
1923 str = g_strdup_printf(
"%s-%0*d", prefix, num_digits,
1924 interval * data->num_children);
1926 str = g_strdup_printf(
"%0*d", num_digits,
1927 interval * data->num_children);
1929 gtk_label_set_text(GTK_LABEL(data->example2), str);
1936 gnc_account_renumber_prefix_changed_cb (GtkEditable *editable,
1939 gnc_account_renumber_update_examples(data);
1943 gnc_account_renumber_interval_changed_cb (GtkSpinButton *spinbutton,
1946 gnc_account_renumber_update_examples(data);
1950 gnc_account_renumber_response_cb (GtkDialog *dialog,
1954 GList *children = NULL, *tmp;
1958 unsigned int num_digits, i;
1960 if (response == GTK_RESPONSE_OK)
1962 gtk_widget_hide(data->dialog);
1964 if (children == NULL)
1966 PWARN (
"Can't renumber children of an account with no children!");
1970 prefix = gtk_editable_get_chars(GTK_EDITABLE(data->prefix), 0, -1);
1972 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(data->interval));
1975 num_digits = (
unsigned int)log10 ((
double)(data->num_children * interval) + 1);
1977 gnc_set_busy_cursor (NULL, TRUE);
1978 for (tmp = children, i = 1; tmp; tmp = g_list_next(tmp), i += 1)
1980 if (strlen (prefix))
1981 str = g_strdup_printf(
"%s-%0*d", prefix,
1982 num_digits, interval * i);
1984 str = g_strdup_printf(
"%0*d", num_digits, interval * i);
1988 gnc_unset_busy_cursor (NULL);
1989 g_list_free(children);
1992 gtk_widget_destroy(data->dialog);
1997 gnc_account_renumber_create_dialog (GtkWidget *window,
Account *account)
2000 GtkBuilder *builder;
2009 data->parent = account;
2012 builder = gtk_builder_new();
2013 gnc_builder_add_from_file (builder,
"dialog-account.glade",
2014 "interval_adjustment");
2015 gnc_builder_add_from_file (builder,
"dialog-account.glade",
2016 "Renumber Accounts");
2017 data->dialog = GTK_WIDGET(gtk_builder_get_object (builder,
2018 "Renumber Accounts"));
2019 gtk_window_set_transient_for(GTK_WINDOW(data->dialog), GTK_WINDOW(window));
2020 g_object_set_data_full(G_OBJECT(data->dialog),
"builder", builder,
2023 widget = GTK_WIDGET(gtk_builder_get_object (builder,
"header_label"));
2024 string = g_strdup_printf(_(
"Renumber the immediate sub-accounts of %s? "
2025 "This will replace the account code field of "
2026 "each child account with a newly generated code."),
2028 gtk_label_set_text(GTK_LABEL(widget),
string);
2031 data->prefix = GTK_WIDGET(gtk_builder_get_object (builder,
"prefix_entry"));
2032 data->interval = GTK_WIDGET(gtk_builder_get_object (builder,
"interval_spin"));
2033 data->example1 = GTK_WIDGET(gtk_builder_get_object (builder,
"example1_label"));
2034 data->example2 = GTK_WIDGET(gtk_builder_get_object (builder,
"example2_label"));
2037 gnc_account_renumber_update_examples(data);
2039 gtk_builder_connect_signals(builder, data);
2041 gtk_widget_show_all(data->dialog);
void xaccAccountSetType(Account *acc, GNCAccountType tip)
void xaccSplitSetValue(Split *s, gnc_numeric amt)
Account * gnc_account_get_parent(const Account *acc)
#define xaccTransAppendSplit(t, s)
Transaction * xaccMallocTransaction(QofBook *book)
void xaccTransSetDatePostedSecsNormalized(Transaction *trans, time64 time)
int gnc_commodity_get_fraction(const gnc_commodity *cm)
void gnc_account_append_child(Account *new_parent, Account *child)
gboolean gnc_account_is_root(const Account *account)
const char * gnc_commodity_get_mnemonic(const gnc_commodity *cm)
int xaccAccountGetCommoditySCUi(const Account *acc)
gboolean xaccAccountGetNonStdSCU(const Account *acc)
Dialog for create/edit an account.
void xaccAccountSetNotes(Account *acc, const char *str)
utility functions for the GnuCash UI
GNCAccountType xaccAccountGetType(const Account *acc)
int xaccAccountGetCommoditySCU(const Account *acc)
const char * xaccAccountGetCode(const Account *acc)
gnc_numeric gnc_numeric_neg(gnc_numeric a)
void xaccAccountSetTaxRelated(Account *acc, gboolean tax_related)
#define DEBUG(format, args...)
void xaccAccountSetCode(Account *acc, const char *str)
Account * gnc_ui_new_accounts_from_name_window(const char *name)
void xaccTransSetDescription(Transaction *trans, const char *desc)
guint32 xaccAccountTypesValid(void)
gboolean gnc_numeric_zero_p(gnc_numeric a)
#define PERR(format, args...)
#define ENTER(format, args...)
Account * gnc_ui_new_accounts_from_name_window_with_types(const char *name, GList *valid_types)
void gnc_ui_edit_account_window(Account *account)
void xaccTransSetCurrency(Transaction *trans, gnc_commodity *curr)
gnc_commodity * gnc_default_currency(void)
void xaccAccountDestroy(Account *acc)
#define PWARN(format, args...)
const char * xaccAccountGetColor(const Account *acc)
#define xaccAccountGetGUID(X)
void xaccSplitSetAmount(Split *s, gnc_numeric amt)
gchar * gnc_account_get_full_name(const Account *account)
void xaccAccountSetPlaceholder(Account *acc, gboolean val)
gboolean xaccAccountTypesCompatible(GNCAccountType parent_type, GNCAccountType child_type)
void xaccAccountSetColor(Account *acc, const char *str)
GtkTreeView implementation for gnucash account tree.
gboolean guid_equal(const GncGUID *guid_1, const GncGUID *guid_2)
GtkTreeView * gnc_tree_view_account_new_with_root(Account *root, gboolean show_root)
const char * xaccAccountGetDescription(const Account *acc)
GtkTreeView * gnc_tree_view_account_new(gboolean show_root)
gint null_strcmp(const gchar *da, const gchar *db)
GList * gnc_account_get_children_sorted(const Account *account)
const char * gnc_commodity_get_fullname(const gnc_commodity *cm)
Account * gnc_account_lookup_by_full_name(const Account *any_acc, const gchar *name)
Account * gnc_tree_view_account_get_account_from_path(GncTreeViewAccount *view, GtkTreePath *s_path)
void xaccTransCommitEdit(Transaction *trans)
gboolean xaccAccountGetTaxRelated(const Account *acc)
void xaccTransBeginEdit(Transaction *trans)
gint gnc_account_n_children(const Account *account)
void gnc_gnome_help(const char *file_name, const char *anchor)
All type declarations for the whole Gnucash engine.
void xaccAccountSetCommoditySCU(Account *acc, int scu)
gboolean xaccAccountGetHidden(const Account *acc)
GtkTreeModel implementation to display account types in a GtkTreeView.
Split * xaccMallocSplit(QofBook *book)
gnc_commodity * gnc_account_or_default_currency(const Account *account, gboolean *currency_from_account_found)
void gnc_ui_new_account_with_types(QofBook *book, GList *valid_types)
guint32 xaccParentAccountTypesCompatibleWith(GNCAccountType type)
void gnc_tree_view_account_set_selected_account(GncTreeViewAccount *view, Account *account)
GList * gnc_account_get_children(const Account *account)
void xaccAccountSetHidden(Account *acc, gboolean val)
void xaccAccountBeginEdit(Account *acc)
gboolean xaccAccountHasAncestor(const Account *acc, const Account *ancestor)
gnc_commodity * xaccAccountGetCommodity(const Account *acc)
const GncGUID * guid_null(void)
void gnc_ui_new_account_window(QofBook *book, Account *parent)
#define xaccAccountInsertSplit(acc, s)
gboolean xaccAccountGetPlaceholder(const Account *acc)
Account * gnc_tree_view_account_get_selected_account(GncTreeViewAccount *view)
#define LEAVE(format, args...)
Account * xaccMallocAccount(QofBook *book)
Account * gnc_ui_new_accounts_from_name_with_defaults(const char *name, GList *valid_types, const gnc_commodity *default_commodity, Account *parent)
time64 gnc_time(time64 *tbuf)
get the current local time
void xaccAccountSetDescription(Account *acc, const char *str)
void xaccAccountSetNonStdSCU(Account *acc, gboolean flag)
const char * xaccAccountGetName(const Account *acc)
const char * xaccAccountGetTypeStr(GNCAccountType type)
API for Transactions and Splits (journal entries)
void xaccAccountCommitEdit(Account *acc)
void xaccAccountSetName(Account *acc, const char *str)
"select" and "new" commodity windows
Commodity handling public routines.
gboolean gnc_commodity_equiv(const gnc_commodity *a, const gnc_commodity *b)
const gchar * QofLogModule
const gchar * gnc_get_account_separator_string(void)
void xaccAccountSetCommodity(Account *acc, gnc_commodity *com)
const char * xaccAccountGetNotes(const Account *acc)
Account * xaccAccountLookup(const GncGUID *guid, QofBook *book)