From 39fad148083fd2abc2e5c816711334901dff7df7 Mon Sep 17 00:00:00 2001 From: David Hampton Date: Sat, 15 Apr 2006 03:52:44 +0000 Subject: [PATCH] Add a per-account "hidden" flag, and update the accounts page and the account quickfill to respect this flag. Also flip the "hide zero balance" flag to a "show zero balance" flag for symmetry. Implements 87077. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13785 57a11ea4-9604-0410-9ed3-97b8803252fd --- ChangeLog | 11 + src/engine/Account.c | 39 +++ src/engine/Account.h | 49 ++- src/gnome-utils/dialog-account.c | 30 +- src/gnome-utils/gnc-tree-view-account.c | 75 ++++- src/gnome-utils/gnc-tree-view-account.h | 10 +- src/gnome/glade/account.glade | 317 ++++++++++-------- src/gnome/gnc-plugin-page-account-tree.c | 3 +- src/gnome/gnc-plugin-page-budget.c | 3 +- .../ledger-core/split-register-load.c | 2 + 10 files changed, 365 insertions(+), 174 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7f88063eb6..eb0b3670ee 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,16 @@ 2006-04-14 David Hampton + * src/register/ledger-core/split-register-load.c: + * src/gnome-utils/gnc-tree-view-account.[ch]: + * src/gnome-utils/dialog-account.c: + * src/gnome/gnc-plugin-page-account-tree.c: + * src/gnome/glade/account.glade: + * src/gnome/gnc-plugin-page-budget.c: + * src/engine/Account.[ch]: Add a per-account "hidden" flag, and + update the accounts page and the account quickfill to respect this + flag. Also flip the "hide zero balance" flag to a "show zero + balance" flag for symmetry. Implements 87077. + * src/gnome/gnc-plugin-page-account-tree.c: Allow the account tree view callback to run in addition the the page callback. Fixes 303995. diff --git a/src/engine/Account.c b/src/engine/Account.c index 1256f94b34..8ea69353cc 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -1960,6 +1960,45 @@ xaccAccountGetDescendantPlaceholder (const Account *acc) /********************************************************************\ \********************************************************************/ +gboolean +xaccAccountGetHidden (const Account *acc) +{ + char *str; + if (!acc) return FALSE; + + str = kvp_frame_get_string(acc->inst.kvp_data, "hidden"); + return (str && !strcmp(str, "true")); +} + +void +xaccAccountSetHidden (Account *acc, gboolean val) +{ + if (!acc) return; + + kvp_frame_set_string (acc->inst.kvp_data, "hidden", + val ? "true" : NULL); + mark_account (acc); + xaccAccountCommitEdit (acc); +} + +gboolean +xaccAccountIsHidden (const Account *acc) +{ + if (!acc) + return FALSE; + if (xaccAccountGetHidden(acc)) + return TRUE; + + while ((acc = xaccAccountGetParentAccount(acc)) != NULL) { + if (xaccAccountGetHidden(acc)) + return TRUE; + } + return FALSE; +} + +/********************************************************************\ +\********************************************************************/ + gboolean xaccAccountHasAncestor (const Account *acc, const Account * ancestor) { diff --git a/src/engine/Account.h b/src/engine/Account.h index 69af26f791..e0364d0476 100644 --- a/src/engine/Account.h +++ b/src/engine/Account.h @@ -673,9 +673,21 @@ typedef enum /** @name Account Placeholder flag @{ */ -/** DOCUMENT ME! */ + +/** Get the "placeholder" flag for an account. If this flag is set + * then the account may not be modified by the user. + * + * @param acc The account whose flag should be retrieved. + * + * @return The current state of the account's "placeholder" flag. */ gboolean xaccAccountGetPlaceholder (const Account *account); -/** DOCUMENT ME! */ + +/** Set the "placeholder" flag for an account. If this flag is set + * then the account may not be modified by the user. + * + * @param acc The account whose flag should be retrieved. + * + * @param val The new state for the account's "placeholder" flag. */ void xaccAccountSetPlaceholder (Account *account, gboolean option); /** Returns PLACEHOLDER_NONE if account is NULL or neither account nor @@ -686,6 +698,39 @@ void xaccAccountSetPlaceholder (Account *account, gboolean option); GNCPlaceholderType xaccAccountGetDescendantPlaceholder(const Account *account); /** @} */ +/** @name Account Hidden flag + @{ +*/ + +/** Get the "hidden" flag for an account. If this flag is set then + * the account (and any children) will be hidden from the user unless + * they explicitly ask to see them. + * + * @param acc The account whose flag should be retrieved. + * + * @return The current state of the account's "hidden" flag. */ +gboolean xaccAccountGetHidden (const Account *acc); + +/** Set the "hidden" flag for an account. If this flag is set then + * the account (and any children) will be hidden from the user unless + * they explicitly ask to see them. + * + * @param acc The account whose flag should be retrieved. + * + * @param val The new state for the account's "hidden" flag. */ +void xaccAccountSetHidden (Account *acc, gboolean val); + +/** Should this account be "hidden". If this flag is set for this + * account (or any parent account) then the account should be hidden + * from the user unless they explicitly ask to see it. This function + * is different from the xaccAccountGetHidden() function because it + * checks the flag in parent accounts in addition to this account. + * + * @param acc The account whose flag should be retrieved. + * + * @return Whether or not this account should be "hidden". */ +gboolean xaccAccountIsHidden (const Account *acc); +/** @} */ /** @name Account Tax related getters/setters @{ diff --git a/src/gnome-utils/dialog-account.c b/src/gnome-utils/dialog-account.c index 9abfa6e0ce..7fed1d3722 100644 --- a/src/gnome-utils/dialog-account.c +++ b/src/gnome-utils/dialog-account.c @@ -101,6 +101,7 @@ typedef struct _AccountWindow GtkWidget * tax_related_button; GtkWidget * placeholder_button; + GtkWidget * hidden_button; gint component_id; } AccountWindow; @@ -180,7 +181,7 @@ gnc_account_to_ui(AccountWindow *aw) Account *account; gnc_commodity * commodity; const char *string; - gboolean tax_related, placeholder, nonstd_scu; + gboolean flag, nonstd_scu; gint index; ENTER("%p", aw); @@ -221,13 +222,17 @@ gnc_account_to_ui(AccountWindow *aw) gtk_text_buffer_set_text (aw->notes_text_buffer, string, strlen(string)); - tax_related = xaccAccountGetTaxRelated (account); + flag = xaccAccountGetTaxRelated (account); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (aw->tax_related_button), - tax_related); + flag); - placeholder = xaccAccountGetPlaceholder (account); + flag = xaccAccountGetPlaceholder (account); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (aw->placeholder_button), - placeholder); + flag); + + flag = xaccAccountGetHidden (account); + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (aw->hidden_button), + flag); gtk_tree_view_collapse_all (aw->parent_tree); gnc_tree_view_account_set_selected_account (GNC_TREE_VIEW_ACCOUNT(aw->parent_tree), account); @@ -295,7 +300,7 @@ gnc_ui_to_account(AccountWindow *aw) Account *parent_account; const char *old_string; const char *string; - gboolean tax_related, placeholder; + gboolean flag; gnc_numeric balance; gboolean use_equity, nonstd; time_t date; @@ -353,13 +358,17 @@ gnc_ui_to_account(AccountWindow *aw) if (safe_strcmp (string, old_string) != 0) xaccAccountSetNotes (account, string); - tax_related = + flag = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (aw->tax_related_button)); - xaccAccountSetTaxRelated (account, tax_related); + xaccAccountSetTaxRelated (account, flag); - placeholder = + flag = gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (aw->placeholder_button)); - xaccAccountSetPlaceholder (account, placeholder); + xaccAccountSetPlaceholder (account, flag); + + flag = + gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (aw->hidden_button)); + xaccAccountSetHidden (account, flag); parent_account = gnc_tree_view_account_get_selected_account (GNC_TREE_VIEW_ACCOUNT (aw->parent_tree)); if (parent_account == aw->top_level_account) @@ -1288,6 +1297,7 @@ gnc_account_window_create(AccountWindow *aw) aw->tax_related_button = glade_xml_get_widget (xml, "tax_related_button"); aw->placeholder_button = glade_xml_get_widget (xml, "placeholder_button"); + aw->hidden_button = glade_xml_get_widget (xml, "hidden_button"); box = glade_xml_get_widget (xml, "opening_balance_box"); amount = gnc_amount_edit_new (); diff --git a/src/gnome-utils/gnc-tree-view-account.c b/src/gnome-utils/gnc-tree-view-account.c index 6ce2b79f32..4aa5bcadea 100644 --- a/src/gnome-utils/gnc-tree-view-account.c +++ b/src/gnome-utils/gnc-tree-view-account.c @@ -1613,7 +1613,12 @@ gnc_plugin_page_account_tree_filter_accounts (Account *account, ENTER("account %p:%s", account, xaccAccountGetName(account)); - if (fd->hide_zero_total) { + if (!fd->show_hidden && xaccAccountIsHidden (account)) { + LEAVE(" hide: hidden"); + return FALSE; + } + + if (!fd->show_zero_total) { total = xaccAccountGetBalanceInCurrency (account, NULL, TRUE); if (gnc_numeric_zero_p(total)) { LEAVE(" hide: zero balance"); @@ -1627,22 +1632,40 @@ gnc_plugin_page_account_tree_filter_accounts (Account *account, return result; } -/** The "hide zero totals" button in the Filter dialog changed state. +/** The "show hidden" button in the Filter dialog changed state. * Update the page to reflect these changes. * * @param button The GtkCheckButton that was toggled. * * @param fd A pointer to the account filter dialog struct. */ void -gppat_filter_hide_zero_toggled_cb (GtkToggleButton *button, +gppat_filter_show_hidden_toggled_cb (GtkToggleButton *button, + AccountFilterDialog *fd) +{ + g_return_if_fail(GTK_IS_TOGGLE_BUTTON(button)); + + ENTER("button %p", button); + fd->show_hidden = gtk_toggle_button_get_active(button); + gnc_tree_view_account_refilter(fd->tree_view); + LEAVE("show_hidden %d", fd->show_hidden); +} + +/** The "show zero totals" button in the Filter dialog changed state. + * Update the page to reflect these changes. + * + * @param button The GtkCheckButton that was toggled. + * + * @param fd A pointer to the account filter dialog struct. */ +void +gppat_filter_show_zero_toggled_cb (GtkToggleButton *button, AccountFilterDialog *fd) { g_return_if_fail(GTK_IS_TOGGLE_BUTTON(button)); ENTER("button %p", button); - fd->hide_zero_total = gtk_toggle_button_get_active(button); + fd->show_zero_total = gtk_toggle_button_get_active(button); gnc_tree_view_account_refilter(fd->tree_view); - LEAVE("hide_zero %d", fd->hide_zero_total); + LEAVE("show_zero %d", fd->show_zero_total); } /** The "clear all account types" button in the Filter dialog was @@ -1779,7 +1802,8 @@ gppat_filter_response_cb (GtkWidget *dialog, if (response != GTK_RESPONSE_OK) { fd->visible_types = fd->original_visible_types; - fd->hide_zero_total = fd->original_hide_zero_total; + fd->show_hidden = fd->original_show_hidden; + fd->show_zero_total = fd->original_show_zero_total; gnc_tree_view_account_refilter(fd->tree_view); } @@ -1823,12 +1847,16 @@ account_filter_dialog_create(AccountFilterDialog *fd, GncPluginPage *page) /* Remember current state */ fd->original_visible_types = fd->visible_types; - fd->original_hide_zero_total = fd->hide_zero_total; + fd->original_show_hidden = fd->show_hidden; + fd->original_show_zero_total = fd->show_zero_total; /* Update the dialog widgets for the current state */ - button = glade_xml_get_widget (xml, "hide_zero"); + button = glade_xml_get_widget (xml, "show_hidden"); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), - fd->hide_zero_total); + fd->show_hidden); + button = glade_xml_get_widget (xml, "show_zero"); + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), + fd->show_zero_total); /* Set up the tree view and model */ view = GTK_TREE_VIEW(glade_xml_get_widget (xml, FILTER_TREE_VIEW)); @@ -1864,7 +1892,8 @@ account_filter_dialog_create(AccountFilterDialog *fd, GncPluginPage *page) #define ACCT_COUNT "Number of Open Accounts" #define ACCT_OPEN "Open Account %d" #define ACCT_SELECTED "Selected Account" -#define HIDE_ZERO "Hide Zero Total" +#define SHOW_HIDDEN "Show Hidden" +#define SHOW_ZERO "Show Zero Total" #define ACCT_TYPES "Account Types" typedef struct foo { @@ -1955,8 +1984,10 @@ gnc_tree_view_account_save(GncTreeViewAccount *view, g_key_file_set_integer(key_file, group_name, ACCT_TYPES, fd->visible_types); - g_key_file_set_boolean(key_file, group_name, HIDE_ZERO, - fd->hide_zero_total); + g_key_file_set_boolean(key_file, group_name, SHOW_HIDDEN, + fd->show_hidden); + g_key_file_set_boolean(key_file, group_name, SHOW_ZERO, + fd->show_zero_total); bar.key_file = key_file; bar.group_name = group_name; @@ -2021,18 +2052,28 @@ gnc_tree_view_account_restore(GncTreeViewAccount *view, GError *error = NULL; gchar *key, *value; gint i, count; - gboolean hide; + gboolean show; /* Filter information. Ignore missing keys. */ - hide = g_key_file_get_boolean(key_file, group_name, HIDE_ZERO, &error); + show = g_key_file_get_boolean(key_file, group_name, SHOW_HIDDEN, &error); if (error) { g_warning("error reading group %s key %s: %s", - group_name, HIDE_ZERO, error->message); + group_name, SHOW_HIDDEN, error->message); g_error_free(error); error = NULL; - hide = FALSE; + show = TRUE; } - fd->hide_zero_total = hide; + fd->show_hidden = show; + + show = g_key_file_get_boolean(key_file, group_name, SHOW_ZERO, &error); + if (error) { + g_warning("error reading group %s key %s: %s", + group_name, SHOW_ZERO, error->message); + g_error_free(error); + error = NULL; + show = TRUE; + } + fd->show_zero_total = show; i = g_key_file_get_integer(key_file, group_name, ACCT_TYPES, &error); if (error) { diff --git a/src/gnome-utils/gnc-tree-view-account.h b/src/gnome-utils/gnc-tree-view-account.h index f22bb13c03..97ab6808f0 100644 --- a/src/gnome-utils/gnc-tree-view-account.h +++ b/src/gnome-utils/gnc-tree-view-account.h @@ -78,8 +78,10 @@ typedef struct { GncTreeViewAccount *tree_view; guint32 visible_types; guint32 original_visible_types; - gboolean hide_zero_total; - gboolean original_hide_zero_total; + gboolean show_hidden; + gboolean original_show_hidden; + gboolean show_zero_total; + gboolean original_show_zero_total; } AccountFilterDialog; void account_filter_dialog_create(AccountFilterDialog *fd, @@ -89,7 +91,9 @@ gboolean gnc_plugin_page_account_tree_filter_accounts (Account *account, gpointer user_data); /* "Filter By" dialog callbacks */ -void gppat_filter_hide_zero_toggled_cb (GtkToggleButton *togglebutton, +void gppat_filter_show_hidden_toggled_cb (GtkToggleButton *togglebutton, + AccountFilterDialog *fd); +void gppat_filter_show_zero_toggled_cb (GtkToggleButton *togglebutton, AccountFilterDialog *fd); void gppat_filter_clear_all_cb (GtkWidget *button, AccountFilterDialog *fd); void gppat_filter_select_all_cb (GtkWidget *button, AccountFilterDialog *fd); diff --git a/src/gnome/glade/account.glade b/src/gnome/glade/account.glade index 890d16bbdd..6ebb346154 100644 --- a/src/gnome/glade/account.glade +++ b/src/gnome/glade/account.glade @@ -187,28 +187,6 @@ - - - True - True - True - True - True - 0 - - True - * - True - - - 1 - 2 - 0 - 1 - - - - True @@ -234,27 +212,6 @@ - - - True - True - True - True - 0 - - True - * - True - - - 1 - 2 - 1 - 2 - - - - True @@ -280,27 +237,6 @@ - - - True - True - True - True - 0 - - True - * - True - - - 1 - 2 - 2 - 3 - - - - True @@ -370,6 +306,161 @@ + + + True + No_tes: + True + False + GTK_JUSTIFY_LEFT + False + False + 0 + 0 + 0 + 0 + notes_text + + + 0 + 1 + 5 + 6 + fill + fill + + + + + + True + True + Ta_x related + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + 1 + 6 + 7 + + + + + + + True + This account is present solely as a placeholder in the hierarchy. Transactions may not be posted to this account, only to sub-accounts of this account. + True + Placeholde_r + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 0 + 1 + 7 + 8 + fill + + + + + + + True + True + H_idden + True + GTK_RELIEF_NORMAL + True + False + False + True + + + 1 + 2 + 6 + 7 + fill + + + + + + + True + True + True + True + True + 0 + + True + * + True + + + 1 + 2 + 0 + 1 + + + + + + + True + True + True + True + 0 + + True + * + True + + + 1 + 2 + 1 + 2 + + + + + + + True + True + True + True + 0 + + True + * + True + + + 1 + 2 + 2 + 3 + + + + True @@ -494,76 +585,6 @@ fill - - - - True - No_tes: - True - False - GTK_JUSTIFY_LEFT - False - False - 0 - 0 - 0 - 0 - notes_text - - - 0 - 1 - 5 - 6 - fill - fill - - - - - - True - This account is present solely as a placeholder in the hierarchy. Transactions may not be posted to this account, only to sub-accounts of this account. - True - Placeholde_r - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - 2 - 7 - 8 - fill - - - - - - - True - True - Ta_x related - True - GTK_RELIEF_NORMAL - True - False - False - True - - - 0 - 2 - 6 - 7 - fill - - - 1 @@ -3092,18 +3113,17 @@ EUR 0 - + True - Hide accounts which have a zero total value. True - Hide _zero totals + Show _hidden accounts True GTK_RELIEF_NORMAL True False False True - + 0 @@ -3113,7 +3133,24 @@ EUR - + + True + Hide accounts which have a zero total value. + True + Show _zero total accounts + True + GTK_RELIEF_NORMAL + True + False + False + True + + + + 0 + False + False + @@ -3129,7 +3166,7 @@ EUR True - Balances + Other False False GTK_JUSTIFY_LEFT diff --git a/src/gnome/gnc-plugin-page-account-tree.c b/src/gnome/gnc-plugin-page-account-tree.c index 28e5039111..30dd548cbc 100644 --- a/src/gnome/gnc-plugin-page-account-tree.c +++ b/src/gnome/gnc-plugin-page-account-tree.c @@ -323,7 +323,8 @@ gnc_plugin_page_account_tree_init (GncPluginPageAccountTree *plugin_page) /* Visisble types */ priv->fd.visible_types = -1; /* Start with all types */ - priv->fd.hide_zero_total = FALSE; + priv->fd.show_hidden = FALSE; + priv->fd.show_zero_total = TRUE; LEAVE("page %p, priv %p, action group %p", plugin_page, priv, action_group); diff --git a/src/gnome/gnc-plugin-page-budget.c b/src/gnome/gnc-plugin-page-budget.c index 2a6cd187a3..dd82c84a19 100644 --- a/src/gnome/gnc-plugin-page-budget.c +++ b/src/gnome/gnc-plugin-page-budget.c @@ -294,7 +294,8 @@ gnc_plugin_page_budget_init (GncPluginPageBudget *plugin_page) /* Visisble types */ priv->fd.visible_types = -1; /* Start with all types */ - priv->fd.hide_zero_total = FALSE; + priv->fd.show_hidden = TRUE; + priv->fd.show_zero_total = TRUE; priv->sigFigs = 1; recurrenceSet(&priv->r, 1, PERIOD_MONTH, NULL); diff --git a/src/register/ledger-core/split-register-load.c b/src/register/ledger-core/split-register-load.c index 465700dbee..c483f8a92c 100644 --- a/src/register/ledger-core/split-register-load.c +++ b/src/register/ledger-core/split-register-load.c @@ -556,6 +556,8 @@ gnc_split_register_load (SplitRegister *reg, GList * slist, static gboolean skip_cb (Account *account, gpointer x) { + if (xaccAccountIsHidden(account)) + return TRUE; return xaccAccountGetPlaceholder (account); }