From b50ca70f50738f38d6d67dc15ae8ab754e2b976a Mon Sep 17 00:00:00 2001 From: Mike Alexander Date: Sun, 1 Dec 2013 04:53:05 +0000 Subject: [PATCH] Update progress bar while writing price DB as well as while reading it. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@23472 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/backend/xml/io-gncxml-v2.c | 47 +++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 6 deletions(-) diff --git a/src/backend/xml/io-gncxml-v2.c b/src/backend/xml/io-gncxml-v2.c index 705bcf6f9a..01f45fccf8 100644 --- a/src/backend/xml/io-gncxml-v2.c +++ b/src/backend/xml/io-gncxml-v2.c @@ -1126,20 +1126,55 @@ static gboolean 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, "\n", parent->name) < 0) + { + xmlFreeNode(parent); + return FALSE; + } + xmlFreeNode(parent); return TRUE; }