GnuCash  2.6.99
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
qofbook.h
Go to the documentation of this file.
1 /********************************************************************\
2  * qofbook.h -- Encapsulate all the information about a dataset. *
3  * This program is free software; you can redistribute it and/or *
4  * modify it under the terms of the GNU General Public License as *
5  * published by the Free Software Foundation; either version 2 of *
6  * the License, or (at your option) any later version. *
7  * *
8  * This program is distributed in the hope that it will be useful, *
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
11  * GNU General Public License for more details. *
12  * *
13  * You should have received a copy of the GNU General Public License*
14  * along with this program; if not, contact: *
15  * *
16  * Free Software Foundation Voice: +1-617-542-5942 *
17  * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 *
18  * Boston, MA 02110-1301, USA [email protected] *
19  * *
20 \********************************************************************/
40 #ifndef QOF_BOOK_H
41 #define QOF_BOOK_H
42 
43 #ifdef __cplusplus
44 extern "C"
45 {
46 #endif
47 
48 /* We only want a few things exported to Guile */
49 #ifndef SWIG
50 
51 typedef struct _QofBookClass QofBookClass;
52 
53 #include "qofid.h"
54 #include "kvp_frame.h"
55 #include "qofinstance.h"
56 
57 /* --- type macros --- */
58 #define QOF_TYPE_BOOK (qof_book_get_type ())
59 #define QOF_BOOK(o) \
60  (G_TYPE_CHECK_INSTANCE_CAST ((o), QOF_TYPE_BOOK, QofBook))
61 #define QOF_BOOK_CLASS(k) \
62  (G_TYPE_CHECK_CLASS_CAST((k), QOF_TYPE_BOOK, QofBookClass))
63 #define QOF_IS_BOOK(o) \
64  (G_TYPE_CHECK_INSTANCE_TYPE ((o), QOF_TYPE_BOOK))
65 #define QOF_IS_BOOK_CLASS(k) \
66  (G_TYPE_CHECK_CLASS_TYPE ((k), QOF_TYPE_BOOK))
67 #define QOF_BOOK_GET_CLASS(o) \
68  (G_TYPE_INSTANCE_GET_CLASS ((o), QOF_TYPE_BOOK, QofBookClass))
69 
70 typedef void (*QofBookDirtyCB) (QofBook *, gboolean dirty, gpointer user_data);
71 
72 typedef struct gnc_option_db GNCOptionDB;
73 
74 typedef void (*GNCOptionSave) (GNCOptionDB*, KvpFrame*, gboolean);
75 typedef void (*GNCOptionLoad) (GNCOptionDB*, KvpFrame*);
76 
77 /* Book structure */
78 struct _QofBook
79 {
80  QofInstance inst; /* Unique guid for this book. */
81 
82  /* Boolean indicates that the session is dirty -- that is, it has
83  * not yet been written out to disk after the last time the
84  * backend ran commit_edit(). This is distinct from the inherited
85  * QofInstance::dirty, which indicates that some persisitent
86  * property of the book object itself has been edited and not
87  * committed. Some backends write data out as part of
88  * commit_edit() and so don't use this flag.
89  */
90  gboolean session_dirty;
91 
92  /* The time when the book was first dirtied. This is a secondary
93  * indicator. It should only be used when session_saved is FALSE. */
94  time64 dirty_time;
95 
96  /* This callback function is called any time the book dirty flag
97  * changes state. Both clean->dirty and dirty->clean transitions
98  * trigger a callback. */
99  QofBookDirtyCB dirty_cb;
100 
101  /* This is the user supplied data that is returned in the dirty
102  * callback function.*/
103  gpointer dirty_data;
104 
105  /* The entity table associates the GUIDs of all the objects
106  * belonging to this book, with their pointers to the respective
107  * objects. This allows a lookup of objects based on thier guid.
108  */
109  GHashTable * hash_of_collections;
110 
111  /* In order to store arbitrary data, for extensibility, add a table
112  * that will be used to hold arbitrary pointers.
113  */
114  GHashTable *data_tables;
115 
116  /* Hash table of destroy callbacks for the data table. */
117  GHashTable *data_table_finalizers;
118 
119  /* Boolean indicates whether book is safe to write to (true means
120  * that it isn't). The usual reason will be a database version
121  * mismatch with the running instance of Gnucash.
122  */
123  gboolean read_only;
124 
125  /* state flag: 'y' means 'open for editing',
126  * 'n' means 'book is closed'
127  * xxxxx shouldn't this be replaced by the instance editlevel ???
128  */
129  char book_open;
130 
131  /* a flag denoting whether the book is closing down, used to
132  * help the QOF objects shut down cleanly without maintaining
133  * internal consistency.
134  * XXX shouldn't this be replaced by instance->do_free ???
135  */
136  gboolean shutting_down;
137 
138  /* version number, used for tracking multiuser updates */
139  gint32 version;
140 
141  /* To be technically correct, backends belong to sessions and
142  * not books. So the pointer below "really shouldn't be here",
143  * except that it provides a nice convenience, avoiding a lookup
144  * from the session. Better solutions welcome ... */
145  QofBackend *backend;
146 };
147 
149 {
150  QofInstanceClass parent_class;
151 };
152 
153 GType qof_book_get_type(void);
154 
164 #define QOF_BOOK_RETURN_ENTITY(book,guid,e_type,c_type) { \
165  QofInstance *val = NULL; \
166  if ((guid != NULL) && (book != NULL)) { \
167  const QofCollection *col; \
168  col = qof_book_get_collection (book, e_type); \
169  val = qof_collection_lookup_entity (col, guid); \
170  } \
171  return (c_type *) val; \
172 }
173 
174 
175 
177 typedef GList QofBookList;
178 
179 typedef void (*QofBookFinalCB) (QofBook *, gpointer key, gpointer user_data);
180 
182 gboolean qof_book_register (void);
183 
186 QofBook * qof_book_new (void);
187 
190 void qof_book_destroy (QofBook *book);
191 
197 void qof_book_mark_closed (QofBook *book);
198 
212 /*@ dependent @*/
213 QofCollection * qof_book_get_collection (const QofBook *, QofIdType);
214 
216 typedef void (*QofCollectionForeachCB) (QofCollection *, gpointer user_data);
217 void qof_book_foreach_collection (const QofBook *, QofCollectionForeachCB, gpointer);
218 
225 void qof_book_set_data (QofBook *book, const gchar *key, gpointer data);
226 
231 void qof_book_set_data_fin (QofBook *book, const gchar *key, gpointer data,
232  QofBookFinalCB);
233 
235 gpointer qof_book_get_data (const QofBook *book, const gchar *key);
236 
238 gboolean qof_book_is_readonly(const QofBook *book);
239 
241 void qof_book_mark_readonly(QofBook *book);
242 
243 #endif /* SWIG */
244 
246 gboolean qof_book_use_trading_accounts (const QofBook *book);
247 
250 gboolean qof_book_uses_autoreadonly (const QofBook *book);
251 
255 gint qof_book_get_num_days_autoreadonly (const QofBook *book);
256 
265 GDate* qof_book_get_autoreadonly_gdate (const QofBook *book);
266 
269 gboolean qof_book_use_split_action_for_num_field (const QofBook *book);
270 
272 gboolean qof_book_shutting_down (const QofBook *book);
273 
281 gboolean qof_book_session_not_saved (const QofBook *book);
282 
283 /* The following functions are not useful in scripting languages */
284 #ifndef SWIG
285 
291 void qof_book_mark_session_saved(QofBook *book);
292 
297 void qof_book_mark_session_dirty(QofBook *book);
298 
300 time64 qof_book_get_session_dirty_time(const QofBook *book);
301 
305 void qof_book_set_dirty_cb(QofBook *book, QofBookDirtyCB cb, gpointer user_data);
306 
310 gint64 qof_book_get_counter (QofBook *book, const char *counter_name);
311 
316 gchar *qof_book_increment_and_format_counter (QofBook *book, const char *counter_name);
317 
322 gchar * qof_book_validate_counter_format(const gchar *format);
323 
328 const char *qof_book_get_counter_format (const QofBook *book,
329  const char *counter_name);
330 
331 const char* qof_book_get_string_option(const QofBook* book, const char* opt_name);
332 void qof_book_set_string_option(QofBook* book, const char* opt_name, const char* opt_val);
333 
336 GHashTable *qof_book_get_features (QofBook *book);
337 void qof_book_set_feature (QofBook *book, const gchar *key, const gchar *descr);
338 
339 void qof_book_begin_edit(QofBook *book);
340 void qof_book_commit_edit(QofBook *book);
341 
342 /* Access functions for loading and saving the file options */
343 void qof_book_load_options (QofBook *book, GNCOptionLoad load_cb,
344  GNCOptionDB *odb);
345 void
346 qof_book_save_options (QofBook *book, GNCOptionSave save_cb,
347  GNCOptionDB* odb, gboolean clear);
348 
349 
351 #define qof_book_get_guid(X) qof_entity_get_guid (QOF_INSTANCE(X))
352 
353 #endif /* SWIG */
354 #ifdef __cplusplus
355 }
356 #endif
357 
358 #endif /* QOF_BOOK_H */
359 
gboolean qof_book_register(void)
void qof_book_set_dirty_cb(QofBook *book, QofBookDirtyCB cb, gpointer user_data)
A key-value frame system.
time64 qof_book_get_session_dirty_time(const QofBook *book)
gchar * qof_book_increment_and_format_counter(QofBook *book, const char *counter_name)
gint qof_book_get_num_days_autoreadonly(const QofBook *book)
gboolean qof_book_use_split_action_for_num_field(const QofBook *book)
QofBook * qof_book_new(void)
const char * qof_book_get_counter_format(const QofBook *book, const char *counter_name)
void qof_book_mark_closed(QofBook *book)
Object instance holds common fields that most gnucash objects use.
void qof_book_mark_readonly(QofBook *book)
QOF entity type identification system.
GHashTable * qof_book_get_features(QofBook *book)
gint64 qof_book_get_counter(QofBook *book, const char *counter_name)
const gchar * QofIdType
Definition: qofid.h:85
GDate * qof_book_get_autoreadonly_gdate(const QofBook *book)
void qof_book_mark_session_saved(QofBook *book)
void qof_book_set_data_fin(QofBook *book, const gchar *key, gpointer data, QofBookFinalCB)
void qof_book_set_data(QofBook *book, const gchar *key, gpointer data)
gboolean qof_book_session_not_saved(const QofBook *book)
void qof_book_mark_session_dirty(QofBook *book)
void(* QofCollectionForeachCB)(QofCollection *, gpointer user_data)
Definition: qofbook.h:216
gboolean qof_book_is_readonly(const QofBook *book)
GList QofBookList
Definition: qofbook.h:177
struct KvpFrameImpl KvpFrame
Definition: kvp_frame.h:76
QofCollection * qof_book_get_collection(const QofBook *, QofIdType)
gint64 time64
Definition: gnc-date.h:83
gboolean qof_book_uses_autoreadonly(const QofBook *book)
gboolean qof_book_shutting_down(const QofBook *book)
gpointer qof_book_get_data(const QofBook *book, const gchar *key)
gboolean qof_book_use_trading_accounts(const QofBook *book)
void qof_book_destroy(QofBook *book)
gchar * qof_book_validate_counter_format(const gchar *format)