r20055 - gnucash/trunk/src - Bug #638543: Make the various counter formats configurable.
Christian Stimming
cstim at code.gnucash.org
Mon Jan 10 16:39:18 EST 2011
Author: cstim
Date: 2011-01-10 16:39:18 -0500 (Mon, 10 Jan 2011)
New Revision: 20055
Trac: http://svn.gnucash.org/trac/changeset/20055
Modified:
gnucash/trunk/src/engine/kvp_doc.txt
gnucash/trunk/src/libqof/qof/qofbook.c
gnucash/trunk/src/libqof/qof/qofbook.h
Log:
Bug #638543: Make the various counter formats configurable.
Patch by Matthijs Kooijman:
This retrieves the counter formats from the kvp slots in the book. The
defaults are unchanged, so this should not affect existing books at all.
Modified: gnucash/trunk/src/engine/kvp_doc.txt
===================================================================
--- gnucash/trunk/src/engine/kvp_doc.txt 2011-01-10 21:39:06 UTC (rev 20054)
+++ gnucash/trunk/src/engine/kvp_doc.txt 2011-01-10 21:39:18 UTC (rev 20055)
@@ -175,6 +175,20 @@
that follows /counters/, e.g. "/counters/GncCustomer"
\endverbatim
+\verbatim
+Name: /counter_formats/...
+Type: string
+Entities: Book
+Use: Holders for a bunch of counter formats for various types. Used
+ specifically in the business objects, to format a counter value
+ into a (string) ID. The counter name is the path that follows
+ /counter_formats/, e.g. "/counter_formats/GncCustomer"
+
+ These formats are printf-style format strings that contain exactly
+ one format specifier for an int64 (optionally preceded or followed
+ by arbitrary other strings).
+\endverbatim
+
\subsection kvpD D
\subsection kvpE E
Modified: gnucash/trunk/src/libqof/qof/qofbook.c
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbook.c 2011-01-10 21:39:06 UTC (rev 20054)
+++ gnucash/trunk/src/libqof/qof/qofbook.c 2011-01-10 21:39:18 UTC (rev 20055)
@@ -436,6 +436,7 @@
KvpFrame *kvp;
KvpValue *value;
gint64 counter;
+ gchar* format;
if (!book)
{
@@ -476,10 +477,60 @@
qof_book_mark_dirty(book);
qof_book_commit_edit(book);
+ format = qof_book_get_counter_format(book, counter_name);
+
+ if (!format)
+ {
+ PWARN("Cannot get format for counter");
+ return NULL;
+ }
+
/* Generate a string version of the counter */
- return g_strdup_printf ("%.6" G_GINT64_FORMAT, counter);
+ return g_strdup_printf(format, counter);
}
+gchar *
+qof_book_get_counter_format(const QofBook *book, const char *counter_name)
+{
+ KvpFrame *kvp;
+ gchar *format;
+ KvpValue *value;
+
+ if (!book)
+ {
+ PWARN ("No book!!!");
+ return NULL;
+ }
+
+ if (!counter_name || *counter_name == '\0')
+ {
+ PWARN ("Invalid counter name.");
+ return NULL;
+ }
+
+ /* Get the KVP from the current book */
+ kvp = qof_book_get_slots (book);
+
+ if (!kvp)
+ {
+ PWARN ("Book has no KVP_Frame");
+ return NULL;
+ }
+
+ /* Get the format string */
+ value = kvp_frame_get_slot_path (kvp, "counter_formats", counter_name, NULL);
+ if (value)
+ {
+ format = kvp_value_get_string (value);
+ }
+ else
+ {
+ /* Use the default format */
+ format = "%.6" G_GINT64_FORMAT;
+ }
+ return format;
+}
+
/* Determine whether this book uses trading accounts */
gboolean
qof_book_use_trading_accounts (const QofBook *book)
Modified: gnucash/trunk/src/libqof/qof/qofbook.h
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbook.h 2011-01-10 21:39:06 UTC (rev 20054)
+++ gnucash/trunk/src/libqof/qof/qofbook.h 2011-01-10 21:39:18 UTC (rev 20055)
@@ -289,6 +289,12 @@
*/
gchar *qof_book_increment_and_format_counter (QofBook *book, const char *counter_name);
+/** Get the format string to use for the named counter.
+ * The return value is NULL on error or the format string of the
+ * counter. The string should not be freed.
+ */
+gchar *qof_book_get_counter_format (const 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