r18594 - gnucash/trunk/src - Create routines qof_book_get_string_option() and qof_book_set_string_option() to get/set a kvp string, respectively.
Phil Longstaff
plongstaff at code.gnucash.org
Sun Jan 31 15:03:23 EST 2010
Author: plongstaff
Date: 2010-01-31 15:03:23 -0500 (Sun, 31 Jan 2010)
New Revision: 18594
Trac: http://svn.gnucash.org/trac/changeset/18594
Modified:
gnucash/trunk/src/app-utils/gnc-ui-util.c
gnucash/trunk/src/backend/sql/gnc-book-sql.c
gnucash/trunk/src/gnome/dialog-tax-info.c
gnucash/trunk/src/libqof/qof/qofbook.c
gnucash/trunk/src/libqof/qof/qofbook.h
Log:
Create routines qof_book_get_string_option() and qof_book_set_string_option() to get/set a kvp string, respectively.
qof_book_set_string_option() also handles saving the book so that the kvp is updated in the db.
In the future, qof_book_set_<type>_option() and qof_book_get_<type>_option() should be created, where type is
boolean, int, double, ... In addition, other places which handle options in the book should use these routines.
Modified: gnucash/trunk/src/app-utils/gnc-ui-util.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-ui-util.c 2010-01-31 18:37:28 UTC (rev 18593)
+++ gnucash/trunk/src/app-utils/gnc-ui-util.c 2010-01-31 20:03:23 UTC (rev 18594)
@@ -200,36 +200,31 @@
return qof_session_get_book (gnc_get_current_session ());
}
+#define OPTION_TAXUS_NAME "book/tax_US/name"
+#define OPTION_TAXUS_TYPE "book/tax_US/type"
+
void
gnc_set_current_book_tax_name (const gchar *tax_name)
{
- QofBook* current_book = gnc_get_current_book();
-
- qof_book_begin_edit(current_book);
- kvp_frame_set_string (qof_book_get_slots (current_book),
- "book/tax_US/name", tax_name);
- qof_book_commit_edit(current_book);
+ qof_book_set_string_option(gnc_get_current_book(), OPTION_TAXUS_NAME, tax_name);
}
const gchar *
gnc_get_current_book_tax_name (void)
{
- return kvp_frame_get_string (qof_book_get_slots (gnc_get_current_book()),
- "book/tax_US/name");
+ return qof_book_get_string_option(gnc_get_current_book(), OPTION_TAXUS_NAME);
}
void
gnc_set_current_book_tax_type (const gchar *tax_type)
{
- kvp_frame_set_string(qof_book_get_slots(gnc_get_current_book()),
- "book/tax_US/type", tax_type);
+ qof_book_set_string_option(gnc_get_current_book(), OPTION_TAXUS_TYPE, tax_type);
}
const gchar *
gnc_get_current_book_tax_type (void)
{
- return kvp_frame_get_string(qof_book_get_slots(gnc_get_current_book()),
- "book/tax_US/type");
+ return qof_book_get_string_option(gnc_get_current_book(), OPTION_TAXUS_TYPE);
}
Account *
Modified: gnucash/trunk/src/backend/sql/gnc-book-sql.c
===================================================================
--- gnucash/trunk/src/backend/sql/gnc-book-sql.c 2010-01-31 18:37:28 UTC (rev 18593)
+++ gnucash/trunk/src/backend/sql/gnc-book-sql.c 2010-01-31 20:03:23 UTC (rev 18594)
@@ -203,11 +203,17 @@
gboolean
gnc_sql_save_book( GncSqlBackend* be, QofInstance* inst)
{
+ gboolean status;
+
g_return_val_if_fail( be != NULL, FALSE );
g_return_val_if_fail( inst != NULL, FALSE );
g_return_val_if_fail( QOF_IS_BOOK(inst), FALSE );
- return gnc_sql_commit_standard_item( be, inst, BOOK_TABLE, GNC_ID_BOOK, col_table );
+ status = gnc_sql_commit_standard_item( be, inst, BOOK_TABLE, GNC_ID_BOOK, col_table );
+
+ qof_book_mark_saved( QOF_BOOK(inst) );
+
+ return status;
}
/* ================================================================= */
Modified: gnucash/trunk/src/gnome/dialog-tax-info.c
===================================================================
--- gnucash/trunk/src/gnome/dialog-tax-info.c 2010-01-31 18:37:28 UTC (rev 18593)
+++ gnucash/trunk/src/gnome/dialog-tax-info.c 2010-01-31 20:03:23 UTC (rev 18594)
@@ -1012,7 +1012,6 @@
{
ti_dialog->tax_type_changed = TRUE;
gnc_set_current_book_tax_type (entry_type);
- qof_book_kvp_changed(ti_dialog->this_book);
ti_dialog->tax_type = g_strdup (entry_type);
if (entry_type != NULL)
{
@@ -1041,7 +1040,6 @@
if (!(safe_strcmp (ti_dialog->tax_name, entry_name) == 0))
{
gnc_set_current_book_tax_name (entry_name);
- qof_book_kvp_changed(ti_dialog->this_book);
ti_dialog->tax_name = g_strdup (entry_name);
gtk_label_set_text (GTK_LABEL (ti_dialog->entity_name_display),
entry_name);
Modified: gnucash/trunk/src/libqof/qof/qofbook.c
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbook.c 2010-01-31 18:37:28 UTC (rev 18593)
+++ gnucash/trunk/src/libqof/qof/qofbook.c 2010-01-31 20:03:23 UTC (rev 18594)
@@ -262,7 +262,9 @@
void qof_book_kvp_changed (QofBook *book)
{
+ qof_book_begin_edit(book);
qof_book_mark_dirty(book);
+ qof_book_commit_edit(book);
}
/* ====================================================================== */
@@ -441,7 +443,8 @@
}
/* Determine whether this book uses trading accounts */
-gboolean qof_book_use_trading_accounts (const QofBook *book)
+gboolean
+qof_book_use_trading_accounts (const QofBook *book)
{
const char *opt;
kvp_value *kvp_val;
@@ -461,7 +464,22 @@
return FALSE;
}
+const char*
+qof_book_get_string_option(const QofBook* book, const char* opt_name)
+{
+ return kvp_frame_get_string(qof_book_get_slots(book), opt_name);
+}
+
void
+qof_book_set_string_option(QofBook* book, const char* opt_name, const char* opt_val)
+{
+ qof_book_begin_edit(book);
+ kvp_frame_set_string(qof_book_get_slots(book), opt_name, opt_val);
+ qof_book_mark_dirty(book);
+ qof_book_commit_edit(book);
+}
+
+void
qof_book_begin_edit (QofBook *book)
{
qof_begin_edit(&book->inst);
Modified: gnucash/trunk/src/libqof/qof/qofbook.h
===================================================================
--- gnucash/trunk/src/libqof/qof/qofbook.h 2010-01-31 18:37:28 UTC (rev 18593)
+++ gnucash/trunk/src/libqof/qof/qofbook.h 2010-01-31 20:03:23 UTC (rev 18594)
@@ -278,6 +278,9 @@
*/
gint64 qof_book_get_counter (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);
+
void qof_book_begin_edit(QofBook *book);
void qof_book_commit_edit(QofBook *book);
More information about the gnucash-changes
mailing list