From 3a51d704c892029d82d3e56827f8f98c63d8f26b Mon Sep 17 00:00:00 2001 From: John Ralls Date: Mon, 21 Oct 2013 15:16:45 -0700 Subject: [PATCH] Replace usage of SX kvp access with SX properties. --- src/app-utils/gnc-sx-instance-model.c | 124 ++++++------------ src/engine/SchedXaction.h | 5 - src/engine/test/test-engine-kvp-properties.c | 7 + src/gnome-utils/gnc-tree-util-split-reg.c | 51 ++++--- src/gnome-utils/gnc-tree-view-split-reg.c | 79 +++-------- src/gnome/dialog-sx-editor.c | 113 +++++++--------- src/gnome/dialog-sx-editor2.c | 111 +++++++--------- src/gnome/gnc-plugin-page-register2.c | 53 ++++---- src/gnome/gnc-split-reg.c | 51 +++---- .../ledger-core/split-register-model-save.c | 82 ++++-------- .../ledger-core/split-register-model.c | 60 +++++---- 11 files changed, 285 insertions(+), 451 deletions(-) diff --git a/src/app-utils/gnc-sx-instance-model.c b/src/app-utils/gnc-sx-instance-model.c index 096507672e..6e3595b889 100644 --- a/src/app-utils/gnc-sx-instance-model.c +++ b/src/app-utils/gnc-sx-instance-model.c @@ -176,10 +176,9 @@ _get_vars_helper(Transaction *txn, void *var_hash_data) { GHashTable *var_hash = (GHashTable*)var_hash_data; GList *split_list; - kvp_frame *kvpf; - kvp_value *kvp_val; Split *s; - char *str; + gchar *credit_formula; + gchar *debit_formula; gnc_commodity *first_cmdty = NULL; split_list = xaccTransGetSplitList(txn); @@ -195,12 +194,12 @@ _get_vars_helper(Transaction *txn, void *var_hash_data) Account *acct; s = (Split*)split_list->data; - kvpf = xaccSplitGetSlots(s); - kvp_val = kvp_frame_get_slot_path(kvpf, - GNC_SX_ID, - GNC_SX_ACCOUNT, - NULL); - acct_guid = kvp_value_get_guid(kvp_val); + + qof_instance_get (QOF_INSTANCE (s), + "sx-account", &acct_guid, + "sx-credit-formula", &credit_formula, + "sx-debit-formula", &debit_formula, + NULL); acct = xaccAccountLookup(acct_guid, gnc_get_current_book()); split_cmdty = xaccAccountGetCommodity(acct); if (first_cmdty == NULL) @@ -226,31 +225,16 @@ _get_vars_helper(Transaction *txn, void *var_hash_data) } // existing... ------------------------------------------ - kvp_val = kvp_frame_get_slot_path(kvpf, - GNC_SX_ID, - GNC_SX_CREDIT_FORMULA, - NULL); - if (kvp_val != NULL) - { - str = kvp_value_get_string(kvp_val); - if (str && strlen(str) != 0) - { - gnc_sx_parse_vars_from_formula(str, var_hash, NULL); - } - } - - kvp_val = kvp_frame_get_slot_path(kvpf, - GNC_SX_ID, - GNC_SX_DEBIT_FORMULA, - NULL); - if (kvp_val != NULL) - { - str = kvp_value_get_string(kvp_val); - if (str && strlen(str) != 0) - { - gnc_sx_parse_vars_from_formula(str, var_hash, NULL); - } - } + if (credit_formula && strlen(credit_formula) != 0) + { + gnc_sx_parse_vars_from_formula(credit_formula, var_hash, NULL); + } + if (debit_formula && strlen(debit_formula) != 0) + { + gnc_sx_parse_vars_from_formula(debit_formula, var_hash, NULL); + } + g_free (credit_formula); + g_free (debit_formula); } return 0; @@ -903,28 +887,9 @@ static gboolean _get_template_split_account(const SchedXaction* sx, const Split *template_split, Account **split_acct, GList **creation_errors) { GncGUID *acct_guid; - kvp_frame *split_kvpf; - kvp_value *kvp_val; - - split_kvpf = xaccSplitGetSlots(template_split); - /* contains the guid of the split's actual account. */ - kvp_val = kvp_frame_get_slot_path(split_kvpf, - GNC_SX_ID, - GNC_SX_ACCOUNT, - NULL); - if (kvp_val == NULL) - { - GString *err = g_string_new(""); - g_string_printf(err, "Null account kvp value for SX [%s], cancelling creation.", - xaccSchedXactionGetName(sx)); - g_critical("%s", err->str); - if (creation_errors != NULL) - *creation_errors = g_list_append(*creation_errors, err); - else - g_string_free(err, TRUE); - return FALSE; - } - acct_guid = kvp_value_get_guid( kvp_val ); + qof_instance_get (QOF_INSTANCE (template_split), + "sx-account", &acct_guid, + NULL); *split_acct = xaccAccountLookup(acct_guid, gnc_get_current_book()); if (*split_acct == NULL) { @@ -948,18 +913,13 @@ _get_template_split_account(const SchedXaction* sx, const Split *template_split, static void _get_sx_formula_value(const SchedXaction* sx, const Split *template_split, gnc_numeric *numeric, GList **creation_errors, const char *formula_key, const char* numeric_key, GHashTable *variable_bindings) { - kvp_frame *split_kvpf; - kvp_value *kvp_val; + char *formula_str, *parseErrorLoc; + qof_instance_get (QOF_INSTANCE (template_split), + formula_key, &formula_str, + numeric_key, &numeric, + NULL); - split_kvpf = xaccSplitGetSlots(template_split); - - /* First look up the gnc_numeric value in the template split */ - kvp_val = kvp_frame_get_slot_path(split_kvpf, - GNC_SX_ID, - numeric_key, - NULL); - *numeric = kvp_value_get_numeric(kvp_val); if ((gnc_numeric_check(*numeric) == GNC_ERROR_OK) && !gnc_numeric_zero_p(*numeric)) { @@ -969,11 +929,6 @@ _get_sx_formula_value(const SchedXaction* sx, const Split *template_split, gnc_n return; } - kvp_val = kvp_frame_get_slot_path(split_kvpf, - GNC_SX_ID, - formula_key, - NULL); - formula_str = kvp_value_get_string(kvp_val); if (formula_str != NULL && strlen(formula_str) != 0) { GHashTable *parser_vars = NULL; @@ -1010,13 +965,17 @@ _get_sx_formula_value(const SchedXaction* sx, const Split *template_split, gnc_n static void _get_credit_formula_value(GncSxInstance *instance, const Split *template_split, gnc_numeric *credit_num, GList **creation_errors) { - _get_sx_formula_value(instance->parent->sx, template_split, credit_num, creation_errors, GNC_SX_CREDIT_FORMULA, GNC_SX_CREDIT_NUMERIC, instance->variable_bindings); + _get_sx_formula_value(instance->parent->sx, template_split, credit_num, + creation_errors, "sx-credit-formula", + "sx-credit-numeric", instance->variable_bindings); } static void _get_debit_formula_value(GncSxInstance *instance, const Split *template_split, gnc_numeric *debit_num, GList **creation_errors) { - _get_sx_formula_value(instance->parent->sx, template_split, debit_num, creation_errors, GNC_SX_DEBIT_FORMULA, GNC_SX_DEBIT_NUMERIC, instance->variable_bindings); + _get_sx_formula_value(instance->parent->sx, template_split, debit_num, + creation_errors, "sx-debit-formula", + "sx-debit-numeric", instance->variable_bindings); } static gboolean @@ -1087,9 +1046,6 @@ create_each_transaction_helper(Transaction *template_txn, void *user_data) break; } - /* clear out any copied Split frame data. */ - qof_instance_set_slots(QOF_INSTANCE(copying_split), kvp_frame_new()); - split_cmdty = xaccAccountGetCommodity(split_acct); if (first_cmdty == NULL) { @@ -1212,9 +1168,10 @@ create_each_transaction_helper(Transaction *template_txn, void *user_data) } { - kvp_frame *txn_frame; - txn_frame = xaccTransGetSlots(new_txn); - kvp_frame_set_guid(txn_frame, "from-sched-xaction", xaccSchedXactionGetGUID(creation_data->instance->parent->sx)); + qof_instance_set (QOF_INSTANCE (new_txn), + "from-sched-xaction", + xaccSchedXactionGetGUID(creation_data->instance->parent->sx), + NULL); } xaccTransCommitEdit(new_txn); @@ -1617,9 +1574,14 @@ create_cashflow_helper(Transaction *template_txn, void *user_data) gint gncn_error; /* Credit value */ - _get_sx_formula_value(creation_data->sx, template_split, &credit_num, creation_data->creation_errors, GNC_SX_CREDIT_FORMULA, GNC_SX_CREDIT_NUMERIC, NULL); + _get_sx_formula_value(creation_data->sx, template_split, + &credit_num, creation_data->creation_errors, + "sx-credit-formula", "sx-credit-numeric", + NULL); /* Debit value */ - _get_sx_formula_value(creation_data->sx, template_split, &debit_num, creation_data->creation_errors, GNC_SX_DEBIT_FORMULA, GNC_SX_DEBIT_NUMERIC, NULL); + _get_sx_formula_value(creation_data->sx, template_split, + &debit_num, creation_data->creation_errors, + "sx-debit-formula", "sx-debit-numeric", NULL); /* The resulting cash flow number: debit minus credit, * multiplied with the count factor. */ diff --git a/src/engine/SchedXaction.h b/src/engine/SchedXaction.h index d78b975ef4..c02183eaf5 100644 --- a/src/engine/SchedXaction.h +++ b/src/engine/SchedXaction.h @@ -304,12 +304,7 @@ void gnc_sx_remove_defer_instance( SchedXaction *sx, void *deferStateData ); GList *gnc_sx_get_defer_instances( SchedXaction *sx ); /* #defines for KvpFrame strings and QOF */ -#define GNC_SX_ID "sched-xaction" -#define GNC_SX_CREDIT_NUMERIC "credit-numeric" -#define GNC_SX_DEBIT_NUMERIC "debit-numeric" #define GNC_SX_SHARES "shares" -#define GNC_SX_AMOUNT "amnt" -#define GNC_SX_FROM_SCHED_XACTION "from-sched-xaction" #define GNC_SX_FREQ_SPEC "scheduled-frequency" #define GNC_SX_NAME "sched-xname" #define GNC_SX_START_DATE "sched-start-date" diff --git a/src/engine/test/test-engine-kvp-properties.c b/src/engine/test/test-engine-kvp-properties.c index a763c89666..cc8dcdc61f 100644 --- a/src/engine/test/test-engine-kvp-properties.c +++ b/src/engine/test/test-engine-kvp-properties.c @@ -263,6 +263,13 @@ test_split_kvp_properties (Fixture *fixture, gconstpointer pData) g_free (debit_numeric_r); g_free (credit_formula_r); g_free (credit_numeric_r); + qof_instance_set (QOF_INSTANCE (fixture->split), + "sx-credit-formula", NULL, + NULL); + qof_instance_get (QOF_INSTANCE (fixture->split), + "sx-credit-formula", &credit_numeric_r, + NULL); + g_assert (credit_numeric_r == NULL); g_free (sx_shares_r); g_free (online_id_r); guid_free (sx_account); diff --git a/src/gnome-utils/gnc-tree-util-split-reg.c b/src/gnome-utils/gnc-tree-util-split-reg.c index c8d7e09b7c..9cbcc2b7ab 100644 --- a/src/gnome-utils/gnc-tree-util-split-reg.c +++ b/src/gnome-utils/gnc-tree-util-split-reg.c @@ -397,30 +397,20 @@ const char * gnc_tree_util_split_reg_template_get_transfer_entry (Split *split) { static char *name = NULL; + Account *account; + GncGUID *guid; - kvp_frame *kvpf; + /* Callers either g_strdup the return or use it as a temp for comparison, + so we keep our static ref and free it on every call. */ + g_free (name); if (!split) return NULL; - - kvpf = xaccSplitGetSlots (split); - - g_free (name); - - if (kvpf) - { - Account *account; - GncGUID *guid; - - guid = kvp_value_get_guid( - kvp_frame_get_slot_path (kvpf, "sched-xaction", "account", NULL)); - - account = xaccAccountLookup (guid, gnc_get_current_book ()); - - name = account ? gnc_get_account_name_for_register (account) : NULL; - } - else - name = NULL; + qof_instance_get (QOF_INSTANCE (split), + "sx-account", &guid, + NULL); + account = xaccAccountLookup (guid, gnc_get_current_book ()); + name = account ? gnc_get_account_name_for_register (account) : NULL; return name; } @@ -429,20 +419,27 @@ gnc_tree_util_split_reg_template_get_transfer_entry (Split *split) const char * gnc_tree_util_split_reg_template_get_fdebt_entry (Split *split) { - kvp_frame *kvpf = xaccSplitGetSlots (split); + gchar *formula; - return kvp_value_get_string( - kvp_frame_get_slot_path (kvpf, "sched-xaction", "debit-formula", NULL)); + g_return_val_if_fail (split != NULL, NULL); + qof_instance_get (QOF_INSTANCE (split), + "sx-debit-formula", &formula, + NULL); + + return formula; } - const char * gnc_tree_util_split_reg_template_get_fcred_entry (Split *split) { - kvp_frame *kvpf = xaccSplitGetSlots (split); + gchar *formula; - return kvp_value_get_string( - kvp_frame_get_slot_path (kvpf, "sched-xaction", "credit-formula", NULL)); + g_return_val_if_fail (split != NULL, NULL); + qof_instance_get (QOF_INSTANCE (split), + "sx-credit-formula", &formula, + NULL); + + return formula; } diff --git a/src/gnome-utils/gnc-tree-view-split-reg.c b/src/gnome-utils/gnc-tree-view-split-reg.c index c1836c584f..2a6ecdb1d0 100644 --- a/src/gnome-utils/gnc-tree-view-split-reg.c +++ b/src/gnome-utils/gnc-tree-view-split-reg.c @@ -4803,9 +4803,8 @@ gtv_sr_edited_template_cb (GtkCellRendererText *cell, const gchar *path_string, if (viewcol == COL_TRANSFERVOID) { Account *template_acc; + Account *acct; const GncGUID *acctGUID; - kvp_frame *kvpf; - Account *acct; /* save the account GncGUID into the kvp_data. */ view->priv->stop_cell_move = FALSE; @@ -4824,9 +4823,9 @@ gtv_sr_edited_template_cb (GtkCellRendererText *cell, const gchar *path_string, } acctGUID = xaccAccountGetGUID (acct); - kvpf = xaccSplitGetSlots (split); - kvp_frame_set_slot_path (kvpf, kvp_value_new_guid (acctGUID), - GNC_SX_ID, GNC_SX_ACCOUNT, NULL); + qof_instance_set (QOF_INSTANCE (split), + "sx-account", acctGUID, + NULL); template_acc = gnc_tree_model_split_reg_get_template_account (model); @@ -4846,20 +4845,11 @@ gtv_sr_edited_template_cb (GtkCellRendererText *cell, const gchar *path_string, /* Setup the debit and credit fields */ if (viewcol == COL_DEBIT) { - kvp_frame *kvpf; char *error_loc; gnc_numeric new_value; gboolean parse_result; - kvpf = xaccSplitGetSlots (split); - - DEBUG ("kvp_frame debit before: %s\n", kvp_frame_to_string (kvpf)); - /* Setup the debit formula */ - kvp_frame_set_slot_path (kvpf, kvp_value_new_string (new_text), - GNC_SX_ID, - GNC_SX_DEBIT_FORMULA, - NULL); /* If the value can be parsed into a numeric result, store that * numeric value additionally. See above comment.*/ @@ -4868,45 +4858,22 @@ gtv_sr_edited_template_cb (GtkCellRendererText *cell, const gchar *path_string, { new_value = gnc_numeric_zero(); } - kvp_frame_set_slot_path (kvpf, kvp_value_new_numeric (new_value), - GNC_SX_ID, - GNC_SX_DEBIT_NUMERIC, - NULL); - - DEBUG ("kvp_frame debit after: %s\n", kvp_frame_to_string (kvpf)); - - /* Blank the credit formula */ - kvp_frame_set_slot_path (kvpf, kvp_value_new_string (NULL), - GNC_SX_ID, - GNC_SX_CREDIT_FORMULA, - NULL); - - new_value = gnc_numeric_zero(); - kvp_frame_set_slot_path (kvpf, kvp_value_new_numeric (new_value), - GNC_SX_ID, - GNC_SX_CREDIT_NUMERIC, - NULL); + qof_instance_set (QOF_INSTANCE (split), + "sx-debit-formula", new_text, + "sx-debit-numeric", &new_value, + "sx-credit-formula", NULL, + "sx-credit-numeric", NULL, + NULL); } /* Setup the debit and credit fields */ if (viewcol == COL_CREDIT) { - kvp_frame *kvpf; char *error_loc; gnc_numeric new_value; gboolean parse_result; - kvpf = xaccSplitGetSlots (split); - - DEBUG ("kvp_frame credit before: %s\n", kvp_frame_to_string (kvpf)); - - /* Setup the credit formula */ - kvp_frame_set_slot_path (kvpf, kvp_value_new_string (new_text), - GNC_SX_ID, - GNC_SX_CREDIT_FORMULA, - NULL); - - /* If the value can be parsed into a numeric result (without any + /* If the value can be parsed into a numeric result (without any * further variable definitions), store that numeric value * additionally in the kvp. Otherwise store a zero numeric * there.*/ @@ -4915,24 +4882,12 @@ gtv_sr_edited_template_cb (GtkCellRendererText *cell, const gchar *path_string, { new_value = gnc_numeric_zero(); } - kvp_frame_set_slot_path (kvpf, kvp_value_new_numeric (new_value), - GNC_SX_ID, - GNC_SX_CREDIT_NUMERIC, - NULL); - - DEBUG ("kvp_frame credit after: %s\n", kvp_frame_to_string (kvpf)); - - /* Blank the debit formula */ - kvp_frame_set_slot_path (kvpf, kvp_value_new_string (NULL), - GNC_SX_ID, - GNC_SX_DEBIT_FORMULA, - NULL); - - new_value = gnc_numeric_zero(); - kvp_frame_set_slot_path (kvpf, kvp_value_new_numeric (new_value), - GNC_SX_ID, - GNC_SX_DEBIT_NUMERIC, - NULL); + qof_instance_set (QOF_INSTANCE (split), + "sx-credit-formula", new_text, + "sx-credit-numeric", &new_value, + "sx-debit-formula", NULL, + "sx-debit-numeric", NULL, + NULL); } /* set the amount to an innocuous value */ xaccSplitSetValue (split, gnc_numeric_create (0, 1)); diff --git a/src/gnome/dialog-sx-editor.c b/src/gnome/dialog-sx-editor.c index b3fb1e85a6..90587762b7 100644 --- a/src/gnome/dialog-sx-editor.c +++ b/src/gnome/dialog-sx-editor.c @@ -549,9 +549,7 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed ) int numIters, i; GHashTable *vars, *txns; GList *splitList = NULL; - char *str; - kvp_frame *f; - kvp_value *v; + gchar *credit_formula, *debit_formula; Split *s; Transaction *t; gnc_numeric tmp; @@ -559,8 +557,10 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed ) gpointer unusedKey, unusedValue; unbalanceable = FALSE; /* innocent until proven guilty */ - vars = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, (GDestroyNotify)gnc_sx_variable_free); - txns = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, g_free); + vars = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, + (GDestroyNotify)gnc_sx_variable_free); + txns = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, + g_free); numIters = NUM_ITERS_NO_VARS; /** * Plan: @@ -622,14 +622,11 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed ) g_hash_table_insert( txns, (gpointer)t, (gpointer)tcds ); } - f = xaccSplitGetSlots( s ); - - /* contains the guid of the split's actual account. */ - v = kvp_frame_get_slot_path(f, - GNC_SX_ID, - GNC_SX_ACCOUNT, - NULL); - acct_guid = kvp_value_get_guid( v ); + qof_instance_get (QOF_INSTANCE (s), + "sx-account", &acct_guid, + "sx-credit-formula", &credit_formula, + "sx-debit-formula", &debit_formula, + NULL); acct = xaccAccountLookup( acct_guid, gnc_get_current_book ()); split_cmdty = xaccAccountGetCommodity(acct); if (base_cmdty == NULL) @@ -638,62 +635,48 @@ gnc_sxed_check_consistent( GncSxEditorDialog *sxed ) } multi_commodity |= !gnc_commodity_equal(split_cmdty, base_cmdty); - v = kvp_frame_get_slot_path( f, - GNC_SX_ID, - GNC_SX_CREDIT_FORMULA, - NULL ); - if ( v - && (str = kvp_value_get_string(v)) - && strlen( str ) != 0 ) - { - if ( gnc_sx_parse_vars_from_formula( str, vars, &tmp ) < 0 ) - { - GString *errStr; + if ( g_strcmp0 (credit_formula, "") != 0 && + gnc_sx_parse_vars_from_formula(credit_formula, vars, + &tmp ) < 0 ) + { + GString *errStr; - errStr = g_string_sized_new( 32 ); - g_string_printf( errStr, - _( "Couldn't parse credit formula for " - "split \"%s\"." ), - xaccSplitGetMemo( s ) ); - gnc_error_dialog( GTK_WIDGET(sxed->dialog), "%s", - errStr->str ); - g_string_free( errStr, TRUE ); + errStr = g_string_sized_new( 32 ); + g_string_printf( errStr, + _( "Couldn't parse credit formula for " + "split \"%s\"." ), + xaccSplitGetMemo( s ) ); + gnc_error_dialog( GTK_WIDGET(sxed->dialog), "%s", + errStr->str ); + g_string_free( errStr, TRUE ); - return FALSE; - } - tcds->creditSum = - gnc_numeric_add( tcds->creditSum, tmp, 100, - (GNC_DENOM_AUTO | GNC_HOW_DENOM_LCD) ); - tmp = gnc_numeric_zero(); - } - v = kvp_frame_get_slot_path( f, - GNC_SX_ID, - GNC_SX_DEBIT_FORMULA, - NULL ); - if ( v - && (str = kvp_value_get_string(v)) - && strlen(str) != 0 ) - { - if ( gnc_sx_parse_vars_from_formula( str, vars, &tmp ) < 0 ) - { - GString *errStr; + return FALSE; + } + tcds->creditSum = + gnc_numeric_add( tcds->creditSum, tmp, 100, + (GNC_DENOM_AUTO | GNC_HOW_DENOM_LCD) ); + tmp = gnc_numeric_zero(); + if ( g_strcmp0 (debit_formula, "") != 0 && + gnc_sx_parse_vars_from_formula( debit_formula, vars, + &tmp ) < 0 ) + { + GString *errStr; - errStr = g_string_sized_new( 32 ); - g_string_printf( errStr, - _( "Couldn't parse debit formula for " - "split \"%s\"." ), - xaccSplitGetMemo( s ) ); - gnc_error_dialog( GTK_WIDGET(sxed->dialog), "%s", - (gchar*)errStr->str ); - g_string_free( errStr, TRUE ); + errStr = g_string_sized_new( 32 ); + g_string_printf( errStr, + _( "Couldn't parse debit formula for " + "split \"%s\"." ), + xaccSplitGetMemo( s ) ); + gnc_error_dialog( GTK_WIDGET(sxed->dialog), "%s", + (gchar*)errStr->str ); + g_string_free( errStr, TRUE ); - return FALSE; - } - tcds->debitSum = gnc_numeric_add( tcds->debitSum, tmp, 100, - (GNC_DENOM_AUTO | GNC_HOW_DENOM_LCD) ); - tmp = gnc_numeric_zero(); - } - } + return FALSE; + } + tcds->debitSum = gnc_numeric_add( tcds->debitSum, tmp, 100, + (GNC_DENOM_AUTO | GNC_HOW_DENOM_LCD) ); + tmp = gnc_numeric_zero(); + } g_hash_table_foreach( txns, check_credit_debit_balance, diff --git a/src/gnome/dialog-sx-editor2.c b/src/gnome/dialog-sx-editor2.c index c9de4dc9f7..3f24dae717 100644 --- a/src/gnome/dialog-sx-editor2.c +++ b/src/gnome/dialog-sx-editor2.c @@ -546,9 +546,7 @@ gnc_sxed_check_consistent (GncSxEditorDialog2 *sxed) int numIters, i; GHashTable *vars, *txns; GList *splitList = NULL; - char *str; - kvp_frame *f; - kvp_value *v; + char *credit_formula, *debit_formula; Split *s; Transaction *t; gnc_numeric tmp; @@ -615,77 +613,60 @@ gnc_sxed_check_consistent (GncSxEditorDialog2 *sxed) g_hash_table_insert (txns, (gpointer)t, (gpointer)tcds); } - f = xaccSplitGetSlots (s); - - /* contains the guid of the split's actual account. */ - v = kvp_frame_get_slot_path (f, - GNC_SX_ID, - GNC_SX_ACCOUNT, - NULL); - acct_guid = kvp_value_get_guid (v); - acct = xaccAccountLookup (acct_guid, gnc_get_current_book ()); - split_cmdty = xaccAccountGetCommodity (acct); + qof_instance_get (QOF_INSTANCE (s), + "sx-account", &acct_guid, + "sx-credit-formula", &credit_formula, + "sx-debit-formula", &debit_formula, + NULL); + acct = xaccAccountLookup( acct_guid, gnc_get_current_book ()); + split_cmdty = xaccAccountGetCommodity(acct); if (base_cmdty == NULL) { base_cmdty = split_cmdty; } - multi_commodity |= !gnc_commodity_equal (split_cmdty, base_cmdty); + multi_commodity |= !gnc_commodity_equal(split_cmdty, base_cmdty); - v = kvp_frame_get_slot_path (f, - GNC_SX_ID, - GNC_SX_CREDIT_FORMULA, - NULL); - if (v - && (str = kvp_value_get_string (v)) - && strlen( str ) != 0) - { - if (gnc_sx_parse_vars_from_formula (str, vars, &tmp ) < 0) - { - GString *errStr; + if ( g_strcmp0 (credit_formula, "") != 0 && + gnc_sx_parse_vars_from_formula(credit_formula, vars, + &tmp ) < 0 ) + { + GString *errStr; - errStr = g_string_sized_new (32); - g_string_printf (errStr, - _( "Couldn't parse credit formula for " - "split \"%s\"."), - xaccSplitGetMemo (s)); - gnc_error_dialog (GTK_WIDGET (sxed->dialog), "%s", - errStr->str); - g_string_free (errStr, TRUE); + errStr = g_string_sized_new( 32 ); + g_string_printf( errStr, + _( "Couldn't parse credit formula for " + "split \"%s\"." ), + xaccSplitGetMemo( s ) ); + gnc_error_dialog( GTK_WIDGET(sxed->dialog), "%s", + errStr->str ); + g_string_free( errStr, TRUE ); - return FALSE; - } - tcds->creditSum = - gnc_numeric_add (tcds->creditSum, tmp, 100, - (GNC_DENOM_AUTO | GNC_HOW_DENOM_LCD)); - tmp = gnc_numeric_zero(); - } - v = kvp_frame_get_slot_path (f, - GNC_SX_ID, - GNC_SX_DEBIT_FORMULA, - NULL); - if (v - && (str = kvp_value_get_string (v)) - && strlen(str) != 0 ) - { - if (gnc_sx_parse_vars_from_formula (str, vars, &tmp ) < 0) - { - GString *errStr; + return FALSE; + } + tcds->creditSum = + gnc_numeric_add( tcds->creditSum, tmp, 100, + (GNC_DENOM_AUTO | GNC_HOW_DENOM_LCD) ); + tmp = gnc_numeric_zero(); + if ( g_strcmp0 (debit_formula, "") != 0 && + gnc_sx_parse_vars_from_formula( debit_formula, vars, + &tmp ) < 0 ) + { + GString *errStr; - errStr = g_string_sized_new (32); - g_string_printf (errStr, - _( "Couldn't parse debit formula for " - "split \"%s\"."), - xaccSplitGetMemo (s)); - gnc_error_dialog (GTK_WIDGET (sxed->dialog), "%s", - (gchar*)errStr->str); - g_string_free (errStr, TRUE); + errStr = g_string_sized_new( 32 ); + g_string_printf( errStr, + _( "Couldn't parse debit formula for " + "split \"%s\"." ), + xaccSplitGetMemo( s ) ); + gnc_error_dialog( GTK_WIDGET(sxed->dialog), "%s", + (gchar*)errStr->str ); + g_string_free( errStr, TRUE ); - return FALSE; - } - tcds->debitSum = gnc_numeric_add (tcds->debitSum, tmp, 100, - (GNC_DENOM_AUTO | GNC_HOW_DENOM_LCD)); - tmp = gnc_numeric_zero(); - } + return FALSE; + } + tcds->debitSum = gnc_numeric_add( tcds->debitSum, tmp, 100, + (GNC_DENOM_AUTO | GNC_HOW_DENOM_LCD) ); + tmp = gnc_numeric_zero(); } g_hash_table_foreach (txns, diff --git a/src/gnome/gnc-plugin-page-register2.c b/src/gnome/gnc-plugin-page-register2.c index bfbbdc71e8..a6c7c9175a 100644 --- a/src/gnome/gnc-plugin-page-register2.c +++ b/src/gnome/gnc-plugin-page-register2.c @@ -3629,39 +3629,30 @@ gnc_plugin_page_register2_cmd_schedule (GtkAction *action, /* If the transaction has a sched-xact KVP frame, then go to the editor * for the existing SX; otherwise, do the sx-from-trans dialog. */ { - kvp_frame *txn_frame; - kvp_value *kvp_val; - /* set a kvp-frame element in the transaction indicating and - * pointing-to the SX this was created from. */ - txn_frame = xaccTransGetSlots (trans); - if ( txn_frame != NULL ) - { - kvp_val = kvp_frame_get_slot (txn_frame, "from-sched-xaction"); - if (kvp_val) - { - GncGUID *fromSXId = kvp_value_get_guid (kvp_val); - SchedXaction *theSX = NULL; - GList *sxElts; + GncGUID *fromSXId; + SchedXaction *theSX = NULL; + GList *sxElts; + qof_instance_get (QOF_INSTANCE (trans), + "from-sched-xaction", &fromSXId, + NULL); - /* Get the correct SX */ - for ( sxElts = gnc_book_get_schedxactions (gnc_get_current_book())->sx_list; - (!theSX) && sxElts; - sxElts = sxElts->next ) - { - SchedXaction *sx = (SchedXaction*)sxElts->data; - theSX = - ((guid_equal (xaccSchedXactionGetGUID (sx), fromSXId)) - ? sx : NULL); - } + /* Get the correct SX */ + for ( sxElts = gnc_book_get_schedxactions (gnc_get_current_book())->sx_list; + (!theSX) && sxElts; + sxElts = sxElts->next ) + { + SchedXaction *sx = (SchedXaction*)sxElts->data; + theSX = + ((guid_equal (xaccSchedXactionGetGUID (sx), fromSXId)) + ? sx : NULL); + } - if (theSX) - { - gnc_ui_scheduled_xaction_editor_dialog_create2 (theSX, FALSE); - LEAVE(" "); - return; - } - } - } + if (theSX) + { + gnc_ui_scheduled_xaction_editor_dialog_create2 (theSX, FALSE); + LEAVE(" "); + return; + } } gnc_sx_create_from_trans (trans); LEAVE(" "); diff --git a/src/gnome/gnc-split-reg.c b/src/gnome/gnc-split-reg.c index 0c66364399..b1aef33a44 100644 --- a/src/gnome/gnc-split-reg.c +++ b/src/gnome/gnc-split-reg.c @@ -1204,38 +1204,29 @@ gsr_default_schedule_handler( GNCSplitReg *gsr, gpointer data ) /* If the transaction has a sched-xact KVP frame, then go to the editor * for the existing SX; otherwise, do the sx-from-trans dialog. */ { - kvp_frame *txn_frame; - kvp_value *kvp_val; - /* set a kvp-frame element in the transaction indicating and - * pointing-to the SX this was created from. */ - txn_frame = xaccTransGetSlots( pending_trans ); - if ( txn_frame != NULL ) - { - kvp_val = kvp_frame_get_slot( txn_frame, "from-sched-xaction" ); - if ( kvp_val ) - { - GncGUID *fromSXId = kvp_value_get_guid( kvp_val ); - SchedXaction *theSX = NULL; - GList *sxElts; + GncGUID *fromSXId; + SchedXaction *theSX = NULL; + GList *sxElts; + qof_instance_get (QOF_INSTANCE (pending_trans), + "from-sched-xaction", &fromSXId, + NULL); - /* Get the correct SX */ - for ( sxElts = gnc_book_get_schedxactions(gnc_get_current_book())->sx_list; - (!theSX) && sxElts; - sxElts = sxElts->next ) - { - SchedXaction *sx = (SchedXaction*)sxElts->data; - theSX = - ( ( guid_equal( xaccSchedXactionGetGUID( sx ), fromSXId ) ) - ? sx : NULL ); - } + /* Get the correct SX */ + for ( sxElts = gnc_book_get_schedxactions (gnc_get_current_book())->sx_list; + (!theSX) && sxElts; + sxElts = sxElts->next ) + { + SchedXaction *sx = (SchedXaction*)sxElts->data; + theSX = + ((guid_equal (xaccSchedXactionGetGUID (sx), fromSXId)) + ? sx : NULL); + } - if ( theSX ) - { - gnc_ui_scheduled_xaction_editor_dialog_create(theSX, FALSE); - return; - } - } - } + if ( theSX ) + { + gnc_ui_scheduled_xaction_editor_dialog_create(theSX, FALSE); + return; + } } gnc_sx_create_from_trans(pending_trans); diff --git a/src/register/ledger-core/split-register-model-save.c b/src/register/ledger-core/split-register-model-save.c index 281477f2c2..6d9ea637f6 100644 --- a/src/register/ledger-core/split-register-model-save.c +++ b/src/register/ledger-core/split-register-model-save.c @@ -674,10 +674,9 @@ gnc_template_register_save_xfrm_cell (BasicCell * cell, } acctGUID = xaccAccountGetGUID (acct); - kvpf = xaccSplitGetSlots (sd->split); - kvp_frame_set_slot_path (kvpf, kvp_value_new_guid(acctGUID), - GNC_SX_ID, GNC_SX_ACCOUNT, NULL); - + qof_instance_set (QOF_INSTANCE (sd->split), + "sx-account", acctGUID, + NULL); template_acc = xaccAccountLookup (&info->template_account, gnc_get_current_book ()); @@ -699,10 +698,9 @@ gnc_template_register_save_debcred_cell (BasicCell * cell, { SRSaveData *sd = save_data; SplitRegister *reg = user_data; - kvp_frame *kvpf; - const char *value; + const char *credit_formula, *debit_formula; char *error_loc; - gnc_numeric new_amount; + gnc_numeric credit_amount, debit_amount; gboolean parse_result; g_return_if_fail (gnc_basic_cell_has_name (cell, FDEBT_CELL) || @@ -711,54 +709,37 @@ gnc_template_register_save_debcred_cell (BasicCell * cell, if (sd->handled_dc) return; - kvpf = xaccSplitGetSlots (sd->split); - - DEBUG ("kvp_frame before: %s\n", kvp_frame_to_string (kvpf)); - /* amountStr = gnc_numeric_to_string (new_amount); */ - value = gnc_table_layout_get_cell_value (reg->table->layout, FCRED_CELL); - kvp_frame_set_slot_path (kvpf, kvp_value_new_string (value), - GNC_SX_ID, - GNC_SX_CREDIT_FORMULA, - NULL); - + credit_formula = gnc_table_layout_get_cell_value (reg->table->layout, + FCRED_CELL); /* If the value can be parsed into a numeric result (without any * further variable definitions), store that numeric value * additionally in the kvp. Otherwise store a zero numeric * there.*/ - parse_result = gnc_exp_parser_parse_separate_vars(value, &new_amount, &error_loc, NULL); + parse_result = gnc_exp_parser_parse_separate_vars(credit_formula, + &credit_amount, + &error_loc, NULL); if (!parse_result) - { - new_amount = gnc_numeric_zero(); - } - kvp_frame_set_slot_path (kvpf, kvp_value_new_numeric (new_amount), - GNC_SX_ID, - GNC_SX_CREDIT_NUMERIC, - NULL); + credit_amount = gnc_numeric_zero(); - value = gnc_table_layout_get_cell_value (reg->table->layout, FDEBT_CELL); - - kvp_frame_set_slot_path (kvpf, - kvp_value_new_string (value), - GNC_SX_ID, - GNC_SX_DEBIT_FORMULA, - NULL); + debit_formula = gnc_table_layout_get_cell_value (reg->table->layout, + FDEBT_CELL); /* If the value can be parsed into a numeric result, store that * numeric value additionally. See above comment.*/ - parse_result = gnc_exp_parser_parse_separate_vars(value, &new_amount, &error_loc, NULL); + parse_result = gnc_exp_parser_parse_separate_vars(debit_formula, + &debit_amount, + &error_loc, NULL); if (!parse_result) - { - new_amount = gnc_numeric_zero(); - } - kvp_frame_set_slot_path (kvpf, kvp_value_new_numeric (new_amount), - GNC_SX_ID, - GNC_SX_DEBIT_NUMERIC, - NULL); - - DEBUG ("kvp_frame after: %s\n", kvp_frame_to_string (kvpf)); + debit_amount = gnc_numeric_zero(); + qof_instance_set (QOF_INSTANCE (sd->split), + "sx-credit-formula", credit_formula, + "sx-credit-numeric", &credit_amount, + "sx-debit-formula", debit_formula, + "sx-debit-numeric", &debit_amount, + NULL); /* set the amount to an innocuous value */ xaccSplitSetValue (sd->split, gnc_numeric_create (0, 1)); @@ -771,24 +752,13 @@ gnc_template_register_save_shares_cell (BasicCell * cell, gpointer user_data) { SRSaveData *sd = save_data; - kvp_frame *kvpf; char *sharesStr = "(x + y)/42"; g_return_if_fail (gnc_basic_cell_has_name (cell, SHRS_CELL)); - - kvpf = xaccSplitGetSlots (sd->split); - /* FIXME: shares cells are numeric by definition. */ - DEBUG ("kvp_frame before: %s\n", kvp_frame_to_string (kvpf)); - - /* sharesStr = gnc_numeric_to_string( sharesStr ); */ - kvp_frame_set_slot_path (kvpf, - kvp_value_new_string (sharesStr), - GNC_SX_ID, - GNC_SX_SHARES, - NULL); - - DEBUG ("kvp_frame after: %s\n", kvp_frame_to_string (kvpf)); + qof_instance_set (QOF_INSTANCE (sd->split), + "sx-shares", sharesStr, + NULL); /* set the shares to an innocuous value */ xaccSplitSetSharePriceAndAmount (sd->split, diff --git a/src/register/ledger-core/split-register-model.c b/src/register/ledger-core/split-register-model.c index 859b20ebff..5294b404ce 100644 --- a/src/register/ledger-core/split-register-model.c +++ b/src/register/ledger-core/split-register-model.c @@ -2095,31 +2095,23 @@ gnc_template_register_get_xfrm_entry (VirtualLocation virt_loc, static char *name = NULL; SplitRegister *reg = user_data; - kvp_frame *kvpf; Split *split; + Account *account; + GncGUID *guid; split = gnc_split_register_get_split (reg, virt_loc.vcell_loc); if (!split) return NULL; - - kvpf = xaccSplitGetSlots (split); - + /* Caller either uses the return as a temporary in a boolean + * expression or g_strdups it, so we keep it static and free the + * old one on every call to avoid leaks. Ugly, but it works. + */ g_free (name); - - if (kvpf) - { - Account *account; - GncGUID *guid; - - guid = kvp_value_get_guid( - kvp_frame_get_slot_path(kvpf, "sched-xaction", "account", NULL)); - - account = xaccAccountLookup (guid, gnc_get_current_book ()); - - name = account ? gnc_get_account_name_for_register (account) : NULL; - } - else - name = NULL; + qof_instance_get (QOF_INSTANCE (split), + "sx-account", &guid, + NULL); + account = xaccAccountLookup (guid, gnc_get_current_book ()); + name = account ? gnc_get_account_name_for_register (account) : NULL; return name; } @@ -2132,10 +2124,13 @@ gnc_template_register_get_fdebt_entry (VirtualLocation virt_loc, { SplitRegister *reg = user_data; Split *split = gnc_split_register_get_split(reg, virt_loc.vcell_loc); - kvp_frame *kvpf = xaccSplitGetSlots(split); + char *formula; - return kvp_value_get_string( - kvp_frame_get_slot_path (kvpf, "sched-xaction", "debit-formula", NULL)); + qof_instance_get (QOF_INSTANCE (split), + "sx-debit-formula", &formula, + NULL); + + return formula; } static char * @@ -2159,14 +2154,15 @@ gnc_template_register_get_fcred_entry (VirtualLocation virt_loc, gpointer user_data) { SplitRegister *reg = user_data; - kvp_frame *kvpf; - Split *split; + Split *split = gnc_split_register_get_split(reg, virt_loc.vcell_loc); + char *formula; - split = gnc_split_register_get_split (reg, virt_loc.vcell_loc); - kvpf = xaccSplitGetSlots (split); + qof_instance_get (QOF_INSTANCE (split), + "sx-credit-formula", &formula, + NULL); + + return formula; - return kvp_value_get_string( - kvp_frame_get_slot_path (kvpf, "sched-xaction", "credit-formula", NULL)); } static char * @@ -2198,8 +2194,13 @@ gnc_template_register_get_debcred_entry (VirtualLocation virt_loc, gboolean *conditionally_changed, gpointer user_data) { + PERR("The function called always returned either NULL or an empty string " + "while issuing dire warnings about how incorrect it is. That code " + "has been removed and the function if called raises this error and " + "returns NULL"); + return NULL; +#if 0 SplitRegister *reg = user_data; - kvp_frame *kvpf; Split *split; split = gnc_split_register_get_split (reg, virt_loc.vcell_loc); @@ -2245,6 +2246,7 @@ gnc_template_register_get_debcred_entry (VirtualLocation virt_loc, } return NULL; +#endif } static void