From 01940cadb95107e6d8f79fc978e9a4b0f92756b5 Mon Sep 17 00:00:00 2001 From: Chris Shoemaker Date: Thu, 19 Jan 2006 18:02:18 +0000 Subject: [PATCH] Filter out deprecated account types from the account types treemodel. Patch by Eskil Bylund git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@12900 57a11ea4-9604-0410-9ed3-97b8803252fd --- AUTHORS | 1 + src/engine/Account.c | 11 +++ src/engine/Account.h | 8 +- .../gnc-tree-model-account-types.c | 83 +++++++++---------- .../gnc-tree-model-account-types.h | 25 ++++-- 5 files changed, 76 insertions(+), 52 deletions(-) diff --git a/AUTHORS b/AUTHORS index 790ce163f0..2fbfbfd992 100644 --- a/AUTHORS +++ b/AUTHORS @@ -105,6 +105,7 @@ Simon Britnell patch to RPM spec Christopher B. Browne for perl, lots of scheme and documentation updates Johan Buret french translation Thomas Bushnell fix for file backups +Eskil Bylund account type deprecation Paul Campbell reconcile children patch Conrad Canterford register bug fix Bill Carlson performance improvements diff --git a/src/engine/Account.c b/src/engine/Account.c index c384d9cb3e..aba12e3591 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -2322,6 +2322,17 @@ xaccAccountTypesCompatible (GNCAccountType parent_type, return compatible; } +guint32 +xaccAccountTypesValid(void) +{ + guint32 mask = (1 << NUM_ACCOUNT_TYPES) - 1; + mask &= ~(1 << CURRENCY); /* DEPRECATED */ + + return mask; +} + + + /********************************************************************\ \********************************************************************/ diff --git a/src/engine/Account.h b/src/engine/Account.h index 4c1de82a44..9af14a4002 100644 --- a/src/engine/Account.h +++ b/src/engine/Account.h @@ -96,8 +96,7 @@ typedef enum * three columns: price, number of shares, and * value. Note: Since version 1.7.0, this account is * no longer needed to exchange currencies between - * accounts, so this type will probably become - * deprecated sometime in the future. */ + * accounts, so this type is DEPRECATED. */ INCOME = 8, /**< Income accounts are used to denote income */ EXPENSE = 9,/**< Expense accounts are used to denote expenses. */ @@ -495,6 +494,11 @@ GNCAccountType xaccAccountGetTypeFromStr (const gchar *str); * 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. */ +guint32 xaccAccountTypesValid(void); + + /** @} */ /* ------------------ */ diff --git a/src/gnome-utils/gnc-tree-model-account-types.c b/src/gnome-utils/gnc-tree-model-account-types.c index 3015b90207..bba7de733a 100644 --- a/src/gnome-utils/gnc-tree-model-account-types.c +++ b/src/gnome-utils/gnc-tree-model-account-types.c @@ -2,9 +2,9 @@ * gnc-tree-model-account-types.c -- GtkTreeModel implementation * to display account types in a GtkTreeView. * - * Copyright (C) 2003 Jan Arne Petersen - * Copyright (C) 2005, Chris Shoemaker - * Author: Jan Arne Petersen + * Copyright (C) 2003 Jan Arne Petersen + * Copyright (C) 2005, 2006 Chris Shoemaker + * Copyright (C) 2006 Eskil Bylund * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -47,54 +47,14 @@ gnc_tree_model_account_types_finalize (GObject * object); static void gnc_tree_model_account_types_tree_model_init (GtkTreeModelIface * iface); -/* -static guint -gnc_tree_model_account_types_get_flags (GtkTreeModel * tree_model); -static int -gnc_tree_model_account_types_get_n_columns (GtkTreeModel * tree_model); -static GType -gnc_tree_model_account_types_get_column_type (GtkTreeModel * tree_model, - int index); -static gboolean -gnc_tree_model_account_types_get_iter (GtkTreeModel * tree_model, - GtkTreeIter * iter, GtkTreePath * path); -static GtkTreePath * -gnc_tree_model_account_types_get_path (GtkTreeModel * tree_model, - GtkTreeIter * iter); -static void -gnc_tree_model_account_types_get_value (GtkTreeModel * tree_model, - GtkTreeIter * iter, int column, - GValue * value); -static gboolean -gnc_tree_model_account_types_iter_next (GtkTreeModel * tree_model, - GtkTreeIter * iter); -static gboolean -gnc_tree_model_account_types_iter_children (GtkTreeModel * tree_model, - GtkTreeIter * iter, - GtkTreeIter * parent); -static gboolean -gnc_tree_model_account_types_iter_has_child (GtkTreeModel * tree_model, - GtkTreeIter * iter); -static int -gnc_tree_model_account_types_iter_n_children (GtkTreeModel * tree_model, - GtkTreeIter * iter); -static gboolean -gnc_tree_model_account_types_iter_nth_child (GtkTreeModel * tree_model, - GtkTreeIter * iter, - GtkTreeIter * parent, int n); -static gboolean -gnc_tree_model_account_types_iter_parent (GtkTreeModel * tree_model, - GtkTreeIter * iter, - GtkTreeIter * child); -*/ - typedef struct GncTreeModelAccountTypesPrivate { guint32 selected; } GncTreeModelAccountTypesPrivate; #define GNC_TREE_MODEL_ACCOUNT_TYPES_GET_PRIVATE(o) \ - (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES, GncTreeModelAccountTypesPrivate)) + (G_TYPE_INSTANCE_GET_PRIVATE ((o), GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES, \ + GncTreeModelAccountTypesPrivate)) static GObjectClass *parent_class = NULL; @@ -193,6 +153,39 @@ gnc_tree_model_account_types_master(void) } +static gboolean +gnc_tree_model_account_types_is_valid (GtkTreeModel *model, + GtkTreeIter *iter, gpointer data) +{ + GNCAccountType type; + guint32 valid_types = GPOINTER_TO_UINT (data); + + gtk_tree_model_get (model, iter, + GNC_TREE_MODEL_ACCOUNT_TYPES_COL_TYPE, &type, -1); + return (valid_types & (1 << type)) ? TRUE : FALSE; +} + +GtkTreeModel * +gnc_tree_model_account_types_valid (void) +{ + return gnc_tree_model_account_types_filter_using_mask( + xaccAccountTypesValid()); +} + +GtkTreeModel * +gnc_tree_model_account_types_filter_using_mask (guint32 types) +{ + GtkTreeModel *f_model; + + f_model = gtk_tree_model_filter_new(gnc_tree_model_account_types_master(), + NULL); + gtk_tree_model_filter_set_visible_func ( + GTK_TREE_MODEL_FILTER (f_model), gnc_tree_model_account_types_is_valid, + GUINT_TO_POINTER (types), NULL); + + return f_model; +} + guint32 gnc_tree_model_account_types_get_selected (GncTreeModelAccountTypes * model) { diff --git a/src/gnome-utils/gnc-tree-model-account-types.h b/src/gnome-utils/gnc-tree-model-account-types.h index 8121e2477c..d8f67cdb96 100644 --- a/src/gnome-utils/gnc-tree-model-account-types.h +++ b/src/gnome-utils/gnc-tree-model-account-types.h @@ -2,9 +2,9 @@ * gnc-tree-model-account-types.h -- GtkTreeModel implementation * to display account types in a GtkTreeView. * - * Copyright (C) 2003 Jan Arne Petersen - * Copyright (C) 2005, Chris Shoemaker - * Author: Jan Arne Petersen + * Copyright (C) 2003 Jan Arne Petersen + * Copyright (C) 2005, 2006 Chris Shoemaker + * Copyright (C) 2006 Eskil Bylund * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as @@ -28,7 +28,8 @@ /** @addtogroup GuiTreeModel * @{ */ /** @file gnc-tree-model-account-types.h - * @brief GtkTreeModel implementation to display account types in a GtkTreeView. + * @brief GtkTreeModel implementation to display account types in a + * GtkTreeView. * @author Copyright (C) 2003 Jan Arne Petersen * @author: Jan Arne Petersen * @@ -93,9 +94,23 @@ GType gnc_tree_model_account_types_get_type (void); /* Get the static GtkTreeModel representing the list of all possible account types. You may not modify this model, but you can use if - for multiple views. */ + for multiple views. You probably want gnc_tree_model_types_valid(). */ GtkTreeModel * gnc_tree_model_account_types_master(void); +/* Returns a GtkTreeModelFilter that wraps the model. Deprecated + account types will be filtered. Use this instead of + gnc_tree_model_account_types_master. Caller is responsible for + ref/unref. */ +GtkTreeModel * gnc_tree_model_account_types_valid (void); + +/* Returns a GtkTreeModelFilter that wraps the model. Only account + types specified by the 'types' bitmask are visible. To force the + visibility of deprecated account types, pass + (xaccAccountTypesValid() & (1 << MY_DEPRECATED_ACCOUNT_TYPE)). + + Caller is responsible for ref/unref. */ +GtkTreeModel * gnc_tree_model_account_types_filter_using_mask (guint32 types); + /* Return the bitmask of the account type enums reflecting the state of the tree selection */ guint32 gnc_tree_model_account_types_get_selection(GtkTreeView *view);