mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Merge Richard Cohen's 'declare-type-gnc-tree-model' into stable.
This commit is contained in:
commit
eee5f674c4
@ -46,16 +46,15 @@ gnc_tree_model_account_types_finalize (GObject * object);
|
|||||||
static void
|
static void
|
||||||
gnc_tree_model_account_types_tree_model_init (GtkTreeModelIface * iface);
|
gnc_tree_model_account_types_tree_model_init (GtkTreeModelIface * iface);
|
||||||
|
|
||||||
typedef struct GncTreeModelAccountTypesPrivate
|
struct _GncTreeModelAccountTypes
|
||||||
{
|
{
|
||||||
guint32 selected;
|
GObject gobject;
|
||||||
} GncTreeModelAccountTypesPrivate;
|
int stamp;
|
||||||
|
|
||||||
#define GNC_TREE_MODEL_ACCOUNT_TYPES_GET_PRIVATE(o) \
|
guint32 selected;
|
||||||
((GncTreeModelAccountTypesPrivate*)gnc_tree_model_account_types_get_instance_private((GncTreeModelAccountTypes*)o))
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_CODE(GncTreeModelAccountTypes, gnc_tree_model_account_types, G_TYPE_OBJECT,
|
G_DEFINE_TYPE_WITH_CODE(GncTreeModelAccountTypes, gnc_tree_model_account_types, G_TYPE_OBJECT,
|
||||||
G_ADD_PRIVATE(GncTreeModelAccountTypes)
|
|
||||||
G_IMPLEMENT_INTERFACE(GTK_TYPE_TREE_MODEL,
|
G_IMPLEMENT_INTERFACE(GTK_TYPE_TREE_MODEL,
|
||||||
gnc_tree_model_account_types_tree_model_init))
|
gnc_tree_model_account_types_tree_model_init))
|
||||||
|
|
||||||
@ -88,12 +87,8 @@ gnc_tree_model_account_types_finalize (GObject * object)
|
|||||||
GtkTreeModel *
|
GtkTreeModel *
|
||||||
gnc_tree_model_account_types_new (guint32 selected)
|
gnc_tree_model_account_types_new (guint32 selected)
|
||||||
{
|
{
|
||||||
GncTreeModelAccountTypes *model;
|
GncTreeModelAccountTypes *model = g_object_new (GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES, NULL);
|
||||||
GncTreeModelAccountTypesPrivate *priv;
|
model->selected = selected;
|
||||||
|
|
||||||
model = g_object_new (GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES, NULL);
|
|
||||||
priv = GNC_TREE_MODEL_ACCOUNT_TYPES_GET_PRIVATE(model);
|
|
||||||
priv->selected = selected;
|
|
||||||
|
|
||||||
return GTK_TREE_MODEL (model);
|
return GTK_TREE_MODEL (model);
|
||||||
}
|
}
|
||||||
@ -407,13 +402,11 @@ gnc_tree_model_account_types_get_value (GtkTreeModel * tree_model,
|
|||||||
GValue * value)
|
GValue * value)
|
||||||
{
|
{
|
||||||
GncTreeModelAccountTypes *model = GNC_TREE_MODEL_ACCOUNT_TYPES(tree_model);
|
GncTreeModelAccountTypes *model = GNC_TREE_MODEL_ACCOUNT_TYPES(tree_model);
|
||||||
GncTreeModelAccountTypesPrivate *priv;
|
|
||||||
|
|
||||||
g_return_if_fail (GNC_IS_TREE_MODEL_ACCOUNT_TYPES (model));
|
g_return_if_fail (GNC_IS_TREE_MODEL_ACCOUNT_TYPES (model));
|
||||||
g_return_if_fail (iter != NULL);
|
g_return_if_fail (iter != NULL);
|
||||||
g_return_if_fail (iter->stamp == model->stamp);
|
g_return_if_fail (iter->stamp == model->stamp);
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_ACCOUNT_TYPES_GET_PRIVATE(model);
|
|
||||||
switch (column)
|
switch (column)
|
||||||
{
|
{
|
||||||
case GNC_TREE_MODEL_ACCOUNT_TYPES_COL_TYPE:
|
case GNC_TREE_MODEL_ACCOUNT_TYPES_COL_TYPE:
|
||||||
@ -427,7 +420,7 @@ gnc_tree_model_account_types_get_value (GtkTreeModel * tree_model,
|
|||||||
break;
|
break;
|
||||||
case GNC_TREE_MODEL_ACCOUNT_TYPES_COL_SELECTED:
|
case GNC_TREE_MODEL_ACCOUNT_TYPES_COL_SELECTED:
|
||||||
g_value_init (value, G_TYPE_BOOLEAN);
|
g_value_init (value, G_TYPE_BOOLEAN);
|
||||||
g_value_set_boolean (value, priv->selected &
|
g_value_set_boolean (value, model->selected &
|
||||||
(1 << GPOINTER_TO_INT (iter->user_data)));
|
(1 << GPOINTER_TO_INT (iter->user_data)));
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -44,11 +44,7 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
/* type macros */
|
/* type macros */
|
||||||
#define GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES (gnc_tree_model_account_types_get_type ())
|
#define GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES (gnc_tree_model_account_types_get_type ())
|
||||||
#define GNC_TREE_MODEL_ACCOUNT_TYPES(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES, GncTreeModelAccountTypes))
|
G_DECLARE_FINAL_TYPE (GncTreeModelAccountTypes, gnc_tree_model_account_types, GNC, TREE_MODEL_ACCOUNT_TYPES, GObject)
|
||||||
#define GNC_TREE_MODEL_ACCOUNT_TYPES_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES, GncTreeModelAccountTypesClass))
|
|
||||||
#define GNC_IS_TREE_MODEL_ACCOUNT_TYPES(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES))
|
|
||||||
#define GNC_IS_TREE_MODEL_ACCOUNT_TYPES_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES))
|
|
||||||
#define GNC_TREE_MODEL_ACCOUNT_TYPES_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES, GncTreeModelAccountTypesClass))
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
@ -58,20 +54,7 @@ typedef enum
|
|||||||
GNC_TREE_MODEL_ACCOUNT_TYPES_NUM_COLUMNS
|
GNC_TREE_MODEL_ACCOUNT_TYPES_NUM_COLUMNS
|
||||||
} GncTreeModelAccountTypesColumn;
|
} GncTreeModelAccountTypesColumn;
|
||||||
|
|
||||||
/* typedefs & structures */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GObject gobject;
|
|
||||||
int stamp;
|
|
||||||
} GncTreeModelAccountTypes;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GObjectClass gobject;
|
|
||||||
} GncTreeModelAccountTypesClass;
|
|
||||||
|
|
||||||
/* function prototypes */
|
/* function prototypes */
|
||||||
GType gnc_tree_model_account_types_get_type (void);
|
|
||||||
|
|
||||||
/* Choose one of two methods to use the GncTreeModelAccountTypes
|
/* Choose one of two methods to use the GncTreeModelAccountTypes
|
||||||
objects defined here, depending on how you want to deal with
|
objects defined here, depending on how you want to deal with
|
||||||
|
@ -90,9 +90,12 @@ static void gnc_tree_model_account_event_handler (QofInstance *entity,
|
|||||||
GncTreeModelAccount *model,
|
GncTreeModelAccount *model,
|
||||||
GncEventData *ed);
|
GncEventData *ed);
|
||||||
|
|
||||||
/** The instance private data for an account tree model. */
|
/** The instance data structure for an account tree model. */
|
||||||
typedef struct GncTreeModelAccountPrivate
|
struct _GncTreeModelAccount
|
||||||
{
|
{
|
||||||
|
GncTreeModel gnc_tree_model; /**< The parent object data. */
|
||||||
|
int stamp; /**< The state of the model. Any state
|
||||||
|
* change increments this number. */
|
||||||
QofBook *book;
|
QofBook *book;
|
||||||
Account *root;
|
Account *root;
|
||||||
gint event_handler_id;
|
gint event_handler_id;
|
||||||
@ -100,18 +103,13 @@ typedef struct GncTreeModelAccountPrivate
|
|||||||
|
|
||||||
GHashTable *account_values_hash;
|
GHashTable *account_values_hash;
|
||||||
|
|
||||||
} GncTreeModelAccountPrivate;
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_CODE (GncTreeModelAccount,
|
G_DEFINE_TYPE_WITH_CODE (GncTreeModelAccount,
|
||||||
gnc_tree_model_account, GNC_TYPE_TREE_MODEL,
|
gnc_tree_model_account, GNC_TYPE_TREE_MODEL,
|
||||||
G_ADD_PRIVATE (GncTreeModelAccount)
|
|
||||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL,
|
G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL,
|
||||||
gnc_tree_model_account_tree_model_init))
|
gnc_tree_model_account_tree_model_init))
|
||||||
|
|
||||||
#define GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(o) \
|
|
||||||
((GncTreeModelAccountPrivate*)gnc_tree_model_account_get_instance_private((GncTreeModelAccount*)o))
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************************/
|
/************************************************************/
|
||||||
/* Account Tree Model - Misc Functions */
|
/* Account Tree Model - Misc Functions */
|
||||||
/************************************************************/
|
/************************************************************/
|
||||||
@ -126,28 +124,25 @@ G_DEFINE_TYPE_WITH_CODE (GncTreeModelAccount,
|
|||||||
static void
|
static void
|
||||||
gnc_tree_model_account_update_color (gpointer gsettings, gchar *key, gpointer user_data)
|
gnc_tree_model_account_update_color (gpointer gsettings, gchar *key, gpointer user_data)
|
||||||
{
|
{
|
||||||
GncTreeModelAccountPrivate *priv;
|
|
||||||
GncTreeModelAccount *model;
|
|
||||||
gboolean use_red;
|
gboolean use_red;
|
||||||
|
|
||||||
g_return_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(user_data));
|
g_return_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(user_data));
|
||||||
model = user_data;
|
GncTreeModelAccount *model = user_data;
|
||||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
// destroy/recreate the cached account value hash to force update
|
// destroy/recreate the cached account value hash to force update
|
||||||
g_hash_table_destroy (priv->account_values_hash);
|
g_hash_table_destroy (model->account_values_hash);
|
||||||
priv->account_values_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
|
model->account_values_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
g_free, g_free);
|
g_free, g_free);
|
||||||
|
|
||||||
use_red = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED);
|
use_red = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED);
|
||||||
|
|
||||||
if (priv->negative_color)
|
if (model->negative_color)
|
||||||
g_free (priv->negative_color);
|
g_free (model->negative_color);
|
||||||
|
|
||||||
if (use_red)
|
if (use_red)
|
||||||
priv->negative_color = gnc_get_negative_color ();
|
model->negative_color = gnc_get_negative_color ();
|
||||||
else
|
else
|
||||||
priv->negative_color = NULL;
|
model->negative_color = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/************************************************************/
|
/************************************************************/
|
||||||
@ -169,7 +164,6 @@ gnc_tree_model_account_class_init (GncTreeModelAccountClass *klass)
|
|||||||
static void
|
static void
|
||||||
gnc_tree_model_account_init (GncTreeModelAccount *model)
|
gnc_tree_model_account_init (GncTreeModelAccount *model)
|
||||||
{
|
{
|
||||||
GncTreeModelAccountPrivate *priv;
|
|
||||||
gboolean use_red;
|
gboolean use_red;
|
||||||
|
|
||||||
ENTER("model %p", model);
|
ENTER("model %p", model);
|
||||||
@ -180,20 +174,19 @@ gnc_tree_model_account_init (GncTreeModelAccount *model)
|
|||||||
|
|
||||||
use_red = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED);
|
use_red = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED);
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
model->book = NULL;
|
||||||
priv->book = NULL;
|
model->root = NULL;
|
||||||
priv->root = NULL;
|
|
||||||
|
|
||||||
if (priv->negative_color)
|
if (model->negative_color)
|
||||||
g_free (priv->negative_color);
|
g_free (model->negative_color);
|
||||||
|
|
||||||
if (use_red)
|
if (use_red)
|
||||||
priv->negative_color = gnc_get_negative_color ();
|
model->negative_color = gnc_get_negative_color ();
|
||||||
else
|
else
|
||||||
priv->negative_color = NULL;
|
model->negative_color = NULL;
|
||||||
|
|
||||||
// create the account values cache hash
|
// create the account values cache hash
|
||||||
priv->account_values_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
|
model->account_values_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
g_free, g_free);
|
g_free, g_free);
|
||||||
|
|
||||||
gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED,
|
gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED,
|
||||||
@ -206,7 +199,6 @@ gnc_tree_model_account_init (GncTreeModelAccount *model)
|
|||||||
static void
|
static void
|
||||||
gnc_tree_model_account_finalize (GObject *object)
|
gnc_tree_model_account_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
GncTreeModelAccountPrivate *priv;
|
|
||||||
GncTreeModelAccount *model;
|
GncTreeModelAccount *model;
|
||||||
|
|
||||||
g_return_if_fail (object != NULL);
|
g_return_if_fail (object != NULL);
|
||||||
@ -215,9 +207,8 @@ gnc_tree_model_account_finalize (GObject *object)
|
|||||||
ENTER("model %p", object);
|
ENTER("model %p", object);
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_ACCOUNT(object);
|
model = GNC_TREE_MODEL_ACCOUNT(object);
|
||||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
priv->book = NULL;
|
model->book = NULL;
|
||||||
|
|
||||||
G_OBJECT_CLASS(gnc_tree_model_account_parent_class)->finalize (object);
|
G_OBJECT_CLASS(gnc_tree_model_account_parent_class)->finalize (object);
|
||||||
LEAVE(" ");
|
LEAVE(" ");
|
||||||
@ -226,7 +217,6 @@ gnc_tree_model_account_finalize (GObject *object)
|
|||||||
static void
|
static void
|
||||||
gnc_tree_model_account_dispose (GObject *object)
|
gnc_tree_model_account_dispose (GObject *object)
|
||||||
{
|
{
|
||||||
GncTreeModelAccountPrivate *priv;
|
|
||||||
GncTreeModelAccount *model;
|
GncTreeModelAccount *model;
|
||||||
|
|
||||||
g_return_if_fail (object != NULL);
|
g_return_if_fail (object != NULL);
|
||||||
@ -235,19 +225,18 @@ gnc_tree_model_account_dispose (GObject *object)
|
|||||||
ENTER("model %p", object);
|
ENTER("model %p", object);
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_ACCOUNT(object);
|
model = GNC_TREE_MODEL_ACCOUNT(object);
|
||||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
if (priv->event_handler_id)
|
if (model->event_handler_id)
|
||||||
{
|
{
|
||||||
qof_event_unregister_handler (priv->event_handler_id);
|
qof_event_unregister_handler (model->event_handler_id);
|
||||||
priv->event_handler_id = 0;
|
model->event_handler_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priv->negative_color)
|
if (model->negative_color)
|
||||||
g_free (priv->negative_color);
|
g_free (model->negative_color);
|
||||||
|
|
||||||
// destroy the cached account values
|
// destroy the cached account values
|
||||||
g_hash_table_destroy (priv->account_values_hash);
|
g_hash_table_destroy (model->account_values_hash);
|
||||||
|
|
||||||
gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED,
|
gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED,
|
||||||
gnc_tree_model_account_update_color,
|
gnc_tree_model_account_update_color,
|
||||||
@ -266,7 +255,6 @@ GtkTreeModel *
|
|||||||
gnc_tree_model_account_new (Account *root)
|
gnc_tree_model_account_new (Account *root)
|
||||||
{
|
{
|
||||||
GncTreeModelAccount *model;
|
GncTreeModelAccount *model;
|
||||||
GncTreeModelAccountPrivate *priv;
|
|
||||||
const GList *item;
|
const GList *item;
|
||||||
|
|
||||||
ENTER("root %p", root);
|
ENTER("root %p", root);
|
||||||
@ -274,8 +262,7 @@ gnc_tree_model_account_new (Account *root)
|
|||||||
for ( ; item; item = g_list_next (item))
|
for ( ; item; item = g_list_next (item))
|
||||||
{
|
{
|
||||||
model = (GncTreeModelAccount *)item->data;
|
model = (GncTreeModelAccount *)item->data;
|
||||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
if (model->root == root)
|
||||||
if (priv->root == root)
|
|
||||||
{
|
{
|
||||||
g_object_ref (G_OBJECT(model));
|
g_object_ref (G_OBJECT(model));
|
||||||
LEAVE("returning existing model %p", model);
|
LEAVE("returning existing model %p", model);
|
||||||
@ -285,11 +272,10 @@ gnc_tree_model_account_new (Account *root)
|
|||||||
|
|
||||||
model = g_object_new (GNC_TYPE_TREE_MODEL_ACCOUNT, NULL);
|
model = g_object_new (GNC_TYPE_TREE_MODEL_ACCOUNT, NULL);
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
model->book = gnc_get_current_book();
|
||||||
priv->book = gnc_get_current_book();
|
model->root = root;
|
||||||
priv->root = root;
|
|
||||||
|
|
||||||
priv->event_handler_id = qof_event_register_handler
|
model->event_handler_id = qof_event_register_handler
|
||||||
((QofEventHandler)gnc_tree_model_account_event_handler, model);
|
((QofEventHandler)gnc_tree_model_account_event_handler, model);
|
||||||
|
|
||||||
LEAVE("model %p", model);
|
LEAVE("model %p", model);
|
||||||
@ -429,7 +415,6 @@ gnc_tree_model_account_get_iter (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *iter,
|
GtkTreeIter *iter,
|
||||||
GtkTreePath *path)
|
GtkTreePath *path)
|
||||||
{
|
{
|
||||||
GncTreeModelAccountPrivate *priv;
|
|
||||||
GncTreeModelAccount *model;
|
GncTreeModelAccount *model;
|
||||||
Account *account, *parent;
|
Account *account, *parent;
|
||||||
gint i, *indices;
|
gint i, *indices;
|
||||||
@ -443,7 +428,6 @@ gnc_tree_model_account_get_iter (GtkTreeModel *tree_model,
|
|||||||
}
|
}
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_ACCOUNT(tree_model);
|
model = GNC_TREE_MODEL_ACCOUNT(tree_model);
|
||||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
if (gtk_tree_path_get_depth (path) <= 0)
|
if (gtk_tree_path_get_depth (path) <= 0)
|
||||||
{
|
{
|
||||||
@ -459,7 +443,7 @@ gnc_tree_model_account_get_iter (GtkTreeModel *tree_model,
|
|||||||
}
|
}
|
||||||
|
|
||||||
parent = NULL;
|
parent = NULL;
|
||||||
account = priv->root;
|
account = model->root;
|
||||||
for (i = 1; i < gtk_tree_path_get_depth (path); i++)
|
for (i = 1; i < gtk_tree_path_get_depth (path); i++)
|
||||||
{
|
{
|
||||||
parent = account;
|
parent = account;
|
||||||
@ -486,7 +470,6 @@ gnc_tree_model_account_get_path (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GncTreeModelAccount *model = GNC_TREE_MODEL_ACCOUNT(tree_model);
|
GncTreeModelAccount *model = GNC_TREE_MODEL_ACCOUNT(tree_model);
|
||||||
GncTreeModelAccountPrivate *priv;
|
|
||||||
Account *account, *parent;
|
Account *account, *parent;
|
||||||
GtkTreePath *path;
|
GtkTreePath *path;
|
||||||
gint i;
|
gint i;
|
||||||
@ -498,8 +481,7 @@ gnc_tree_model_account_get_path (GtkTreeModel *tree_model,
|
|||||||
|
|
||||||
ENTER("model %p, iter %s", model, iter_to_string (iter));
|
ENTER("model %p, iter %s", model, iter_to_string (iter));
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
if (model->root == NULL)
|
||||||
if (priv->root == NULL)
|
|
||||||
{
|
{
|
||||||
LEAVE("failed (1)");
|
LEAVE("failed (1)");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -539,11 +521,8 @@ gnc_tree_model_account_set_color (GncTreeModelAccount *model,
|
|||||||
gboolean negative,
|
gboolean negative,
|
||||||
GValue *value)
|
GValue *value)
|
||||||
{
|
{
|
||||||
GncTreeModelAccountPrivate *priv;
|
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
|
||||||
if (negative)
|
if (negative)
|
||||||
g_value_set_static_string (value, priv->negative_color);
|
g_value_set_static_string (value, model->negative_color);
|
||||||
else
|
else
|
||||||
g_value_set_static_string (value, NULL);
|
g_value_set_static_string (value, NULL);
|
||||||
}
|
}
|
||||||
@ -554,7 +533,6 @@ gnc_tree_model_account_compute_period_balance (GncTreeModelAccount *model,
|
|||||||
gboolean recurse,
|
gboolean recurse,
|
||||||
gboolean *negative)
|
gboolean *negative)
|
||||||
{
|
{
|
||||||
GncTreeModelAccountPrivate *priv;
|
|
||||||
GNCPrintAmountInfo print_info;
|
GNCPrintAmountInfo print_info;
|
||||||
time64 t1, t2;
|
time64 t1, t2;
|
||||||
gnc_numeric b3;
|
gnc_numeric b3;
|
||||||
@ -562,8 +540,7 @@ gnc_tree_model_account_compute_period_balance (GncTreeModelAccount *model,
|
|||||||
if (negative)
|
if (negative)
|
||||||
*negative = FALSE;
|
*negative = FALSE;
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
if (acct == model->root)
|
||||||
if (acct == priv->root)
|
|
||||||
return g_strdup ("");
|
return g_strdup ("");
|
||||||
|
|
||||||
t1 = gnc_accounting_period_fiscal_start ();
|
t1 = gnc_accounting_period_fiscal_start ();
|
||||||
@ -597,11 +574,9 @@ gnc_tree_model_account_clear_cache (GncTreeModelAccount *model)
|
|||||||
{
|
{
|
||||||
if (model)
|
if (model)
|
||||||
{
|
{
|
||||||
GncTreeModelAccountPrivate *priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
// destroy the cached account values and recreate
|
// destroy the cached account values and recreate
|
||||||
g_hash_table_destroy (priv->account_values_hash);
|
g_hash_table_destroy (model->account_values_hash);
|
||||||
priv->account_values_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
|
model->account_values_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||||
g_free, g_free);
|
g_free, g_free);
|
||||||
|
|
||||||
gtk_tree_model_foreach (GTK_TREE_MODEL(model), row_changed_foreach_func, NULL);
|
gtk_tree_model_foreach (GTK_TREE_MODEL(model), row_changed_foreach_func, NULL);
|
||||||
@ -641,20 +616,19 @@ clear_account_cached_values (GncTreeModelAccount *model, GHashTable *hash, Accou
|
|||||||
static void
|
static void
|
||||||
gnc_tree_model_account_clear_cached_values (GncTreeModelAccount *model, Account *account)
|
gnc_tree_model_account_clear_cached_values (GncTreeModelAccount *model, Account *account)
|
||||||
{
|
{
|
||||||
GncTreeModelAccountPrivate *priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
|
||||||
Account *parent;
|
Account *parent;
|
||||||
|
|
||||||
// no hash table or account, return
|
// no hash table or account, return
|
||||||
if ((!priv->account_values_hash) || (!account))
|
if ((!model->account_values_hash) || (!account))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
clear_account_cached_values (model, priv->account_values_hash, account);
|
clear_account_cached_values (model, model->account_values_hash, account);
|
||||||
parent = gnc_account_get_parent (account);
|
parent = gnc_account_get_parent (account);
|
||||||
|
|
||||||
// clear also all parent accounts, this will update any balances/totals
|
// clear also all parent accounts, this will update any balances/totals
|
||||||
while (parent)
|
while (parent)
|
||||||
{
|
{
|
||||||
clear_account_cached_values (model, priv->account_values_hash, parent);
|
clear_account_cached_values (model, model->account_values_hash, parent);
|
||||||
parent = gnc_account_get_parent (parent);
|
parent = gnc_account_get_parent (parent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -663,19 +637,18 @@ static gboolean
|
|||||||
gnc_tree_model_account_get_cached_value (GncTreeModelAccount *model, Account *account,
|
gnc_tree_model_account_get_cached_value (GncTreeModelAccount *model, Account *account,
|
||||||
gint column, gchar **cached_string)
|
gint column, gchar **cached_string)
|
||||||
{
|
{
|
||||||
GncTreeModelAccountPrivate *priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
|
||||||
gchar acct_guid_str[GUID_ENCODING_LENGTH + 1];
|
gchar acct_guid_str[GUID_ENCODING_LENGTH + 1];
|
||||||
gchar *key = NULL;
|
gchar *key = NULL;
|
||||||
gpointer value;
|
gpointer value;
|
||||||
gboolean found;
|
gboolean found;
|
||||||
|
|
||||||
if ((!priv->account_values_hash) || (!account))
|
if ((!model->account_values_hash) || (!account))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
guid_to_string_buff (xaccAccountGetGUID (account), acct_guid_str);
|
guid_to_string_buff (xaccAccountGetGUID (account), acct_guid_str);
|
||||||
key = g_strdup_printf ("%s,%d", acct_guid_str, column);
|
key = g_strdup_printf ("%s,%d", acct_guid_str, column);
|
||||||
|
|
||||||
found = g_hash_table_lookup_extended (priv->account_values_hash, key,
|
found = g_hash_table_lookup_extended (model->account_values_hash, key,
|
||||||
NULL, &value);
|
NULL, &value);
|
||||||
|
|
||||||
if (found)
|
if (found)
|
||||||
@ -690,9 +663,7 @@ static void
|
|||||||
gnc_tree_model_account_set_cached_value (GncTreeModelAccount *model, Account *account,
|
gnc_tree_model_account_set_cached_value (GncTreeModelAccount *model, Account *account,
|
||||||
gint column, GValue *value)
|
gint column, GValue *value)
|
||||||
{
|
{
|
||||||
GncTreeModelAccountPrivate *priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
if ((!model->account_values_hash) || (!account))
|
||||||
|
|
||||||
if ((!priv->account_values_hash) || (!account))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// only interested in string values
|
// only interested in string values
|
||||||
@ -705,7 +676,7 @@ gnc_tree_model_account_set_cached_value (GncTreeModelAccount *model, Account *ac
|
|||||||
guid_to_string_buff (xaccAccountGetGUID (account), acct_guid_str);
|
guid_to_string_buff (xaccAccountGetGUID (account), acct_guid_str);
|
||||||
key = g_strdup_printf ("%s,%d", acct_guid_str, column);
|
key = g_strdup_printf ("%s,%d", acct_guid_str, column);
|
||||||
|
|
||||||
g_hash_table_insert (priv->account_values_hash, key, g_strdup (str));
|
g_hash_table_insert (model->account_values_hash, key, g_strdup (str));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -716,7 +687,6 @@ gnc_tree_model_account_get_value (GtkTreeModel *tree_model,
|
|||||||
GValue *value)
|
GValue *value)
|
||||||
{
|
{
|
||||||
GncTreeModelAccount *model = GNC_TREE_MODEL_ACCOUNT(tree_model);
|
GncTreeModelAccount *model = GNC_TREE_MODEL_ACCOUNT(tree_model);
|
||||||
GncTreeModelAccountPrivate *priv;
|
|
||||||
Account *account;
|
Account *account;
|
||||||
gboolean negative; /* used to set "deficit style" also known as red numbers */
|
gboolean negative; /* used to set "deficit style" also known as red numbers */
|
||||||
gchar *string;
|
gchar *string;
|
||||||
@ -733,7 +703,6 @@ gnc_tree_model_account_get_value (GtkTreeModel *tree_model,
|
|||||||
iter_to_string (iter), column);
|
iter_to_string (iter), column);
|
||||||
|
|
||||||
account = (Account *) iter->user_data;
|
account = (Account *) iter->user_data;
|
||||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
// lets see if the value is in the cache
|
// lets see if the value is in the cache
|
||||||
if (gnc_tree_model_account_get_cached_value (model, account, column, &cached_string))
|
if (gnc_tree_model_account_get_cached_value (model, account, column, &cached_string))
|
||||||
@ -748,7 +717,7 @@ gnc_tree_model_account_get_value (GtkTreeModel *tree_model,
|
|||||||
{
|
{
|
||||||
case GNC_TREE_MODEL_ACCOUNT_COL_NAME:
|
case GNC_TREE_MODEL_ACCOUNT_COL_NAME:
|
||||||
g_value_init (value, G_TYPE_STRING);
|
g_value_init (value, G_TYPE_STRING);
|
||||||
if (account == priv->root)
|
if (account == model->root)
|
||||||
g_value_set_string (value, _("New top level account"));
|
g_value_set_string (value, _("New top level account"));
|
||||||
else
|
else
|
||||||
g_value_set_string (value, xaccAccountGetName (account));
|
g_value_set_string (value, xaccAccountGetName (account));
|
||||||
@ -1029,7 +998,6 @@ gnc_tree_model_account_iter_children (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *iter,
|
GtkTreeIter *iter,
|
||||||
GtkTreeIter *parent_iter)
|
GtkTreeIter *parent_iter)
|
||||||
{
|
{
|
||||||
GncTreeModelAccountPrivate *priv;
|
|
||||||
GncTreeModelAccount *model;
|
GncTreeModelAccount *model;
|
||||||
Account *account, *parent;
|
Account *account, *parent;
|
||||||
|
|
||||||
@ -1038,9 +1006,8 @@ gnc_tree_model_account_iter_children (GtkTreeModel *tree_model,
|
|||||||
tree_model, iter, (parent_iter ? iter_to_string (parent_iter) : "(null)"));
|
tree_model, iter, (parent_iter ? iter_to_string (parent_iter) : "(null)"));
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_ACCOUNT(tree_model);
|
model = GNC_TREE_MODEL_ACCOUNT(tree_model);
|
||||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
if (priv->root == NULL)
|
if (model->root == NULL)
|
||||||
{
|
{
|
||||||
iter->stamp = 0;
|
iter->stamp = 0;
|
||||||
LEAVE("failed (no root)");
|
LEAVE("failed (no root)");
|
||||||
@ -1050,7 +1017,7 @@ gnc_tree_model_account_iter_children (GtkTreeModel *tree_model,
|
|||||||
/* Special case when no parent supplied. */
|
/* Special case when no parent supplied. */
|
||||||
if (!parent_iter)
|
if (!parent_iter)
|
||||||
{
|
{
|
||||||
iter->user_data = priv->root;
|
iter->user_data = model->root;
|
||||||
iter->user_data2 = NULL;
|
iter->user_data2 = NULL;
|
||||||
iter->user_data3 = GINT_TO_POINTER(0);
|
iter->user_data3 = GINT_TO_POINTER(0);
|
||||||
iter->stamp = model->stamp;
|
iter->stamp = model->stamp;
|
||||||
@ -1144,7 +1111,6 @@ gnc_tree_model_account_iter_nth_child (GtkTreeModel *tree_model,
|
|||||||
int n)
|
int n)
|
||||||
{
|
{
|
||||||
GncTreeModelAccount *model;
|
GncTreeModelAccount *model;
|
||||||
GncTreeModelAccountPrivate *priv;
|
|
||||||
Account *account, *parent;
|
Account *account, *parent;
|
||||||
|
|
||||||
if (parent_iter)
|
if (parent_iter)
|
||||||
@ -1164,7 +1130,6 @@ gnc_tree_model_account_iter_nth_child (GtkTreeModel *tree_model,
|
|||||||
gnc_leave_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(tree_model), FALSE);
|
gnc_leave_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(tree_model), FALSE);
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_ACCOUNT(tree_model);
|
model = GNC_TREE_MODEL_ACCOUNT(tree_model);
|
||||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
/* Special case when no parent supplied. */
|
/* Special case when no parent supplied. */
|
||||||
if (!parent_iter)
|
if (!parent_iter)
|
||||||
@ -1175,7 +1140,7 @@ gnc_tree_model_account_iter_nth_child (GtkTreeModel *tree_model,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
iter->user_data = priv->root;
|
iter->user_data = model->root;
|
||||||
iter->user_data2 = NULL;
|
iter->user_data2 = NULL;
|
||||||
iter->user_data3 = GINT_TO_POINTER(0);
|
iter->user_data3 = GINT_TO_POINTER(0);
|
||||||
iter->stamp = model->stamp;
|
iter->stamp = model->stamp;
|
||||||
@ -1294,7 +1259,6 @@ gnc_tree_model_account_get_iter_from_account (GncTreeModelAccount *model,
|
|||||||
Account *account,
|
Account *account,
|
||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GncTreeModelAccountPrivate *priv;
|
|
||||||
Account *parent;
|
Account *parent;
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
@ -1306,8 +1270,7 @@ gnc_tree_model_account_get_iter_from_account (GncTreeModelAccount *model,
|
|||||||
iter->user_data = account;
|
iter->user_data = account;
|
||||||
iter->stamp = model->stamp;
|
iter->stamp = model->stamp;
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
if (account == model->root)
|
||||||
if (account == priv->root)
|
|
||||||
{
|
{
|
||||||
iter->user_data2 = NULL;
|
iter->user_data2 = NULL;
|
||||||
iter->user_data3 = GINT_TO_POINTER(0);
|
iter->user_data3 = GINT_TO_POINTER(0);
|
||||||
@ -1315,7 +1278,7 @@ gnc_tree_model_account_get_iter_from_account (GncTreeModelAccount *model,
|
|||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priv->root != gnc_account_get_root (account))
|
if (model->root != gnc_account_get_root (account))
|
||||||
{
|
{
|
||||||
LEAVE("Root doesn't match");
|
LEAVE("Root doesn't match");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -1440,7 +1403,6 @@ gnc_tree_model_account_event_handler (QofInstance *entity,
|
|||||||
GncTreeModelAccount *model,
|
GncTreeModelAccount *model,
|
||||||
GncEventData *ed)
|
GncEventData *ed)
|
||||||
{
|
{
|
||||||
GncTreeModelAccountPrivate *priv;
|
|
||||||
const gchar *parent_name;
|
const gchar *parent_name;
|
||||||
GtkTreePath *path = NULL;
|
GtkTreePath *path = NULL;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
@ -1453,16 +1415,15 @@ gnc_tree_model_account_event_handler (QofInstance *entity,
|
|||||||
|
|
||||||
ENTER("entity %p of type %d, model %p, event_data %p",
|
ENTER("entity %p of type %d, model %p, event_data %p",
|
||||||
entity, event_type, model, ed);
|
entity, event_type, model, ed);
|
||||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
account = GNC_ACCOUNT(entity);
|
account = GNC_ACCOUNT(entity);
|
||||||
|
|
||||||
if (gnc_account_get_book (account) != priv->book)
|
if (gnc_account_get_book (account) != model->book)
|
||||||
{
|
{
|
||||||
LEAVE("not in this book");
|
LEAVE("not in this book");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (gnc_account_get_root (account) != priv->root)
|
if (gnc_account_get_root (account) != model->root)
|
||||||
{
|
{
|
||||||
LEAVE("not in this model");
|
LEAVE("not in this model");
|
||||||
return;
|
return;
|
||||||
@ -1497,7 +1458,7 @@ gnc_tree_model_account_event_handler (QofInstance *entity,
|
|||||||
case QOF_EVENT_REMOVE:
|
case QOF_EVENT_REMOVE:
|
||||||
if (!ed) /* Required for a remove. */
|
if (!ed) /* Required for a remove. */
|
||||||
break;
|
break;
|
||||||
parent = ed->node ? GNC_ACCOUNT(ed->node) : priv->root;
|
parent = ed->node ? GNC_ACCOUNT(ed->node) : model->root;
|
||||||
parent_name = ed->node ? xaccAccountGetName (parent) : "Root";
|
parent_name = ed->node ? xaccAccountGetName (parent) : "Root";
|
||||||
DEBUG("remove child %d of account %p (%s)", ed->idx, parent, parent_name);
|
DEBUG("remove child %d of account %p (%s)", ed->idx, parent, parent_name);
|
||||||
path = gnc_tree_model_account_get_path_from_account (model, parent);
|
path = gnc_tree_model_account_get_path_from_account (model, parent);
|
||||||
|
@ -45,14 +45,9 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
/* type macros */
|
/* type macros */
|
||||||
#define GNC_TYPE_TREE_MODEL_ACCOUNT (gnc_tree_model_account_get_type ())
|
#define GNC_TYPE_TREE_MODEL_ACCOUNT (gnc_tree_model_account_get_type ())
|
||||||
#define GNC_TREE_MODEL_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_TREE_MODEL_ACCOUNT, GncTreeModelAccount))
|
G_DECLARE_FINAL_TYPE (GncTreeModelAccount, gnc_tree_model_account, GNC, TREE_MODEL_ACCOUNT, GncTreeModel)
|
||||||
#define GNC_TREE_MODEL_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_TREE_MODEL_ACCOUNT, GncTreeModelAccountClass))
|
|
||||||
#define GNC_IS_TREE_MODEL_ACCOUNT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_TREE_MODEL_ACCOUNT))
|
|
||||||
#define GNC_IS_TREE_MODEL_ACCOUNT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_TREE_MODEL_ACCOUNT))
|
|
||||||
#define GNC_TREE_MODEL_ACCOUNT_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_TREE_MODEL_ACCOUNT, GncTreeModelAccountClass))
|
|
||||||
#define GNC_TREE_MODEL_ACCOUNT_NAME "GncTreeModelAccount"
|
#define GNC_TREE_MODEL_ACCOUNT_NAME "GncTreeModelAccount"
|
||||||
|
|
||||||
|
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
GNC_TREE_MODEL_ACCOUNT_COL_NAME,
|
GNC_TREE_MODEL_ACCOUNT_COL_NAME,
|
||||||
@ -101,31 +96,6 @@ typedef enum
|
|||||||
GNC_TREE_MODEL_ACCOUNT_NUM_COLUMNS
|
GNC_TREE_MODEL_ACCOUNT_NUM_COLUMNS
|
||||||
} GncTreeModelAccountColumn;
|
} GncTreeModelAccountColumn;
|
||||||
|
|
||||||
/* typedefs & structures */
|
|
||||||
|
|
||||||
/** The instance data structure for an account tree model. */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GncTreeModel gnc_tree_model; /**< The parent object data. */
|
|
||||||
int stamp; /**< The state of the model. Any state
|
|
||||||
* change increments this number. */
|
|
||||||
} GncTreeModelAccount;
|
|
||||||
|
|
||||||
|
|
||||||
/** The class data structure for an account tree model. */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GncTreeModelClass gnc_tree_model;/**< The parent object data. */
|
|
||||||
} GncTreeModelAccountClass;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Get the type of an account tree plugin.
|
|
||||||
*
|
|
||||||
* @return A GType.
|
|
||||||
*/
|
|
||||||
GType gnc_tree_model_account_get_type (void);
|
|
||||||
|
|
||||||
/** Clear the tree model account cached values.
|
/** Clear the tree model account cached values.
|
||||||
*
|
*
|
||||||
* @param model A pointer to the account tree model.
|
* @param model A pointer to the account tree model.
|
||||||
|
@ -91,19 +91,19 @@ static void gnc_tree_model_commodity_event_handler (QofInstance *entity,
|
|||||||
gpointer user_data,
|
gpointer user_data,
|
||||||
gpointer event_data);
|
gpointer event_data);
|
||||||
|
|
||||||
/** The instance private data for a commodity database tree model. */
|
/** The instance data structure for a commodity tree model. */
|
||||||
typedef struct GncTreeModelCommodityPrivate
|
struct _GncTreeModelCommodity
|
||||||
{
|
{
|
||||||
|
GncTreeModel gnc_tree_model; /**< The parent object data. */
|
||||||
|
int stamp; /**< The state of the model. Any state
|
||||||
|
* change increments this number. */
|
||||||
|
|
||||||
QofBook *book;
|
QofBook *book;
|
||||||
gnc_commodity_table *commodity_table;
|
gnc_commodity_table *commodity_table;
|
||||||
gint event_handler_id;
|
gint event_handler_id;
|
||||||
} GncTreeModelCommodityPrivate;
|
};
|
||||||
|
|
||||||
#define GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(o) \
|
|
||||||
((GncTreeModelCommodityPrivate*)gnc_tree_model_commodity_get_instance_private((GncTreeModelCommodity*)o))
|
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_CODE(GncTreeModelCommodity, gnc_tree_model_commodity, GNC_TYPE_TREE_MODEL,
|
G_DEFINE_TYPE_WITH_CODE(GncTreeModelCommodity, gnc_tree_model_commodity, GNC_TYPE_TREE_MODEL,
|
||||||
G_ADD_PRIVATE(GncTreeModelCommodity)
|
|
||||||
G_IMPLEMENT_INTERFACE(GTK_TYPE_TREE_MODEL,
|
G_IMPLEMENT_INTERFACE(GTK_TYPE_TREE_MODEL,
|
||||||
gnc_tree_model_commodity_tree_model_init))
|
gnc_tree_model_commodity_tree_model_init))
|
||||||
|
|
||||||
@ -129,7 +129,6 @@ static void
|
|||||||
gnc_tree_model_commodity_finalize (GObject *object)
|
gnc_tree_model_commodity_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
GncTreeModelCommodity *model;
|
GncTreeModelCommodity *model;
|
||||||
GncTreeModelCommodityPrivate *priv;
|
|
||||||
|
|
||||||
g_return_if_fail (object != NULL);
|
g_return_if_fail (object != NULL);
|
||||||
g_return_if_fail (GNC_IS_TREE_MODEL_COMMODITY (object));
|
g_return_if_fail (GNC_IS_TREE_MODEL_COMMODITY (object));
|
||||||
@ -137,9 +136,8 @@ gnc_tree_model_commodity_finalize (GObject *object)
|
|||||||
ENTER("model %p", object);
|
ENTER("model %p", object);
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_COMMODITY (object);
|
model = GNC_TREE_MODEL_COMMODITY (object);
|
||||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
model->book = NULL;
|
||||||
priv->book = NULL;
|
model->commodity_table = NULL;
|
||||||
priv->commodity_table = NULL;
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (gnc_tree_model_commodity_parent_class)->finalize (object);
|
G_OBJECT_CLASS (gnc_tree_model_commodity_parent_class)->finalize (object);
|
||||||
LEAVE(" ");
|
LEAVE(" ");
|
||||||
@ -149,19 +147,17 @@ static void
|
|||||||
gnc_tree_model_commodity_dispose (GObject *object)
|
gnc_tree_model_commodity_dispose (GObject *object)
|
||||||
{
|
{
|
||||||
GncTreeModelCommodity *model;
|
GncTreeModelCommodity *model;
|
||||||
GncTreeModelCommodityPrivate *priv;
|
|
||||||
|
|
||||||
g_return_if_fail (object != NULL);
|
g_return_if_fail (object != NULL);
|
||||||
g_return_if_fail (GNC_IS_TREE_MODEL_COMMODITY (object));
|
g_return_if_fail (GNC_IS_TREE_MODEL_COMMODITY (object));
|
||||||
|
|
||||||
ENTER("model %p", object);
|
ENTER("model %p", object);
|
||||||
model = GNC_TREE_MODEL_COMMODITY (object);
|
model = GNC_TREE_MODEL_COMMODITY (object);
|
||||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
if (priv->event_handler_id)
|
if (model->event_handler_id)
|
||||||
{
|
{
|
||||||
qof_event_unregister_handler (priv->event_handler_id);
|
qof_event_unregister_handler (model->event_handler_id);
|
||||||
priv->event_handler_id = 0;
|
model->event_handler_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
G_OBJECT_CLASS (gnc_tree_model_commodity_parent_class)->dispose (object);
|
G_OBJECT_CLASS (gnc_tree_model_commodity_parent_class)->dispose (object);
|
||||||
@ -172,7 +168,6 @@ GtkTreeModel *
|
|||||||
gnc_tree_model_commodity_new (QofBook *book, gnc_commodity_table *ct)
|
gnc_tree_model_commodity_new (QofBook *book, gnc_commodity_table *ct)
|
||||||
{
|
{
|
||||||
GncTreeModelCommodity *model;
|
GncTreeModelCommodity *model;
|
||||||
GncTreeModelCommodityPrivate *priv;
|
|
||||||
const GList *item;
|
const GList *item;
|
||||||
|
|
||||||
ENTER("");
|
ENTER("");
|
||||||
@ -181,8 +176,7 @@ gnc_tree_model_commodity_new (QofBook *book, gnc_commodity_table *ct)
|
|||||||
for ( ; item; item = g_list_next(item))
|
for ( ; item; item = g_list_next(item))
|
||||||
{
|
{
|
||||||
model = (GncTreeModelCommodity *)item->data;
|
model = (GncTreeModelCommodity *)item->data;
|
||||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
if (model->commodity_table == ct)
|
||||||
if (priv->commodity_table == ct)
|
|
||||||
{
|
{
|
||||||
g_object_ref(G_OBJECT(model));
|
g_object_ref(G_OBJECT(model));
|
||||||
LEAVE("returning existing model %p", model);
|
LEAVE("returning existing model %p", model);
|
||||||
@ -191,11 +185,10 @@ gnc_tree_model_commodity_new (QofBook *book, gnc_commodity_table *ct)
|
|||||||
}
|
}
|
||||||
|
|
||||||
model = g_object_new (GNC_TYPE_TREE_MODEL_COMMODITY, NULL);
|
model = g_object_new (GNC_TYPE_TREE_MODEL_COMMODITY, NULL);
|
||||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
model->book = book;
|
||||||
priv->book = book;
|
model->commodity_table = ct;
|
||||||
priv->commodity_table = ct;
|
|
||||||
|
|
||||||
priv->event_handler_id =
|
model->event_handler_id =
|
||||||
qof_event_register_handler (gnc_tree_model_commodity_event_handler, model);
|
qof_event_register_handler (gnc_tree_model_commodity_event_handler, model);
|
||||||
|
|
||||||
LEAVE("");
|
LEAVE("");
|
||||||
@ -389,7 +382,6 @@ gnc_tree_model_commodity_get_iter (GtkTreeModel *tree_model,
|
|||||||
GtkTreePath *path)
|
GtkTreePath *path)
|
||||||
{
|
{
|
||||||
GncTreeModelCommodity *model;
|
GncTreeModelCommodity *model;
|
||||||
GncTreeModelCommodityPrivate *priv;
|
|
||||||
gnc_commodity_table *ct;
|
gnc_commodity_table *ct;
|
||||||
gnc_commodity_namespace *name_space;
|
gnc_commodity_namespace *name_space;
|
||||||
gnc_commodity *commodity = NULL;
|
gnc_commodity *commodity = NULL;
|
||||||
@ -419,8 +411,7 @@ gnc_tree_model_commodity_get_iter (GtkTreeModel *tree_model,
|
|||||||
|
|
||||||
/* Make sure the model has a commodity db. */
|
/* Make sure the model has a commodity db. */
|
||||||
model = GNC_TREE_MODEL_COMMODITY (tree_model);
|
model = GNC_TREE_MODEL_COMMODITY (tree_model);
|
||||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
ct = model->commodity_table;
|
||||||
ct = priv->commodity_table;
|
|
||||||
if (ct == NULL)
|
if (ct == NULL)
|
||||||
{
|
{
|
||||||
LEAVE("no commodity table");
|
LEAVE("no commodity table");
|
||||||
@ -472,7 +463,6 @@ gnc_tree_model_commodity_get_path (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GncTreeModelCommodity *model;
|
GncTreeModelCommodity *model;
|
||||||
GncTreeModelCommodityPrivate *priv;
|
|
||||||
GtkTreePath *path;
|
GtkTreePath *path;
|
||||||
gnc_commodity_table *ct;
|
gnc_commodity_table *ct;
|
||||||
gnc_commodity_namespace *name_space;
|
gnc_commodity_namespace *name_space;
|
||||||
@ -487,8 +477,7 @@ gnc_tree_model_commodity_get_path (GtkTreeModel *tree_model,
|
|||||||
ENTER("model %p, iter %p (%s)", tree_model, iter, iter_to_string(iter));
|
ENTER("model %p, iter %p (%s)", tree_model, iter, iter_to_string(iter));
|
||||||
|
|
||||||
/* Make sure this model has a commodity db. */
|
/* Make sure this model has a commodity db. */
|
||||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
ct = model->commodity_table;
|
||||||
ct = priv->commodity_table;
|
|
||||||
if (ct == NULL)
|
if (ct == NULL)
|
||||||
{
|
{
|
||||||
LEAVE("no commodity table");
|
LEAVE("no commodity table");
|
||||||
@ -651,7 +640,6 @@ gnc_tree_model_commodity_iter_next (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GncTreeModelCommodity *model;
|
GncTreeModelCommodity *model;
|
||||||
GncTreeModelCommodityPrivate *priv;
|
|
||||||
gnc_commodity_table *ct;
|
gnc_commodity_table *ct;
|
||||||
gnc_commodity_namespace *name_space;
|
gnc_commodity_namespace *name_space;
|
||||||
GList *list;
|
GList *list;
|
||||||
@ -665,10 +653,9 @@ gnc_tree_model_commodity_iter_next (GtkTreeModel *tree_model,
|
|||||||
g_return_val_if_fail (iter->stamp == model->stamp, FALSE);
|
g_return_val_if_fail (iter->stamp == model->stamp, FALSE);
|
||||||
|
|
||||||
ENTER("model %p, iter %p(%s)", tree_model, iter, iter_to_string(iter));
|
ENTER("model %p, iter %p(%s)", tree_model, iter, iter_to_string(iter));
|
||||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
|
||||||
if (iter->user_data == ITER_IS_NAMESPACE)
|
if (iter->user_data == ITER_IS_NAMESPACE)
|
||||||
{
|
{
|
||||||
ct = priv->commodity_table;
|
ct = model->commodity_table;
|
||||||
list = gnc_commodity_table_get_namespaces_list(ct);
|
list = gnc_commodity_table_get_namespaces_list(ct);
|
||||||
}
|
}
|
||||||
else if (iter->user_data == ITER_IS_COMMODITY)
|
else if (iter->user_data == ITER_IS_COMMODITY)
|
||||||
@ -701,7 +688,6 @@ gnc_tree_model_commodity_iter_children (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *parent)
|
GtkTreeIter *parent)
|
||||||
{
|
{
|
||||||
GncTreeModelCommodity *model;
|
GncTreeModelCommodity *model;
|
||||||
GncTreeModelCommodityPrivate *priv;
|
|
||||||
gnc_commodity_table *ct;
|
gnc_commodity_table *ct;
|
||||||
gnc_commodity_namespace *name_space;
|
gnc_commodity_namespace *name_space;
|
||||||
GList *list;
|
GList *list;
|
||||||
@ -711,11 +697,10 @@ gnc_tree_model_commodity_iter_children (GtkTreeModel *tree_model,
|
|||||||
ENTER("model %p, iter %p, parent %p (%s)",
|
ENTER("model %p, iter %p, parent %p (%s)",
|
||||||
tree_model, iter, parent, iter_to_string(parent));
|
tree_model, iter, parent, iter_to_string(parent));
|
||||||
model = GNC_TREE_MODEL_COMMODITY (tree_model);
|
model = GNC_TREE_MODEL_COMMODITY (tree_model);
|
||||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
if (parent == NULL)
|
if (parent == NULL)
|
||||||
{
|
{
|
||||||
ct = priv->commodity_table;
|
ct = model->commodity_table;
|
||||||
list = gnc_commodity_table_get_namespaces_list(ct);
|
list = gnc_commodity_table_get_namespaces_list(ct);
|
||||||
if (list == NULL)
|
if (list == NULL)
|
||||||
{
|
{
|
||||||
@ -781,7 +766,6 @@ gnc_tree_model_commodity_iter_n_children (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GncTreeModelCommodity *model;
|
GncTreeModelCommodity *model;
|
||||||
GncTreeModelCommodityPrivate *priv;
|
|
||||||
gnc_commodity_table *ct;
|
gnc_commodity_table *ct;
|
||||||
gnc_commodity_namespace *name_space;
|
gnc_commodity_namespace *name_space;
|
||||||
GList *list;
|
GList *list;
|
||||||
@ -790,11 +774,10 @@ gnc_tree_model_commodity_iter_n_children (GtkTreeModel *tree_model,
|
|||||||
|
|
||||||
ENTER("model %p, iter %p (%s)", tree_model, iter, iter_to_string(iter));
|
ENTER("model %p, iter %p (%s)", tree_model, iter, iter_to_string(iter));
|
||||||
model = GNC_TREE_MODEL_COMMODITY (tree_model);
|
model = GNC_TREE_MODEL_COMMODITY (tree_model);
|
||||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
if (iter == NULL)
|
if (iter == NULL)
|
||||||
{
|
{
|
||||||
ct = priv->commodity_table;
|
ct = model->commodity_table;
|
||||||
list = gnc_commodity_table_get_namespaces_list(ct);
|
list = gnc_commodity_table_get_namespaces_list(ct);
|
||||||
LEAVE("ns list length %d", g_list_length(list));
|
LEAVE("ns list length %d", g_list_length(list));
|
||||||
return g_list_length (list);
|
return g_list_length (list);
|
||||||
@ -819,7 +802,6 @@ gnc_tree_model_commodity_iter_nth_child (GtkTreeModel *tree_model,
|
|||||||
int n)
|
int n)
|
||||||
{
|
{
|
||||||
GncTreeModelCommodity *model;
|
GncTreeModelCommodity *model;
|
||||||
GncTreeModelCommodityPrivate *priv;
|
|
||||||
gnc_commodity_table *ct;
|
gnc_commodity_table *ct;
|
||||||
gnc_commodity_namespace *name_space;
|
gnc_commodity_namespace *name_space;
|
||||||
GList *list;
|
GList *list;
|
||||||
@ -830,11 +812,10 @@ gnc_tree_model_commodity_iter_nth_child (GtkTreeModel *tree_model,
|
|||||||
ENTER("model %p, iter %p, parent %p (%s)",
|
ENTER("model %p, iter %p, parent %p (%s)",
|
||||||
tree_model, iter, parent, iter_to_string(parent));
|
tree_model, iter, parent, iter_to_string(parent));
|
||||||
model = GNC_TREE_MODEL_COMMODITY (tree_model);
|
model = GNC_TREE_MODEL_COMMODITY (tree_model);
|
||||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
if (parent == NULL)
|
if (parent == NULL)
|
||||||
{
|
{
|
||||||
ct = priv->commodity_table;
|
ct = model->commodity_table;
|
||||||
list = gnc_commodity_table_get_namespaces_list(ct);
|
list = gnc_commodity_table_get_namespaces_list(ct);
|
||||||
|
|
||||||
iter->stamp = model->stamp;
|
iter->stamp = model->stamp;
|
||||||
@ -869,7 +850,6 @@ gnc_tree_model_commodity_iter_parent (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *child)
|
GtkTreeIter *child)
|
||||||
{
|
{
|
||||||
GncTreeModelCommodity *model;
|
GncTreeModelCommodity *model;
|
||||||
GncTreeModelCommodityPrivate *priv;
|
|
||||||
gnc_commodity_table *ct;
|
gnc_commodity_table *ct;
|
||||||
gnc_commodity_namespace *name_space;
|
gnc_commodity_namespace *name_space;
|
||||||
GList *list;
|
GList *list;
|
||||||
@ -881,7 +861,6 @@ gnc_tree_model_commodity_iter_parent (GtkTreeModel *tree_model,
|
|||||||
ENTER("model %p, iter %p, child %p (%s)",
|
ENTER("model %p, iter %p, child %p (%s)",
|
||||||
tree_model, iter, child, iter_to_string(child));
|
tree_model, iter, child, iter_to_string(child));
|
||||||
model = GNC_TREE_MODEL_COMMODITY (tree_model);
|
model = GNC_TREE_MODEL_COMMODITY (tree_model);
|
||||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
if (child->user_data == ITER_IS_NAMESPACE)
|
if (child->user_data == ITER_IS_NAMESPACE)
|
||||||
{
|
{
|
||||||
@ -889,7 +868,7 @@ gnc_tree_model_commodity_iter_parent (GtkTreeModel *tree_model,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
ct = priv->commodity_table;
|
ct = model->commodity_table;
|
||||||
list = gnc_commodity_table_get_namespaces_list(ct);
|
list = gnc_commodity_table_get_namespaces_list(ct);
|
||||||
name_space = gnc_commodity_get_namespace_ds((gnc_commodity*)child->user_data2);
|
name_space = gnc_commodity_get_namespace_ds((gnc_commodity*)child->user_data2);
|
||||||
|
|
||||||
@ -1000,7 +979,6 @@ gnc_tree_model_commodity_get_iter_from_namespace (GncTreeModelCommodity *model,
|
|||||||
gnc_commodity_namespace *name_space,
|
gnc_commodity_namespace *name_space,
|
||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GncTreeModelCommodityPrivate *priv;
|
|
||||||
GList *list;
|
GList *list;
|
||||||
gint n;
|
gint n;
|
||||||
|
|
||||||
@ -1010,8 +988,7 @@ gnc_tree_model_commodity_get_iter_from_namespace (GncTreeModelCommodity *model,
|
|||||||
|
|
||||||
ENTER("model %p, namespace %p, iter %p", model, name_space, iter);
|
ENTER("model %p, namespace %p, iter %p", model, name_space, iter);
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
list = gnc_commodity_table_get_namespaces_list(model->commodity_table);
|
||||||
list = gnc_commodity_table_get_namespaces_list(priv->commodity_table);
|
|
||||||
if (list == NULL)
|
if (list == NULL)
|
||||||
{
|
{
|
||||||
LEAVE("");
|
LEAVE("");
|
||||||
|
@ -45,11 +45,8 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
/* type macros */
|
/* type macros */
|
||||||
#define GNC_TYPE_TREE_MODEL_COMMODITY (gnc_tree_model_commodity_get_type ())
|
#define GNC_TYPE_TREE_MODEL_COMMODITY (gnc_tree_model_commodity_get_type ())
|
||||||
#define GNC_TREE_MODEL_COMMODITY(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_TREE_MODEL_COMMODITY, GncTreeModelCommodity))
|
G_DECLARE_FINAL_TYPE (GncTreeModelCommodity, gnc_tree_model_commodity, GNC, TREE_MODEL_COMMODITY, GncTreeModel)
|
||||||
#define GNC_TREE_MODEL_COMMODITY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_TREE_MODEL_COMMODITY, GncTreeModelCommodityClass))
|
|
||||||
#define GNC_IS_TREE_MODEL_COMMODITY(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_TREE_MODEL_COMMODITY))
|
|
||||||
#define GNC_IS_TREE_MODEL_COMMODITY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_TREE_MODEL_COMMODITY))
|
|
||||||
#define GNC_TREE_MODEL_COMMODITY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_TREE_MODEL_COMMODITY, GncTreeModelCommodityClass))
|
|
||||||
#define GNC_TREE_MODEL_COMMODITY_NAME "GncTreeModelCommodity"
|
#define GNC_TREE_MODEL_COMMODITY_NAME "GncTreeModelCommodity"
|
||||||
|
|
||||||
|
|
||||||
@ -75,31 +72,6 @@ typedef enum
|
|||||||
GNC_TREE_MODEL_COMMODITY_NUM_COLUMNS
|
GNC_TREE_MODEL_COMMODITY_NUM_COLUMNS
|
||||||
} GncTreeModelCommodityColumn;
|
} GncTreeModelCommodityColumn;
|
||||||
|
|
||||||
/* typedefs & structures */
|
|
||||||
|
|
||||||
/** The instance data structure for a commodity tree model. */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GncTreeModel gnc_tree_model; /**< The parent object data. */
|
|
||||||
int stamp; /**< The state of the model. Any state
|
|
||||||
* change increments this number. */
|
|
||||||
} GncTreeModelCommodity;
|
|
||||||
|
|
||||||
|
|
||||||
/** The class data structure for a commodity tree model. */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GncTreeModelClass gnc_tree_model;/**< The parent object data. */
|
|
||||||
} GncTreeModelCommodityClass;
|
|
||||||
|
|
||||||
|
|
||||||
/** Get the type of a commodity tree plugin.
|
|
||||||
*
|
|
||||||
* @return A GType.
|
|
||||||
*/
|
|
||||||
GType gnc_tree_model_commodity_get_type (void);
|
|
||||||
|
|
||||||
|
|
||||||
/** @name Account Tree Model Constructors
|
/** @name Account Tree Model Constructors
|
||||||
@{ */
|
@{ */
|
||||||
|
|
||||||
|
@ -86,26 +86,25 @@ static void gnc_tree_model_owner_event_handler (QofInstance *entity,
|
|||||||
GncTreeModelOwner *model,
|
GncTreeModelOwner *model,
|
||||||
GncEventData *ed);
|
GncEventData *ed);
|
||||||
|
|
||||||
/** The instance private data for an owner tree model. */
|
/** The instance data structure for an owner tree model. */
|
||||||
typedef struct GncTreeModelOwnerPrivate
|
struct _GncTreeModelOwner
|
||||||
{
|
{
|
||||||
|
GncTreeModel gnc_tree_model; /**< The parent object data. */
|
||||||
|
int stamp; /**< The state of the model. Any state
|
||||||
|
* change increments this number. */
|
||||||
|
|
||||||
QofBook *book;
|
QofBook *book;
|
||||||
GncOwnerType owner_type;
|
GncOwnerType owner_type;
|
||||||
OwnerList *owner_list;
|
OwnerList *owner_list;
|
||||||
gint event_handler_id;
|
gint event_handler_id;
|
||||||
const gchar *negative_color;
|
const gchar *negative_color;
|
||||||
} GncTreeModelOwnerPrivate;
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_CODE(GncTreeModelOwner, gnc_tree_model_owner,
|
G_DEFINE_TYPE_WITH_CODE(GncTreeModelOwner, gnc_tree_model_owner,
|
||||||
GNC_TYPE_TREE_MODEL,
|
GNC_TYPE_TREE_MODEL,
|
||||||
G_ADD_PRIVATE(GncTreeModelOwner)
|
|
||||||
G_IMPLEMENT_INTERFACE(GTK_TYPE_TREE_MODEL,
|
G_IMPLEMENT_INTERFACE(GTK_TYPE_TREE_MODEL,
|
||||||
gnc_tree_model_owner_tree_model_init))
|
gnc_tree_model_owner_tree_model_init))
|
||||||
|
|
||||||
#define GNC_TREE_MODEL_OWNER_GET_PRIVATE(o) \
|
|
||||||
((GncTreeModelOwnerPrivate*)gnc_tree_model_owner_get_instance_private((GncTreeModelOwner*)o))
|
|
||||||
|
|
||||||
|
|
||||||
/************************************************************/
|
/************************************************************/
|
||||||
/* Owner Tree Model - Misc Functions */
|
/* Owner Tree Model - Misc Functions */
|
||||||
/************************************************************/
|
/************************************************************/
|
||||||
@ -119,15 +118,13 @@ G_DEFINE_TYPE_WITH_CODE(GncTreeModelOwner, gnc_tree_model_owner,
|
|||||||
static void
|
static void
|
||||||
gnc_tree_model_owner_update_color (gpointer gsettings, gchar *key, gpointer user_data)
|
gnc_tree_model_owner_update_color (gpointer gsettings, gchar *key, gpointer user_data)
|
||||||
{
|
{
|
||||||
GncTreeModelOwnerPrivate *priv;
|
|
||||||
GncTreeModelOwner *model;
|
GncTreeModelOwner *model;
|
||||||
gboolean use_red;
|
gboolean use_red;
|
||||||
|
|
||||||
g_return_if_fail(GNC_IS_TREE_MODEL_OWNER(user_data));
|
g_return_if_fail(GNC_IS_TREE_MODEL_OWNER(user_data));
|
||||||
model = user_data;
|
model = user_data;
|
||||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
|
||||||
use_red = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED);
|
use_red = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED);
|
||||||
priv->negative_color = use_red ? "red" : NULL;
|
model->negative_color = use_red ? "red" : NULL;
|
||||||
}
|
}
|
||||||
/************************************************************/
|
/************************************************************/
|
||||||
/* g_object required functions */
|
/* g_object required functions */
|
||||||
@ -148,7 +145,6 @@ gnc_tree_model_owner_class_init (GncTreeModelOwnerClass *klass)
|
|||||||
static void
|
static void
|
||||||
gnc_tree_model_owner_init (GncTreeModelOwner *model)
|
gnc_tree_model_owner_init (GncTreeModelOwner *model)
|
||||||
{
|
{
|
||||||
GncTreeModelOwnerPrivate *priv;
|
|
||||||
gboolean red;
|
gboolean red;
|
||||||
|
|
||||||
ENTER("model %p", model);
|
ENTER("model %p", model);
|
||||||
@ -159,11 +155,10 @@ gnc_tree_model_owner_init (GncTreeModelOwner *model)
|
|||||||
|
|
||||||
red = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED);
|
red = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED);
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
model->book = NULL;
|
||||||
priv->book = NULL;
|
model->owner_list = NULL;
|
||||||
priv->owner_list = NULL;
|
model->owner_type = GNC_OWNER_NONE;
|
||||||
priv->owner_type = GNC_OWNER_NONE;
|
model->negative_color = red ? "red" : NULL;
|
||||||
priv->negative_color = red ? "red" : NULL;
|
|
||||||
|
|
||||||
gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED,
|
gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED,
|
||||||
gnc_tree_model_owner_update_color,
|
gnc_tree_model_owner_update_color,
|
||||||
@ -175,7 +170,6 @@ gnc_tree_model_owner_init (GncTreeModelOwner *model)
|
|||||||
static void
|
static void
|
||||||
gnc_tree_model_owner_finalize (GObject *object)
|
gnc_tree_model_owner_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
GncTreeModelOwnerPrivate *priv;
|
|
||||||
GncTreeModelOwner *model;
|
GncTreeModelOwner *model;
|
||||||
|
|
||||||
g_return_if_fail (object != NULL);
|
g_return_if_fail (object != NULL);
|
||||||
@ -184,13 +178,12 @@ gnc_tree_model_owner_finalize (GObject *object)
|
|||||||
ENTER("model %p", object);
|
ENTER("model %p", object);
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_OWNER (object);
|
model = GNC_TREE_MODEL_OWNER (object);
|
||||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
if (priv->owner_list)
|
if (model->owner_list)
|
||||||
g_list_free_full (priv->owner_list, (GDestroyNotify) gncOwnerFree);
|
g_list_free_full (model->owner_list, (GDestroyNotify) gncOwnerFree);
|
||||||
|
|
||||||
priv->book = NULL;
|
model->book = NULL;
|
||||||
priv->owner_list = NULL;
|
model->owner_list = NULL;
|
||||||
|
|
||||||
G_OBJECT_CLASS(gnc_tree_model_owner_parent_class)->finalize (object);
|
G_OBJECT_CLASS(gnc_tree_model_owner_parent_class)->finalize (object);
|
||||||
LEAVE(" ");
|
LEAVE(" ");
|
||||||
@ -199,7 +192,6 @@ gnc_tree_model_owner_finalize (GObject *object)
|
|||||||
static void
|
static void
|
||||||
gnc_tree_model_owner_dispose (GObject *object)
|
gnc_tree_model_owner_dispose (GObject *object)
|
||||||
{
|
{
|
||||||
GncTreeModelOwnerPrivate *priv;
|
|
||||||
GncTreeModelOwner *model;
|
GncTreeModelOwner *model;
|
||||||
|
|
||||||
g_return_if_fail (object != NULL);
|
g_return_if_fail (object != NULL);
|
||||||
@ -208,12 +200,11 @@ gnc_tree_model_owner_dispose (GObject *object)
|
|||||||
ENTER("model %p", object);
|
ENTER("model %p", object);
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_OWNER (object);
|
model = GNC_TREE_MODEL_OWNER (object);
|
||||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
if (priv->event_handler_id)
|
if (model->event_handler_id)
|
||||||
{
|
{
|
||||||
qof_event_unregister_handler (priv->event_handler_id);
|
qof_event_unregister_handler (model->event_handler_id);
|
||||||
priv->event_handler_id = 0;
|
model->event_handler_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
gnc_prefs_remove_cb_by_func(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED,
|
gnc_prefs_remove_cb_by_func(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED,
|
||||||
@ -233,7 +224,6 @@ GtkTreeModel *
|
|||||||
gnc_tree_model_owner_new (GncOwnerType owner_type)
|
gnc_tree_model_owner_new (GncOwnerType owner_type)
|
||||||
{
|
{
|
||||||
GncTreeModelOwner *model;
|
GncTreeModelOwner *model;
|
||||||
GncTreeModelOwnerPrivate *priv;
|
|
||||||
const GList *item;
|
const GList *item;
|
||||||
|
|
||||||
ENTER("owner_type %d", owner_type);
|
ENTER("owner_type %d", owner_type);
|
||||||
@ -241,8 +231,7 @@ gnc_tree_model_owner_new (GncOwnerType owner_type)
|
|||||||
for ( ; item; item = g_list_next(item))
|
for ( ; item; item = g_list_next(item))
|
||||||
{
|
{
|
||||||
model = (GncTreeModelOwner *)item->data;
|
model = (GncTreeModelOwner *)item->data;
|
||||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
if (model->owner_type == owner_type)
|
||||||
if (priv->owner_type == owner_type)
|
|
||||||
{
|
{
|
||||||
g_object_ref(G_OBJECT(model));
|
g_object_ref(G_OBJECT(model));
|
||||||
LEAVE("returning existing model %p", model);
|
LEAVE("returning existing model %p", model);
|
||||||
@ -253,12 +242,11 @@ gnc_tree_model_owner_new (GncOwnerType owner_type)
|
|||||||
model = g_object_new (GNC_TYPE_TREE_MODEL_OWNER,
|
model = g_object_new (GNC_TYPE_TREE_MODEL_OWNER,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
model->book = gnc_get_current_book();
|
||||||
priv->book = gnc_get_current_book();
|
model->owner_type = owner_type;
|
||||||
priv->owner_type = owner_type;
|
model->owner_list = gncBusinessGetOwnerList (model->book, gncOwnerTypeToQofIdType(owner_type), TRUE);
|
||||||
priv->owner_list = gncBusinessGetOwnerList (priv->book, gncOwnerTypeToQofIdType(owner_type), TRUE);
|
|
||||||
|
|
||||||
priv->event_handler_id = qof_event_register_handler
|
model->event_handler_id = qof_event_register_handler
|
||||||
((QofEventHandler)gnc_tree_model_owner_event_handler, model);
|
((QofEventHandler)gnc_tree_model_owner_event_handler, model);
|
||||||
|
|
||||||
LEAVE("model %p", model);
|
LEAVE("model %p", model);
|
||||||
@ -378,7 +366,6 @@ gnc_tree_model_owner_get_iter (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *iter,
|
GtkTreeIter *iter,
|
||||||
GtkTreePath *path)
|
GtkTreePath *path)
|
||||||
{
|
{
|
||||||
GncTreeModelOwnerPrivate *priv;
|
|
||||||
GncTreeModelOwner *model;
|
GncTreeModelOwner *model;
|
||||||
GncOwner *owner;
|
GncOwner *owner;
|
||||||
gint *indices;
|
gint *indices;
|
||||||
@ -392,7 +379,6 @@ gnc_tree_model_owner_get_iter (GtkTreeModel *tree_model,
|
|||||||
}
|
}
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_OWNER (tree_model);
|
model = GNC_TREE_MODEL_OWNER (tree_model);
|
||||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
/* We keep a simple list of owners, not a tree, so only depth 1 is valid */
|
/* We keep a simple list of owners, not a tree, so only depth 1 is valid */
|
||||||
if (gtk_tree_path_get_depth (path) != 1)
|
if (gtk_tree_path_get_depth (path) != 1)
|
||||||
@ -403,7 +389,7 @@ gnc_tree_model_owner_get_iter (GtkTreeModel *tree_model,
|
|||||||
|
|
||||||
indices = gtk_tree_path_get_indices (path);
|
indices = gtk_tree_path_get_indices (path);
|
||||||
|
|
||||||
owner = g_list_nth_data (priv->owner_list, indices[0]);
|
owner = g_list_nth_data (model->owner_list, indices[0]);
|
||||||
if (owner == NULL)
|
if (owner == NULL)
|
||||||
{
|
{
|
||||||
iter->stamp = 0;
|
iter->stamp = 0;
|
||||||
@ -425,7 +411,6 @@ gnc_tree_model_owner_get_path (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GncTreeModelOwner *model = GNC_TREE_MODEL_OWNER (tree_model);
|
GncTreeModelOwner *model = GNC_TREE_MODEL_OWNER (tree_model);
|
||||||
GncTreeModelOwnerPrivate *priv;
|
|
||||||
GncOwner *owner;
|
GncOwner *owner;
|
||||||
GtkTreePath *path;
|
GtkTreePath *path;
|
||||||
gint i;
|
gint i;
|
||||||
@ -437,8 +422,7 @@ gnc_tree_model_owner_get_path (GtkTreeModel *tree_model,
|
|||||||
|
|
||||||
ENTER("model %p, iter %s", model, iter_to_string(iter));
|
ENTER("model %p, iter %s", model, iter_to_string(iter));
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
if (model->owner_list == NULL)
|
||||||
if (priv->owner_list == NULL)
|
|
||||||
{
|
{
|
||||||
LEAVE("failed (1)");
|
LEAVE("failed (1)");
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -447,7 +431,7 @@ gnc_tree_model_owner_get_path (GtkTreeModel *tree_model,
|
|||||||
owner = (GncOwner *) iter->user_data;
|
owner = (GncOwner *) iter->user_data;
|
||||||
|
|
||||||
path = gtk_tree_path_new ();
|
path = gtk_tree_path_new ();
|
||||||
i = g_list_index (priv->owner_list, owner);
|
i = g_list_index (model->owner_list, owner);
|
||||||
if (i == -1)
|
if (i == -1)
|
||||||
{
|
{
|
||||||
gtk_tree_path_free (path);
|
gtk_tree_path_free (path);
|
||||||
@ -469,11 +453,8 @@ gnc_tree_model_owner_set_color(GncTreeModelOwner *model,
|
|||||||
gboolean negative,
|
gboolean negative,
|
||||||
GValue *value)
|
GValue *value)
|
||||||
{
|
{
|
||||||
GncTreeModelOwnerPrivate *priv;
|
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
|
||||||
if (negative)
|
if (negative)
|
||||||
g_value_set_static_string (value, priv->negative_color);
|
g_value_set_static_string (value, model->negative_color);
|
||||||
else
|
else
|
||||||
g_value_set_static_string (value, NULL);
|
g_value_set_static_string (value, NULL);
|
||||||
}
|
}
|
||||||
@ -638,7 +619,6 @@ gnc_tree_model_owner_iter_next (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GncTreeModelOwner *model = GNC_TREE_MODEL_OWNER (tree_model);
|
GncTreeModelOwner *model = GNC_TREE_MODEL_OWNER (tree_model);
|
||||||
GncTreeModelOwnerPrivate *priv;
|
|
||||||
GncOwner *owner;
|
GncOwner *owner;
|
||||||
gint i;
|
gint i;
|
||||||
|
|
||||||
@ -649,11 +629,9 @@ gnc_tree_model_owner_iter_next (GtkTreeModel *tree_model,
|
|||||||
|
|
||||||
ENTER("model %p, iter %s", tree_model, iter_to_string (iter));
|
ENTER("model %p, iter %s", tree_model, iter_to_string (iter));
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
/* Get the *next* sibling owner. */
|
/* Get the *next* sibling owner. */
|
||||||
i = GPOINTER_TO_INT (iter->user_data2);
|
i = GPOINTER_TO_INT (iter->user_data2);
|
||||||
owner = g_list_nth_data (priv->owner_list, i + 1);
|
owner = g_list_nth_data (model->owner_list, i + 1);
|
||||||
if (owner == NULL)
|
if (owner == NULL)
|
||||||
{
|
{
|
||||||
iter->stamp = 0;
|
iter->stamp = 0;
|
||||||
@ -674,7 +652,6 @@ gnc_tree_model_owner_iter_children (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *iter,
|
GtkTreeIter *iter,
|
||||||
GtkTreeIter *parent_iter)
|
GtkTreeIter *parent_iter)
|
||||||
{
|
{
|
||||||
GncTreeModelOwnerPrivate *priv;
|
|
||||||
GncTreeModelOwner *model;
|
GncTreeModelOwner *model;
|
||||||
|
|
||||||
g_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (tree_model), FALSE);
|
g_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (tree_model), FALSE);
|
||||||
@ -682,14 +659,13 @@ gnc_tree_model_owner_iter_children (GtkTreeModel *tree_model,
|
|||||||
tree_model, iter, (parent_iter ? iter_to_string(parent_iter) : "(null)"));
|
tree_model, iter, (parent_iter ? iter_to_string(parent_iter) : "(null)"));
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_OWNER (tree_model);
|
model = GNC_TREE_MODEL_OWNER (tree_model);
|
||||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
/* Owner lists don't have children, so this function call only
|
/* Owner lists don't have children, so this function call only
|
||||||
* makes sense if no parent_iter was supplied. In that case,
|
* makes sense if no parent_iter was supplied. In that case,
|
||||||
* return the first owner in the list */
|
* return the first owner in the list */
|
||||||
if (!parent_iter)
|
if (!parent_iter)
|
||||||
{
|
{
|
||||||
iter->user_data = g_list_nth_data (priv->owner_list, 0);
|
iter->user_data = g_list_nth_data (model->owner_list, 0);
|
||||||
iter->user_data2 = GINT_TO_POINTER (0);
|
iter->user_data2 = GINT_TO_POINTER (0);
|
||||||
iter->user_data3 = NULL;
|
iter->user_data3 = NULL;
|
||||||
iter->stamp = model->stamp;
|
iter->stamp = model->stamp;
|
||||||
@ -717,19 +693,17 @@ gnc_tree_model_owner_iter_n_children (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GncTreeModelOwner *model;
|
GncTreeModelOwner *model;
|
||||||
GncTreeModelOwnerPrivate *priv;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (tree_model), -1);
|
g_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (tree_model), -1);
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_OWNER (tree_model);
|
model = GNC_TREE_MODEL_OWNER (tree_model);
|
||||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE (model);
|
|
||||||
|
|
||||||
/* Owner lists don't have children, so always return 0, except for
|
/* Owner lists don't have children, so always return 0, except for
|
||||||
* the special case this request comes for the special "root" iter
|
* the special case this request comes for the special "root" iter
|
||||||
* (NULL). For that exception we return the size of the owner list.
|
* (NULL). For that exception we return the size of the owner list.
|
||||||
*/
|
*/
|
||||||
if (iter == NULL)
|
if (iter == NULL)
|
||||||
return (gint) g_list_length (priv->owner_list);
|
return (gint) g_list_length (model->owner_list);
|
||||||
|
|
||||||
g_return_val_if_fail (
|
g_return_val_if_fail (
|
||||||
GNC_TREE_MODEL_OWNER (tree_model)->stamp == iter->stamp, -1);
|
GNC_TREE_MODEL_OWNER (tree_model)->stamp == iter->stamp, -1);
|
||||||
@ -744,7 +718,6 @@ gnc_tree_model_owner_iter_nth_child (GtkTreeModel *tree_model,
|
|||||||
int n)
|
int n)
|
||||||
{
|
{
|
||||||
GncTreeModelOwner *model;
|
GncTreeModelOwner *model;
|
||||||
GncTreeModelOwnerPrivate *priv;
|
|
||||||
|
|
||||||
if (parent_iter)
|
if (parent_iter)
|
||||||
{
|
{
|
||||||
@ -763,14 +736,13 @@ gnc_tree_model_owner_iter_nth_child (GtkTreeModel *tree_model,
|
|||||||
gnc_leave_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (tree_model), FALSE);
|
gnc_leave_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (tree_model), FALSE);
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_OWNER (tree_model);
|
model = GNC_TREE_MODEL_OWNER (tree_model);
|
||||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
/* Owner lists don't have children, so this function call only
|
/* Owner lists don't have children, so this function call only
|
||||||
* makes sense if no parent_iter was supplied. In that case,
|
* makes sense if no parent_iter was supplied. In that case,
|
||||||
* return the first owner in the list */
|
* return the first owner in the list */
|
||||||
if (!parent_iter)
|
if (!parent_iter)
|
||||||
{
|
{
|
||||||
iter->user_data = g_list_nth_data (priv->owner_list, n);
|
iter->user_data = g_list_nth_data (model->owner_list, n);
|
||||||
iter->user_data2 = GINT_TO_POINTER (n);
|
iter->user_data2 = GINT_TO_POINTER (n);
|
||||||
iter->user_data3 = NULL;
|
iter->user_data3 = NULL;
|
||||||
iter->stamp = model->stamp;
|
iter->stamp = model->stamp;
|
||||||
@ -826,7 +798,6 @@ gnc_tree_model_owner_get_iter_from_owner (GncTreeModelOwner *model,
|
|||||||
GncOwner *owner,
|
GncOwner *owner,
|
||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GncTreeModelOwnerPrivate *priv;
|
|
||||||
GList *owner_in_list;
|
GList *owner_in_list;
|
||||||
|
|
||||||
ENTER("model %p, owner %p, iter %p", model, owner, iter);
|
ENTER("model %p, owner %p, iter %p", model, owner, iter);
|
||||||
@ -834,14 +805,12 @@ gnc_tree_model_owner_get_iter_from_owner (GncTreeModelOwner *model,
|
|||||||
gnc_leave_return_val_if_fail ((owner != NULL), FALSE);
|
gnc_leave_return_val_if_fail ((owner != NULL), FALSE);
|
||||||
gnc_leave_return_val_if_fail ((iter != NULL), FALSE);
|
gnc_leave_return_val_if_fail ((iter != NULL), FALSE);
|
||||||
|
|
||||||
|
owner_in_list = g_list_find_custom (model->owner_list, (gconstpointer)owner, (GCompareFunc)gncOwnerGCompareFunc);
|
||||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
|
||||||
owner_in_list = g_list_find_custom (priv->owner_list, (gconstpointer)owner, (GCompareFunc)gncOwnerGCompareFunc);
|
|
||||||
if (owner_in_list)
|
if (owner_in_list)
|
||||||
{
|
{
|
||||||
iter->stamp = model->stamp;
|
iter->stamp = model->stamp;
|
||||||
iter->user_data = owner_in_list->data;
|
iter->user_data = owner_in_list->data;
|
||||||
iter->user_data2 = GINT_TO_POINTER (g_list_position (priv->owner_list, owner_in_list));
|
iter->user_data2 = GINT_TO_POINTER (g_list_position (model->owner_list, owner_in_list));
|
||||||
iter->user_data3 = NULL;
|
iter->user_data3 = NULL;
|
||||||
LEAVE("iter %s", iter_to_string (iter));
|
LEAVE("iter %s", iter_to_string (iter));
|
||||||
return TRUE;
|
return TRUE;
|
||||||
@ -937,7 +906,6 @@ gnc_tree_model_owner_event_handler (QofInstance *entity,
|
|||||||
GncTreeModelOwner *model,
|
GncTreeModelOwner *model,
|
||||||
GncEventData *ed)
|
GncEventData *ed)
|
||||||
{
|
{
|
||||||
GncTreeModelOwnerPrivate *priv;
|
|
||||||
GtkTreePath *path = NULL;
|
GtkTreePath *path = NULL;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GncOwner owner;
|
GncOwner owner;
|
||||||
@ -949,16 +917,15 @@ gnc_tree_model_owner_event_handler (QofInstance *entity,
|
|||||||
|
|
||||||
ENTER("entity %p of type %d, model %p, event_data %p",
|
ENTER("entity %p of type %d, model %p, event_data %p",
|
||||||
entity, event_type, model, ed);
|
entity, event_type, model, ed);
|
||||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
qofOwnerSetEntity (&owner, entity);
|
qofOwnerSetEntity (&owner, entity);
|
||||||
if (gncOwnerGetType(&owner) != priv->owner_type)
|
if (gncOwnerGetType(&owner) != model->owner_type)
|
||||||
{
|
{
|
||||||
LEAVE("model type and owner type differ");
|
LEAVE("model type and owner type differ");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (qof_instance_get_book (entity) != priv->book)
|
if (qof_instance_get_book (entity) != model->book)
|
||||||
{
|
{
|
||||||
LEAVE("not in this book");
|
LEAVE("not in this book");
|
||||||
return;
|
return;
|
||||||
@ -971,11 +938,11 @@ gnc_tree_model_owner_event_handler (QofInstance *entity,
|
|||||||
/* Tell the filters/views where the new owner was added. */
|
/* Tell the filters/views where the new owner was added. */
|
||||||
DEBUG("add owner %p (%s)", &owner, gncOwnerGetName(&owner));
|
DEBUG("add owner %p (%s)", &owner, gncOwnerGetName(&owner));
|
||||||
/* First update our copy of the owner list. This isn't done automatically */
|
/* First update our copy of the owner list. This isn't done automatically */
|
||||||
if (priv->owner_list)
|
if (model->owner_list)
|
||||||
g_list_free_full (priv->owner_list, (GDestroyNotify) gncOwnerFree);
|
g_list_free_full (model->owner_list, (GDestroyNotify) gncOwnerFree);
|
||||||
|
|
||||||
priv->owner_list = gncBusinessGetOwnerList (priv->book,
|
model->owner_list = gncBusinessGetOwnerList (model->book,
|
||||||
gncOwnerTypeToQofIdType(priv->owner_type), TRUE);
|
gncOwnerTypeToQofIdType(model->owner_type), TRUE);
|
||||||
increment_stamp(model);
|
increment_stamp(model);
|
||||||
if (!gnc_tree_model_owner_get_iter_from_owner (model, &owner, &iter))
|
if (!gnc_tree_model_owner_get_iter_from_owner (model, &owner, &iter))
|
||||||
{
|
{
|
||||||
@ -995,7 +962,7 @@ gnc_tree_model_owner_event_handler (QofInstance *entity,
|
|||||||
if (!ed) /* Required for a remove. */
|
if (!ed) /* Required for a remove. */
|
||||||
break;
|
break;
|
||||||
DEBUG("remove owner %d (%s) from owner_list %p", ed->idx,
|
DEBUG("remove owner %d (%s) from owner_list %p", ed->idx,
|
||||||
gncOwnerGetName(&owner), priv->owner_list);
|
gncOwnerGetName(&owner), model->owner_list);
|
||||||
path = gtk_tree_path_new();
|
path = gtk_tree_path_new();
|
||||||
if (!path)
|
if (!path)
|
||||||
{
|
{
|
||||||
|
@ -43,11 +43,8 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
/* type macros */
|
/* type macros */
|
||||||
#define GNC_TYPE_TREE_MODEL_OWNER (gnc_tree_model_owner_get_type ())
|
#define GNC_TYPE_TREE_MODEL_OWNER (gnc_tree_model_owner_get_type ())
|
||||||
#define GNC_TREE_MODEL_OWNER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_TREE_MODEL_OWNER, GncTreeModelOwner))
|
G_DECLARE_FINAL_TYPE (GncTreeModelOwner, gnc_tree_model_owner, GNC, TREE_MODEL_OWNER, GncTreeModel)
|
||||||
#define GNC_TREE_MODEL_OWNER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_TREE_MODEL_OWNER, GncTreeModelOwnerClass))
|
|
||||||
#define GNC_IS_TREE_MODEL_OWNER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_TREE_MODEL_OWNER))
|
|
||||||
#define GNC_IS_TREE_MODEL_OWNER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_TREE_MODEL_OWNER))
|
|
||||||
#define GNC_TREE_MODEL_OWNER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_TREE_MODEL_OWNER, GncTreeModelOwnerClass))
|
|
||||||
#define GNC_TREE_MODEL_OWNER_NAME "GncTreeModelOwner"
|
#define GNC_TREE_MODEL_OWNER_NAME "GncTreeModelOwner"
|
||||||
|
|
||||||
|
|
||||||
@ -78,32 +75,6 @@ typedef enum
|
|||||||
GNC_TREE_MODEL_OWNER_NUM_COLUMNS
|
GNC_TREE_MODEL_OWNER_NUM_COLUMNS
|
||||||
} GncTreeModelOwnerColumn;
|
} GncTreeModelOwnerColumn;
|
||||||
|
|
||||||
/* typedefs & structures */
|
|
||||||
|
|
||||||
/** The instance data structure for an owner tree model. */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GncTreeModel gnc_tree_model; /**< The parent object data. */
|
|
||||||
int stamp; /**< The state of the model. Any state
|
|
||||||
* change increments this number. */
|
|
||||||
} GncTreeModelOwner;
|
|
||||||
|
|
||||||
|
|
||||||
/** The class data structure for an owner tree model. */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GncTreeModelClass gnc_tree_model;/**< The parent object data. */
|
|
||||||
} GncTreeModelOwnerClass;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Get the type of an owner tree plugin.
|
|
||||||
*
|
|
||||||
* @return A GType.
|
|
||||||
*/
|
|
||||||
GType gnc_tree_model_owner_get_type (void);
|
|
||||||
|
|
||||||
|
|
||||||
/** @name Owner Tree Model Constructors
|
/** @name Owner Tree Model Constructors
|
||||||
@{ */
|
@{ */
|
||||||
|
|
||||||
|
@ -120,20 +120,19 @@ static void gnc_tree_model_price_event_handler (QofInstance *entity,
|
|||||||
gpointer user_data,
|
gpointer user_data,
|
||||||
gpointer event_data);
|
gpointer event_data);
|
||||||
|
|
||||||
/** The instance private data for a price database tree model. */
|
/** The instance data structure for a price tree model. */
|
||||||
typedef struct GncTreeModelPricePrivate
|
struct _GncTreeModelPrice
|
||||||
{
|
{
|
||||||
|
GncTreeModel gnc_tree_model; /**< The parent object data. */
|
||||||
|
int stamp; /**< The state of the model. Any state
|
||||||
|
* change increments this number. */
|
||||||
QofBook *book;
|
QofBook *book;
|
||||||
GNCPriceDB *price_db;
|
GNCPriceDB *price_db;
|
||||||
gint event_handler_id;
|
gint event_handler_id;
|
||||||
GNCPrintAmountInfo print_info;
|
GNCPrintAmountInfo print_info;
|
||||||
} GncTreeModelPricePrivate;
|
};
|
||||||
|
|
||||||
#define GNC_TREE_MODEL_PRICE_GET_PRIVATE(o) \
|
|
||||||
((GncTreeModelPricePrivate*)gnc_tree_model_price_get_instance_private((GncTreeModelPrice*)o))
|
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_CODE(GncTreeModelPrice, gnc_tree_model_price, GNC_TYPE_TREE_MODEL,
|
G_DEFINE_TYPE_WITH_CODE(GncTreeModelPrice, gnc_tree_model_price, GNC_TYPE_TREE_MODEL,
|
||||||
G_ADD_PRIVATE(GncTreeModelPrice)
|
|
||||||
G_IMPLEMENT_INTERFACE(GTK_TYPE_TREE_MODEL,
|
G_IMPLEMENT_INTERFACE(GTK_TYPE_TREE_MODEL,
|
||||||
gnc_tree_model_price_tree_model_init))
|
gnc_tree_model_price_tree_model_init))
|
||||||
|
|
||||||
@ -149,22 +148,18 @@ gnc_tree_model_price_class_init (GncTreeModelPriceClass *klass)
|
|||||||
static void
|
static void
|
||||||
gnc_tree_model_price_init (GncTreeModelPrice *model)
|
gnc_tree_model_price_init (GncTreeModelPrice *model)
|
||||||
{
|
{
|
||||||
GncTreeModelPricePrivate *priv;
|
|
||||||
|
|
||||||
while (model->stamp == 0)
|
while (model->stamp == 0)
|
||||||
{
|
{
|
||||||
model->stamp = g_random_int ();
|
model->stamp = g_random_int ();
|
||||||
}
|
}
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
model->print_info = gnc_default_price_print_info(NULL);
|
||||||
priv->print_info = gnc_default_price_print_info(NULL);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
gnc_tree_model_price_finalize (GObject *object)
|
gnc_tree_model_price_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
GncTreeModelPrice *model;
|
GncTreeModelPrice *model;
|
||||||
GncTreeModelPricePrivate *priv;
|
|
||||||
|
|
||||||
ENTER("model %p", object);
|
ENTER("model %p", object);
|
||||||
|
|
||||||
@ -172,10 +167,9 @@ gnc_tree_model_price_finalize (GObject *object)
|
|||||||
g_return_if_fail (GNC_IS_TREE_MODEL_PRICE (object));
|
g_return_if_fail (GNC_IS_TREE_MODEL_PRICE (object));
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_PRICE (object);
|
model = GNC_TREE_MODEL_PRICE (object);
|
||||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
priv->book = NULL;
|
model->book = NULL;
|
||||||
priv->price_db = NULL;
|
model->price_db = NULL;
|
||||||
|
|
||||||
G_OBJECT_CLASS (gnc_tree_model_price_parent_class)->finalize (object);
|
G_OBJECT_CLASS (gnc_tree_model_price_parent_class)->finalize (object);
|
||||||
LEAVE(" ");
|
LEAVE(" ");
|
||||||
@ -185,19 +179,17 @@ static void
|
|||||||
gnc_tree_model_price_dispose (GObject *object)
|
gnc_tree_model_price_dispose (GObject *object)
|
||||||
{
|
{
|
||||||
GncTreeModelPrice *model;
|
GncTreeModelPrice *model;
|
||||||
GncTreeModelPricePrivate *priv;
|
|
||||||
|
|
||||||
ENTER("model %p", object);
|
ENTER("model %p", object);
|
||||||
g_return_if_fail (object != NULL);
|
g_return_if_fail (object != NULL);
|
||||||
g_return_if_fail (GNC_IS_TREE_MODEL_PRICE (object));
|
g_return_if_fail (GNC_IS_TREE_MODEL_PRICE (object));
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_PRICE (object);
|
model = GNC_TREE_MODEL_PRICE (object);
|
||||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
if (priv->event_handler_id)
|
if (model->event_handler_id)
|
||||||
{
|
{
|
||||||
qof_event_unregister_handler (priv->event_handler_id);
|
qof_event_unregister_handler (model->event_handler_id);
|
||||||
priv->event_handler_id = 0;
|
model->event_handler_id = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
G_OBJECT_CLASS (gnc_tree_model_price_parent_class)->dispose (object);
|
G_OBJECT_CLASS (gnc_tree_model_price_parent_class)->dispose (object);
|
||||||
@ -208,7 +200,6 @@ GtkTreeModel *
|
|||||||
gnc_tree_model_price_new (QofBook *book, GNCPriceDB *price_db)
|
gnc_tree_model_price_new (QofBook *book, GNCPriceDB *price_db)
|
||||||
{
|
{
|
||||||
GncTreeModelPrice *model;
|
GncTreeModelPrice *model;
|
||||||
GncTreeModelPricePrivate *priv;
|
|
||||||
const GList *item;
|
const GList *item;
|
||||||
|
|
||||||
ENTER(" ");
|
ENTER(" ");
|
||||||
@ -217,8 +208,7 @@ gnc_tree_model_price_new (QofBook *book, GNCPriceDB *price_db)
|
|||||||
for ( ; item; item = g_list_next(item))
|
for ( ; item; item = g_list_next(item))
|
||||||
{
|
{
|
||||||
model = (GncTreeModelPrice *)item->data;
|
model = (GncTreeModelPrice *)item->data;
|
||||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
if (model->price_db == price_db)
|
||||||
if (priv->price_db == price_db)
|
|
||||||
{
|
{
|
||||||
g_object_ref(G_OBJECT(model));
|
g_object_ref(G_OBJECT(model));
|
||||||
LEAVE("returning existing model %p", model);
|
LEAVE("returning existing model %p", model);
|
||||||
@ -228,11 +218,10 @@ gnc_tree_model_price_new (QofBook *book, GNCPriceDB *price_db)
|
|||||||
|
|
||||||
model = g_object_new (GNC_TYPE_TREE_MODEL_PRICE, NULL);
|
model = g_object_new (GNC_TYPE_TREE_MODEL_PRICE, NULL);
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
model->book = book;
|
||||||
priv->book = book;
|
model->price_db = price_db;
|
||||||
priv->price_db = price_db;
|
|
||||||
|
|
||||||
priv->event_handler_id =
|
model->event_handler_id =
|
||||||
qof_event_register_handler (gnc_tree_model_price_event_handler, model);
|
qof_event_register_handler (gnc_tree_model_price_event_handler, model);
|
||||||
|
|
||||||
LEAVE("returning new model %p", model);
|
LEAVE("returning new model %p", model);
|
||||||
@ -332,7 +321,6 @@ gnc_tree_model_price_get_price (GncTreeModelPrice *model,
|
|||||||
static const gchar *
|
static const gchar *
|
||||||
iter_to_string (GncTreeModelPrice *model, GtkTreeIter *iter)
|
iter_to_string (GncTreeModelPrice *model, GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GncTreeModelPricePrivate *priv;
|
|
||||||
gnc_commodity_namespace *name_space;
|
gnc_commodity_namespace *name_space;
|
||||||
gnc_commodity *commodity;
|
gnc_commodity *commodity;
|
||||||
GNCPrice *price;
|
GNCPrice *price;
|
||||||
@ -350,7 +338,6 @@ iter_to_string (GncTreeModelPrice *model, GtkTreeIter *iter)
|
|||||||
static char string[ITER_STRING_LEN + 1];
|
static char string[ITER_STRING_LEN + 1];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
|
||||||
if (iter)
|
if (iter)
|
||||||
{
|
{
|
||||||
switch (GPOINTER_TO_INT(iter->user_data))
|
switch (GPOINTER_TO_INT(iter->user_data))
|
||||||
@ -380,7 +367,7 @@ iter_to_string (GncTreeModelPrice *model, GtkTreeIter *iter)
|
|||||||
"[stamp:%x data:%d (PRICE), %p (%s:%s), %d]",
|
"[stamp:%x data:%d (PRICE), %p (%s:%s), %d]",
|
||||||
iter->stamp, GPOINTER_TO_INT(iter->user_data),
|
iter->stamp, GPOINTER_TO_INT(iter->user_data),
|
||||||
iter->user_data2, gnc_commodity_get_mnemonic (commodity),
|
iter->user_data2, gnc_commodity_get_mnemonic (commodity),
|
||||||
xaccPrintAmount (gnc_price_get_value (price), priv->print_info),
|
xaccPrintAmount (gnc_price_get_value (price), model->print_info),
|
||||||
GPOINTER_TO_INT(iter->user_data3));
|
GPOINTER_TO_INT(iter->user_data3));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -461,7 +448,6 @@ gnc_tree_model_price_get_iter (GtkTreeModel *tree_model,
|
|||||||
GtkTreePath *path)
|
GtkTreePath *path)
|
||||||
{
|
{
|
||||||
GncTreeModelPrice *model;
|
GncTreeModelPrice *model;
|
||||||
GncTreeModelPricePrivate *priv;
|
|
||||||
gnc_commodity_table *ct;
|
gnc_commodity_table *ct;
|
||||||
gnc_commodity_namespace *name_space;
|
gnc_commodity_namespace *name_space;
|
||||||
gnc_commodity *commodity = NULL;
|
gnc_commodity *commodity = NULL;
|
||||||
@ -489,15 +475,14 @@ gnc_tree_model_price_get_iter (GtkTreeModel *tree_model,
|
|||||||
|
|
||||||
/* Make sure the model has a price db. */
|
/* Make sure the model has a price db. */
|
||||||
model = GNC_TREE_MODEL_PRICE (tree_model);
|
model = GNC_TREE_MODEL_PRICE (tree_model);
|
||||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
if (model->price_db == NULL)
|
||||||
if (priv->price_db == NULL)
|
|
||||||
{
|
{
|
||||||
LEAVE("no price db");
|
LEAVE("no price db");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Verify the first part of the path: the namespace. */
|
/* Verify the first part of the path: the namespace. */
|
||||||
ct = qof_book_get_data (priv->book, GNC_COMMODITY_TABLE);
|
ct = qof_book_get_data (model->book, GNC_COMMODITY_TABLE);
|
||||||
ns_list = gnc_commodity_table_get_namespaces_list(ct);
|
ns_list = gnc_commodity_table_get_namespaces_list(ct);
|
||||||
i = gtk_tree_path_get_indices (path)[0];
|
i = gtk_tree_path_get_indices (path)[0];
|
||||||
name_space = g_list_nth_data (ns_list, i);
|
name_space = g_list_nth_data (ns_list, i);
|
||||||
@ -541,7 +526,7 @@ gnc_tree_model_price_get_iter (GtkTreeModel *tree_model,
|
|||||||
|
|
||||||
/* Verify the third part of the path: the price. */
|
/* Verify the third part of the path: the price. */
|
||||||
i = gtk_tree_path_get_indices (path)[2];
|
i = gtk_tree_path_get_indices (path)[2];
|
||||||
price = gnc_pricedb_nth_price(priv->price_db, commodity, i);
|
price = gnc_pricedb_nth_price(model->price_db, commodity, i);
|
||||||
/* There's a race condition here that I can't resolve.
|
/* There's a race condition here that I can't resolve.
|
||||||
* Comment this check out for now, and we'll handle the
|
* Comment this check out for now, and we'll handle the
|
||||||
* resulting problem elsewhere. */
|
* resulting problem elsewhere. */
|
||||||
@ -567,7 +552,6 @@ gnc_tree_model_price_get_path (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GncTreeModelPrice *model = GNC_TREE_MODEL_PRICE (tree_model);
|
GncTreeModelPrice *model = GNC_TREE_MODEL_PRICE (tree_model);
|
||||||
GncTreeModelPricePrivate *priv;
|
|
||||||
gnc_commodity_table *ct;
|
gnc_commodity_table *ct;
|
||||||
gnc_commodity_namespace *name_space;
|
gnc_commodity_namespace *name_space;
|
||||||
gnc_commodity *commodity;
|
gnc_commodity *commodity;
|
||||||
@ -581,8 +565,7 @@ gnc_tree_model_price_get_path (GtkTreeModel *tree_model,
|
|||||||
g_return_val_if_fail (iter->stamp == model->stamp, NULL);
|
g_return_val_if_fail (iter->stamp == model->stamp, NULL);
|
||||||
|
|
||||||
/* Make sure this model has a price db. */
|
/* Make sure this model has a price db. */
|
||||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
if (model->price_db == NULL)
|
||||||
if (priv->price_db == NULL)
|
|
||||||
{
|
{
|
||||||
LEAVE("no price db");
|
LEAVE("no price db");
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@ -599,7 +582,7 @@ gnc_tree_model_price_get_path (GtkTreeModel *tree_model,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Get the namespaces list. */
|
/* Get the namespaces list. */
|
||||||
ct = qof_book_get_data (priv->book, GNC_COMMODITY_TABLE);
|
ct = qof_book_get_data (model->book, GNC_COMMODITY_TABLE);
|
||||||
ns_list = gnc_commodity_table_get_namespaces_list(ct);
|
ns_list = gnc_commodity_table_get_namespaces_list(ct);
|
||||||
|
|
||||||
if (iter->user_data == ITER_IS_COMMODITY)
|
if (iter->user_data == ITER_IS_COMMODITY)
|
||||||
@ -633,7 +616,6 @@ gnc_tree_model_price_get_value (GtkTreeModel *tree_model,
|
|||||||
GValue *value)
|
GValue *value)
|
||||||
{
|
{
|
||||||
GncTreeModelPrice *model = GNC_TREE_MODEL_PRICE (tree_model);
|
GncTreeModelPrice *model = GNC_TREE_MODEL_PRICE (tree_model);
|
||||||
GncTreeModelPricePrivate *priv;
|
|
||||||
gnc_commodity_namespace *name_space;
|
gnc_commodity_namespace *name_space;
|
||||||
gnc_commodity *commodity;
|
gnc_commodity *commodity;
|
||||||
GNCPrice *price;
|
GNCPrice *price;
|
||||||
@ -742,9 +724,8 @@ gnc_tree_model_price_get_value (GtkTreeModel *tree_model,
|
|||||||
break;
|
break;
|
||||||
case GNC_TREE_MODEL_PRICE_COL_VALUE:
|
case GNC_TREE_MODEL_PRICE_COL_VALUE:
|
||||||
g_value_init (value, G_TYPE_STRING);
|
g_value_init (value, G_TYPE_STRING);
|
||||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
|
||||||
g_value_set_string (value, xaccPrintAmount (gnc_price_get_value (price),
|
g_value_set_string (value, xaccPrintAmount (gnc_price_get_value (price),
|
||||||
priv->print_info));
|
model->print_info));
|
||||||
break;
|
break;
|
||||||
case GNC_TREE_MODEL_PRICE_COL_VISIBILITY:
|
case GNC_TREE_MODEL_PRICE_COL_VISIBILITY:
|
||||||
g_value_init (value, G_TYPE_BOOLEAN);
|
g_value_init (value, G_TYPE_BOOLEAN);
|
||||||
@ -760,7 +741,6 @@ gnc_tree_model_price_iter_next (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GncTreeModelPrice *model = GNC_TREE_MODEL_PRICE (tree_model);
|
GncTreeModelPrice *model = GNC_TREE_MODEL_PRICE (tree_model);
|
||||||
GncTreeModelPricePrivate *priv;
|
|
||||||
gnc_commodity_table *ct;
|
gnc_commodity_table *ct;
|
||||||
gnc_commodity *commodity;
|
gnc_commodity *commodity;
|
||||||
gnc_commodity_namespace *name_space;
|
gnc_commodity_namespace *name_space;
|
||||||
@ -773,10 +753,9 @@ gnc_tree_model_price_iter_next (GtkTreeModel *tree_model,
|
|||||||
g_return_val_if_fail (iter->user_data != NULL, FALSE);
|
g_return_val_if_fail (iter->user_data != NULL, FALSE);
|
||||||
g_return_val_if_fail (iter->stamp == model->stamp, FALSE);
|
g_return_val_if_fail (iter->stamp == model->stamp, FALSE);
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
|
||||||
if (iter->user_data == ITER_IS_NAMESPACE)
|
if (iter->user_data == ITER_IS_NAMESPACE)
|
||||||
{
|
{
|
||||||
ct = qof_book_get_data (priv->book, GNC_COMMODITY_TABLE);
|
ct = qof_book_get_data (model->book, GNC_COMMODITY_TABLE);
|
||||||
list = gnc_commodity_table_get_namespaces_list(ct);
|
list = gnc_commodity_table_get_namespaces_list(ct);
|
||||||
n = GPOINTER_TO_INT(iter->user_data3) + 1;
|
n = GPOINTER_TO_INT(iter->user_data3) + 1;
|
||||||
iter->user_data2 = g_list_nth_data(list, n);
|
iter->user_data2 = g_list_nth_data(list, n);
|
||||||
@ -808,7 +787,7 @@ gnc_tree_model_price_iter_next (GtkTreeModel *tree_model,
|
|||||||
{
|
{
|
||||||
commodity = gnc_price_get_commodity((GNCPrice*)iter->user_data2);
|
commodity = gnc_price_get_commodity((GNCPrice*)iter->user_data2);
|
||||||
n = GPOINTER_TO_INT(iter->user_data3) + 1;
|
n = GPOINTER_TO_INT(iter->user_data3) + 1;
|
||||||
iter->user_data2 = gnc_pricedb_nth_price(priv->price_db, commodity, n);
|
iter->user_data2 = gnc_pricedb_nth_price(model->price_db, commodity, n);
|
||||||
if (iter->user_data2 == NULL)
|
if (iter->user_data2 == NULL)
|
||||||
{
|
{
|
||||||
LEAVE("no next iter");
|
LEAVE("no next iter");
|
||||||
@ -831,7 +810,6 @@ gnc_tree_model_price_iter_children (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *parent)
|
GtkTreeIter *parent)
|
||||||
{
|
{
|
||||||
GncTreeModelPrice *model;
|
GncTreeModelPrice *model;
|
||||||
GncTreeModelPricePrivate *priv;
|
|
||||||
gnc_commodity_table *ct;
|
gnc_commodity_table *ct;
|
||||||
gnc_commodity_namespace *name_space;
|
gnc_commodity_namespace *name_space;
|
||||||
gnc_commodity *commodity;
|
gnc_commodity *commodity;
|
||||||
@ -843,10 +821,9 @@ gnc_tree_model_price_iter_children (GtkTreeModel *tree_model,
|
|||||||
ENTER("model %p, iter %p, parent %p (%s)",
|
ENTER("model %p, iter %p, parent %p (%s)",
|
||||||
tree_model, iter, parent, iter_to_string(model, parent));
|
tree_model, iter, parent, iter_to_string(model, parent));
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
|
||||||
if (parent == NULL)
|
if (parent == NULL)
|
||||||
{
|
{
|
||||||
ct = qof_book_get_data (priv->book, GNC_COMMODITY_TABLE);
|
ct = qof_book_get_data (model->book, GNC_COMMODITY_TABLE);
|
||||||
list = gnc_commodity_table_get_namespaces_list(ct);
|
list = gnc_commodity_table_get_namespaces_list(ct);
|
||||||
if (list == NULL)
|
if (list == NULL)
|
||||||
{
|
{
|
||||||
@ -884,7 +861,7 @@ gnc_tree_model_price_iter_children (GtkTreeModel *tree_model,
|
|||||||
{
|
{
|
||||||
GNCPrice *price;
|
GNCPrice *price;
|
||||||
commodity = (gnc_commodity *)parent->user_data2;
|
commodity = (gnc_commodity *)parent->user_data2;
|
||||||
price = gnc_pricedb_nth_price(priv->price_db, commodity, 0);
|
price = gnc_pricedb_nth_price(model->price_db, commodity, 0);
|
||||||
if (price == NULL)
|
if (price == NULL)
|
||||||
{
|
{
|
||||||
LEAVE("no prices");
|
LEAVE("no prices");
|
||||||
@ -907,7 +884,6 @@ gnc_tree_model_price_iter_has_child (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GncTreeModelPrice *model;
|
GncTreeModelPrice *model;
|
||||||
GncTreeModelPricePrivate *priv;
|
|
||||||
gnc_commodity_namespace *name_space;
|
gnc_commodity_namespace *name_space;
|
||||||
gnc_commodity *commodity;
|
gnc_commodity *commodity;
|
||||||
gboolean result;
|
gboolean result;
|
||||||
@ -919,7 +895,6 @@ gnc_tree_model_price_iter_has_child (GtkTreeModel *tree_model,
|
|||||||
g_return_val_if_fail (tree_model != NULL, FALSE);
|
g_return_val_if_fail (tree_model != NULL, FALSE);
|
||||||
g_return_val_if_fail (iter != NULL, FALSE);
|
g_return_val_if_fail (iter != NULL, FALSE);
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
|
||||||
if (iter->user_data == ITER_IS_PRICE)
|
if (iter->user_data == ITER_IS_PRICE)
|
||||||
{
|
{
|
||||||
LEAVE("price has no children");
|
LEAVE("price has no children");
|
||||||
@ -937,7 +912,7 @@ gnc_tree_model_price_iter_has_child (GtkTreeModel *tree_model,
|
|||||||
if (iter->user_data == ITER_IS_COMMODITY)
|
if (iter->user_data == ITER_IS_COMMODITY)
|
||||||
{
|
{
|
||||||
commodity = (gnc_commodity *)iter->user_data2;
|
commodity = (gnc_commodity *)iter->user_data2;
|
||||||
result = gnc_pricedb_has_prices(priv->price_db, commodity, NULL);
|
result = gnc_pricedb_has_prices(model->price_db, commodity, NULL);
|
||||||
LEAVE("%s children", result ? "has" : "no");
|
LEAVE("%s children", result ? "has" : "no");
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -951,7 +926,6 @@ gnc_tree_model_price_iter_n_children (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GncTreeModelPrice *model;
|
GncTreeModelPrice *model;
|
||||||
GncTreeModelPricePrivate *priv;
|
|
||||||
gnc_commodity_table *ct;
|
gnc_commodity_table *ct;
|
||||||
gnc_commodity_namespace *name_space;
|
gnc_commodity_namespace *name_space;
|
||||||
gnc_commodity *commodity;
|
gnc_commodity *commodity;
|
||||||
@ -964,10 +938,9 @@ gnc_tree_model_price_iter_n_children (GtkTreeModel *tree_model,
|
|||||||
ENTER("model %p, iter %p (%s)", tree_model, iter,
|
ENTER("model %p, iter %p (%s)", tree_model, iter,
|
||||||
iter_to_string(model, iter));
|
iter_to_string(model, iter));
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
|
||||||
if (iter == NULL)
|
if (iter == NULL)
|
||||||
{
|
{
|
||||||
ct = qof_book_get_data (priv->book, GNC_COMMODITY_TABLE);
|
ct = qof_book_get_data (model->book, GNC_COMMODITY_TABLE);
|
||||||
list = gnc_commodity_table_get_namespaces_list(ct);
|
list = gnc_commodity_table_get_namespaces_list(ct);
|
||||||
LEAVE("ns list length %d", g_list_length(list));
|
LEAVE("ns list length %d", g_list_length(list));
|
||||||
return g_list_length (list);
|
return g_list_length (list);
|
||||||
@ -984,7 +957,7 @@ gnc_tree_model_price_iter_n_children (GtkTreeModel *tree_model,
|
|||||||
if (iter->user_data == ITER_IS_COMMODITY)
|
if (iter->user_data == ITER_IS_COMMODITY)
|
||||||
{
|
{
|
||||||
commodity = (gnc_commodity *)iter->user_data2;
|
commodity = (gnc_commodity *)iter->user_data2;
|
||||||
n = gnc_pricedb_num_prices(priv->price_db, commodity);
|
n = gnc_pricedb_num_prices(model->price_db, commodity);
|
||||||
LEAVE("price list length %d", n);
|
LEAVE("price list length %d", n);
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
@ -1000,7 +973,6 @@ gnc_tree_model_price_iter_nth_child (GtkTreeModel *tree_model,
|
|||||||
int n)
|
int n)
|
||||||
{
|
{
|
||||||
GncTreeModelPrice *model;
|
GncTreeModelPrice *model;
|
||||||
GncTreeModelPricePrivate *priv;
|
|
||||||
gnc_commodity_table *ct;
|
gnc_commodity_table *ct;
|
||||||
gnc_commodity_namespace *name_space;
|
gnc_commodity_namespace *name_space;
|
||||||
gnc_commodity *commodity;
|
gnc_commodity *commodity;
|
||||||
@ -1013,10 +985,9 @@ gnc_tree_model_price_iter_nth_child (GtkTreeModel *tree_model,
|
|||||||
ENTER("model %p, iter %p, parent %p (%s), n %d",
|
ENTER("model %p, iter %p, parent %p (%s), n %d",
|
||||||
tree_model, iter, parent, iter_to_string(model, parent), n);
|
tree_model, iter, parent, iter_to_string(model, parent), n);
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
|
||||||
if (parent == NULL)
|
if (parent == NULL)
|
||||||
{
|
{
|
||||||
ct = qof_book_get_data (priv->book, GNC_COMMODITY_TABLE);
|
ct = qof_book_get_data (model->book, GNC_COMMODITY_TABLE);
|
||||||
list = gnc_commodity_table_get_namespaces_list(ct);
|
list = gnc_commodity_table_get_namespaces_list(ct);
|
||||||
|
|
||||||
iter->stamp = model->stamp;
|
iter->stamp = model->stamp;
|
||||||
@ -1046,7 +1017,7 @@ gnc_tree_model_price_iter_nth_child (GtkTreeModel *tree_model,
|
|||||||
|
|
||||||
iter->stamp = model->stamp;
|
iter->stamp = model->stamp;
|
||||||
iter->user_data = ITER_IS_PRICE;
|
iter->user_data = ITER_IS_PRICE;
|
||||||
iter->user_data2 = gnc_pricedb_nth_price(priv->price_db, commodity, n);
|
iter->user_data2 = gnc_pricedb_nth_price(model->price_db, commodity, n);
|
||||||
iter->user_data3 = GINT_TO_POINTER(n);
|
iter->user_data3 = GINT_TO_POINTER(n);
|
||||||
LEAVE("price iter %p (%s)", iter, iter_to_string(model, iter));
|
LEAVE("price iter %p (%s)", iter, iter_to_string(model, iter));
|
||||||
return iter->user_data2 != NULL;
|
return iter->user_data2 != NULL;
|
||||||
@ -1063,7 +1034,6 @@ gnc_tree_model_price_iter_parent (GtkTreeModel *tree_model,
|
|||||||
GtkTreeIter *child)
|
GtkTreeIter *child)
|
||||||
{
|
{
|
||||||
GncTreeModelPrice *model;
|
GncTreeModelPrice *model;
|
||||||
GncTreeModelPricePrivate *priv;
|
|
||||||
gnc_commodity_table *ct;
|
gnc_commodity_table *ct;
|
||||||
gnc_commodity * commodity;
|
gnc_commodity * commodity;
|
||||||
gnc_commodity_namespace *name_space;
|
gnc_commodity_namespace *name_space;
|
||||||
@ -1077,7 +1047,6 @@ gnc_tree_model_price_iter_parent (GtkTreeModel *tree_model,
|
|||||||
ENTER("model %p, iter %p, child %p (%s)",
|
ENTER("model %p, iter %p, child %p (%s)",
|
||||||
tree_model, iter, child, iter_to_string(model, child));
|
tree_model, iter, child, iter_to_string(model, child));
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
|
||||||
if (child->user_data == ITER_IS_NAMESPACE)
|
if (child->user_data == ITER_IS_NAMESPACE)
|
||||||
{
|
{
|
||||||
LEAVE("ns has no parent");
|
LEAVE("ns has no parent");
|
||||||
@ -1086,7 +1055,7 @@ gnc_tree_model_price_iter_parent (GtkTreeModel *tree_model,
|
|||||||
|
|
||||||
if (child->user_data == ITER_IS_COMMODITY)
|
if (child->user_data == ITER_IS_COMMODITY)
|
||||||
{
|
{
|
||||||
ct = qof_book_get_data (priv->book, GNC_COMMODITY_TABLE);
|
ct = qof_book_get_data (model->book, GNC_COMMODITY_TABLE);
|
||||||
list = gnc_commodity_table_get_namespaces_list(ct);
|
list = gnc_commodity_table_get_namespaces_list(ct);
|
||||||
name_space = gnc_commodity_get_namespace_ds((gnc_commodity*)child->user_data2);
|
name_space = gnc_commodity_get_namespace_ds((gnc_commodity*)child->user_data2);
|
||||||
|
|
||||||
@ -1124,7 +1093,6 @@ gnc_tree_model_price_get_iter_from_price (GncTreeModelPrice *model,
|
|||||||
GNCPrice *price,
|
GNCPrice *price,
|
||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GncTreeModelPricePrivate *priv;
|
|
||||||
gnc_commodity *commodity;
|
gnc_commodity *commodity;
|
||||||
GList *list;
|
GList *list;
|
||||||
gint n;
|
gint n;
|
||||||
@ -1134,7 +1102,6 @@ gnc_tree_model_price_get_iter_from_price (GncTreeModelPrice *model,
|
|||||||
g_return_val_if_fail ((price != NULL), FALSE);
|
g_return_val_if_fail ((price != NULL), FALSE);
|
||||||
g_return_val_if_fail ((iter != NULL), FALSE);
|
g_return_val_if_fail ((iter != NULL), FALSE);
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
|
||||||
commodity = gnc_price_get_commodity(price);
|
commodity = gnc_price_get_commodity(price);
|
||||||
if (commodity == NULL)
|
if (commodity == NULL)
|
||||||
{
|
{
|
||||||
@ -1142,7 +1109,7 @@ gnc_tree_model_price_get_iter_from_price (GncTreeModelPrice *model,
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
list = gnc_pricedb_get_prices(priv->price_db, commodity, NULL);
|
list = gnc_pricedb_get_prices(model->price_db, commodity, NULL);
|
||||||
if (list == NULL)
|
if (list == NULL)
|
||||||
{
|
{
|
||||||
LEAVE("empty list");
|
LEAVE("empty list");
|
||||||
@ -1260,7 +1227,6 @@ gnc_tree_model_price_get_iter_from_namespace (GncTreeModelPrice *model,
|
|||||||
gnc_commodity_namespace *name_space,
|
gnc_commodity_namespace *name_space,
|
||||||
GtkTreeIter *iter)
|
GtkTreeIter *iter)
|
||||||
{
|
{
|
||||||
GncTreeModelPricePrivate *priv;
|
|
||||||
gnc_commodity_table *ct;
|
gnc_commodity_table *ct;
|
||||||
GList *list;
|
GList *list;
|
||||||
gint n;
|
gint n;
|
||||||
@ -1270,8 +1236,7 @@ gnc_tree_model_price_get_iter_from_namespace (GncTreeModelPrice *model,
|
|||||||
g_return_val_if_fail ((name_space != NULL), FALSE);
|
g_return_val_if_fail ((name_space != NULL), FALSE);
|
||||||
g_return_val_if_fail ((iter != NULL), FALSE);
|
g_return_val_if_fail ((iter != NULL), FALSE);
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
ct = qof_book_get_data (model->book, GNC_COMMODITY_TABLE);
|
||||||
ct = qof_book_get_data (priv->book, GNC_COMMODITY_TABLE);
|
|
||||||
list = gnc_commodity_table_get_namespaces_list(ct);
|
list = gnc_commodity_table_get_namespaces_list(ct);
|
||||||
if (list == NULL)
|
if (list == NULL)
|
||||||
{
|
{
|
||||||
@ -1533,7 +1498,6 @@ gnc_tree_model_price_event_handler (QofInstance *entity,
|
|||||||
gpointer event_data)
|
gpointer event_data)
|
||||||
{
|
{
|
||||||
GncTreeModelPrice *model;
|
GncTreeModelPrice *model;
|
||||||
GncTreeModelPricePrivate *priv;
|
|
||||||
GtkTreePath *path;
|
GtkTreePath *path;
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
remove_data *data;
|
remove_data *data;
|
||||||
@ -1542,11 +1506,10 @@ gnc_tree_model_price_event_handler (QofInstance *entity,
|
|||||||
ENTER("entity %p, event %d, model %p, event data %p",
|
ENTER("entity %p, event %d, model %p, event data %p",
|
||||||
entity, event_type, user_data, event_data);
|
entity, event_type, user_data, event_data);
|
||||||
model = (GncTreeModelPrice *)user_data;
|
model = (GncTreeModelPrice *)user_data;
|
||||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
/* Do deletions if any are pending. */
|
/* Do deletions if any are pending. */
|
||||||
if (pending_removals)
|
if (pending_removals)
|
||||||
gnc_tree_model_price_do_deletions (priv->price_db);
|
gnc_tree_model_price_do_deletions (model->price_db);
|
||||||
|
|
||||||
/* hard failures */
|
/* hard failures */
|
||||||
g_return_if_fail(GNC_IS_TREE_MODEL_PRICE(model));
|
g_return_if_fail(GNC_IS_TREE_MODEL_PRICE(model));
|
||||||
@ -1608,7 +1571,7 @@ gnc_tree_model_price_event_handler (QofInstance *entity,
|
|||||||
case QOF_EVENT_ADD:
|
case QOF_EVENT_ADD:
|
||||||
/* Tell the filters/views where the new price was added. */
|
/* Tell the filters/views where the new price was added. */
|
||||||
DEBUG("add %s", name);
|
DEBUG("add %s", name);
|
||||||
gnc_pricedb_nth_price_reset_cache (priv->price_db);
|
gnc_pricedb_nth_price_reset_cache (model->price_db);
|
||||||
gnc_tree_model_price_row_add (model, &iter);
|
gnc_tree_model_price_row_add (model, &iter);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1627,7 +1590,7 @@ gnc_tree_model_price_event_handler (QofInstance *entity,
|
|||||||
data->path = path;
|
data->path = path;
|
||||||
pending_removals = g_slist_append (pending_removals, data);
|
pending_removals = g_slist_append (pending_removals, data);
|
||||||
g_idle_add_full(G_PRIORITY_HIGH_IDLE,
|
g_idle_add_full(G_PRIORITY_HIGH_IDLE,
|
||||||
gnc_tree_model_price_do_deletions, priv->price_db, NULL);
|
gnc_tree_model_price_do_deletions, model->price_db, NULL);
|
||||||
|
|
||||||
LEAVE(" ");
|
LEAVE(" ");
|
||||||
return;
|
return;
|
||||||
|
@ -45,11 +45,8 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
/* type macros */
|
/* type macros */
|
||||||
#define GNC_TYPE_TREE_MODEL_PRICE (gnc_tree_model_price_get_type ())
|
#define GNC_TYPE_TREE_MODEL_PRICE (gnc_tree_model_price_get_type ())
|
||||||
#define GNC_TREE_MODEL_PRICE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_TREE_MODEL_PRICE, GncTreeModelPrice))
|
G_DECLARE_FINAL_TYPE (GncTreeModelPrice, gnc_tree_model_price, GNC, TREE_MODEL_PRICE, GncTreeModel)
|
||||||
#define GNC_TREE_MODEL_PRICE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_TREE_MODEL_PRICE, GncTreeModelPriceClass))
|
|
||||||
#define GNC_IS_TREE_MODEL_PRICE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_TREE_MODEL_PRICE))
|
|
||||||
#define GNC_IS_TREE_MODEL_PRICE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_TREE_MODEL_PRICE))
|
|
||||||
#define GNC_TREE_MODEL_PRICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_TREE_MODEL_PRICE, GncTreeModelPriceClass))
|
|
||||||
#define GNC_TREE_MODEL_PRICE_NAME "GncTreeModelPrice"
|
#define GNC_TREE_MODEL_PRICE_NAME "GncTreeModelPrice"
|
||||||
|
|
||||||
|
|
||||||
@ -69,31 +66,6 @@ typedef enum
|
|||||||
GNC_TREE_MODEL_PRICE_NUM_COLUMNS
|
GNC_TREE_MODEL_PRICE_NUM_COLUMNS
|
||||||
} GncTreeModelPriceColumn;
|
} GncTreeModelPriceColumn;
|
||||||
|
|
||||||
/* typedefs & structures */
|
|
||||||
|
|
||||||
/** The instance data structure for a price tree model. */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GncTreeModel gnc_tree_model; /**< The parent object data. */
|
|
||||||
int stamp; /**< The state of the model. Any state
|
|
||||||
* change increments this number. */
|
|
||||||
} GncTreeModelPrice;
|
|
||||||
|
|
||||||
|
|
||||||
/** The class data structure for a price tree model. */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GncTreeModelClass gnc_tree_model;/**< The parent object data. */
|
|
||||||
} GncTreeModelPriceClass;
|
|
||||||
|
|
||||||
|
|
||||||
/** Get the type of a price tree plugin.
|
|
||||||
*
|
|
||||||
* @return A GType.
|
|
||||||
*/
|
|
||||||
GType gnc_tree_model_price_get_type (void);
|
|
||||||
|
|
||||||
|
|
||||||
/** @name Account Tree Model Constructors
|
/** @name Account Tree Model Constructors
|
||||||
@{ */
|
@{ */
|
||||||
|
|
||||||
|
@ -1,638 +0,0 @@
|
|||||||
/*
|
|
||||||
* gnc-tree-model-selection.c -- GtkTreeModel which supports a
|
|
||||||
* selectable column.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2003 Jan Arne Petersen
|
|
||||||
* Author: Jan Arne Petersen <jpetersen@uni-bonn.de>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2 of
|
|
||||||
* the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, contact:
|
|
||||||
*
|
|
||||||
* Free Software Foundation Voice: +1-617-542-5942
|
|
||||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
|
||||||
* Boston, MA 02110-1301, USA gnu@gnu.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <config.h>
|
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
|
||||||
|
|
||||||
#include "gnc-tree-model-selection.h"
|
|
||||||
|
|
||||||
static void gnc_tree_model_selection_finalize (GObject *object);
|
|
||||||
|
|
||||||
static void gnc_tree_model_selection_tree_model_init (GtkTreeModelIface *iface);
|
|
||||||
static GtkTreeModelFlags gnc_tree_model_selection_get_flags (GtkTreeModel *tree_model);
|
|
||||||
static int gnc_tree_model_selection_get_n_columns (GtkTreeModel *tree_model);
|
|
||||||
static GType gnc_tree_model_selection_get_column_type (GtkTreeModel *tree_model,
|
|
||||||
int index);
|
|
||||||
static gboolean gnc_tree_model_selection_get_iter (GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
GtkTreePath *path);
|
|
||||||
static GtkTreePath *gnc_tree_model_selection_get_path (GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter);
|
|
||||||
static void gnc_tree_model_selection_get_value (GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
int column,
|
|
||||||
GValue *value);
|
|
||||||
static gboolean gnc_tree_model_selection_iter_next (GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter);
|
|
||||||
static gboolean gnc_tree_model_selection_iter_children (GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
GtkTreeIter *parent);
|
|
||||||
static gboolean gnc_tree_model_selection_iter_has_child (GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter);
|
|
||||||
static int gnc_tree_model_selection_iter_n_children (GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter);
|
|
||||||
static gboolean gnc_tree_model_selection_iter_nth_child (GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
GtkTreeIter *parent,
|
|
||||||
int n);
|
|
||||||
static gboolean gnc_tree_model_selection_iter_parent (GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
GtkTreeIter *child);
|
|
||||||
|
|
||||||
static void gnc_tree_model_selection_row_changed (GtkTreeModel *tree_model,
|
|
||||||
GtkTreePath *path,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
GncTreeModelSelection *selection_model);
|
|
||||||
static void gnc_tree_model_selection_row_inserted (GtkTreeModel *tree_model,
|
|
||||||
GtkTreePath *path,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
GncTreeModelSelection *selection_model);
|
|
||||||
static void gnc_tree_model_selection_row_has_child_toggled (GtkTreeModel *tree_model,
|
|
||||||
GtkTreePath *path,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
GncTreeModelSelection *selection_model);
|
|
||||||
static void gnc_tree_model_selection_row_deleted (GtkTreeModel *tree_model,
|
|
||||||
GtkTreePath *path,
|
|
||||||
GncTreeModelSelection *selection_model);
|
|
||||||
static void gnc_tree_model_selection_rows_reordered (GtkTreeModel *tree_model,
|
|
||||||
GtkTreePath *path,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
gint *new_order,
|
|
||||||
GncTreeModelSelection *selection_model);
|
|
||||||
|
|
||||||
static void gnc_tree_model_selection_toggled (GtkCellRendererToggle *toggle,
|
|
||||||
gchar *path,
|
|
||||||
GncTreeModelSelection *model);
|
|
||||||
|
|
||||||
typedef struct GncTreeModelSelectionPrivate
|
|
||||||
{
|
|
||||||
GtkTreeModel *child_model;
|
|
||||||
|
|
||||||
GHashTable *selections;
|
|
||||||
} GncTreeModelSelectionPrivate;
|
|
||||||
|
|
||||||
#define GNC_TREE_MODEL_SELECTION_GET_PRIVATE(o) \
|
|
||||||
((GncTreeModelSelectionPrivate*)gnc_tree_model_selection_get_instance_private((GncTreeModelSelection*)o))
|
|
||||||
|
|
||||||
G_DEFINE_TYPE_WITH_CODE(GncTreeModelSelection, gnc_tree_model_selection, G_TYPE_OBJECT
|
|
||||||
G_ADD_PRIVATE(GncTreeModelSelection)
|
|
||||||
G_IMPLEMENT_INTERFACE(GTK_TYPE_TREE_MODEL,
|
|
||||||
gnc_tree_model_selection_tree_model_init))
|
|
||||||
|
|
||||||
static void
|
|
||||||
gnc_tree_model_selection_class_init (GncTreeModelSelectionClass *klass)
|
|
||||||
{
|
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
|
||||||
|
|
||||||
object_class->finalize = gnc_tree_model_selection_finalize;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gnc_tree_model_selection_init (GncTreeModelSelection *model)
|
|
||||||
{
|
|
||||||
GncTreeModelSelectionPrivate *priv;
|
|
||||||
|
|
||||||
while (model->stamp == 0)
|
|
||||||
{
|
|
||||||
model->stamp = g_random_int ();
|
|
||||||
}
|
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_SELECTION_GET_PRIVATE(model);
|
|
||||||
priv->selections = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gnc_tree_model_selection_finalize (GObject *object)
|
|
||||||
{
|
|
||||||
GncTreeModelSelection *model;
|
|
||||||
GncTreeModelSelectionPrivate *priv;
|
|
||||||
|
|
||||||
g_return_if_fail (object != NULL);
|
|
||||||
g_return_if_fail (GNC_IS_TREE_MODEL_SELECTION (object));
|
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_SELECTION (object);
|
|
||||||
priv = GNC_TREE_MODEL_SELECTION_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
g_object_unref (priv->child_model);
|
|
||||||
g_hash_table_destroy (priv->selections);
|
|
||||||
|
|
||||||
G_OBJECT_CLASS (gnc_tree_model_selection_parent_class)->finalize (object);
|
|
||||||
}
|
|
||||||
|
|
||||||
GtkTreeModel *
|
|
||||||
gnc_tree_model_selection_new (GtkTreeModel *child_model)
|
|
||||||
{
|
|
||||||
GncTreeModelSelection *model;
|
|
||||||
GncTreeModelSelectionPrivate *priv;
|
|
||||||
|
|
||||||
model = g_object_new (GNC_TYPE_TREE_MODEL_SELECTION, NULL);
|
|
||||||
priv = GNC_TREE_MODEL_SELECTION_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
priv->child_model = child_model;
|
|
||||||
g_object_ref (child_model);
|
|
||||||
g_signal_connect (G_OBJECT (child_model), "row_changed",
|
|
||||||
G_CALLBACK (gnc_tree_model_selection_row_changed), model);
|
|
||||||
g_signal_connect (G_OBJECT (child_model), "row_inserted",
|
|
||||||
G_CALLBACK (gnc_tree_model_selection_row_inserted), model);
|
|
||||||
g_signal_connect (G_OBJECT (child_model), "row_has_child_toggled",
|
|
||||||
G_CALLBACK (gnc_tree_model_selection_row_has_child_toggled), model);
|
|
||||||
g_signal_connect (G_OBJECT (child_model), "row_deleted",
|
|
||||||
G_CALLBACK (gnc_tree_model_selection_row_deleted), model);
|
|
||||||
g_signal_connect (G_OBJECT (child_model), "rows_reordered",
|
|
||||||
G_CALLBACK (gnc_tree_model_selection_rows_reordered), model);
|
|
||||||
|
|
||||||
return GTK_TREE_MODEL (model);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gnc_tree_model_selection_convert_child_iter_to_iter (GncTreeModelSelection *model,
|
|
||||||
GtkTreeIter *selection_iter,
|
|
||||||
GtkTreeIter *child_iter)
|
|
||||||
{
|
|
||||||
g_return_if_fail (GNC_IS_TREE_MODEL_SELECTION (model));
|
|
||||||
g_return_if_fail (child_iter != NULL);
|
|
||||||
g_return_if_fail (selection_iter != NULL);
|
|
||||||
|
|
||||||
selection_iter->stamp = model->stamp;
|
|
||||||
|
|
||||||
selection_iter->user_data = gtk_tree_iter_copy (child_iter);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
|
||||||
gnc_tree_model_selection_convert_iter_to_child_iter (GncTreeModelSelection *model,
|
|
||||||
GtkTreeIter *child_iter,
|
|
||||||
GtkTreeIter *selection_iter)
|
|
||||||
{
|
|
||||||
g_return_if_fail (GNC_IS_TREE_MODEL_SELECTION (model));
|
|
||||||
g_return_if_fail (selection_iter != NULL);
|
|
||||||
g_return_if_fail (GNC_TREE_MODEL_SELECTION (model)->stamp == selection_iter->stamp);
|
|
||||||
g_return_if_fail (selection_iter->user_data != NULL);
|
|
||||||
g_return_if_fail (child_iter != NULL);
|
|
||||||
|
|
||||||
child_iter->stamp = ((GtkTreeIter *) selection_iter->user_data)->stamp;
|
|
||||||
child_iter->user_data = ((GtkTreeIter *) selection_iter->user_data)->user_data;
|
|
||||||
child_iter->user_data2 = ((GtkTreeIter *) selection_iter->user_data)->user_data2;
|
|
||||||
child_iter->user_data3 = ((GtkTreeIter *) selection_iter->user_data)->user_data3;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
gnc_tree_model_selection_set_selected (GncTreeModelSelection *model,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
gboolean selected)
|
|
||||||
{
|
|
||||||
GncTreeModelSelectionPrivate *priv;
|
|
||||||
gchar *path_string;
|
|
||||||
GtkTreePath *path;
|
|
||||||
|
|
||||||
priv = GNC_TREE_MODEL_SELECTION_GET_PRIVATE(model);
|
|
||||||
path_string = gtk_tree_model_get_string_from_iter (GTK_TREE_MODEL (model), iter);
|
|
||||||
|
|
||||||
if (selected == (g_hash_table_lookup (priv->selections, path_string) != NULL))
|
|
||||||
{
|
|
||||||
g_free (path_string);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (selected)
|
|
||||||
{
|
|
||||||
g_hash_table_insert (priv->selections, g_strdup (path_string), GINT_TO_POINTER (1));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_hash_table_remove (priv->selections, path_string);
|
|
||||||
}
|
|
||||||
|
|
||||||
path = gtk_tree_path_new_from_string (path_string);
|
|
||||||
gtk_tree_model_row_changed (GTK_TREE_MODEL (model), path, iter);
|
|
||||||
gtk_tree_path_free (path);
|
|
||||||
|
|
||||||
g_free (path_string);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gnc_tree_model_selection_tree_model_init (GtkTreeModelIface *iface)
|
|
||||||
{
|
|
||||||
iface->get_flags = gnc_tree_model_selection_get_flags;
|
|
||||||
iface->get_n_columns = gnc_tree_model_selection_get_n_columns;
|
|
||||||
iface->get_column_type = gnc_tree_model_selection_get_column_type;
|
|
||||||
iface->get_iter = gnc_tree_model_selection_get_iter;
|
|
||||||
iface->get_path = gnc_tree_model_selection_get_path;
|
|
||||||
iface->get_value = gnc_tree_model_selection_get_value;
|
|
||||||
iface->iter_next = gnc_tree_model_selection_iter_next;
|
|
||||||
iface->iter_children = gnc_tree_model_selection_iter_children;
|
|
||||||
iface->iter_has_child = gnc_tree_model_selection_iter_has_child;
|
|
||||||
iface->iter_n_children = gnc_tree_model_selection_iter_n_children;
|
|
||||||
iface->iter_nth_child = gnc_tree_model_selection_iter_nth_child;
|
|
||||||
iface->iter_parent = gnc_tree_model_selection_iter_parent;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GtkTreeModelFlags
|
|
||||||
gnc_tree_model_selection_get_flags (GtkTreeModel *tree_model)
|
|
||||||
{
|
|
||||||
GncTreeModelSelection *model;
|
|
||||||
GncTreeModelSelectionPrivate *priv;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GNC_IS_TREE_MODEL_SELECTION (tree_model), 0);
|
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_SELECTION (tree_model);
|
|
||||||
priv = GNC_TREE_MODEL_SELECTION_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
return gtk_tree_model_get_flags (priv->child_model);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
gnc_tree_model_selection_get_n_columns (GtkTreeModel *tree_model)
|
|
||||||
{
|
|
||||||
GncTreeModelSelection *model;
|
|
||||||
GncTreeModelSelectionPrivate *priv;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GNC_IS_TREE_MODEL_SELECTION (tree_model), 0);
|
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_SELECTION (tree_model);
|
|
||||||
priv = GNC_TREE_MODEL_SELECTION_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
return gtk_tree_model_get_n_columns (priv->child_model) + 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GType
|
|
||||||
gnc_tree_model_selection_get_column_type (GtkTreeModel *tree_model,
|
|
||||||
int index)
|
|
||||||
{
|
|
||||||
GncTreeModelSelection *model;
|
|
||||||
GncTreeModelSelectionPrivate *priv;
|
|
||||||
gint columns = gnc_tree_model_selection_get_n_columns (tree_model);
|
|
||||||
|
|
||||||
g_return_val_if_fail (GNC_IS_TREE_MODEL_SELECTION (tree_model), G_TYPE_INVALID);
|
|
||||||
g_return_val_if_fail ((index >= 0) && (index < columns), G_TYPE_INVALID);
|
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_SELECTION (tree_model);
|
|
||||||
priv = GNC_TREE_MODEL_SELECTION_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
if (index < columns - 1)
|
|
||||||
{
|
|
||||||
return gtk_tree_model_get_column_type (priv->child_model, index);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return G_TYPE_BOOLEAN;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gnc_tree_model_selection_get_iter (GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
GtkTreePath *path)
|
|
||||||
{
|
|
||||||
GncTreeModelSelection *model;
|
|
||||||
GncTreeModelSelectionPrivate *priv;
|
|
||||||
GtkTreeIter child_iter;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GNC_IS_TREE_MODEL_SELECTION (tree_model), FALSE);
|
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_SELECTION (tree_model);
|
|
||||||
priv = GNC_TREE_MODEL_SELECTION_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
if (!gtk_tree_model_get_iter (priv->child_model, &child_iter, path))
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
gnc_tree_model_selection_convert_child_iter_to_iter (model, iter, &child_iter);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static GtkTreePath *
|
|
||||||
gnc_tree_model_selection_get_path (GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter)
|
|
||||||
{
|
|
||||||
GncTreeModelSelection *model;
|
|
||||||
GncTreeModelSelectionPrivate *priv;
|
|
||||||
GtkTreeIter child_iter;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GNC_IS_TREE_MODEL_SELECTION (tree_model), NULL);
|
|
||||||
g_return_val_if_fail (iter != NULL, NULL);
|
|
||||||
g_return_val_if_fail (iter->stamp == GNC_TREE_MODEL_SELECTION (tree_model)->stamp, NULL);
|
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_SELECTION (tree_model);
|
|
||||||
priv = GNC_TREE_MODEL_SELECTION_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
gnc_tree_model_selection_convert_iter_to_child_iter (model, &child_iter, iter);
|
|
||||||
|
|
||||||
return gtk_tree_model_get_path (priv->child_model, &child_iter);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gnc_tree_model_selection_get_value (GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
int column,
|
|
||||||
GValue *value)
|
|
||||||
{
|
|
||||||
gint columns = gnc_tree_model_selection_get_n_columns (tree_model);
|
|
||||||
GncTreeModelSelection *model;
|
|
||||||
GncTreeModelSelectionPrivate *priv;
|
|
||||||
GtkTreeIter child_iter;
|
|
||||||
gchar *path;
|
|
||||||
|
|
||||||
g_return_if_fail (GNC_IS_TREE_MODEL_SELECTION (tree_model));
|
|
||||||
g_return_if_fail ((column >= 0) && (column < columns));
|
|
||||||
g_return_if_fail (iter != NULL);
|
|
||||||
g_return_if_fail (iter->stamp == GNC_TREE_MODEL_SELECTION (tree_model)->stamp);
|
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_SELECTION (tree_model);
|
|
||||||
priv = GNC_TREE_MODEL_SELECTION_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
gnc_tree_model_selection_convert_iter_to_child_iter (model, &child_iter, iter);
|
|
||||||
|
|
||||||
if (column < columns - 1)
|
|
||||||
{
|
|
||||||
gtk_tree_model_get_value (priv->child_model, &child_iter, column, value);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_value_init (value, G_TYPE_BOOLEAN);
|
|
||||||
|
|
||||||
path = gtk_tree_model_get_string_from_iter (priv->child_model, &child_iter);
|
|
||||||
g_value_set_boolean (value, g_hash_table_lookup (priv->selections, path) != NULL);
|
|
||||||
g_free (path);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gnc_tree_model_selection_iter_next (GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter)
|
|
||||||
{
|
|
||||||
GncTreeModelSelection *model;
|
|
||||||
GncTreeModelSelectionPrivate *priv;
|
|
||||||
GtkTreeIter child_iter;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GNC_IS_TREE_MODEL_SELECTION (tree_model), FALSE);
|
|
||||||
g_return_val_if_fail (iter != NULL, FALSE);
|
|
||||||
g_return_val_if_fail (iter->stamp == GNC_TREE_MODEL_SELECTION (tree_model)->stamp, FALSE);
|
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_SELECTION (tree_model);
|
|
||||||
priv = GNC_TREE_MODEL_SELECTION_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
gnc_tree_model_selection_convert_iter_to_child_iter (model, &child_iter, iter);
|
|
||||||
|
|
||||||
if (!gtk_tree_model_iter_next (priv->child_model, &child_iter))
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gnc_tree_model_selection_convert_child_iter_to_iter (model, iter, &child_iter);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gnc_tree_model_selection_iter_children (GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
GtkTreeIter *parent)
|
|
||||||
{
|
|
||||||
GncTreeModelSelection *model;
|
|
||||||
GncTreeModelSelectionPrivate *priv;
|
|
||||||
GtkTreeIter child_iter;
|
|
||||||
GtkTreeIter child_parent;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GNC_IS_TREE_MODEL_SELECTION (tree_model), FALSE);
|
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_SELECTION (tree_model);
|
|
||||||
priv = GNC_TREE_MODEL_SELECTION_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
if (parent == NULL)
|
|
||||||
{
|
|
||||||
if (!gtk_tree_model_iter_children (priv->child_model, &child_iter, NULL))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (parent != NULL, FALSE);
|
|
||||||
g_return_val_if_fail (parent->stamp == model->stamp, FALSE);
|
|
||||||
|
|
||||||
gnc_tree_model_selection_convert_iter_to_child_iter (model, &child_parent, parent);
|
|
||||||
|
|
||||||
if (!gtk_tree_model_iter_children (priv->child_model, &child_iter, &child_parent))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
gnc_tree_model_selection_convert_child_iter_to_iter (model, iter, &child_iter);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gnc_tree_model_selection_iter_has_child (GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter)
|
|
||||||
{
|
|
||||||
GncTreeModelSelection *model;
|
|
||||||
GncTreeModelSelectionPrivate *priv;
|
|
||||||
GtkTreeIter child_iter;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GNC_IS_TREE_MODEL_SELECTION (tree_model), FALSE);
|
|
||||||
g_return_val_if_fail (iter != NULL, FALSE);
|
|
||||||
g_return_val_if_fail (iter->stamp == GNC_TREE_MODEL_SELECTION (tree_model)->stamp, FALSE);
|
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_SELECTION (tree_model);
|
|
||||||
priv = GNC_TREE_MODEL_SELECTION_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
gnc_tree_model_selection_convert_iter_to_child_iter (model, &child_iter, iter);
|
|
||||||
|
|
||||||
return gtk_tree_model_iter_has_child (priv->child_model, &child_iter);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int
|
|
||||||
gnc_tree_model_selection_iter_n_children (GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter)
|
|
||||||
{
|
|
||||||
GncTreeModelSelection *model;
|
|
||||||
GncTreeModelSelectionPrivate *priv;
|
|
||||||
GtkTreeIter child_iter;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GNC_IS_TREE_MODEL_SELECTION (tree_model), 0);
|
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_SELECTION (tree_model);
|
|
||||||
priv = GNC_TREE_MODEL_SELECTION_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
if (iter == NULL)
|
|
||||||
{
|
|
||||||
return gtk_tree_model_iter_n_children (priv->child_model, NULL);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (iter != NULL, 0);
|
|
||||||
g_return_val_if_fail (iter->stamp == model->stamp, 0);
|
|
||||||
|
|
||||||
gnc_tree_model_selection_convert_iter_to_child_iter (model, &child_iter, iter);
|
|
||||||
|
|
||||||
return gtk_tree_model_iter_n_children (priv->child_model, &child_iter);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gnc_tree_model_selection_iter_nth_child (GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
GtkTreeIter *parent,
|
|
||||||
int n)
|
|
||||||
{
|
|
||||||
GncTreeModelSelection *model;
|
|
||||||
GncTreeModelSelectionPrivate *priv;
|
|
||||||
GtkTreeIter child_iter;
|
|
||||||
GtkTreeIter child_parent;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GNC_IS_TREE_MODEL_SELECTION (tree_model), FALSE);
|
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_SELECTION (tree_model);
|
|
||||||
priv = GNC_TREE_MODEL_SELECTION_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
if (parent == NULL)
|
|
||||||
{
|
|
||||||
if (!gtk_tree_model_iter_nth_child (priv->child_model, &child_iter, NULL, n))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
g_return_val_if_fail (iter != NULL, FALSE);
|
|
||||||
g_return_val_if_fail (iter->stamp == model->stamp, FALSE);
|
|
||||||
|
|
||||||
gnc_tree_model_selection_convert_iter_to_child_iter (model, &child_parent, parent);
|
|
||||||
|
|
||||||
if (!gtk_tree_model_iter_nth_child (priv->child_model, &child_iter, &child_parent, n))
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
|
|
||||||
gnc_tree_model_selection_convert_child_iter_to_iter (model, iter, &child_iter);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
|
|
||||||
static gboolean
|
|
||||||
gnc_tree_model_selection_iter_parent (GtkTreeModel *tree_model,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
GtkTreeIter *child)
|
|
||||||
{
|
|
||||||
GncTreeModelSelection *model;
|
|
||||||
GncTreeModelSelectionPrivate *priv;
|
|
||||||
GtkTreeIter child_child;
|
|
||||||
GtkTreeIter child_iter;
|
|
||||||
|
|
||||||
g_return_val_if_fail (GNC_IS_TREE_MODEL_SELECTION (tree_model), FALSE);
|
|
||||||
g_return_val_if_fail (child != NULL, FALSE);
|
|
||||||
g_return_val_if_fail (child->stamp == GNC_TREE_MODEL_SELECTION (tree_model)->stamp, FALSE);
|
|
||||||
|
|
||||||
model = GNC_TREE_MODEL_SELECTION (tree_model);
|
|
||||||
priv = GNC_TREE_MODEL_SELECTION_GET_PRIVATE(model);
|
|
||||||
|
|
||||||
gnc_tree_model_selection_convert_iter_to_child_iter (model, &child_child, child);
|
|
||||||
|
|
||||||
if (!gtk_tree_model_iter_parent (priv->child_model, &child_iter, &child_child))
|
|
||||||
{
|
|
||||||
return FALSE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
gnc_tree_model_selection_convert_child_iter_to_iter (model, iter, &child_iter);
|
|
||||||
|
|
||||||
return TRUE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gnc_tree_model_selection_row_changed (GtkTreeModel *tree_model,
|
|
||||||
GtkTreePath *path,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
GncTreeModelSelection *selection_model)
|
|
||||||
{
|
|
||||||
GtkTreeIter selection_iter;
|
|
||||||
|
|
||||||
gnc_tree_model_selection_convert_child_iter_to_iter (selection_model, &selection_iter, iter);
|
|
||||||
|
|
||||||
gtk_tree_model_row_changed (GTK_TREE_MODEL (selection_model), path, &selection_iter);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gnc_tree_model_selection_row_inserted (GtkTreeModel *tree_model,
|
|
||||||
GtkTreePath *path,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
GncTreeModelSelection *selection_model)
|
|
||||||
{
|
|
||||||
GtkTreeIter selection_iter;
|
|
||||||
|
|
||||||
gnc_tree_model_selection_convert_child_iter_to_iter (selection_model, &selection_iter, iter);
|
|
||||||
|
|
||||||
gtk_tree_model_row_inserted (GTK_TREE_MODEL (selection_model), path, &selection_iter);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gnc_tree_model_selection_row_has_child_toggled (GtkTreeModel *tree_model,
|
|
||||||
GtkTreePath *path,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
GncTreeModelSelection *selection_model)
|
|
||||||
{
|
|
||||||
GtkTreeIter selection_iter;
|
|
||||||
|
|
||||||
gnc_tree_model_selection_convert_child_iter_to_iter (selection_model, &selection_iter, iter);
|
|
||||||
|
|
||||||
gtk_tree_model_row_has_child_toggled (GTK_TREE_MODEL (selection_model), path, &selection_iter);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gnc_tree_model_selection_row_deleted (GtkTreeModel *tree_model,
|
|
||||||
GtkTreePath *path,
|
|
||||||
GncTreeModelSelection *selection_model)
|
|
||||||
{
|
|
||||||
gtk_tree_model_row_deleted (GTK_TREE_MODEL (selection_model), path);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gnc_tree_model_selection_rows_reordered (GtkTreeModel *tree_model,
|
|
||||||
GtkTreePath *path,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
gint *new_order,
|
|
||||||
GncTreeModelSelection *selection_model)
|
|
||||||
{
|
|
||||||
GtkTreeIter selection_iter;
|
|
||||||
|
|
||||||
gnc_tree_model_selection_convert_child_iter_to_iter (selection_model, &selection_iter, iter);
|
|
||||||
|
|
||||||
gtk_tree_model_rows_reordered (GTK_TREE_MODEL (selection_model), path, &selection_iter, new_order);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void
|
|
||||||
gnc_tree_model_selection_toggled (GtkCellRendererToggle *toggle,
|
|
||||||
gchar *path,
|
|
||||||
GncTreeModelSelection *model)
|
|
||||||
{
|
|
||||||
GtkTreeIter iter;
|
|
||||||
|
|
||||||
if (gtk_tree_model_get_iter_from_string (GTK_TREE_MODEL (model), &iter, path))
|
|
||||||
{
|
|
||||||
gnc_tree_model_selection_set_selected (model, &iter, !gtk_cell_renderer_toggle_get_active (toggle));
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,82 +0,0 @@
|
|||||||
/*
|
|
||||||
* gnc-tree-model-selection.h -- GtkTreeModel which supports a
|
|
||||||
* selectable column.
|
|
||||||
*
|
|
||||||
* Copyright (C) 2003 Jan Arne Petersen
|
|
||||||
* Author: Jan Arne Petersen <jpetersen@uni-bonn.de>
|
|
||||||
*
|
|
||||||
* This program is free software; you can redistribute it and/or
|
|
||||||
* modify it under the terms of the GNU General Public License as
|
|
||||||
* published by the Free Software Foundation; either version 2 of
|
|
||||||
* the License, or (at your option) any later version.
|
|
||||||
*
|
|
||||||
* This program is distributed in the hope that it will be useful,
|
|
||||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
||||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
||||||
* GNU General Public License for more details.
|
|
||||||
*
|
|
||||||
* You should have received a copy of the GNU General Public License
|
|
||||||
* along with this program; if not, contact:
|
|
||||||
*
|
|
||||||
* Free Software Foundation Voice: +1-617-542-5942
|
|
||||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
|
|
||||||
* Boston, MA 02110-1301, USA gnu@gnu.org
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* This file creates a GtkTreeModel that extends an existing
|
|
||||||
* GtkTreeModel by a single column. This new column holds a single
|
|
||||||
* boolean value per row.
|
|
||||||
*
|
|
||||||
* GtkTreeViews allow the creation of columns in any order, not just
|
|
||||||
* the order they appear in the underlying model. The most likely use
|
|
||||||
* of this code will have the first view column mapped to this extra
|
|
||||||
* boolean model column, and the column value displayed by a checkbox.
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef __GNC_TREE_MODEL_SELECTION_H
|
|
||||||
#define __GNC_TREE_MODEL_SELECTION_H
|
|
||||||
|
|
||||||
#include <gtk/gtk.h>
|
|
||||||
|
|
||||||
G_BEGIN_DECLS
|
|
||||||
|
|
||||||
/* type macros */
|
|
||||||
#define GNC_TYPE_TREE_MODEL_SELECTION (gnc_tree_model_selection_get_type ())
|
|
||||||
#define GNC_TREE_MODEL_SELECTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_TREE_MODEL_SELECTION, GncTreeModelSelection))
|
|
||||||
#define GNC_TREE_MODEL_SELECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_TREE_MODEL_SELECTION, GncTreeModelSelectionClass))
|
|
||||||
#define GNC_IS_TREE_MODEL_SELECTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_TREE_MODEL_SELECTION))
|
|
||||||
#define GNC_IS_TREE_MODEL_SELECTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_TREE_MODEL_SELECTION))
|
|
||||||
#define GNC_TREE_MODEL_SELECTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_TREE_MODEL_SELECTION, GncTreeModelSelectionClass))
|
|
||||||
|
|
||||||
/* typedefs & structures */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GObject gobject;
|
|
||||||
int stamp;
|
|
||||||
} GncTreeModelSelection;
|
|
||||||
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GObjectClass gobject;
|
|
||||||
} GncTreeModelSelectionClass;
|
|
||||||
|
|
||||||
/* function prototypes */
|
|
||||||
GType gnc_tree_model_selection_get_type (void);
|
|
||||||
|
|
||||||
GtkTreeModel *gnc_tree_model_selection_new (GtkTreeModel *child_model);
|
|
||||||
|
|
||||||
void gnc_tree_model_selection_convert_child_iter_to_iter (GncTreeModelSelection *model,
|
|
||||||
GtkTreeIter *selection_iter,
|
|
||||||
GtkTreeIter *child_iter);
|
|
||||||
void gnc_tree_model_selection_convert_iter_to_child_iter (GncTreeModelSelection *model,
|
|
||||||
GtkTreeIter *child_iter,
|
|
||||||
GtkTreeIter *selection_iter);
|
|
||||||
|
|
||||||
void gnc_tree_model_selection_set_selected (GncTreeModelSelection *model,
|
|
||||||
GtkTreeIter *iter,
|
|
||||||
gboolean selected);
|
|
||||||
|
|
||||||
G_END_DECLS
|
|
||||||
|
|
||||||
#endif /* __GNC_TREE_MODEL_SELECTION_H */
|
|
@ -41,36 +41,17 @@ G_BEGIN_DECLS
|
|||||||
|
|
||||||
/* type macros */
|
/* type macros */
|
||||||
#define GNC_TYPE_TREE_MODEL (gnc_tree_model_get_type ())
|
#define GNC_TYPE_TREE_MODEL (gnc_tree_model_get_type ())
|
||||||
#define GNC_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GNC_TYPE_TREE_MODEL, GncTreeModel))
|
G_DECLARE_DERIVABLE_TYPE (GncTreeModel, gnc_tree_model, GNC, TREE_MODEL, GObject)
|
||||||
#define GNC_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GNC_TYPE_TREE_MODEL, GncTreeModelClass))
|
|
||||||
#define GNC_IS_TREE_MODEL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GNC_TYPE_TREE_MODEL))
|
|
||||||
#define GNC_IS_TREE_MODEL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GNC_TYPE_TREE_MODEL))
|
|
||||||
#define GNC_TREE_MODEL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GNC_TYPE_TREE_MODEL, GncTreeModelClass))
|
|
||||||
#define GNC_TREE_MODEL_NAME "GncTreeModel"
|
#define GNC_TREE_MODEL_NAME "GncTreeModel"
|
||||||
|
|
||||||
/* typedefs & structures */
|
/* typedefs & structures */
|
||||||
|
|
||||||
/** The instance data structure for a generic tree model. */
|
|
||||||
typedef struct
|
|
||||||
{
|
|
||||||
GObject g_object; /**< The parent object data. */
|
|
||||||
} GncTreeModel;
|
|
||||||
|
|
||||||
|
|
||||||
/** The class data structure for a generic tree model. */
|
/** The class data structure for a generic tree model. */
|
||||||
typedef struct
|
struct _GncTreeModelClass
|
||||||
{
|
{
|
||||||
GObjectClass g_object; /**< The parent object data. */
|
GObjectClass g_object; /**< The parent object data. */
|
||||||
} GncTreeModelClass;
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/** Get the type of a generic tree model plugin.
|
|
||||||
*
|
|
||||||
* @return A GType.
|
|
||||||
*/
|
|
||||||
GType gnc_tree_model_get_type (void);
|
|
||||||
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user