r15562 - gnucash/branches/remove-group2/src - Update the example accounts code to work properly with a root account.

David Hampton hampton at cvs.gnucash.org
Sat Feb 10 19:34:39 EST 2007


Author: hampton
Date: 2007-02-10 19:34:38 -0500 (Sat, 10 Feb 2007)
New Revision: 15562
Trac: http://svn.gnucash.org/trac/changeset/15562

Modified:
   gnucash/branches/remove-group2/src/backend/file/io-example-account.c
   gnucash/branches/remove-group2/src/backend/file/io-example-account.h
   gnucash/branches/remove-group2/src/backend/file/test/test-load-example-account.c
   gnucash/branches/remove-group2/src/gnome/druid-hierarchy.c
Log:
Update the example accounts code to work properly with a root account.


Modified: gnucash/branches/remove-group2/src/backend/file/io-example-account.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/file/io-example-account.c	2007-02-11 00:30:57 UTC (rev 15561)
+++ gnucash/branches/remove-group2/src/backend/file/io-example-account.c	2007-02-11 00:34:38 UTC (rev 15562)
@@ -45,6 +45,7 @@
 
 #include "Scrub.h"
 #include "TransLog.h"
+#include "AccountP.h"
 
 static QofLogModule log_module = GNC_MOD_IO;
 
@@ -84,6 +85,11 @@
         g_free(gea->long_description);
         gea->long_description = NULL;
     }
+    if(gea->book != NULL)
+    {
+        qof_book_destroy(gea->book);
+        gea->book = NULL;
+    }
     g_free(gea);
 }
 
@@ -137,8 +143,12 @@
 
     xaccAccountScrubCommodity (act);
 
-    if (!gnc_account_get_parent(act))
+    if (xaccAccountGetType(act) == ACCT_TYPE_ROOT)
     {
+        gea->root = act;
+    }
+    else if (!gnc_account_get_parent(act))
+    {
         gnc_account_append_child(gea->root, act);
     }
 }
@@ -288,19 +298,18 @@
 
 
 GncExampleAccount*
-gnc_read_example_account(QofBook *book, const gchar *filename)
+gnc_read_example_account(const gchar *filename)
 {
     GncExampleAccount *gea;
     sixtp *top_parser;
     sixtp *main_parser;
 
-    g_return_val_if_fail (book != NULL, NULL);
+    g_return_val_if_fail (filename != NULL, NULL);
 
     gea = g_new0(GncExampleAccount, 1);
 
-    gea->book = book;
+    gea->book = qof_book_new();
     gea->filename = g_strdup(filename);
-    gea->root = xaccMallocAccount(book);
 
     top_parser = sixtp_new();
     main_parser = sixtp_new();
@@ -326,18 +335,14 @@
         return FALSE;
     }
 
-    xaccAccountBeginEdit(gea->root);
-
     if(!gnc_xml_parse_file(top_parser, filename,
-                           generic_callback, gea, book))
+                           generic_callback, gea, gea->book))
     {
         sixtp_destroy(top_parser);
         xaccLogEnable ();
         return FALSE;
     }
 
-    xaccAccountCommitEdit(gea->root);
-    
     return gea;
 }
 
@@ -371,6 +376,7 @@
 gnc_write_example_account(GncExampleAccount *gea, const gchar *filename)
 {
     FILE *out;
+    sixtp_gdv2 data = { 0 };;
 
     out = fopen(filename, "w");
     if (out == NULL)
@@ -389,7 +395,7 @@
     
     write_bool_part(out, GNC_ACCOUNT_EXCLUDEP, gea->exclude_from_select_all);
 
-    write_account_tree(out, gea->root, NULL);
+    write_account_tree(out, gea->root, &data);
 
     fprintf(out, "</" GNC_ACCOUNT_STRING ">\n\n");
     
@@ -432,9 +438,9 @@
 
     return S_ISDIR(fileinfo.st_mode);
 }
-    
+
 GSList*
-gnc_load_example_account_list(QofBook *book, const char *dirname)
+gnc_load_example_account_list(const char *dirname)
 {
     GSList *ret;
     DIR *dir;
@@ -457,7 +463,7 @@
 
         if(!is_directory(filename))
         {
-            gea = gnc_read_example_account(book, filename);
+            gea = gnc_read_example_account(filename);
 
             if(gea == NULL)
             {

Modified: gnucash/branches/remove-group2/src/backend/file/io-example-account.h
===================================================================
--- gnucash/branches/remove-group2/src/backend/file/io-example-account.h	2007-02-11 00:30:57 UTC (rev 15561)
+++ gnucash/branches/remove-group2/src/backend/file/io-example-account.h	2007-02-11 00:34:38 UTC (rev 15562)
@@ -47,13 +47,11 @@
 
 gboolean gnc_write_example_account(GncExampleAccount *gea,
                                    const gchar *filename);
-GncExampleAccount *gnc_read_example_account(QofBook *book,
-                                            const gchar *filename);
+GncExampleAccount *gnc_read_example_account(const gchar *filename);
 
 
 void gnc_free_example_account_list(GSList *list);
-GSList* gnc_load_example_account_list(QofBook *book,
-                                      const char *dirname);
+GSList* gnc_load_example_account_list(const char *dirname);
 
 gboolean gnc_is_example_account_xml(const gchar *name);
 

Modified: gnucash/branches/remove-group2/src/backend/file/test/test-load-example-account.c
===================================================================
--- gnucash/branches/remove-group2/src/backend/file/test/test-load-example-account.c	2007-02-11 00:30:57 UTC (rev 15561)
+++ gnucash/branches/remove-group2/src/backend/file/test/test-load-example-account.c	2007-02-11 00:34:38 UTC (rev 15562)
@@ -45,11 +45,11 @@
 static const gchar *da_ending = ".gnucash-xea";
 
 static void
-test_load_file(QofBook *book, const char *filename)
+test_load_file(const char *filename)
 {
     GncExampleAccount *gea;
 
-    gea = gnc_read_example_account(book, filename);
+    gea = gnc_read_example_account(filename);
 
     if(gea != NULL)
     {
@@ -69,7 +69,6 @@
     const char *location = getenv("GNC_ACCOUNT_PATH");
     GSList *list = NULL;
     DIR *ea_dir;
-    QofBook *book;
 
     if (!location)
     {
@@ -79,8 +78,6 @@
     gnc_module_system_init();
     gnc_module_load("gnucash/engine", 0);
 
-    book = qof_book_new ();
-
     if((ea_dir = opendir(location)) == NULL)
     {
         failure("unable to open ea directory");
@@ -104,7 +101,7 @@
                 {
                     if(!S_ISDIR(file_info.st_mode))
                     {
-                        test_load_file(book, to_open);
+                        test_load_file(to_open);
                     }
                 }
                 g_free(to_open);
@@ -114,7 +111,7 @@
     closedir(ea_dir);
     
     {
-        list = gnc_load_example_account_list(book, location);
+        list = gnc_load_example_account_list(location);
 
         do_test(list != NULL, "gnc_load_example_account_list");
         

Modified: gnucash/branches/remove-group2/src/gnome/druid-hierarchy.c
===================================================================
--- gnucash/branches/remove-group2/src/gnome/druid-hierarchy.c	2007-02-11 00:30:57 UTC (rev 15561)
+++ gnucash/branches/remove-group2/src/gnome/druid-hierarchy.c	2007-02-11 00:34:38 UTC (rev 15562)
@@ -374,8 +374,7 @@
 
 	gnc_accounts_dir = gnc_path_get_accountsdir ();
 	locale_dir = gnc_get_ea_locale_dir (gnc_accounts_dir);
- 	list = gnc_load_example_account_list (data->temporary,
-					      locale_dir);
+ 	list = gnc_load_example_account_list (locale_dir);
 	g_free (gnc_accounts_dir);
 	g_free (locale_dir);
 
@@ -455,7 +454,6 @@
 
     /* Build the categories tree if necessary */
     gnc_suspend_gui_refresh ();
-    data->temporary = qof_book_new();
     account_categories_tree_view_prepare (data);
     gnc_resume_gui_refresh ();
   }
@@ -999,7 +997,6 @@
         account_trees_merge(gnc_get_current_root_account(), data->our_account_tree);
 
         delete_our_account_tree (data);
-        qof_book_destroy(data->temporary);
 
         when_completed = data->when_completed;
 	g_free(data);



More information about the gnucash-changes mailing list