mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Use the stable sort function from Account.c to back up the user
selected primary sort column. Fixes 334595. Also collapse common code, pull strings via the model, and use the utf8 collate function instead of strcmp. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13653 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
15
ChangeLog
15
ChangeLog
@@ -1,3 +1,18 @@
|
||||
2006-03-16 David Hampton <hampton@employees.org>
|
||||
|
||||
* src/gnome-utils/gnc-tree-view-account.c:
|
||||
* src/gnome-utils/gnc-tree-view-commodity.c:
|
||||
* src/gnome-utils/gnc-tree-view-price.c:
|
||||
* src/gnome-utils/gnc-tree-view.c: Use the stable sort function
|
||||
from Account.c to back up the user selected primary sort
|
||||
column. Fixes 334595. Also collapse common code, pull strings via
|
||||
the model, and use the utf8 collate function instead of strcmp.
|
||||
|
||||
* src/gnome-utils/gnc-tree-model-account.c:
|
||||
* src/engine/Account.[ch]:
|
||||
* src/engine/Recurrence.c: Collapse duplicated code into a single
|
||||
function.
|
||||
|
||||
2006-03-16 Andreas Köhler <andi5.py@gmx.net>
|
||||
|
||||
* src/gnome/dialog-commodities.c:
|
||||
|
||||
@@ -39,9 +39,11 @@
|
||||
|
||||
#include "Account.h"
|
||||
#include "Group.h"
|
||||
#include "gnc-accounting-period.h"
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-component-manager.h"
|
||||
#include "gnc-engine.h"
|
||||
#include "gnc-glib-utils.h"
|
||||
#include "gnc-gobject-utils.h"
|
||||
#include "gnc-hooks.h"
|
||||
#include "gnc-session.h"
|
||||
@@ -230,6 +232,81 @@ gnc_tree_view_account_placeholder_toggled (GtkCellRendererToggle *cell,
|
||||
/* sort functions */
|
||||
/************************************************************/
|
||||
|
||||
static GtkTreeModel *
|
||||
sort_cb_setup_w_iters (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
GtkTreeIter *f_iter_b,
|
||||
GtkTreeIter *iter_a,
|
||||
GtkTreeIter *iter_b,
|
||||
const Account **account_a,
|
||||
const Account **account_b)
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
|
||||
model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model));
|
||||
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER(f_model),
|
||||
iter_a,
|
||||
f_iter_a);
|
||||
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER(f_model),
|
||||
iter_b,
|
||||
f_iter_b);
|
||||
*account_a = gnc_tree_model_account_get_account (GNC_TREE_MODEL_ACCOUNT(model), iter_a);
|
||||
*account_b = gnc_tree_model_account_get_account (GNC_TREE_MODEL_ACCOUNT(model), iter_b);
|
||||
return model;
|
||||
}
|
||||
|
||||
static void
|
||||
sort_cb_setup (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
GtkTreeIter *f_iter_b,
|
||||
const Account **account_a,
|
||||
const Account **account_b)
|
||||
{
|
||||
GtkTreeIter iter_a, iter_b;
|
||||
|
||||
sort_cb_setup_w_iters (f_model, f_iter_a, f_iter_b,
|
||||
&iter_a, &iter_b, account_a, account_b);
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_by_string (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter1,
|
||||
GtkTreeIter *f_iter2,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter1, iter2;
|
||||
const Account *account1, *account2;
|
||||
const gchar *str1, *str2;
|
||||
gint column = GPOINTER_TO_INT(user_data);
|
||||
gint result;
|
||||
|
||||
model = sort_cb_setup_w_iters(f_model, f_iter1, f_iter2, &iter1, &iter2, &account1, &account2);
|
||||
|
||||
/* Get the strings. */
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(model), &iter1, column, &str1, -1);
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(model), &iter2, column, &str2, -1);
|
||||
|
||||
result = safe_utf8_collate(str1, str2);
|
||||
if (result != 0)
|
||||
return result;
|
||||
return xaccAccountOrder(&account1, &account2);
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_by_code (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
GtkTreeIter *f_iter_b,
|
||||
gpointer user_data)
|
||||
{
|
||||
const Account *account_a, *account_b;
|
||||
|
||||
sort_cb_setup (f_model, f_iter_a, f_iter_b, &account_a, &account_b);
|
||||
|
||||
/* Default ordering uses this column first. */
|
||||
return xaccAccountOrder(&account_a, &account_b);
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_by_xxx_value (xaccGetBalanceInCurrencyFn fn,
|
||||
gboolean recurse,
|
||||
@@ -238,28 +315,21 @@ sort_by_xxx_value (xaccGetBalanceInCurrencyFn fn,
|
||||
GtkTreeIter *f_iter_b,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
Account *account;
|
||||
const Account *account_a, *account_b;
|
||||
gnc_numeric balance_a, balance_b;
|
||||
gint result;
|
||||
|
||||
model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model));
|
||||
/* Find the accounts */
|
||||
sort_cb_setup (f_model, f_iter_a, f_iter_b, &account_a, &account_b);
|
||||
|
||||
/* Get balance 1 */
|
||||
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER(f_model),
|
||||
&iter,
|
||||
f_iter_a);
|
||||
account = gnc_tree_model_account_get_account (GNC_TREE_MODEL_ACCOUNT(model), &iter);
|
||||
balance_a = gnc_ui_account_get_balance_full(fn, account, recurse, NULL, NULL);
|
||||
/* Get balances */
|
||||
balance_a = gnc_ui_account_get_balance_full(fn, account_a, recurse, NULL, NULL);
|
||||
balance_b = gnc_ui_account_get_balance_full(fn, account_b, recurse, NULL, NULL);
|
||||
|
||||
/* Get balance 2 */
|
||||
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER(f_model),
|
||||
&iter,
|
||||
f_iter_b);
|
||||
account = gnc_tree_model_account_get_account (GNC_TREE_MODEL_ACCOUNT(model), &iter);
|
||||
balance_b = gnc_ui_account_get_balance_full(fn, account, recurse, NULL, NULL);
|
||||
|
||||
return gnc_numeric_compare(balance_a, balance_b);
|
||||
result = gnc_numeric_compare(balance_a, balance_b);
|
||||
if (result != 0)
|
||||
return result;
|
||||
return xaccAccountOrder(&account_a, &account_b);
|
||||
}
|
||||
|
||||
static gint
|
||||
@@ -328,32 +398,65 @@ sort_by_placeholder (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_b,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter;
|
||||
Account *account;
|
||||
const Account *account_a, *account_b;
|
||||
gboolean flag_a, flag_b;
|
||||
|
||||
model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model));
|
||||
/* Find the accounts */
|
||||
sort_cb_setup (f_model, f_iter_a, f_iter_b, &account_a, &account_b);
|
||||
|
||||
/* Get balance 1 */
|
||||
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER(f_model),
|
||||
&iter,
|
||||
f_iter_a);
|
||||
account = gnc_tree_model_account_get_account (GNC_TREE_MODEL_ACCOUNT(model), &iter);
|
||||
flag_a = xaccAccountGetPlaceholder(account);
|
||||
|
||||
/* Get balance 2 */
|
||||
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER(f_model),
|
||||
&iter,
|
||||
f_iter_b);
|
||||
account = gnc_tree_model_account_get_account (GNC_TREE_MODEL_ACCOUNT(model), &iter);
|
||||
flag_b = xaccAccountGetPlaceholder(account);
|
||||
/* Get the placeholder flags. */
|
||||
flag_a = xaccAccountGetPlaceholder(account_a);
|
||||
flag_b = xaccAccountGetPlaceholder(account_b);
|
||||
|
||||
if (flag_a > flag_b)
|
||||
return -1;
|
||||
else if (flag_a == flag_b)
|
||||
return 0;
|
||||
return 1;
|
||||
else if (flag_a < flag_b)
|
||||
return 1;
|
||||
return xaccAccountOrder(&account_a, &account_b);
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_by_xxx_period_value (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
GtkTreeIter *f_iter_b,
|
||||
gboolean recurse)
|
||||
{
|
||||
Account *acct1, *acct2;
|
||||
time_t t1, t2;
|
||||
gnc_numeric b1, b2;
|
||||
gint result;
|
||||
|
||||
sort_cb_setup (f_model, f_iter_a, f_iter_b,
|
||||
(const Account **)&acct1, (const Account **)&acct2);
|
||||
|
||||
t1 = gnc_accounting_period_fiscal_start();
|
||||
t2 = gnc_accounting_period_fiscal_end();
|
||||
|
||||
b1 = xaccAccountGetBalanceChangeForPeriod(acct1, t1, t2, recurse);
|
||||
b2 = xaccAccountGetBalanceChangeForPeriod(acct2, t1, t2, recurse);
|
||||
|
||||
result = gnc_numeric_compare(b1, b2);
|
||||
if (result != 0)
|
||||
return result;
|
||||
return xaccAccountOrder((const Account **)&acct1, (const Account **)&acct2);
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_by_balance_period_value (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
GtkTreeIter *f_iter_b,
|
||||
gpointer user_data)
|
||||
{
|
||||
return sort_by_xxx_period_value (f_model, f_iter_a, f_iter_b, FALSE);
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_by_total_period_value (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
GtkTreeIter *f_iter_b,
|
||||
gpointer user_data)
|
||||
{
|
||||
return sort_by_xxx_period_value (f_model, f_iter_a, f_iter_b, TRUE);
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
@@ -412,33 +515,33 @@ gnc_tree_view_account_new_with_group (AccountGroup *group, gboolean show_root)
|
||||
GNC_STOCK_ACCOUNT, "Expenses:Entertainment",
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_NAME,
|
||||
GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
|
||||
NULL);
|
||||
sort_by_string);
|
||||
gnc_tree_view_add_text_column(view, _("Type"), "type", NULL, sample_type,
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_TYPE,
|
||||
GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
|
||||
NULL);
|
||||
sort_by_string);
|
||||
gnc_tree_view_add_text_column(view, _("Commodity"), "commodity", NULL,
|
||||
sample_commodity,
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_COMMODITY,
|
||||
GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
|
||||
NULL);
|
||||
sort_by_string);
|
||||
priv->code_column
|
||||
= gnc_tree_view_add_text_column(view, _("Account Code"), "account-code", NULL,
|
||||
"1-123-1234",
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_CODE,
|
||||
GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
|
||||
NULL);
|
||||
sort_by_code);
|
||||
priv->desc_column
|
||||
= gnc_tree_view_add_text_column(view, _("Description"), "description", NULL,
|
||||
"Sample account description.",
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_DESCRIPTION,
|
||||
GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
|
||||
NULL);
|
||||
sort_by_string);
|
||||
gnc_tree_view_add_numeric_column(view, _("Last Num"), "lastnum", "12345",
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_LASTNUM,
|
||||
GNC_TREE_VIEW_COLUMN_COLOR_NONE,
|
||||
GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
|
||||
NULL);
|
||||
sort_by_string);
|
||||
gnc_tree_view_add_numeric_column(view, _("Present"), "present",
|
||||
SAMPLE_ACCOUNT_VALUE,
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_PRESENT,
|
||||
@@ -471,7 +574,7 @@ gnc_tree_view_account_new_with_group (AccountGroup *group, gboolean show_root)
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_BALANCE_PERIOD,
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_COLOR_BALANCE_PERIOD,
|
||||
GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
|
||||
NULL);
|
||||
sort_by_balance_period_value);
|
||||
gnc_tree_view_add_numeric_column(view, _("Cleared"), "cleared",
|
||||
SAMPLE_ACCOUNT_VALUE,
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_CLEARED,
|
||||
@@ -529,18 +632,18 @@ gnc_tree_view_account_new_with_group (AccountGroup *group, gboolean show_root)
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_TOTAL_PERIOD,
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_COLOR_TOTAL_PERIOD,
|
||||
GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
|
||||
NULL);
|
||||
sort_by_total_period_value);
|
||||
priv->notes_column
|
||||
= gnc_tree_view_add_text_column(view, _("Notes"), "notes", NULL,
|
||||
"Sample account notes.",
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_NOTES,
|
||||
GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
|
||||
NULL);
|
||||
sort_by_string);
|
||||
gnc_tree_view_add_text_column(view, _("Tax Info"), "tax-info", NULL,
|
||||
"Sample tax info.",
|
||||
GNC_TREE_MODEL_ACCOUNT_COL_TAX_INFO,
|
||||
GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
|
||||
NULL);
|
||||
sort_by_string);
|
||||
gnc_tree_view_add_toggle_column
|
||||
(view, _("Placeholder"),
|
||||
/* Translators: This string has a context prefix; the translation
|
||||
|
||||
@@ -159,36 +159,56 @@ gnc_tree_view_commodity_destroy (GtkObject *object)
|
||||
/************************************************************/
|
||||
|
||||
static gboolean
|
||||
get_commodities (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
GtkTreeIter *f_iter_b,
|
||||
gnc_commodity **comm_a,
|
||||
gnc_commodity **comm_b)
|
||||
get_commodities_w_iters (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
GtkTreeIter *f_iter_b,
|
||||
GtkTreeModel **model_p,
|
||||
GtkTreeIter *iter_a,
|
||||
GtkTreeIter *iter_b,
|
||||
gnc_commodity **comm_a,
|
||||
gnc_commodity **comm_b)
|
||||
{
|
||||
GncTreeModelCommodity *model;
|
||||
GtkTreeModel *tree_model;
|
||||
GtkTreeIter iter_a, iter_b;
|
||||
|
||||
tree_model = gtk_tree_model_filter_get_model(GTK_TREE_MODEL_FILTER(f_model));
|
||||
model = GNC_TREE_MODEL_COMMODITY(tree_model);
|
||||
|
||||
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER(f_model),
|
||||
&iter_a,
|
||||
iter_a,
|
||||
f_iter_a);
|
||||
|
||||
/* Both iters must point to commodities for this to be meaningful */
|
||||
if (!gnc_tree_model_commodity_iter_is_commodity (model, &iter_a))
|
||||
return FALSE;
|
||||
|
||||
gtk_tree_model_filter_convert_iter_to_child_iter (GTK_TREE_MODEL_FILTER(f_model),
|
||||
&iter_b,
|
||||
iter_b,
|
||||
f_iter_b);
|
||||
|
||||
*comm_a = gnc_tree_model_commodity_get_commodity (model, &iter_a);
|
||||
*comm_b = gnc_tree_model_commodity_get_commodity (model, &iter_b);
|
||||
/* Both iters must point to commodities for this to be meaningful */
|
||||
if (!gnc_tree_model_commodity_iter_is_commodity (model, iter_a))
|
||||
return FALSE;
|
||||
if (!gnc_tree_model_commodity_iter_is_commodity (model, iter_b))
|
||||
return FALSE;
|
||||
|
||||
*comm_a = gnc_tree_model_commodity_get_commodity (model, iter_a);
|
||||
*comm_b = gnc_tree_model_commodity_get_commodity (model, iter_b);
|
||||
if (model_p)
|
||||
*model_p = tree_model;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
get_commodities (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
GtkTreeIter *f_iter_b,
|
||||
GtkTreeModel **model_p,
|
||||
gnc_commodity **comm_a,
|
||||
gnc_commodity **comm_b)
|
||||
{
|
||||
GtkTreeIter iter_a, iter_b;
|
||||
|
||||
return get_commodities_w_iters(f_model, f_iter_a, f_iter_b, model_p,
|
||||
&iter_a, &iter_b, comm_a, comm_b);
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_namespace (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
@@ -211,9 +231,8 @@ sort_namespace (GtkTreeModel *f_model,
|
||||
|
||||
ns_a = gnc_tree_model_commodity_get_namespace (model, &iter_a);
|
||||
ns_b = gnc_tree_model_commodity_get_namespace (model, &iter_b);
|
||||
SAFE_STRCMP (gnc_commodity_namespace_get_name (ns_a),
|
||||
gnc_commodity_namespace_get_name (ns_b));
|
||||
return 0;
|
||||
return safe_utf8_collate (gnc_commodity_namespace_get_name (ns_a),
|
||||
gnc_commodity_namespace_get_name (ns_b));
|
||||
}
|
||||
|
||||
static gint
|
||||
@@ -250,106 +269,32 @@ default_sort (gnc_commodity *comm_a, gnc_commodity *comm_b)
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_by_namespace (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
GtkTreeIter *f_iter_b,
|
||||
gpointer user_data)
|
||||
sort_by_commodity_string (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
GtkTreeIter *f_iter_b,
|
||||
gpointer user_data)
|
||||
{
|
||||
GtkTreeModel *model;
|
||||
GtkTreeIter iter_a, iter_b;
|
||||
gnc_commodity *comm_a, *comm_b;
|
||||
const gchar *str1, *str2;
|
||||
gint column = GPOINTER_TO_INT(user_data);
|
||||
gint result;
|
||||
|
||||
if (!get_commodities (f_model, f_iter_a, f_iter_b, &comm_a, &comm_b))
|
||||
if (!get_commodities_w_iters(f_model, f_iter_a, f_iter_b,
|
||||
&model, &iter_a, &iter_b, &comm_a, &comm_b))
|
||||
return sort_namespace (f_model, f_iter_a, f_iter_b);
|
||||
|
||||
SAFE_STRCMP (gnc_commodity_get_namespace (comm_a),
|
||||
gnc_commodity_get_namespace (comm_b));
|
||||
/* Get the strings. */
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(model), &iter_a, column, &str1, -1);
|
||||
gtk_tree_model_get(GTK_TREE_MODEL(model), &iter_b, column, &str2, -1);
|
||||
|
||||
result = safe_utf8_collate(str1, str2);
|
||||
if (result != 0)
|
||||
return result;
|
||||
return default_sort(comm_a, comm_b);
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_by_mnemonic (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
GtkTreeIter *f_iter_b,
|
||||
gpointer user_data)
|
||||
{
|
||||
gnc_commodity *comm_a, *comm_b;
|
||||
|
||||
if (!get_commodities (f_model, f_iter_a, f_iter_b, &comm_a, &comm_b))
|
||||
return sort_namespace (f_model, f_iter_a, f_iter_b);
|
||||
|
||||
SAFE_STRCMP (gnc_commodity_get_mnemonic (comm_a),
|
||||
gnc_commodity_get_mnemonic (comm_b));
|
||||
|
||||
return default_sort(comm_a, comm_b);
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_by_fullname (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
GtkTreeIter *f_iter_b,
|
||||
gpointer user_data)
|
||||
{
|
||||
gnc_commodity *comm_a, *comm_b;
|
||||
|
||||
if (!get_commodities (f_model, f_iter_a, f_iter_b, &comm_a, &comm_b))
|
||||
return sort_namespace (f_model, f_iter_a, f_iter_b);
|
||||
|
||||
SAFE_STRCMP (gnc_commodity_get_fullname (comm_a),
|
||||
gnc_commodity_get_fullname (comm_b));
|
||||
|
||||
return default_sort(comm_a, comm_b);
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_by_printname (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
GtkTreeIter *f_iter_b,
|
||||
gpointer user_data)
|
||||
{
|
||||
gnc_commodity *comm_a, *comm_b;
|
||||
|
||||
if (!get_commodities (f_model, f_iter_a, f_iter_b, &comm_a, &comm_b))
|
||||
return sort_namespace (f_model, f_iter_a, f_iter_b);
|
||||
|
||||
SAFE_STRCMP (gnc_commodity_get_printname (comm_a),
|
||||
gnc_commodity_get_printname (comm_b));
|
||||
|
||||
return default_sort(comm_a, comm_b);
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_by_unique_name (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
GtkTreeIter *f_iter_b,
|
||||
gpointer user_data)
|
||||
{
|
||||
gnc_commodity *comm_a, *comm_b;
|
||||
|
||||
if (!get_commodities (f_model, f_iter_a, f_iter_b, &comm_a, &comm_b))
|
||||
return sort_namespace (f_model, f_iter_a, f_iter_b);
|
||||
|
||||
SAFE_STRCMP (gnc_commodity_get_unique_name (comm_a),
|
||||
gnc_commodity_get_unique_name (comm_b));
|
||||
|
||||
return default_sort(comm_a, comm_b);
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_by_cusip_code (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
GtkTreeIter *f_iter_b,
|
||||
gpointer user_data)
|
||||
{
|
||||
gnc_commodity *comm_a, *comm_b;
|
||||
|
||||
if (!get_commodities (f_model, f_iter_a, f_iter_b, &comm_a, &comm_b))
|
||||
return sort_namespace (f_model, f_iter_a, f_iter_b);
|
||||
|
||||
SAFE_STRCMP (gnc_commodity_get_cusip (comm_a),
|
||||
gnc_commodity_get_cusip (comm_b));
|
||||
|
||||
return default_sort(comm_a, comm_b);
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_by_fraction (GtkTreeModel *f_model,
|
||||
@@ -360,7 +305,7 @@ sort_by_fraction (GtkTreeModel *f_model,
|
||||
gnc_commodity *comm_a, *comm_b;
|
||||
gint fraction_a, fraction_b;
|
||||
|
||||
if (!get_commodities (f_model, f_iter_a, f_iter_b, &comm_a, &comm_b))
|
||||
if (!get_commodities (f_model, f_iter_a, f_iter_b, NULL, &comm_a, &comm_b))
|
||||
return sort_namespace (f_model, f_iter_a, f_iter_b);
|
||||
|
||||
fraction_a = gnc_commodity_get_fraction (comm_a);
|
||||
@@ -384,7 +329,7 @@ sort_by_quote_flag (GtkTreeModel *f_model,
|
||||
gnc_commodity *comm_a, *comm_b;
|
||||
gboolean flag_a, flag_b;
|
||||
|
||||
if (!get_commodities (f_model, f_iter_a, f_iter_b, &comm_a, &comm_b))
|
||||
if (!get_commodities (f_model, f_iter_a, f_iter_b, NULL, &comm_a, &comm_b))
|
||||
return sort_namespace (f_model, f_iter_a, f_iter_b);
|
||||
|
||||
flag_a = gnc_commodity_get_quote_flag(comm_a);
|
||||
@@ -397,44 +342,6 @@ sort_by_quote_flag (GtkTreeModel *f_model,
|
||||
return default_sort(comm_a, comm_b);
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_by_quote_source (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
GtkTreeIter *f_iter_b,
|
||||
gpointer user_data)
|
||||
{
|
||||
gnc_commodity *comm_a, *comm_b;
|
||||
gnc_quote_source *source_a, *source_b;
|
||||
|
||||
if (!get_commodities (f_model, f_iter_a, f_iter_b, &comm_a, &comm_b))
|
||||
return sort_namespace (f_model, f_iter_a, f_iter_b);
|
||||
|
||||
source_a = gnc_commodity_get_quote_source (comm_a);
|
||||
source_b = gnc_commodity_get_quote_source (comm_b);
|
||||
|
||||
SAFE_STRCMP(gnc_quote_source_get_user_name (source_a),
|
||||
gnc_quote_source_get_user_name (source_b));
|
||||
|
||||
return default_sort(comm_a, comm_b);
|
||||
}
|
||||
|
||||
static gint
|
||||
sort_by_quote_tz (GtkTreeModel *f_model,
|
||||
GtkTreeIter *f_iter_a,
|
||||
GtkTreeIter *f_iter_b,
|
||||
gpointer user_data)
|
||||
{
|
||||
gnc_commodity *comm_a, *comm_b;
|
||||
|
||||
if (!get_commodities (f_model, f_iter_a, f_iter_b, &comm_a, &comm_b))
|
||||
return sort_namespace (f_model, f_iter_a, f_iter_b);
|
||||
|
||||
SAFE_STRCMP (gnc_commodity_get_quote_tz (comm_a),
|
||||
gnc_commodity_get_quote_tz (comm_b));
|
||||
|
||||
return default_sort(comm_a, comm_b);
|
||||
}
|
||||
|
||||
/************************************************************/
|
||||
/* New View Creation */
|
||||
/************************************************************/
|
||||
@@ -486,32 +393,32 @@ gnc_tree_view_commodity_new (QofBook *book,
|
||||
"NASDAQ",
|
||||
GNC_TREE_MODEL_COMMODITY_COL_NAMESPACE,
|
||||
GNC_TREE_VIEW_COLUMN_VISIBLE_ALWAYS,
|
||||
sort_by_namespace);
|
||||
sort_by_commodity_string);
|
||||
gnc_tree_view_add_text_column (view, _("Symbol"), "symbol", NULL,
|
||||
"ACMEACME",
|
||||
GNC_TREE_MODEL_COMMODITY_COL_MNEMONIC,
|
||||
GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY,
|
||||
sort_by_mnemonic);
|
||||
sort_by_commodity_string);
|
||||
gnc_tree_view_add_text_column (view, _("Name"), "name", NULL,
|
||||
"Acme Corporation, Inc.",
|
||||
GNC_TREE_MODEL_COMMODITY_COL_FULLNAME,
|
||||
GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY,
|
||||
sort_by_fullname);
|
||||
sort_by_commodity_string);
|
||||
gnc_tree_view_add_text_column (view, _("Print Name"), "printname", NULL,
|
||||
"ACMEACME (Acme Corporation, Inc.)",
|
||||
GNC_TREE_MODEL_COMMODITY_COL_PRINTNAME,
|
||||
GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY,
|
||||
sort_by_printname);
|
||||
sort_by_commodity_string);
|
||||
gnc_tree_view_add_text_column (view, _("Unique Name"), "uniquename", NULL,
|
||||
"NASDAQ::ACMEACME",
|
||||
GNC_TREE_MODEL_COMMODITY_COL_UNIQUE_NAME,
|
||||
GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY,
|
||||
sort_by_unique_name);
|
||||
sort_by_commodity_string);
|
||||
gnc_tree_view_add_text_column (view, _("CUSIP code"), "cusip_code", NULL,
|
||||
"QWERTYUIOP",
|
||||
GNC_TREE_MODEL_COMMODITY_COL_CUSIP,
|
||||
GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY,
|
||||
sort_by_cusip_code);
|
||||
sort_by_commodity_string);
|
||||
gnc_tree_view_add_numeric_column (view, _("Fraction"), "fraction", "10000",
|
||||
GNC_TREE_MODEL_COMMODITY_COL_FRACTION,
|
||||
GNC_TREE_VIEW_COLUMN_COLOR_NONE,
|
||||
@@ -531,12 +438,12 @@ gnc_tree_view_commodity_new (QofBook *book,
|
||||
"yahoo",
|
||||
GNC_TREE_MODEL_COMMODITY_COL_QUOTE_SOURCE,
|
||||
GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY,
|
||||
sort_by_quote_source);
|
||||
sort_by_commodity_string);
|
||||
gnc_tree_view_add_text_column (view, _("Timezone"), "quote_timezone", NULL,
|
||||
"America/New_York",
|
||||
GNC_TREE_MODEL_COMMODITY_COL_QUOTE_TZ,
|
||||
GNC_TREE_MODEL_COMMODITY_COL_VISIBILITY,
|
||||
sort_by_quote_tz);
|
||||
sort_by_commodity_string);
|
||||
|
||||
gnc_tree_view_configure_columns(view, "symbol", "name", "cusip_code",
|
||||
"fraction", NULL);
|
||||
|
||||
@@ -213,16 +213,14 @@ sort_ns_or_cm (GtkTreeModel *f_model,
|
||||
if (gnc_tree_model_price_iter_is_namespace (model, &iter_a)) {
|
||||
ns_a = gnc_tree_model_price_get_namespace (model, &iter_a);
|
||||
ns_b = gnc_tree_model_price_get_namespace (model, &iter_b);
|
||||
SAFE_STRCMP (gnc_commodity_namespace_get_name (ns_a),
|
||||
gnc_commodity_namespace_get_name (ns_b));
|
||||
return 0;
|
||||
return safe_utf8_collate (gnc_commodity_namespace_get_name (ns_a),
|
||||
gnc_commodity_namespace_get_name (ns_b));
|
||||
}
|
||||
|
||||
comm_a = gnc_tree_model_price_get_commodity (model, &iter_a);
|
||||
comm_b = gnc_tree_model_price_get_commodity (model, &iter_b);
|
||||
SAFE_STRCMP (gnc_commodity_get_mnemonic (comm_a),
|
||||
gnc_commodity_get_mnemonic (comm_b));
|
||||
return 0;
|
||||
return safe_utf8_collate (gnc_commodity_get_mnemonic (comm_a),
|
||||
gnc_commodity_get_mnemonic (comm_b));
|
||||
}
|
||||
|
||||
static gint
|
||||
@@ -251,7 +249,8 @@ default_sort (GNCPrice *price_a, GNCPrice *price_b)
|
||||
ts_b = gnc_price_get_time (price_b);
|
||||
result = timespec_cmp (&ts_a, &ts_b);
|
||||
if (result)
|
||||
return result;
|
||||
/* Reverse the result to present the most recent quote first. */
|
||||
return -result;
|
||||
|
||||
/* last sort: value */
|
||||
return gnc_numeric_compare (gnc_price_get_value (price_a),
|
||||
@@ -290,7 +289,8 @@ sort_by_date (GtkTreeModel *f_model,
|
||||
ts_b = gnc_price_get_time (price_b);
|
||||
result = timespec_cmp (&ts_a, &ts_b);
|
||||
if (result)
|
||||
return result;
|
||||
/* Reverse the result to present the most recent quote first. */
|
||||
return -result;
|
||||
|
||||
return default_sort (price_a, price_b);
|
||||
}
|
||||
@@ -302,13 +302,16 @@ sort_by_source (GtkTreeModel *f_model,
|
||||
gpointer user_data)
|
||||
{
|
||||
GNCPrice *price_a, *price_b;
|
||||
gint result;
|
||||
|
||||
if (!get_prices (f_model, f_iter_a, f_iter_b, &price_a, &price_b))
|
||||
return sort_ns_or_cm (f_model, f_iter_a, f_iter_b);
|
||||
|
||||
/* sort by source first */
|
||||
SAFE_STRCMP (gnc_price_get_source (price_a),
|
||||
gnc_price_get_source (price_b));
|
||||
result = safe_utf8_collate (gnc_price_get_source (price_a),
|
||||
gnc_price_get_source (price_b));
|
||||
if (result != 0)
|
||||
return result;
|
||||
|
||||
return default_sort (price_a, price_b);
|
||||
}
|
||||
@@ -320,13 +323,16 @@ sort_by_type (GtkTreeModel *f_model,
|
||||
gpointer user_data)
|
||||
{
|
||||
GNCPrice *price_a, *price_b;
|
||||
gint result;
|
||||
|
||||
if (!get_prices (f_model, f_iter_a, f_iter_b, &price_a, &price_b))
|
||||
return sort_ns_or_cm (f_model, f_iter_a, f_iter_b);
|
||||
|
||||
/* sort by source first */
|
||||
SAFE_STRCMP (gnc_price_get_type (price_a),
|
||||
gnc_price_get_type (price_b));
|
||||
result = safe_utf8_collate (gnc_price_get_type (price_a),
|
||||
gnc_price_get_type (price_b));
|
||||
if (result != 0)
|
||||
return result;
|
||||
|
||||
return default_sort (price_a, price_b);
|
||||
}
|
||||
@@ -340,6 +346,7 @@ sort_by_value (GtkTreeModel *f_model,
|
||||
gnc_commodity *comm_a, *comm_b;
|
||||
GNCPrice *price_a, *price_b;
|
||||
gboolean result;
|
||||
gint value;
|
||||
|
||||
if (!get_prices (f_model, f_iter_a, f_iter_b, &price_a, &price_b))
|
||||
return sort_ns_or_cm (f_model, f_iter_a, f_iter_b);
|
||||
@@ -352,11 +359,14 @@ sort_by_value (GtkTreeModel *f_model,
|
||||
comm_a = gnc_price_get_currency (price_a);
|
||||
comm_b = gnc_price_get_currency (price_b);
|
||||
if (comm_a && comm_b){
|
||||
SAFE_STRCMP (gnc_commodity_get_namespace (comm_a),
|
||||
gnc_commodity_get_namespace (comm_b));
|
||||
|
||||
SAFE_STRCMP (gnc_commodity_get_mnemonic (comm_a),
|
||||
gnc_commodity_get_mnemonic (comm_b));
|
||||
value = safe_utf8_collate (gnc_commodity_get_namespace (comm_a),
|
||||
gnc_commodity_get_namespace (comm_b));
|
||||
if (value != 0)
|
||||
return value;
|
||||
value = safe_utf8_collate (gnc_commodity_get_mnemonic (comm_a),
|
||||
gnc_commodity_get_mnemonic (comm_b));
|
||||
if (value != 0)
|
||||
return value;
|
||||
}
|
||||
|
||||
/*
|
||||
|
||||
@@ -1799,7 +1799,7 @@ gnc_tree_view_column_properties (GncTreeView *view,
|
||||
if (column_sort_fn) {
|
||||
gtk_tree_sortable_set_sort_func (GTK_TREE_SORTABLE(s_model),
|
||||
data_column, column_sort_fn,
|
||||
NULL /* user_data */,
|
||||
GINT_TO_POINTER(data_column),
|
||||
NULL /* destroy fn */);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user