From 94364fb33e3e44dfa314b8822a10b54a26b1db63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andreas=20K=C3=B6hler?= Date: Sat, 21 Apr 2007 12:00:56 +0000 Subject: [PATCH] Improve handling of the account in the account dialog. * rename xaccAccountTypesCompatibleWith to xaccParentAccountTypesCompatibleWith, typically allow ACCT_TYPE_ROOT as parent but not as child * remove ACCT_TYPE_ROOT from xaccAccountTypesValid * no need to single-case the root account in gnc_common_ok anymore git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@15946 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/Account.c | 16 ++++++++++------ src/engine/Account.h | 7 ++++--- src/gnome-utils/dialog-account.c | 5 ++--- src/gnome-utils/gnc-tree-model-account-types.h | 2 +- 4 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/engine/Account.c b/src/engine/Account.c index 6c340c3d05..96483ad1fb 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -3759,7 +3759,7 @@ xaccAccountGetTypeFromStr (const gchar *str) \********************************************************************/ guint32 -xaccAccountTypesCompatibleWith (GNCAccountType type) +xaccParentAccountTypesCompatibleWith (GNCAccountType type) { switch (type) { case ACCT_TYPE_BANK: @@ -3782,15 +3782,18 @@ xaccAccountTypesCompatibleWith (GNCAccountType type) (1 << ACCT_TYPE_CREDIT) | (1 << ACCT_TYPE_LIABILITY) | (1 << ACCT_TYPE_RECEIVABLE) | - (1 << ACCT_TYPE_PAYABLE); + (1 << ACCT_TYPE_PAYABLE) | + (1 << ACCT_TYPE_ROOT); case ACCT_TYPE_INCOME: case ACCT_TYPE_EXPENSE: return (1 << ACCT_TYPE_INCOME) | - (1 << ACCT_TYPE_EXPENSE); + (1 << ACCT_TYPE_EXPENSE) | + (1 << ACCT_TYPE_ROOT); case ACCT_TYPE_EQUITY: return - (1 << ACCT_TYPE_EQUITY); + (1 << ACCT_TYPE_EQUITY) | + (1 << ACCT_TYPE_ROOT); default: PERR("bad account type: %d", type); return 0; @@ -3801,7 +3804,7 @@ gboolean xaccAccountTypesCompatible (GNCAccountType parent_type, GNCAccountType child_type) { - return ((xaccAccountTypesCompatibleWith (parent_type) & + return ((xaccParentAccountTypesCompatibleWith (parent_type) & (1 << child_type)) != 0); } @@ -3810,7 +3813,8 @@ guint32 xaccAccountTypesValid(void) { guint32 mask = (1 << NUM_ACCOUNT_TYPES) - 1; - mask &= ~(1 << ACCT_TYPE_CURRENCY); /* DEPRECATED */ + mask &= ~((1 << ACCT_TYPE_CURRENCY) | /* DEPRECATED */ + (1 << ACCT_TYPE_ROOT)); /* ROOT */ return mask; } diff --git a/src/engine/Account.h b/src/engine/Account.h index 42c4329c1f..2fc739d9bb 100644 --- a/src/engine/Account.h +++ b/src/engine/Account.h @@ -946,15 +946,16 @@ const char * xaccAccountGetTypeStr (GNCAccountType type); * to the local language. */ GNCAccountType xaccAccountGetTypeFromStr (const gchar *str); -/** Return the bitmask of account types compatible with a given type. */ -guint32 xaccAccountTypesCompatibleWith (GNCAccountType type); +/** Return the bitmask of parent account types compatible with a given type. */ +guint32 xaccParentAccountTypesCompatibleWith (GNCAccountType type); /** Return TRUE if accounts of type parent_type can have accounts * of type child_type as children. */ gboolean xaccAccountTypesCompatible (GNCAccountType parent_type, GNCAccountType child_type); -/* Returns the bitmask of the account type enums that are valid. */ +/** Returns the bitmask of the account type enums that are valid. Deprecated and + * root account types are stripped. */ guint32 xaccAccountTypesValid(void); diff --git a/src/gnome-utils/dialog-account.c b/src/gnome-utils/dialog-account.c index c8c5655271..98069a4db8 100644 --- a/src/gnome-utils/dialog-account.c +++ b/src/gnome-utils/dialog-account.c @@ -750,8 +750,7 @@ gnc_common_ok (AccountWindow *aw) } /* check whether the types of child and parent are compatible */ - if (!gnc_account_is_root(parent) && - !xaccAccountTypesCompatible (aw->type, xaccAccountGetType (parent))) { + if (!xaccAccountTypesCompatible (aw->type, xaccAccountGetType (parent))) { const char *message = _("The selected account type is incompatible with " "the one of the selected parent."); gnc_error_dialog(aw->dialog, message); @@ -969,7 +968,7 @@ gnc_account_parent_changed_cb (GtkTreeSelection *selection, gpointer data) types = aw->valid_types; } else { types = aw->valid_types & - xaccAccountTypesCompatibleWith (xaccAccountGetType (parent_account)); + xaccParentAccountTypesCompatibleWith (xaccAccountGetType (parent_account)); } type_model = gtk_tree_view_get_model (GTK_TREE_VIEW (aw->type_view)); diff --git a/src/gnome-utils/gnc-tree-model-account-types.h b/src/gnome-utils/gnc-tree-model-account-types.h index 0994a21804..aea388ced6 100644 --- a/src/gnome-utils/gnc-tree-model-account-types.h +++ b/src/gnome-utils/gnc-tree-model-account-types.h @@ -94,7 +94,7 @@ GType gnc_tree_model_account_types_get_type (void); /*************** Method 1 functions ***************/ -/* Returns a GtkTreeModelFilter that wraps the model. Deprecated +/* Returns a GtkTreeModelFilter that wraps the model. Deprecated and root account types will be filtered. Caller is responsible for ref/unref. */ GtkTreeModel * gnc_tree_model_account_types_valid (void);