GnuCash c935c2f+
Loading...
Searching...
No Matches
Files | Functions
Creating and editing accounts in the GUI

Files

 

Functions

void gnc_account_renumber_create_dialog (GtkWidget *window, Account *account)
 
void gnc_account_cascade_properties_dialog (GtkWidget *window, Account *account)
 

Non-Modal

void gnc_ui_edit_account_window (GtkWindow *parent, Account *account)
 Display a window for editing the attributes of an existing account.
 
void gnc_ui_new_account_with_types_and_commodity (GtkWindow *parent, QofBook *book, GList *valid_types, gnc_commodity *)
 Display a window for creating a new account.
 
void gnc_ui_new_account_window (GtkWindow *parent, QofBook *book, Account *parent_acct)
 Display a window for creating a new account.
 
void gnc_ui_new_account_with_types (GtkWindow *parent, QofBook *book, GList *valid_types)
 Display a window for creating a new account.
 

Modal

Accountgnc_ui_new_accounts_from_name_window (GtkWindow *parent, const char *name)
 Display a modal window for creating a new account.
 
Accountgnc_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 gnc_ui_register_account_destroy_callback (void(*cb)(Account *))
 

Detailed Description

Function Documentation

◆ gnc_account_cascade_properties_dialog()

void gnc_account_cascade_properties_dialog ( GtkWidget *  window,
Account account 
)

Definition at line 2423 of file dialog-account.c.

2424{
2425 GtkWidget *dialog;
2426 GtkBuilder *builder;
2427 GtkWidget *label;
2428 GtkWidget *color_button, *over_write, *color_button_default;
2429 GtkWidget *enable_color, *enable_placeholder, *enable_hidden;
2430 GtkWidget *color_box, *placeholder_box, *hidden_box;
2431 GtkWidget *placeholder_button, *hidden_button;
2432
2433 gchar *string, *fullname;
2434 const char *color_string;
2435 gchar *old_color_string = NULL;
2436 GdkRGBA color;
2437 gint response;
2438
2439 // check if we actually do have sub accounts
2440 g_return_if_fail (gnc_account_n_children (account) > 0);
2441
2442 builder = gtk_builder_new ();
2443 gnc_builder_add_from_file (builder, "dialog-account.glade", "account_cascade_dialog");
2444 dialog = GTK_WIDGET(gtk_builder_get_object (builder, "account_cascade_dialog"));
2445 gtk_window_set_transient_for (GTK_WINDOW(dialog), GTK_WINDOW(window));
2446
2447 // Color section
2448 enable_color = GTK_WIDGET(gtk_builder_get_object (builder, "enable_cascade_color"));
2449 color_box = GTK_WIDGET(gtk_builder_get_object (builder, "color_box"));
2450
2451 label = GTK_WIDGET(gtk_builder_get_object (builder, "color_label"));
2452 over_write = GTK_WIDGET(gtk_builder_get_object (builder, "replace_check"));
2453 color_button = GTK_WIDGET(gtk_builder_get_object (builder, "color_button"));
2454 color_button_default = GTK_WIDGET(gtk_builder_get_object (builder, "color_button_default"));
2455
2456 gtk_color_chooser_set_use_alpha (GTK_COLOR_CHOOSER(color_button), FALSE);
2457
2458 g_signal_connect (G_OBJECT(enable_color), "toggled",
2459 G_CALLBACK(enable_box_cb), (gpointer)color_box);
2460
2461 g_signal_connect (G_OBJECT(color_button_default), "clicked",
2462 G_CALLBACK(default_color_button_cb), (gpointer)color_button);
2463
2464 fullname = gnc_account_get_full_name (account);
2465 string = g_strdup_printf (_( "Set the account color for account '%s' "
2466 "including all sub-accounts to the selected color"),
2467 fullname);
2468 gtk_label_set_text (GTK_LABEL(label), string);
2469 g_free (string);
2470
2471 color_string = xaccAccountGetColor (account); // get existing account color
2472
2473 if (!color_string)
2474 color_string = DEFAULT_COLOR;
2475 else
2476 old_color_string = g_strdup (color_string); // save the old color string
2477
2478 if (!gdk_rgba_parse (&color, color_string))
2479 gdk_rgba_parse (&color, DEFAULT_COLOR);
2480
2481 // set the color chooser to account color
2482 gtk_color_chooser_set_rgba (GTK_COLOR_CHOOSER(color_button), &color);
2483
2484 // Placeholder section
2485 enable_placeholder = GTK_WIDGET(gtk_builder_get_object (builder, "enable_cascade_placeholder"));
2486 placeholder_box = GTK_WIDGET(gtk_builder_get_object (builder, "placeholder_box"));
2487 label = GTK_WIDGET(gtk_builder_get_object (builder, "placeholder_label"));
2488 placeholder_button = GTK_WIDGET(gtk_builder_get_object (builder, "placeholder_check_button"));
2489 g_signal_connect (G_OBJECT(enable_placeholder), "toggled",
2490 G_CALLBACK(enable_box_cb), (gpointer)placeholder_box);
2491
2492 string = g_strdup_printf (_( "Set the account placeholder value for account '%s' "
2493 "including all sub-accounts"),
2494 fullname);
2495 gtk_label_set_text (GTK_LABEL(label), string);
2496 g_free (string);
2497
2498 // Hidden section
2499 enable_hidden = GTK_WIDGET(gtk_builder_get_object (builder, "enable_cascade_hidden"));
2500 hidden_box = GTK_WIDGET(gtk_builder_get_object (builder, "hidden_box"));
2501 label = GTK_WIDGET(gtk_builder_get_object (builder, "hidden_label"));
2502 hidden_button = GTK_WIDGET(gtk_builder_get_object (builder, "hidden_check_button"));
2503 g_signal_connect (G_OBJECT(enable_hidden), "toggled",
2504 G_CALLBACK(enable_box_cb), (gpointer)hidden_box);
2505
2506 string = g_strdup_printf (_( "Set the account hidden value for account '%s' "
2507 "including all sub-accounts"),
2508 fullname);
2509 gtk_label_set_text (GTK_LABEL(label), string);
2510 g_free (string);
2511 g_free (fullname);
2512
2513 /* default to cancel */
2514 gtk_dialog_set_default_response (GTK_DIALOG(dialog), GTK_RESPONSE_CANCEL);
2515
2516 gtk_builder_connect_signals (builder, dialog);
2517 g_object_unref (G_OBJECT(builder));
2518
2519 gtk_widget_show_all (dialog);
2520
2521 response = gtk_dialog_run (GTK_DIALOG(dialog));
2522
2523 if (response == GTK_RESPONSE_OK)
2524 {
2525 GList *accounts = gnc_account_get_descendants (account);
2526 GdkRGBA new_color;
2527 gchar *new_color_string = NULL;
2528 gboolean color_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(enable_color));
2529 gboolean placeholder_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(enable_placeholder));
2530 gboolean hidden_active = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(enable_hidden));
2531 gboolean replace = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(over_write));
2532 gboolean placeholder = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(placeholder_button));
2533 gboolean hidden = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON(hidden_button));
2534
2535 // Update Account Colors
2536 if (color_active)
2537 {
2538 gtk_color_chooser_get_rgba (GTK_COLOR_CHOOSER(color_button), &new_color);
2539 new_color_string = gdk_rgba_to_string (&new_color);
2540
2541 if (g_strcmp0 (new_color_string, DEFAULT_COLOR) == 0)
2542 {
2543 g_free (new_color_string);
2544 new_color_string = NULL;
2545 }
2546
2547 // check/update selected account
2548 update_account_color (account, old_color_string, new_color_string, replace);
2549 }
2550
2551 // Update Account Placeholder value
2552 if (placeholder_active)
2553 xaccAccountSetPlaceholder (account, placeholder);
2554
2555 // Update Account Hidden value
2556 if (hidden_active)
2557 xaccAccountSetHidden (account, hidden);
2558
2559 // Update SubAccounts
2560 if (accounts)
2561 {
2562 for (GList *acct = accounts; acct; acct = g_list_next(acct))
2563 {
2564 // Update SubAccount Colors
2565 if (color_active)
2566 {
2567 const char *string = xaccAccountGetColor (acct->data);
2568 update_account_color (acct->data, string, new_color_string, replace);
2569 }
2570 // Update SubAccount PlaceHolder
2571 if (placeholder_active)
2572 xaccAccountSetPlaceholder (acct->data, placeholder);
2573 // Update SubAccount Hidden
2574 if (hidden_active)
2575 xaccAccountSetHidden (acct->data, hidden);
2576 }
2577 }
2578 g_list_free (accounts);
2579 g_free (new_color_string);
2580 }
2581 if (old_color_string)
2582 g_free (old_color_string);
2583
2584 gtk_widget_destroy (dialog);
2585}
const char * xaccAccountGetColor(const Account *acc)
Get the account's color.
Definition Account.cpp:3350
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...
Definition Account.cpp:3305
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...
Definition Account.cpp:3044
gint gnc_account_n_children(const Account *account)
Return the number of children of the specified account.
Definition Account.cpp:2976
void xaccAccountSetHidden(Account *acc, gboolean val)
Set the "hidden" flag for an account.
Definition Account.cpp:4196
void xaccAccountSetPlaceholder(Account *acc, gboolean val)
Set the "placeholder" flag for an account.
Definition Account.cpp:4125

◆ gnc_account_renumber_create_dialog()

void gnc_account_renumber_create_dialog ( GtkWidget *  window,
Account account 
)

Definition at line 2331 of file dialog-account.c.

2332{
2333 RenumberDialog *data;
2334 GtkBuilder *builder;
2335 GtkWidget *widget;
2336 gchar *string, *fullname;
2337
2338 /* This is a safety check; the menu item calling this dialog
2339 * should be disabled if the account has no children.
2340 */
2341 g_return_if_fail (gnc_account_n_children (account) > 0);
2342
2343 data = g_new (RenumberDialog, 1);
2344 data->parent = account;
2345 data->num_children = gnc_account_n_children (account);
2346
2347 builder = gtk_builder_new ();
2348 gnc_builder_add_from_file (builder, "dialog-account.glade", "interval_adjustment");
2349 gnc_builder_add_from_file (builder, "dialog-account.glade", "digit_spin_adjustment");
2350 gnc_builder_add_from_file (builder, "dialog-account.glade", "account_renumber_dialog");
2351 data->dialog = GTK_WIDGET(gtk_builder_get_object (builder, "account_renumber_dialog"));
2352 gtk_window_set_transient_for (GTK_WINDOW(data->dialog), GTK_WINDOW(window));
2353
2354 g_object_set_data_full (G_OBJECT(data->dialog), "builder", builder,
2355 g_object_unref);
2356
2357 widget = GTK_WIDGET(gtk_builder_get_object (builder, "header_label"));
2358 fullname = gnc_account_get_full_name (account);
2359 string = g_strdup_printf (_("Renumber the immediate sub-accounts of '%s'?"),
2360 fullname);
2361 gtk_label_set_text (GTK_LABEL(widget), string);
2362 g_free (string);
2363 g_free (fullname);
2364
2365 data->prefix = GTK_WIDGET(gtk_builder_get_object (builder, "prefix_entry"));
2366 data->interval = GTK_WIDGET(gtk_builder_get_object (builder, "interval_spin"));
2367 data->digits = GTK_WIDGET(gtk_builder_get_object (builder, "digit_spin"));
2368 data->example1 = GTK_WIDGET(gtk_builder_get_object (builder, "example1_label"));
2369 data->example2 = GTK_WIDGET(gtk_builder_get_object (builder, "example2_label"));
2370
2371 gtk_entry_set_text (GTK_ENTRY(data->prefix), xaccAccountGetCode (account));
2372 gnc_account_renumber_update_examples (data);
2373
2374 gtk_builder_connect_signals (builder, data);
2375
2376 gtk_widget_show_all (data->dialog);
2377}
const char * xaccAccountGetCode(const Account *acc)
Get the account's accounting code.
Definition Account.cpp:3336

◆ gnc_ui_edit_account_window()

void gnc_ui_edit_account_window ( GtkWindow *  parent,
Account account 
)

Display a window for editing the attributes of an existing account.

Parameters
parentThe widget on which to parent the dialog.
accountThis parameter specifies the account whose data will be edited.

Definition at line 2102 of file dialog-account.c.

2103{
2104 AccountWindow * aw;
2105 Account *parent_acct;
2106
2107 if (account == NULL)
2108 return;
2109
2110 aw = gnc_find_first_gui_component (DIALOG_EDIT_ACCOUNT_CM_CLASS,
2111 find_by_account, account);
2112 if (aw)
2113 {
2114 gtk_window_present (GTK_WINDOW(aw->dialog));
2115 return;
2116 }
2117
2118 aw = g_new0 (AccountWindow, 1);
2119
2120 aw->book = gnc_account_get_book (account);
2121 aw->modal = FALSE;
2122 aw->dialog_type = EDIT_ACCOUNT;
2123 aw->account = *xaccAccountGetGUID (account);
2124 aw->subaccount_names = NULL;
2125 aw->type = xaccAccountGetType (account);
2126
2127 gnc_suspend_gui_refresh ();
2128
2129 gnc_account_window_create (parent, aw);
2130 gnc_account_to_ui (aw);
2131
2132 gnc_resume_gui_refresh ();
2133
2134 gtk_widget_show_all (aw->dialog);
2135 if (xaccAccountGetSplitsSize (account) != 0)
2136 gtk_widget_hide (aw->opening_balance_page);
2137
2138 parent_acct = gnc_account_get_parent (account);
2139 if (parent_acct == NULL)
2140 parent_acct = account; // must be at the root
2141
2142 gtk_tree_view_collapse_all (aw->parent_tree);
2143 gnc_tree_view_account_set_selected_account (GNC_TREE_VIEW_ACCOUNT(
2144 aw->parent_tree),
2145 parent_acct);
2146
2147 gnc_account_window_set_name (aw);
2148
2149 gnc_window_adjust_for_screen (GTK_WINDOW(aw->dialog));
2150
2151 aw->component_id = gnc_register_gui_component (DIALOG_EDIT_ACCOUNT_CM_CLASS,
2152 refresh_handler,
2153 close_handler, aw);
2154
2155 gnc_gui_component_set_session (aw->component_id, gnc_get_current_session ());
2156 gnc_gui_component_watch_entity_type (aw->component_id,
2157 GNC_ID_ACCOUNT,
2158 QOF_EVENT_MODIFY | QOF_EVENT_DESTROY);
2159
2160 gtk_window_present (GTK_WINDOW(aw->dialog));
2161}
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
Definition Account.cpp:3267
#define xaccAccountGetGUID(X)
Definition Account.h:252
Account * gnc_account_get_parent(const Account *acc)
This routine returns a pointer to the parent of the specified account.
Definition Account.cpp:2935
void gnc_tree_view_account_set_selected_account(GncTreeViewAccount *view, Account *account)
This function selects an account in the account tree view.
STRUCTS.

◆ gnc_ui_new_account_window()

void gnc_ui_new_account_window ( GtkWindow *  parent,
QofBook book,
Account parent_acct 
)

Display a window for creating a new account.

This function will also initially set the parent account of the new account to what the caller specified. The user is free, however, to choose any parent account they wish.

Parameters
parentThe widget on which to parent the dialog.
bookThe book in which the new account should be created. This is a required argument.
parent_acctThe initially selected parent account. This argument is optional, but if supplied must be an account contained in the specified book.

Definition at line 2178 of file dialog-account.c.

2180{
2181 g_return_if_fail(book != NULL);
2182 if (parent_acct && book)
2183 g_return_if_fail(gnc_account_get_book (parent_acct) == book);
2184
2185 gnc_ui_new_account_window_internal (parent, book, parent_acct, NULL, NULL,
2186 NULL, FALSE);
2187}

◆ gnc_ui_new_account_with_types()

void gnc_ui_new_account_with_types ( GtkWindow *  parent,
QofBook book,
GList *  valid_types 
)

Display a window for creating a new account.

This function will restrict the available account type values to the list specified by the caller.

Parameters
parentThe widget on which to parent the dialog.
bookThe book in which the new account should be created. This is a required argument.
valid_typesA GList of GNCAccountType gints [as pointers] which are allowed to be created. The calling function is responsible for freeing this list.

◆ gnc_ui_new_account_with_types_and_commodity()

void gnc_ui_new_account_with_types_and_commodity ( GtkWindow *  parent,
QofBook book,
GList *  valid_types,
gnc_commodity *  default_commodity 
)

Display a window for creating a new account.

This function will restrict the available account type values to the list specified by the caller.

Parameters
parentThe widget on which to parent the dialog.
bookThe book in which the new account should be created. This is a required argument.
valid_typesA GList of GNCAccountType gints [as pointers] which are allowed to be created. The calling function is responsible for freeing this list.
default_commodityA gnc_commodity* to specify the default commodity to create. May be NULL.

Definition at line 2164 of file dialog-account.c.

2166{
2167 gnc_ui_new_account_window_internal (parent, book, NULL, NULL,
2168 valid_types, default_commodity, FALSE);
2169}

◆ gnc_ui_new_accounts_from_name_window()

Account * gnc_ui_new_accounts_from_name_window ( GtkWindow *  parent,
const char *  name 
)

Display a modal window for creating a new account.

Parameters
parentThe widget on which to parent the dialog.
nameThe account name/path to be created. This parameter is not used for determining the initially selected parent account.

Definition at line 2008 of file dialog-account.c.

2009{
2010 return gnc_ui_new_accounts_from_name_with_defaults (parent, name, NULL,
2011 NULL, NULL);
2012}
Account * gnc_ui_new_accounts_from_name_with_defaults(GtkWindow *parent, const char *name, GList *valid_types, const gnc_commodity *default_commodity, Account *parent_acct)
Display a modal window for creating a new account.

◆ gnc_ui_new_accounts_from_name_with_defaults()

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.

This function will restrict the available account type values to the list specified by the caller.

Parameters
parentThe widget on which to parent the dialog.
nameThe account name/path to be created. This parameter is not used for determining the initially selected parent account.
valid_typesA GList of GNCAccountType gints [as pointers] which are allowed to be created. The calling function is responsible for freeing this list.
default_commodityThe commodity to initially select when the dialog is presented.
parent_acctThe initially selected parent account.
Returns
A pointer to the newly created account.

Definition at line 2015 of file dialog-account.c.

2020{
2021 QofBook *book;
2022 AccountWindow *aw;
2023 Account *base_account = NULL;
2024 Account *created_account = NULL;
2025 gchar ** subaccount_names;
2026 gint response;
2027 gboolean done = FALSE;
2028
2029 ENTER("name %s, valid %p, commodity %p, account %p",
2030 name, valid_types, default_commodity, parent_acct);
2031 book = gnc_get_current_book ();
2032 if (!name || *name == '\0')
2033 {
2034 subaccount_names = NULL;
2035 base_account = NULL;
2036 }
2037 else
2038 subaccount_names = gnc_split_account_name (book, name, &base_account);
2039
2040 if (parent_acct != NULL)
2041 {
2042 base_account = parent_acct;
2043 }
2044 aw = gnc_ui_new_account_window_internal (parent, book, base_account,
2045 subaccount_names,
2046 valid_types,
2047 default_commodity,
2048 TRUE);
2049
2050 while (!done)
2051 {
2052 response = gtk_dialog_run (GTK_DIALOG(aw->dialog));
2053
2054 /* This can destroy the dialog */
2055 gnc_account_window_response_cb (GTK_DIALOG(aw->dialog), response, (gpointer)aw);
2056
2057 switch (response)
2058 {
2059 case GTK_RESPONSE_OK:
2060 created_account = aw->created_account;
2061 done = (created_account != NULL);
2062 break;
2063
2064 case GTK_RESPONSE_HELP:
2065 done = FALSE;
2066 break;
2067
2068 default:
2069 done = TRUE;
2070 break;
2071 }
2072 }
2073
2074 close_handler (aw);
2075 LEAVE("created %s (%p)", xaccAccountGetName (created_account), created_account);
2076 return created_account;
2077}
const char * xaccAccountGetName(const Account *acc)
Get the account's name.
Definition Account.cpp:3289
#define LEAVE(format, args...)
Print a function exit debugging message.
Definition qoflog.h:282
#define ENTER(format, args...)
Print a function entry debugging message.
Definition qoflog.h:272
QofBook reference.
Definition qofbook-p.hpp:47

◆ gnc_ui_register_account_destroy_callback()

void gnc_ui_register_account_destroy_callback ( void(*)(Account *)  cb)

Definition at line 2200 of file dialog-account.c.

2201{
2202 if (!cb)
2203 return;
2204
2205 if (g_list_index (ac_destroy_cb_list, cb) == -1)
2206 ac_destroy_cb_list = g_list_append (ac_destroy_cb_list, cb);
2207
2208 return;
2209}