static void
gnc_template_register_save_xfrm_cell (BasicCell * cell,
                                      gpointer save_data,
                                      gpointer user_data)
{
    SRSaveData *sd = save_data;
    SplitRegister *reg = user_data;
    SRInfo *info = gnc_split_register_get_info (reg);
    Account *template_acc;
    const GncGUID *acctGUID;
    kvp_frame *kvpf;
    Account *acct;

    g_return_if_fail (gnc_basic_cell_has_name (cell, XFRM_CELL));

    /* save the account GncGUID into the kvp_data. */
    acct = gnc_split_register_get_account (reg, XFRM_CELL);
    if (!acct)
    {
        PERR ("unknown account");
        return;
    }

    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);

    template_acc = xaccAccountLookup (&info->template_account,
                                      gnc_get_current_book ());

    /* set the actual account to the fake account for these templates */
    xaccAccountInsertSplit (template_acc, sd->split);
    qof_instance_set_dirty (QOF_INSTANCE (sd->split));
}
Exemplo n.º 2
0
void
kvp_frame_set_guid(KvpFrame * frame, const char * path, const GncGUID *guid)
{
    KvpValue *value;
    value = kvp_value_new_guid (guid);
    frame = kvp_frame_set_value_nc (frame, path, value);
    if (!frame) kvp_value_delete (value);
}
Exemplo n.º 3
0
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;
}
Exemplo n.º 4
0
void gnc_ofx_kvp_set_assoc_account(Account* investment_account,
                                   const Account *income_account)
{
    kvp_frame * acc_frame;
    kvp_value * kvp_val;
    const GncGUID * income_acc_guid;

    g_assert(investment_account);
    g_assert(income_account);

    acc_frame = xaccAccountGetSlots(investment_account);
    g_assert(acc_frame); // Must not be NULL, but the QofInstance doc is unclear about this
    income_acc_guid = xaccAccountGetGUID(income_account);
    kvp_val = kvp_value_new_guid(income_acc_guid);
    xaccAccountBeginEdit(investment_account);
    kvp_frame_set_slot_nc(acc_frame, KEY_ASSOC_INCOME_ACCOUNT,
                          kvp_val);
    qof_instance_set_dirty(QOF_INSTANCE (investment_account));
    xaccAccountCommitEdit(investment_account);
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
static void
save_slot( const gchar* key, KvpValue* value, gpointer data )
{
    slot_info_t* pSlot_info = (slot_info_t*)data;
    gsize curlen;

    g_return_if_fail( key != NULL );
    g_return_if_fail( value != NULL );
    g_return_if_fail( data != NULL );

    // Ignore if we've already run into a failure
    if ( !pSlot_info->is_ok )
    {
        return;
    }

    curlen = pSlot_info->path->len;
    pSlot_info->pKvpValue = value;
    if ( curlen != 0 )
    {
        (void)g_string_append( pSlot_info->path, "/" );
    }
    (void)g_string_append( pSlot_info->path, key );
    pSlot_info->value_type = kvp_value_get_type( value );

    switch ( pSlot_info->value_type )
    {
    case KVP_TYPE_FRAME:
    {
        KvpFrame* pKvpFrame = kvp_value_get_frame( value );
        GncGUID guid = guid_new_return();
        slot_info_t *pNewInfo = slot_info_copy( pSlot_info, &guid );
        KvpValue *oldValue = pSlot_info->pKvpValue;
        pSlot_info->pKvpValue = kvp_value_new_guid( &guid );
        pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be,
                            OP_DB_INSERT, TABLE_NAME,
                            TABLE_NAME, pSlot_info,
                            col_table );
        g_return_if_fail( pSlot_info->is_ok );
        kvp_frame_for_each_slot( pKvpFrame, save_slot, pNewInfo );
        kvp_value_delete( pSlot_info->pKvpValue );
        pSlot_info->pKvpValue = oldValue;
        g_string_free( pNewInfo->path, TRUE );
        g_slice_free( slot_info_t, pNewInfo );
    }
    break;
    case KVP_TYPE_GLIST:
    {
        GList *cursor;
        GncGUID guid = guid_new_return();
        slot_info_t *pNewInfo = slot_info_copy( pSlot_info, &guid );
        KvpValue *oldValue = pSlot_info->pKvpValue;
        pSlot_info->pKvpValue = kvp_value_new_guid( &guid );
        pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be,
                            OP_DB_INSERT, TABLE_NAME,
                            TABLE_NAME, pSlot_info,
                            col_table );
        g_return_if_fail( pSlot_info->is_ok );
        for (cursor = kvp_value_get_glist(value); cursor; cursor = cursor->next)
        {
            kvp_value *val = (kvp_value*)cursor->data;
            save_slot("", val, pNewInfo);
        }
        kvp_value_delete( pSlot_info->pKvpValue );
        pSlot_info->pKvpValue = oldValue;
        g_string_free( pNewInfo->path, TRUE );
        g_slice_free( slot_info_t, pNewInfo );
    }
    break;
    default:
    {
        pSlot_info->is_ok = gnc_sql_do_db_operation( pSlot_info->be,
                            OP_DB_INSERT, TABLE_NAME,
                            TABLE_NAME, pSlot_info,
                            col_table );
    }
    break;
    }

    (void)g_string_truncate( pSlot_info->path, curlen );
}
Exemplo n.º 7
0
static void
set_guid_val( gpointer pObject, /*@ null @*/ gpointer pValue )
{
    slot_info_t* pInfo = (slot_info_t*)pObject;

    g_return_if_fail( pObject != NULL );
    if ( pValue == NULL ) return;

    switch ( pInfo->value_type)
    {
    case KVP_TYPE_GUID:
    {
        KvpValue *value = kvp_value_new_guid( (GncGUID*)pValue );
        set_slot_from_value( pInfo, value );
        break;
    }
    case KVP_TYPE_GLIST:
    {
        slot_info_t *newInfo = slot_info_copy( pInfo, (GncGUID*)pValue );
        kvp_value *pValue = NULL;
        gchar *key = get_key_from_path( pInfo->path );

        newInfo->context = LIST;

        slots_load_info( newInfo );
        pValue = kvp_value_new_glist_nc( newInfo->pList );
        kvp_frame_set_slot_nc(pInfo->pKvpFrame, key, pValue);
        g_string_free( newInfo->path, TRUE );
        g_slice_free( slot_info_t, newInfo );
        g_free( key );
        break;
    }
    case KVP_TYPE_FRAME:
    {
        slot_info_t *newInfo = slot_info_copy( pInfo, (GncGUID*)pValue ) ;
        KvpFrame *newFrame = kvp_frame_new();
        newInfo->pKvpFrame = newFrame;

        switch ( pInfo->context )
        {
        case LIST:
        {
            KvpValue *value = kvp_value_new_frame_nc( newFrame );
            gchar *key = get_key_from_path( pInfo->path );
            newInfo->path = g_string_assign( newInfo->path, key );
            pInfo->pList = g_list_append( pInfo->pList, value );
            g_free( key );
            break;
        }
        case FRAME:
        default:
        {
            gchar *key = get_key_from_path( pInfo->path );
            kvp_frame_set_frame_nc( pInfo->pKvpFrame, key, newFrame );
            g_free( key );
            break;
        }
        }

        newInfo->context = FRAME;
        slots_load_info ( newInfo );
        g_string_free( newInfo->path, TRUE );
        g_slice_free( slot_info_t, newInfo );
        break;
    }
    default:
        break;
    }
}