Reimplement AQBanking template list in C++ and in libqof.

It requires direct manipulation of KVP, so it needs to be hidden away in
libqof.
This commit is contained in:
John Ralls
2015-06-06 12:08:28 -07:00
parent b4e0240783
commit dcc9bfec36
12 changed files with 331 additions and 429 deletions

View File

@@ -396,7 +396,6 @@ src/import-export/aqb/gnc-ab-getbalance.c
src/import-export/aqb/gnc-ab-gettrans.c
src/import-export/aqb/gnc-ab-kvp.c
src/import-export/aqb/gnc-ab-transfer.c
src/import-export/aqb/gnc-ab-trans-templ.c
src/import-export/aqb/gnc-ab-utils.c
src/import-export/aqb/gnc-file-aqb-import.c
src/import-export/aqb/gnc-gwen-gui.c
@@ -463,6 +462,7 @@ src/import-export/qif-imp/qif-objects.scm
src/import-export/qif-imp/qif-parse.scm
src/import-export/qif-imp/qif-to-gnc.scm
src/import-export/qif-imp/qif-utils.scm
src/libqof/qof/gnc-aqbanking-templates.cpp
src/libqof/qof/gnc-date.cpp
src/libqof/qof/gnc-int128.cpp
src/libqof/qof/gnc-numeric.cpp

View File

@@ -9,7 +9,6 @@ libgncmod_aqbanking_la_SOURCES = \
gnc-ab-getbalance.c \
gnc-ab-gettrans.c \
gnc-ab-kvp.c \
gnc-ab-trans-templ.c \
gnc-ab-transfer.c \
gnc-ab-utils.c \
gnc-file-aqb-import.c \
@@ -24,7 +23,6 @@ noinst_HEADERS = \
gnc-ab-getbalance.h \
gnc-ab-gettrans.h \
gnc-ab-kvp.h \
gnc-ab-trans-templ.h \
gnc-ab-transfer.h \
gnc-ab-utils.h \
gnc-file-aqb-import.h \

View File

@@ -41,10 +41,10 @@
#include <aqbanking/jobsepatransfer.h>
#include <aqbanking/jobsepadebitnote.h>
#include <gnc-aqbanking-templates.h>
#include "dialog-ab-trans.h"
#include "dialog-transfer.h"
#include "dialog-utils.h"
#include "gnc-ab-trans-templ.h"
#include "gnc-ab-utils.h"
#include "gnc-amount-edit.h"
#include "gnc-ui.h"

View File

@@ -114,44 +114,3 @@ gnc_ab_set_account_trans_retrieval(Account *a, Timespec time)
NULL);
xaccAccountCommitEdit(a);
}
#define AB_KEY "hbci"
#define AB_TEMPLATES "template-list"
static KvpFrame *gnc_ab_get_book_kvp(QofBook *b, gboolean create);
/* EFFECTIVE FRIEND FUNCTION */
extern KvpFrame *qof_instance_get_slots (const QofInstance *);
/* EFFECTIVE FRIEND FUNCTION */
extern void qof_instance_set_dirty_flag (gconstpointer inst, gboolean flag);
GList *
gnc_ab_get_book_template_list(QofBook *b)
{
KvpFrame *frame = gnc_ab_get_book_kvp(b, FALSE);
KvpValue *value = kvp_frame_get_slot(frame, AB_TEMPLATES);
return kvp_value_get_glist(value);
}
void
gnc_ab_set_book_template_list(QofBook *b, GList *template_list)
{
KvpFrame *frame = gnc_ab_get_book_kvp(b, TRUE);
KvpValue *value = kvp_value_new_glist_nc(template_list);
kvp_frame_set_slot_nc(frame, AB_TEMPLATES, value);
qof_instance_set_dirty_flag(QOF_INSTANCE(b), TRUE);
}
static KvpFrame *
gnc_ab_get_book_kvp(QofBook *b, gboolean create)
{
KvpFrame *toplevel = qof_instance_get_slots(QOF_INSTANCE(b));
KvpFrame *result = kvp_frame_get_frame(toplevel, AB_KEY);
if (!result && create)
{
result = kvp_frame_new();
kvp_frame_add_frame_nc(toplevel, AB_KEY, result);
}
return result;
}

View File

@@ -43,9 +43,7 @@ G_BEGIN_DECLS
* @{ */
/**
* Return a non-copied pointer to the accountid string in the Account @a a.
* The gchar* is still owned by the kvp_frame, so don't free it until you want
* to delete the whole kvp_frame.
* Return accountid string in the Account @a a.
*
* @param a Account
* @return Account ID
@@ -62,9 +60,7 @@ const gchar *gnc_ab_get_account_accountid(const Account *a);
void gnc_ab_set_account_accountid(Account *a, const gchar *id);
/**
* Return a non-copied pointer to the bankcode string in the Account @a a. The
* gchar* is still owned by the kvp_frame, so don't free it until you want to
* delete the whole kvp_frame.
* Return the bankcode string in the Account @a a.
*
* @param a Account
* @return Bank code
@@ -116,33 +112,4 @@ void gnc_ab_set_account_trans_retrieval(Account *a, Timespec time);
/** @} */
/** @name Book
* @{ */
/**
* Return a non-copied pointer to the GList of kvp_frames which eventually are
* the template transactions, stored in the given book.
*
* @param b Book
* @return Template list
*/
GList *gnc_ab_get_book_template_list(QofBook *b);
/**
* Set the GList of kvp_frames of template transactions in the Book @a b to @a
* template_list. No copy of the GList will be stored, the callee becomes the
* owner and the caller must not free it. The book will be marked "dirty".
*
* @param b Book
* @param template_list Template list
*/
void gnc_ab_set_book_template_list(QofBook *b, GList *template_list);
/** @} */
G_END_DECLS
/** @} */
/** @} */
#endif /* GNC_AB_KVP_H */

View File

@@ -1,287 +0,0 @@
/*
* gnc-ab-trans-templ.c --
*
* 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
*/
/**
* @internal
* @file gnc-ab-trans-templ.c
* @brief Templates for AqBanking transactions
* @author Copyright (C) 2002 Christian Stimming <stimming@tuhh.de>
* @author Copyright (C) 2008 Andreas Koehler <andi5.py@gmx.net>
*/
#include "config.h"
#include "gnc-ab-trans-templ.h"
/* This static indicates the debugging module that this .o belongs to. */
G_GNUC_UNUSED static QofLogModule log_module = G_LOG_DOMAIN;
/* KvpFrame slot names */
#define TT_NAME "name"
#define TT_RNAME "rnam"
#define TT_RACC "racc"
#define TT_RBCODE "rbcd"
#define TT_PURPOS "purp"
#define TT_PURPOSCT "purc"
#define TT_AMOUNT "amou"
struct _GncABTransTempl
{
/* Name of this Template */
gchar *name;
gchar *name_key; /* Collation key */
/* Recipient */
gchar *recp_name;
gchar *recp_account;
gchar *recp_bankcode;
/* Amount */
gnc_numeric amount;
/* Purpose, description */
gchar *purpose;
gchar *purpose_cont;
};
GncABTransTempl *
gnc_ab_trans_templ_new(void)
{
return gnc_ab_trans_templ_new_full(NULL, NULL, NULL, NULL,
gnc_numeric_zero(), NULL, NULL);
}
GncABTransTempl *
gnc_ab_trans_templ_new_full(const char *name, const char *recp_name,
const char *recp_account, const char *recp_bankcode,
gnc_numeric amount, const char *purpose,
const char *purpose_cont)
{
GncABTransTempl *r = g_new(GncABTransTempl, 1);
r->name = g_strdup(name);
r->name_key = g_utf8_collate_key(name, -1);
r->recp_name = g_strdup(recp_name);
r->recp_account = g_strdup(recp_account);
r->recp_bankcode = g_strdup(recp_bankcode);
r->amount = amount;
r->purpose = g_strdup(purpose);
r->purpose_cont = g_strdup(purpose_cont);
return r;
}
GncABTransTempl *
gnc_ab_trans_templ_new_from_kvp(const KvpFrame *k)
{
g_return_val_if_fail(k, NULL);
return gnc_ab_trans_templ_new_full(
kvp_value_get_string(kvp_frame_get_slot(k, TT_NAME)),
kvp_value_get_string(kvp_frame_get_slot(k, TT_RNAME)),
kvp_value_get_string(kvp_frame_get_slot(k, TT_RACC)),
kvp_value_get_string(kvp_frame_get_slot(k, TT_RBCODE)),
kvp_value_get_numeric(kvp_frame_get_slot(k, TT_AMOUNT)),
kvp_value_get_string(kvp_frame_get_slot(k, TT_PURPOS)),
kvp_value_get_string(kvp_frame_get_slot(k, TT_PURPOSCT)));
}
GList *
gnc_ab_trans_templ_list_new_from_kvp_list(GList *v)
{
GList *res = NULL;
GList *iter;
for (iter = v; iter; iter = iter->next)
{
KvpFrame *frame = kvp_value_get_frame((KvpValue*) iter->data);
res = g_list_prepend(res, gnc_ab_trans_templ_new_from_kvp(frame));
}
res = g_list_reverse(res);
return res;
}
void
gnc_ab_trans_templ_free(GncABTransTempl *t)
{
if (!t) return;
g_free(t->name);
g_free(t->name_key);
g_free(t->recp_name);
g_free(t->recp_account);
g_free(t->recp_bankcode);
g_free(t->purpose);
g_free(t->purpose_cont);
g_free(t);
}
void
gnc_ab_trans_templ_list_free(GList *l)
{
GList *iter;
for (iter = l; iter; iter = iter->next)
gnc_ab_trans_templ_free((GncABTransTempl*) iter->data);
g_list_free(l);
}
KvpFrame *
gnc_ab_trans_templ_to_kvp(const GncABTransTempl *t)
{
KvpFrame *k;
g_return_val_if_fail(t, NULL);
k = kvp_frame_new();
kvp_frame_set_slot(k, TT_NAME, kvp_value_new_string(t->name));
kvp_frame_set_slot(k, TT_RNAME, kvp_value_new_string(t->recp_name));
kvp_frame_set_slot(k, TT_RACC, kvp_value_new_string(t->recp_account));
kvp_frame_set_slot(k, TT_RBCODE, kvp_value_new_string(t->recp_bankcode));
kvp_frame_set_slot(k, TT_AMOUNT, kvp_value_new_gnc_numeric(t->amount));
kvp_frame_set_slot(k, TT_PURPOS, kvp_value_new_string(t->purpose));
kvp_frame_set_slot(k, TT_PURPOSCT, kvp_value_new_string(t->purpose_cont));
return k;
}
GList *
gnc_ab_trans_templ_list_to_kvp_list(GList *k)
{
GList *res = NULL;
GList *iter;
for (iter = k; iter; iter = iter->next)
{
GncABTransTempl *t = (GncABTransTempl*) iter->data;
KvpValue *value = kvp_value_new_frame_nc(gnc_ab_trans_templ_to_kvp(t));
res = g_list_prepend(res, value);
}
res = g_list_reverse(res);
return res;
}
const gchar *
gnc_ab_trans_templ_get_name(const GncABTransTempl *t)
{
g_return_val_if_fail(t, NULL);
return t->name;
}
const gchar *
gnc_ab_trans_templ_get_recp_name(const GncABTransTempl *t)
{
g_return_val_if_fail(t, NULL);
return t->recp_name;
}
const gchar *
gnc_ab_trans_templ_get_recp_account(const GncABTransTempl *t)
{
g_return_val_if_fail(t, NULL);
return t->recp_account;
}
const gchar *
gnc_ab_trans_templ_get_recp_bankcode(const GncABTransTempl *t)
{
g_return_val_if_fail(t, NULL);
return t->recp_bankcode;
}
gnc_numeric
gnc_ab_trans_templ_get_amount(const GncABTransTempl *t)
{
g_return_val_if_fail(t, gnc_numeric_zero());
return t->amount;
}
const gchar *
gnc_ab_trans_templ_get_purpose(const GncABTransTempl *t)
{
g_return_val_if_fail(t, NULL);
return t->purpose;
}
const gchar *
gnc_ab_trans_templ_get_purpose_cont(const GncABTransTempl *t)
{
g_return_val_if_fail(t, NULL);
return t->purpose_cont;
}
void
gnc_ab_trans_templ_set_name(GncABTransTempl *t, const gchar *name)
{
g_return_if_fail(t);
g_free(t->name);
t->name = g_strdup(name);
}
void
gnc_ab_trans_templ_set_recp_name(GncABTransTempl *t, const gchar *recp_name)
{
g_return_if_fail(t);
g_free(t->recp_name);
t->recp_name = g_strdup(recp_name);
}
void
gnc_ab_trans_templ_set_recp_account(GncABTransTempl *t,
const gchar *recp_account)
{
g_return_if_fail(t);
g_free(t->recp_account);
t->recp_account = g_strdup(recp_account);
}
void
gnc_ab_trans_templ_set_recp_bankcode(GncABTransTempl *t,
const gchar *recp_bankcode)
{
g_return_if_fail(t);
g_free(t->recp_bankcode);
t->recp_bankcode = g_strdup(recp_bankcode);
}
void
gnc_ab_trans_templ_set_amount(GncABTransTempl *t, gnc_numeric amount)
{
g_return_if_fail(t);
t->amount = amount;
}
void
gnc_ab_trans_templ_set_purpose(GncABTransTempl *t, const gchar *purpose)
{
g_return_if_fail(t);
g_free(t->purpose);
t->purpose = g_strdup(purpose);
}
void
gnc_ab_trans_templ_set_purpose_cont(GncABTransTempl *t,
const gchar *purpose_cont)
{
g_return_if_fail(t);
g_free(t->purpose_cont);
t->purpose_cont = g_strdup(purpose_cont);
}

View File

@@ -35,12 +35,12 @@
#include <gtk/gtk.h>
#include <aqbanking/banking.h>
#include "Transaction.h"
#include <gnc-aqbanking-templates.h>
#include <Transaction.h>
#include "dialog-transfer.h"
#include "gnc-ab-transfer.h"
#include "gnc-ab-kvp.h"
#include "gnc-ab-utils.h"
#include "gnc-ab-trans-templ.h"
#include "gnc-gwen-gui.h"
#include "gnc-ui.h"
@@ -62,8 +62,7 @@ save_templates(GtkWidget *parent, Account *gnc_acc, GList *templates,
"but you cancelled the transfer dialog. "
"Do you nevertheless want to store the changes?")))
{
GList *kvp_list = gnc_ab_trans_templ_list_to_kvp_list(templates);
gnc_ab_set_book_template_list(gnc_account_get_book(gnc_acc), kvp_list);
gnc_ab_set_book_template_list(gnc_account_get_book(gnc_acc), templates);
}
}
@@ -119,8 +118,8 @@ gnc_ab_maketrans(GtkWidget *parent, Account *gnc_acc,
}
/* Get list of template transactions */
templates = gnc_ab_trans_templ_list_new_from_kvp_list(
gnc_ab_get_book_template_list(gnc_account_get_book(gnc_acc)));
templates = gnc_ab_trans_templ_list_new_from_book(
gnc_account_get_book(gnc_acc));
/* Create new ABTransDialog */
td = gnc_ab_trans_dialog_new(parent, ab_acc,

View File

@@ -127,8 +127,7 @@ gint gnc_AB_BANKING_fini(AB_BANKING *api);
/**
* Get the corresponding AqBanking account to the GnuCash account @a gnc_acc.
* Of course this only works after the GnuCash account has been set up for
* AqBanking use, i.e. the kvp_frame "hbci/..." has been filled with
* information.
* AqBanking use, i.e. the account's hbci data have been set up and populated.
*
* @param api The AB_BANKING to get the AB_ACCOUNT from
* @param gnc_acc The GnuCash account to query for AB_ACCOUNT reference data

View File

@@ -25,7 +25,7 @@
// for the gnc_ab_get_book_template_list() et al. functions
#include "import-export/aqb/gnc-ab-kvp.h"
#include "import-export/aqb/gnc-ab-trans-templ.h"
#include <gnc-aqbanking-templates.h>
#include "engine/gnc-hooks.h"
static char* get_filepath(const char* filename)
@@ -78,14 +78,6 @@ test_qofsession_aqb_kvp( void )
//printf("io_err2 = %d\n", io_err);
g_assert(io_err == 0);
// No HBCI slot exists, of course
{
// No HBCI slot exists, of course
GList *mylist = gnc_ab_get_book_template_list(qof_session_get_book(new_session));
g_assert(mylist == 0);
}
g_free(newfile);
g_free(file1);
@@ -121,11 +113,7 @@ test_qofsession_aqb_kvp( void )
const char* ORIGINAL_NAME = "Some Name";
const char* CHANGED_NAME = "Some Changed Name";
GList *kvp_list = gnc_ab_get_book_template_list(book);
g_assert(kvp_list != 0); // do we have the slot?!
g_assert_cmpint(g_list_length(kvp_list), ==, 1);
templ_list = gnc_ab_trans_templ_list_new_from_kvp_list(kvp_list);
templ_list = gnc_ab_trans_templ_list_new_from_book (book);
g_assert_cmpint(g_list_length(templ_list), ==, 1);
templ = templ_list->data;
@@ -134,21 +122,16 @@ test_qofsession_aqb_kvp( void )
// Now we change the name into something else and verify it can be saved
gnc_ab_trans_templ_set_name(templ, CHANGED_NAME);
{
GList *kvp_list_new = gnc_ab_trans_templ_list_to_kvp_list(templ_list);
gnc_ab_trans_templ_list_free(templ_list);
g_assert(!qof_instance_get_dirty(QOF_INSTANCE(book))); // not yet dirty
// Here we save the changed kvp
gnc_ab_set_book_template_list(book, kvp_list_new);
gnc_ab_set_book_template_list(book, templ_list);
g_assert(qof_instance_get_dirty(QOF_INSTANCE(book))); // yup, now dirty
gnc_ab_trans_templ_list_free(templ_list);
}
{
GList *mylist = gnc_ab_get_book_template_list(book);
g_assert(mylist != 0);
g_assert_cmpint(g_list_length(mylist), ==, 1);
templ_list = gnc_ab_trans_templ_list_new_from_kvp_list(mylist);
templ_list = gnc_ab_trans_templ_list_new_from_book (book);
g_assert_cmpint(g_list_length(templ_list), ==, 1);
templ = templ_list->data;

View File

@@ -23,6 +23,7 @@ AM_CPPFLAGS = \
$(BOOST_CPPFLAGS)
libgnc_qof_la_SOURCES = \
gnc-aqbanking-templates.cpp \
gnc-date.cpp \
gnc-int128.cpp \
gnc-numeric.cpp \
@@ -50,6 +51,7 @@ libgnc_qof_la_SOURCES = \
qofincludedir = ${pkgincludedir}
qofinclude_HEADERS = \
gnc-aqbanking-templates.h \
gnc-date-p.h \
gnc-date.h \
gnc-numeric.h \

View File

@@ -0,0 +1,292 @@
/********************************************************************
* gnc-aqbanking-templates.cpp implements transaction templates *
* for AQBanking. *
* Copyright 2015 John Ralls <jralls@ceridwen.us> *
* *
* 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 *
* *
********************************************************************/
/** Class for managing AQBanking Transaction Templates.
*/
#include <string>
extern "C"
{
#include "gnc-aqbanking-templates.h"
#include "kvp_frame.h"
#include "qofinstance-p.h"
}
#include "gnc-rational.hpp"
namespace {
static const char* TT_NAME {"name"};
static const char* TT_RNAME {"rnam"};
static const char* TT_RACC {"racc"};
static const char* TT_RBCODE {"rbcd"};
static const char* TT_PURPOS {"purp"};
static const char* TT_PURPOSCT {"purc"};
static const char* TT_AMOUNT {"amou"};
}
struct _GncABTransTempl
{
public:
_GncABTransTempl () :
m_name(), m_recipient_name(), m_recipient_account(),
m_recipient_bankcode(), m_amount(gnc_numeric_zero()), m_purpose(),
m_purpose_continuation() {}
_GncABTransTempl (const std::string& name,
const std::string& recip_name,
const std::string& recip_account,
const std::string& recip_code,
const GncRational& amount,
const std::string& purpose,
const std::string& purpose_cont) :
m_name(name), m_recipient_name(recip_name),
m_recipient_account(recip_account), m_recipient_bankcode(recip_code),
m_amount(amount), m_purpose(purpose),
m_purpose_continuation(purpose_cont) {}
KvpFrame* make_kvp_frame();
const char* name() const { return m_name.c_str(); }
const char* recipient_name() const { return m_recipient_name.c_str(); }
const char* recipient_account() const
{
return m_recipient_account.c_str();
}
const char* recipient_bankcode() const
{
return m_recipient_bankcode.c_str();
}
const GncRational amount() const { return m_amount; }
const char* purpose() const { return m_purpose.c_str(); }
const char* purpose_continuation() const
{
return m_purpose_continuation.c_str();
}
void set_name (const char* name) { m_name = name; }
void set_recipient_name (const char* name) { m_recipient_name = name; }
void set_recipient_account (const char* account) {
m_recipient_account = account;
}
void set_recipient_bankcode (const char* code) {
m_recipient_bankcode = code;
}
void set_amount (GncRational amount) { m_amount = amount; }
void set_purpose (const char* purpose) { m_purpose = purpose; }
void set_purpose_continuation (const char* name) { m_name = name; }
private:
std::string m_name;
std::string m_recipient_name;
std::string m_recipient_account;
std::string m_recipient_bankcode;
GncRational m_amount;
std::string m_purpose;
std::string m_purpose_continuation;
};
KvpFrame*
_GncABTransTempl::make_kvp_frame()
{
auto frame = kvp_frame_new();
kvp_frame_set_slot(frame, TT_NAME, kvp_value_new_string(m_name.c_str()));
kvp_frame_set_slot(frame, TT_RNAME,
kvp_value_new_string(m_recipient_name.c_str()));
kvp_frame_set_slot(frame, TT_RACC,
kvp_value_new_string(m_recipient_account.c_str()));
kvp_frame_set_slot(frame, TT_RBCODE,
kvp_value_new_string(m_recipient_bankcode.c_str()));
kvp_frame_set_slot(frame, TT_AMOUNT, kvp_value_new_gnc_numeric(m_amount));
kvp_frame_set_slot(frame, TT_PURPOS,
kvp_value_new_string(m_purpose.c_str()));
kvp_frame_set_slot(frame, TT_PURPOSCT,
kvp_value_new_string(m_purpose_continuation.c_str()));
return frame;
}
GncABTransTempl*
gnc_ab_trans_templ_new()
{
return new _GncABTransTempl;
}
GncABTransTempl*
gnc_ab_trans_templ_new_full(const gchar *name, const gchar *recp_name,
const gchar *recp_account,
const gchar *recp_bankcode, gnc_numeric amount,
const gchar *purpose, const gchar *purpose_cont)
{
return new _GncABTransTempl(name, recp_name, recp_account, recp_bankcode,
amount, purpose, purpose_cont);
}
GList*
gnc_ab_trans_templ_list_new_from_book(QofBook *b)
{
GList *retval = NULL;
KvpFrame *toplevel = qof_instance_get_slots (QOF_INSTANCE (b));
KvpFrame *hbci = kvp_frame_get_frame (toplevel, "hbci");
KvpValue *listval = kvp_frame_get_slot (hbci, "template-list");
GList *list = kvp_value_get_glist (listval);
for (auto node = list; node != NULL; node = g_list_next (node))
{
KvpFrame *frame = kvp_value_get_frame (static_cast<KvpValue*>(node->data));
auto func = [frame](const char* key)
{return kvp_value_get_string(kvp_frame_get_slot(frame, key));};
auto templ = new _GncABTransTempl (func(TT_NAME), func(TT_RNAME),
func(TT_RACC), func(TT_RBCODE),
kvp_value_get_numeric(kvp_frame_get_slot(frame, TT_AMOUNT)),
func(TT_PURPOS), func(TT_PURPOSCT));
retval = g_list_prepend (retval, templ);
}
retval = g_list_reverse (retval);
return retval;
}
void
gnc_ab_trans_templ_free (GncABTransTempl *t)
{
delete t;
}
void
gnc_ab_trans_templ_list_free (GList *l)
{
for(GList *node = l; node != NULL; node = g_list_next(node))
delete static_cast<_GncABTransTempl*>(node->data);
}
void
gnc_ab_set_book_template_list (QofBook *b, GList *template_list)
{
GList *kvp_list = NULL;
for (auto node = template_list; node != NULL; node = g_list_next (node))
{
auto value = kvp_value_new_frame_nc (static_cast<_GncABTransTempl*>(node->data)->make_kvp_frame());
kvp_list = g_list_prepend (kvp_list, value);
}
kvp_list = g_list_reverse (kvp_list);
auto value = kvp_value_new_glist_nc(kvp_list);
KvpFrame *toplevel = qof_instance_get_slots (QOF_INSTANCE (b));
KvpFrame *hbci = kvp_frame_get_frame (toplevel, "hbci");
kvp_frame_set_slot_nc (hbci, "template-list", value);
qof_instance_set_dirty_flag (QOF_INSTANCE (b), TRUE);
}
const gchar *
gnc_ab_trans_templ_get_name(const GncABTransTempl *t)
{
g_return_val_if_fail(t, NULL);
return t->name();
}
const gchar *
gnc_ab_trans_templ_get_recp_name(const GncABTransTempl *t)
{
g_return_val_if_fail(t, NULL);
return t->recipient_name();
}
const gchar *
gnc_ab_trans_templ_get_recp_account(const GncABTransTempl *t)
{
g_return_val_if_fail(t, NULL);
return t->recipient_account();
}
const gchar *
gnc_ab_trans_templ_get_recp_bankcode(const GncABTransTempl *t)
{
g_return_val_if_fail(t, NULL);
return t->recipient_bankcode();
}
gnc_numeric
gnc_ab_trans_templ_get_amount(const GncABTransTempl *t)
{
g_return_val_if_fail(t, gnc_numeric_zero());
return t->amount();
}
const gchar *
gnc_ab_trans_templ_get_purpose(const GncABTransTempl *t)
{
g_return_val_if_fail(t, NULL);
return t->purpose();
}
const gchar *
gnc_ab_trans_templ_get_purpose_cont(const GncABTransTempl *t)
{
g_return_val_if_fail(t, NULL);
return t->purpose_continuation();
}
void
gnc_ab_trans_templ_set_name(GncABTransTempl *t, const gchar *name)
{
g_return_if_fail(t);
t->set_name(name);
}
void
gnc_ab_trans_templ_set_recp_name(GncABTransTempl *t, const gchar *recp_name)
{
g_return_if_fail(t);
t->set_recipient_name(recp_name);
}
void
gnc_ab_trans_templ_set_recp_account(GncABTransTempl *t,
const gchar *recp_account)
{
g_return_if_fail(t);
t->set_recipient_account(recp_account);
}
void
gnc_ab_trans_templ_set_recp_bankcode(GncABTransTempl *t,
const gchar *recp_bankcode)
{
g_return_if_fail(t);
t->set_recipient_bankcode(recp_bankcode);
}
void
gnc_ab_trans_templ_set_amount(GncABTransTempl *t, gnc_numeric amount)
{
g_return_if_fail(t);
t->set_amount(amount);
}
void
gnc_ab_trans_templ_set_purpose(GncABTransTempl *t, const gchar *purpose)
{
g_return_if_fail(t);
t->set_purpose(purpose);
}
void
gnc_ab_trans_templ_set_purpose_cont(GncABTransTempl *t,
const gchar *purpose_cont)
{
g_return_if_fail(t);
t->set_purpose_continuation (purpose_cont);
}

View File

@@ -33,8 +33,13 @@
#ifndef GNC_AB_TRANS_TEMPL_H
#define GNC_AB_TRANS_TEMPL_H
#include <glib.h>
#ifdef __cplusplus
extern "C"
{
#endif
#include <config.h>
#include <glib.h>
#include "qof.h"
G_BEGIN_DECLS
@@ -67,25 +72,25 @@ GncABTransTempl *gnc_ab_trans_templ_new_full(
const gchar *purpose_cont);
/**
* Create a template, taking the values from a KvpFrame.
* Obtain the list of QofTemplates saved in a Book.
*
* @param k KvpFrame
* @return A newly allocated GncABTransTempl
*/
GncABTransTempl *gnc_ab_trans_templ_new_from_kvp(const KvpFrame *k);
/**
* Create a list of templates from a list of kvp_values which in turn
* contain a KvpFrame.
*
* @param v GList of kvp_values
* @param b QofBook containing the templates.
* @return A GList of newly allocated GncABTransTempls
*/
GList *gnc_ab_trans_templ_list_new_from_kvp_list(GList *v);
GList *gnc_ab_trans_templ_list_new_from_book(QofBook *b);
/**
* Set the GList of kvp_frames of template transactions in the Book @a b to @a
* template_list. No copy of the GList will be stored, the callee becomes the
* owner and the caller must not free it. The book will be marked "dirty".
*
* @param b Book
* @param template_list Template list
*/
void gnc_ab_set_book_template_list(QofBook *b, GList *template_list);
/**
* Free the memory used by a template.
*
* @param t GncABTransTempl to be freed
*/
void gnc_ab_trans_templ_free(GncABTransTempl *t);
@@ -97,23 +102,6 @@ void gnc_ab_trans_templ_free(GncABTransTempl *t);
*/
void gnc_ab_trans_templ_list_free(GList *l);
/**
* Create a KvpFrame a given template.
*
* @param t Template
* @return A newly allocated KvpFrame
*/
KvpFrame *gnc_ab_trans_templ_to_kvp(const GncABTransTempl *t);
/**
* Create a list of kvp_values, which in turn contain a KvpFrame, from a list
* of templates.
*
* @param k GList of GncABTransTempls
* @return GList of newly allocated kvp_values
*/
GList *gnc_ab_trans_templ_list_to_kvp_list(GList *k);
/**
* @param t Template
* @return Name of the template, an internal string
@@ -217,7 +205,9 @@ void gnc_ab_trans_templ_set_purpose_cont(GncABTransTempl *t,
const gchar *purpose_cont);
G_END_DECLS
#ifdef __cplusplus
}
#endif
#endif /* GNC_AB_TRANS_TEMPL_H */
/** @} */
/** @} */