diff --git a/ChangeLog b/ChangeLog index 382e9a86b2..1aa02174a2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2006-03-14 David Hampton + + * src/gnome-utils/gnc-tree-view-account.c: + * src/gnome-utils/gnc-account-sel.c: + * src/gnome/druid-stock-split.c: + * src/engine/Account.c: + * src/engine/gw-engine-spec.scm: + * src/engine/Group.[ch]: Leave the accounts unordered in the + engine. Switch the g-wrap functions that return account lists to + use new functions that return sorted lists so that they see no + change. Fixes 331855. Also change the default account sorting to + sort on utf8 strings. + + * src/gnome-utils/dialog-account.c: Fix a warning message. + 2006-03-13 Neil Williams * : Synchronise with external QOF 0.6.3 diff --git a/src/engine/Account.c b/src/engine/Account.c index 33bfc3254a..4296c7e09c 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -335,6 +335,7 @@ static inline void acc_free (QofInstance *inst) void xaccAccountCommitEdit (Account *acc) { + g_return_if_fail(acc); if(!qof_commit_edit(&acc->inst)) { return;} /* If marked for deletion, get rid of subaccounts first, @@ -375,9 +376,6 @@ xaccAccountCommitEdit (Account *acc) else { xaccAccountBringUpToDate(acc); - - /* force re-sort of parent group */ - xaccGroupInsertAccount(acc->parent, acc); } qof_commit_edit_part2(&acc->inst, on_err, on_done, acc_free); @@ -1022,7 +1020,15 @@ xaccAccountOrder (const Account **aa, const Account **ab) /* otherwise, sort on accountName strings */ da = (*aa)->accountName; db = (*ab)->accountName; - SAFE_STRCMP (da, db); + if (da && db) { + gint result = g_utf8_collate(da, db); + if (result) + return result; + } else if (da) { + return -1; + } else if (db) { + return 1; + } /* guarantee a stable sort */ return guid_compare (&((*aa)->inst.entity.guid), &((*ab)->inst.entity.guid)); diff --git a/src/engine/Group.c b/src/engine/Group.c index 4543b08277..6f4b83f160 100644 --- a/src/engine/Group.c +++ b/src/engine/Group.c @@ -418,6 +418,50 @@ xaccGroupGetSubAccounts (const AccountGroup *grp) return g_list_reverse (accounts); } +static int +group_sort_helper (gconstpointer a, gconstpointer b) +{ + const Account *aa = (const Account *) a; + const Account *bb = (const Account *) b; + + /* xaccAccountOrder returns > 1 if aa should come after bb. + * This funciton is building a reversed list. */ + return xaccAccountOrder (&aa, &bb); +} + +static void +xaccPrependAccountsSorted (const AccountGroup *grp, GList **accounts_p) +{ + GList *node, *tmp_list; + + if (!grp || !accounts_p) return; + + tmp_list = g_list_copy(grp->accounts); + tmp_list = g_list_sort(tmp_list, group_sort_helper); + + for (node = tmp_list; node; node = node->next) + { + Account *account = node->data; + + *accounts_p = g_list_prepend (*accounts_p, account); + + xaccPrependAccountsSorted (account->children, accounts_p); + } + g_list_free(tmp_list); +} + +AccountList * +xaccGroupGetSubAccountsSorted (const AccountGroup *grp) +{ + GList *accounts = NULL; + + if (!grp) return NULL; + + xaccPrependAccountsSorted (grp, &accounts); + + return g_list_reverse (accounts); +} + AccountList * xaccGroupGetAccountList (const AccountGroup *grp) { @@ -426,6 +470,15 @@ xaccGroupGetAccountList (const AccountGroup *grp) return grp->accounts; } +GList * +xaccGroupGetAccountListSorted (const AccountGroup *grp) +{ + if (!grp) return NULL; + + return g_list_sort(g_list_copy(grp->accounts), group_sort_helper); + +} + /********************************************************************\ * Fetch the root of the tree * \********************************************************************/ @@ -692,16 +745,6 @@ xaccAccountInsertSubAccount (Account *adult, Account *child) /********************************************************************\ \********************************************************************/ -static int -group_sort_helper (gconstpointer a, gconstpointer b) -{ - const Account *aa = (const Account *) a; - const Account *bb = (const Account *) b; - - /* return > 1 if aa should come after bb */ - return xaccAccountOrder (&aa, &bb); -} - void xaccGroupInsertAccount (AccountGroup *grp, Account *acc) { @@ -713,11 +756,7 @@ xaccGroupInsertAccount (AccountGroup *grp, Account *acc) * first. Basically, we can't have accounts being in two places at * once. If old and new parents are the same, reinsertion causes * the sort order to be checked. */ - if (acc->parent == grp) - { - grp->accounts = g_list_sort (grp->accounts, group_sort_helper); - } - else + if (acc->parent != grp) { xaccAccountBeginEdit (acc); @@ -753,8 +792,7 @@ xaccGroupInsertAccount (AccountGroup *grp, Account *acc) /* set back-pointer to the account's parent */ acc->parent = grp; - grp->accounts = g_list_insert_sorted (grp->accounts, acc, - group_sort_helper); + grp->accounts = g_list_append (grp->accounts, acc); /* Gather event data */ qof_event_gen (&acc->inst.entity, QOF_EVENT_ADD, NULL); @@ -820,8 +858,7 @@ xaccGroupCopyGroup (AccountGroup *to, AccountGroup *from) to_acc = xaccCloneAccount (from_acc, to->book); xaccAccountBeginEdit (to_acc); - to->accounts = g_list_insert_sorted (to->accounts, to_acc, - group_sort_helper); + to->accounts = g_list_append (to->accounts, to_acc); to_acc->parent = to; to_acc->inst.dirty = TRUE; diff --git a/src/engine/Group.h b/src/engine/Group.h index b7c99e7149..d41b85c638 100644 --- a/src/engine/Group.h +++ b/src/engine/Group.h @@ -198,12 +198,25 @@ Account * xaccGroupGetAccount (const AccountGroup *group, int index); */ AccountList * xaccGroupGetSubAccounts (const AccountGroup *grp); +/** The xaccGroupGetSubAccounts() subroutine returns a sorted list of + * the accounts, including subaccounts, in the account group. The + * returned list should be freed with g_list_free() when no longer + * needed. + */ +AccountList * xaccGroupGetSubAccountsSorted (const AccountGroup *grp); + /** The xaccGroupGetAccountList() subroutines returns only the immediate * children of the account group. The returned list should *not* * be freed by the caller. */ AccountList * xaccGroupGetAccountList (const AccountGroup *grp); +/** The xaccGroupGetAccountList() subroutines returns only the + * immediate children of the account group. The returned list + * should be freed with g_list_free() when no longer needed. + */ +GList * xaccGroupGetAccountListSorted (const AccountGroup *grp); + /** The xaccGroupGetRoot() subroutine will find the topmost * (root) group to which this group belongs. */ diff --git a/src/engine/gw-engine-spec.scm b/src/engine/gw-engine-spec.scm index cab02081b0..aa07b59a82 100644 --- a/src/engine/gw-engine-spec.scm +++ b/src/engine/gw-engine-spec.scm @@ -1087,7 +1087,7 @@ group") ws 'gnc:group-get-subaccounts '(gw:glist-of caller-owned) - "xaccGroupGetSubAccounts" + "xaccGroupGetSubAccountsSorted" '(( g)) "Return a list containing all of the accounts, including subaccounts, in the account group. The returned array should be freed @@ -1096,8 +1096,8 @@ when no longer needed.") (gw:wrap-function ws 'gnc:group-get-account-list - '(gw:glist-of callee-owned) - "xaccGroupGetAccountList" + '(gw:glist-of caller-owned) + "xaccGroupGetAccountListSorted" '(( g)) "Return a list containing the immediate children of g.") diff --git a/src/gnome-utils/gnc-account-sel.c b/src/gnome-utils/gnc-account-sel.c index 75b906ad80..dcc90e6559 100644 --- a/src/gnome-utils/gnc-account-sel.c +++ b/src/gnome-utils/gnc-account-sel.c @@ -195,7 +195,7 @@ gas_populate_list( GNCAccountSel *gas ) GTK_EDITABLE(gas->combo->entry), 0, -1 ); ag = gnc_book_get_group( gnc_get_current_book() ); - accts = (GList*)xaccGroupGetSubAccounts( ag ); + accts = (GList*)xaccGroupGetSubAccountsSorted( ag ); nameList = NULL; atnd.gas = gas; diff --git a/src/gnome-utils/gnc-tree-view-account.c b/src/gnome-utils/gnc-tree-view-account.c index 5ffb67d6c5..88bf824d4c 100644 --- a/src/gnome-utils/gnc-tree-view-account.c +++ b/src/gnome-utils/gnc-tree-view-account.c @@ -615,6 +615,11 @@ gnc_tree_view_account_new_with_group (AccountGroup *group, gboolean show_root) view, NULL); + /* Default the sorting to account name */ + gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(s_model), + GNC_TREE_MODEL_ACCOUNT_COL_NAME, + GTK_SORT_ASCENDING); + gtk_widget_show(GTK_WIDGET(view)); LEAVE("%p", view); return GTK_TREE_VIEW(view); diff --git a/src/gnome/druid-stock-split.c b/src/gnome/druid-stock-split.c index fb8b9255ca..9516611ae0 100644 --- a/src/gnome/druid-stock-split.c +++ b/src/gnome/druid-stock-split.c @@ -120,7 +120,7 @@ fill_account_list (StockSplitInfo *info, Account *account) gtk_clist_clear (clist); - accounts = xaccGroupGetSubAccounts (gnc_get_current_group ()); + accounts = xaccGroupGetSubAccountsSorted (gnc_get_current_group ()); for (node = accounts; node; node = node->next) { Account *account = node->data; @@ -157,6 +157,7 @@ fill_account_list (StockSplitInfo *info, Account *account) rows++; } + g_list_free(accounts); { gint row = 0;