mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20055 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
aa151f0ae0
commit
e1c6d28eac
@ -175,6 +175,20 @@ Use: Holders for a bunch of counters for various types. Used specifically
|
||||
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
|
||||
|
@ -436,6 +436,7 @@ qof_book_increment_and_format_counter (QofBook *book, const char *counter_name)
|
||||
KvpFrame *kvp;
|
||||
KvpValue *value;
|
||||
gint64 counter;
|
||||
gchar* format;
|
||||
|
||||
if (!book)
|
||||
{
|
||||
@ -476,8 +477,58 @@ qof_book_increment_and_format_counter (QofBook *book, const char *counter_name)
|
||||
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 */
|
||||
|
@ -289,6 +289,12 @@ gint64 qof_book_get_counter (QofBook *book, const char *counter_name);
|
||||
*/
|
||||
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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user