r20411 - gnucash/trunk/src/import-export/ofx - Refactor KVP-related functions of OFX into separate file.
Christian Stimming
cstim at code.gnucash.org
Sun Mar 13 05:58:58 EDT 2011
Author: cstim
Date: 2011-03-13 05:58:55 -0400 (Sun, 13 Mar 2011)
New Revision: 20411
Trac: http://svn.gnucash.org/trac/changeset/20411
Added:
gnucash/trunk/src/import-export/ofx/gnc-ofx-kvp.c
gnucash/trunk/src/import-export/ofx/gnc-ofx-kvp.h
Modified:
gnucash/trunk/src/import-export/ofx/Makefile.am
gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c
Log:
Refactor KVP-related functions of OFX into separate file.
Modified: gnucash/trunk/src/import-export/ofx/Makefile.am
===================================================================
--- gnucash/trunk/src/import-export/ofx/Makefile.am 2011-03-13 09:54:27 UTC (rev 20410)
+++ gnucash/trunk/src/import-export/ofx/Makefile.am 2011-03-13 09:58:55 UTC (rev 20411)
@@ -4,11 +4,13 @@
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
Modified: gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c
===================================================================
--- gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c 2011-03-13 09:54:27 UTC (rev 20410)
+++ gnucash/trunk/src/import-export/ofx/gnc-ofx-import.c 2011-03-13 09:58:55 UTC (rev 20411)
@@ -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 @@
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 @@
{
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 @@
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");
}
Added: gnucash/trunk/src/import-export/ofx/gnc-ofx-kvp.c
===================================================================
--- gnucash/trunk/src/import-export/ofx/gnc-ofx-kvp.c (rev 0)
+++ gnucash/trunk/src/import-export/ofx/gnc-ofx-kvp.c 2011-03-13 09:58:55 UTC (rev 20411)
@@ -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 at 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);
+}
Property changes on: gnucash/trunk/src/import-export/ofx/gnc-ofx-kvp.c
___________________________________________________________________
Added: svn:eol-style
+ LF
Added: gnucash/trunk/src/import-export/ofx/gnc-ofx-kvp.h
===================================================================
--- gnucash/trunk/src/import-export/ofx/gnc-ofx-kvp.h (rev 0)
+++ gnucash/trunk/src/import-export/ofx/gnc-ofx-kvp.h 2011-03-13 09:58:55 UTC (rev 20411)
@@ -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 at 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_ */
Property changes on: gnucash/trunk/src/import-export/ofx/gnc-ofx-kvp.h
___________________________________________________________________
Added: svn:eol-style
+ LF
More information about the gnucash-changes
mailing list