2006/1/17, Chris Shoemaker <[EMAIL PROTECTED]>:
> If you want to continue with this, here's what I suggest:
>
>   1) move the filter function into gnc-tree-model-account-types.c.  I
> think it can be private because...
>   2) add a public convenience routine to
> gnc-tree-model-account-types.[ch] that will return a filter model
> already wrapped around the master account_types tree model.  This
> function does the middle chunk of what your
> gnc_account_type_combo_box_init() does.  Let this function take the
> "valid_types" mask, and pass it as data to the filter function setter.
>   3) change the filter function to take just the valid_types as data
> -- no need for a struct.
>

The attached patch implements this. How does it look?

The gnc_tree_model_account_types_filter_get_valid_types function
should probably be put in the engine, but I'll leave that to you since
I wouldn't know where.
Index: src/gnome-utils/gnc-tree-model-account-types.c
===================================================================
--- src/gnome-utils/gnc-tree-model-account-types.c	(revision 12371)
+++ src/gnome-utils/gnc-tree-model-account-types.c	(arbetskopia)
@@ -193,7 +193,55 @@
 }
 
 
+static gboolean
+gnc_tree_model_account_types_is_visible (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
+{
+    GNCAccountType type;
+    guint32 valid_types;
+
+    gtk_tree_model_get (model, iter, GNC_TREE_MODEL_ACCOUNT_TYPES_COL_TYPE, &type, -1);
+    valid_types = GPOINTER_TO_UINT (data);
+
+    return (valid_types & (1 << type)) ? TRUE : FALSE;
+}
+
+GtkTreeModel *
+gnc_tree_model_account_types_filter (GncTreeModelAccountTypes *model)
+{
+    return gnc_tree_model_account_types_filter_using_mask (model,
+                                                           gnc_tree_model_account_types_filter_get_valid_types ());
+}
+
+GtkTreeModel *
+gnc_tree_model_account_types_filter_using_mask (GncTreeModelAccountTypes *model, guint32 types)
+{
+    GtkTreeModel *f_model;
+
+    if (model == NULL)
+        model = GNC_TREE_MODEL_ACCOUNT_TYPES (gnc_tree_model_account_types_master ());
+    else
+        g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT_TYPES (model), NULL);
+
+    f_model = gtk_tree_model_filter_new (GTK_TREE_MODEL (model), NULL);
+    gtk_tree_model_filter_set_visible_func (GTK_TREE_MODEL_FILTER (f_model),
+                                            gnc_tree_model_account_types_is_visible,
+                                            GUINT_TO_POINTER (types),
+                                            NULL);
+
+    return f_model;
+}
+
 guint32
+gnc_tree_model_account_types_filter_get_valid_types (void)
+{
+    guint32 mask = -1;
+    mask &= ~(1 << CURRENCY);
+
+    return mask;
+}
+
+
+guint32
 gnc_tree_model_account_types_get_selected (GncTreeModelAccountTypes * model)
 {
 	GncTreeModelAccountTypesPrivate *priv;
Index: src/gnome-utils/gnc-tree-model-account-types.h
===================================================================
--- src/gnome-utils/gnc-tree-model-account-types.h	(revision 12371)
+++ src/gnome-utils/gnc-tree-model-account-types.h	(arbetskopia)
@@ -96,6 +96,20 @@
    for multiple views. */
 GtkTreeModel * gnc_tree_model_account_types_master(void);
 
+/* Returns a GtkTreeModelFilter that wraps the model. Deprecated account
+   types will be filtered. You probably want to use this instead of
+   gnc_tree_model_account_types_master. If the model is NULL the static
+   model will be used. */
+GtkTreeModel * gnc_tree_model_account_types_filter (GncTreeModelAccountTypes *model);
+
+/* Returns a GtkTreeModelFilter that wraps the model. Account types will
+   be filtered using the account type enums bitmask. If the model is NULL
+   the static model will be used.*/
+GtkTreeModel * gnc_tree_model_account_types_filter_using_mask (GncTreeModelAccountTypes *model, guint32 types);
+
+/* Returns the bitmask of the account type enums that are valid. */
+guint32 gnc_tree_model_account_types_filter_get_valid_types (void);
+
 /* 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);
_______________________________________________
gnucash-devel mailing list
[email protected]
https://lists.gnucash.org/mailman/listinfo/gnucash-devel

Reply via email to