diff --git a/gnucash/gnome-utils/gnc-tree-model-account.c b/gnucash/gnome-utils/gnc-tree-model-account.c index 21ea030b1f..a8fe36f1fc 100644 --- a/gnucash/gnome-utils/gnc-tree-model-account.c +++ b/gnucash/gnome-utils/gnc-tree-model-account.c @@ -1,6 +1,6 @@ /* * gnc-tree-model-account.c -- GtkTreeModel implementation to - * display accounts in a GtkTreeView. + * display accounts in a GtkTreeView. * * Copyright (C) 2003 Jan Arne Petersen * Copyright (C) 2003 David Hampton @@ -67,20 +67,20 @@ static void gnc_tree_model_account_get_value (GtkTreeModel *tree_model, GtkTreeIter *iter, int column, GValue *value); -static gboolean gnc_tree_model_account_iter_next (GtkTreeModel *tree_model, +static gboolean gnc_tree_model_account_iter_next (GtkTreeModel *tree_model, GtkTreeIter *iter); -static gboolean gnc_tree_model_account_iter_children (GtkTreeModel *tree_model, +static gboolean gnc_tree_model_account_iter_children (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *parent); -static gboolean gnc_tree_model_account_iter_has_child (GtkTreeModel *tree_model, +static gboolean gnc_tree_model_account_iter_has_child (GtkTreeModel *tree_model, GtkTreeIter *iter); static int gnc_tree_model_account_iter_n_children (GtkTreeModel *tree_model, GtkTreeIter *iter); -static gboolean gnc_tree_model_account_iter_nth_child (GtkTreeModel *tree_model, +static gboolean gnc_tree_model_account_iter_nth_child (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *parent, int n); -static gboolean gnc_tree_model_account_iter_parent (GtkTreeModel *tree_model, +static gboolean gnc_tree_model_account_iter_parent (GtkTreeModel *tree_model, GtkTreeIter *iter, GtkTreeIter *child); @@ -97,10 +97,13 @@ typedef struct GncTreeModelAccountPrivate Account *root; gint event_handler_id; const gchar *negative_color; + + GHashTable *account_values_hash; + } GncTreeModelAccountPrivate; #define GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(o) \ - ((GncTreeModelAccountPrivate*)g_type_instance_get_private((GTypeInstance*)o, GNC_TYPE_TREE_MODEL_ACCOUNT)) + ((GncTreeModelAccountPrivate*)g_type_instance_get_private ((GTypeInstance*)o, GNC_TYPE_TREE_MODEL_ACCOUNT)) /************************************************************/ @@ -131,12 +134,19 @@ gnc_tree_model_account_update_color (gpointer gsettings, gchar *key, gpointer us GncTreeModelAccount *model; 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; priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model); + + // destroy/recreate the cached acount 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_free, g_free); + use_red = gnc_prefs_get_bool (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED); priv->negative_color = use_red ? get_negative_color () : NULL; } + /************************************************************/ /* g_object required functions */ /************************************************************/ @@ -156,7 +166,7 @@ gnc_tree_model_account_class_init (GncTreeModelAccountClass *klass) parent_class = g_type_class_peek_parent (klass); - o_class = G_OBJECT_CLASS (klass); + o_class = G_OBJECT_CLASS(klass); /* GObject signals */ o_class->finalize = gnc_tree_model_account_finalize; @@ -175,16 +185,20 @@ gnc_tree_model_account_init (GncTreeModelAccount *model) model->stamp = g_random_int (); } - 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_ACCOUNT_GET_PRIVATE(model); priv->book = NULL; priv->root = NULL; priv->negative_color = red ? get_negative_color () : NULL; - gnc_prefs_register_cb(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED, - gnc_tree_model_account_update_color, - model); + // create the account values cache hash + priv->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, + gnc_tree_model_account_update_color, + model); LEAVE(" "); } @@ -196,16 +210,16 @@ gnc_tree_model_account_finalize (GObject *object) GncTreeModelAccount *model; g_return_if_fail (object != NULL); - g_return_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (object)); + g_return_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(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; - if (G_OBJECT_CLASS (parent_class)->finalize) + if (G_OBJECT_CLASS(parent_class)->finalize) G_OBJECT_CLASS(parent_class)->finalize (object); LEAVE(" "); } @@ -217,11 +231,11 @@ gnc_tree_model_account_dispose (GObject *object) GncTreeModelAccount *model; g_return_if_fail (object != NULL); - g_return_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (object)); + g_return_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(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) @@ -230,12 +244,15 @@ gnc_tree_model_account_dispose (GObject *object) priv->event_handler_id = 0; } - gnc_prefs_remove_cb_by_func(GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED, - gnc_tree_model_account_update_color, - model); + // destroy the cached acount values + g_hash_table_destroy (priv->account_values_hash); - if (G_OBJECT_CLASS (parent_class)->dispose) - G_OBJECT_CLASS (parent_class)->dispose (object); + gnc_prefs_remove_cb_by_func (GNC_PREFS_GROUP_GENERAL, GNC_PREF_NEGATIVE_IN_RED, + gnc_tree_model_account_update_color, + model); + + if (G_OBJECT_CLASS(parent_class)->dispose) + G_OBJECT_CLASS(parent_class)->dispose (object); LEAVE(" "); } @@ -252,21 +269,20 @@ gnc_tree_model_account_new (Account *root) const GList *item; ENTER("root %p", root); - item = gnc_gobject_tracking_get_list(GNC_TREE_MODEL_ACCOUNT_NAME); - for ( ; item; item = g_list_next(item)) + item = gnc_gobject_tracking_get_list (GNC_TREE_MODEL_ACCOUNT_NAME); + for ( ; item; item = g_list_next (item)) { model = (GncTreeModelAccount *)item->data; priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model); if (priv->root == root) { - g_object_ref(G_OBJECT(model)); + g_object_ref (G_OBJECT(model)); LEAVE("returning existing model %p", model); return GTK_TREE_MODEL(model); } } - 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); priv->book = gnc_get_current_book(); @@ -276,7 +292,7 @@ gnc_tree_model_account_new (Account *root) ((QofEventHandler)gnc_tree_model_account_event_handler, model); LEAVE("model %p", model); - return GTK_TREE_MODEL (model); + return GTK_TREE_MODEL(model); } @@ -304,13 +320,13 @@ iter_to_string (GtkTreeIter *iter) #endif if (iter) - snprintf(string, ITER_STRING_LEN, - "[stamp:%x data:%p (%s), %p, %d]", - iter->stamp, iter->user_data, - xaccAccountGetName ((Account *) iter->user_data), - iter->user_data2, GPOINTER_TO_INT(iter->user_data3)); + snprintf (string, ITER_STRING_LEN, + "[stamp:%x data:%p (%s), %p, %d]", + iter->stamp, iter->user_data, + xaccAccountGetName ((Account *) iter->user_data), + iter->user_data2, GPOINTER_TO_INT(iter->user_data3)); else - strcpy(string, "(null)"); + strcpy (string, "(null)"); return string; } @@ -345,14 +361,13 @@ gnc_tree_model_account_get_flags (GtkTreeModel *tree_model) static int gnc_tree_model_account_get_n_columns (GtkTreeModel *tree_model) { - g_return_val_if_fail(GNC_IS_TREE_MODEL_ACCOUNT(tree_model), -1); + g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(tree_model), -1); return GNC_TREE_MODEL_ACCOUNT_NUM_COLUMNS; } static GType -gnc_tree_model_account_get_column_type (GtkTreeModel *tree_model, - int index) +gnc_tree_model_account_get_column_type (GtkTreeModel *tree_model, int index) { g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (tree_model), G_TYPE_INVALID); g_return_val_if_fail ((index < GNC_TREE_MODEL_ACCOUNT_NUM_COLUMNS) && (index >= 0), G_TYPE_INVALID); @@ -414,15 +429,15 @@ gnc_tree_model_account_get_iter (GtkTreeModel *tree_model, Account *account, *parent; gint i, *indices; - g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (tree_model), FALSE); + g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(tree_model), FALSE); { - gchar *path_string = gtk_tree_path_to_string(path); + gchar *path_string = gtk_tree_path_to_string (path); ENTER("model %p, iter %p, path %s", tree_model, iter, path_string); - g_free(path_string); + g_free (path_string); } - 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) @@ -443,7 +458,7 @@ gnc_tree_model_account_get_iter (GtkTreeModel *tree_model, for (i = 1; i < gtk_tree_path_get_depth (path); i++) { parent = account; - account = gnc_account_nth_child(parent, indices[i]); + account = gnc_account_nth_child (parent, indices[i]); if (account == NULL) { iter->stamp = 0; @@ -455,9 +470,9 @@ gnc_tree_model_account_get_iter (GtkTreeModel *tree_model, iter->stamp = model->stamp; iter->user_data = account; iter->user_data2 = parent; - iter->user_data3 = GINT_TO_POINTER (indices[i - 1]); + iter->user_data3 = GINT_TO_POINTER(indices[i - 1]); - LEAVE("iter %s", iter_to_string(iter)); + LEAVE("iter %s", iter_to_string (iter)); return TRUE; } @@ -465,18 +480,18 @@ static GtkTreePath * gnc_tree_model_account_get_path (GtkTreeModel *tree_model, GtkTreeIter *iter) { - GncTreeModelAccount *model = GNC_TREE_MODEL_ACCOUNT (tree_model); + GncTreeModelAccount *model = GNC_TREE_MODEL_ACCOUNT(tree_model); GncTreeModelAccountPrivate *priv; Account *account, *parent; GtkTreePath *path; gint i; - g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (model), NULL); + g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(model), NULL); g_return_val_if_fail (iter != NULL, NULL); g_return_val_if_fail (iter->user_data != NULL, NULL); g_return_val_if_fail (iter->stamp == model->stamp, NULL); - 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 (priv->root == NULL) @@ -491,7 +506,7 @@ gnc_tree_model_account_get_path (GtkTreeModel *tree_model, path = gtk_tree_path_new (); while (parent) { - i = gnc_account_child_index(parent, account); + i = gnc_account_child_index (parent, account); if (i == -1) { gtk_tree_path_free (path); @@ -500,24 +515,24 @@ gnc_tree_model_account_get_path (GtkTreeModel *tree_model, } gtk_tree_path_prepend_index (path, i); account = parent; - parent = gnc_account_get_parent(account); + parent = gnc_account_get_parent (account); }; /* Add the root node. */ gtk_tree_path_prepend_index (path, 0); { - gchar *path_string = gtk_tree_path_to_string(path); + gchar *path_string = gtk_tree_path_to_string (path); LEAVE("path (4) %s", path_string); - g_free(path_string); + g_free (path_string); } return path; } static void -gnc_tree_model_account_set_color(GncTreeModelAccount *model, - gboolean negative, - GValue *value) +gnc_tree_model_account_set_color (GncTreeModelAccount *model, + gboolean negative, + GValue *value) { GncTreeModelAccountPrivate *priv; @@ -529,36 +544,161 @@ gnc_tree_model_account_set_color(GncTreeModelAccount *model, } static gchar * -gnc_tree_model_account_compute_period_balance(GncTreeModelAccount *model, - Account *acct, - gboolean recurse, - gboolean *negative) +gnc_tree_model_account_compute_period_balance (GncTreeModelAccount *model, + Account *acct, + gboolean recurse, + gboolean *negative) { GncTreeModelAccountPrivate *priv; time64 t1, t2; gnc_numeric b3; - if ( negative ) + if (negative) *negative = FALSE; priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model); if (acct == priv->root) - return g_strdup(""); + return g_strdup (""); - t1 = gnc_accounting_period_fiscal_start(); - t2 = gnc_accounting_period_fiscal_end(); + t1 = gnc_accounting_period_fiscal_start (); + t2 = gnc_accounting_period_fiscal_end (); if (t1 > t2) - return g_strdup(""); + return g_strdup (""); - b3 = xaccAccountGetBalanceChangeForPeriod(acct, t1, t2, recurse); + b3 = xaccAccountGetBalanceChangeForPeriod (acct, t1, t2, recurse); if (gnc_reverse_balance (acct)) b3 = gnc_numeric_neg (b3); if (negative) - *negative = gnc_numeric_negative_p(b3); + *negative = gnc_numeric_negative_p (b3); - return g_strdup(xaccPrintAmount(b3, gnc_account_print_info(acct, TRUE))); + return g_strdup(xaccPrintAmount (b3, gnc_account_print_info (acct, TRUE))); +} + +static gboolean +row_changed_foreach_func (GtkTreeModel *model, GtkTreePath *path, + GtkTreeIter *iter, gpointer user_data) +{ + gtk_tree_model_row_changed (model, path, iter); + return FALSE; +} + +void +gnc_tree_model_account_clear_cache (GncTreeModelAccount *model) +{ + if (model) + { + GncTreeModelAccountPrivate *priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model); + + // destroy the cached acount 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_free, g_free); + + gtk_tree_model_foreach (GTK_TREE_MODEL(model), row_changed_foreach_func, NULL); + } +} + +static void +clear_account_cached_values (GncTreeModelAccount *model, GHashTable *hash, Account *account) +{ + GtkTreeIter iter; + gchar acct_guid_str[GUID_ENCODING_LENGTH + 1]; + + if (!account) + return; + + // make sure tree view sees the change + if (gnc_tree_model_account_get_iter_from_account (model, account, &iter)) + { + GtkTreePath *path = gtk_tree_model_get_path (GTK_TREE_MODEL(model), &iter); + + gtk_tree_model_row_changed (GTK_TREE_MODEL(model), path, &iter); + gtk_tree_path_free (path); + } + + guid_to_string_buff (xaccAccountGetGUID (account), acct_guid_str); + + // loop over the columns and remove any found + for (gint col = 0; col <= GNC_TREE_MODEL_ACCOUNT_NUM_COLUMNS; col++) + { + gchar *key = g_strdup_printf ("%s,%d", acct_guid_str, col); + + g_hash_table_remove (hash, key); + g_free (key); + } +} + +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)) + return; + + clear_account_cached_values (model, priv->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); + parent = gnc_account_get_parent (parent); + } +} + +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)) + 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, + NULL, &value); + + if (found) + *cached_string = g_strdup (value); + + g_free (key); + + return found; +} + +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)) + return; + + // only interested in string values + if (G_VALUE_HOLDS_STRING(value)) + { + gchar acct_guid_str[GUID_ENCODING_LENGTH + 1]; + const gchar *str = g_value_get_string (value); + gchar *key = NULL; + + 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)); + } } static void @@ -567,24 +707,34 @@ gnc_tree_model_account_get_value (GtkTreeModel *tree_model, int column, GValue *value) { - GncTreeModelAccount *model = GNC_TREE_MODEL_ACCOUNT (tree_model); + 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; + gchar *cached_string = NULL; + time64 last_date; - g_return_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (model)); + g_return_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(model)); g_return_if_fail (iter != NULL); g_return_if_fail (iter->user_data != NULL); g_return_if_fail (iter->stamp == model->stamp); ENTER("model %p, iter %s, col %d", tree_model, - iter_to_string(iter), column); + 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)) + { + g_value_init (value, G_TYPE_STRING); + g_value_take_string (value, cached_string); + return; + } + switch (column) { case GNC_TREE_MODEL_ACCOUNT_COL_NAME: @@ -615,151 +765,149 @@ gnc_tree_model_account_get_value (GtkTreeModel *tree_model, case GNC_TREE_MODEL_ACCOUNT_COL_PRESENT: g_value_init (value, G_TYPE_STRING); - string = gnc_ui_account_get_print_balance(xaccAccountGetPresentBalanceInCurrency, + string = gnc_ui_account_get_print_balance (xaccAccountGetPresentBalanceInCurrency, account, TRUE, &negative); g_value_take_string (value, string); break; case GNC_TREE_MODEL_ACCOUNT_COL_PRESENT_REPORT: g_value_init (value, G_TYPE_STRING); - string = gnc_ui_account_get_print_report_balance(xaccAccountGetPresentBalanceInCurrency, + string = gnc_ui_account_get_print_report_balance (xaccAccountGetPresentBalanceInCurrency, account, TRUE, &negative); g_value_take_string (value, string); break; case GNC_TREE_MODEL_ACCOUNT_COL_COLOR_PRESENT: g_value_init (value, G_TYPE_STRING); - string = gnc_ui_account_get_print_balance(xaccAccountGetPresentBalanceInCurrency, + string = gnc_ui_account_get_print_balance (xaccAccountGetPresentBalanceInCurrency, account, TRUE, &negative); - gnc_tree_model_account_set_color(model, negative, value); - g_free(string); + gnc_tree_model_account_set_color (model, negative, value); + g_free (string); break; case GNC_TREE_MODEL_ACCOUNT_COL_BALANCE: g_value_init (value, G_TYPE_STRING); - string = gnc_ui_account_get_print_balance(xaccAccountGetBalanceInCurrency, + string = gnc_ui_account_get_print_balance (xaccAccountGetBalanceInCurrency, account, FALSE, &negative); g_value_take_string (value, string); break; case GNC_TREE_MODEL_ACCOUNT_COL_BALANCE_REPORT: g_value_init (value, G_TYPE_STRING); - string = gnc_ui_account_get_print_report_balance(xaccAccountGetBalanceInCurrency, + string = gnc_ui_account_get_print_report_balance (xaccAccountGetBalanceInCurrency, account, FALSE, &negative); g_value_take_string (value, string); break; case GNC_TREE_MODEL_ACCOUNT_COL_COLOR_BALANCE: g_value_init (value, G_TYPE_STRING); - string = gnc_ui_account_get_print_balance(xaccAccountGetBalanceInCurrency, + string = gnc_ui_account_get_print_balance (xaccAccountGetBalanceInCurrency, account, FALSE, &negative); - gnc_tree_model_account_set_color(model, negative, value); - g_free(string); + gnc_tree_model_account_set_color (model, negative, value); + g_free (string); break; case GNC_TREE_MODEL_ACCOUNT_COL_BALANCE_PERIOD: g_value_init (value, G_TYPE_STRING); - string = gnc_tree_model_account_compute_period_balance(model, account, FALSE, &negative); + string = gnc_tree_model_account_compute_period_balance (model, account, FALSE, &negative); g_value_take_string (value, string); break; case GNC_TREE_MODEL_ACCOUNT_COL_COLOR_BALANCE_PERIOD: g_value_init (value, G_TYPE_STRING); - string = gnc_tree_model_account_compute_period_balance(model, account, FALSE, &negative); - gnc_tree_model_account_set_color(model, negative, value); + string = gnc_tree_model_account_compute_period_balance (model, account, FALSE, &negative); + gnc_tree_model_account_set_color (model, negative, value); g_free (string); break; case GNC_TREE_MODEL_ACCOUNT_COL_CLEARED: g_value_init (value, G_TYPE_STRING); - string = gnc_ui_account_get_print_balance(xaccAccountGetClearedBalanceInCurrency, + string = gnc_ui_account_get_print_balance (xaccAccountGetClearedBalanceInCurrency, account, TRUE, &negative); g_value_take_string (value, string); break; case GNC_TREE_MODEL_ACCOUNT_COL_CLEARED_REPORT: g_value_init (value, G_TYPE_STRING); - string = gnc_ui_account_get_print_report_balance(xaccAccountGetClearedBalanceInCurrency, + string = gnc_ui_account_get_print_report_balance (xaccAccountGetClearedBalanceInCurrency, account, TRUE, &negative); g_value_take_string (value, string); break; case GNC_TREE_MODEL_ACCOUNT_COL_COLOR_CLEARED: g_value_init (value, G_TYPE_STRING); - string = gnc_ui_account_get_print_balance(xaccAccountGetClearedBalanceInCurrency, + string = gnc_ui_account_get_print_balance (xaccAccountGetClearedBalanceInCurrency, account, TRUE, &negative); - gnc_tree_model_account_set_color(model, negative, value); - g_free(string); + gnc_tree_model_account_set_color (model, negative, value); + g_free (string); break; case GNC_TREE_MODEL_ACCOUNT_COL_RECONCILED: g_value_init (value, G_TYPE_STRING); - string = gnc_ui_account_get_print_balance(xaccAccountGetReconciledBalanceInCurrency, + string = gnc_ui_account_get_print_balance (xaccAccountGetReconciledBalanceInCurrency, account, TRUE, &negative); g_value_take_string (value, string); break; case GNC_TREE_MODEL_ACCOUNT_COL_RECONCILED_REPORT: g_value_init (value, G_TYPE_STRING); - string = gnc_ui_account_get_print_report_balance(xaccAccountGetReconciledBalanceInCurrency, + string = gnc_ui_account_get_print_report_balance (xaccAccountGetReconciledBalanceInCurrency, account, TRUE, &negative); g_value_take_string (value, string); break; case GNC_TREE_MODEL_ACCOUNT_COL_RECONCILED_DATE: g_value_init (value, G_TYPE_STRING); - if (xaccAccountGetReconcileLastDate(account, &last_date)) - { - g_value_take_string(value, qof_print_date(last_date)); - } + if (xaccAccountGetReconcileLastDate (account, &last_date)) + g_value_take_string (value, qof_print_date (last_date)); break; case GNC_TREE_MODEL_ACCOUNT_COL_COLOR_RECONCILED: g_value_init (value, G_TYPE_STRING); - string = gnc_ui_account_get_print_balance(xaccAccountGetReconciledBalanceInCurrency, + string = gnc_ui_account_get_print_balance (xaccAccountGetReconciledBalanceInCurrency, account, TRUE, &negative); - gnc_tree_model_account_set_color(model, negative, value); + gnc_tree_model_account_set_color (model, negative, value); g_free (string); break; case GNC_TREE_MODEL_ACCOUNT_COL_FUTURE_MIN: g_value_init (value, G_TYPE_STRING); - string = gnc_ui_account_get_print_balance(xaccAccountGetProjectedMinimumBalanceInCurrency, + string = gnc_ui_account_get_print_balance (xaccAccountGetProjectedMinimumBalanceInCurrency, account, TRUE, &negative); g_value_take_string (value, string); break; case GNC_TREE_MODEL_ACCOUNT_COL_FUTURE_MIN_REPORT: g_value_init (value, G_TYPE_STRING); - string = gnc_ui_account_get_print_report_balance(xaccAccountGetProjectedMinimumBalanceInCurrency, + string = gnc_ui_account_get_print_report_balance (xaccAccountGetProjectedMinimumBalanceInCurrency, account, TRUE, &negative); g_value_take_string (value, string); break; case GNC_TREE_MODEL_ACCOUNT_COL_COLOR_FUTURE_MIN: g_value_init (value, G_TYPE_STRING); - string = gnc_ui_account_get_print_balance(xaccAccountGetProjectedMinimumBalanceInCurrency, + string = gnc_ui_account_get_print_balance (xaccAccountGetProjectedMinimumBalanceInCurrency, account, TRUE, &negative); - gnc_tree_model_account_set_color(model, negative, value); + gnc_tree_model_account_set_color (model, negative, value); g_free (string); break; case GNC_TREE_MODEL_ACCOUNT_COL_TOTAL: g_value_init (value, G_TYPE_STRING); - string = gnc_ui_account_get_print_balance(xaccAccountGetBalanceInCurrency, + string = gnc_ui_account_get_print_balance (xaccAccountGetBalanceInCurrency, account, TRUE, &negative); g_value_take_string (value, string); break; case GNC_TREE_MODEL_ACCOUNT_COL_TOTAL_REPORT: g_value_init (value, G_TYPE_STRING); - string = gnc_ui_account_get_print_report_balance(xaccAccountGetBalanceInCurrency, + string = gnc_ui_account_get_print_report_balance (xaccAccountGetBalanceInCurrency, account, TRUE, &negative); g_value_take_string (value, string); break; case GNC_TREE_MODEL_ACCOUNT_COL_COLOR_TOTAL: g_value_init (value, G_TYPE_STRING); - string = gnc_ui_account_get_print_balance(xaccAccountGetBalanceInCurrency, + string = gnc_ui_account_get_print_balance (xaccAccountGetBalanceInCurrency, account, TRUE, &negative); - gnc_tree_model_account_set_color(model, negative, value); + gnc_tree_model_account_set_color (model, negative, value); g_free (string); break; case GNC_TREE_MODEL_ACCOUNT_COL_TOTAL_PERIOD: g_value_init (value, G_TYPE_STRING); - string = gnc_tree_model_account_compute_period_balance(model, account, TRUE, &negative); + string = gnc_tree_model_account_compute_period_balance (model, account, TRUE, &negative); g_value_take_string (value, string); break; case GNC_TREE_MODEL_ACCOUNT_COL_COLOR_TOTAL_PERIOD: g_value_init (value, G_TYPE_STRING); - string = gnc_tree_model_account_compute_period_balance(model, account, TRUE, &negative); - gnc_tree_model_account_set_color(model, negative, value); + string = gnc_tree_model_account_compute_period_balance (model, account, TRUE, &negative); + gnc_tree_model_account_set_color (model, negative, value); g_free (string); break; @@ -797,6 +945,10 @@ gnc_tree_model_account_get_value (GtkTreeModel *tree_model, g_assert_not_reached (); break; } + + // save the value to the account values cache + gnc_tree_model_account_set_cached_value (model, account, column, value); + LEAVE(" "); } @@ -804,16 +956,16 @@ static gboolean gnc_tree_model_account_iter_next (GtkTreeModel *tree_model, GtkTreeIter *iter) { - GncTreeModelAccount *model = GNC_TREE_MODEL_ACCOUNT (tree_model); + GncTreeModelAccount *model = GNC_TREE_MODEL_ACCOUNT(tree_model); Account *account, *parent; gint i; - g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (model), FALSE); + g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(model), FALSE); g_return_val_if_fail (iter != NULL, FALSE); g_return_val_if_fail (iter->user_data != NULL, FALSE); g_return_val_if_fail (iter->stamp == model->stamp, FALSE); - ENTER("model %p, iter %s", tree_model, iter_to_string(iter)); + ENTER("model %p, iter %s", tree_model, iter_to_string (iter)); parent = (Account *) iter->user_data2; if (parent == NULL) @@ -824,7 +976,7 @@ gnc_tree_model_account_iter_next (GtkTreeModel *tree_model, } /* Get the *next* sibling account. */ - i = GPOINTER_TO_INT (iter->user_data3); + i = GPOINTER_TO_INT(iter->user_data3); account = gnc_account_nth_child (parent, i + 1); if (account == NULL) { @@ -835,9 +987,9 @@ gnc_tree_model_account_iter_next (GtkTreeModel *tree_model, iter->user_data = account; iter->user_data2 = parent; - iter->user_data3 = GINT_TO_POINTER (i + 1); + iter->user_data3 = GINT_TO_POINTER(i + 1); - LEAVE("iter %s", iter_to_string(iter)); + LEAVE("iter %s", iter_to_string (iter)); return TRUE; } @@ -850,11 +1002,11 @@ gnc_tree_model_account_iter_children (GtkTreeModel *tree_model, GncTreeModelAccount *model; Account *account, *parent; - g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (tree_model), FALSE); + g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(tree_model), FALSE); ENTER("model %p, iter %p (to be filed in), parent %s", - 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) @@ -869,9 +1021,9 @@ gnc_tree_model_account_iter_children (GtkTreeModel *tree_model, { iter->user_data = priv->root; iter->user_data2 = NULL; - iter->user_data3 = GINT_TO_POINTER (0); + iter->user_data3 = GINT_TO_POINTER(0); iter->stamp = model->stamp; - LEAVE("iter (2) %s", iter_to_string(iter)); + LEAVE("iter (2) %s", iter_to_string (iter)); return TRUE; } @@ -891,9 +1043,9 @@ gnc_tree_model_account_iter_children (GtkTreeModel *tree_model, iter->user_data = account; iter->user_data2 = parent; - iter->user_data3 = GINT_TO_POINTER (0); + iter->user_data3 = GINT_TO_POINTER(0); iter->stamp = model->stamp; - LEAVE("iter (3) %s", iter_to_string(iter)); + LEAVE("iter (3) %s", iter_to_string (iter)); return TRUE; } @@ -904,18 +1056,18 @@ gnc_tree_model_account_iter_has_child (GtkTreeModel *tree_model, GncTreeModelAccount *model; Account *account; - g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (tree_model), FALSE); + g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(tree_model), FALSE); - ENTER("model %p, iter %s", tree_model, iter_to_string(iter)); + ENTER("model %p, iter %s", tree_model, iter_to_string (iter)); - model = GNC_TREE_MODEL_ACCOUNT (tree_model); + model = GNC_TREE_MODEL_ACCOUNT(tree_model); gnc_leave_return_val_if_fail (iter != NULL, FALSE); gnc_leave_return_val_if_fail (iter->user_data != NULL, FALSE); gnc_leave_return_val_if_fail (iter->stamp == model->stamp, FALSE); account = (Account *) iter->user_data; - if (gnc_account_n_children(account) > 0) + if (gnc_account_n_children (account) > 0) { LEAVE("yes"); return TRUE; @@ -932,10 +1084,10 @@ gnc_tree_model_account_iter_n_children (GtkTreeModel *tree_model, GncTreeModelAccount *model; gint num; - g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (tree_model), FALSE); - ENTER("model %p, iter %s", tree_model, iter_to_string(iter)); + g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(tree_model), FALSE); + ENTER("model %p, iter %s", tree_model, iter_to_string (iter)); - model = GNC_TREE_MODEL_ACCOUNT (tree_model); + model = GNC_TREE_MODEL_ACCOUNT(tree_model); if (iter == NULL) { @@ -949,7 +1101,7 @@ gnc_tree_model_account_iter_n_children (GtkTreeModel *tree_model, gnc_leave_return_val_if_fail (iter->user_data != NULL, FALSE); gnc_leave_return_val_if_fail (iter->stamp == model->stamp, FALSE); - num = gnc_account_n_children(iter->user_data); + num = gnc_account_n_children (iter->user_data); LEAVE("count is %d", num); return num; } @@ -967,20 +1119,20 @@ gnc_tree_model_account_iter_nth_child (GtkTreeModel *tree_model, if (parent_iter) { gchar *parent_string; - parent_string = g_strdup(iter_to_string(parent_iter)); + parent_string = g_strdup (iter_to_string (parent_iter)); ENTER("model %p, iter %s, parent_iter %s, n %d", - tree_model, iter_to_string(iter), + tree_model, iter_to_string (iter), parent_string, n); - g_free(parent_string); + g_free (parent_string); } else { ENTER("model %p, iter %s, parent_iter (null), n %d", - tree_model, iter_to_string(iter), n); + tree_model, iter_to_string (iter), n); } - 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. */ @@ -994,9 +1146,9 @@ gnc_tree_model_account_iter_nth_child (GtkTreeModel *tree_model, iter->user_data = priv->root; iter->user_data2 = NULL; - iter->user_data3 = GINT_TO_POINTER (0); + iter->user_data3 = GINT_TO_POINTER(0); iter->stamp = model->stamp; - LEAVE("root %s", iter_to_string(iter)); + LEAVE("root %s", iter_to_string (iter)); return TRUE; } @@ -1004,7 +1156,7 @@ gnc_tree_model_account_iter_nth_child (GtkTreeModel *tree_model, gnc_leave_return_val_if_fail (parent_iter->stamp == model->stamp, FALSE); parent = (Account *)parent_iter->user_data; - account = gnc_account_nth_child(parent, n); + account = gnc_account_nth_child (parent, n); if (account == NULL) { iter->stamp = 0; @@ -1014,9 +1166,9 @@ gnc_tree_model_account_iter_nth_child (GtkTreeModel *tree_model, iter->user_data = account; iter->user_data2 = parent; - iter->user_data3 = GINT_TO_POINTER (n); + iter->user_data3 = GINT_TO_POINTER(n); iter->stamp = model->stamp; - LEAVE("iter (2) %s", iter_to_string(iter)); + LEAVE("iter (2) %s", iter_to_string (iter)); return TRUE; } @@ -1033,27 +1185,27 @@ gnc_tree_model_account_iter_parent (GtkTreeModel *tree_model, { gchar *child_string; - child_string = g_strdup(iter_to_string(child)); + child_string = g_strdup (iter_to_string (child)); ENTER("model %p, iter %s, child %s", - tree_model, iter_to_string(iter), + tree_model, iter_to_string (iter), child_string); - g_free(child_string); + g_free (child_string); } else { ENTER("model %p, iter %s, child (null)", - tree_model, iter_to_string(iter)); + tree_model, iter_to_string (iter)); } - 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); gnc_leave_return_val_if_fail (child != NULL, FALSE); gnc_leave_return_val_if_fail (child->user_data != NULL, FALSE); gnc_leave_return_val_if_fail (child->stamp == model->stamp, FALSE); account = (Account *) child->user_data; - account = gnc_account_get_parent(account); + account = gnc_account_get_parent (account); if (account == NULL) { /* Can't go up from the root node */ @@ -1062,7 +1214,7 @@ gnc_tree_model_account_iter_parent (GtkTreeModel *tree_model, return FALSE; } - parent = gnc_account_get_parent(account); + parent = gnc_account_get_parent (account); if (parent == NULL) { /* Now at the root. */ @@ -1070,13 +1222,13 @@ gnc_tree_model_account_iter_parent (GtkTreeModel *tree_model, } else { - i = gnc_account_child_index(parent, account); + i = gnc_account_child_index (parent, account); } iter->user_data = account; iter->user_data2 = parent; - iter->user_data3 = GINT_TO_POINTER (i); + iter->user_data3 = GINT_TO_POINTER(i); iter->stamp = model->stamp; - LEAVE("iter (2) %s", iter_to_string(iter)); + LEAVE("iter (2) %s", iter_to_string (iter)); return TRUE; } @@ -1093,7 +1245,7 @@ Account * gnc_tree_model_account_get_account (GncTreeModelAccount *model, GtkTreeIter *iter) { - g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (model), NULL); + g_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(model), NULL); g_return_val_if_fail (iter != NULL, NULL); g_return_val_if_fail (iter->user_data != NULL, NULL); g_return_val_if_fail (iter->stamp == model->stamp, NULL); @@ -1108,15 +1260,15 @@ gnc_tree_model_account_get_account (GncTreeModelAccount *model, */ gboolean gnc_tree_model_account_get_iter_from_account (GncTreeModelAccount *model, - Account *account, - GtkTreeIter *iter) + Account *account, + GtkTreeIter *iter) { GncTreeModelAccountPrivate *priv; Account *parent; gint i; ENTER("model %p, account %p, iter %p", model, account, iter); - gnc_leave_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (model), FALSE); + gnc_leave_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(model), FALSE); gnc_leave_return_val_if_fail ((account != NULL), FALSE); gnc_leave_return_val_if_fail ((iter != NULL), FALSE); @@ -1127,7 +1279,7 @@ gnc_tree_model_account_get_iter_from_account (GncTreeModelAccount *model, if (account == priv->root) { iter->user_data2 = NULL; - iter->user_data3 = GINT_TO_POINTER (0); + iter->user_data3 = GINT_TO_POINTER(0); LEAVE("Matched root"); return TRUE; } @@ -1138,11 +1290,11 @@ gnc_tree_model_account_get_iter_from_account (GncTreeModelAccount *model, return FALSE; } - parent = gnc_account_get_parent(account); - i = gnc_account_child_index(parent, account); + parent = gnc_account_get_parent (account); + i = gnc_account_child_index (parent, account); iter->user_data2 = parent; - iter->user_data3 = GINT_TO_POINTER (i); - LEAVE("iter %s", iter_to_string(iter)); + iter->user_data3 = GINT_TO_POINTER(i); + LEAVE("iter %s", iter_to_string (iter)); return (i != -1); } @@ -1153,13 +1305,13 @@ gnc_tree_model_account_get_iter_from_account (GncTreeModelAccount *model, */ GtkTreePath * gnc_tree_model_account_get_path_from_account (GncTreeModelAccount *model, - Account *account) + Account *account) { GtkTreeIter tree_iter; GtkTreePath *tree_path; ENTER("model %p, account %p", model, account); - gnc_leave_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT (model), NULL); + gnc_leave_return_val_if_fail (GNC_IS_TREE_MODEL_ACCOUNT(model), NULL); gnc_leave_return_val_if_fail (account != NULL, NULL); if (!gnc_tree_model_account_get_iter_from_account (model, account, @@ -1172,9 +1324,9 @@ gnc_tree_model_account_get_path_from_account (GncTreeModelAccount *model, tree_path = gtk_tree_model_get_path (GTK_TREE_MODEL(model), &tree_iter); if (tree_path) { - gchar *path_string = gtk_tree_path_to_string(tree_path); + gchar *path_string = gtk_tree_path_to_string (tree_path); LEAVE("path (2) %s", path_string); - g_free(path_string); + g_free (path_string); } else { @@ -1188,38 +1340,38 @@ gnc_tree_model_account_get_path_from_account (GncTreeModelAccount *model, /************************************************************/ static void -increment_stamp(GncTreeModelAccount *model) +increment_stamp (GncTreeModelAccount *model) { do model->stamp++; while (!model->stamp); } static void -propagate_change(GtkTreeModel *model, GtkTreePath *path, gint toggle_if_num) +propagate_change (GtkTreeModel *model, GtkTreePath *path, gint toggle_if_num) { GtkTreeIter iter; /* Already at the invisible root node? */ - if (!gtk_tree_path_up(path)) + if (!gtk_tree_path_up (path)) return; /* Did we just move up to the invisible root node? */ - if (gtk_tree_path_get_depth(path) == 0) + if (gtk_tree_path_get_depth (path) == 0) return; /* Handle the immediate parent */ - if (gtk_tree_model_get_iter(model, &iter, path)) + if (gtk_tree_model_get_iter (model, &iter, path)) { - gtk_tree_model_row_changed(model, path, &iter); - if (gtk_tree_model_iter_n_children(model, &iter) == toggle_if_num) - gtk_tree_model_row_has_child_toggled(model, path, &iter); + gtk_tree_model_row_changed (model, path, &iter); + if (gtk_tree_model_iter_n_children (model, &iter) == toggle_if_num) + gtk_tree_model_row_has_child_toggled (model, path, &iter); } /* All other ancestors */ - while (gtk_tree_path_up(path) && gtk_tree_path_get_depth(path) > 0 && - gtk_tree_model_get_iter(model, &iter, path)) + while (gtk_tree_path_up (path) && gtk_tree_path_get_depth (path) > 0 && + gtk_tree_model_get_iter (model, &iter, path)) { - gtk_tree_model_row_changed(model, path, &iter); + gtk_tree_model_row_changed (model, path, &iter); } } @@ -1263,7 +1415,8 @@ gnc_tree_model_account_event_handler (QofInstance *entity, GtkTreeIter iter; Account *account, *parent; - g_return_if_fail(model); /* Required */ + g_return_if_fail (model); /* Required */ + if (!GNC_IS_ACCOUNT(entity)) return; @@ -1272,12 +1425,16 @@ gnc_tree_model_account_event_handler (QofInstance *entity, priv = GNC_TREE_MODEL_ACCOUNT_GET_PRIVATE(model); account = GNC_ACCOUNT(entity); - if (gnc_account_get_book(account) != priv->book) + + /* clear the cached model values for account */ + gnc_tree_model_account_clear_cached_values (model, account); + + if (gnc_account_get_book (account) != priv->book) { LEAVE("not in this book"); return; } - if (gnc_account_get_root(account) != priv->root) + if (gnc_account_get_root (account) != priv->root) { LEAVE("not in this model"); return; @@ -1287,56 +1444,56 @@ gnc_tree_model_account_event_handler (QofInstance *entity, { case QOF_EVENT_ADD: /* Tell the filters/views where the new account was added. */ - DEBUG("add account %p (%s)", account, xaccAccountGetName(account)); - path = gnc_tree_model_account_get_path_from_account(model, account); + DEBUG("add account %p (%s)", account, xaccAccountGetName (account)); + path = gnc_tree_model_account_get_path_from_account (model, account); if (!path) { DEBUG("can't generate path"); break; } - increment_stamp(model); - if (!gnc_tree_model_account_get_iter(GTK_TREE_MODEL(model), &iter, path)) + increment_stamp (model); + if (!gnc_tree_model_account_get_iter (GTK_TREE_MODEL(model), &iter, path)) { DEBUG("can't generate iter"); break; } gtk_tree_model_row_inserted (GTK_TREE_MODEL(model), path, &iter); - propagate_change(GTK_TREE_MODEL(model), path, 1); + propagate_change (GTK_TREE_MODEL(model), path, 1); break; case QOF_EVENT_REMOVE: if (!ed) /* Required for a remove. */ break; parent = ed->node ? GNC_ACCOUNT(ed->node) : priv->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); - path = gnc_tree_model_account_get_path_from_account(model, parent); + path = gnc_tree_model_account_get_path_from_account (model, parent); if (!path) { DEBUG("can't generate path"); break; } - increment_stamp(model); + increment_stamp (model); gtk_tree_path_append_index (path, ed->idx); gtk_tree_model_row_deleted (GTK_TREE_MODEL(model), path); - propagate_change(GTK_TREE_MODEL(model), path, 0); + propagate_change (GTK_TREE_MODEL(model), path, 0); break; case QOF_EVENT_MODIFY: - DEBUG("modify account %p (%s)", account, xaccAccountGetName(account)); - path = gnc_tree_model_account_get_path_from_account(model, account); + DEBUG("modify account %p (%s)", account, xaccAccountGetName (account)); + path = gnc_tree_model_account_get_path_from_account (model, account); if (!path) { DEBUG("can't generate path"); break; } - if (!gnc_tree_model_account_get_iter(GTK_TREE_MODEL(model), &iter, path)) + if (!gnc_tree_model_account_get_iter (GTK_TREE_MODEL(model), &iter, path)) { DEBUG("can't generate iter"); break; } - gtk_tree_model_row_changed(GTK_TREE_MODEL(model), path, &iter); - propagate_change(GTK_TREE_MODEL(model), path, -1); + gtk_tree_model_row_changed (GTK_TREE_MODEL(model), path, &iter); + propagate_change (GTK_TREE_MODEL(model), path, -1); break; default: @@ -1345,7 +1502,7 @@ gnc_tree_model_account_event_handler (QofInstance *entity, } if (path) - gtk_tree_path_free(path); + gtk_tree_path_free (path); LEAVE(" "); return; } diff --git a/gnucash/gnome-utils/gnc-tree-model-account.h b/gnucash/gnome-utils/gnc-tree-model-account.h index 9561ad04ab..8d8337579f 100644 --- a/gnucash/gnome-utils/gnc-tree-model-account.h +++ b/gnucash/gnome-utils/gnc-tree-model-account.h @@ -1,6 +1,6 @@ /* * gnc-tree-model-account.h -- GtkTreeModel implementation to - * display accounts in a GtkTreeView. + * display accounts in a GtkTreeView. * * Copyright (C) 2003 Jan Arne Petersen * Copyright (C) 2003 David Hampton @@ -122,6 +122,11 @@ typedef struct */ GType gnc_tree_model_account_get_type (void); +/** Clear the tree model account cached values. + * + * @param model A pointer to the account tree model. + */ +void gnc_tree_model_account_clear_cache (GncTreeModelAccount *model); /** @name Account Tree Model Constructors @{ */ diff --git a/gnucash/gnome-utils/gnc-tree-view-account.c b/gnucash/gnome-utils/gnc-tree-view-account.c index 35fd96e0c0..d4d82756cc 100644 --- a/gnucash/gnome-utils/gnc-tree-view-account.c +++ b/gnucash/gnome-utils/gnc-tree-view-account.c @@ -1076,6 +1076,17 @@ gnc_tree_view_account_count_children (GncTreeViewAccount *view, return num_children; } +void +gnc_tree_view_account_clear_model_cache (GncTreeViewAccount *view) +{ + GtkTreeModel *model, *f_model, *s_model; + + s_model = gtk_tree_view_get_model (GTK_TREE_VIEW(view)); + f_model = gtk_tree_model_sort_get_model (GTK_TREE_MODEL_SORT(s_model)); + model = gtk_tree_model_filter_get_model (GTK_TREE_MODEL_FILTER(f_model)); + + gnc_tree_model_account_clear_cache (GNC_TREE_MODEL_ACCOUNT(model)); +} /************************************************************/ /* Account Tree View Filter Functions */ diff --git a/gnucash/gnome-utils/gnc-tree-view-account.h b/gnucash/gnome-utils/gnc-tree-view-account.h index 418a0ebda8..03daa8c661 100644 --- a/gnucash/gnome-utils/gnc-tree-view-account.h +++ b/gnucash/gnome-utils/gnc-tree-view-account.h @@ -346,6 +346,13 @@ void gnc_tree_view_account_refilter (GncTreeViewAccount *view); gint gnc_tree_view_account_count_children (GncTreeViewAccount *view, Account *account); +/** This function clears the tree model account cache so the values will + * be updated/refreshed. + * + * @param view A pointer to an account tree view. + * + */ +void gnc_tree_view_account_clear_model_cache (GncTreeViewAccount *view); /** This function returns the account associated with the specified diff --git a/gnucash/gnome/dialog-price-edit-db.c b/gnucash/gnome/dialog-price-edit-db.c index ef89a72e61..d6ce1d1b82 100644 --- a/gnucash/gnome/dialog-price-edit-db.c +++ b/gnucash/gnome/dialog-price-edit-db.c @@ -205,6 +205,7 @@ gnc_prices_dialog_remove_clicked (GtkWidget *widget, gpointer data) g_list_foreach(price_list, (GFunc)remove_helper, pdb_dialog->price_db); } g_list_free(price_list); + gnc_gui_refresh_all (); LEAVE(" "); } @@ -504,6 +505,7 @@ gnc_prices_dialog_remove_old_clicked (GtkWidget *widget, gpointer data) } g_list_free (comm_list); } + gnc_gui_refresh_all (); gtk_widget_destroy (pdb_dialog->remove_dialog); LEAVE(" "); } diff --git a/gnucash/gnome/gnc-plugin-page-account-tree.c b/gnucash/gnome/gnc-plugin-page-account-tree.c index 76b571b657..ecd5a2369b 100644 --- a/gnucash/gnome/gnc-plugin-page-account-tree.c +++ b/gnucash/gnome/gnc-plugin-page-account-tree.c @@ -602,6 +602,8 @@ gnc_plugin_page_account_refresh_cb (GHashTable *changes, gpointer user_data) return; priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page); + + gnc_tree_view_account_clear_model_cache (GNC_TREE_VIEW_ACCOUNT(priv->tree_view)); gtk_widget_queue_draw(priv->widget); } @@ -1671,6 +1673,8 @@ gnc_plugin_page_account_tree_cmd_refresh (GtkAction *action, g_return_if_fail(GNC_IS_PLUGIN_PAGE_ACCOUNT_TREE(page)); priv = GNC_PLUGIN_PAGE_ACCOUNT_TREE_GET_PRIVATE(page); + + gnc_tree_view_account_clear_model_cache (GNC_TREE_VIEW_ACCOUNT(priv->tree_view)); gtk_widget_queue_draw (priv->widget); } diff --git a/gnucash/report/html-style-sheet.scm b/gnucash/report/html-style-sheet.scm index 7852cb2859..d3aa5e46be 100644 --- a/gnucash/report/html-style-sheet.scm +++ b/gnucash/report/html-style-sheet.scm @@ -21,6 +21,7 @@ ;; Boston, MA 02110-1301, USA gnu@gnu.org ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +(use-modules (ice-9 match)) (use-modules (gnucash gettext)) (define *gnc:_style-sheet-templates_* (make-hash-table 23)) @@ -67,23 +68,15 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (define (gnc:define-html-style-sheet . args) - (let ((ss - ((record-constructor ) #f #f #f #f))) - (let loop ((left args)) - (if (and (list? left) - (not (null? left)) - (not (null? (cdr left)))) - (let* ((field (car left)) - (value (cadr left)) - (mod (record-modifier field))) - (mod ss value) - (loop (cddr left))))) - - ;; store the style sheet template - (hash-set! *gnc:_style-sheet-templates_* - (gnc:html-style-sheet-template-name ss) - ss))) - + (let loop ((args args) + (ss ((record-constructor ) #f #f #f #f))) + (match args + ((field value . rest) + ((record-modifier field) ss value) + (loop rest ss)) + (else ;; store the style sheet template + (hash-set! *gnc:_style-sheet-templates_* + (gnc:html-style-sheet-template-name ss) ss))))) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; methods diff --git a/gnucash/report/report-utilities.scm b/gnucash/report/report-utilities.scm index 294ae6503f..16d58e1f31 100644 --- a/gnucash/report/report-utilities.scm +++ b/gnucash/report/report-utilities.scm @@ -959,15 +959,8 @@ (format #f "[~a]" (gnc:monetary->string mon))) (define (owner->str owner) - (define owner-alist - (list (cons GNC-OWNER-NONE "None") - (cons GNC-OWNER-UNDEFINED "Undefined") - (cons GNC-OWNER-JOB "Job") - (cons GNC-OWNER-CUSTOMER "Cust") - (cons GNC-OWNER-VENDOR "Vend") - (cons GNC-OWNER-EMPLOYEE "Emp"))) (format #f "[~a:~a]" - (or (assv-ref owner-alist (gncOwnerGetType owner)) "Owner") + (gncOwnerGetTypeString owner) (gncOwnerGetName owner))) (define (invoice->str inv) (format #f "~a" @@ -978,6 +971,13 @@ (monetary->string (gnc:make-gnc-monetary (gncInvoiceGetCurrency inv) (gncInvoiceGetTotal inv))))) + (define (lot->str lot) + (format #f "Lot" + (gnc:strify (xaccAccountGetName (gnc-lot-get-account lot))) + (gnc-lot-get-title lot) + (gnc-lot-get-notes lot) + (gnc-lot-get-balance lot) + (gnc-lot-count-splits lot))) (define (try proc) ;; Try proc with d as a parameter, catching exceptions to return ;; #f to the (or) evaluator below. @@ -1008,6 +1008,7 @@ (try gnc-budget-get-name) (try owner->str) (try invoice->str) + (try lot->str) (object->string d))) (define (pair->num pair) diff --git a/gnucash/report/reports/aging.scm b/gnucash/report/reports/aging.scm index ca2b52d231..678f01431b 100644 --- a/gnucash/report/reports/aging.scm +++ b/gnucash/report/reports/aging.scm @@ -29,6 +29,9 @@ (use-modules (gnucash utilities)) (use-modules (gnucash gnc-module)) (use-modules (gnucash gettext)) +(eval-when (compile load eval expand) + (load-extension "libgncmod-gnome-utils" "scm_init_sw_gnome_utils_module")) +(use-modules (sw_gnome_utils)) (gnc:module-load "gnucash/report" 0) @@ -211,15 +214,18 @@ (if (not (gnc-commodity-equiv this-currency (company-get-currency company-info))) - (let ((error-str - (string-append "IGNORING TRANSACTION!\n" "Invoice Owner: " (gncOwnerGetName owner) - "\nTransaction GUID:" (gncTransGetGuid transaction) - "\nTransaction Currency" (gnc-commodity-get-mnemonic this-currency) - "\nClient Currency" (gnc-ommodity-get-mnemonic(company-get-currency company-info))))) - (gnc-error-dialog '() error-str) - (gnc:error error-str) - (cons #f (format - (_ "Transactions relating to '~a' contain \ + (let ((error-str + (string-append "IGNORING TRANSACTION!\n" "Invoice Owner: " (gnc:strify owner) + "\nTransaction:" (gnc:strify transaction) + "\nSplits are:\n" + (string-join + (map gnc:strify (xaccTransGetSplitList transaction)) + "\n") + "\nTransaction Currency:" (gnc:strify this-currency) + "\nClient Currency:" (gnc:strify (company-get-currency company-info))))) + (gnc-error-dialog '() error-str) + (gnc:error error-str) + (cons #f (format #f (_ "Transactions relating to '~a' contain \ more than one currency. This report is not designed to cope with this possibility.") (gncOwnerGetName owner)))) (begin (gnc:debug "it's an old company") diff --git a/gnucash/report/stylesheets/CMakeLists.txt b/gnucash/report/stylesheets/CMakeLists.txt index cf049f8307..ac83e6e233 100644 --- a/gnucash/report/stylesheets/CMakeLists.txt +++ b/gnucash/report/stylesheets/CMakeLists.txt @@ -1,9 +1,7 @@ set(stylesheets_SCHEME plain.scm - fancy.scm footer.scm - easy.scm head-or-tail.scm ) @@ -25,8 +23,8 @@ gnc_add_scheme_targets(scm-report-stylesheets-1 ) # Module interfaces deprecated in 4.x, will be removed for 5.x -gnc_add_scheme_deprecated_module ("gnucash report stylesheet-easy" "gnucash report stylesheets easy" "scm-report-stylesheets-1" "") -gnc_add_scheme_deprecated_module ("gnucash report stylesheet-fancy" "gnucash report stylesheets fancy" "scm-report-stylesheets-1" "") +gnc_add_scheme_deprecated_module ("gnucash report stylesheet-easy" "gnucash report stylesheets footer" "scm-report-stylesheets-1" "") +gnc_add_scheme_deprecated_module ("gnucash report stylesheet-fancy" "gnucash report stylesheets footer" "scm-report-stylesheets-1" "") gnc_add_scheme_deprecated_module ("gnucash report stylesheet-footer" "gnucash report stylesheets footer" "scm-report-stylesheets-1" "") gnc_add_scheme_deprecated_module ("gnucash report stylesheet-head-or-tail" "gnucash report stylesheets head-or-tail" "scm-report-stylesheets-1" "") gnc_add_scheme_deprecated_module ("gnucash report stylesheet-plain" "gnucash report stylesheets plain" "scm-report-stylesheets-1" "") diff --git a/gnucash/report/stylesheets/easy.scm b/gnucash/report/stylesheets/easy.scm deleted file mode 100644 index 8eaf8f8c3f..0000000000 --- a/gnucash/report/stylesheets/easy.scm +++ /dev/null @@ -1,394 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; stylesheet-easy.scm: stylesheet with nicer formatting for -;; printing and easier configurability -;; -;; Copyright 2004 James Strandboge -;; -;; 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 -;; -;; Based on work from: -;; stylesheet-header.scm -;; Copyright 2000 Bill Gribble -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - - -(define-module (gnucash report stylesheets easy)) - -(use-modules (gnucash utilities)) -(use-modules (gnucash gnc-module)) -(use-modules (gnucash gettext)) - -(gnc:module-load "gnucash/html" 0) -(gnc:module-load "gnucash/report" 0) - -(define (easy-options) - (let* ((options (gnc:new-options)) - (opt-register - (lambda (opt) - (gnc:register-option options opt)))) - (opt-register - (gnc:make-string-option - (N_ "General") - (N_ "Preparer") "a" - (N_ "Name of person preparing the report.") - "")) - (opt-register - (gnc:make-string-option - (N_ "General") - (N_ "Prepared for") "b" - (N_ "Name of organization or company prepared for.") - "")) - (opt-register - (gnc:make-simple-boolean-option - (N_ "General") - (N_ "Show preparer info") "c" - (N_ "Name of organization or company.") - #f)) - (opt-register - (gnc:make-simple-boolean-option - (N_ "General") - (N_ "Enable Links") "d" - (N_ "Enable hyperlinks in reports.") - #t)) - - (opt-register - (gnc:make-pixmap-option - (N_ "Images") - (N_ "Background Tile") "a" (N_ "Background tile for reports.") - "")) - (opt-register - (gnc:make-pixmap-option - (N_ "Images") - (N_ "Heading Banner") "b" (N_ "Banner for top of report.") - "")) - (opt-register - (gnc:make-multichoice-option - (N_ "Images") - (N_ "Heading Alignment") "c" (N_ "Banner for top of report.") - 'left - (list (vector 'left - (N_ "Left") - (N_ "Align the banner to the left.")) - (vector 'center - (N_ "Center") - (N_ "Align the banner in the center.")) - (vector 'right - (N_ "Right") - (N_ "Align the banner to the right.")) - ))) - (opt-register - (gnc:make-pixmap-option - (N_ "Images") - (N_ "Logo") "d" (N_ "Company logo image.") - "")) - - (opt-register - (gnc:make-color-option - (N_ "Colors") - (N_ "Background Color") "a" (N_ "General background color for report.") - (list #xff #xff #xff #xff) - 255 #f)) - - (opt-register - (gnc:make-color-option - (N_ "Colors") - (N_ "Text Color") "b" (N_ "Normal body text color.") - (list #x00 #x00 #x00 #xff) - 255 #f)) - - (opt-register - (gnc:make-color-option - (N_ "Colors") - (N_ "Link Color") "c" (N_ "Link text color.") - (list #xb2 #x22 #x22 #xff) - 255 #f)) - - (opt-register - (gnc:make-color-option - (N_ "Colors") - (N_ "Table Cell Color") "c" (N_ "Default background for table cells.") - (list #xff #xff #xff #xff) - 255 #f)) - - (opt-register - (gnc:make-color-option - (N_ "Colors") - (N_ "Alternate Table Cell Color") "d" - (N_ "Default alternate background for table cells.") - (list #xff #xff #xff #xff) - 255 #f)) - - (opt-register - (gnc:make-color-option - (N_ "Colors") - (N_ "Subheading/Subtotal Cell Color") "e" - (N_ "Default color for subtotal rows.") - (list #xee #xe8 #xaa #xff) - 255 #f)) - - (opt-register - (gnc:make-color-option - (N_ "Colors") - (N_ "Sub-subheading/total Cell Color") "f" - (N_ "Color for subsubtotals.") - (list #xfa #xfa #xd2 #xff) - 255 #f)) - - (opt-register - (gnc:make-color-option - (N_ "Colors") - (N_ "Grand Total Cell Color") "g" - (N_ "Color for grand totals.") - (list #xff #xff #x00 #xff) - 255 #f)) - - (opt-register - (gnc:make-number-range-option - (N_ "Tables") - (N_ "Table cell spacing") "a" (N_ "Space between table cells.") - 1 0 20 0 1)) - - (opt-register - (gnc:make-number-range-option - (N_ "Tables") - (N_ "Table cell padding") "b" (N_ "Space between table cell edge and content.") - 1 0 20 0 1)) - - (opt-register - (gnc:make-number-range-option - (N_ "Tables") - (N_ "Table border width") "c" (N_ "Bevel depth on tables.") - 1 0 20 0 1)) - (register-font-options options) - - options)) - -(define (easy-renderer options doc) - (let* ((ssdoc (gnc:make-html-document)) - (opt-val - (lambda (section name) - (gnc:option-value - (gnc:lookup-option options section name)))) - (color-val - (lambda (section name) - (gnc:color-option->html - (gnc:lookup-option options section name)))) - (preparer (opt-val "General" "Preparer")) - (prepared-for (opt-val "General" "Prepared for")) - (show-preparer? (opt-val "General" "Show preparer info")) - (links? (opt-val "General" "Enable Links")) - (bgcolor (color-val "Colors" "Background Color")) - (textcolor (color-val "Colors" "Text Color")) - (linkcolor (color-val "Colors" "Link Color")) - (normal-row-color (color-val "Colors" "Table Cell Color")) - (alternate-row-color (color-val "Colors" "Alternate Table Cell Color")) - (primary-subheading-color - (color-val "Colors" "Subheading/Subtotal Cell Color")) - (secondary-subheading-color - (color-val "Colors" "Sub-subheading/total Cell Color")) - (grand-total-color (color-val "Colors" "Grand Total Cell Color")) - (bgpixmap (opt-val "Images" "Background Tile")) - (headpixmap (opt-val "Images" "Heading Banner")) - (logopixmap (opt-val "Images" "Logo")) - (align (gnc:value->string (opt-val "Images" "Heading Alignment"))) - (spacing (opt-val "Tables" "Table cell spacing")) - (padding (opt-val "Tables" "Table cell padding")) - (border (opt-val "Tables" "Table border width")) - (headcolumn 0)) - - (gnc:html-document-set-style! - ssdoc "body" - 'attribute (list "bgcolor" bgcolor) - 'attribute (list "text" textcolor) - 'attribute (list "link" linkcolor)) -;;;; -;;;; -;;;; - (gnc:html-document-set-style! - ssdoc "column-heading-left" - 'tag "th" - 'attribute (list "class" "column-heading-left")) - - (gnc:html-document-set-style! - ssdoc "column-heading-center" - 'tag "th" - 'attribute (list "class" "column-heading-center")) - - (gnc:html-document-set-style! - ssdoc "column-heading-right" - 'tag "th" - 'attribute (list "class" "column-heading-right")) - - (gnc:html-document-set-style! - ssdoc "date-cell" - 'tag "td" - 'attribute (list "class" "date-cell")) - - (gnc:html-document-set-style! - ssdoc "anchor-cell" - 'tag "td" - 'attribute (list "class" "anchor-cell")) - - (gnc:html-document-set-style! - ssdoc "number-cell" - 'tag "td" - 'attribute (list "class" "number-cell")) - - (gnc:html-document-set-style! - ssdoc "number-cell-neg" - 'tag "td" - 'attribute (list "class" "number-cell neg")) - - (gnc:html-document-set-style! - ssdoc "number-header" - 'tag "th" - 'attribute (list "class" "number-header")) - - (gnc:html-document-set-style! - ssdoc "text-cell" - 'tag "td" - 'attribute (list "class" "text-cell")) - - (gnc:html-document-set-style! - ssdoc "total-number-cell" - 'tag '("td") - 'attribute (list "class" "total-number-cell")) - - (gnc:html-document-set-style! - ssdoc "total-number-cell-neg" - 'tag '("td") - 'attribute (list "class" "total-number-cell neg")) - - (gnc:html-document-set-style! - ssdoc "total-label-cell" - 'tag '("td") - 'attribute (list "class" "total-label-cell")) - - (gnc:html-document-set-style! - ssdoc "centered-label-cell" - 'tag '("td") - 'attribute (list "class" "centered-label-cell")) - - (if (and bgpixmap - (not (string=? bgpixmap ""))) - (gnc:html-document-set-style! - ssdoc "body" - 'attribute (list "background" (make-file-url bgpixmap)))) - - (gnc:html-document-set-style! - ssdoc "table" - 'attribute (list "border" border) - 'attribute (list "cellspacing" spacing) - 'attribute (list "cellpadding" padding)) - - (gnc:html-document-set-style! - ssdoc "normal-row" - 'attribute (list "bgcolor" normal-row-color) - 'tag "tr") - (gnc:html-document-set-style! - ssdoc "alternate-row" - 'attribute (list "bgcolor" alternate-row-color) - 'tag "tr") - (gnc:html-document-set-style! - ssdoc "primary-subheading" - 'attribute (list "bgcolor" primary-subheading-color) - 'tag "tr") - (gnc:html-document-set-style! - ssdoc "secondary-subheading" - 'attribute (list "bgcolor" secondary-subheading-color) - 'tag "tr") - (gnc:html-document-set-style! - ssdoc "grand-total" - 'attribute (list "bgcolor" grand-total-color) - 'tag "tr") - - ;; don't surround marked-up links with - (if (not links?) - (gnc:html-document-set-style! - ssdoc "a" 'tag "")) - - (add-css-information-to-doc options ssdoc doc) - - (let ((t (gnc:make-html-table))) - ;; we don't want a bevel for this table, but we don't want - ;; that to propagate - (gnc:html-table-set-style! - t "table" - 'attribute (list "border" 0) - 'attribute (list "style" "margin-left:auto; margin-right:auto") - 'inheritable? #f) - - ;; set the header column to be the 2nd when we have a logo - ;; do this so that when logo is not present, the document - ;; is perfectly centered - (if (and logopixmap (> (string-length logopixmap) 0)) - (set! headcolumn 1)) - - (let* ((headline (or (gnc:html-document-headline doc) - (gnc:html-document-title doc)))) - - (gnc:html-table-set-cell! - t 1 headcolumn - (if show-preparer? - ;; title plus preparer info - (gnc:make-html-text - (gnc:html-markup-h3 headline) - (gnc:html-markup-br) - (_ "Prepared by: ") - (gnc:html-markup-b preparer) - (gnc:html-markup-br) - (_ "Prepared for: ") - (gnc:html-markup-b prepared-for) - (gnc:html-markup-br) - (_ "Date: ") - (qof-print-date - (current-time))) - - ;; title only - (gnc:make-html-text - (gnc:html-markup-h3 headline)))) - ) - - ;; only setup an image if we specified one - (if (and logopixmap (> (string-length logopixmap) 0)) - (gnc:html-table-set-cell! - t 0 0 - (gnc:make-html-text - (gnc:html-markup-img (make-file-url logopixmap))))) - - (if (and headpixmap (> (string-length headpixmap) 0)) - (let* ((div (gnc:html-markup-img (make-file-url headpixmap))) - (cell (gnc:make-html-table-cell (gnc:make-html-text div)))) - (gnc:html-table-cell-set-style! cell "td" 'attribute `("align" ,align)) - (gnc:html-table-set-cell! t 0 headcolumn cell)) - (gnc:html-table-set-cell! t 0 headcolumn (gnc:make-html-text " "))) - - (apply - gnc:html-table-set-cell! - t 2 headcolumn - (gnc:html-document-objects doc)) - (gnc:html-document-add-object! ssdoc t)) - ssdoc)) - -(gnc:define-html-style-sheet - 'version 1 - 'name (N_ "Easy") - 'renderer easy-renderer - 'options-generator easy-options) - -(gnc:make-html-style-sheet "Easy" (N_ "Easy")) diff --git a/gnucash/report/stylesheets/fancy.scm b/gnucash/report/stylesheets/fancy.scm deleted file mode 100644 index 39b1f0adb2..0000000000 --- a/gnucash/report/stylesheets/fancy.scm +++ /dev/null @@ -1,388 +0,0 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; stylesheet-header.scm : stylesheet with nicer layout -;; Copyright 2000 Bill Gribble -;; -;; 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 -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - - -(define-module (gnucash report stylesheets fancy)) - -(use-modules (gnucash utilities)) -(use-modules (gnucash gnc-module)) -(use-modules (gnucash gettext)) - -(gnc:module-load "gnucash/html" 0) -(gnc:module-load "gnucash/report" 0) - -(define (fancy-options) - (let* ((options (gnc:new-options)) - (opt-register - (lambda (opt) - (gnc:register-option options opt)))) - (opt-register - (gnc:make-string-option - (N_ "General") - (N_ "Preparer") "a" - (N_ "Name of person preparing the report.") - "")) - (opt-register - (gnc:make-string-option - (N_ "General") - (N_ "Prepared for") "b" - (N_ "Name of organization or company prepared for.") - "")) - (opt-register - (gnc:make-simple-boolean-option - (N_ "General") - (N_ "Show preparer info") "c" - (N_ "Name of organization or company.") - #f)) - (opt-register - (gnc:make-simple-boolean-option - (N_ "General") - (N_ "Enable Links") "d" - (N_ "Enable hyperlinks in reports.") - #t)) - - (opt-register - (gnc:make-pixmap-option - (N_ "Images") - (N_ "Background Tile") "a" (N_ "Background tile for reports.") - "")) - (opt-register - (gnc:make-pixmap-option - (N_ "Images") - (N_ "Heading Banner") "b" (N_ "Banner for top of report.") - "")) - (opt-register - (gnc:make-multichoice-option - (N_ "Images") - (N_ "Heading Alignment") "c" (N_ "Banner for top of report.") - 'left - (list (vector 'left - (N_ "Left") - (N_ "Align the banner to the left.")) - (vector 'center - (N_ "Center") - (N_ "Align the banner in the center.")) - (vector 'right - (N_ "Right") - (N_ "Align the banner to the right.")) - ))) - (opt-register - (gnc:make-pixmap-option - (N_ "Images") - (N_ "Logo") "d" (N_ "Company logo image.") - "")) - - (opt-register - (gnc:make-color-option - (N_ "Colors") - (N_ "Background Color") "a" (N_ "General background color for report.") - (list #xff #xff #xff #xff) - 255 #f)) - - (opt-register - (gnc:make-color-option - (N_ "Colors") - (N_ "Text Color") "b" (N_ "Normal body text color.") - (list #x00 #x00 #x00 #xff) - 255 #f)) - - (opt-register - (gnc:make-color-option - (N_ "Colors") - (N_ "Link Color") "c" (N_ "Link text color.") - (list #xb2 #x22 #x22 #xff) - 255 #f)) - - (opt-register - (gnc:make-color-option - (N_ "Colors") - (N_ "Table Cell Color") "c" (N_ "Default background for table cells.") - (list #xff #xff #xff #xff) - 255 #f)) - - (opt-register - (gnc:make-color-option - (N_ "Colors") - (N_ "Alternate Table Cell Color") "d" - (N_ "Default alternate background for table cells.") - (list #xff #xff #xff #xff) - 255 #f)) - - (opt-register - (gnc:make-color-option - (N_ "Colors") - (N_ "Subheading/Subtotal Cell Color") "e" - (N_ "Default color for subtotal rows.") - (list #xee #xe8 #xaa #xff) - 255 #f)) - - (opt-register - (gnc:make-color-option - (N_ "Colors") - (N_ "Sub-subheading/total Cell Color") "f" - (N_ "Color for subsubtotals.") - (list #xfa #xfa #xd2 #xff) - 255 #f)) - - (opt-register - (gnc:make-color-option - (N_ "Colors") - (N_ "Grand Total Cell Color") "g" - (N_ "Color for grand totals.") - (list #xff #xff #x00 #xff) - 255 #f)) - - (opt-register - (gnc:make-number-range-option - (N_ "Tables") - (N_ "Table cell spacing") "a" (N_ "Space between table cells.") - 1 0 20 0 1)) - - (opt-register - (gnc:make-number-range-option - (N_ "Tables") - (N_ "Table cell padding") "b" (N_ "Space between table cell edge and content.") - 1 0 20 0 1)) - - (opt-register - (gnc:make-number-range-option - (N_ "Tables") - (N_ "Table border width") "c" (N_ "Bevel depth on tables.") - 1 0 20 0 1)) - (register-font-options options) - - options)) - -(define (fancy-renderer options doc) - (let* ((ssdoc (gnc:make-html-document)) - (opt-val - (lambda (section name) - (gnc:option-value - (gnc:lookup-option options section name)))) - (color-val - (lambda (section name) - (gnc:color-option->html - (gnc:lookup-option options section name)))) - (preparer (opt-val "General" "Preparer")) - (prepared-for (opt-val "General" "Prepared for")) - (show-preparer? (opt-val "General" "Show preparer info")) - (links? (opt-val "General" "Enable Links")) - (bgcolor (color-val "Colors" "Background Color")) - (textcolor (color-val "Colors" "Text Color")) - (linkcolor (color-val "Colors" "Link Color")) - (normal-row-color (color-val "Colors" "Table Cell Color")) - (alternate-row-color (color-val "Colors" "Alternate Table Cell Color")) - (primary-subheading-color - (color-val "Colors" "Subheading/Subtotal Cell Color")) - (secondary-subheading-color - (color-val "Colors" "Sub-subheading/total Cell Color")) - (grand-total-color (color-val "Colors" "Grand Total Cell Color")) - (bgpixmap (opt-val "Images" "Background Tile")) - (headpixmap (opt-val "Images" "Heading Banner")) - (logopixmap (opt-val "Images" "Logo")) - (align (gnc:value->string (opt-val "Images" "Heading Alignment"))) - (spacing (opt-val "Tables" "Table cell spacing")) - (padding (opt-val "Tables" "Table cell padding")) - (border (opt-val "Tables" "Table border width")) - (headcolumn 0)) - - (gnc:html-document-set-style! - ssdoc "body" - 'attribute (list "bgcolor" bgcolor) - 'attribute (list "text" textcolor) - 'attribute (list "link" linkcolor)) -;;;; -;;;; -;;;; - (gnc:html-document-set-style! - ssdoc "column-heading-left" - 'tag "th" - 'attribute (list "class" "column-heading-left")) - - (gnc:html-document-set-style! - ssdoc "column-heading-center" - 'tag "th" - 'attribute (list "class" "column-heading-center")) - - (gnc:html-document-set-style! - ssdoc "column-heading-right" - 'tag "th" - 'attribute (list "class" "column-heading-right")) - - (gnc:html-document-set-style! - ssdoc "date-cell" - 'tag "td" - 'attribute (list "class" "date-cell")) - - (gnc:html-document-set-style! - ssdoc "anchor-cell" - 'tag "td" - 'attribute (list "class" "anchor-cell")) - - (gnc:html-document-set-style! - ssdoc "number-cell" - 'tag "td" - 'attribute (list "class" "number-cell")) - - (gnc:html-document-set-style! - ssdoc "number-cell-neg" - 'tag "td" - 'attribute (list "class" "number-cell neg")) - - (gnc:html-document-set-style! - ssdoc "number-header" - 'tag "th" - 'attribute (list "class" "number-header")) - - (gnc:html-document-set-style! - ssdoc "text-cell" - 'tag "td" - 'attribute (list "class" "text-cell")) - - (gnc:html-document-set-style! - ssdoc "total-number-cell" - 'tag '("td") - 'attribute (list "class" "total-number-cell")) - - (gnc:html-document-set-style! - ssdoc "total-number-cell-neg" - 'tag '("td") - 'attribute (list "class" "total-number-cell neg")) - - (gnc:html-document-set-style! - ssdoc "total-label-cell" - 'tag '("td") - 'attribute (list "class" "total-label-cell")) - - (gnc:html-document-set-style! - ssdoc "centered-label-cell" - 'tag '("td") - 'attribute (list "class" "centered-label-cell")) - - (if (and bgpixmap - (not (string=? bgpixmap ""))) - (gnc:html-document-set-style! - ssdoc "body" - 'attribute (list "background" (make-file-url bgpixmap)))) - - (gnc:html-document-set-style! - ssdoc "table" - 'attribute (list "border" border) - 'attribute (list "cellspacing" spacing) - 'attribute (list "cellpadding" padding)) - - (gnc:html-document-set-style! - ssdoc "normal-row" - 'attribute (list "bgcolor" normal-row-color) - 'tag "tr") - (gnc:html-document-set-style! - ssdoc "alternate-row" - 'attribute (list "bgcolor" alternate-row-color) - 'tag "tr") - (gnc:html-document-set-style! - ssdoc "primary-subheading" - 'attribute (list "bgcolor" primary-subheading-color) - 'tag "tr") - (gnc:html-document-set-style! - ssdoc "secondary-subheading" - 'attribute (list "bgcolor" secondary-subheading-color) - 'tag "tr") - (gnc:html-document-set-style! - ssdoc "grand-total" - 'attribute (list "bgcolor" grand-total-color) - 'tag "tr") - - ;; don't surround marked-up links with - (if (not links?) - (gnc:html-document-set-style! - ssdoc "a" 'tag "")) - - (add-css-information-to-doc options ssdoc doc) - - (let ((t (gnc:make-html-table))) - ;; we don't want a bevel for this table, but we don't want - ;; that to propagate - (gnc:html-table-set-style! - t "table" - 'attribute (list "border" 0) - 'attribute (list "style" "margin-left:auto; margin-right:auto") - 'inheritable? #f) - - ;; set the header column to be the 2nd when we have a logo - ;; do this so that when logo is not present, the document - ;; is perfectly centered - (if (and logopixmap (> (string-length logopixmap) 0)) - (set! headcolumn 1)) - - (let* ((headline (or (gnc:html-document-headline doc) - (gnc:html-document-title doc)))) - - (gnc:html-table-set-cell! - t 1 headcolumn - (if show-preparer? - ;; title plus preparer info - (gnc:make-html-text - (gnc:html-markup-h3 headline) - (gnc:html-markup-br) - (_ "Prepared by: ") - (gnc:html-markup-b preparer) - (gnc:html-markup-br) - (_ "Prepared for: ") - (gnc:html-markup-b prepared-for) - (gnc:html-markup-br) - (_ "Date: ") - (qof-print-date - (current-time))) - - ;; title only - (gnc:make-html-text - (gnc:html-markup-h3 headline)))) - ) - - ;; only setup an image if we specified one - (if (and logopixmap (> (string-length logopixmap) 0)) - (gnc:html-table-set-cell! - t 0 0 - (gnc:make-html-text - (gnc:html-markup-img (make-file-url logopixmap))))) - - (if (and headpixmap (> (string-length headpixmap) 0)) - (let* ((div (gnc:html-markup-img (make-file-url headpixmap))) - (cell (gnc:make-html-table-cell (gnc:make-html-text div)))) - (gnc:html-table-cell-set-style! cell "td" 'attribute `("align" ,align)) - (gnc:html-table-set-cell! t 0 headcolumn cell)) - (gnc:html-table-set-cell! t 0 headcolumn (gnc:make-html-text " "))) - - (apply - gnc:html-table-set-cell! - t 2 headcolumn - (gnc:html-document-objects doc)) - (gnc:html-document-add-object! ssdoc t)) - ssdoc)) - -(gnc:define-html-style-sheet - 'version 1.01 - 'name (N_ "Fancy") - 'renderer fancy-renderer - 'options-generator fancy-options) - -(gnc:make-html-style-sheet "Fancy" (N_ "Technicolor")) diff --git a/gnucash/report/stylesheets/footer.scm b/gnucash/report/stylesheets/footer.scm index 78d1fc1ed9..70f0a542d9 100644 --- a/gnucash/report/stylesheets/footer.scm +++ b/gnucash/report/stylesheets/footer.scm @@ -27,6 +27,8 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; +;; Merged with easy/fancy/footer stylesheets +;; by Christopher Lam in 2019 ;; Modified by Graham Billiau to include a text footer ;; with small adjustments by Frank H. Ellenberger 2010 ; @@ -41,36 +43,40 @@ (gnc:module-load "gnucash/html" 0) (gnc:module-load "gnucash/report" 0) -(define (footer-options) +(define (easy-fancy-footer-options) (let* ((options (gnc:new-options)) (opt-register (lambda (opt) (gnc:register-option options opt)))) + (opt-register (gnc:make-string-option (N_ "General") (N_ "Preparer") "a" (N_ "Name of person preparing the report.") "")) + (opt-register (gnc:make-string-option (N_ "General") (N_ "Prepared for") "b" (N_ "Name of organization or company prepared for.") "")) + (opt-register (gnc:make-simple-boolean-option (N_ "General") (N_ "Show preparer info") "c" (N_ "Name of organization or company.") #f)) + (opt-register (gnc:make-simple-boolean-option (N_ "General") (N_ "Enable Links") "d" (N_ "Enable hyperlinks in reports.") #t)) - ;; FIXME: put this in a more sensible tab like Text or Header/Footer + (opt-register (gnc:make-text-option (N_ "General") @@ -83,12 +89,14 @@ (N_ "Images") (N_ "Background Tile") "a" (N_ "Background tile for reports.") "")) + (opt-register (gnc:make-pixmap-option (N_ "Images") ;;; Translators: Banner is an image like Logo. (N_ "Heading Banner") "b" (N_ "Banner for top of report.") "")) + (opt-register (gnc:make-multichoice-option (N_ "Images") @@ -102,8 +110,8 @@ (N_ "Align the banner in the center.")) (vector 'right (N_ "Right") - (N_ "Align the banner to the right.")) - ))) + (N_ "Align the banner to the right."))))) + (opt-register (gnc:make-pixmap-option (N_ "Images") @@ -191,7 +199,7 @@ options)) -(define (footer-renderer options doc) +(define (easy-fancy-footer-renderer options doc) (let* ((ssdoc (gnc:make-html-document)) (opt-val (lambda (section name) @@ -222,8 +230,7 @@ (align (gnc:value->string (opt-val "Images" "Heading Alignment"))) (spacing (opt-val "Tables" "Table cell spacing")) (padding (opt-val "Tables" "Table cell padding")) - (border (opt-val "Tables" "Table border width")) - (headcolumn 0)) + (border (opt-val "Tables" "Table border width"))) (gnc:html-document-set-style! ssdoc "body" @@ -314,18 +321,22 @@ ssdoc "normal-row" 'attribute (list "bgcolor" normal-row-color) 'tag "tr") + (gnc:html-document-set-style! ssdoc "alternate-row" 'attribute (list "bgcolor" alternate-row-color) 'tag "tr") + (gnc:html-document-set-style! ssdoc "primary-subheading" 'attribute (list "bgcolor" primary-subheading-color) 'tag "tr") + (gnc:html-document-set-style! ssdoc "secondary-subheading" 'attribute (list "bgcolor" secondary-subheading-color) 'tag "tr") + (gnc:html-document-set-style! ssdoc "grand-total" 'attribute (list "bgcolor" grand-total-color) @@ -338,7 +349,13 @@ (add-css-information-to-doc options ssdoc doc) - (let ((t (gnc:make-html-table))) + (let ((t (gnc:make-html-table)) + ;; set the header column to be the 2nd when we have a logo + ;; do this so that when logo is not present, the document is + ;; perfectly centered + (headcolumn (if (and logopixmap (> (string-length logopixmap) 0)) + 1 0))) + ;; we don't want a bevel for this table, but we don't want ;; that to propagate (gnc:html-table-set-style! @@ -347,12 +364,6 @@ 'attribute (list "style" "margin-left:auto; margin-right:auto") 'inheritable? #f) - ;; set the header column to be the 2nd when we have a logo - ;; do this so that when logo is not present, the document - ;; is perfectly centered - (if (and logopixmap (> (string-length logopixmap) 0)) - (set! headcolumn 1)) - (let* ((headline (or (gnc:html-document-headline doc) (gnc:html-document-title doc)))) @@ -375,8 +386,7 @@ ;; title only (gnc:make-html-text - (gnc:html-markup-h3 headline)))) - ) + (gnc:html-markup-h3 headline))))) ;; only setup an image if we specified one (if (and logopixmap (> (string-length logopixmap) 0)) @@ -396,9 +406,9 @@ gnc:html-table-set-cell! t 2 headcolumn (gnc:html-document-objects doc)) + (gnc:html-document-add-object! ssdoc t) - ;; I think this is the correct place to put the footer (gnc:html-table-set-cell! t 3 headcolumn (gnc:make-html-text footer-text))) @@ -406,8 +416,22 @@ (gnc:define-html-style-sheet 'version 1 - 'name (N_ "Footer") - 'renderer footer-renderer - 'options-generator footer-options) + 'name (N_ "Easy") + 'renderer easy-fancy-footer-renderer + 'options-generator easy-fancy-footer-options) +(gnc:define-html-style-sheet + 'version 1.01 + 'name (N_ "Fancy") + 'renderer easy-fancy-footer-renderer + 'options-generator easy-fancy-footer-options) + +(gnc:define-html-style-sheet + 'version 1 + 'name (N_ "Footer") + 'renderer easy-fancy-footer-renderer + 'options-generator easy-fancy-footer-options) + +(gnc:make-html-style-sheet "Easy" (N_ "Easy")) +(gnc:make-html-style-sheet "Fancy" (N_ "Technicolor")) (gnc:make-html-style-sheet "Footer" (N_ "Footer")) diff --git a/libgnucash/engine/gncOwner.c b/libgnucash/engine/gncOwner.c index 53e648edb9..93a8211e57 100644 --- a/libgnucash/engine/gncOwner.c +++ b/libgnucash/engine/gncOwner.c @@ -204,6 +204,29 @@ GncOwnerType gncOwnerGetType (const GncOwner *owner) return owner->type; } +const char * gncOwnerGetTypeString (const GncOwner *owner) +{ + GncOwnerType type = gncOwnerGetType(owner); + switch (type) + { + case GNC_OWNER_NONE: + return "None"; + case GNC_OWNER_UNDEFINED: + return "Undefined"; + case GNC_OWNER_CUSTOMER: + return "Customer"; + case GNC_OWNER_JOB: + return "Job"; + case GNC_OWNER_VENDOR: + return "Vendor"; + case GNC_OWNER_EMPLOYEE: + return "Employee"; + default: + PWARN ("Unknown owner type"); + return NULL; + } +} + QofIdTypeConst qofOwnerGetType(const GncOwner *owner) { diff --git a/libgnucash/engine/gncOwner.h b/libgnucash/engine/gncOwner.h index 28251ac335..c66d60fe5a 100644 --- a/libgnucash/engine/gncOwner.h +++ b/libgnucash/engine/gncOwner.h @@ -65,6 +65,8 @@ to QOF as they can be used by objects like GncInvoice. */ /** return the type for the collection. */ QofIdTypeConst qofOwnerGetType(const GncOwner *owner); +/** return the type for the owner as an untranslated string. */ +const char * gncOwnerGetTypeString (const GncOwner *owner); /** return the owner itself as an entity. */ QofInstance* qofOwnerGetOwner (const GncOwner *owner); /** set the owner from the entity. */ diff --git a/po/POTFILES.in b/po/POTFILES.in index ddf68e2730..d421ddbe7a 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -495,8 +495,6 @@ gnucash/report/reports/support/receipt.eguile.scm gnucash/report/reports/support/taxinvoice.eguile.scm gnucash/report/report.scm gnucash/report/report-utilities.scm -gnucash/report/stylesheets/easy.scm -gnucash/report/stylesheets/fancy.scm gnucash/report/stylesheets/footer.scm gnucash/report/stylesheets/head-or-tail.scm gnucash/report/stylesheets/plain.scm