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.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@18594 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Phil Longstaff 2010-01-31 20:03:23 +00:00
parent ef5a742bf1
commit 6ed568ab77
5 changed files with 36 additions and 16 deletions

View File

@ -200,36 +200,31 @@ gnc_get_current_book (void)
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 *

View File

@ -203,11 +203,17 @@ create_book_tables( GncSqlBackend* be )
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;
}
/* ================================================================= */

View File

@ -1012,7 +1012,6 @@ identity_edit_response_cb (GtkDialog *dialog, gint response, gpointer data)
{
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 @@ identity_edit_response_cb (GtkDialog *dialog, gint response, gpointer data)
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);

View File

@ -262,7 +262,9 @@ qof_book_set_backend (QofBook *book, QofBackend *be)
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 @@ qof_book_get_counter (const QofBook *book, const char *counter_name)
}
/* 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,6 +464,21 @@ gboolean qof_book_use_trading_accounts (const QofBook *book)
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)
{

View File

@ -278,6 +278,9 @@ gboolean qof_book_equal (const QofBook *book_1, const QofBook *book_2);
*/
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);