Miscellaneous KVP cleanup in Engine.

Doesn't include tests or Scheme support.
This commit is contained in:
John Ralls 2015-06-09 16:19:41 -07:00
parent f631f6e6c5
commit a4c748e201
8 changed files with 52 additions and 36 deletions

View File

@ -338,7 +338,7 @@ gnc_numeric xaccSplitGetReconciledBalance (const Split *split);
*
* @param check_txn_splits If the pointers are not equal, but
* everything else so far is equal (including memo, amount, value,
* kvp_frame), then, when comparing the parenting transactions with
* kvp), then, when comparing the parenting transactions with
* xaccTransEqual(), set its argument check_splits to be TRUE.
*/
gboolean xaccSplitEqual(const Split *sa, const Split *sb,
@ -515,8 +515,6 @@ gnc_numeric xaccSplitVoidFormerValue(const Split *split);
* override so the gnome-search dialog displays the right type.
@{
*/
#define SPLIT_KVP "kvp"
#define SPLIT_DATE_RECONCILED "date-reconciled"
#define SPLIT_BALANCE "balance"
#define SPLIT_CLEARED_BALANCE "cleared-balance"

View File

@ -164,13 +164,6 @@ QofBackend * xaccTransactionGetBackend (Transaction *trans);
void xaccEnableDataScrubbing(void);
void xaccDisableDataScrubbing(void);
/** Set the KvpFrame slots of this transaction to the given frm by
* * directly using the frm pointer (i.e. non-copying).
* * XXX this is wrong, nedds to be replaced with a transactional thingy
* in kvp + qofinstance. for now, this is a quasi-unctional placeholder.
* */
#define xaccTransSetSlots_nc(T,F) qof_instance_set_slots(QOF_INSTANCE(T),F)
void xaccTransRemoveSplit (Transaction *trans, const Split *split);
void check_open (const Transaction *trans);

View File

@ -940,8 +940,7 @@ gnc_commodity_copy(gnc_commodity * dest, const gnc_commodity *src)
gnc_commodity_set_quote_flag (dest, src_priv->quote_flag);
gnc_commodity_set_quote_source (dest, gnc_commodity_get_quote_source (src));
gnc_commodity_set_quote_tz (dest, src_priv->quote_tz);
kvp_frame_delete (dest->inst.kvp_data);
dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);
qof_instance_copy_kvp (QOF_INSTANCE (dest), QOF_INSTANCE (src));
}
gnc_commodity *
@ -967,8 +966,7 @@ gnc_commodity_clone(const gnc_commodity *src, QofBook *dest_book)
gnc_commodity_set_quote_source (dest, gnc_commodity_get_quote_source (src));
kvp_frame_delete (dest->inst.kvp_data);
dest->inst.kvp_data = kvp_frame_copy (src->inst.kvp_data);
qof_instance_copy_kvp (QOF_INSTANCE (dest), QOF_INSTANCE (src));
reset_printname(dest_priv);
reset_unique_name(dest_priv);
@ -1087,11 +1085,14 @@ static gboolean
gnc_commodity_get_auto_quote_control_flag(const gnc_commodity *cm)
{
const char *str;
GValue v = G_VALUE_INIT;
if (!cm) return FALSE;
str = kvp_frame_get_string(cm->inst.kvp_data, "auto_quote_control");
return !str || (strcmp(str, "false") != 0);
qof_instance_get_kvp (QOF_INSTANCE (cm), "auto_quote_control", &v);
if (G_VALUE_HOLDS_STRING (&v) &&
strcmp(g_value_get_string (&v), "false") == 0)
return FALSE;
return TRUE;
}
/********************************************************************
@ -1148,8 +1149,12 @@ const char*
gnc_commodity_get_user_symbol(const gnc_commodity *cm)
{
const char *str;
GValue v = G_VALUE_INIT;
if (!cm) return NULL;
return kvp_frame_get_string(cm->inst.kvp_data, "user_symbol");
qof_instance_get_kvp (QOF_INSTANCE(cm), "user_symbol", &v);
if (G_VALUE_HOLDS_STRING (&v))
return g_value_get_string (&v);
return NULL;
}
/********************************************************************
@ -1308,6 +1313,7 @@ static void
gnc_commodity_set_auto_quote_control_flag(gnc_commodity *cm,
const gboolean flag)
{
GValue v = G_VALUE_INIT;
ENTER ("(cm=%p, flag=%d)", cm, flag);
if (!cm)
@ -1315,10 +1321,15 @@ gnc_commodity_set_auto_quote_control_flag(gnc_commodity *cm,
LEAVE("");
return;
}
gnc_commodity_begin_edit(cm);
kvp_frame_set_string(cm->inst.kvp_data,
"auto_quote_control", flag ? NULL : "false");
if (flag)
qof_instance_set_kvp (QOF_INSTANCE (cm), "auto_quote_control", NULL);
else
{
g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, "false");
qof_instance_set_kvp (QOF_INSTANCE (cm), "auto_quote_control", &v);
}
mark_commodity_dirty(cm);
gnc_commodity_commit_edit(cm);
LEAVE("");
@ -1431,7 +1442,7 @@ void
gnc_commodity_set_user_symbol(gnc_commodity * cm, const char * user_symbol)
{
struct lconv *lc;
GValue v = G_VALUE_INIT;
if (!cm) return;
ENTER ("(cm=%p, symbol=%s)", cm, user_symbol ? user_symbol : "(null)");
@ -1448,8 +1459,15 @@ gnc_commodity_set_user_symbol(gnc_commodity * cm, const char * user_symbol)
user_symbol = NULL;
else if (!g_strcmp0(user_symbol, gnc_commodity_get_default_symbol(cm)))
user_symbol = NULL;
if (user_symbol)
{
g_value_init (&v, G_TYPE_STRING);
g_value_set_string (&v, user_symbol);
qof_instance_set_kvp (QOF_INSTANCE(cm), "user_symbol", &v);
}
else
qof_instance_set_kvp (QOF_INSTANCE(cm), "user_symbol", NULL);
kvp_frame_set_string(cm->inst.kvp_data, "user_symbol", user_symbol);
mark_commodity_dirty(cm);
gnc_commodity_commit_edit(cm);

View File

@ -495,7 +495,7 @@ static void address_free (QofInstance *inst)
void gncAddressCommitEdit (GncAddress *addr)
{
/* GnuCash 2.6.3 and earlier didn't handle address kvp's... */
if (!kvp_frame_is_empty (addr->inst.kvp_data))
if (qof_instance_has_kvp(QOF_INSTANCE(addr)))
gnc_features_set_used (qof_instance_get_book (QOF_INSTANCE (addr)), GNC_FEATURE_KVP_EXTRA_DATA);
if (!qof_commit_edit (QOF_INSTANCE(addr))) return;

View File

@ -1532,8 +1532,9 @@ static void entry_free (QofInstance *inst)
void gncEntryCommitEdit (GncEntry *entry)
{
/* GnuCash 2.6.3 and earlier didn't handle entry kvp's... */
if (!kvp_frame_is_empty (entry->inst.kvp_data))
gnc_features_set_used (qof_instance_get_book (QOF_INSTANCE (entry)), GNC_FEATURE_KVP_EXTRA_DATA);
if (qof_instance_has_kvp(QOF_INSTANCE(entry)))
gnc_features_set_used (qof_instance_get_book (QOF_INSTANCE (entry)),
GNC_FEATURE_KVP_EXTRA_DATA);
if (!qof_commit_edit (QOF_INSTANCE(entry))) return;
qof_commit_edit_part2 (&entry->inst, gncEntryOnError,

View File

@ -338,7 +338,7 @@ GncInvoice *gncInvoiceCopy (const GncInvoice *from)
GncInvoice *invoice;
QofBook* book;
GList *node;
gint64 is_cn;
GValue v = G_VALUE_INIT;
g_assert(from);
book = qof_instance_get_book(from);
@ -354,8 +354,9 @@ GncInvoice *gncInvoiceCopy (const GncInvoice *from)
invoice->billing_id = CACHE_INSERT (from->billing_id);
invoice->active = from->active;
is_cn = kvp_frame_get_gint64(from->inst.kvp_data, GNC_INVOICE_IS_CN);
kvp_frame_set_gint64(invoice->inst.kvp_data, GNC_INVOICE_IS_CN, is_cn);
qof_instance_get_kvp (QOF_INSTANCE (from), GNC_INVOICE_IS_CN, &v);
if (G_VALUE_HOLDS_INT64 (&v))
qof_instance_set_kvp (QOF_INSTANCE (invoice), GNC_INVOICE_IS_CN, &v);
invoice->terms = from->terms;
gncBillTermIncRef (invoice->terms);
@ -545,10 +546,12 @@ void gncInvoiceSetActive (GncInvoice *invoice, gboolean active)
void gncInvoiceSetIsCreditNote (GncInvoice *invoice, gboolean credit_note)
{
GValue v = G_VALUE_INIT;
if (!invoice) return;
gncInvoiceBeginEdit (invoice);
kvp_frame_set_gint64(invoice->inst.kvp_data, GNC_INVOICE_IS_CN,
credit_note ? 1 : 0);
g_value_init (&v, G_TYPE_INT64);
g_value_set_int64(&v, credit_note ? 1 : 0);
qof_instance_set_kvp (QOF_INSTANCE (invoice), GNC_INVOICE_IS_CN, &v);
mark_invoice (invoice);
gncInvoiceCommitEdit (invoice);
@ -1035,8 +1038,10 @@ gboolean gncInvoiceGetActive (const GncInvoice *invoice)
gboolean gncInvoiceGetIsCreditNote (const GncInvoice *invoice)
{
GValue v = G_VALUE_INIT;
if (!invoice) return FALSE;
if (kvp_frame_get_gint64(invoice->inst.kvp_data, GNC_INVOICE_IS_CN))
qof_instance_get_kvp (QOF_INSTANCE(invoice), GNC_INVOICE_IS_CN, &v);
if (G_VALUE_HOLDS_INT64(&v) && g_value_get_int64(&v))
return TRUE;
else
return FALSE;

View File

@ -655,8 +655,9 @@ static void table_free (QofInstance *inst)
void gncTaxTableCommitEdit (GncTaxTable *table)
{
/* GnuCash 2.6.3 and earlier didn't handle taxtable kvp's... */
if (!kvp_frame_is_empty (table->inst.kvp_data))
gnc_features_set_used (qof_instance_get_book (QOF_INSTANCE (table)), GNC_FEATURE_KVP_EXTRA_DATA);
if (qof_instance_has_kvp (QOF_INSTANCE (table)))
gnc_features_set_used (qof_instance_get_book (QOF_INSTANCE (table)),
GNC_FEATURE_KVP_EXTRA_DATA);
if (!qof_commit_edit (QOF_INSTANCE(table))) return;
qof_commit_edit_part2 (&table->inst, gncTaxTableOnError,

View File

@ -1464,7 +1464,7 @@ get_random_transaction_with_currency(QofBook *book,
trn_add_ran_timespec(trans, xaccTransSetDateEnteredTS);
f = get_random_kvp_frame();
xaccTransSetSlots_nc(trans, f);
qof_instance_set_slots (QOF_INSTANCE (trans), f);
add_random_splits(book, trans, account_list);
@ -1525,7 +1525,7 @@ make_random_changes_to_transaction (QofBook *book, Transaction *trans)
set_tran_random_string (trans, xaccTransSetDescription);
xaccTransSetSlots_nc (trans, get_random_kvp_frame());
qof_instance_set_slots (QOF_INSTANCE (trans), get_random_kvp_frame());
/* Do split manipulations in higher-level functions */