Add support for directly marking the book dirty, for recording the

time that the book transitioned from clean to dirty, and for calling
back a registered function when the book transitions from clean to
dirty.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@13931 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
David Hampton 2006-05-06 21:09:59 +00:00
parent f455c29dc8
commit fad343b4e2
5 changed files with 80 additions and 3 deletions

View File

@ -1,5 +1,12 @@
2006-05-06 David Hampton <hampton@employees.org>
* lib/libqof/qof/qofbook.[ch]:
* lib/libqof/qof/qofbook-p.h:
* lib/libqof/qof/qofutil.c: Add support for directly marking the
book dirty, for recording the time that the book transitioned from
clean to dirty, and for calling back a registered function when
the book transitions from clean to dirty.
* configure.in: Can't use external qof until it supports
"alternate dirty mode".

View File

@ -48,6 +48,19 @@ struct _QofBook
{
QofInstance inst; /* Unique guid for this book. */
/* The time when the book was first dirtied. This is a secondary
* indicator. It should only be used when inst.dirty is TRUE. */
time_t dirty_time;
/* This callback function is called any time the book dirty flag
* changes state. Both clean->dirty and dirty->clean transitions
* trigger a callback. */
QofBookDirtyCB dirty_cb;
/* This is the user supplied data that is returned in the dirty
* callback function.*/
gpointer dirty_data;
/* The entity table associates the GUIDs of all the objects
* belonging to this book, with their pointers to the respective
* objects. This allows a lookup of objects based on thier guid.

View File

@ -155,10 +155,33 @@ qof_book_not_saved (QofBook *book)
void
qof_book_mark_saved (QofBook *book)
{
gboolean was_dirty;
if (!book) return;
was_dirty = book->inst.dirty;
book->inst.dirty = FALSE;
book->dirty_time = 0;
qof_object_mark_clean (book);
if (was_dirty) {
if (book->dirty_cb)
book->dirty_cb(book, FALSE, book->dirty_data);
}
}
void qof_book_mark_dirty (QofBook *book)
{
gboolean was_dirty;
if (!book) return;
was_dirty = book->inst.dirty;
book->inst.dirty = TRUE;
if (!was_dirty) {
book->dirty_time = time(NULL);
if (book->dirty_cb)
book->dirty_cb(book, TRUE, book->dirty_data);
}
}
void
@ -169,6 +192,19 @@ qof_book_print_dirty (QofBook *book)
qof_book_foreach_collection(book, qof_collection_print_dirty, NULL);
}
time_t
qof_book_get_dirty_time (QofBook *book)
{
return book->dirty_time;
}
void
qof_book_set_dirty_cb(QofBook *book, QofBookDirtyCB cb, gpointer user_data)
{
book->dirty_data = user_data;
book->dirty_cb = cb;
}
/* ====================================================================== */
/* getters */
@ -200,8 +236,7 @@ qof_book_set_backend (QofBook *book, QofBackend *be)
void qof_book_kvp_changed (QofBook *book)
{
if (!book) return;
book->inst.dirty = TRUE;
qof_book_mark_dirty(book);
}
/* ====================================================================== */

View File

@ -66,6 +66,7 @@ typedef struct _QofBook QofBook;
typedef GList QofBookList;
typedef void (*QofBookFinalCB) (QofBook *, gpointer key, gpointer user_data);
typedef void (*QofBookDirtyCB) (QofBook *, gboolean dirty, gpointer user_data);
/** Register the book object with the QOF object system. */
gboolean qof_book_register (void);
@ -154,8 +155,27 @@ gboolean qof_book_not_saved (QofBook *book);
* by the frontend when the used has said to abandon any changes.
*/
void qof_book_mark_saved(QofBook *book);
/** The qof_book_mark_dirty() routine marks the book as having been
* modified. It can be used by frontend when the used has made a
* change at the book level.
*/
void qof_book_mark_dirty(QofBook *book);
/** This debugging function can be used to traverse the book structure
* and all subsidiary structures, printing out which structures
* have been marked dirty.
*/
void qof_book_print_dirty (QofBook *book);
/** Retrieve the earliest modification time on the book. */
time_t qof_book_get_dirty_time(QofBook *book);
/** Set the function to call when a book transitions from clean to
* dirty, or vice versa.
*/
void qof_book_set_dirty_cb(QofBook *book, QofBookDirtyCB cb, gpointer user_data);
/** Call this function when you change the book kvp, to make sure the book
* is marked 'dirty'. */
void qof_book_kvp_changed (QofBook *book);

View File

@ -302,8 +302,10 @@ qof_commit_edit_part2(QofInstance *inst,
return TRUE;
}
if (dirty && qof_get_alt_dirty_mode())
if (dirty && qof_get_alt_dirty_mode()) {
qof_collection_mark_dirty(inst->entity.collection);
qof_book_mark_dirty(inst->book);
}
if (on_done)
on_done(inst);
return TRUE;