r20054 - gnucash/trunk/src - Bug #638543: Centralize the counter formatting in qofbook.

Christian Stimming cstim at code.gnucash.org
Mon Jan 10 16:39:06 EST 2011


Author: cstim
Date: 2011-01-10 16:39:06 -0500 (Mon, 10 Jan 2011)
New Revision: 20054
Trac: http://svn.gnucash.org/trac/changeset/20054

Modified:
   gnucash/trunk/src/business/business-gnome/dialog-customer.c
   gnucash/trunk/src/business/business-gnome/dialog-employee.c
   gnucash/trunk/src/business/business-gnome/dialog-invoice.c
   gnucash/trunk/src/business/business-gnome/dialog-job.c
   gnucash/trunk/src/business/business-gnome/dialog-order.c
   gnucash/trunk/src/business/business-gnome/dialog-vendor.c
   gnucash/trunk/src/engine/gncCustomer.c
   gnucash/trunk/src/engine/gncCustomerP.h
   gnucash/trunk/src/engine/gncEmployee.c
   gnucash/trunk/src/engine/gncEmployeeP.h
   gnucash/trunk/src/engine/gncInvoice.c
   gnucash/trunk/src/engine/gncInvoiceP.h
   gnucash/trunk/src/engine/gncJob.c
   gnucash/trunk/src/engine/gncJobP.h
   gnucash/trunk/src/engine/gncOrder.c
   gnucash/trunk/src/engine/gncOrderP.h
   gnucash/trunk/src/engine/gncVendor.c
   gnucash/trunk/src/engine/gncVendorP.h
   gnucash/trunk/src/libqof/qof/qofbook.c
   gnucash/trunk/src/libqof/qof/qofbook.h
Log:
Bug #638543: Centralize the counter formatting in qofbook.

Patch by Matthijs Kooijman:

Instead of querying qofbook for the next counter number and then doing
the formatting in all the different business modules (all using the same
format string), the formatting is now moved inside
qof_book_increment_and_get_counter (which is renamed to
qof_book_increment_and_format_counter).

This changes the return value of a bunch of helper functions from gint64
(the counter value) to gchar* (the formatted counter value), but does
not have any user-visible changes.

Modified: gnucash/trunk/src/business/business-gnome/dialog-customer.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-customer.c	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/business/business-gnome/dialog-customer.c	2011-01-10 21:39:06 UTC (rev 20054)
@@ -305,8 +305,7 @@
     /* Set the customer id if one has not been chosen */
     if (safe_strcmp (gtk_entry_get_text (GTK_ENTRY (cw->id_entry)), "") == 0)
     {
-        string = g_strdup_printf ("%.6" G_GINT64_FORMAT,
-                                  gncCustomerNextID (cw->book));
+        string = gncCustomerNextID (cw->book);
         gtk_entry_set_text (GTK_ENTRY (cw->id_entry), string);
         g_free(string);
     }

Modified: gnucash/trunk/src/business/business-gnome/dialog-employee.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-employee.c	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/business/business-gnome/dialog-employee.c	2011-01-10 21:39:06 UTC (rev 20054)
@@ -241,8 +241,7 @@
     /* Set the employee id if one has not been chosen */
     if (safe_strcmp (gtk_entry_get_text (GTK_ENTRY (ew->id_entry)), "") == 0)
     {
-        string = g_strdup_printf ("%.6" G_GINT64_FORMAT,
-                                  gncEmployeeNextID (ew->book));
+        string = gncEmployeeNextID (ew->book);
         gtk_entry_set_text (GTK_ENTRY (ew->id_entry), string);
         g_free(string);
     }

Modified: gnucash/trunk/src/business/business-gnome/dialog-invoice.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/business/business-gnome/dialog-invoice.c	2011-01-10 21:39:06 UTC (rev 20054)
@@ -364,8 +364,7 @@
            Therefore we pass the GncOwer to gncInvoiceNextID
            so it knows whether we are creating a bill
            or an invoice. */
-        string = g_strdup_printf ("%.6" G_GINT64_FORMAT,
-                                  gncInvoiceNextID(iw->book, &(iw->owner)));
+        string = gncInvoiceNextID(iw->book, &(iw->owner));
         gtk_entry_set_text (GTK_ENTRY (iw->id_entry), string);
         g_free(string);
     }

Modified: gnucash/trunk/src/business/business-gnome/dialog-job.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-job.c	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/business/business-gnome/dialog-job.c	2011-01-10 21:39:06 UTC (rev 20054)
@@ -149,8 +149,7 @@
     res = gtk_entry_get_text (GTK_ENTRY (jw->id_entry));
     if (safe_strcmp (res, "") == 0)
     {
-        string = g_strdup_printf ("%.6" G_GINT64_FORMAT,
-                                  gncJobNextID(jw->book));
+        string = gncJobNextID(jw->book);
         gtk_entry_set_text (GTK_ENTRY (jw->id_entry), string);
         g_free(string);
     }

Modified: gnucash/trunk/src/business/business-gnome/dialog-order.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-order.c	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/business/business-gnome/dialog-order.c	2011-01-10 21:39:06 UTC (rev 20054)
@@ -705,8 +705,7 @@
                                        ow);
     /* Setup initial values */
     ow->order_guid = *gncOrderGetGUID (order);
-    string = g_strdup_printf ("%.6" G_GINT64_FORMAT,
-                              gncOrderNextID(bookp));
+    string = gncOrderNextID(bookp);
     gtk_entry_set_text (GTK_ENTRY (ow->id_entry), string);
     g_free(string);
 

Modified: gnucash/trunk/src/business/business-gnome/dialog-vendor.c
===================================================================
--- gnucash/trunk/src/business/business-gnome/dialog-vendor.c	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/business/business-gnome/dialog-vendor.c	2011-01-10 21:39:06 UTC (rev 20054)
@@ -225,8 +225,7 @@
     /* Check for valid id and set one if necessary */
     if (safe_strcmp (gtk_entry_get_text (GTK_ENTRY (vw->id_entry)), "") == 0)
     {
-        string = g_strdup_printf ("%.6" G_GINT64_FORMAT,
-                                  gncVendorNextID(vw->book));
+        string = gncVendorNextID(vw->book);
         gtk_entry_set_text (GTK_ENTRY (vw->id_entry), string);
         g_free(string);
     }

Modified: gnucash/trunk/src/engine/gncCustomer.c
===================================================================
--- gnucash/trunk/src/engine/gncCustomer.c	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/engine/gncCustomer.c	2011-01-10 21:39:06 UTC (rev 20054)
@@ -949,7 +949,7 @@
     return qof_object_register (&gncCustomerDesc);
 }
 
-gint64 gncCustomerNextID (QofBook *book)
+gchar *gncCustomerNextID (QofBook *book)
 {
-    return qof_book_increment_and_get_counter (book, _GNC_MOD_NAME);
+    return qof_book_increment_and_format_counter (book, _GNC_MOD_NAME);
 }

Modified: gnucash/trunk/src/engine/gncCustomerP.h
===================================================================
--- gnucash/trunk/src/engine/gncCustomerP.h	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/engine/gncCustomerP.h	2011-01-10 21:39:06 UTC (rev 20054)
@@ -32,7 +32,7 @@
 #include "gncCustomer.h"
 
 gboolean gncCustomerRegister (void);
-gint64 gncCustomerNextID (QofBook *book);
+gchar *gncCustomerNextID (QofBook *book);
 
 /** The gncCloneCustomer() routine makes a copy of the indicated
  *  customer, placing it in the indicated book.  It copies

Modified: gnucash/trunk/src/engine/gncEmployee.c
===================================================================
--- gnucash/trunk/src/engine/gncEmployee.c	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/engine/gncEmployee.c	2011-01-10 21:39:06 UTC (rev 20054)
@@ -740,7 +740,7 @@
     return qof_object_register (&gncEmployeeDesc);
 }
 
-gint64 gncEmployeeNextID (QofBook *book)
+gchar *gncEmployeeNextID (QofBook *book)
 {
-    return qof_book_increment_and_get_counter (book, _GNC_MOD_NAME);
+    return qof_book_increment_and_format_counter (book, _GNC_MOD_NAME);
 }

Modified: gnucash/trunk/src/engine/gncEmployeeP.h
===================================================================
--- gnucash/trunk/src/engine/gncEmployeeP.h	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/engine/gncEmployeeP.h	2011-01-10 21:39:06 UTC (rev 20054)
@@ -32,7 +32,7 @@
 #include "gncEmployee.h"
 
 gboolean gncEmployeeRegister (void);
-gint64 gncEmployeeNextID (QofBook *book);
+gchar *gncEmployeeNextID (QofBook *book);
 
 /** The gncCloneEmployee() routine makes a copy of the indicated
  *  employee, placing it in the indicated book.  It copies

Modified: gnucash/trunk/src/engine/gncInvoice.c
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.c	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/engine/gncInvoice.c	2011-01-10 21:39:06 UTC (rev 20054)
@@ -2125,22 +2125,22 @@
     return qof_object_register (&gncInvoiceDesc);
 }
 
-gint64 gncInvoiceNextID (QofBook *book, GncOwner *owner)
+gchar *gncInvoiceNextID (QofBook *book, GncOwner *owner)
 {
-    gint64 nextID;
+    gchar *nextID;
     switch (gncOwnerGetType(gncOwnerGetEndOwner(owner)))
     {
     case GNC_OWNER_CUSTOMER:
-        nextID = qof_book_increment_and_get_counter (book, "gncInvoice");
+        nextID = qof_book_increment_and_format_counter (book, "gncInvoice");
         break;
     case GNC_OWNER_VENDOR:
-        nextID = qof_book_increment_and_get_counter (book, "gncBill");
+        nextID = qof_book_increment_and_format_counter (book, "gncBill");
         break;
     case GNC_OWNER_EMPLOYEE:
-        nextID = qof_book_increment_and_get_counter (book, "gncExpVoucher");
+        nextID = qof_book_increment_and_format_counter (book, "gncExpVoucher");
         break;
     default:
-        nextID = qof_book_increment_and_get_counter (book, _GNC_MOD_NAME);
+        nextID = qof_book_increment_and_format_counter (book, _GNC_MOD_NAME);
         break;
     }
     return nextID;

Modified: gnucash/trunk/src/engine/gncInvoiceP.h
===================================================================
--- gnucash/trunk/src/engine/gncInvoiceP.h	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/engine/gncInvoiceP.h	2011-01-10 21:39:06 UTC (rev 20054)
@@ -35,7 +35,7 @@
 #include "gncOwner.h"
 
 gboolean gncInvoiceRegister (void);
-gint64 gncInvoiceNextID (QofBook *book, GncOwner *owner);
+gchar *gncInvoiceNextID (QofBook *book, GncOwner *owner);
 void gncInvoiceSetPostedAcc (GncInvoice *invoice, Account *acc);
 void gncInvoiceSetPostedTxn (GncInvoice *invoice, Transaction *txn);
 void gncInvoiceSetPostedLot (GncInvoice *invoice, GNCLot *lot);

Modified: gnucash/trunk/src/engine/gncJob.c
===================================================================
--- gnucash/trunk/src/engine/gncJob.c	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/engine/gncJob.c	2011-01-10 21:39:06 UTC (rev 20054)
@@ -583,7 +583,7 @@
     return qof_object_register (&gncJobDesc);
 }
 
-gint64 gncJobNextID (QofBook *book)
+gchar *gncJobNextID (QofBook *book)
 {
-    return qof_book_increment_and_get_counter (book, _GNC_MOD_NAME);
+    return qof_book_increment_and_format_counter (book, _GNC_MOD_NAME);
 }

Modified: gnucash/trunk/src/engine/gncJobP.h
===================================================================
--- gnucash/trunk/src/engine/gncJobP.h	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/engine/gncJobP.h	2011-01-10 21:39:06 UTC (rev 20054)
@@ -32,7 +32,7 @@
 #include "gncJob.h"
 
 gboolean gncJobRegister (void);
-gint64 gncJobNextID (QofBook *book);
+gchar *gncJobNextID (QofBook *book);
 
 /** The gncCloneTaxTable() routine makes a copy of the indicated
  *  tax table, placing it in the indicated book.  It copies

Modified: gnucash/trunk/src/engine/gncOrder.c
===================================================================
--- gnucash/trunk/src/engine/gncOrder.c	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/engine/gncOrder.c	2011-01-10 21:39:06 UTC (rev 20054)
@@ -604,7 +604,7 @@
     return qof_object_register (&gncOrderDesc);
 }
 
-gint64 gncOrderNextID (QofBook *book)
+gchar *gncOrderNextID (QofBook *book)
 {
-    return qof_book_increment_and_get_counter (book, _GNC_MOD_NAME);
+    return qof_book_increment_and_format_counter (book, _GNC_MOD_NAME);
 }

Modified: gnucash/trunk/src/engine/gncOrderP.h
===================================================================
--- gnucash/trunk/src/engine/gncOrderP.h	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/engine/gncOrderP.h	2011-01-10 21:39:06 UTC (rev 20054)
@@ -32,7 +32,7 @@
 #include "gncOrder.h"
 
 gboolean gncOrderRegister (void);
-gint64 gncOrderNextID (QofBook *book);
+gchar *gncOrderNextID (QofBook *book);
 
 /** The gncCloneOrder() routine makes a copy of the indicated
  *  order, placing it in the indicated book.  It copies

Modified: gnucash/trunk/src/engine/gncVendor.c
===================================================================
--- gnucash/trunk/src/engine/gncVendor.c	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/engine/gncVendor.c	2011-01-10 21:39:06 UTC (rev 20054)
@@ -859,7 +859,7 @@
     return qof_object_register (&gncVendorDesc);
 }
 
-gint64 gncVendorNextID (QofBook *book)
+gchar *gncVendorNextID (QofBook *book)
 {
-    return qof_book_increment_and_get_counter (book, _GNC_MOD_NAME);
+    return qof_book_increment_and_format_counter (book, _GNC_MOD_NAME);
 }

Modified: gnucash/trunk/src/engine/gncVendorP.h
===================================================================
--- gnucash/trunk/src/engine/gncVendorP.h	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/engine/gncVendorP.h	2011-01-10 21:39:06 UTC (rev 20054)
@@ -31,7 +31,7 @@
 #include "gncVendor.h"
 
 gboolean gncVendorRegister (void);
-gint64 gncVendorNextID (QofBook *book);
+gchar *gncVendorNextID (QofBook *book);
 
 /** The gncCloneVendor() routine makes a copy of the indicated
  *  vendor, placing it in the indicated book.  It copies

Modified: gnucash/trunk/src/libqof/qof/qofbook.c
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbook.c	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/libqof/qof/qofbook.c	2011-01-10 21:39:06 UTC (rev 20054)
@@ -429,8 +429,8 @@
     }
 }
 
-gint64
-qof_book_increment_and_get_counter (QofBook *book, const char *counter_name)
+gchar *
+qof_book_increment_and_format_counter (QofBook *book, const char *counter_name)
 {
     QofBackend *be;
     KvpFrame *kvp;
@@ -440,13 +440,13 @@
     if (!book)
     {
         PWARN ("No book!!!");
-        return -1;
+        return NULL;
     }
 
     if (!counter_name || *counter_name == '\0')
     {
         PWARN ("Invalid counter name.");
-        return -1;
+        return NULL;
     }
 
     /* Get the current counter value from the KVP in the book. */
@@ -454,7 +454,7 @@
 
     /* Check if an error occured */
     if (counter < 0)
-	return -1;
+	return NULL;
 
     /* Increment the counter */
     counter++;
@@ -465,7 +465,7 @@
     if (!kvp)
     {
 	PWARN ("Book has no KVP_Frame");
-	return -1;
+	return NULL;
     }
 
     /* Save off the new counter */
@@ -476,7 +476,8 @@
     qof_book_mark_dirty(book);
     qof_book_commit_edit(book);
 
-    return counter;
+    /* Generate a string version of the counter */
+    return g_strdup_printf ("%.6" G_GINT64_FORMAT, counter);
 }
 
 /* Determine whether this book uses trading accounts */

Modified: gnucash/trunk/src/libqof/qof/qofbook.h
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbook.h	2011-01-10 21:38:54 UTC (rev 20053)
+++ gnucash/trunk/src/libqof/qof/qofbook.h	2011-01-10 21:39:06 UTC (rev 20054)
@@ -283,11 +283,11 @@
  */
 gint64 qof_book_get_counter (QofBook *book, const char *counter_name);
 
-/** This will increment the named counter for this book and return it.
- *    The return value is -1 on error or the (new) value of the
- *    counter.
+/** This will increment the named counter for this book and format it.
+ *    The return value is NULL on error or the formatted (new) value of
+ *    the counter. The caller should free the result with g_gree.
  */
-gint64 qof_book_increment_and_get_counter (QofBook *book, const char *counter_name);
+gchar *qof_book_increment_and_format_counter (QofBook *book, const char *counter_name);
 
 const char* qof_book_get_string_option(const QofBook* book, const char* opt_name);
 void qof_book_set_string_option(QofBook* book, const char* opt_name, const char* opt_val);



More information about the gnucash-changes mailing list