mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Refactor KVP-related functions of OFX into separate file.
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@20411 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
9c8e3d0f3f
commit
4fda8dcedb
@ -4,11 +4,13 @@ pkglib_LTLIBRARIES=libgncmod-ofx.la
|
||||
|
||||
libgncmod_ofx_la_SOURCES = \
|
||||
gnc-ofx-import.c \
|
||||
gnc-ofx-kvp.c \
|
||||
gncmod-ofx-import.c \
|
||||
gnc-plugin-ofx.c
|
||||
|
||||
noinst_HEADERS = \
|
||||
gnc-ofx-import.h \
|
||||
gnc-ofx-kvp.h \
|
||||
gnc-plugin-ofx.h
|
||||
|
||||
libgncmod_ofx_la_LDFLAGS = -avoid-version
|
||||
|
@ -49,6 +49,8 @@
|
||||
#include "gnc-glib-utils.h"
|
||||
#include "core-utils/gnc-gconf-utils.h"
|
||||
|
||||
#include "gnc-ofx-kvp.h"
|
||||
|
||||
#define GCONF_SECTION "dialogs/import/ofx"
|
||||
|
||||
static QofLogModule log_module = GNC_MOD_IMPORT;
|
||||
@ -276,9 +278,6 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u
|
||||
Account *account;
|
||||
Account *investment_account = NULL;
|
||||
Account *income_account = NULL;
|
||||
kvp_frame * acc_frame;
|
||||
kvp_value * kvp_val;
|
||||
const GncGUID * income_acc_guid;
|
||||
gchar *investment_account_text;
|
||||
gnc_commodity *currency = NULL;
|
||||
gnc_commodity *investment_commodity = NULL;
|
||||
@ -540,13 +539,8 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u
|
||||
{
|
||||
DEBUG("Now let's find an account for the destination split");
|
||||
|
||||
acc_frame = xaccAccountGetSlots(investment_account);
|
||||
kvp_val = kvp_frame_get_slot(acc_frame,
|
||||
"ofx/associated-income-account");
|
||||
if (kvp_val != NULL)
|
||||
{
|
||||
income_account = xaccAccountLookup(kvp_value_get_guid(kvp_val), book);
|
||||
}
|
||||
income_account = gnc_ofx_kvp_get_assoc_account(investment_account);
|
||||
|
||||
if (income_account == NULL)
|
||||
{
|
||||
DEBUG("Couldn't find an associated income account");
|
||||
@ -564,15 +558,8 @@ int ofx_proc_transaction_cb(struct OfxTransactionData data, void * transaction_u
|
||||
ACCT_TYPE_INCOME,
|
||||
NULL,
|
||||
NULL);
|
||||
income_acc_guid = xaccAccountGetGUID(income_account);
|
||||
kvp_val = kvp_value_new_guid(income_acc_guid);
|
||||
if (acc_frame == NULL)
|
||||
{
|
||||
DEBUG("The kvp_frame was NULL, allocating new one");
|
||||
acc_frame = kvp_frame_new();
|
||||
}
|
||||
kvp_frame_set_slot_nc(acc_frame, "ofx/associated-income-account",
|
||||
kvp_val);
|
||||
gnc_ofx_kvp_set_assoc_account(investment_account,
|
||||
income_account);
|
||||
DEBUG("KVP written");
|
||||
|
||||
}
|
||||
|
85
src/import-export/ofx/gnc-ofx-kvp.c
Normal file
85
src/import-export/ofx/gnc-ofx-kvp.c
Normal file
@ -0,0 +1,85 @@
|
||||
/*******************************************************************\
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/*
|
||||
* gnc-ofx-kvp.c
|
||||
*
|
||||
* Created on: 13.03.2011
|
||||
* Author: cs
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include "gnc-ofx-kvp.h"
|
||||
|
||||
static const char *KEY_ASSOC_INCOME_ACCOUNT = "ofx/associated-income-account";
|
||||
static void force_account_dirty(Account *acct);
|
||||
|
||||
|
||||
Account *gnc_ofx_kvp_get_assoc_account(const Account* investment_account)
|
||||
{
|
||||
kvp_frame * acc_frame;
|
||||
kvp_value * kvp_val;
|
||||
Account *result = NULL;
|
||||
|
||||
g_assert(investment_account);
|
||||
|
||||
acc_frame = xaccAccountGetSlots(investment_account);
|
||||
kvp_val = kvp_frame_get_slot(acc_frame, KEY_ASSOC_INCOME_ACCOUNT);
|
||||
if (kvp_val != NULL)
|
||||
{
|
||||
result = xaccAccountLookup(kvp_value_get_guid(kvp_val),
|
||||
gnc_account_get_book(investment_account));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void gnc_ofx_kvp_set_assoc_account(Account* investment_account,
|
||||
const Account *income_account)
|
||||
{
|
||||
kvp_frame * acc_frame;
|
||||
kvp_value * kvp_val;
|
||||
Account *result = NULL;
|
||||
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);
|
||||
force_account_dirty(investment_account);
|
||||
xaccAccountCommitEdit(investment_account);
|
||||
}
|
||||
|
||||
// copied from gnc-ab-kvp.c
|
||||
static void
|
||||
force_account_dirty(Account *acct)
|
||||
{
|
||||
gchar *name = g_strdup(xaccAccountGetName(acct));
|
||||
|
||||
/* This is necessary because modifying the KvpFrames doesn't mark
|
||||
* accounts dirty, which means the changes wont be propagated to the
|
||||
* backend.
|
||||
*/
|
||||
xaccAccountSetName(acct, name);
|
||||
g_free(name);
|
||||
}
|
38
src/import-export/ofx/gnc-ofx-kvp.h
Normal file
38
src/import-export/ofx/gnc-ofx-kvp.h
Normal file
@ -0,0 +1,38 @@
|
||||
/*******************************************************************\
|
||||
* This program is free software; you can redistribute it and/or *
|
||||
* modify it under the terms of the GNU General Public License as *
|
||||
* published by the Free Software Foundation; either version 2 of *
|
||||
* the License, or (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License*
|
||||
* along with this program; if not, contact: *
|
||||
* *
|
||||
* Free Software Foundation Voice: +1-617-542-5942 *
|
||||
* 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
|
||||
* Boston, MA 02110-1301, USA gnu@gnu.org *
|
||||
\********************************************************************/
|
||||
/*
|
||||
* gnc-ofx-kvp.h
|
||||
*
|
||||
* Created on: 13.03.2011
|
||||
* Author: cs
|
||||
*/
|
||||
|
||||
#ifndef GNC_OFX_KVP_H_
|
||||
#define GNC_OFX_KVP_H_
|
||||
|
||||
#include <glib.h>
|
||||
#include <engine/Account.h>
|
||||
|
||||
Account *gnc_ofx_kvp_get_assoc_account(const Account* investment_account);
|
||||
|
||||
void gnc_ofx_kvp_set_assoc_account(Account* investment_account,
|
||||
const Account *associated_income_accout);
|
||||
|
||||
|
||||
#endif /* GNC_OFX_CONVERSIONS_H_ */
|
Loading…
Reference in New Issue
Block a user