static void gnc_template_register_save_shares_cell (BasicCell * cell, gpointer save_data, 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)); /* set the shares to an innocuous value */ /* Note that this marks the split dirty */ xaccSplitSetSharePriceAndAmount (sd->split, gnc_numeric_create (0, 1), gnc_numeric_create (0, 1)); }
void kvp_frame_set_string(KvpFrame * frame, const char * path, const char* str) { KvpValue *value; value = kvp_value_new_string (str); frame = kvp_frame_set_value_nc (frame, path, value); if (!frame) kvp_value_delete (value); }
static void set_string_val( gpointer pObject, /*@ null @*/ gpointer pValue ) { slot_info_t* pInfo = (slot_info_t*)pObject; KvpValue *value = NULL; g_return_if_fail( pObject != NULL ); if ( pInfo->value_type != KVP_TYPE_STRING || pValue == NULL ) return; value = kvp_value_new_string( (gchar*)pValue ); set_slot_from_value( pInfo, value ); }
KvpValue * kvp_value_copy(const KvpValue * value) { if (!value) return NULL; switch (value->type) { case KVP_TYPE_GINT64: return kvp_value_new_gint64(value->value.int64); break; case KVP_TYPE_DOUBLE: return kvp_value_new_double(value->value.dbl); break; case KVP_TYPE_NUMERIC: return kvp_value_new_gnc_numeric(value->value.numeric); break; case KVP_TYPE_STRING: return kvp_value_new_string(value->value.str); break; case KVP_TYPE_GUID: return kvp_value_new_guid(value->value.guid); break; case KVP_TYPE_GDATE: return kvp_value_new_gdate(value->value.gdate); break; case KVP_TYPE_TIMESPEC: return kvp_value_new_timespec(value->value.timespec); break; case KVP_TYPE_BINARY: return kvp_value_new_binary(value->value.binary.data, value->value.binary.datasize); break; case KVP_TYPE_GLIST: return kvp_value_new_glist(value->value.list); break; case KVP_TYPE_FRAME: return kvp_value_new_frame(value->value.frame); break; default: break; } return NULL; }
KvpValue* kvp_value_from_gvalue (const GValue *gval) { KvpValue *val = NULL; GType type = G_VALUE_TYPE (gval); g_return_val_if_fail (G_VALUE_TYPE (gval), NULL); if (type == G_TYPE_INT64) val = kvp_value_new_gint64 (g_value_get_int64 (gval)); else if (type == G_TYPE_DOUBLE) val = kvp_value_new_double (g_value_get_double (gval)); else if (type == GNC_TYPE_NUMERIC) val = kvp_value_new_numeric (*(gnc_numeric*)g_value_get_boxed (gval)); else if (type == G_TYPE_STRING) val = kvp_value_new_string (g_value_get_string (gval)); else if (type == GNC_TYPE_GUID) val = kvp_value_new_guid ((GncGUID*)g_value_get_boxed (gval)); else if (type == GNC_TYPE_TIMESPEC) val = kvp_value_new_timespec (*(Timespec*)g_value_get_boxed (gval)); else if (type == G_TYPE_DATE) val = kvp_value_new_gdate (*(GDate*)g_value_get_boxed (gval)); else if (type == GNC_TYPE_VALUE_LIST) { GList *gvalue_list = (GList*)g_value_get_boxed (gval); GList *kvp_list = NULL; g_list_foreach (gvalue_list, (GFunc)kvp_value_list_from_gvalue, &kvp_list); kvp_list = g_list_reverse (kvp_list); val = kvp_value_new_glist_nc (kvp_list); // g_list_free_full (gvalue_list, (GDestroyNotify)g_value_unset); // gvalue_list = NULL; } else PWARN ("Error! Don't know how to make a KvpValue from a %s", G_VALUE_TYPE_NAME (gval)); return val; }
static void gnc_template_register_save_debcred_cell (BasicCell * cell, gpointer save_data, gpointer user_data) { SRSaveData *sd = save_data; SplitRegister *reg = user_data; kvp_frame *kvpf; const char *value; char *error_loc; gnc_numeric new_amount; gboolean parse_result; g_return_if_fail (gnc_basic_cell_has_name (cell, FDEBT_CELL) || gnc_basic_cell_has_name (cell, FCRED_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); /* 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); 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); 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); /* 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); 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)); /* set the amount to an innocuous value */ /* Note that this marks the split dirty */ xaccSplitSetValue (sd->split, gnc_numeric_create (0, 1)); sd->handled_dc = TRUE; }
void qof_backend_prepare_option(QofBackend *be, const QofBackendOption *option) { KvpValue *value; gchar *temp; gint count; g_return_if_fail(be || option); count = be->config_count; count++; value = NULL; switch (option->type) { case KVP_TYPE_GINT64 : { value = kvp_value_new_gint64(*(gint64*)option->value); break; } case KVP_TYPE_DOUBLE : { value = kvp_value_new_double(*(double*)option->value); break; } case KVP_TYPE_NUMERIC : { value = kvp_value_new_numeric(*(gnc_numeric*)option->value); break; } case KVP_TYPE_STRING : { value = kvp_value_new_string((const char*)option->value); break; } case KVP_TYPE_GUID : { break; /* unsupported */ } case KVP_TYPE_TIMESPEC : { value = kvp_value_new_timespec(*(Timespec*)option->value); break; } case KVP_TYPE_BINARY : { break; /* unsupported */ } case KVP_TYPE_GLIST : { break; /* unsupported */ } case KVP_TYPE_FRAME : { break; /* unsupported */ } case KVP_TYPE_GDATE : { break; /* unsupported */ } } if (value) { temp = g_strdup_printf("/%s", option->option_name); kvp_frame_set_value(be->backend_configuration, temp, value); g_free(temp); temp = g_strdup_printf("/%s/%s", QOF_CONFIG_DESC, option->option_name); kvp_frame_set_string(be->backend_configuration, temp, option->description); g_free(temp); temp = g_strdup_printf("/%s/%s", QOF_CONFIG_TIP, option->option_name); kvp_frame_set_string(be->backend_configuration, temp, option->tooltip); g_free(temp); /* only increment the counter if successful */ be->config_count = count; } }