[Gnucash-changes] r12056 - gnucash/trunk - Better integrate stock prices with QOF. Gnucash now warns you about

David Hampton hampton at cvs.gnucash.org
Sun Nov 27 22:25:46 EST 2005


Author: hampton
Date: 2005-11-27 22:25:43 -0500 (Sun, 27 Nov 2005)
New Revision: 12056
Trac: http://svn.gnucash.org/trac/changeset/12056

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/src/backend/file/gnc-pricedb-xml-v2.c
   gnucash/trunk/src/backend/file/io-gncbin-r.c
   gnucash/trunk/src/backend/file/io-gncxml-v1.c
   gnucash/trunk/src/backend/postgres/price.c
   gnucash/trunk/src/engine/gnc-pricedb-p.h
   gnucash/trunk/src/engine/gnc-pricedb.c
   gnucash/trunk/src/engine/gnc-pricedb.h
Log:
Better integrate stock prices with QOF.  Gnucash now warns you about
unsaved stock price changes.


Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2005-11-26 22:47:32 UTC (rev 12055)
+++ gnucash/trunk/ChangeLog	2005-11-28 03:25:43 UTC (rev 12056)
@@ -1,3 +1,13 @@
+2005-11-27  David Hampton  <hampton at employees.org>
+
+	* src/backend/file/io-gncbin-r.c:
+	* src/backend/file/gnc-pricedb-xml-v2.c:
+	* src/backend/file/io-gncxml-v1.c:
+	* src/backend/postgres/price.c:
+	* src/engine/gnc-pricedb.[ch]:
+	* src/engine/gnc-pricedb-p.h: Better integrate stock prices with
+	QOF.  Gnucash now warns you about unsaved stock price changes.
+
 2005-11-26  David Hampton  <hampton at employees.org>
 
 	* src/gnome/gnc-plugin-page-register.c: Change "Reverse
@@ -1652,7 +1662,7 @@
 	* src/engine/Period.h: Doxygen tweak.
 	* src/engine/Transaction.c: qof_begin_edit changes.
 	* src/engine/gnc-engine.c: Load the two default GModules.
-	* src/engine/gnc-pricedb.c: Pair up the ENTER and LEAVE calls.
+	* src/engine/gnc-pricedb.c: Pair up the ENTER printf c%s: alls.
 	* src/engine/gnc-trace.c: QOF sync.
 	* src/engine/gnc-trace.h: QOF Sync
 	* src/engine/qof-be-utils.h: qof_begin_edit changes.
@@ -1880,7 +1890,7 @@
 	* src/report/standard-reports/transaction.scm: 
 	* src/app-utils/date-utilities.scm: 
 	* src/app-utils/app-utils.scm: 
-	Add "Quarterly" option to transaction report. Add support
+	Add "Q __FUNCTION__,uarterly" option to transaction report. Add support
 	functions to app-utils.scm and date-utilities.scm to support
 	finding the quarter of a given date, and to format it as Q1, Q2,
 	Q3, or Q4.  Fix a bug in the as-yet-unused function
@@ -2040,8 +2050,8 @@
 	applications.
 	* src/engine/qofbook.h
 	* src/engine/qofbook.c: New trace subsystem, qof.h
-	fixes and test-period fixes. Balance ENTER and LEAVE
-	in log output.
+	fixes and test-period fixes. Balance ENTER printf
+	%s: in log output.
 	* src/engine/qofquery.c: Balance ENTER and LEAVE.
 	* src/engine/qofsession.c: Balance ENTER and LEAVE
 	and new trace subsystem changes.
@@ -2214,7 +2224,7 @@
 2005-09-21  David Hampton  <hampton at employees.org>
 
 	* src/gnome-utils/dialog-options.c: Remove remnants of the old
-	"Advanced Preferences" page.
+	"A __FUNCTION__,dvanced Preferences" page.
 	
 	* src/app-utils/prefs.scm:
 	* src/gnome/schemas/apps_gnucash_dialog_common.schemas:
@@ -3455,7 +3465,7 @@
 	  Handle new (private) header file, gnc-hooks-scm.h
 
 	* src/engine/gnc-hooks.c:
-	  Use ENTER/LEAVE macros instead of commented printfs
+	  Use printf m%s: acros instead of commented printfs
 
 	* src/engine/gw-engine-spec.scm:
 	  use gnc-hooks-scm.h header

Modified: gnucash/trunk/src/backend/file/gnc-pricedb-xml-v2.c
===================================================================
--- gnucash/trunk/src/backend/file/gnc-pricedb-xml-v2.c	2005-11-26 22:47:32 UTC (rev 12055)
+++ gnucash/trunk/src/backend/file/gnc-pricedb-xml-v2.c	2005-11-28 03:25:43 UTC (rev 12056)
@@ -229,7 +229,7 @@
 {
   gxpf_data *gdata = global_data;
   QofBook *book = gdata->bookdata;
-  GNCPriceDB *db = gnc_pricedb_create(book);
+  GNCPriceDB *db = gnc_book_get_pricedb(book);
   g_return_val_if_fail(db, FALSE);
   gnc_pricedb_set_bulk_update(db, TRUE);
   *result = db;

Modified: gnucash/trunk/src/backend/file/io-gncbin-r.c
===================================================================
--- gnucash/trunk/src/backend/file/io-gncbin-r.c	2005-11-26 22:47:32 UTC (rev 12055)
+++ gnucash/trunk/src/backend/file/io-gncbin-r.c	2005-11-28 03:25:43 UTC (rev 12056)
@@ -199,7 +199,7 @@
 {
   GSList *item = potential_quotes;
 
-  *prices = gnc_pricedb_create(book);
+  *prices = gnc_book_get_pricedb(book);
   if (!*prices) return FALSE;
 
   while(item)

Modified: gnucash/trunk/src/backend/file/io-gncxml-v1.c
===================================================================
--- gnucash/trunk/src/backend/file/io-gncxml-v1.c	2005-11-26 22:47:32 UTC (rev 12055)
+++ gnucash/trunk/src/backend/file/io-gncxml-v1.c	2005-11-28 03:25:43 UTC (rev 12056)
@@ -1142,7 +1142,6 @@
       return FALSE;
     }
     status->pricedb = pdb;
-    gnc_pricedb_mark_clean(pdb);
     child_result->should_cleanup = FALSE;
   }
   return(TRUE);
@@ -3704,7 +3703,7 @@
                       gchar **attrs)
 {
   GNCParseStatus *pstatus = (GNCParseStatus *) global_data;
-  GNCPriceDB *db = gnc_pricedb_create(pstatus->book);
+  GNCPriceDB *db = gnc_book_get_pricedb(pstatus->book);
   g_return_val_if_fail(db, FALSE);
   *result = db;
   return(TRUE);

Modified: gnucash/trunk/src/backend/postgres/price.c
===================================================================
--- gnucash/trunk/src/backend/postgres/price.c	2005-11-26 22:47:32 UTC (rev 12055)
+++ gnucash/trunk/src/backend/postgres/price.c	2005-11-28 03:25:43 UTC (rev 12056)
@@ -440,10 +440,6 @@
    SEND_QUERY (be, be->buff, );
    pgendGetResults (be, get_price_cb, NULL);
 
-   /* insertion into the price db will mark it dirty;
-    * but it really isn't at this point. */
-   gnc_pricedb_mark_clean (look->prdb);
-
    /* re-enable events */
    pgendEnable(be);
    gnc_engine_resume_events();

Modified: gnucash/trunk/src/engine/gnc-pricedb-p.h
===================================================================
--- gnucash/trunk/src/engine/gnc-pricedb-p.h	2005-11-26 22:47:32 UTC (rev 12055)
+++ gnucash/trunk/src/engine/gnc-pricedb-p.h	2005-11-28 03:25:43 UTC (rev 12056)
@@ -89,7 +89,6 @@
 } GNCPriceLookupHelper;
 
 #define  gnc_price_set_guid(P,G)  qof_entity_set_guid(QOF_ENTITY(P),(G))
-#define  gnc_pricedb_mark_clean(db) qof_instance_mark_clean(QOF_INSTANCE(db))
 void     gnc_pricedb_substitute_commodity(GNCPriceDB *db,
                                           gnc_commodity *old_c,
                                           gnc_commodity *new_c);

Modified: gnucash/trunk/src/engine/gnc-pricedb.c
===================================================================
--- gnucash/trunk/src/engine/gnc-pricedb.c	2005-11-26 22:47:32 UTC (rev 12055)
+++ gnucash/trunk/src/engine/gnc-pricedb.c	2005-11-28 03:25:43 UTC (rev 12056)
@@ -177,6 +177,21 @@
 /* ==================================================================== */
 /* setters */
 
+static void
+gnc_price_set_dirty (GNCPrice *p)
+{
+  if (p->db) {
+    qof_instance_set_dirty(&p->inst);
+    return;
+  }
+
+  /* This is a transient price structure, probably for the add new
+   * price dialog.  The user may end up cancelling it instead of
+   * saving it, so don't mark the collection dirty. We'll mark it
+   * dirty later if the price is ever saved to the db. */
+  p->inst.dirty = TRUE;
+}
+
 void
 gnc_price_set_commodity(GNCPrice *p, gnc_commodity *c)
 {
@@ -191,7 +206,7 @@
     remove_price (p->db, p, TRUE);
     gnc_price_begin_edit (p);
     p->commodity = c;
-    if(p->db) p->db->inst.dirty = TRUE;
+    gnc_price_set_dirty(p);
     gnc_price_commit_edit (p);
     add_price (p->db, p);
     gnc_price_unref (p);
@@ -213,7 +228,7 @@
     remove_price (p->db, p, TRUE);
     gnc_price_begin_edit (p);
     p->currency = c;
-    if(p->db) p->db->inst.dirty = TRUE;
+    gnc_price_set_dirty(p);
     gnc_price_commit_edit (p);
     add_price (p->db, p);
     gnc_price_unref (p);
@@ -233,7 +248,7 @@
     remove_price (p->db, p, FALSE);
     gnc_price_begin_edit (p);
     p->tmspec = t;
-    if(p->db) p->db->inst.dirty = TRUE;
+    gnc_price_set_dirty(p);
     gnc_price_commit_edit (p);
     add_price (p->db, p);
     gnc_price_unref (p);
@@ -252,7 +267,7 @@
     tmp = gnc_string_cache_insert((gpointer) s);
     if(p->source) gnc_string_cache_remove(p->source);
     p->source = tmp;
-    if(p->db) p->db->inst.dirty = TRUE;
+    gnc_price_set_dirty(p);
     gnc_price_commit_edit (p);
   }
 }
@@ -269,7 +284,7 @@
     tmp = gnc_string_cache_insert((gpointer) type);
     if(p->type) gnc_string_cache_remove(p->type);
     p->type = tmp;
-    if(p->db) p->db->inst.dirty = TRUE;
+    gnc_price_set_dirty(p);
     gnc_price_commit_edit (p);
   }
 }
@@ -282,7 +297,7 @@
   {
     gnc_price_begin_edit (p);
     p->value = value;
-    if(p->db) p->db->inst.dirty = TRUE;
+    gnc_price_set_dirty(p);
     gnc_price_commit_edit (p);
   }
 }
@@ -574,7 +589,7 @@
   return gnc_commodity_equiv (ca, cb);
 }
 
-GNCPriceDB *
+static GNCPriceDB *
 gnc_pricedb_create(QofBook * book)
 {
   GNCPriceDB * result;
@@ -676,6 +691,7 @@
 GNCPriceDB *
 gnc_collection_get_pricedb(QofCollection *col)
 {
+  if (!col) return NULL;
   return qof_collection_get_data (col);
 }
 
@@ -683,6 +699,7 @@
 gnc_pricedb_get_db(QofBook *book)
 {
   QofCollection *col;
+
   if (!book) return NULL;
   col = qof_book_get_collection (book, GNC_ID_PRICEDB);
   return gnc_collection_get_pricedb (col);
@@ -862,13 +879,9 @@
 	  return FALSE;
   }
 
-  /* If we haven't been able to call the backend before, call it now */
-  if (TRUE == p->inst.dirty)
-  {
-    gnc_price_begin_edit(p);
-    db->inst.dirty = TRUE;
-    gnc_price_commit_edit(p);
-  }
+  gnc_pricedb_begin_edit(db);
+  qof_instance_set_dirty(&db->inst);
+  gnc_pricedb_commit_edit(db);
 
   LEAVE ("db=%p, pr=%p dirty=%d do-free=%d",
          db, p, p->inst.dirty, p->inst.do_free);
@@ -948,13 +961,14 @@
 
   gnc_price_ref(p);
   rc = remove_price (db, p, TRUE);
+  gnc_pricedb_begin_edit(db);
+  qof_instance_set_dirty(&db->inst);
+  gnc_pricedb_commit_edit(db);
 
   /* invoke the backend to delete this price */
   gnc_price_begin_edit (p);
-  db->inst.dirty = TRUE;
   p->inst.do_free = TRUE;
   gnc_price_commit_edit (p);
-
   p->db = NULL;
   gnc_price_unref(p);
   LEAVE ("db=%p, pr=%p", db, p);
@@ -2113,25 +2127,29 @@
 static void
 pricedb_book_begin (QofBook *book)
 {
-  gnc_pricedb_create(book);
+  GNCPriceDB *db;
+
+  db = gnc_pricedb_create(book);
 }
 
 static void
 pricedb_book_end (QofBook *book)
 {
-  /* ????? */
-}
+  GNCPriceDB *db;
+  QofCollection *col;
 
-static gboolean
-pricedb_is_dirty (QofCollection *col)
-{
-  return gnc_pricedb_dirty(gnc_collection_get_pricedb(col));
+  if (!book)
+    return;
+  col = qof_book_get_collection(book, GNC_ID_PRICEDB);
+  db = qof_collection_get_data(col);
+  qof_collection_set_data(col, NULL);
+  gnc_pricedb_destroy(db);
 }
 
-static void
-pricedb_mark_clean(QofCollection *col)
+static gpointer
+price_create (QofBook *book)
 {
-  gnc_pricedb_mark_clean(gnc_collection_get_pricedb(col));
+  return gnc_price_create(book);
 }
 
 /* ==================================================================== */
@@ -2183,9 +2201,11 @@
 }
 
 static void
-pricedb_foreach(QofCollection *col, QofEntityForeachCB cb, gpointer data)
+price_foreach(QofCollection *col, QofEntityForeachCB cb, gpointer data)
 {
-  GNCPriceDB *db = gnc_collection_get_pricedb(col);
+  GNCPriceDB *db;
+
+  db = qof_collection_get_data(col);
   void_unstable_price_traversal(db,
                        (void (*)(GNCPrice *, gpointer)) cb,
                        data);
@@ -2194,7 +2214,7 @@
 /* ==================================================================== */
 
 static const char *
-pricedb_printable(gpointer obj)
+price_printable(gpointer obj)
 {
   GNCPrice *pr = obj;
   gnc_commodity *commodity;
@@ -2219,18 +2239,33 @@
   return buff;
 }
 
-static QofObject pricedb_object_def =
+static QofObject price_object_def =
 {
   interface_version: QOF_OBJECT_VERSION,
   e_type:            GNC_ID_PRICE,
   type_label:        "Price",
-  create:            (gpointer)gnc_price_create,
+  create:            price_create,
+  book_begin:        NULL,
+  book_end:          NULL,
+  is_dirty:          qof_collection_is_dirty,
+  mark_clean:        qof_collection_mark_clean,
+  foreach:           price_foreach,
+  printable:         price_printable,
+  version_cmp:       NULL,
+};
+
+static QofObject pricedb_object_def =
+{
+  interface_version: QOF_OBJECT_VERSION,
+  e_type:            GNC_ID_PRICEDB,
+  type_label:        "PriceDB",
+  create:            NULL,
   book_begin:        pricedb_book_begin,
   book_end:          pricedb_book_end,
-  is_dirty:          pricedb_is_dirty,
-  mark_clean:        pricedb_mark_clean,
-  foreach:           pricedb_foreach,
-  printable:         pricedb_printable,
+  is_dirty:          qof_collection_is_dirty,
+  mark_clean:        qof_collection_mark_clean,
+  foreach:           NULL,
+  printable:         NULL,
   version_cmp:       NULL,
 };
 
@@ -2249,6 +2284,8 @@
 
   qof_class_register (GNC_ID_PRICE, NULL, params);
 
+  if (!qof_object_register (&price_object_def))
+    return FALSE;
   return qof_object_register (&pricedb_object_def);
 }
 

Modified: gnucash/trunk/src/engine/gnc-pricedb.h
===================================================================
--- gnucash/trunk/src/engine/gnc-pricedb.h	2005-11-26 22:47:32 UTC (rev 12055)
+++ gnucash/trunk/src/engine/gnc-pricedb.h	2005-11-28 03:25:43 UTC (rev 12056)
@@ -245,10 +245,6 @@
 /** Data type */
 typedef struct gnc_price_db_s GNCPriceDB;
 
-/** gnc_pricedb_create - create a new pricedb.  Normally you won't need
-     this; you will get the pricedb via gnc_pricedb_get_db. */
-GNCPriceDB * gnc_pricedb_create(QofBook *book);
-
 /* XXX backwards-compat defines, remove these someday */
 #define gnc_book_get_pricedb  gnc_pricedb_get_db
 
@@ -381,10 +377,6 @@
                                        gpointer user_data,
                                        gboolean stable_order);
 
-/** gnc_pricedb_dirty - return FALSE if the database has not been
-   modified. */
-#define gnc_pricedb_dirty(db) qof_instance_is_dirty(QOF_INSTANCE(db))
-
 /** gnc_pricedb_get_num_prices - return the number of prices
    in the database. */
 guint gnc_pricedb_get_num_prices(GNCPriceDB *db);



More information about the gnucash-changes mailing list