GnuCash  5.6-150-g038405b370+
import-utilities.cpp
1 /********************************************************************\
2  * This program is free software; you can redistribute it and/or *
3  * modify it under the terms of the GNU General Public License as *
4  * published by the Free Software Foundation; either version 2 of *
5  * the License, or (at your option) any later version. *
6  * *
7  * This program is distributed in the hope that it will be useful, *
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
10  * GNU General Public License for more details. *
11  * *
12  * You should have received a copy of the GNU General Public License*
13  * along with this program; if not, contact: *
14  * *
15  * Free Software Foundation Voice: +1-617-542-5942 *
16  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
17  * Boston, MA 02110-1301, USA gnu@gnu.org *
18 \********************************************************************/
26 #include <config.h>
27 
28 
29 #include <glib.h>
30 
31 #include <stdlib.h>
32 #include "import-utilities.h"
33 #include "qof.h"
34 #include "Account.h"
35 #include "Transaction.h"
36 
37 
38 /********************************************************************\
39  * Setter and getter functions for the online_id kvp frame in
40  * Account, Transaction and Split
41 \********************************************************************/
42 
43 gchar *
44 gnc_import_get_acc_online_id (Account * account)
45 {
46  gchar *id = NULL;
47  qof_instance_get (QOF_INSTANCE (account), "online-id", &id, NULL);
48  return id;
49 }
50 
51 /* Used in the midst of editing a transaction; make it save the
52  * account data. */
53 void
54 gnc_import_set_acc_online_id (Account *account, const gchar *id)
55 {
56  g_return_if_fail (account != NULL);
57  xaccAccountBeginEdit (account);
58  qof_instance_set (QOF_INSTANCE (account), "online-id", id, NULL);
59  xaccAccountCommitEdit (account);
60 }
61 
62 gchar *
63 gnc_import_get_trans_online_id (Transaction * transaction)
64 {
65  gchar *id = NULL;
66  qof_instance_get (QOF_INSTANCE (transaction), "online-id", &id, NULL);
67  return id;
68 }
69 
70 /* Not actually used */
71 void
72 gnc_import_set_trans_online_id (Transaction *transaction, const gchar *id)
73 {
74  g_return_if_fail (transaction != NULL);
75  xaccTransBeginEdit (transaction);
76  qof_instance_set (QOF_INSTANCE (transaction), "online-id", id, NULL);
77  xaccTransCommitEdit (transaction);
78 }
79 
80 gboolean
81 gnc_import_trans_has_online_id (Transaction * transaction)
82 {
83  gchar *online_id = gnc_import_get_trans_online_id(transaction);
84  gboolean retval = (online_id && *online_id);
85  g_free (online_id);
86  return retval;
87 }
88 
89 gchar *
90 gnc_import_get_split_online_id (Split * split)
91 {
92  gchar *id = NULL;
93  qof_instance_get (QOF_INSTANCE (split), "online-id", &id, NULL);
94  return id;
95 }
96 
97 /* Used several places in a transaction edit where many other
98  * parameters are also being set, so individual commits wouldn't be
99  * appropriate. Besides, there isn't a function for one.*/
100 void
101 gnc_import_set_split_online_id (Split *split, const gchar *id)
102 {
103  g_return_if_fail (split != NULL);
104  qof_instance_set (QOF_INSTANCE (split), "online-id", id, NULL);
105 }
106 
107 gboolean
108 gnc_import_split_has_online_id (Split * split)
109 {
110  gchar *online_id = gnc_import_get_split_online_id(split);
111  gboolean retval = (online_id && *online_id);
112  g_free (online_id);
113  return retval;
114 }
115 
116 /* @} */
void qof_instance_get(const QofInstance *inst, const gchar *first_prop,...)
Wrapper for g_object_get.
STRUCTS.
void qof_instance_set(QofInstance *inst, const gchar *first_prop,...)
Wrapper for g_object_set Group setting multiple parameters in a single begin/commit/rollback.
Account handling public routines.
void xaccTransCommitEdit(Transaction *trans)
The xaccTransCommitEdit() method indicates that the changes to the transaction and its splits are com...
void xaccTransBeginEdit(Transaction *trans)
The xaccTransBeginEdit() method must be called before any changes are made to a transaction or any of...
void xaccAccountBeginEdit(Account *acc)
The xaccAccountBeginEdit() subroutine is the first phase of a two-phase-commit wrapper for account up...
Definition: Account.cpp:1477
Utility functions for writing import modules.
API for Transactions and Splits (journal entries)
void xaccAccountCommitEdit(Account *acc)
ThexaccAccountCommitEdit() subroutine is the second phase of a two-phase-commit wrapper for account u...
Definition: Account.cpp:1518