GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
gnc-ab-trans-templ.c
1 /*
2  * gnc-ab-trans-templ.c --
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, contact:
16  *
17  * Free Software Foundation Voice: +1-617-542-5942
18  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
19  * Boston, MA 02110-1301, USA [email protected]
20  */
21 
30 #include "config.h"
31 
32 #include "gnc-ab-trans-templ.h"
33 
34 /* This static indicates the debugging module that this .o belongs to. */
35 G_GNUC_UNUSED static QofLogModule log_module = G_LOG_DOMAIN;
36 
37 /* KvpFrame slot names */
38 #define TT_NAME "name"
39 #define TT_RNAME "rnam"
40 #define TT_RACC "racc"
41 #define TT_RBCODE "rbcd"
42 #define TT_PURPOS "purp"
43 #define TT_PURPOSCT "purc"
44 #define TT_AMOUNT "amou"
45 
47 {
48  /* Name of this Template */
49  gchar *name;
50  gchar *name_key; /* Collation key */
51 
52  /* Recipient */
53  gchar *recp_name;
54  gchar *recp_account;
55  gchar *recp_bankcode;
56 
57  /* Amount */
58  gnc_numeric amount;
59 
60  /* Purpose, description */
61  gchar *purpose;
62  gchar *purpose_cont;
63 };
64 
65 
68 {
69  return gnc_ab_trans_templ_new_full(NULL, NULL, NULL, NULL,
70  gnc_numeric_zero(), NULL, NULL);
71 }
72 
74 gnc_ab_trans_templ_new_full(const char *name, const char *recp_name,
75  const char *recp_account, const char *recp_bankcode,
76  gnc_numeric amount, const char *purpose,
77  const char *purpose_cont)
78 {
79  GncABTransTempl *r = g_new(GncABTransTempl, 1);
80  r->name = g_strdup(name);
81  r->name_key = g_utf8_collate_key(name, -1);
82  r->recp_name = g_strdup(recp_name);
83  r->recp_account = g_strdup(recp_account);
84  r->recp_bankcode = g_strdup(recp_bankcode);
85  r->amount = amount;
86  r->purpose = g_strdup(purpose);
87  r->purpose_cont = g_strdup(purpose_cont);
88 
89  return r;
90 }
91 
94 {
95  g_return_val_if_fail(k, NULL);
96 
98  kvp_value_get_string(kvp_frame_get_slot(k, TT_NAME)),
99  kvp_value_get_string(kvp_frame_get_slot(k, TT_RNAME)),
100  kvp_value_get_string(kvp_frame_get_slot(k, TT_RACC)),
101  kvp_value_get_string(kvp_frame_get_slot(k, TT_RBCODE)),
102  kvp_value_get_numeric(kvp_frame_get_slot(k, TT_AMOUNT)),
103  kvp_value_get_string(kvp_frame_get_slot(k, TT_PURPOS)),
104  kvp_value_get_string(kvp_frame_get_slot(k, TT_PURPOSCT)));
105 }
106 
107 GList *
109 {
110  GList *res = NULL;
111  GList *iter;
112 
113  for (iter = v; iter; iter = iter->next)
114  {
115  KvpFrame *frame = kvp_value_get_frame((KvpValue*) iter->data);
116  res = g_list_prepend(res, gnc_ab_trans_templ_new_from_kvp(frame));
117  }
118  res = g_list_reverse(res);
119 
120  return res;
121 }
122 
123 void
125 {
126  if (!t) return;
127  g_free(t->name);
128  g_free(t->name_key);
129  g_free(t->recp_name);
130  g_free(t->recp_account);
131  g_free(t->recp_bankcode);
132  g_free(t->purpose);
133  g_free(t->purpose_cont);
134  g_free(t);
135 }
136 
137 void
139 {
140  GList *iter;
141  for (iter = l; iter; iter = iter->next)
143  g_list_free(l);
144 }
145 
146 KvpFrame *
148 {
149  KvpFrame *k;
150 
151  g_return_val_if_fail(t, NULL);
152 
153  k = kvp_frame_new();
154  kvp_frame_set_slot(k, TT_NAME, kvp_value_new_string(t->name));
155  kvp_frame_set_slot(k, TT_RNAME, kvp_value_new_string(t->recp_name));
156  kvp_frame_set_slot(k, TT_RACC, kvp_value_new_string(t->recp_account));
157  kvp_frame_set_slot(k, TT_RBCODE, kvp_value_new_string(t->recp_bankcode));
158  kvp_frame_set_slot(k, TT_AMOUNT, kvp_value_new_gnc_numeric(t->amount));
159  kvp_frame_set_slot(k, TT_PURPOS, kvp_value_new_string(t->purpose));
160  kvp_frame_set_slot(k, TT_PURPOSCT, kvp_value_new_string(t->purpose_cont));
161 
162  return k;
163 }
164 
165 GList *
167 {
168  GList *res = NULL;
169  GList *iter;
170 
171  for (iter = k; iter; iter = iter->next)
172  {
173  GncABTransTempl *t = (GncABTransTempl*) iter->data;
175  res = g_list_prepend(res, value);
176  }
177  res = g_list_reverse(res);
178 
179  return res;
180 }
181 
182 const gchar *
184 {
185  g_return_val_if_fail(t, NULL);
186  return t->name;
187 }
188 
189 const gchar *
191 {
192  g_return_val_if_fail(t, NULL);
193  return t->recp_name;
194 }
195 
196 const gchar *
198 {
199  g_return_val_if_fail(t, NULL);
200  return t->recp_account;
201 }
202 
203 const gchar *
205 {
206  g_return_val_if_fail(t, NULL);
207  return t->recp_bankcode;
208 }
209 
212 {
213  g_return_val_if_fail(t, gnc_numeric_zero());
214  return t->amount;
215 }
216 
217 const gchar *
219 {
220  g_return_val_if_fail(t, NULL);
221  return t->purpose;
222 }
223 
224 const gchar *
226 {
227  g_return_val_if_fail(t, NULL);
228  return t->purpose_cont;
229 }
230 
231 void
233 {
234  g_return_if_fail(t);
235  g_free(t->name);
236  t->name = g_strdup(name);
237 }
238 
239 void
241 {
242  g_return_if_fail(t);
243  g_free(t->recp_name);
244  t->recp_name = g_strdup(recp_name);
245 }
246 
247 void
249  const gchar *recp_account)
250 {
251  g_return_if_fail(t);
252  g_free(t->recp_account);
253  t->recp_account = g_strdup(recp_account);
254 }
255 
256 void
258  const gchar *recp_bankcode)
259 {
260  g_return_if_fail(t);
261  g_free(t->recp_bankcode);
262  t->recp_bankcode = g_strdup(recp_bankcode);
263 }
264 
265 void
267 {
268  g_return_if_fail(t);
269  t->amount = amount;
270 }
271 
272 void
274 {
275  g_return_if_fail(t);
276  g_free(t->purpose);
277  t->purpose = g_strdup(purpose);
278 }
279 
280 void
282  const gchar *purpose_cont)
283 {
284  g_return_if_fail(t);
285  g_free(t->purpose_cont);
286  t->purpose_cont = g_strdup(purpose_cont);
287 }
typedefG_BEGIN_DECLS struct _GncABTransTempl GncABTransTempl
const gchar * gnc_ab_trans_templ_get_purpose(const GncABTransTempl *t)
void gnc_ab_trans_templ_free(GncABTransTempl *t)
void kvp_frame_set_slot(KvpFrame *frame, const gchar *key, KvpValue *value)
void gnc_ab_trans_templ_set_purpose_cont(GncABTransTempl *t, const gchar *purpose_cont)
Templates for AqBanking transactions.
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
void gnc_ab_trans_templ_set_amount(GncABTransTempl *t, gnc_numeric amount)
const gchar * gnc_ab_trans_templ_get_recp_account(const GncABTransTempl *t)
void gnc_ab_trans_templ_list_free(GList *l)
void gnc_ab_trans_templ_set_recp_account(GncABTransTempl *t, const gchar *recp_account)
void gnc_ab_trans_templ_set_name(GncABTransTempl *t, const gchar *name)
KvpValue * kvp_value_new_frame_nc(KvpFrame *value)
GList * gnc_ab_trans_templ_list_to_kvp_list(GList *k)
void gnc_ab_trans_templ_set_recp_name(GncABTransTempl *t, const gchar *recp_name)
void gnc_ab_trans_templ_set_recp_bankcode(GncABTransTempl *t, const gchar *recp_bankcode)
GncABTransTempl * gnc_ab_trans_templ_new(void)
void gnc_ab_trans_templ_set_purpose(GncABTransTempl *t, const gchar *purpose)
char * kvp_value_get_string(const KvpValue *value)
const gchar * gnc_ab_trans_templ_get_name(const GncABTransTempl *t)
gnc_numeric gnc_ab_trans_templ_get_amount(const GncABTransTempl *t)
#define kvp_value_new_gnc_numeric
Definition: kvp_frame.h:466
const gchar * gnc_ab_trans_templ_get_recp_bankcode(const GncABTransTempl *t)
GncABTransTempl * gnc_ab_trans_templ_new_from_kvp(const KvpFrame *k)
const gchar * gnc_ab_trans_templ_get_recp_name(const GncABTransTempl *t)
KvpFrame * gnc_ab_trans_templ_to_kvp(const GncABTransTempl *t)
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)
const gchar * gnc_ab_trans_templ_get_purpose_cont(const GncABTransTempl *t)
struct KvpFrameImpl KvpFrame
Definition: kvp_frame.h:76
KvpFrame * kvp_frame_new(void)
KvpFrame * kvp_value_get_frame(const KvpValue *value)
GList * gnc_ab_trans_templ_list_new_from_kvp_list(GList *v)
struct KvpValueImpl KvpValue
Definition: kvp_frame.h:80
const gchar * QofLogModule
Definition: qofid.h:89