static QofSession* create_session(void) { QofSession* session = qof_session_new(); QofBook* book = qof_session_get_book( session ); Account* root = gnc_book_get_root_account( book ); Account* acct1; Account* acct2; KvpFrame* frame; Transaction* tx; Split* spl1; Split* spl2; Timespec ts; struct timeval tv; gnc_commodity_table* table; gnc_commodity* currency; table = gnc_commodity_table_get_table( book ); currency = gnc_commodity_table_lookup( table, GNC_COMMODITY_NS_CURRENCY, "CAD" ); acct1 = xaccMallocAccount( book ); xaccAccountSetType( acct1, ACCT_TYPE_BANK ); xaccAccountSetName( acct1, "Bank 1" ); xaccAccountSetCommodity( acct1, currency ); frame = qof_instance_get_slots( QOF_INSTANCE(acct1) ); kvp_frame_set_gint64( frame, "int64-val", 100 ); kvp_frame_set_double( frame, "double-val", 3.14159 ); kvp_frame_set_numeric( frame, "numeric-val", gnc_numeric_zero() ); time( &(tv.tv_sec) ); tv.tv_usec = 0; ts.tv_sec = tv.tv_sec; ts.tv_nsec = 1000 * tv.tv_usec; kvp_frame_set_timespec( frame, "timespec-val", ts ); kvp_frame_set_string( frame, "string-val", "abcdefghijklmnop" ); kvp_frame_set_guid( frame, "guid-val", qof_instance_get_guid( QOF_INSTANCE(acct1) ) ); gnc_account_append_child( root, acct1 ); acct2 = xaccMallocAccount( book ); xaccAccountSetType( acct2, ACCT_TYPE_BANK ); xaccAccountSetName( acct2, "Bank 1" ); tx = xaccMallocTransaction( book ); xaccTransBeginEdit( tx ); xaccTransSetCurrency( tx, currency ); spl1 = xaccMallocSplit( book ); xaccTransAppendSplit( tx, spl1 ); spl2 = xaccMallocSplit( book ); xaccTransAppendSplit( tx, spl2 ); xaccTransCommitEdit( tx ); return session; }
/* Set the option with the default KvpValue, manipulate the option in the supplied callback routine then set the value of the option into the KvpValue in the configuration frame. */ static void config_foreach_cb (const char *key, KvpValue *value, gpointer data) { QofBackendOption option; gint64 int64; double db; gnc_numeric num; Timespec ts; gchar *parent; struct config_iterate *helper; g_return_if_fail(key || value || data); helper = (struct config_iterate*)data; if (!helper->recursive) { PERR (" no parent frame"); return; } // skip the presets. if (0 == safe_strcmp(key, QOF_CONFIG_DESC)) { return; } if (0 == safe_strcmp(key, QOF_CONFIG_TIP)) { return; } ENTER (" key=%s", key); option.option_name = key; option.type = kvp_value_get_type(value); if (!option.type) { return; } switch (option.type) { /* set the KvpFrame value into the option */ case KVP_TYPE_GINT64 : { int64 = kvp_value_get_gint64(value); option.value = (gpointer) & int64; break; } case KVP_TYPE_DOUBLE : { db = kvp_value_get_double(value); option.value = (gpointer) & db; break; } case KVP_TYPE_NUMERIC : { num = kvp_value_get_numeric(value); option.value = (gpointer) & num; break; } case KVP_TYPE_STRING : { option.value = (gpointer)kvp_value_get_string(value); break; } case KVP_TYPE_TIMESPEC : { ts = kvp_value_get_timespec(value); option.value = (gpointer) & ts; break; } case KVP_TYPE_GUID : { break; /* unsupported */ } case KVP_TYPE_BINARY : { break; /* unsupported */ } case KVP_TYPE_GLIST : { break; /* unsupported */ } case KVP_TYPE_FRAME : { break; /* unsupported */ } case KVP_TYPE_GDATE : { break; /* unsupported */ } } parent = g_strdup_printf("/%s/%s", QOF_CONFIG_DESC, key); option.description = kvp_frame_get_string(helper->recursive, parent); g_free(parent); parent = g_strdup_printf("/%s/%s", QOF_CONFIG_TIP, key); option.tooltip = kvp_frame_get_string(helper->recursive, parent); g_free(parent); helper->count++; /* manipulate the option */ helper->fcn (&option, helper->data); switch (option.type) { /* set the option value into the KvpFrame */ case KVP_TYPE_GINT64 : { kvp_frame_set_gint64(helper->recursive, key, (*(gint64*)option.value)); break; } case KVP_TYPE_DOUBLE : { kvp_frame_set_double(helper->recursive, key, (*(double*)option.value)); break; } case KVP_TYPE_NUMERIC : { kvp_frame_set_numeric(helper->recursive, key, (*(gnc_numeric*)option.value)); break; } case KVP_TYPE_STRING : { kvp_frame_set_string(helper->recursive, key, (gchar*)option.value); break; } case KVP_TYPE_TIMESPEC : { kvp_frame_set_timespec(helper->recursive, key, (*(Timespec*)option.value)); break; } case KVP_TYPE_GUID : { break; /* unsupported */ } case KVP_TYPE_BINARY : { break; /* unsupported */ } case KVP_TYPE_GLIST : { break; /* unsupported */ } case KVP_TYPE_FRAME : { break; /* unsupported */ } case KVP_TYPE_GDATE : { break; /* unsupported */ } } LEAVE (" "); }