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 "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_view;
106 GtkTreeView *parent_tree;
107 GtkWidget *parent_scroll;
109 GtkWidget *opening_balance_button;
110 GtkWidget *opening_balance_edit;
111 GtkWidget *opening_balance_date_edit;
112 GtkWidget *opening_balance_page;
114 GtkWidget *opening_equity_radio;
115 GtkWidget *transfer_account_scroll;
116 GtkWidget *transfer_tree;
118 GtkWidget *tax_related_button;
119 GtkWidget *placeholder_button;
120 GtkWidget *hidden_button;
121 GtkWidget *auto_interest_button;
126 typedef struct _RenumberDialog
140 static QofLogModule log_module = GNC_MOD_GUI;
144 static GList *ac_destroy_cb_list = NULL;
149 void gnc_account_renumber_prefix_changed_cb (GtkEditable *editable,
RenumberDialog *data);
150 void gnc_account_renumber_interval_changed_cb (GtkSpinButton *spinbutton,
RenumberDialog *data);
151 void gnc_account_renumber_digits_changed_cb (GtkSpinButton *spinbutton,
RenumberDialog *data);
152 void gnc_account_renumber_response_cb (GtkDialog *dialog, gint response,
RenumberDialog *data);
154 void gnc_account_window_destroy_cb (GtkWidget *
object, gpointer data);
155 void opening_equity_cb (GtkWidget *w, gpointer data);
156 static void gnc_account_parent_changed_cb (GtkTreeSelection *selection, gpointer data);
157 void gnc_account_name_changed_cb (GtkWidget *widget, gpointer data);
158 void gnc_account_color_default_cb (GtkWidget *widget, gpointer data);
159 void gnc_account_name_insert_text_cb (GtkWidget *entry,
169 aw_call_destroy_callbacks (
Account* acc)
174 for (node = ac_destroy_cb_list; node; node = node->next)
191 gnc_account_commodity_from_type (
AccountWindow * aw, gboolean update)
202 if (update && (new_mode != aw->commodity_mode))
204 gnc_general_select_set_selected (GNC_GENERAL_SELECT(aw->commodity_edit),
207 aw->commodity_mode = new_mode;
211 gnc_account_opening_balance_button_update (
AccountWindow *aw, gnc_commodity *commodity)
213 Account *account = aw_get_account (aw);
219 gtk_widget_set_sensitive (aw->opening_balance_button, FALSE);
227 if (!gnc_using_equity_type_opening_balance_account (gnc_get_current_book()))
230 switch (aw->dialog_type)
233 gtk_widget_set_sensitive (aw->opening_balance_button, (ob_account == NULL ||
234 ob_account == account) &&
238 gtk_widget_set_sensitive (aw->opening_balance_button, ob_account == NULL);
248 gnc_commodity * commodity;
251 gboolean flag, nonstd_scu;
255 account = aw_get_account (aw);
265 gtk_entry_set_text (GTK_ENTRY(aw->name_entry),
string);
270 gtk_entry_set_text (GTK_ENTRY(aw->description_entry),
string);
275 string = DEFAULT_COLOR;
277 if (!gdk_rgba_parse (&color,
string))
278 gdk_rgba_parse (&color, DEFAULT_COLOR);
280 gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER(aw->color_entry_button), &color);
283 gnc_general_select_set_selected (GNC_GENERAL_SELECT(aw->commodity_edit),
285 gnc_account_commodity_from_type (aw, FALSE);
291 index = log10 (index) + 1;
297 gtk_combo_box_set_active (GTK_COMBO_BOX(aw->account_scu), index);
302 gtk_entry_set_text (GTK_ENTRY(aw->code_entry),
string);
308 gtk_text_buffer_set_text (aw->notes_text_buffer,
string, strlen(
string));
310 gnc_account_opening_balance_button_update (aw, commodity);
313 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(aw->opening_balance_button),
317 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(aw->tax_related_button),
321 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(aw->placeholder_button),
325 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(aw->hidden_button),
328 set_auto_interest_box (aw);
333 gnc_account_create_transfer_balance (QofBook *book,
345 g_return_val_if_fail (account != NULL, FALSE);
346 g_return_val_if_fail (transfer != NULL, FALSE);
389 gnc_commodity *commodity;
391 const char *old_string;
396 gboolean use_equity, nonstd;
398 gint index, old_scu, new_scu;
399 GtkTextIter start, end;
401 account = aw_get_account (aw);
408 if (aw->dialog_type == EDIT_ACCOUNT
412 aw_call_destroy_callbacks (account);
420 last_used_account_type = aw->type;
422 string = gtk_entry_get_text (GTK_ENTRY(aw->name_entry));
424 if (g_strcmp0 (
string, old_string) != 0)
427 string = gtk_entry_get_text (GTK_ENTRY(aw->description_entry));
429 if (g_strcmp0 (
string, old_string) != 0)
432 gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER(aw->color_entry_button), &color);
433 string = gdk_rgba_to_string (&color);
435 if (g_strcmp0 (
string, DEFAULT_COLOR) == 0)
440 if (!
string && old_string)
444 if (g_strcmp0 (
string, old_string) != 0)
448 commodity = (gnc_commodity *)
449 gnc_general_select_get_selected (GNC_GENERAL_SELECT(aw->commodity_edit));
461 index = gtk_combo_box_get_active (GTK_COMBO_BOX(aw->account_scu));
462 nonstd = (index != 0);
466 if (old_scu != new_scu)
469 string = gtk_entry_get_text (GTK_ENTRY(aw->code_entry));
471 if (g_strcmp0 (
string, old_string) != 0)
474 gtk_text_buffer_get_start_iter (aw->notes_text_buffer, &start);
475 gtk_text_buffer_get_end_iter (aw->notes_text_buffer, &end);
476 string = gtk_text_buffer_get_text (aw->notes_text_buffer, &start, &end, FALSE);
481 flag = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(aw->opening_balance_button));
485 flag = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(aw->tax_related_button));
489 flag = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(aw->placeholder_button));
493 flag = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(aw->hidden_button));
497 flag = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(aw->auto_interest_button));
503 if (parent_account == NULL)
504 parent_account = gnc_book_get_root_account (aw->book);
510 balance = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT(aw->opening_balance_edit));
514 LEAVE(
"zero balance");
518 if (gnc_reverse_balance (account))
521 date = gnc_date_edit_get_date (GNC_DATE_EDIT(aw->opening_balance_date_edit));
523 use_equity = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(aw->opening_equity_radio));
527 if (!gnc_account_create_opening_balance (account, balance, date, aw->book))
529 const char *message = _(
"Could not create opening balance.");
530 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
540 LEAVE(
"no transfer account");
544 gnc_account_create_transfer_balance (aw->book, account, transfer, balance, date);
552 GList *children, *iter;
555 if (children == NULL)
558 for (iter = children; iter; iter = iter->next)
560 account = iter->data;
565 aw_call_destroy_callbacks (account);
571 set_children_types (account, type);
573 g_list_free (children);
581 g_return_if_fail (aw);
583 if (aw->dialog_type == NEW_ACCOUNT)
586 account = aw_get_account (aw);
587 g_return_if_fail (account);
592 set_children_types (account, aw->type);
599 gnc_suspend_gui_refresh ();
602 make_children_compatible (aw);
603 gnc_ui_to_account (aw);
605 gnc_resume_gui_refresh ();
608 if ((aw->dialog_type == NEW_ACCOUNT) && aw->next_name && *aw->next_name)
610 gnc_commodity *commodity;
613 GtkTreeSelection *selection;
616 gtk_container_remove (GTK_CONTAINER(aw->parent_scroll), GTK_WIDGET(aw->parent_tree));
618 gtk_container_add (GTK_CONTAINER(aw->parent_scroll), GTK_WIDGET(aw->parent_tree));
619 gtk_widget_show (GTK_WIDGET(aw->parent_tree));
621 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(aw->parent_tree));
622 g_signal_connect (G_OBJECT(selection),
"changed",
623 G_CALLBACK(gnc_account_parent_changed_cb), aw);
625 gnc_suspend_gui_refresh ();
627 parent = aw_get_account (aw);
635 gnc_account_to_ui (aw);
637 gnc_account_window_set_name (aw);
640 gnc_general_select_set_selected (GNC_GENERAL_SELECT(aw->commodity_edit),
642 gnc_account_commodity_from_type (aw, FALSE);
648 gnc_resume_gui_refresh ();
654 aw->created_account = aw_get_account (aw);
659 gnc_close_gui_component (aw->component_id);
664 add_children_to_expander (GObject *
object, GParamSpec *param_spec, gpointer data)
666 GtkExpander *expander = GTK_EXPANDER(
object);
668 GtkWidget *scrolled_window;
671 if (gtk_expander_get_expanded (expander) &&
672 !gtk_bin_get_child (GTK_BIN(expander)))
676 scrolled_window = gtk_scrolled_window_new (NULL, NULL);
677 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(scrolled_window),
678 GTK_POLICY_AUTOMATIC,
679 GTK_POLICY_AUTOMATIC);
680 gtk_scrolled_window_set_shadow_type (GTK_SCROLLED_WINDOW(scrolled_window),
682 gtk_container_add (GTK_CONTAINER(scrolled_window), GTK_WIDGET(view));
684 gtk_container_add (GTK_CONTAINER(expander), scrolled_window);
685 gtk_widget_set_vexpand (GTK_WIDGET(scrolled_window), TRUE);
686 gtk_widget_show_all (scrolled_window);
697 GtkWidget *dialog, *vbox, *hbox, *label, *expander;
704 account = aw_get_account (aw);
714 dialog = gtk_dialog_new_with_buttons (
"",
715 GTK_WINDOW(aw->dialog),
716 GTK_DIALOG_DESTROY_WITH_PARENT |
718 _(
"_Cancel"), GTK_RESPONSE_CANCEL,
719 _(
"_OK"), GTK_RESPONSE_OK,
722 gtk_window_set_skip_taskbar_hint (GTK_WINDOW(dialog), TRUE);
724 hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 12);
725 gtk_box_set_homogeneous (GTK_BOX(hbox), FALSE);
726 vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 12);
727 gtk_box_set_homogeneous (GTK_BOX(vbox), FALSE);
729 gtk_box_pack_start (GTK_BOX(hbox),
730 gtk_image_new_from_icon_name (
"dialog-information",
731 GTK_ICON_SIZE_DIALOG), FALSE, FALSE, 0);
734 label = gtk_label_new (_(
"Give the children the same type?"));
735 gtk_label_set_line_wrap (GTK_LABEL(label), TRUE);
736 gtk_label_set_selectable (GTK_LABEL(label), TRUE);
737 gnc_label_set_alignment (label, 0.0, 0.0);
740 gnc_widget_style_context_add_class (GTK_WIDGET(label),
"gnc-class-title");
742 gtk_box_pack_start (GTK_BOX(vbox), label, FALSE, FALSE, 0);
745 str = g_strdup_printf (_(
"The children of the edited account have to be " 746 "changed to type \"%s\" to make them compatible."),
748 label = gtk_label_new (str);
750 gtk_label_set_line_wrap (GTK_LABEL(label), TRUE);
751 gtk_label_set_selectable (GTK_LABEL(label), TRUE);
752 gnc_label_set_alignment (label, 0.0, 0.0);
753 gtk_box_pack_start (GTK_BOX(vbox), label, FALSE, FALSE, 0);
756 expander = gtk_expander_new_with_mnemonic (_(
"_Show children accounts"));
757 gtk_expander_set_spacing (GTK_EXPANDER(expander), 6);
758 g_signal_connect (G_OBJECT(expander),
"notify::expanded",
759 G_CALLBACK(add_children_to_expander), account);
760 gtk_box_pack_start (GTK_BOX(vbox), expander, TRUE, TRUE, 0);
762 gtk_box_pack_start (GTK_BOX(hbox), vbox, TRUE, TRUE, 0);
764 gtk_box_pack_start (GTK_BOX(gtk_dialog_get_content_area (GTK_DIALOG(dialog))),
765 hbox, TRUE, TRUE, 0);
768 gtk_container_set_border_width (GTK_CONTAINER(dialog), 5);
769 gtk_container_set_border_width (GTK_CONTAINER(hbox), 5);
770 gtk_box_set_spacing (GTK_BOX(gtk_dialog_get_content_area (GTK_DIALOG(dialog))), 14);
772 gtk_widget_show_all (hbox);
774 gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_OK);
776 result = (gtk_dialog_run (GTK_DIALOG(dialog)) == GTK_RESPONSE_OK);
778 gtk_widget_destroy (dialog);
784 gnc_filter_parent_accounts (
Account *account, gpointer data)
787 Account *aw_account = aw_get_account (aw);
792 if (aw_account == NULL)
798 if (account == aw_account)
810 Account *root, *account, *parent;
811 gnc_commodity * commodity;
812 gchar *fullname, *fullname_parent;
813 const gchar *name, *separator;
816 root = gnc_book_get_root_account (aw->book);
821 name = gtk_entry_get_text (GTK_ENTRY(aw->name_entry));
822 if (g_strcmp0 (name,
"") == 0)
824 const char *message = _(
"The account must be given a name.");
825 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
832 (GNC_TREE_VIEW_ACCOUNT(aw->parent_tree));
840 fullname = g_strconcat (fullname_parent, separator, name, NULL);
844 g_free (fullname_parent);
847 if ((account != NULL) &&
850 const char *message = _(
"There is already an account with that name.");
851 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
852 LEAVE(
"duplicate name");
857 if (!gnc_filter_parent_accounts (parent, aw))
859 const char *message = _(
"You must choose a valid parent account.");
860 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
861 LEAVE(
"invalid parent");
868 const char *message = _(
"You must select an account type.");
869 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
870 LEAVE(
"invalid type");
877 const char *message = _(
"The selected account type is incompatible with " 878 "the one of the selected parent.");
879 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
880 LEAVE(
"incompatible types");
885 commodity = (gnc_commodity *)
886 gnc_general_select_get_selected (GNC_GENERAL_SELECT(aw->commodity_edit));
889 const char *message = _(
"You must choose a commodity.");
890 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
891 LEAVE(
"invalid commodity");
906 account = aw_get_account (aw);
913 if (!gnc_common_ok (aw))
919 if (!verify_children_compatible (aw))
936 if (!gnc_common_ok (aw))
942 if (!gnc_amount_edit_evaluate (GNC_AMOUNT_EDIT(aw->opening_balance_edit), NULL))
944 const char *message = _(
"You must enter a valid opening balance " 945 "or leave it blank.");
946 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
951 balance = gnc_amount_edit_get_amount (GNC_AMOUNT_EDIT(aw->opening_balance_edit));
957 use_equity = gtk_toggle_button_get_active
958 (GTK_TOGGLE_BUTTON(aw->opening_equity_radio));
968 const char *message = _(
"You must select a transfer account or choose" 969 " the opening balances equity account.");
970 gnc_error_dialog (GTK_WINDOW(aw->dialog),
"%s", message);
982 gnc_account_window_response_cb (GtkDialog *dialog,
988 ENTER(
"dialog %p, response %d, aw %p", dialog, response, aw);
991 case GTK_RESPONSE_OK:
992 switch (aw->dialog_type)
995 DEBUG(
"new acct dialog, OK");
996 gnc_new_account_ok (aw);
999 DEBUG(
"edit acct dialog, OK");
1000 gnc_edit_account_ok (aw);
1003 g_assert_not_reached ();
1007 case GTK_RESPONSE_HELP:
1008 switch (aw->dialog_type)
1011 DEBUG(
"new acct dialog, HELP");
1015 DEBUG(
"edit acct dialog, HELP");
1019 g_assert_not_reached ();
1023 case GTK_RESPONSE_CANCEL:
1026 gnc_close_gui_component (aw->component_id);
1033 gnc_account_window_destroy_cb (GtkWidget *
object, gpointer data)
1038 ENTER(
"object %p, aw %p",
object, aw);
1039 account = aw_get_account (aw);
1041 gnc_suspend_gui_refresh ();
1043 switch (aw->dialog_type)
1046 if (account != NULL)
1053 DEBUG (
"account add window destroyed\n");
1060 PERR (
"unexpected dialog type\n");
1061 gnc_resume_gui_refresh ();
1066 gnc_unregister_gui_component (aw->component_id);
1068 gnc_resume_gui_refresh ();
1070 if (aw->subaccount_names)
1072 g_strfreev (aw->subaccount_names);
1073 aw->subaccount_names = NULL;
1074 aw->next_name = NULL;
1082 gnc_account_parent_changed_cb (GtkTreeSelection *selection, gpointer data)
1086 guint32 types, old_types;
1087 GtkTreeModel *type_model;
1088 GtkTreeSelection *type_selection;
1089 gboolean scroll_to = FALSE;
1091 g_return_if_fail (aw);
1094 GNC_TREE_VIEW_ACCOUNT(aw->parent_tree));
1095 if (!parent_account)
1100 types = aw->valid_types;
1104 types = aw->valid_types &
1108 type_model = gtk_tree_view_get_model (GTK_TREE_VIEW(aw->type_view));
1112 if (aw->type != aw->preferred_account_type &&
1113 (types & (1 << aw->preferred_account_type)) != 0)
1116 aw->type = aw->preferred_account_type;
1119 else if ((types & (1 << aw->type)) == 0)
1127 old_types = gnc_tree_model_account_types_get_mask (type_model);
1128 if (old_types != types)
1132 gnc_tree_model_account_types_set_mask (type_model, types);
1136 type_selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(aw->type_view));
1137 gnc_tree_model_account_types_set_selection (type_selection, 1 << aw->type);
1140 gnc_account_window_set_name (aw);
1146 Account* account = aw_get_account (aw);
1147 gboolean type_ok = account_type_has_auto_interest_xfer (aw->type);
1149 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(aw->auto_interest_button),
1150 type_ok && pref_set);
1151 gtk_widget_set_sensitive (GTK_WIDGET(aw->auto_interest_button), type_ok);
1155 gnc_account_type_changed_cb (GtkTreeSelection *selection, gpointer data)
1161 g_return_if_fail (aw != NULL);
1165 type_id = gnc_tree_model_account_types_get_selection_single (selection);
1173 aw->preferred_account_type = type_id;
1175 gnc_account_commodity_from_type (aw, TRUE);
1184 gtk_widget_set_sensitive (aw->opening_balance_page, sensitive);
1188 gnc_amount_edit_set_amount (GNC_AMOUNT_EDIT(aw->opening_balance_edit),
1189 gnc_numeric_zero ());
1191 set_auto_interest_box (aw);
1195 gnc_account_type_view_create (
AccountWindow *aw, guint32 compat_types)
1197 GtkTreeModel *model;
1198 GtkTreeSelection *selection;
1199 GtkCellRenderer *renderer;
1202 aw->valid_types &= compat_types;
1203 if (aw->valid_types == 0)
1206 aw->valid_types = compat_types | (1 << aw->type);
1207 aw->preferred_account_type = aw->type;
1209 else if ((aw->valid_types & (1 << aw->type)) != 0)
1212 aw->preferred_account_type = aw->type;
1214 else if ((aw->valid_types & (1 << last_used_account_type)) != 0)
1217 aw->type = last_used_account_type;
1218 aw->preferred_account_type = last_used_account_type;
1224 aw->preferred_account_type = aw->type;
1226 for (i = 0; i < 32; i++)
1227 if ((aw->valid_types & (1 << i)) != 0)
1234 model = gnc_tree_model_account_types_filter_using_mask (aw->valid_types);
1236 view = GTK_TREE_VIEW(aw->type_view);
1237 gtk_tree_view_set_model (view, model);
1238 g_object_unref (G_OBJECT(model));
1240 renderer = gtk_cell_renderer_text_new ();
1241 gtk_tree_view_insert_column_with_attributes (view, -1, NULL, renderer,
"text",
1242 GNC_TREE_MODEL_ACCOUNT_TYPES_COL_NAME,
1244 gtk_tree_view_set_search_column (view, GNC_TREE_MODEL_ACCOUNT_TYPES_COL_NAME);
1246 selection = gtk_tree_view_get_selection (view);
1247 g_signal_connect (G_OBJECT(selection),
"changed",
1248 G_CALLBACK(gnc_account_type_changed_cb), aw);
1250 gnc_tree_model_account_types_set_selection (selection, 1 << aw->type);
1254 gnc_account_name_insert_text_cb (GtkWidget *entry,
1260 GtkEditable *editable = GTK_EDITABLE(entry);
1261 const gchar *separator = NULL;
1265 strsplit = g_strsplit (text, separator, 0);
1266 if (strsplit[1] != NULL)
1268 gchar *result = g_strjoinv (NULL, strsplit);
1269 g_signal_handlers_block_by_func (G_OBJECT(editable),
1270 G_CALLBACK(gnc_account_name_insert_text_cb),
1272 gtk_editable_insert_text (editable, result, g_utf8_strlen (result, -1), position);
1273 g_signal_handlers_unblock_by_func (G_OBJECT(editable),
1274 G_CALLBACK(gnc_account_name_insert_text_cb),
1276 g_signal_stop_emission_by_name (G_OBJECT(editable),
"insert_text");
1280 g_strfreev (strsplit);
1284 gnc_account_name_changed_cb (GtkWidget *widget, gpointer data)
1288 gnc_account_window_set_name (aw);
1292 gnc_account_color_default_cb (GtkWidget *widget, gpointer data)
1297 gdk_rgba_parse (&color, DEFAULT_COLOR);
1298 gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER(aw->color_entry_button), &color);
1306 gnc_commodity *currency;
1307 GtkTreeSelection *selection;
1308 Account *account = aw_get_account (aw);
1310 currency = (gnc_commodity *) gnc_general_select_get_selected (gsl);
1317 if (ob_account != account)
1319 gchar *dialog_msg = _(
"An account with opening balance already exists for the desired currency.");
1320 gchar *dialog_title = _(
"Cannot change currency");
1325 "%s", dialog_title);
1326 gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG(dialog),
1328 gtk_dialog_run (GTK_DIALOG(dialog));
1329 gtk_widget_destroy (dialog);
1330 g_signal_handlers_block_by_func (gsl, commodity_changed_cb, data);
1332 g_signal_handlers_unblock_by_func (gsl, commodity_changed_cb, data);
1337 gnc_amount_edit_set_fraction (GNC_AMOUNT_EDIT(aw->opening_balance_edit),
1339 gnc_amount_edit_set_print_info (GNC_AMOUNT_EDIT(aw->opening_balance_edit),
1340 gnc_commodity_print_info (currency, FALSE));
1342 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(aw->transfer_tree));
1343 gtk_tree_selection_unselect_all (selection);
1344 gnc_account_opening_balance_button_update (aw, currency);
1348 account_commodity_filter (GtkTreeSelection *selection,
1349 GtkTreeModel *unused_model,
1350 GtkTreePath *s_path,
1351 gboolean path_currently_selected,
1354 gnc_commodity *commodity;
1358 g_return_val_if_fail (GTK_IS_TREE_SELECTION(selection), FALSE);
1362 if (path_currently_selected)
1374 commodity = (gnc_commodity *)
1375 gnc_general_select_get_selected (GNC_GENERAL_SELECT(aw->commodity_edit));
1381 opening_equity_cb (GtkWidget *w, gpointer data)
1384 gboolean use_equity;
1386 use_equity = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(w));
1388 gtk_widget_set_sensitive (aw->transfer_account_scroll, !use_equity);
1400 gnc_account_window_create (GtkWindow *parent,
AccountWindow *aw)
1403 GtkWidget *date_edit;
1407 GtkBuilder *builder;
1408 GtkTreeSelection *selection;
1409 const gchar *tt = _(
"This Account contains Transactions.\nChanging this option is not possible.");
1412 ENTER(
"aw %p, modal %d", aw, aw->modal);
1413 builder = gtk_builder_new ();
1414 gnc_builder_add_from_file (builder,
"dialog-account.glade",
"fraction_liststore");
1415 gnc_builder_add_from_file (builder,
"dialog-account.glade",
"account_dialog");
1417 aw->dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"account_dialog"));
1418 awo = G_OBJECT(aw->dialog);
1421 gtk_window_set_transient_for (GTK_WINDOW(aw->dialog), parent);
1424 gtk_widget_set_name (GTK_WIDGET(aw->dialog),
"gnc-id-account");
1425 gnc_widget_style_context_add_class (GTK_WIDGET(aw->dialog),
"gnc-class-account");
1428 g_object_set_data (awo,
"dialog_info", aw);
1431 g_signal_connect (awo,
"response",
1432 G_CALLBACK(gnc_account_window_response_cb), aw);
1434 gtk_window_set_modal (GTK_WINDOW(aw->dialog), TRUE);
1436 aw->notebook = GTK_WIDGET(gtk_builder_get_object (builder,
"account_notebook"));
1437 aw->name_entry = GTK_WIDGET(gtk_builder_get_object (builder,
"name_entry"));
1438 aw->description_entry = GTK_WIDGET(gtk_builder_get_object (builder,
"description_entry"));
1439 aw->color_entry_button = GTK_WIDGET(gtk_builder_get_object (builder,
"color_entry_button"));
1440 aw->color_default_button = GTK_WIDGET(gtk_builder_get_object (builder,
"color_default_button"));
1441 aw->code_entry = GTK_WIDGET(gtk_builder_get_object (builder,
"code_entry"));
1442 aw->notes_text_buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(GTK_WIDGET(
1443 gtk_builder_get_object (builder,
1446 box = GTK_WIDGET(gtk_builder_get_object (builder,
"commodity_hbox"));
1447 aw->commodity_edit = gnc_general_select_new (GNC_GENERAL_SELECT_TYPE_SELECT,
1448 gnc_commodity_edit_get_string,
1449 gnc_commodity_edit_new_select,
1450 &aw->commodity_mode);
1456 aw_get_account (aw)));
1457 GtkWidget *label = gtk_label_new (sec_name);
1458 gtk_widget_set_tooltip_text (label, tt);
1459 gtk_box_pack_start (GTK_BOX(box), label, FALSE, FALSE, 0);
1460 gtk_widget_show (label);
1464 gtk_box_pack_start (GTK_BOX(box), aw->commodity_edit, TRUE, TRUE, 0);
1465 gtk_widget_show (aw->commodity_edit);
1468 label = GTK_WIDGET(gtk_builder_get_object (builder,
"security_label"));
1469 gnc_general_select_make_mnemonic_target (GNC_GENERAL_SELECT(aw->commodity_edit), label);
1471 g_signal_connect (G_OBJECT(aw->commodity_edit),
"changed",
1472 G_CALLBACK(commodity_changed_cb), aw);
1474 aw->account_scu = GTK_WIDGET(gtk_builder_get_object (builder,
"account_scu"));
1476 aw->parent_scroll = GTK_WIDGET(gtk_builder_get_object (builder,
"parent_scroll"));
1479 gtk_container_add (GTK_CONTAINER(aw->parent_scroll), GTK_WIDGET(aw->parent_tree));
1480 gtk_widget_show (GTK_WIDGET(aw->parent_tree));
1481 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(aw->parent_tree));
1483 g_signal_connect (G_OBJECT(selection),
"changed",
1484 G_CALLBACK(gnc_account_parent_changed_cb), aw);
1486 aw->opening_balance_button = GTK_WIDGET(gtk_builder_get_object (builder,
"opening_balance_button"));
1487 aw->tax_related_button = GTK_WIDGET(gtk_builder_get_object (builder,
"tax_related_button"));
1488 aw->placeholder_button = GTK_WIDGET(gtk_builder_get_object (builder,
"placeholder_button"));
1489 aw->hidden_button = GTK_WIDGET(gtk_builder_get_object (builder,
"hidden_button"));
1490 aw->auto_interest_button = GTK_WIDGET(gtk_builder_get_object (builder,
"auto_interest_button"));
1491 set_auto_interest_box (aw);
1494 box = GTK_WIDGET(gtk_builder_get_object (builder,
"opening_balance_box"));
1495 amount = gnc_amount_edit_new ();
1496 aw->opening_balance_edit = amount;
1497 gtk_box_pack_start (GTK_BOX(box), amount, TRUE, TRUE, 0);
1498 gnc_amount_edit_set_evaluate_on_enter (GNC_AMOUNT_EDIT(amount), TRUE);
1499 gtk_widget_show (amount);
1501 label = GTK_WIDGET(gtk_builder_get_object (builder,
"balance_label"));
1502 gnc_amount_edit_make_mnemonic_target (GNC_AMOUNT_EDIT(amount), label);
1504 box = GTK_WIDGET(gtk_builder_get_object (builder,
"opening_balance_date_box"));
1505 label = GTK_WIDGET(gtk_builder_get_object (builder,
"date_label"));
1506 date_edit = gnc_date_edit_new (
gnc_time (NULL), 0, 0);
1507 gnc_date_make_mnemonic_target (GNC_DATE_EDIT(date_edit), label);
1508 aw->opening_balance_date_edit = date_edit;
1509 gtk_box_pack_start (GTK_BOX(box), date_edit, TRUE, TRUE, 0);
1510 gtk_widget_show (date_edit);
1512 aw->opening_balance_page =
1513 gtk_notebook_get_nth_page (GTK_NOTEBOOK(aw->notebook), 1);
1515 aw->opening_equity_radio = GTK_WIDGET(gtk_builder_get_object (builder,
1516 "opening_equity_radio"));
1518 box = GTK_WIDGET(gtk_builder_get_object (builder,
"transfer_account_scroll"));
1519 aw->transfer_account_scroll = box;
1522 selection = gtk_tree_view_get_selection (GTK_TREE_VIEW(aw->transfer_tree));
1523 gtk_tree_selection_set_select_function (selection, account_commodity_filter, aw, NULL);
1525 gtk_container_add (GTK_CONTAINER(box), GTK_WIDGET(aw->transfer_tree));
1526 gtk_widget_show (GTK_WIDGET(aw->transfer_tree));
1528 label = GTK_WIDGET(gtk_builder_get_object (builder,
"parent_label"));
1529 gtk_label_set_mnemonic_widget (GTK_LABEL(label), GTK_WIDGET(aw->parent_tree));
1532 aw->type_view = GTK_WIDGET(gtk_builder_get_object (builder,
"type_view"));
1549 gnc_account_type_view_create (aw, compat_types);
1551 gnc_restore_window_size (GNC_PREFS_GROUP, GTK_WINDOW(aw->dialog), parent);
1553 gtk_widget_grab_focus (GTK_WIDGET(aw->name_entry));
1555 gtk_builder_connect_signals (builder, aw);
1556 g_object_unref (G_OBJECT(builder));
1568 name = gtk_entry_get_text (GTK_ENTRY(aw->name_entry));
1569 if (!name || *name ==
'\0')
1570 name = _(
"<No name>");
1579 fullname = g_strconcat (parent_name, separator, name, NULL);
1580 g_free (parent_name);
1583 fullname = g_strdup (name);
1594 if (!aw || !aw->parent_tree)
1597 fullname = get_ui_fullname (aw);
1599 if (aw->dialog_type == EDIT_ACCOUNT)
1600 title = g_strconcat(_(
"Edit Account"),
" - ", fullname, NULL);
1601 else if (aw->next_name && (g_strv_length (aw->next_name) > 0))
1603 const char *format = _(
"(%d) New Accounts");
1604 char *prefix = g_strdup_printf (format,
1605 g_strv_length (aw->next_name) + 1);
1607 title = g_strconcat (prefix,
" - ", fullname,
" ...", NULL);
1611 title = g_strconcat (_(
"New Account"),
" - ", fullname, NULL);
1613 gtk_window_set_title (GTK_WINDOW(aw->dialog), title);
1620 close_handler (gpointer user_data)
1624 ENTER(
"aw %p, modal %d", aw, aw->modal);
1625 gnc_save_window_size (GNC_PREFS_GROUP, GTK_WINDOW(aw->dialog));
1627 gtk_widget_destroy (GTK_WIDGET(aw->dialog));
1646 gnc_account_window_set_name (aw);
1650 refresh_handler (GHashTable *changes, gpointer user_data)
1655 account = aw_get_account (aw);
1658 gnc_close_gui_component (aw->component_id);
1664 const EventInfo *info = gnc_gui_get_entity_events (changes, &aw->account);
1665 if (info && (info->event_mask & QOF_EVENT_DESTROY))
1667 gnc_close_gui_component (aw->component_id);
1671 gnc_ui_refresh_account_window (aw);
1675 gnc_ui_new_account_window_internal (GtkWindow *parent,
1678 gchar **subaccount_names,
1680 const gnc_commodity * default_commodity,
1683 const gnc_commodity *commodity, *parent_commodity;
1688 g_return_val_if_fail(book, NULL);
1694 aw->dialog_type = NEW_ACCOUNT;
1696 aw->valid_types = 0;
1697 for (list = valid_types; list; list = list->next)
1698 aw->valid_types |= (1 << GPOINTER_TO_INT (list->data));
1710 aw->type = last_used_account_type;
1714 gnc_suspend_gui_refresh ();
1716 if (subaccount_names && *subaccount_names)
1719 aw->subaccount_names = subaccount_names;
1720 aw->next_name = subaccount_names + 1;
1723 gnc_account_window_create (parent, aw);
1724 gnc_account_to_ui (aw);
1726 gnc_resume_gui_refresh ();
1728 if (default_commodity != NULL)
1730 commodity = default_commodity;
1733 gtk_entry_set_text (GTK_ENTRY(aw->name_entry),
1735 gtk_entry_set_text (GTK_ENTRY(aw->description_entry),
1741 commodity = parent_commodity;
1747 gnc_general_select_set_selected (GNC_GENERAL_SELECT(aw->commodity_edit),
1748 (gpointer) commodity);
1749 gnc_account_commodity_from_type (aw, FALSE);
1751 if (base_account == NULL)
1753 base_account = gnc_book_get_root_account (book);
1756 gtk_tree_view_collapse_all (aw->parent_tree);
1761 gtk_widget_show (aw->dialog);
1763 gnc_window_adjust_for_screen (GTK_WINDOW(aw->dialog));
1765 gnc_account_window_set_name (aw);
1767 aw->component_id = gnc_register_gui_component (DIALOG_NEW_ACCOUNT_CM_CLASS,
1769 modal ? NULL : close_handler,
1772 gnc_gui_component_set_session (aw->component_id, gnc_get_current_session());
1773 gnc_gui_component_watch_entity_type (aw->component_id,
1775 QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
1780 gnc_split_account_name (QofBook *book,
const char *in_name,
Account **base_account)
1783 gchar **names, **ptr, **out_names;
1786 root = gnc_book_get_root_account (book);
1790 for (ptr = names; *ptr; ptr++)
1797 for (node = list; node; node = g_list_next (node))
1799 account = node->data;
1804 *base_account = account;
1817 out_names = g_strdupv (ptr);
1841 valid_types, NULL, NULL);
1848 const gnc_commodity * default_commodity,
1854 Account *created_account = NULL;
1855 gchar ** subaccount_names;
1857 gboolean done = FALSE;
1859 ENTER(
"name %s, valid %p, commodity %p, account %p",
1860 name, valid_types, default_commodity, parent_acct);
1861 book = gnc_get_current_book ();
1862 if (!name || *name ==
'\0')
1864 subaccount_names = NULL;
1865 base_account = NULL;
1868 subaccount_names = gnc_split_account_name (book, name, &base_account);
1870 if (parent_acct != NULL)
1872 base_account = parent_acct;
1874 aw = gnc_ui_new_account_window_internal (parent, book, base_account,
1882 response = gtk_dialog_run (GTK_DIALOG(aw->dialog));
1885 gnc_account_window_response_cb (GTK_DIALOG(aw->dialog), response, (gpointer)aw);
1889 case GTK_RESPONSE_OK:
1890 created_account = aw->created_account;
1891 done = (created_account != NULL);
1894 case GTK_RESPONSE_HELP:
1906 return created_account;
1914 find_by_account (gpointer
find_data, gpointer user_data)
1937 if (account == NULL)
1940 aw = gnc_find_first_gui_component (DIALOG_EDIT_ACCOUNT_CM_CLASS,
1941 find_by_account, account);
1944 gtk_window_present (GTK_WINDOW(aw->dialog));
1950 aw->book = gnc_account_get_book (account);
1952 aw->dialog_type = EDIT_ACCOUNT;
1954 aw->subaccount_names = NULL;
1957 gnc_suspend_gui_refresh ();
1959 gnc_account_window_create (parent, aw);
1960 gnc_account_to_ui (aw);
1962 gnc_resume_gui_refresh ();
1964 gtk_widget_show_all (aw->dialog);
1966 gtk_widget_hide (aw->opening_balance_page);
1969 if (parent_acct == NULL)
1970 parent_acct = account;
1972 gtk_tree_view_collapse_all (aw->parent_tree);
1977 gnc_account_window_set_name (aw);
1979 gnc_window_adjust_for_screen (GTK_WINDOW(aw->dialog));
1981 aw->component_id = gnc_register_gui_component (DIALOG_EDIT_ACCOUNT_CM_CLASS,
1985 gnc_gui_component_set_session (aw->component_id, gnc_get_current_session ());
1986 gnc_gui_component_watch_entity_type (aw->component_id,
1988 QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
1990 gtk_window_present (GTK_WINDOW(aw->dialog));
2003 g_return_if_fail(book != NULL);
2004 if (parent_acct && book)
2005 g_return_if_fail(gnc_account_get_book (parent_acct) == book);
2007 gnc_ui_new_account_window_internal (parent, book, parent_acct, NULL, NULL,
2015 gnc_ui_new_account_window_internal (parent, book, NULL, NULL,
2016 valid_types, NULL, FALSE);
2030 gnc_ui_register_account_destroy_callback (
void (*cb)(
Account *))
2035 if (g_list_index (ac_destroy_cb_list, cb) == -1)
2036 ac_destroy_cb_list = g_list_append (ac_destroy_cb_list, cb);
2050 unsigned int num_digits = 1;
2052 g_return_if_fail (data->num_children > 0);
2054 prefix = gtk_editable_get_chars (GTK_EDITABLE(data->prefix), 0, -1);
2055 interval = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(data->interval));
2056 digits = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(data->digits));
2061 num_digits = (
unsigned int)log10((
double)(data->num_children * interval)) + 1;
2063 if (digits <= num_digits)
2065 g_signal_handlers_block_by_func (GTK_SPIN_BUTTON(data->digits),
2066 (gpointer)gnc_account_renumber_digits_changed_cb,
2068 gtk_spin_button_set_value (GTK_SPIN_BUTTON(data->digits), num_digits);
2069 g_signal_handlers_unblock_by_func (GTK_SPIN_BUTTON(data->digits),
2070 (gpointer)gnc_account_renumber_digits_changed_cb,
2074 num_digits = digits;
2076 if (strlen (prefix))
2077 str = g_strdup_printf (
"%s-%0*d", prefix, num_digits, interval);
2079 str = g_strdup_printf (
"%0*d", num_digits, interval);
2081 gtk_label_set_text (GTK_LABEL(data->example1), str);
2084 if (strlen (prefix))
2085 str = g_strdup_printf (
"%s-%0*d", prefix, num_digits,
2086 interval * data->num_children);
2088 str = g_strdup_printf (
"%0*d", num_digits,
2089 interval * data->num_children);
2091 gtk_label_set_text (GTK_LABEL(data->example2), str);
2098 gnc_account_renumber_prefix_changed_cb (GtkEditable *editable,
2101 gnc_account_renumber_update_examples (data);
2105 gnc_account_renumber_interval_changed_cb (GtkSpinButton *spinbutton,
2108 gnc_account_renumber_update_examples (data);
2112 gnc_account_renumber_digits_changed_cb (GtkSpinButton *spinbutton,
2115 gnc_account_renumber_update_examples (data);
2119 gnc_account_renumber_response_cb (GtkDialog *dialog,
2123 if (response == GTK_RESPONSE_OK)
2129 unsigned int num_digits, i;
2131 gtk_widget_hide (data->dialog);
2133 if (children == NULL)
2135 PWARN(
"Can't renumber children of an account with no children!");
2139 prefix = gtk_editable_get_chars (GTK_EDITABLE(data->prefix), 0, -1);
2140 interval = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(data->interval));
2141 num_digits = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON(data->digits));
2143 gnc_set_busy_cursor (NULL, TRUE);
2144 for (tmp = children, i = 1; tmp; tmp = g_list_next (tmp), i += 1)
2147 if (strlen (prefix))
2148 str = g_strdup_printf (
"%s-%0*d", prefix,
2149 num_digits, interval * i);
2151 str = g_strdup_printf (
"%0*d", num_digits, interval * i);
2156 gnc_unset_busy_cursor (NULL);
2158 g_list_free (children);
2160 gtk_widget_destroy (data->dialog);
2165 gnc_account_renumber_create_dialog (GtkWidget *window,
Account *account)
2168 GtkBuilder *builder;
2170 gchar *string, *fullname;
2178 data->parent = account;
2181 builder = gtk_builder_new ();
2182 gnc_builder_add_from_file (builder,
"dialog-account.glade",
"interval_adjustment");
2183 gnc_builder_add_from_file (builder,
"dialog-account.glade",
"digit_spin_adjustment");
2184 gnc_builder_add_from_file (builder,
"dialog-account.glade",
"account_renumber_dialog");
2185 data->dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"account_renumber_dialog"));
2186 gtk_window_set_transient_for (GTK_WINDOW(data->dialog), GTK_WINDOW(window));
2188 g_object_set_data_full (G_OBJECT(data->dialog),
"builder", builder,
2191 widget = GTK_WIDGET(gtk_builder_get_object (builder,
"header_label"));
2193 string = g_strdup_printf (_(
"Renumber the immediate sub-accounts of '%s'?"),
2195 gtk_label_set_text (GTK_LABEL(widget),
string);
2199 data->prefix = GTK_WIDGET(gtk_builder_get_object (builder,
"prefix_entry"));
2200 data->interval = GTK_WIDGET(gtk_builder_get_object (builder,
"interval_spin"));
2201 data->digits = GTK_WIDGET(gtk_builder_get_object (builder,
"digit_spin"));
2202 data->example1 = GTK_WIDGET(gtk_builder_get_object (builder,
"example1_label"));
2203 data->example2 = GTK_WIDGET(gtk_builder_get_object (builder,
"example2_label"));
2206 gnc_account_renumber_update_examples (data);
2208 gtk_builder_connect_signals (builder, data);
2210 gtk_widget_show_all (data->dialog);
2214 default_color_button_cb (GtkButton *button, gpointer user_data)
2218 if (gdk_rgba_parse (&color, DEFAULT_COLOR))
2219 gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER(user_data), &color);
2223 update_account_color (
Account *acc,
const gchar *old_color,
const gchar *new_color, gboolean replace)
2225 PINFO(
"Account is '%s', old_color is '%s', new_color is '%s', replace is %d",
2231 if (!old_color || replace)
2234 if (g_strcmp0 (new_color, old_color) != 0)
2240 if (old_color && replace)
2246 enable_box_cb (GtkToggleButton *toggle_button, gpointer user_data)
2248 gboolean sensitive = FALSE;
2250 if (gtk_toggle_button_get_active (toggle_button))
2253 gtk_widget_set_sensitive (GTK_WIDGET(user_data), sensitive);
2257 gnc_account_cascade_properties_dialog (GtkWidget *window,
Account *account)
2260 GtkBuilder *builder;
2262 GtkWidget *color_button, *over_write, *color_button_default;
2263 GtkWidget *enable_color, *enable_placeholder, *enable_hidden;
2264 GtkWidget *color_box, *placeholder_box, *hidden_box;
2265 GtkWidget *placeholder_button, *hidden_button;
2267 gchar *string, *fullname;
2268 const char *color_string;
2269 gchar *old_color_string = NULL;
2276 builder = gtk_builder_new ();
2277 gnc_builder_add_from_file (builder,
"dialog-account.glade",
"account_cascade_dialog");
2278 dialog = GTK_WIDGET(gtk_builder_get_object (builder,
"account_cascade_dialog"));
2279 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(window));
2282 enable_color = GTK_WIDGET(gtk_builder_get_object (builder,
"enable_cascade_color"));
2283 color_box = GTK_WIDGET(gtk_builder_get_object (builder,
"color_box"));
2285 label = GTK_WIDGET(gtk_builder_get_object (builder,
"color_label"));
2286 over_write = GTK_WIDGET(gtk_builder_get_object (builder,
"replace_check"));
2287 color_button = GTK_WIDGET(gtk_builder_get_object (builder,
"color_button"));
2288 color_button_default = GTK_WIDGET(gtk_builder_get_object (builder,
"color_button_default"));
2290 gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER(color_button), FALSE);
2292 g_signal_connect (G_OBJECT(enable_color),
"toggled",
2293 G_CALLBACK(enable_box_cb), (gpointer)color_box);
2295 g_signal_connect (G_OBJECT(color_button_default),
"clicked",
2296 G_CALLBACK(default_color_button_cb), (gpointer)color_button);
2299 string = g_strdup_printf (_(
"Set the account color for account '%s' " 2300 "including all sub-accounts to the selected color"),
2302 gtk_label_set_text (GTK_LABEL(label),
string);
2308 color_string = DEFAULT_COLOR;
2310 old_color_string = g_strdup (color_string);
2312 if (!gdk_rgba_parse (&color, color_string))
2313 gdk_rgba_parse (&color, DEFAULT_COLOR);
2316 gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER(color_button), &color);
2319 enable_placeholder = GTK_WIDGET(gtk_builder_get_object (builder,
"enable_cascade_placeholder"));
2320 placeholder_box = GTK_WIDGET(gtk_builder_get_object (builder,
"placeholder_box"));
2321 label = GTK_WIDGET(gtk_builder_get_object (builder,
"placeholder_label"));
2322 placeholder_button = GTK_WIDGET(gtk_builder_get_object (builder,
"placeholder_check_button"));
2323 g_signal_connect (G_OBJECT(enable_placeholder),
"toggled",
2324 G_CALLBACK(enable_box_cb), (gpointer)placeholder_box);
2326 string = g_strdup_printf (_(
"Set the account placeholder value for account '%s' " 2327 "including all sub-accounts"),
2329 gtk_label_set_text (GTK_LABEL(label),
string);
2333 enable_hidden = GTK_WIDGET(gtk_builder_get_object (builder,
"enable_cascade_hidden"));
2334 hidden_box = GTK_WIDGET(gtk_builder_get_object (builder,
"hidden_box"));
2335 label = GTK_WIDGET(gtk_builder_get_object (builder,
"hidden_label"));
2336 hidden_button = GTK_WIDGET(gtk_builder_get_object (builder,
"hidden_check_button"));
2337 g_signal_connect (G_OBJECT(enable_hidden),
"toggled",
2338 G_CALLBACK(enable_box_cb), (gpointer)hidden_box);
2340 string = g_strdup_printf (_(
"Set the account hidden value for account '%s' " 2341 "including all sub-accounts"),
2343 gtk_label_set_text (GTK_LABEL(label),
string);
2348 gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);
2350 gtk_builder_connect_signals (builder, dialog);
2351 g_object_unref (G_OBJECT(builder));
2353 gtk_widget_show_all (dialog);
2355 response = gtk_dialog_run (GTK_DIALOG(dialog));
2357 if (response == GTK_RESPONSE_OK)
2361 const gchar *new_color_string = NULL;
2362 gboolean color_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(enable_color));
2363 gboolean placeholder_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(enable_placeholder));
2364 gboolean hidden_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(enable_hidden));
2365 gboolean replace = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(over_write));
2366 gboolean placeholder = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(placeholder_button));
2367 gboolean hidden = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(hidden_button));
2372 gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER(color_button), &new_color);
2373 new_color_string = gdk_rgba_to_string (&new_color);
2375 if (g_strcmp0 (new_color_string, DEFAULT_COLOR) == 0)
2376 new_color_string = NULL;
2379 update_account_color (account, old_color_string, new_color_string, replace);
2383 if (placeholder_active)
2393 for (GList *acct = accounts; acct; acct = g_list_next(acct))
2399 update_account_color (acct->data,
string, new_color_string, replace);
2402 if (placeholder_active)
2409 g_list_free (accounts);
2411 if (old_color_string)
2412 g_free (old_color_string);
2414 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...
SplitList * xaccAccountGetSplitList(const Account *acc)
The xaccAccountGetSplitList() routine returns a pointer to a GList of the splits in the account...
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 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.
#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.
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 xaccAccountSetColor(Account *acc, const char *str)
Set the account's Color.
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.
gint null_strcmp(const gchar *da, const gchar *db)
The null_strcmp compares strings a and b the same way that strcmp() does, except that either may be n...
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.
Account * gnc_ui_new_accounts_from_name_window_with_types(GtkWindow *parent, const char *name, GList *valid_types)
Display a modal window for creating a new account.
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.
const char * gnc_commodity_get_printname(const gnc_commodity *cm)
Retrieve the 'print' name for the specified commodity.
guint32 xaccParentAccountTypesCompatibleWith(GNCAccountType type)
Return the bitmask of parent account types compatible with a given type.
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...
void gnc_ui_new_account_with_types(GtkWindow *parent, QofBook *book, GList *valid_types)
Display a window for creating a new account.
#define LEAVE(format, args...)
Print a function exit debugging message.
Account * xaccMallocAccount(QofBook *book)
Constructor.
time64 gnc_time(time64 *tbuf)
get the current local time
gint64 time64
Many systems, including Microsoft Windows and BSD-derived Unixes like Darwin, are retaining the int-3...
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.
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...