GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
qif-import.h
1 /*
2  * qif-import.h -- a QIF Import module
3  *
4  * Written By: Derek Atkins <[email protected]>
5  * Copyright (c) 2003 Derek Atkins <[email protected]>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License as
9  * published by the Free Software Foundation; either version 2 of
10  * the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, contact:
19  *
20  * Free Software Foundation Voice: +1-617-542-5942
21  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652
22  * Boston, MA 02110-1301, USA [email protected]
23  */
24 
25 #ifndef QIF_IMPORT_H
26 #define QIF_IMPORT_H
27 
28 #include <stdio.h>
29 #include "qof.h"
30 
31 typedef enum
32 {
33  QIF_TYPE_BANK = 1,
34  QIF_TYPE_CASH,
35  QIF_TYPE_CCARD,
36  QIF_TYPE_INVST,
37  QIF_TYPE_PORT,
38  QIF_TYPE_OTH_A,
39  QIF_TYPE_OTH_L,
40  QIF_TYPE_CLASS,
41  QIF_TYPE_CAT,
42  QIF_TYPE_SECURITY,
43  QIF_ACCOUNT,
44  QIF_AUTOSWITCH,
45  QIF_CLEAR_AUTOSWITCH
46 } QifType;
47 
48 /* Make sure this patches */
49 #define QIF_TYPE_MAX QIF_CLEAR_AUTOSWITCH
50 
51 typedef struct _QifHandler *QifHandler;
52 typedef struct _QifContext *QifContext;
53 typedef struct _QifLine *QifLine;
54 
55 /* Qif Flags */
56 #define QIF_F_IGNORE_ACCOUNTS (1 << 0)
57 #define QIF_F_TXN_NEEDS_ACCT (1 << 1)
58 #define QIF_F_ITXN_NEEDS_ACCT (1 << 2)
59 
60 /* Qif Reconciled Flag */
61 typedef enum
62 {
63  QIF_R_NO = 0,
64  QIF_R_CLEARED,
65  QIF_R_RECONCILED,
66  QIF_R_BUDGETED,
67 } QifRecnFlag;
68 
69 /* Qif Errors */
70 
71 typedef enum
72 {
73  QIF_E_OK = 0,
74  QIF_E_INTERNAL,
75  QIF_E_BADSTATE,
76  QIF_E_BADARGS,
77  QIF_E_NOFILE,
78 } QifError;
79 
80 
81 /* Qif (investment?) Actions */
82 typedef enum
83 {
84  QIF_A_NONE = 0,
85  QIF_A_BUY,
86  QIF_A_BUYX,
87  QIF_A_CGLONG,
88  QIF_A_CGLONGX,
89  QIF_A_CGMID,
90  QIF_A_CGMIDX,
91  QIF_A_CGSHORT,
92  QIF_A_CGSHORTX,
93  QIF_A_DIV,
94  QIF_A_DIVX,
95  QIF_A_EXERCISE,
96  QIF_A_EXERCISEX,
97  QIF_A_EXPIRE,
98  QIF_A_GRANT,
99  QIF_A_INTINC,
100  QIF_A_INTINCX,
101  QIF_A_MARGINT,
102  QIF_A_MARGINTX,
103  QIF_A_MISCEXP,
104  QIF_A_MISCEXPX,
105  QIF_A_MISCINC,
106  QIF_A_MISCINCX,
107  QIF_A_REINVDIV,
108  QIF_A_REINVINT,
109  QIF_A_REINVLG,
110  QIF_A_REINVMD,
111  QIF_A_REINVSG,
112  QIF_A_REINVSH,
113  QIF_A_REMINDER,
114  QIF_A_RTRNCAP,
115  QIF_A_RTRNCAPX,
116  QIF_A_SELL,
117  QIF_A_SELLX,
118  QIF_A_SHRSIN,
119  QIF_A_SHRSOUT,
120  QIF_A_STKSPLIT,
121  QIF_A_VEST,
122  QIF_A_XIN,
123  QIF_A_XOUT,
124 } QifAction;
125 
126 /* Public API Functions */
127 
128 /* Create a QIF Import Context */
129 QifContext qif_context_new(void);
130 void qif_context_destroy(QifContext ctx);
131 
132 /* Open and read a QIF File. You must pass in the parent
133  * context; it will return the child (file) context
134  */
135 QifContext qif_file_new(QifContext ctx, const char* filename);
136 
137 /* Does a qif-file need a default QIF account? */
138 gboolean qif_file_needs_account(QifContext ctx);
139 
140 /* Return the filename of the QIF file */
141 const char * qif_file_filename(QifContext ctx);
142 
143 /* Provide a default QIF Account for the QIF File */
144 void qif_file_set_default_account(QifContext ctx, const char *acct_name);
145 
146 /* Parse the QIF File */
147 QifError qif_file_parse(QifContext ctx, gpointer ui_arg);
148 
149 /* Merge all the qif-files from the children and into the context */
150 void qif_parse_merge_files(QifContext ctx);
151 
152 /* Obtain the list of USED QifAccounts and QifCategories. Finds all
153  * references from the transactions in the QifContext. The returned
154  * GList must be freed by the caller.
155  */
156 GList *qif_context_get_accounts(QifContext ctx);
157 GList *qif_context_get_categories(QifContext ctx);
158 
159 #endif /* QIF_IMPORT_H */