r23472 - gnucash/trunk/src/backend/xml - Update progress bar while writing price DB as well as while reading it.

Mike Alexander mta at code.gnucash.org
Sat Nov 30 23:53:06 EST 2013


Author: mta
Date: 2013-11-30 23:53:05 -0500 (Sat, 30 Nov 2013)
New Revision: 23472
Trac: http://svn.gnucash.org/trac/changeset/23472

Modified:
   gnucash/trunk/src/backend/xml/io-gncxml-v2.c
Log:
Update progress bar while writing price DB as well as while reading it.

Modified: gnucash/trunk/src/backend/xml/io-gncxml-v2.c
===================================================================
--- gnucash/trunk/src/backend/xml/io-gncxml-v2.c	2013-12-01 03:24:43 UTC (rev 23471)
+++ gnucash/trunk/src/backend/xml/io-gncxml-v2.c	2013-12-01 04:53:05 UTC (rev 23472)
@@ -1126,20 +1126,55 @@
 write_pricedb(FILE *out, QofBook *book, sixtp_gdv2 *gd)
 {
     xmlNodePtr node;
+    xmlNodePtr parent;
+    xmlOutputBufferPtr outbuf;
 
-    node = gnc_pricedb_dom_tree_create(gnc_pricedb_get_db(book));
+    parent = gnc_pricedb_dom_tree_create(gnc_pricedb_get_db(book));
 
-    if (!node)
+    if (!parent)
     {
         return TRUE;
     }
 
-    xmlElemDump(out, NULL, node);
-    xmlFreeNode(node);
-
-    if (ferror(out) || fprintf(out, "\n") < 0)
+    /* Write out the parent pricedb tag then loop to write out each price.
+       We do it this way instead of just calling xmlElemDump so that we can
+       increment the progress bar as we go. */
+       
+    if (fprintf( out, "<%s version=\"%s\">\n", parent->name, 
+                 xmlGetProp(parent, (xmlChar*) "version")) < 0)
         return FALSE;
+        
+    /* We create our own output buffer so we can call xmlNodeDumpOutput to get
+       the indendation correct. */
+    outbuf = xmlOutputBufferCreateFile(out, NULL);
+    if (outbuf == NULL)
+    {
+        xmlFreeNode(parent);
+        return FALSE;
+    }
+       
+    for (node = parent->children; node; node = node->next)
+    {
+        /* Write two spaces since xmlNodeDumpOutput doesn't indent the first line */
+        xmlOutputBufferWrite(outbuf, 2, "  ");
+        xmlNodeDumpOutput(outbuf, NULL, node, 1, 1, NULL);
+        /* It also doesn't terminate the last line */
+        xmlOutputBufferWrite(outbuf, 1, "\n");
+        if (ferror(out)) 
+            break;
+        gd->counter.prices_loaded += 1;
+        run_callback(gd, "prices");
+    }
+    
+    xmlOutputBufferClose(outbuf);
+    
+    if (ferror(out) || fprintf(out, "</%s>\n", parent->name) < 0)
+    {
+        xmlFreeNode(parent);
+        return FALSE;
+    }
 
+    xmlFreeNode(parent);
     return TRUE;
 }
 



More information about the gnucash-changes mailing list