|
GnuCash 2.4.99
|
00001 /********************************************************************\ 00002 * qofbook.h -- Encapsulate all the information about a dataset. * 00003 * This program is free software; you can redistribute it and/or * 00004 * modify it under the terms of the GNU General Public License as * 00005 * published by the Free Software Foundation; either version 2 of * 00006 * the License, or (at your option) any later version. * 00007 * * 00008 * This program is distributed in the hope that it will be useful, * 00009 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00010 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00011 * GNU General Public License for more details. * 00012 * * 00013 * You should have received a copy of the GNU General Public License* 00014 * along with this program; if not, contact: * 00015 * * 00016 * Free Software Foundation Voice: +1-617-542-5942 * 00017 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * 00018 * Boston, MA 02110-1301, USA gnu@gnu.org * 00019 * * 00020 \********************************************************************/ 00040 #ifndef QOF_BOOK_H 00041 #define QOF_BOOK_H 00042 00043 /* We only want a few things exported to Guile */ 00044 #ifndef SWIG 00045 00046 typedef struct _QofBookClass QofBookClass; 00047 00048 #include "qofid.h" 00049 #include "kvp_frame.h" 00050 #include "qofinstance.h" 00051 00052 /* --- type macros --- */ 00053 #define QOF_TYPE_BOOK (qof_book_get_type ()) 00054 #define QOF_BOOK(o) \ 00055 (G_TYPE_CHECK_INSTANCE_CAST ((o), QOF_TYPE_BOOK, QofBook)) 00056 #define QOF_BOOK_CLASS(k) \ 00057 (G_TYPE_CHECK_CLASS_CAST((k), QOF_TYPE_BOOK, QofBookClass)) 00058 #define QOF_IS_BOOK(o) \ 00059 (G_TYPE_CHECK_INSTANCE_TYPE ((o), QOF_TYPE_BOOK)) 00060 #define QOF_IS_BOOK_CLASS(k) \ 00061 (G_TYPE_CHECK_CLASS_TYPE ((k), QOF_TYPE_BOOK)) 00062 #define QOF_BOOK_GET_CLASS(o) \ 00063 (G_TYPE_INSTANCE_GET_CLASS ((o), QOF_TYPE_BOOK, QofBookClass)) 00064 00065 typedef void (*QofBookDirtyCB) (QofBook *, gboolean dirty, gpointer user_data); 00066 00067 /* Book structure */ 00068 struct _QofBook 00069 { 00070 QofInstance inst; /* Unique guid for this book. */ 00071 00072 /* Boolean indicates that the session is dirty -- that is, it has 00073 * not yet been written out to disk after the last time the 00074 * backend ran commit_edit(). This is distinct from the inherited 00075 * QofInstance::dirty, which indicates that some persisitent 00076 * property of the book object itself has been edited and not 00077 * committed. Some backends write data out as part of 00078 * commit_edit() and so don't use this flag. 00079 */ 00080 gboolean session_dirty; 00081 00082 /* The time when the book was first dirtied. This is a secondary 00083 * indicator. It should only be used when session_saved is FALSE. */ 00084 time_t dirty_time; 00085 00086 /* This callback function is called any time the book dirty flag 00087 * changes state. Both clean->dirty and dirty->clean transitions 00088 * trigger a callback. */ 00089 QofBookDirtyCB dirty_cb; 00090 00091 /* This is the user supplied data that is returned in the dirty 00092 * callback function.*/ 00093 gpointer dirty_data; 00094 00095 /* The entity table associates the GUIDs of all the objects 00096 * belonging to this book, with their pointers to the respective 00097 * objects. This allows a lookup of objects based on thier guid. 00098 */ 00099 GHashTable * hash_of_collections; 00100 00101 /* In order to store arbitrary data, for extensibility, add a table 00102 * that will be used to hold arbitrary pointers. 00103 */ 00104 GHashTable *data_tables; 00105 00106 /* Hash table of destroy callbacks for the data table. */ 00107 GHashTable *data_table_finalizers; 00108 00109 /* Boolean indicates whether book is safe to write to (true means 00110 * that it isn't). The usual reason will be a database version 00111 * mismatch with the running instance of Gnucash. 00112 */ 00113 gboolean read_only; 00114 00115 /* state flag: 'y' means 'open for editing', 00116 * 'n' means 'book is closed' 00117 * xxxxx shouldn't this be replaced by the instance editlevel ??? 00118 */ 00119 char book_open; 00120 00121 /* a flag denoting whether the book is closing down, used to 00122 * help the QOF objects shut down cleanly without maintaining 00123 * internal consistency. 00124 * XXX shouldn't this be replaced by instance->do_free ??? 00125 */ 00126 gboolean shutting_down; 00127 00128 /* version number, used for tracking multiuser updates */ 00129 gint32 version; 00130 00131 /* To be technically correct, backends belong to sessions and 00132 * not books. So the pointer below "really shouldn't be here", 00133 * except that it provides a nice convenience, avoiding a lookup 00134 * from the session. Better solutions welcome ... */ 00135 QofBackend *backend; 00136 }; 00137 00138 struct _QofBookClass 00139 { 00140 QofInstanceClass parent_class; 00141 }; 00142 00143 GType qof_book_get_type(void); 00144 00154 #define QOF_BOOK_RETURN_ENTITY(book,guid,e_type,c_type) { \ 00155 QofInstance *val = NULL; \ 00156 if ((guid != NULL) && (book != NULL)) { \ 00157 const QofCollection *col; \ 00158 col = qof_book_get_collection (book, e_type); \ 00159 val = qof_collection_lookup_entity (col, guid); \ 00160 } \ 00161 return (c_type *) val; \ 00162 } 00163 00164 00165 00167 typedef GList QofBookList; 00168 00169 typedef void (*QofBookFinalCB) (QofBook *, gpointer key, gpointer user_data); 00170 00172 gboolean qof_book_register (void); 00173 00176 QofBook * qof_book_new (void); 00177 00180 void qof_book_destroy (QofBook *book); 00181 00187 void qof_book_mark_closed (QofBook *book); 00188 00202 /*@ dependent @*/ 00203 QofCollection * qof_book_get_collection (const QofBook *, QofIdType); 00204 00206 typedef void (*QofCollectionForeachCB) (QofCollection *, gpointer user_data); 00207 void qof_book_foreach_collection (const QofBook *, QofCollectionForeachCB, gpointer); 00208 00216 KvpFrame *qof_book_get_slots(const QofBook *book); 00217 00228 void qof_book_set_data (QofBook *book, const gchar *key, gpointer data); 00229 00234 void qof_book_set_data_fin (QofBook *book, const gchar *key, gpointer data, 00235 QofBookFinalCB); 00236 00238 gpointer qof_book_get_data (const QofBook *book, const gchar *key); 00239 00241 gboolean qof_book_is_readonly(const QofBook *book); 00242 00244 void qof_book_mark_readonly(QofBook *book); 00245 00246 #endif /* SWIG */ 00247 00249 gboolean qof_book_use_trading_accounts (const QofBook *book); 00250 00253 gboolean qof_book_uses_autoreadonly (const QofBook *book); 00254 00258 gint qof_book_get_num_days_autoreadonly (const QofBook *book); 00259 00268 GDate* qof_book_get_autoreadonly_gdate (const QofBook *book); 00269 00271 gboolean qof_book_shutting_down (const QofBook *book); 00272 00280 gboolean qof_book_session_not_saved (const QofBook *book); 00281 00282 /* The following functions are not useful in scripting languages */ 00283 #ifndef SWIG 00284 00290 void qof_book_mark_session_saved(QofBook *book); 00291 00296 void qof_book_mark_session_dirty(QofBook *book); 00297 00299 time_t qof_book_get_session_dirty_time(const QofBook *book); 00300 00304 void qof_book_set_dirty_cb(QofBook *book, QofBookDirtyCB cb, gpointer user_data); 00305 00308 void qof_book_kvp_changed (QofBook *book); 00309 00313 gint64 qof_book_get_counter (QofBook *book, const char *counter_name); 00314 00319 gchar *qof_book_increment_and_format_counter (QofBook *book, const char *counter_name); 00320 00325 gchar * qof_book_validate_counter_format(const gchar *format); 00326 00331 gchar *qof_book_get_counter_format (const QofBook *book, const char *counter_name); 00332 00333 const char* qof_book_get_string_option(const QofBook* book, const char* opt_name); 00334 void qof_book_set_string_option(QofBook* book, const char* opt_name, const char* opt_val); 00335 00336 void qof_book_begin_edit(QofBook *book); 00337 void qof_book_commit_edit(QofBook *book); 00338 00340 #define qof_book_get_guid(X) qof_entity_get_guid (QOF_INSTANCE(X)) 00341 00342 #endif /* SWIG */ 00343 00344 #endif /* QOF_BOOK_H */ 00345
1.7.4