mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Refactor: remove unnecessary GncTreeModel*Private
This commit is contained in:
parent
1084071be6
commit
c87f9db9ef
@ -50,18 +50,11 @@ struct _GncTreeModelAccountTypes
|
||||
{
|
||||
GObject gobject;
|
||||
int stamp;
|
||||
|
||||
guint32 selected;
|
||||
};
|
||||
|
||||
typedef struct GncTreeModelAccountTypesPrivate
|
||||
{
|
||||
guint32 selected;
|
||||
} GncTreeModelAccountTypesPrivate;
|
||||
|
||||
#define GNC_TREE_MODEL_ACCOUNT_TYPES_GET_PRIVATE(o) \
|
||||
((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_ADD_PRIVATE(GncTreeModelAccountTypes)
|
||||
G_IMPLEMENT_INTERFACE(GTK_TYPE_TREE_MODEL,
|
||||
gnc_tree_model_account_types_tree_model_init))
|
||||
|
||||
@ -94,12 +87,8 @@ gnc_tree_model_account_types_finalize (GObject * object)
|
||||
GtkTreeModel *
|
||||
gnc_tree_model_account_types_new (guint32 selected)
|
||||
{
|
||||
GncTreeModelAccountTypes *model;
|
||||
GncTreeModelAccountTypesPrivate *priv;
|
||||
|
||||
model = g_object_new (GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES, NULL);
|
||||
priv = GNC_TREE_MODEL_ACCOUNT_TYPES_GET_PRIVATE(model);
|
||||
priv->selected = selected;
|
||||
GncTreeModelAccountTypes *model = g_object_new (GNC_TYPE_TREE_MODEL_ACCOUNT_TYPES, NULL);
|
||||
model->selected = selected;
|
||||
|
||||
return GTK_TREE_MODEL (model);
|
||||
}
|
||||
@ -413,13 +402,11 @@ gnc_tree_model_account_types_get_value (GtkTreeModel * tree_model,
|
||||
GValue * value)
|
||||
{
|
||||
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 (iter != NULL);
|
||||
g_return_if_fail (iter->stamp == model->stamp);
|
||||
|
||||
priv = GNC_TREE_MODEL_ACCOUNT_TYPES_GET_PRIVATE(model);
|
||||
switch (column)
|
||||
{
|
||||
case GNC_TREE_MODEL_ACCOUNT_TYPES_COL_TYPE:
|
||||
@ -433,7 +420,7 @@ gnc_tree_model_account_types_get_value (GtkTreeModel * tree_model,
|
||||
break;
|
||||
case GNC_TREE_MODEL_ACCOUNT_TYPES_COL_SELECTED:
|
||||
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)));
|
||||
break;
|
||||
default:
|
||||
|
@ -96,11 +96,6 @@ struct _GncTreeModelAccount
|
||||
GncTreeModel gnc_tree_model; /**< The parent object data. */
|
||||
int stamp; /**< The state of the model. Any state
|
||||
* change increments this number. */
|
||||
};
|
||||
|
||||
/** The instance private data for an account tree model. */
|
||||
typedef struct GncTreeModelAccountPrivate
|
||||
{
|
||||
QofBook *book;
|
||||
Account *root;
|
||||
gint event_handler_id;
|
||||
@ -108,18 +103,13 @@ typedef struct GncTreeModelAccountPrivate
|
||||
|
||||
GHashTable *account_values_hash;
|
||||
|
||||
} GncTreeModelAccountPrivate;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE (GncTreeModelAccount,
|
||||
gnc_tree_model_account, GNC_TYPE_TREE_MODEL,
|
||||
G_ADD_PRIVATE (GncTreeModelAccount)
|
||||
G_IMPLEMENT_INTERFACE (GTK_TYPE_TREE_MODEL,
|
||||
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 */
|
||||
/************************************************************/
|
||||
@ -134,28 +124,25 @@ G_DEFINE_TYPE_WITH_CODE (GncTreeModelAccount,
|
||||
static void
|
||||
gnc_tree_model_account_update_color (gpointer gsettings, gchar *key, gpointer user_data)
|
||||
{
|
||||
GncTreeModelAccountPrivate *priv;
|
||||
GncTreeModelAccount *model;
|
||||
gboolean use_red;
|
||||
|
||||
g_return_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(user_data));
|
||||
model = user_data;
|
||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
||||
GncTreeModelAccount *model = user_data;
|
||||
|
||||
// destroy/recreate the cached account value hash to force update
|
||||
g_hash_table_destroy (priv->account_values_hash);
|
||||
priv->account_values_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_hash_table_destroy (model->account_values_hash);
|
||||
model->account_values_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free, g_free);
|
||||
|
||||
use_red = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED);
|
||||
|
||||
if (priv->negative_color)
|
||||
g_free (priv->negative_color);
|
||||
if (model->negative_color)
|
||||
g_free (model->negative_color);
|
||||
|
||||
if (use_red)
|
||||
priv->negative_color = gnc_get_negative_color ();
|
||||
model->negative_color = gnc_get_negative_color ();
|
||||
else
|
||||
priv->negative_color = NULL;
|
||||
model->negative_color = NULL;
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
@ -177,7 +164,6 @@ gnc_tree_model_account_class_init (GncTreeModelAccountClass *klass)
|
||||
static void
|
||||
gnc_tree_model_account_init (GncTreeModelAccount *model)
|
||||
{
|
||||
GncTreeModelAccountPrivate *priv;
|
||||
gboolean use_red;
|
||||
|
||||
ENTER("model %p", model);
|
||||
@ -188,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);
|
||||
|
||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
||||
priv->book = NULL;
|
||||
priv->root = NULL;
|
||||
model->book = NULL;
|
||||
model->root = NULL;
|
||||
|
||||
if (priv->negative_color)
|
||||
g_free (priv->negative_color);
|
||||
if (model->negative_color)
|
||||
g_free (model->negative_color);
|
||||
|
||||
if (use_red)
|
||||
priv->negative_color = gnc_get_negative_color ();
|
||||
model->negative_color = gnc_get_negative_color ();
|
||||
else
|
||||
priv->negative_color = NULL;
|
||||
model->negative_color = NULL;
|
||||
|
||||
// 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);
|
||||
|
||||
gnc_prefs_register_cb (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED,
|
||||
@ -214,7 +199,6 @@ gnc_tree_model_account_init (GncTreeModelAccount *model)
|
||||
static void
|
||||
gnc_tree_model_account_finalize (GObject *object)
|
||||
{
|
||||
GncTreeModelAccountPrivate *priv;
|
||||
GncTreeModelAccount *model;
|
||||
|
||||
g_return_if_fail (object != NULL);
|
||||
@ -223,9 +207,8 @@ gnc_tree_model_account_finalize (GObject *object)
|
||||
ENTER("model %p", 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);
|
||||
LEAVE(" ");
|
||||
@ -234,7 +217,6 @@ gnc_tree_model_account_finalize (GObject *object)
|
||||
static void
|
||||
gnc_tree_model_account_dispose (GObject *object)
|
||||
{
|
||||
GncTreeModelAccountPrivate *priv;
|
||||
GncTreeModelAccount *model;
|
||||
|
||||
g_return_if_fail (object != NULL);
|
||||
@ -243,19 +225,18 @@ gnc_tree_model_account_dispose (GObject *object)
|
||||
ENTER("model %p", 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);
|
||||
priv->event_handler_id = 0;
|
||||
qof_event_unregister_handler (model->event_handler_id);
|
||||
model->event_handler_id = 0;
|
||||
}
|
||||
|
||||
if (priv->negative_color)
|
||||
g_free (priv->negative_color);
|
||||
if (model->negative_color)
|
||||
g_free (model->negative_color);
|
||||
|
||||
// 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_tree_model_account_update_color,
|
||||
@ -274,7 +255,6 @@ GtkTreeModel *
|
||||
gnc_tree_model_account_new (Account *root)
|
||||
{
|
||||
GncTreeModelAccount *model;
|
||||
GncTreeModelAccountPrivate *priv;
|
||||
const GList *item;
|
||||
|
||||
ENTER("root %p", root);
|
||||
@ -282,8 +262,7 @@ gnc_tree_model_account_new (Account *root)
|
||||
for ( ; item; item = g_list_next (item))
|
||||
{
|
||||
model = (GncTreeModelAccount *)item->data;
|
||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
||||
if (priv->root == root)
|
||||
if (model->root == root)
|
||||
{
|
||||
g_object_ref (G_OBJECT(model));
|
||||
LEAVE("returning existing model %p", model);
|
||||
@ -293,11 +272,10 @@ gnc_tree_model_account_new (Account *root)
|
||||
|
||||
model = g_object_new (GNC_TYPE_TREE_MODEL_ACCOUNT, NULL);
|
||||
|
||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
||||
priv->book = gnc_get_current_book();
|
||||
priv->root = root;
|
||||
model->book = gnc_get_current_book();
|
||||
model->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);
|
||||
|
||||
LEAVE("model %p", model);
|
||||
@ -437,7 +415,6 @@ gnc_tree_model_account_get_iter (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter,
|
||||
GtkTreePath *path)
|
||||
{
|
||||
GncTreeModelAccountPrivate *priv;
|
||||
GncTreeModelAccount *model;
|
||||
Account *account, *parent;
|
||||
gint i, *indices;
|
||||
@ -451,7 +428,6 @@ gnc_tree_model_account_get_iter (GtkTreeModel *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)
|
||||
{
|
||||
@ -467,7 +443,7 @@ gnc_tree_model_account_get_iter (GtkTreeModel *tree_model,
|
||||
}
|
||||
|
||||
parent = NULL;
|
||||
account = priv->root;
|
||||
account = model->root;
|
||||
for (i = 1; i < gtk_tree_path_get_depth (path); i++)
|
||||
{
|
||||
parent = account;
|
||||
@ -494,7 +470,6 @@ gnc_tree_model_account_get_path (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GncTreeModelAccount *model = GNC_TREE_MODEL_ACCOUNT(tree_model);
|
||||
GncTreeModelAccountPrivate *priv;
|
||||
Account *account, *parent;
|
||||
GtkTreePath *path;
|
||||
gint i;
|
||||
@ -506,8 +481,7 @@ gnc_tree_model_account_get_path (GtkTreeModel *tree_model,
|
||||
|
||||
ENTER("model %p, iter %s", model, iter_to_string (iter));
|
||||
|
||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
||||
if (priv->root == NULL)
|
||||
if (model->root == NULL)
|
||||
{
|
||||
LEAVE("failed (1)");
|
||||
return NULL;
|
||||
@ -547,11 +521,8 @@ gnc_tree_model_account_set_color (GncTreeModelAccount *model,
|
||||
gboolean negative,
|
||||
GValue *value)
|
||||
{
|
||||
GncTreeModelAccountPrivate *priv;
|
||||
|
||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
||||
if (negative)
|
||||
g_value_set_static_string (value, priv->negative_color);
|
||||
g_value_set_static_string (value, model->negative_color);
|
||||
else
|
||||
g_value_set_static_string (value, NULL);
|
||||
}
|
||||
@ -562,7 +533,6 @@ gnc_tree_model_account_compute_period_balance (GncTreeModelAccount *model,
|
||||
gboolean recurse,
|
||||
gboolean *negative)
|
||||
{
|
||||
GncTreeModelAccountPrivate *priv;
|
||||
GNCPrintAmountInfo print_info;
|
||||
time64 t1, t2;
|
||||
gnc_numeric b3;
|
||||
@ -570,8 +540,7 @@ gnc_tree_model_account_compute_period_balance (GncTreeModelAccount *model,
|
||||
if (negative)
|
||||
*negative = FALSE;
|
||||
|
||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
||||
if (acct == priv->root)
|
||||
if (acct == model->root)
|
||||
return g_strdup ("");
|
||||
|
||||
t1 = gnc_accounting_period_fiscal_start ();
|
||||
@ -605,11 +574,9 @@ gnc_tree_model_account_clear_cache (GncTreeModelAccount *model)
|
||||
{
|
||||
if (model)
|
||||
{
|
||||
GncTreeModelAccountPrivate *priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
||||
|
||||
// destroy the cached account values and recreate
|
||||
g_hash_table_destroy (priv->account_values_hash);
|
||||
priv->account_values_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_hash_table_destroy (model->account_values_hash);
|
||||
model->account_values_hash = g_hash_table_new_full (g_str_hash, g_str_equal,
|
||||
g_free, g_free);
|
||||
|
||||
gtk_tree_model_foreach (GTK_TREE_MODEL(model), row_changed_foreach_func, NULL);
|
||||
@ -649,20 +616,19 @@ clear_account_cached_values (GncTreeModelAccount *model, GHashTable *hash, Accou
|
||||
static void
|
||||
gnc_tree_model_account_clear_cached_values (GncTreeModelAccount *model, Account *account)
|
||||
{
|
||||
GncTreeModelAccountPrivate *priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
||||
Account *parent;
|
||||
|
||||
// no hash table or account, return
|
||||
if ((!priv->account_values_hash) || (!account))
|
||||
if ((!model->account_values_hash) || (!account))
|
||||
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);
|
||||
|
||||
// clear also all parent accounts, this will update any balances/totals
|
||||
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);
|
||||
}
|
||||
}
|
||||
@ -671,19 +637,18 @@ static gboolean
|
||||
gnc_tree_model_account_get_cached_value (GncTreeModelAccount *model, Account *account,
|
||||
gint column, gchar **cached_string)
|
||||
{
|
||||
GncTreeModelAccountPrivate *priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
||||
gchar acct_guid_str[GUID_ENCODING_LENGTH + 1];
|
||||
gchar *key = NULL;
|
||||
gpointer value;
|
||||
gboolean found;
|
||||
|
||||
if ((!priv->account_values_hash) || (!account))
|
||||
if ((!model->account_values_hash) || (!account))
|
||||
return FALSE;
|
||||
|
||||
guid_to_string_buff (xaccAccountGetGUID (account), acct_guid_str);
|
||||
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);
|
||||
|
||||
if (found)
|
||||
@ -698,9 +663,7 @@ static void
|
||||
gnc_tree_model_account_set_cached_value (GncTreeModelAccount *model, Account *account,
|
||||
gint column, GValue *value)
|
||||
{
|
||||
GncTreeModelAccountPrivate *priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
||||
|
||||
if ((!priv->account_values_hash) || (!account))
|
||||
if ((!model->account_values_hash) || (!account))
|
||||
return;
|
||||
|
||||
// only interested in string values
|
||||
@ -713,7 +676,7 @@ gnc_tree_model_account_set_cached_value (GncTreeModelAccount *model, Account *ac
|
||||
guid_to_string_buff (xaccAccountGetGUID (account), acct_guid_str);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
@ -724,7 +687,6 @@ gnc_tree_model_account_get_value (GtkTreeModel *tree_model,
|
||||
GValue *value)
|
||||
{
|
||||
GncTreeModelAccount *model = GNC_TREE_MODEL_ACCOUNT(tree_model);
|
||||
GncTreeModelAccountPrivate *priv;
|
||||
Account *account;
|
||||
gboolean negative; /* used to set "deficit style" also known as red numbers */
|
||||
gchar *string;
|
||||
@ -741,7 +703,6 @@ gnc_tree_model_account_get_value (GtkTreeModel *tree_model,
|
||||
iter_to_string (iter), column);
|
||||
|
||||
account = (Account *) iter->user_data;
|
||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
||||
|
||||
// lets see if the value is in the cache
|
||||
if (gnc_tree_model_account_get_cached_value (model, account, column, &cached_string))
|
||||
@ -756,7 +717,7 @@ gnc_tree_model_account_get_value (GtkTreeModel *tree_model,
|
||||
{
|
||||
case GNC_TREE_MODEL_ACCOUNT_COL_NAME:
|
||||
g_value_init (value, G_TYPE_STRING);
|
||||
if (account == priv->root)
|
||||
if (account == model->root)
|
||||
g_value_set_string (value, _("New top level account"));
|
||||
else
|
||||
g_value_set_string (value, xaccAccountGetName (account));
|
||||
@ -1037,7 +998,6 @@ gnc_tree_model_account_iter_children (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter,
|
||||
GtkTreeIter *parent_iter)
|
||||
{
|
||||
GncTreeModelAccountPrivate *priv;
|
||||
GncTreeModelAccount *model;
|
||||
Account *account, *parent;
|
||||
|
||||
@ -1046,9 +1006,8 @@ gnc_tree_model_account_iter_children (GtkTreeModel *tree_model,
|
||||
tree_model, iter, (parent_iter ? iter_to_string (parent_iter) : "(null)"));
|
||||
|
||||
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;
|
||||
LEAVE("failed (no root)");
|
||||
@ -1058,7 +1017,7 @@ gnc_tree_model_account_iter_children (GtkTreeModel *tree_model,
|
||||
/* Special case when no parent supplied. */
|
||||
if (!parent_iter)
|
||||
{
|
||||
iter->user_data = priv->root;
|
||||
iter->user_data = model->root;
|
||||
iter->user_data2 = NULL;
|
||||
iter->user_data3 = GINT_TO_POINTER(0);
|
||||
iter->stamp = model->stamp;
|
||||
@ -1152,7 +1111,6 @@ gnc_tree_model_account_iter_nth_child (GtkTreeModel *tree_model,
|
||||
int n)
|
||||
{
|
||||
GncTreeModelAccount *model;
|
||||
GncTreeModelAccountPrivate *priv;
|
||||
Account *account, *parent;
|
||||
|
||||
if (parent_iter)
|
||||
@ -1172,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);
|
||||
|
||||
model = GNC_TREE_MODEL_ACCOUNT(tree_model);
|
||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
||||
|
||||
/* Special case when no parent supplied. */
|
||||
if (!parent_iter)
|
||||
@ -1183,7 +1140,7 @@ gnc_tree_model_account_iter_nth_child (GtkTreeModel *tree_model,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
iter->user_data = priv->root;
|
||||
iter->user_data = model->root;
|
||||
iter->user_data2 = NULL;
|
||||
iter->user_data3 = GINT_TO_POINTER(0);
|
||||
iter->stamp = model->stamp;
|
||||
@ -1302,7 +1259,6 @@ gnc_tree_model_account_get_iter_from_account (GncTreeModelAccount *model,
|
||||
Account *account,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GncTreeModelAccountPrivate *priv;
|
||||
Account *parent;
|
||||
gint i;
|
||||
|
||||
@ -1314,8 +1270,7 @@ gnc_tree_model_account_get_iter_from_account (GncTreeModelAccount *model,
|
||||
iter->user_data = account;
|
||||
iter->stamp = model->stamp;
|
||||
|
||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
||||
if (account == priv->root)
|
||||
if (account == model->root)
|
||||
{
|
||||
iter->user_data2 = NULL;
|
||||
iter->user_data3 = GINT_TO_POINTER(0);
|
||||
@ -1323,7 +1278,7 @@ gnc_tree_model_account_get_iter_from_account (GncTreeModelAccount *model,
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (priv->root != gnc_account_get_root (account))
|
||||
if (model->root != gnc_account_get_root (account))
|
||||
{
|
||||
LEAVE("Root doesn't match");
|
||||
return FALSE;
|
||||
@ -1448,7 +1403,6 @@ gnc_tree_model_account_event_handler (QofInstance *entity,
|
||||
GncTreeModelAccount *model,
|
||||
GncEventData *ed)
|
||||
{
|
||||
GncTreeModelAccountPrivate *priv;
|
||||
const gchar *parent_name;
|
||||
GtkTreePath *path = NULL;
|
||||
GtkTreeIter iter;
|
||||
@ -1461,16 +1415,15 @@ gnc_tree_model_account_event_handler (QofInstance *entity,
|
||||
|
||||
ENTER("entity %p of type %d, model %p, event_data %p",
|
||||
entity, event_type, model, ed);
|
||||
priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model);
|
||||
|
||||
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");
|
||||
return;
|
||||
}
|
||||
if (gnc_account_get_root (account) != priv->root)
|
||||
if (gnc_account_get_root (account) != model->root)
|
||||
{
|
||||
LEAVE("not in this model");
|
||||
return;
|
||||
@ -1505,7 +1458,7 @@ gnc_tree_model_account_event_handler (QofInstance *entity,
|
||||
case QOF_EVENT_REMOVE:
|
||||
if (!ed) /* Required for a remove. */
|
||||
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";
|
||||
DEBUG("remove child %d of account %p (%s)", ed->idx, parent, parent_name);
|
||||
path = gnc_tree_model_account_get_path_from_account (model, parent);
|
||||
|
@ -97,21 +97,13 @@ struct _GncTreeModelCommodity
|
||||
GncTreeModel gnc_tree_model; /**< The parent object data. */
|
||||
int stamp; /**< The state of the model. Any state
|
||||
* change increments this number. */
|
||||
};
|
||||
|
||||
/** The instance private data for a commodity database tree model. */
|
||||
typedef struct GncTreeModelCommodityPrivate
|
||||
{
|
||||
QofBook *book;
|
||||
gnc_commodity_table *commodity_table;
|
||||
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_ADD_PRIVATE(GncTreeModelCommodity)
|
||||
G_IMPLEMENT_INTERFACE(GTK_TYPE_TREE_MODEL,
|
||||
gnc_tree_model_commodity_tree_model_init))
|
||||
|
||||
@ -137,7 +129,6 @@ static void
|
||||
gnc_tree_model_commodity_finalize (GObject *object)
|
||||
{
|
||||
GncTreeModelCommodity *model;
|
||||
GncTreeModelCommodityPrivate *priv;
|
||||
|
||||
g_return_if_fail (object != NULL);
|
||||
g_return_if_fail (GNC_IS_TREE_MODEL_COMMODITY (object));
|
||||
@ -145,9 +136,8 @@ gnc_tree_model_commodity_finalize (GObject *object)
|
||||
ENTER("model %p", object);
|
||||
|
||||
model = GNC_TREE_MODEL_COMMODITY (object);
|
||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
||||
priv->book = NULL;
|
||||
priv->commodity_table = NULL;
|
||||
model->book = NULL;
|
||||
model->commodity_table = NULL;
|
||||
|
||||
G_OBJECT_CLASS (gnc_tree_model_commodity_parent_class)->finalize (object);
|
||||
LEAVE(" ");
|
||||
@ -157,19 +147,17 @@ static void
|
||||
gnc_tree_model_commodity_dispose (GObject *object)
|
||||
{
|
||||
GncTreeModelCommodity *model;
|
||||
GncTreeModelCommodityPrivate *priv;
|
||||
|
||||
g_return_if_fail (object != NULL);
|
||||
g_return_if_fail (GNC_IS_TREE_MODEL_COMMODITY (object));
|
||||
|
||||
ENTER("model %p", 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);
|
||||
priv->event_handler_id = 0;
|
||||
qof_event_unregister_handler (model->event_handler_id);
|
||||
model->event_handler_id = 0;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (gnc_tree_model_commodity_parent_class)->dispose (object);
|
||||
@ -180,7 +168,6 @@ GtkTreeModel *
|
||||
gnc_tree_model_commodity_new (QofBook *book, gnc_commodity_table *ct)
|
||||
{
|
||||
GncTreeModelCommodity *model;
|
||||
GncTreeModelCommodityPrivate *priv;
|
||||
const GList *item;
|
||||
|
||||
ENTER("");
|
||||
@ -189,8 +176,7 @@ gnc_tree_model_commodity_new (QofBook *book, gnc_commodity_table *ct)
|
||||
for ( ; item; item = g_list_next(item))
|
||||
{
|
||||
model = (GncTreeModelCommodity *)item->data;
|
||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
||||
if (priv->commodity_table == ct)
|
||||
if (model->commodity_table == ct)
|
||||
{
|
||||
g_object_ref(G_OBJECT(model));
|
||||
LEAVE("returning existing model %p", model);
|
||||
@ -199,11 +185,10 @@ gnc_tree_model_commodity_new (QofBook *book, gnc_commodity_table *ct)
|
||||
}
|
||||
|
||||
model = g_object_new (GNC_TYPE_TREE_MODEL_COMMODITY, NULL);
|
||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
||||
priv->book = book;
|
||||
priv->commodity_table = ct;
|
||||
model->book = book;
|
||||
model->commodity_table = ct;
|
||||
|
||||
priv->event_handler_id =
|
||||
model->event_handler_id =
|
||||
qof_event_register_handler (gnc_tree_model_commodity_event_handler, model);
|
||||
|
||||
LEAVE("");
|
||||
@ -397,7 +382,6 @@ gnc_tree_model_commodity_get_iter (GtkTreeModel *tree_model,
|
||||
GtkTreePath *path)
|
||||
{
|
||||
GncTreeModelCommodity *model;
|
||||
GncTreeModelCommodityPrivate *priv;
|
||||
gnc_commodity_table *ct;
|
||||
gnc_commodity_namespace *name_space;
|
||||
gnc_commodity *commodity = NULL;
|
||||
@ -427,8 +411,7 @@ gnc_tree_model_commodity_get_iter (GtkTreeModel *tree_model,
|
||||
|
||||
/* Make sure the model has a commodity db. */
|
||||
model = GNC_TREE_MODEL_COMMODITY (tree_model);
|
||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
||||
ct = priv->commodity_table;
|
||||
ct = model->commodity_table;
|
||||
if (ct == NULL)
|
||||
{
|
||||
LEAVE("no commodity table");
|
||||
@ -480,7 +463,6 @@ gnc_tree_model_commodity_get_path (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GncTreeModelCommodity *model;
|
||||
GncTreeModelCommodityPrivate *priv;
|
||||
GtkTreePath *path;
|
||||
gnc_commodity_table *ct;
|
||||
gnc_commodity_namespace *name_space;
|
||||
@ -495,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));
|
||||
|
||||
/* Make sure this model has a commodity db. */
|
||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
||||
ct = priv->commodity_table;
|
||||
ct = model->commodity_table;
|
||||
if (ct == NULL)
|
||||
{
|
||||
LEAVE("no commodity table");
|
||||
@ -659,7 +640,6 @@ gnc_tree_model_commodity_iter_next (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GncTreeModelCommodity *model;
|
||||
GncTreeModelCommodityPrivate *priv;
|
||||
gnc_commodity_table *ct;
|
||||
gnc_commodity_namespace *name_space;
|
||||
GList *list;
|
||||
@ -673,10 +653,9 @@ gnc_tree_model_commodity_iter_next (GtkTreeModel *tree_model,
|
||||
g_return_val_if_fail (iter->stamp == model->stamp, FALSE);
|
||||
|
||||
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)
|
||||
{
|
||||
ct = priv->commodity_table;
|
||||
ct = model->commodity_table;
|
||||
list = gnc_commodity_table_get_namespaces_list(ct);
|
||||
}
|
||||
else if (iter->user_data == ITER_IS_COMMODITY)
|
||||
@ -709,7 +688,6 @@ gnc_tree_model_commodity_iter_children (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *parent)
|
||||
{
|
||||
GncTreeModelCommodity *model;
|
||||
GncTreeModelCommodityPrivate *priv;
|
||||
gnc_commodity_table *ct;
|
||||
gnc_commodity_namespace *name_space;
|
||||
GList *list;
|
||||
@ -719,11 +697,10 @@ gnc_tree_model_commodity_iter_children (GtkTreeModel *tree_model,
|
||||
ENTER("model %p, iter %p, parent %p (%s)",
|
||||
tree_model, iter, parent, iter_to_string(parent));
|
||||
model = GNC_TREE_MODEL_COMMODITY (tree_model);
|
||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
||||
|
||||
if (parent == NULL)
|
||||
{
|
||||
ct = priv->commodity_table;
|
||||
ct = model->commodity_table;
|
||||
list = gnc_commodity_table_get_namespaces_list(ct);
|
||||
if (list == NULL)
|
||||
{
|
||||
@ -789,7 +766,6 @@ gnc_tree_model_commodity_iter_n_children (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GncTreeModelCommodity *model;
|
||||
GncTreeModelCommodityPrivate *priv;
|
||||
gnc_commodity_table *ct;
|
||||
gnc_commodity_namespace *name_space;
|
||||
GList *list;
|
||||
@ -798,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));
|
||||
model = GNC_TREE_MODEL_COMMODITY (tree_model);
|
||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
||||
|
||||
if (iter == NULL)
|
||||
{
|
||||
ct = priv->commodity_table;
|
||||
ct = model->commodity_table;
|
||||
list = gnc_commodity_table_get_namespaces_list(ct);
|
||||
LEAVE("ns list length %d", g_list_length(list));
|
||||
return g_list_length (list);
|
||||
@ -827,7 +802,6 @@ gnc_tree_model_commodity_iter_nth_child (GtkTreeModel *tree_model,
|
||||
int n)
|
||||
{
|
||||
GncTreeModelCommodity *model;
|
||||
GncTreeModelCommodityPrivate *priv;
|
||||
gnc_commodity_table *ct;
|
||||
gnc_commodity_namespace *name_space;
|
||||
GList *list;
|
||||
@ -838,11 +812,10 @@ gnc_tree_model_commodity_iter_nth_child (GtkTreeModel *tree_model,
|
||||
ENTER("model %p, iter %p, parent %p (%s)",
|
||||
tree_model, iter, parent, iter_to_string(parent));
|
||||
model = GNC_TREE_MODEL_COMMODITY (tree_model);
|
||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
||||
|
||||
if (parent == NULL)
|
||||
{
|
||||
ct = priv->commodity_table;
|
||||
ct = model->commodity_table;
|
||||
list = gnc_commodity_table_get_namespaces_list(ct);
|
||||
|
||||
iter->stamp = model->stamp;
|
||||
@ -877,7 +850,6 @@ gnc_tree_model_commodity_iter_parent (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *child)
|
||||
{
|
||||
GncTreeModelCommodity *model;
|
||||
GncTreeModelCommodityPrivate *priv;
|
||||
gnc_commodity_table *ct;
|
||||
gnc_commodity_namespace *name_space;
|
||||
GList *list;
|
||||
@ -889,7 +861,6 @@ gnc_tree_model_commodity_iter_parent (GtkTreeModel *tree_model,
|
||||
ENTER("model %p, iter %p, child %p (%s)",
|
||||
tree_model, iter, child, iter_to_string(child));
|
||||
model = GNC_TREE_MODEL_COMMODITY (tree_model);
|
||||
priv = GNC_TREE_MODEL_COMMODITY_GET_PRIVATE(model);
|
||||
|
||||
if (child->user_data == ITER_IS_NAMESPACE)
|
||||
{
|
||||
@ -897,7 +868,7 @@ gnc_tree_model_commodity_iter_parent (GtkTreeModel *tree_model,
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
ct = priv->commodity_table;
|
||||
ct = model->commodity_table;
|
||||
list = gnc_commodity_table_get_namespaces_list(ct);
|
||||
name_space = gnc_commodity_get_namespace_ds((gnc_commodity*)child->user_data2);
|
||||
|
||||
@ -1008,7 +979,6 @@ gnc_tree_model_commodity_get_iter_from_namespace (GncTreeModelCommodity *model,
|
||||
gnc_commodity_namespace *name_space,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GncTreeModelCommodityPrivate *priv;
|
||||
GList *list;
|
||||
gint n;
|
||||
|
||||
@ -1018,8 +988,7 @@ gnc_tree_model_commodity_get_iter_from_namespace (GncTreeModelCommodity *model,
|
||||
|
||||
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(priv->commodity_table);
|
||||
list = gnc_commodity_table_get_namespaces_list(model->commodity_table);
|
||||
if (list == NULL)
|
||||
{
|
||||
LEAVE("");
|
||||
|
@ -92,28 +92,19 @@ struct _GncTreeModelOwner
|
||||
GncTreeModel gnc_tree_model; /**< The parent object data. */
|
||||
int stamp; /**< The state of the model. Any state
|
||||
* change increments this number. */
|
||||
};
|
||||
|
||||
/** The instance private data for an owner tree model. */
|
||||
typedef struct GncTreeModelOwnerPrivate
|
||||
{
|
||||
QofBook *book;
|
||||
GncOwnerType owner_type;
|
||||
OwnerList *owner_list;
|
||||
gint event_handler_id;
|
||||
const gchar *negative_color;
|
||||
} GncTreeModelOwnerPrivate;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE_WITH_CODE(GncTreeModelOwner, gnc_tree_model_owner,
|
||||
GNC_TYPE_TREE_MODEL,
|
||||
G_ADD_PRIVATE(GncTreeModelOwner)
|
||||
G_IMPLEMENT_INTERFACE(GTK_TYPE_TREE_MODEL,
|
||||
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 */
|
||||
/************************************************************/
|
||||
@ -127,15 +118,13 @@ G_DEFINE_TYPE_WITH_CODE(GncTreeModelOwner, gnc_tree_model_owner,
|
||||
static void
|
||||
gnc_tree_model_owner_update_color (gpointer gsettings, gchar *key, gpointer user_data)
|
||||
{
|
||||
GncTreeModelOwnerPrivate *priv;
|
||||
GncTreeModelOwner *model;
|
||||
gboolean use_red;
|
||||
|
||||
g_return_if_fail(GNC_IS_TREE_MODEL_OWNER(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);
|
||||
priv->negative_color = use_red ? "red" : NULL;
|
||||
model->negative_color = use_red ? "red" : NULL;
|
||||
}
|
||||
/************************************************************/
|
||||
/* g_object required functions */
|
||||
@ -156,7 +145,6 @@ gnc_tree_model_owner_class_init (GncTreeModelOwnerClass *klass)
|
||||
static void
|
||||
gnc_tree_model_owner_init (GncTreeModelOwner *model)
|
||||
{
|
||||
GncTreeModelOwnerPrivate *priv;
|
||||
gboolean red;
|
||||
|
||||
ENTER("model %p", model);
|
||||
@ -167,11 +155,10 @@ gnc_tree_model_owner_init (GncTreeModelOwner *model)
|
||||
|
||||
red = gnc_prefs_get_bool(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED);
|
||||
|
||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
||||
priv->book = NULL;
|
||||
priv->owner_list = NULL;
|
||||
priv->owner_type = GNC_OWNER_NONE;
|
||||
priv->negative_color = red ? "red" : NULL;
|
||||
model->book = NULL;
|
||||
model->owner_list = NULL;
|
||||
model->owner_type = GNC_OWNER_NONE;
|
||||
model->negative_color = red ? "red" : NULL;
|
||||
|
||||
gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED,
|
||||
gnc_tree_model_owner_update_color,
|
||||
@ -183,7 +170,6 @@ gnc_tree_model_owner_init (GncTreeModelOwner *model)
|
||||
static void
|
||||
gnc_tree_model_owner_finalize (GObject *object)
|
||||
{
|
||||
GncTreeModelOwnerPrivate *priv;
|
||||
GncTreeModelOwner *model;
|
||||
|
||||
g_return_if_fail (object != NULL);
|
||||
@ -192,13 +178,12 @@ gnc_tree_model_owner_finalize (GObject *object)
|
||||
ENTER("model %p", object);
|
||||
|
||||
model = GNC_TREE_MODEL_OWNER (object);
|
||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
||||
|
||||
if (priv->owner_list)
|
||||
g_list_free_full (priv->owner_list, (GDestroyNotify) gncOwnerFree);
|
||||
if (model->owner_list)
|
||||
g_list_free_full (model->owner_list, (GDestroyNotify) gncOwnerFree);
|
||||
|
||||
priv->book = NULL;
|
||||
priv->owner_list = NULL;
|
||||
model->book = NULL;
|
||||
model->owner_list = NULL;
|
||||
|
||||
G_OBJECT_CLASS(gnc_tree_model_owner_parent_class)->finalize (object);
|
||||
LEAVE(" ");
|
||||
@ -207,7 +192,6 @@ gnc_tree_model_owner_finalize (GObject *object)
|
||||
static void
|
||||
gnc_tree_model_owner_dispose (GObject *object)
|
||||
{
|
||||
GncTreeModelOwnerPrivate *priv;
|
||||
GncTreeModelOwner *model;
|
||||
|
||||
g_return_if_fail (object != NULL);
|
||||
@ -216,12 +200,11 @@ gnc_tree_model_owner_dispose (GObject *object)
|
||||
ENTER("model %p", 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);
|
||||
priv->event_handler_id = 0;
|
||||
qof_event_unregister_handler (model->event_handler_id);
|
||||
model->event_handler_id = 0;
|
||||
}
|
||||
|
||||
gnc_prefs_remove_cb_by_func(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED,
|
||||
@ -241,7 +224,6 @@ GtkTreeModel *
|
||||
gnc_tree_model_owner_new (GncOwnerType owner_type)
|
||||
{
|
||||
GncTreeModelOwner *model;
|
||||
GncTreeModelOwnerPrivate *priv;
|
||||
const GList *item;
|
||||
|
||||
ENTER("owner_type %d", owner_type);
|
||||
@ -249,8 +231,7 @@ gnc_tree_model_owner_new (GncOwnerType owner_type)
|
||||
for ( ; item; item = g_list_next(item))
|
||||
{
|
||||
model = (GncTreeModelOwner *)item->data;
|
||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
||||
if (priv->owner_type == owner_type)
|
||||
if (model->owner_type == owner_type)
|
||||
{
|
||||
g_object_ref(G_OBJECT(model));
|
||||
LEAVE("returning existing model %p", model);
|
||||
@ -261,12 +242,11 @@ gnc_tree_model_owner_new (GncOwnerType owner_type)
|
||||
model = g_object_new (GNC_TYPE_TREE_MODEL_OWNER,
|
||||
NULL);
|
||||
|
||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
||||
priv->book = gnc_get_current_book();
|
||||
priv->owner_type = owner_type;
|
||||
priv->owner_list = gncBusinessGetOwnerList (priv->book, gncOwnerTypeToQofIdType(owner_type), TRUE);
|
||||
model->book = gnc_get_current_book();
|
||||
model->owner_type = owner_type;
|
||||
model->owner_list = gncBusinessGetOwnerList (model->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);
|
||||
|
||||
LEAVE("model %p", model);
|
||||
@ -386,7 +366,6 @@ gnc_tree_model_owner_get_iter (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter,
|
||||
GtkTreePath *path)
|
||||
{
|
||||
GncTreeModelOwnerPrivate *priv;
|
||||
GncTreeModelOwner *model;
|
||||
GncOwner *owner;
|
||||
gint *indices;
|
||||
@ -400,7 +379,6 @@ gnc_tree_model_owner_get_iter (GtkTreeModel *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 */
|
||||
if (gtk_tree_path_get_depth (path) != 1)
|
||||
@ -411,7 +389,7 @@ gnc_tree_model_owner_get_iter (GtkTreeModel *tree_model,
|
||||
|
||||
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)
|
||||
{
|
||||
iter->stamp = 0;
|
||||
@ -433,7 +411,6 @@ gnc_tree_model_owner_get_path (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GncTreeModelOwner *model = GNC_TREE_MODEL_OWNER (tree_model);
|
||||
GncTreeModelOwnerPrivate *priv;
|
||||
GncOwner *owner;
|
||||
GtkTreePath *path;
|
||||
gint i;
|
||||
@ -445,8 +422,7 @@ gnc_tree_model_owner_get_path (GtkTreeModel *tree_model,
|
||||
|
||||
ENTER("model %p, iter %s", model, iter_to_string(iter));
|
||||
|
||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
||||
if (priv->owner_list == NULL)
|
||||
if (model->owner_list == NULL)
|
||||
{
|
||||
LEAVE("failed (1)");
|
||||
return NULL;
|
||||
@ -455,7 +431,7 @@ gnc_tree_model_owner_get_path (GtkTreeModel *tree_model,
|
||||
owner = (GncOwner *) iter->user_data;
|
||||
|
||||
path = gtk_tree_path_new ();
|
||||
i = g_list_index (priv->owner_list, owner);
|
||||
i = g_list_index (model->owner_list, owner);
|
||||
if (i == -1)
|
||||
{
|
||||
gtk_tree_path_free (path);
|
||||
@ -477,11 +453,8 @@ gnc_tree_model_owner_set_color(GncTreeModelOwner *model,
|
||||
gboolean negative,
|
||||
GValue *value)
|
||||
{
|
||||
GncTreeModelOwnerPrivate *priv;
|
||||
|
||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
||||
if (negative)
|
||||
g_value_set_static_string (value, priv->negative_color);
|
||||
g_value_set_static_string (value, model->negative_color);
|
||||
else
|
||||
g_value_set_static_string (value, NULL);
|
||||
}
|
||||
@ -646,7 +619,6 @@ gnc_tree_model_owner_iter_next (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GncTreeModelOwner *model = GNC_TREE_MODEL_OWNER (tree_model);
|
||||
GncTreeModelOwnerPrivate *priv;
|
||||
GncOwner *owner;
|
||||
gint i;
|
||||
|
||||
@ -657,11 +629,9 @@ gnc_tree_model_owner_iter_next (GtkTreeModel *tree_model,
|
||||
|
||||
ENTER("model %p, iter %s", tree_model, iter_to_string (iter));
|
||||
|
||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
||||
|
||||
/* Get the *next* sibling owner. */
|
||||
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)
|
||||
{
|
||||
iter->stamp = 0;
|
||||
@ -682,7 +652,6 @@ gnc_tree_model_owner_iter_children (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter,
|
||||
GtkTreeIter *parent_iter)
|
||||
{
|
||||
GncTreeModelOwnerPrivate *priv;
|
||||
GncTreeModelOwner *model;
|
||||
|
||||
g_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (tree_model), FALSE);
|
||||
@ -690,14 +659,13 @@ gnc_tree_model_owner_iter_children (GtkTreeModel *tree_model,
|
||||
tree_model, iter, (parent_iter ? iter_to_string(parent_iter) : "(null)"));
|
||||
|
||||
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
|
||||
* makes sense if no parent_iter was supplied. In that case,
|
||||
* return the first owner in the list */
|
||||
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_data3 = NULL;
|
||||
iter->stamp = model->stamp;
|
||||
@ -725,19 +693,17 @@ gnc_tree_model_owner_iter_n_children (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GncTreeModelOwner *model;
|
||||
GncTreeModelOwnerPrivate *priv;
|
||||
|
||||
g_return_val_if_fail (GNC_IS_TREE_MODEL_OWNER (tree_model), -1);
|
||||
|
||||
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
|
||||
* the special case this request comes for the special "root" iter
|
||||
* (NULL). For that exception we return the size of the owner list.
|
||||
*/
|
||||
if (iter == NULL)
|
||||
return (gint) g_list_length (priv->owner_list);
|
||||
return (gint) g_list_length (model->owner_list);
|
||||
|
||||
g_return_val_if_fail (
|
||||
GNC_TREE_MODEL_OWNER (tree_model)->stamp == iter->stamp, -1);
|
||||
@ -752,7 +718,6 @@ gnc_tree_model_owner_iter_nth_child (GtkTreeModel *tree_model,
|
||||
int n)
|
||||
{
|
||||
GncTreeModelOwner *model;
|
||||
GncTreeModelOwnerPrivate *priv;
|
||||
|
||||
if (parent_iter)
|
||||
{
|
||||
@ -771,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);
|
||||
|
||||
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
|
||||
* makes sense if no parent_iter was supplied. In that case,
|
||||
* return the first owner in the list */
|
||||
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_data3 = NULL;
|
||||
iter->stamp = model->stamp;
|
||||
@ -834,7 +798,6 @@ gnc_tree_model_owner_get_iter_from_owner (GncTreeModelOwner *model,
|
||||
GncOwner *owner,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GncTreeModelOwnerPrivate *priv;
|
||||
GList *owner_in_list;
|
||||
|
||||
ENTER("model %p, owner %p, iter %p", model, owner, iter);
|
||||
@ -842,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 ((iter != NULL), FALSE);
|
||||
|
||||
|
||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
||||
owner_in_list = g_list_find_custom (priv->owner_list, (gconstpointer)owner, (GCompareFunc)gncOwnerGCompareFunc);
|
||||
owner_in_list = g_list_find_custom (model->owner_list, (gconstpointer)owner, (GCompareFunc)gncOwnerGCompareFunc);
|
||||
if (owner_in_list)
|
||||
{
|
||||
iter->stamp = model->stamp;
|
||||
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;
|
||||
LEAVE("iter %s", iter_to_string (iter));
|
||||
return TRUE;
|
||||
@ -945,7 +906,6 @@ gnc_tree_model_owner_event_handler (QofInstance *entity,
|
||||
GncTreeModelOwner *model,
|
||||
GncEventData *ed)
|
||||
{
|
||||
GncTreeModelOwnerPrivate *priv;
|
||||
GtkTreePath *path = NULL;
|
||||
GtkTreeIter iter;
|
||||
GncOwner owner;
|
||||
@ -957,16 +917,15 @@ gnc_tree_model_owner_event_handler (QofInstance *entity,
|
||||
|
||||
ENTER("entity %p of type %d, model %p, event_data %p",
|
||||
entity, event_type, model, ed);
|
||||
priv = GNC_TREE_MODEL_OWNER_GET_PRIVATE(model);
|
||||
|
||||
qofOwnerSetEntity (&owner, entity);
|
||||
if (gncOwnerGetType(&owner) != priv->owner_type)
|
||||
if (gncOwnerGetType(&owner) != model->owner_type)
|
||||
{
|
||||
LEAVE("model type and owner type differ");
|
||||
return;
|
||||
}
|
||||
|
||||
if (qof_instance_get_book (entity) != priv->book)
|
||||
if (qof_instance_get_book (entity) != model->book)
|
||||
{
|
||||
LEAVE("not in this book");
|
||||
return;
|
||||
@ -979,11 +938,11 @@ gnc_tree_model_owner_event_handler (QofInstance *entity,
|
||||
/* Tell the filters/views where the new owner was added. */
|
||||
DEBUG("add owner %p (%s)", &owner, gncOwnerGetName(&owner));
|
||||
/* First update our copy of the owner list. This isn't done automatically */
|
||||
if (priv->owner_list)
|
||||
g_list_free_full (priv->owner_list, (GDestroyNotify) gncOwnerFree);
|
||||
if (model->owner_list)
|
||||
g_list_free_full (model->owner_list, (GDestroyNotify) gncOwnerFree);
|
||||
|
||||
priv->owner_list = gncBusinessGetOwnerList (priv->book,
|
||||
gncOwnerTypeToQofIdType(priv->owner_type), TRUE);
|
||||
model->owner_list = gncBusinessGetOwnerList (model->book,
|
||||
gncOwnerTypeToQofIdType(model->owner_type), TRUE);
|
||||
increment_stamp(model);
|
||||
if (!gnc_tree_model_owner_get_iter_from_owner (model, &owner, &iter))
|
||||
{
|
||||
@ -1003,7 +962,7 @@ gnc_tree_model_owner_event_handler (QofInstance *entity,
|
||||
if (!ed) /* Required for a remove. */
|
||||
break;
|
||||
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();
|
||||
if (!path)
|
||||
{
|
||||
|
@ -126,22 +126,13 @@ struct _GncTreeModelPrice
|
||||
GncTreeModel gnc_tree_model; /**< The parent object data. */
|
||||
int stamp; /**< The state of the model. Any state
|
||||
* change increments this number. */
|
||||
};
|
||||
|
||||
/** The instance private data for a price database tree model. */
|
||||
typedef struct GncTreeModelPricePrivate
|
||||
{
|
||||
QofBook *book;
|
||||
GNCPriceDB *price_db;
|
||||
gint event_handler_id;
|
||||
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_ADD_PRIVATE(GncTreeModelPrice)
|
||||
G_IMPLEMENT_INTERFACE(GTK_TYPE_TREE_MODEL,
|
||||
gnc_tree_model_price_tree_model_init))
|
||||
|
||||
@ -157,22 +148,18 @@ gnc_tree_model_price_class_init (GncTreeModelPriceClass *klass)
|
||||
static void
|
||||
gnc_tree_model_price_init (GncTreeModelPrice *model)
|
||||
{
|
||||
GncTreeModelPricePrivate *priv;
|
||||
|
||||
while (model->stamp == 0)
|
||||
{
|
||||
model->stamp = g_random_int ();
|
||||
}
|
||||
|
||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
||||
priv->print_info = gnc_default_price_print_info(NULL);
|
||||
model->print_info = gnc_default_price_print_info(NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
gnc_tree_model_price_finalize (GObject *object)
|
||||
{
|
||||
GncTreeModelPrice *model;
|
||||
GncTreeModelPricePrivate *priv;
|
||||
|
||||
ENTER("model %p", object);
|
||||
|
||||
@ -180,10 +167,9 @@ gnc_tree_model_price_finalize (GObject *object)
|
||||
g_return_if_fail (GNC_IS_TREE_MODEL_PRICE (object));
|
||||
|
||||
model = GNC_TREE_MODEL_PRICE (object);
|
||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
||||
|
||||
priv->book = NULL;
|
||||
priv->price_db = NULL;
|
||||
model->book = NULL;
|
||||
model->price_db = NULL;
|
||||
|
||||
G_OBJECT_CLASS (gnc_tree_model_price_parent_class)->finalize (object);
|
||||
LEAVE(" ");
|
||||
@ -193,19 +179,17 @@ static void
|
||||
gnc_tree_model_price_dispose (GObject *object)
|
||||
{
|
||||
GncTreeModelPrice *model;
|
||||
GncTreeModelPricePrivate *priv;
|
||||
|
||||
ENTER("model %p", object);
|
||||
g_return_if_fail (object != NULL);
|
||||
g_return_if_fail (GNC_IS_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);
|
||||
priv->event_handler_id = 0;
|
||||
qof_event_unregister_handler (model->event_handler_id);
|
||||
model->event_handler_id = 0;
|
||||
}
|
||||
|
||||
G_OBJECT_CLASS (gnc_tree_model_price_parent_class)->dispose (object);
|
||||
@ -216,7 +200,6 @@ GtkTreeModel *
|
||||
gnc_tree_model_price_new (QofBook *book, GNCPriceDB *price_db)
|
||||
{
|
||||
GncTreeModelPrice *model;
|
||||
GncTreeModelPricePrivate *priv;
|
||||
const GList *item;
|
||||
|
||||
ENTER(" ");
|
||||
@ -225,8 +208,7 @@ gnc_tree_model_price_new (QofBook *book, GNCPriceDB *price_db)
|
||||
for ( ; item; item = g_list_next(item))
|
||||
{
|
||||
model = (GncTreeModelPrice *)item->data;
|
||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
||||
if (priv->price_db == price_db)
|
||||
if (model->price_db == price_db)
|
||||
{
|
||||
g_object_ref(G_OBJECT(model));
|
||||
LEAVE("returning existing model %p", model);
|
||||
@ -236,11 +218,10 @@ gnc_tree_model_price_new (QofBook *book, GNCPriceDB *price_db)
|
||||
|
||||
model = g_object_new (GNC_TYPE_TREE_MODEL_PRICE, NULL);
|
||||
|
||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
||||
priv->book = book;
|
||||
priv->price_db = price_db;
|
||||
model->book = book;
|
||||
model->price_db = price_db;
|
||||
|
||||
priv->event_handler_id =
|
||||
model->event_handler_id =
|
||||
qof_event_register_handler (gnc_tree_model_price_event_handler, model);
|
||||
|
||||
LEAVE("returning new model %p", model);
|
||||
@ -340,7 +321,6 @@ gnc_tree_model_price_get_price (GncTreeModelPrice *model,
|
||||
static const gchar *
|
||||
iter_to_string (GncTreeModelPrice *model, GtkTreeIter *iter)
|
||||
{
|
||||
GncTreeModelPricePrivate *priv;
|
||||
gnc_commodity_namespace *name_space;
|
||||
gnc_commodity *commodity;
|
||||
GNCPrice *price;
|
||||
@ -358,7 +338,6 @@ iter_to_string (GncTreeModelPrice *model, GtkTreeIter *iter)
|
||||
static char string[ITER_STRING_LEN + 1];
|
||||
#endif
|
||||
|
||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
||||
if (iter)
|
||||
{
|
||||
switch (GPOINTER_TO_INT(iter->user_data))
|
||||
@ -388,7 +367,7 @@ iter_to_string (GncTreeModelPrice *model, GtkTreeIter *iter)
|
||||
"[stamp:%x data:%d (PRICE), %p (%s:%s), %d]",
|
||||
iter->stamp, GPOINTER_TO_INT(iter->user_data),
|
||||
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));
|
||||
break;
|
||||
|
||||
@ -469,7 +448,6 @@ gnc_tree_model_price_get_iter (GtkTreeModel *tree_model,
|
||||
GtkTreePath *path)
|
||||
{
|
||||
GncTreeModelPrice *model;
|
||||
GncTreeModelPricePrivate *priv;
|
||||
gnc_commodity_table *ct;
|
||||
gnc_commodity_namespace *name_space;
|
||||
gnc_commodity *commodity = NULL;
|
||||
@ -497,15 +475,14 @@ gnc_tree_model_price_get_iter (GtkTreeModel *tree_model,
|
||||
|
||||
/* Make sure the model has a price db. */
|
||||
model = GNC_TREE_MODEL_PRICE (tree_model);
|
||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
||||
if (priv->price_db == NULL)
|
||||
if (model->price_db == NULL)
|
||||
{
|
||||
LEAVE("no price db");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* 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);
|
||||
i = gtk_tree_path_get_indices (path)[0];
|
||||
name_space = g_list_nth_data (ns_list, i);
|
||||
@ -549,7 +526,7 @@ gnc_tree_model_price_get_iter (GtkTreeModel *tree_model,
|
||||
|
||||
/* Verify the third part of the path: the price. */
|
||||
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.
|
||||
* Comment this check out for now, and we'll handle the
|
||||
* resulting problem elsewhere. */
|
||||
@ -575,7 +552,6 @@ gnc_tree_model_price_get_path (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GncTreeModelPrice *model = GNC_TREE_MODEL_PRICE (tree_model);
|
||||
GncTreeModelPricePrivate *priv;
|
||||
gnc_commodity_table *ct;
|
||||
gnc_commodity_namespace *name_space;
|
||||
gnc_commodity *commodity;
|
||||
@ -589,8 +565,7 @@ gnc_tree_model_price_get_path (GtkTreeModel *tree_model,
|
||||
g_return_val_if_fail (iter->stamp == model->stamp, NULL);
|
||||
|
||||
/* Make sure this model has a price db. */
|
||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
||||
if (priv->price_db == NULL)
|
||||
if (model->price_db == NULL)
|
||||
{
|
||||
LEAVE("no price db");
|
||||
return FALSE;
|
||||
@ -607,7 +582,7 @@ gnc_tree_model_price_get_path (GtkTreeModel *tree_model,
|
||||
}
|
||||
|
||||
/* 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);
|
||||
|
||||
if (iter->user_data == ITER_IS_COMMODITY)
|
||||
@ -641,7 +616,6 @@ gnc_tree_model_price_get_value (GtkTreeModel *tree_model,
|
||||
GValue *value)
|
||||
{
|
||||
GncTreeModelPrice *model = GNC_TREE_MODEL_PRICE (tree_model);
|
||||
GncTreeModelPricePrivate *priv;
|
||||
gnc_commodity_namespace *name_space;
|
||||
gnc_commodity *commodity;
|
||||
GNCPrice *price;
|
||||
@ -750,9 +724,8 @@ gnc_tree_model_price_get_value (GtkTreeModel *tree_model,
|
||||
break;
|
||||
case GNC_TREE_MODEL_PRICE_COL_VALUE:
|
||||
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),
|
||||
priv->print_info));
|
||||
model->print_info));
|
||||
break;
|
||||
case GNC_TREE_MODEL_PRICE_COL_VISIBILITY:
|
||||
g_value_init (value, G_TYPE_BOOLEAN);
|
||||
@ -768,7 +741,6 @@ gnc_tree_model_price_iter_next (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GncTreeModelPrice *model = GNC_TREE_MODEL_PRICE (tree_model);
|
||||
GncTreeModelPricePrivate *priv;
|
||||
gnc_commodity_table *ct;
|
||||
gnc_commodity *commodity;
|
||||
gnc_commodity_namespace *name_space;
|
||||
@ -781,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->stamp == model->stamp, FALSE);
|
||||
|
||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
||||
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);
|
||||
n = GPOINTER_TO_INT(iter->user_data3) + 1;
|
||||
iter->user_data2 = g_list_nth_data(list, n);
|
||||
@ -816,7 +787,7 @@ gnc_tree_model_price_iter_next (GtkTreeModel *tree_model,
|
||||
{
|
||||
commodity = gnc_price_get_commodity((GNCPrice*)iter->user_data2);
|
||||
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)
|
||||
{
|
||||
LEAVE("no next iter");
|
||||
@ -839,7 +810,6 @@ gnc_tree_model_price_iter_children (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *parent)
|
||||
{
|
||||
GncTreeModelPrice *model;
|
||||
GncTreeModelPricePrivate *priv;
|
||||
gnc_commodity_table *ct;
|
||||
gnc_commodity_namespace *name_space;
|
||||
gnc_commodity *commodity;
|
||||
@ -851,10 +821,9 @@ gnc_tree_model_price_iter_children (GtkTreeModel *tree_model,
|
||||
ENTER("model %p, iter %p, parent %p (%s)",
|
||||
tree_model, iter, parent, iter_to_string(model, parent));
|
||||
|
||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
||||
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);
|
||||
if (list == NULL)
|
||||
{
|
||||
@ -892,7 +861,7 @@ gnc_tree_model_price_iter_children (GtkTreeModel *tree_model,
|
||||
{
|
||||
GNCPrice *price;
|
||||
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)
|
||||
{
|
||||
LEAVE("no prices");
|
||||
@ -915,7 +884,6 @@ gnc_tree_model_price_iter_has_child (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GncTreeModelPrice *model;
|
||||
GncTreeModelPricePrivate *priv;
|
||||
gnc_commodity_namespace *name_space;
|
||||
gnc_commodity *commodity;
|
||||
gboolean result;
|
||||
@ -927,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 (iter != NULL, FALSE);
|
||||
|
||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
||||
if (iter->user_data == ITER_IS_PRICE)
|
||||
{
|
||||
LEAVE("price has no children");
|
||||
@ -945,7 +912,7 @@ gnc_tree_model_price_iter_has_child (GtkTreeModel *tree_model,
|
||||
if (iter->user_data == ITER_IS_COMMODITY)
|
||||
{
|
||||
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");
|
||||
return result;
|
||||
}
|
||||
@ -959,7 +926,6 @@ gnc_tree_model_price_iter_n_children (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GncTreeModelPrice *model;
|
||||
GncTreeModelPricePrivate *priv;
|
||||
gnc_commodity_table *ct;
|
||||
gnc_commodity_namespace *name_space;
|
||||
gnc_commodity *commodity;
|
||||
@ -972,10 +938,9 @@ gnc_tree_model_price_iter_n_children (GtkTreeModel *tree_model,
|
||||
ENTER("model %p, iter %p (%s)", tree_model, iter,
|
||||
iter_to_string(model, iter));
|
||||
|
||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
||||
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);
|
||||
LEAVE("ns list length %d", g_list_length(list));
|
||||
return g_list_length (list);
|
||||
@ -992,7 +957,7 @@ gnc_tree_model_price_iter_n_children (GtkTreeModel *tree_model,
|
||||
if (iter->user_data == ITER_IS_COMMODITY)
|
||||
{
|
||||
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);
|
||||
return n;
|
||||
}
|
||||
@ -1008,7 +973,6 @@ gnc_tree_model_price_iter_nth_child (GtkTreeModel *tree_model,
|
||||
int n)
|
||||
{
|
||||
GncTreeModelPrice *model;
|
||||
GncTreeModelPricePrivate *priv;
|
||||
gnc_commodity_table *ct;
|
||||
gnc_commodity_namespace *name_space;
|
||||
gnc_commodity *commodity;
|
||||
@ -1021,10 +985,9 @@ gnc_tree_model_price_iter_nth_child (GtkTreeModel *tree_model,
|
||||
ENTER("model %p, iter %p, parent %p (%s), n %d",
|
||||
tree_model, iter, parent, iter_to_string(model, parent), n);
|
||||
|
||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
||||
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);
|
||||
|
||||
iter->stamp = model->stamp;
|
||||
@ -1054,7 +1017,7 @@ gnc_tree_model_price_iter_nth_child (GtkTreeModel *tree_model,
|
||||
|
||||
iter->stamp = model->stamp;
|
||||
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);
|
||||
LEAVE("price iter %p (%s)", iter, iter_to_string(model, iter));
|
||||
return iter->user_data2 != NULL;
|
||||
@ -1071,7 +1034,6 @@ gnc_tree_model_price_iter_parent (GtkTreeModel *tree_model,
|
||||
GtkTreeIter *child)
|
||||
{
|
||||
GncTreeModelPrice *model;
|
||||
GncTreeModelPricePrivate *priv;
|
||||
gnc_commodity_table *ct;
|
||||
gnc_commodity * commodity;
|
||||
gnc_commodity_namespace *name_space;
|
||||
@ -1085,7 +1047,6 @@ gnc_tree_model_price_iter_parent (GtkTreeModel *tree_model,
|
||||
ENTER("model %p, iter %p, child %p (%s)",
|
||||
tree_model, iter, child, iter_to_string(model, child));
|
||||
|
||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
||||
if (child->user_data == ITER_IS_NAMESPACE)
|
||||
{
|
||||
LEAVE("ns has no parent");
|
||||
@ -1094,7 +1055,7 @@ gnc_tree_model_price_iter_parent (GtkTreeModel *tree_model,
|
||||
|
||||
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);
|
||||
name_space = gnc_commodity_get_namespace_ds((gnc_commodity*)child->user_data2);
|
||||
|
||||
@ -1132,7 +1093,6 @@ gnc_tree_model_price_get_iter_from_price (GncTreeModelPrice *model,
|
||||
GNCPrice *price,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GncTreeModelPricePrivate *priv;
|
||||
gnc_commodity *commodity;
|
||||
GList *list;
|
||||
gint n;
|
||||
@ -1142,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 ((iter != NULL), FALSE);
|
||||
|
||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
||||
commodity = gnc_price_get_commodity(price);
|
||||
if (commodity == NULL)
|
||||
{
|
||||
@ -1150,7 +1109,7 @@ gnc_tree_model_price_get_iter_from_price (GncTreeModelPrice *model,
|
||||
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)
|
||||
{
|
||||
LEAVE("empty list");
|
||||
@ -1268,7 +1227,6 @@ gnc_tree_model_price_get_iter_from_namespace (GncTreeModelPrice *model,
|
||||
gnc_commodity_namespace *name_space,
|
||||
GtkTreeIter *iter)
|
||||
{
|
||||
GncTreeModelPricePrivate *priv;
|
||||
gnc_commodity_table *ct;
|
||||
GList *list;
|
||||
gint n;
|
||||
@ -1278,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 ((iter != NULL), FALSE);
|
||||
|
||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
||||
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);
|
||||
if (list == NULL)
|
||||
{
|
||||
@ -1541,7 +1498,6 @@ gnc_tree_model_price_event_handler (QofInstance *entity,
|
||||
gpointer event_data)
|
||||
{
|
||||
GncTreeModelPrice *model;
|
||||
GncTreeModelPricePrivate *priv;
|
||||
GtkTreePath *path;
|
||||
GtkTreeIter iter;
|
||||
remove_data *data;
|
||||
@ -1550,11 +1506,10 @@ gnc_tree_model_price_event_handler (QofInstance *entity,
|
||||
ENTER("entity %p, event %d, model %p, event data %p",
|
||||
entity, event_type, user_data, event_data);
|
||||
model = (GncTreeModelPrice *)user_data;
|
||||
priv = GNC_TREE_MODEL_PRICE_GET_PRIVATE(model);
|
||||
|
||||
/* Do deletions if any are pending. */
|
||||
if (pending_removals)
|
||||
gnc_tree_model_price_do_deletions (priv->price_db);
|
||||
gnc_tree_model_price_do_deletions (model->price_db);
|
||||
|
||||
/* hard failures */
|
||||
g_return_if_fail(GNC_IS_TREE_MODEL_PRICE(model));
|
||||
@ -1616,7 +1571,7 @@ gnc_tree_model_price_event_handler (QofInstance *entity,
|
||||
case QOF_EVENT_ADD:
|
||||
/* Tell the filters/views where the new price was added. */
|
||||
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);
|
||||
break;
|
||||
|
||||
@ -1635,7 +1590,7 @@ gnc_tree_model_price_event_handler (QofInstance *entity,
|
||||
data->path = path;
|
||||
pending_removals = g_slist_append (pending_removals, data);
|
||||
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(" ");
|
||||
return;
|
||||
|
Loading…
Reference in New Issue
Block a user