[Gnucash-changes] r13931 - gnucash/trunk - Add support for directly marking the book dirty, for recording the

David Hampton hampton at cvs.gnucash.org
Sat May 6 17:10:01 EDT 2006


Author: hampton
Date: 2006-05-06 17:09:59 -0400 (Sat, 06 May 2006)
New Revision: 13931
Trac: http://svn.gnucash.org/trac/changeset/13931

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/lib/libqof/qof/qofbook-p.h
   gnucash/trunk/lib/libqof/qof/qofbook.c
   gnucash/trunk/lib/libqof/qof/qofbook.h
   gnucash/trunk/lib/libqof/qof/qofutil.c
Log:
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.


Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2006-05-06 14:53:22 UTC (rev 13930)
+++ gnucash/trunk/ChangeLog	2006-05-06 21:09:59 UTC (rev 13931)
@@ -1,5 +1,12 @@
 2006-05-06  David Hampton  <hampton at 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".
 

Modified: gnucash/trunk/lib/libqof/qof/qofbook-p.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofbook-p.h	2006-05-06 14:53:22 UTC (rev 13930)
+++ gnucash/trunk/lib/libqof/qof/qofbook-p.h	2006-05-06 21:09:59 UTC (rev 13931)
@@ -48,6 +48,19 @@
 {
   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.

Modified: gnucash/trunk/lib/libqof/qof/qofbook.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofbook.c	2006-05-06 14:53:22 UTC (rev 13930)
+++ gnucash/trunk/lib/libqof/qof/qofbook.c	2006-05-06 21:09:59 UTC (rev 13931)
@@ -155,12 +155,35 @@
 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
 qof_book_print_dirty (QofBook *book)
 {
@@ -169,6 +192,19 @@
   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 @@
 
 void qof_book_kvp_changed (QofBook *book)
 {
-  if (!book) return;
-  book->inst.dirty = TRUE;
+  qof_book_mark_dirty(book);
 }
 
 /* ====================================================================== */

Modified: gnucash/trunk/lib/libqof/qof/qofbook.h
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofbook.h	2006-05-06 14:53:22 UTC (rev 13930)
+++ gnucash/trunk/lib/libqof/qof/qofbook.h	2006-05-06 21:09:59 UTC (rev 13931)
@@ -66,6 +66,7 @@
 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 @@
  *    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);

Modified: gnucash/trunk/lib/libqof/qof/qofutil.c
===================================================================
--- gnucash/trunk/lib/libqof/qof/qofutil.c	2006-05-06 14:53:22 UTC (rev 13930)
+++ gnucash/trunk/lib/libqof/qof/qofutil.c	2006-05-06 21:09:59 UTC (rev 13931)
@@ -302,8 +302,10 @@
         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;



More information about the gnucash-changes mailing list