Filter out deprecated account types from the account types treemodel.

Patch by Eskil Bylund <eskil.bylund@gmail.com>


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@12900 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Chris Shoemaker 2006-01-19 18:02:18 +00:00
parent 540cca4e7a
commit 01940cadb9
5 changed files with 76 additions and 52 deletions

View File

@ -105,6 +105,7 @@ Simon Britnell <simon.britnell@peace.com> patch to RPM spec
Christopher B. Browne <cbbrowne@hex.net> for perl, lots of scheme and documentation updates
Johan Buret <johanburet@free.fr> french translation
Thomas Bushnell <tb@becket.net> fix for file backups
Eskil Bylund <eskil.bylund@gmail.com> account type deprecation
Paul Campbell <kemitix@users.sourceforge.net> reconcile children patch
Conrad Canterford <conrad@mail.watersprite.com.au> register bug fix
Bill Carlson <wwc@wwcnet.nu> performance improvements

View File

@ -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;
}
/********************************************************************\
\********************************************************************/

View File

@ -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);
/** @} */
/* ------------------ */

View File

@ -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 <c.shoemaker@cox.net>
* Author: Jan Arne Petersen <jpetersen@uni-bonn.de>
* Copyright (C) 2003 Jan Arne Petersen <jpetersen@uni-bonn.de>
* Copyright (C) 2005, 2006 Chris Shoemaker <c.shoemaker@cox.net>
* Copyright (C) 2006 Eskil Bylund <eskil.bylund@gmail.com>
*
* 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)
{

View File

@ -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 <c.shoemaker@cox.net>
* Author: Jan Arne Petersen <jpetersen@uni-bonn.de>
* Copyright (C) 2003 Jan Arne Petersen <jpetersen@uni-bonn.de>
* Copyright (C) 2005, 2006 Chris Shoemaker <c.shoemaker@cox.net>
* Copyright (C) 2006 Eskil Bylund <eskil.bylund@gmail.com>
*
* 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 <jpetersen@uni-bonn.de>
*
@ -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);