[Gnucash-changes] r13624 - gnucash/trunk - Leave the accounts unordered in the engine. Switch the g-wrap

David Hampton hampton at cvs.gnucash.org
Tue Mar 14 01:32:55 EST 2006


Author: hampton
Date: 2006-03-14 01:32:54 -0500 (Tue, 14 Mar 2006)
New Revision: 13624
Trac: http://svn.gnucash.org/trac/changeset/13624

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/src/engine/Account.c
   gnucash/trunk/src/engine/Group.c
   gnucash/trunk/src/engine/Group.h
   gnucash/trunk/src/engine/gw-engine-spec.scm
   gnucash/trunk/src/gnome-utils/gnc-account-sel.c
   gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c
   gnucash/trunk/src/gnome/druid-stock-split.c
Log:
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.


Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2006-03-14 06:08:47 UTC (rev 13623)
+++ gnucash/trunk/ChangeLog	2006-03-14 06:32:54 UTC (rev 13624)
@@ -1,3 +1,18 @@
+2006-03-14  David Hampton  <hampton at employees.org>
+
+	* 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  <linux at codehelp.co.uk>
 
 	* : Synchronise with external QOF 0.6.3

Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c	2006-03-14 06:08:47 UTC (rev 13623)
+++ gnucash/trunk/src/engine/Account.c	2006-03-14 06:32:54 UTC (rev 13624)
@@ -335,6 +335,7 @@
 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 @@
   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 @@
   /* 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));

Modified: gnucash/trunk/src/engine/Group.c
===================================================================
--- gnucash/trunk/src/engine/Group.c	2006-03-14 06:08:47 UTC (rev 13623)
+++ gnucash/trunk/src/engine/Group.c	2006-03-14 06:32:54 UTC (rev 13624)
@@ -418,7 +418,51 @@
   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)
 {
   if (!grp) return NULL;
@@ -426,6 +470,15 @@
   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 @@
 /********************************************************************\
 \********************************************************************/
 
-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,12 +756,8 @@
    * 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)
+  if (acc->parent != grp)
   {
-    grp->accounts = g_list_sort (grp->accounts, group_sort_helper);
-  }
-  else
-  {
     xaccAccountBeginEdit (acc);
 
     if (acc->parent) 
@@ -753,8 +792,7 @@
     /* 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 @@
       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;

Modified: gnucash/trunk/src/engine/Group.h
===================================================================
--- gnucash/trunk/src/engine/Group.h	2006-03-14 06:08:47 UTC (rev 13623)
+++ gnucash/trunk/src/engine/Group.h	2006-03-14 06:32:54 UTC (rev 13624)
@@ -198,12 +198,25 @@
  */
 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.
  */

Modified: gnucash/trunk/src/engine/gw-engine-spec.scm
===================================================================
--- gnucash/trunk/src/engine/gw-engine-spec.scm	2006-03-14 06:08:47 UTC (rev 13623)
+++ gnucash/trunk/src/engine/gw-engine-spec.scm	2006-03-14 06:32:54 UTC (rev 13624)
@@ -1087,7 +1087,7 @@
  ws
  'gnc:group-get-subaccounts
  '(gw:glist-of <gnc:Account*> caller-owned)
- "xaccGroupGetSubAccounts"
+ "xaccGroupGetSubAccountsSorted"
  '((<gnc:AccountGroup*> 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 @@
 (gw:wrap-function
  ws
  'gnc:group-get-account-list
- '(gw:glist-of <gnc:Account*> callee-owned)
- "xaccGroupGetAccountList"
+ '(gw:glist-of <gnc:Account*> caller-owned)
+ "xaccGroupGetAccountListSorted"
  '((<gnc:AccountGroup*> g))
  "Return a list containing the immediate children of g.")
 

Modified: gnucash/trunk/src/gnome/druid-stock-split.c
===================================================================
--- gnucash/trunk/src/gnome/druid-stock-split.c	2006-03-14 06:08:47 UTC (rev 13623)
+++ gnucash/trunk/src/gnome/druid-stock-split.c	2006-03-14 06:32:54 UTC (rev 13624)
@@ -120,7 +120,7 @@
 
   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 @@
 
     rows++;
   }
+  g_list_free(accounts);
 
   {
     gint row = 0;

Modified: gnucash/trunk/src/gnome-utils/gnc-account-sel.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-account-sel.c	2006-03-14 06:08:47 UTC (rev 13623)
+++ gnucash/trunk/src/gnome-utils/gnc-account-sel.c	2006-03-14 06:32:54 UTC (rev 13624)
@@ -195,7 +195,7 @@
                 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;

Modified: gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c	2006-03-14 06:08:47 UTC (rev 13623)
+++ gnucash/trunk/src/gnome-utils/gnc-tree-view-account.c	2006-03-14 06:32:54 UTC (rev 13624)
@@ -615,6 +615,11 @@
 					  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);



More information about the gnucash-changes mailing list