[Gnucash-changes] r13928 - gnucash/trunk - Add begin_edit/commit_edit brackets around object modifications. Some

David Hampton hampton at cvs.gnucash.org
Sat May 6 02:14:22 EDT 2006


Author: hampton
Date: 2006-05-06 02:14:21 -0400 (Sat, 06 May 2006)
New Revision: 13928
Trac: http://svn.gnucash.org/trac/changeset/13928

Modified:
   gnucash/trunk/ChangeLog
   gnucash/trunk/src/engine/Account.c
   gnucash/trunk/src/engine/SchedXaction.c
   gnucash/trunk/src/engine/SchedXaction.h
   gnucash/trunk/src/engine/gnc-commodity.c
   gnucash/trunk/src/engine/gnc-commodity.h
   gnucash/trunk/src/engine/gnc-lot.c
   gnucash/trunk/src/engine/gnc-lot.h
   gnucash/trunk/src/engine/gnc-pricedb.c
   gnucash/trunk/src/gnome-utils/dialog-commodity.c
Log:
Add begin_edit/commit_edit brackets around object modifications.  Some
other related edit changes.  Bug #339943 should be fixed as of this
change.


Modified: gnucash/trunk/ChangeLog
===================================================================
--- gnucash/trunk/ChangeLog	2006-05-06 06:03:48 UTC (rev 13927)
+++ gnucash/trunk/ChangeLog	2006-05-06 06:14:21 UTC (rev 13928)
@@ -1,5 +1,21 @@
 2006-05-06  David Hampton  <hampton at employees.org>
 
+	* src/gnome-utils/dialog-commodity.c:
+	* src/engine/gnc-lot.[ch]:
+	* src/engine/gnc-commodity.[ch]:
+	* src/engine/SchedXaction.[ch]: Add begin_edit/commit_edit
+	brackets around object modifications.  Bug #339943 should be fixed
+	as of this change.
+
+	* src/engine/gnc-pricedb.c: No longer need special handling when
+	marking prices as dirty.
+
+	* src/engine/Account.c: Remove redundant setting an account dirty.
+	Set collection clean/dirty functions.
+
+	* src/engine/gnc-engine.c: Unconditionally enable qof alternate
+	dirty mode.
+
 	* lib/libqof/qof/qofbook.[ch]:
 	* lib/libqof/qof/qofid-p.h:
 	* lib/libqof/qof/qofinstance.[ch]:

Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c	2006-05-06 06:03:48 UTC (rev 13927)
+++ gnucash/trunk/src/engine/Account.c	2006-05-06 06:14:21 UTC (rev 13928)
@@ -1245,7 +1245,6 @@
   kvp_frame_set_slot_nc(acc->inst.kvp_data, "old-currency",
                         kvp_value_new_string(string));
   mark_account (acc);
-  qof_instance_set_dirty(&acc->inst);
   xaccAccountCommitEdit(acc);
 
   commodity = DxaccAccountGetCurrency (acc);
@@ -2657,8 +2656,8 @@
   create:                (gpointer)xaccMallocAccount,
   book_begin:            NULL,
   book_end:              NULL,
-  is_dirty:              NULL,
-  mark_clean:            NULL,
+  is_dirty:              qof_collection_is_dirty,
+  mark_clean:            qof_collection_mark_clean,
   foreach:               qof_collection_foreach,
   printable:             (const char* (*)(gpointer)) xaccAccountGetName,
   version_cmp:           (int (*)(gpointer,gpointer)) qof_instance_version_cmp,

Modified: gnucash/trunk/src/engine/SchedXaction.c
===================================================================
--- gnucash/trunk/src/engine/SchedXaction.c	2006-05-06 06:03:48 UTC (rev 13927)
+++ gnucash/trunk/src/engine/SchedXaction.c	2006-05-06 06:14:21 UTC (rev 13928)
@@ -181,6 +181,28 @@
 
 /* ============================================================ */
 
+void
+gnc_sx_begin_edit (SchedXaction *sx)
+{
+  qof_begin_edit (&sx->inst);
+}
+
+static inline void commit_err (QofInstance *inst, QofBackendError errcode)
+{
+  PERR ("Failed to commit: %d", errcode);
+}
+
+static inline void noop (QofInstance *inst) {}
+
+void
+gnc_sx_commit_edit (SchedXaction *sx)
+{
+  if (!qof_commit_edit (QOF_INSTANCE(sx))) return;
+  qof_commit_edit_part2 (&sx->inst, commit_err, noop, noop);
+}
+
+/* ============================================================ */
+
 FreqSpec *
 xaccSchedXactionGetFreqSpec( SchedXaction *sx )
 {
@@ -192,9 +214,11 @@
 {
    g_return_if_fail( fs );
 
+   gnc_sx_begin_edit(sx);
    xaccFreqSpecFree( sx->freq );
    sx->freq = fs;
    qof_instance_set_dirty(&sx->inst);
+   gnc_sx_commit_edit(sx);
 }
 
 gchar *
@@ -207,12 +231,14 @@
 xaccSchedXactionSetName( SchedXaction *sx, const gchar *newName )
 {
    g_return_if_fail( newName != NULL );
+   gnc_sx_begin_edit(sx);
    if ( sx->name != NULL ) {
            g_free( sx->name );
            sx->name = NULL;
    }
    sx->name = g_strdup( newName );
    qof_instance_set_dirty(&sx->inst);
+   gnc_sx_commit_edit(sx);
 }
 
 GDate*
@@ -224,8 +250,10 @@
 void
 xaccSchedXactionSetStartDate( SchedXaction *sx, GDate* newStart )
 {
+   gnc_sx_begin_edit(sx);
    sx->start_date = *newStart;
    qof_instance_set_dirty(&sx->inst);
+   gnc_sx_commit_edit(sx);
 }
 
 gboolean
@@ -254,8 +282,10 @@
     return;
   }
 
+  gnc_sx_begin_edit(sx);
   sx->end_date = *newEnd;
   qof_instance_set_dirty(&sx->inst);
+  gnc_sx_commit_edit(sx);
 }
 
 GDate*
@@ -267,8 +297,10 @@
 void
 xaccSchedXactionSetLastOccurDate( SchedXaction *sx, GDate* newLastOccur )
 {
+  gnc_sx_begin_edit(sx);
   sx->last_date = *newLastOccur;
   qof_instance_set_dirty(&sx->inst);
+  gnc_sx_commit_edit(sx);
 }
 
 gboolean
@@ -286,8 +318,10 @@
 void
 xaccSchedXactionSetNumOccur( SchedXaction *sx, gint newNum )
 {
+  gnc_sx_begin_edit(sx);
   sx->num_occurances_remain = sx->num_occurances_total = newNum;
   qof_instance_set_dirty(&sx->inst);
+  gnc_sx_commit_edit(sx);
 }
 
 gint
@@ -307,8 +341,10 @@
   }
   else
   {
+    gnc_sx_begin_edit(sx);
     sx->num_occurances_remain = numRemain;
     qof_instance_set_dirty(&sx->inst);
+    gnc_sx_commit_edit(sx);
   }
 }
 
@@ -328,8 +364,10 @@
 {
   if (!sx) return;
 
+  gnc_sx_begin_edit(sx);
   kvp_frame_set_slot( sx->inst.kvp_data, slot, value );
   qof_instance_set_dirty(&sx->inst);
+  gnc_sx_commit_edit(sx);
 }
 
 void
@@ -348,9 +386,11 @@
                                gboolean newNotify )
 {
  
+  gnc_sx_begin_edit(sx);
   sx->autoCreateOption = newAutoCreate;
   sx->autoCreateNotify = newNotify; 
   qof_instance_set_dirty(&sx->inst);
+  gnc_sx_commit_edit(sx);
   return;
 }
 
@@ -363,8 +403,10 @@
 void
 xaccSchedXactionSetAdvanceCreation( SchedXaction *sx, gint createDays )
 {
+  gnc_sx_begin_edit(sx);
   sx->advanceCreateDays = createDays;
   qof_instance_set_dirty(&sx->inst);
+  gnc_sx_commit_edit(sx);
 }
 
 gint
@@ -376,8 +418,10 @@
 void
 xaccSchedXactionSetAdvanceReminder( SchedXaction *sx, gint reminderDays )
 {
+  gnc_sx_begin_edit(sx);
   sx->advanceRemindDays = reminderDays;
   qof_instance_set_dirty(&sx->inst);
+  gnc_sx_commit_edit(sx);
 }
 
 
@@ -657,10 +701,12 @@
 gnc_sx_revert_to_temporal_state( SchedXaction *sx, void *stateData )
 {
    temporalStateData *tsd = (temporalStateData*)stateData;
+   gnc_sx_begin_edit(sx);
    sx->last_date        = tsd->last_date;
    sx->num_occurances_remain = tsd->num_occur_rem;
    sx->instance_num     = tsd->num_inst;
    qof_instance_set_dirty(&sx->inst);
+   gnc_sx_commit_edit(sx);
 }
 
 void
@@ -738,8 +784,8 @@
 	create            : (gpointer)xaccSchedXactionMalloc,
 	book_begin        : NULL,
 	book_end          : NULL,
-	is_dirty          : NULL,
-	mark_clean        : NULL,
+	is_dirty          : qof_collection_is_dirty,
+	mark_clean        : qof_collection_mark_clean,
 	foreach           : qof_collection_foreach,
 	printable         : NULL,
 	version_cmp       : (int (*)(gpointer, gpointer)) qof_instance_version_cmp,

Modified: gnucash/trunk/src/engine/SchedXaction.h
===================================================================
--- gnucash/trunk/src/engine/SchedXaction.h	2006-05-06 06:03:48 UTC (rev 13927)
+++ gnucash/trunk/src/engine/SchedXaction.h	2006-05-06 06:14:21 UTC (rev 13928)
@@ -57,6 +57,9 @@
 */
 void xaccSchedXactionFree( SchedXaction *sx );
 
+void gnc_sx_begin_edit (SchedXaction *sx);
+void gnc_sx_commit_edit (SchedXaction *sx);
+
 FreqSpec *xaccSchedXactionGetFreqSpec( SchedXaction *sx );
 /**
  * The FreqSpec is given to the SchedXaction for mem mgmt; it should

Modified: gnucash/trunk/src/engine/gnc-commodity.c
===================================================================
--- gnucash/trunk/src/engine/gnc-commodity.c	2006-05-06 06:03:48 UTC (rev 13927)
+++ gnucash/trunk/src/engine/gnc-commodity.c	2006-05-06 06:14:21 UTC (rev 13928)
@@ -468,6 +468,30 @@
 }
 
 /********************************************************************
+ * QoF Helpers
+ ********************************************************************/
+
+void
+gnc_commodity_begin_edit (gnc_commodity *cm)
+{
+  qof_begin_edit(&cm->inst);
+}
+
+static inline void commit_err (QofInstance *inst, QofBackendError errcode)
+{
+  PERR ("Failed to commit: %d", errcode);
+}
+
+static inline void noop (QofInstance *inst) {}
+
+void
+gnc_commodity_commit_edit (gnc_commodity *cm)
+{
+  if (!qof_commit_edit (QOF_INSTANCE(cm))) return;
+  qof_commit_edit_part2 (&cm->inst, commit_err, noop, noop);
+}
+
+/********************************************************************
  * gnc_commodity_new
  ********************************************************************/
 
@@ -775,12 +799,14 @@
   if(!cm) return;
   if(cm->mnemonic == mnemonic) return;
 
+  gnc_commodity_begin_edit(cm);
   CACHE_REMOVE (cm->mnemonic);
   cm->mnemonic = CACHE_INSERT(mnemonic);
 
   mark_commodity_dirty (cm);
   reset_printname(cm);
   reset_unique_name(cm);
+  gnc_commodity_commit_edit(cm);
 }
 
 /********************************************************************
@@ -801,12 +827,14 @@
   if (cm->namespace == nsp)
     return;
 
+  gnc_commodity_begin_edit(cm);
   cm->namespace = nsp;
   if (nsp->iso4217)
     cm->quote_source = gnc_quote_source_lookup_by_internal("currency");
   mark_commodity_dirty(cm);
   reset_printname(cm);
   reset_unique_name(cm);
+  gnc_commodity_commit_edit(cm);
 }
 
 /********************************************************************
@@ -822,8 +850,10 @@
   CACHE_REMOVE (cm->fullname);
   cm->fullname = CACHE_INSERT (fullname);
 
+  gnc_commodity_begin_edit(cm);
   mark_commodity_dirty(cm);
   reset_printname(cm);
+  gnc_commodity_commit_edit(cm);
 }
 
 /********************************************************************
@@ -837,9 +867,11 @@
   if(!cm) return;
   if(cm->cusip == cusip) return;
 
+  gnc_commodity_begin_edit(cm);
   CACHE_REMOVE (cm->cusip);
   cm->cusip = CACHE_INSERT (cusip);
   mark_commodity_dirty(cm);
+  gnc_commodity_commit_edit(cm);
 }
 
 /********************************************************************
@@ -850,8 +882,10 @@
 gnc_commodity_set_fraction(gnc_commodity * cm, int fraction) 
 {
   if(!cm) return;
+  gnc_commodity_begin_edit(cm);
   cm->fraction = fraction;
   mark_commodity_dirty(cm);
+  gnc_commodity_commit_edit(cm);
 }
 
 /********************************************************************
@@ -875,8 +909,10 @@
   ENTER ("(cm=%p, flag=%d)", cm, flag);
 
   if(!cm) return;
+  gnc_commodity_begin_edit(cm);
   cm->quote_flag = flag;
   mark_commodity_dirty(cm);
+  gnc_commodity_commit_edit(cm);
   LEAVE(" ");
 }
 
@@ -890,8 +926,10 @@
   ENTER ("(cm=%p, src=%p(%s))", cm, src, src ? src->internal_name : "unknown");
 
   if(!cm) return;
+  gnc_commodity_begin_edit(cm);
   cm->quote_source = src;
   mark_commodity_dirty(cm);
+  gnc_commodity_commit_edit(cm);
   LEAVE(" ");
 }
 
@@ -906,10 +944,11 @@
 
   if(!cm || tz == cm->quote_tz) return;
 
+  gnc_commodity_begin_edit(cm);
   CACHE_REMOVE (cm->quote_tz);
   cm->quote_tz = CACHE_INSERT (tz);
-
   mark_commodity_dirty(cm);
+  gnc_commodity_commit_edit(cm);
   LEAVE(" ");
 }
 
@@ -1802,8 +1841,8 @@
   create:            NULL,
   book_begin:        commodity_table_book_begin,
   book_end:          commodity_table_book_end,
-  is_dirty:          NULL,
-  mark_clean:        NULL,
+  is_dirty:          qof_collection_is_dirty,
+  mark_clean:        qof_collection_mark_clean,
   foreach:           NULL,
   printable:         NULL,
   version_cmp:       NULL,

Modified: gnucash/trunk/src/engine/gnc-commodity.h
===================================================================
--- gnucash/trunk/src/engine/gnc-commodity.h	2006-05-06 06:03:48 UTC (rev 13927)
+++ gnucash/trunk/src/engine/gnc-commodity.h	2006-05-06 06:14:21 UTC (rev 13928)
@@ -881,6 +881,9 @@
  * commodity table.
  */
 gboolean gnc_commodity_table_register (void);
+
+void gnc_commodity_begin_edit (gnc_commodity *cm);
+void gnc_commodity_commit_edit (gnc_commodity *cm);
 		  
 /** @} */
 

Modified: gnucash/trunk/src/engine/gnc-lot.c
===================================================================
--- gnucash/trunk/src/engine/gnc-lot.c	2006-05-06 06:03:48 UTC (rev 13927)
+++ gnucash/trunk/src/engine/gnc-lot.c	2006-05-06 06:14:21 UTC (rev 13928)
@@ -101,6 +101,28 @@
 
 /* ============================================================= */
 
+void
+gnc_lot_begin_edit (GNCLot *lot)
+{
+  qof_begin_edit(&lot->inst);
+}
+
+static inline void commit_err (QofInstance *inst, QofBackendError errcode)
+{
+  PERR ("Failed to commit: %d", errcode);
+}
+
+static inline void noop (QofInstance *inst) {}
+
+void
+gnc_lot_commit_edit (GNCLot *lot)
+{
+  if (!qof_commit_edit (QOF_INSTANCE(lot))) return;
+  qof_commit_edit_part2 (&lot->inst, commit_err, noop, noop);
+}
+
+/* ============================================================= */
+
 GNCLot *
 gnc_lot_lookup (const GUID *guid, QofBook *book)
 {
@@ -173,16 +195,20 @@
 gnc_lot_set_title (GNCLot *lot, const char *str)
 {
    if (!lot) return;
+   qof_begin_edit(QOF_INSTANCE(lot));
    qof_instance_set_dirty(QOF_INSTANCE(lot));
-   return kvp_frame_set_str (lot->inst.kvp_data, "/title", str);
+   kvp_frame_set_str (lot->inst.kvp_data, "/title", str);
+   gnc_lot_commit_edit(lot);
 }
 
 void
 gnc_lot_set_notes (GNCLot *lot, const char *str)
 {
    if (!lot) return;
+   gnc_lot_begin_edit(lot);
    qof_instance_set_dirty(QOF_INSTANCE(lot));
-   return kvp_frame_set_str (lot->inst.kvp_data, "/notes", str);
+   kvp_frame_set_str (lot->inst.kvp_data, "/notes", str);
+   gnc_lot_commit_edit(lot);
 }
 
 /* ============================================================= */
@@ -280,6 +306,7 @@
         gnc_lot_get_title (lot), 
         gnc_num_dbg_to_string (split->amount),
         gnc_num_dbg_to_string (split->value));
+   gnc_lot_begin_edit(lot);
    acc = xaccSplitGetAccount (split);
    qof_instance_set_dirty(QOF_INSTANCE(lot));
    if (NULL == lot->account)
@@ -292,10 +319,14 @@
             "be added to this lot!\n"
             "\tlot account=\'%s\', split account=\'%s\'\n",
             xaccAccountGetName(lot->account), xaccAccountGetName (acc));
+      gnc_lot_commit_edit(lot);
       return;
    }
 
-   if (lot == split->lot) return; /* handle not-uncommon no-op */
+   if (lot == split->lot) {
+        gnc_lot_commit_edit(lot);
+	return; /* handle not-uncommon no-op */
+   }
    if (split->lot)
    {
       gnc_lot_remove_split (split->lot, split);
@@ -306,6 +337,7 @@
 
     /* for recomputation of is-closed */
    lot->is_closed = -1;
+   gnc_lot_commit_edit(lot);
 
    qof_event_gen (&lot->inst.entity, QOF_EVENT_MODIFY, NULL);
 }
@@ -316,6 +348,7 @@
    if (!lot || !split) return;
 
    ENTER ("(lot=%p, split=%p)", lot, split);
+   gnc_lot_begin_edit(lot);
    qof_instance_set_dirty(QOF_INSTANCE(lot));
    lot->splits = g_list_remove (lot->splits, split);
    split->lot = NULL;
@@ -326,6 +359,7 @@
       xaccAccountRemoveLot (lot->account, lot);
       lot->account = NULL;
    }
+   gnc_lot_commit_edit(lot);
    qof_event_gen (&lot->inst.entity, QOF_EVENT_MODIFY, NULL);
 }
 

Modified: gnucash/trunk/src/engine/gnc-lot.h
===================================================================
--- gnucash/trunk/src/engine/gnc-lot.h	2006-05-06 06:03:48 UTC (rev 13927)
+++ gnucash/trunk/src/engine/gnc-lot.h	2006-05-06 06:14:21 UTC (rev 13928)
@@ -68,6 +68,9 @@
 GNCLot * gnc_lot_lookup (const GUID *guid, QofBook *book);
 QofBook * gnc_lot_get_book (GNCLot *);		  
 
+void gnc_lot_begin_edit (GNCLot *lot);
+void gnc_lot_commit_edit (GNCLot *lot);
+
 /** The gnc_lot_add_split() routine adds a split to this lot.  Note
  *    that *all* splits in a lot must also be in the same account.
  *    Note that this routine adds the split unconditionally, with

Modified: gnucash/trunk/src/engine/gnc-pricedb.c
===================================================================
--- gnucash/trunk/src/engine/gnc-pricedb.c	2006-05-06 06:03:48 UTC (rev 13927)
+++ gnucash/trunk/src/engine/gnc-pricedb.c	2006-05-06 06:14:21 UTC (rev 13928)
@@ -176,16 +176,7 @@
 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;
+  qof_instance_set_dirty(&p->inst);
 }
 
 void

Modified: gnucash/trunk/src/gnome-utils/dialog-commodity.c
===================================================================
--- gnucash/trunk/src/gnome-utils/dialog-commodity.c	2006-05-06 06:03:48 UTC (rev 13927)
+++ gnucash/trunk/src/gnome-utils/dialog-commodity.c	2006-05-06 06:14:21 UTC (rev 13928)
@@ -1171,11 +1171,13 @@
   if (gnc_commodity_namespace_is_iso (namespace)) {
     if (w->edit_commodity) {
       c = w->edit_commodity;
+      gnc_commodity_begin_edit(c);
       gnc_commodity_set_quote_flag (c, gtk_toggle_button_get_active
 				    (GTK_TOGGLE_BUTTON (w->get_quote_check)));
       selection = gnc_option_menu_get_active (w->quote_tz_menu);
       string = gnc_timezone_menu_position_to_string(selection);
       gnc_commodity_set_quote_tz(c, string);
+      gnc_commodity_commit_edit(c);
       return TRUE;
     }
     gnc_warning_dialog(w->dialog,
@@ -1198,9 +1200,10 @@
     if (!w->edit_commodity) {
       c = gnc_commodity_new(book, fullname, namespace, mnemonic, code, fraction);
       w->edit_commodity = c;
-    }
-    else {
+      gnc_commodity_begin_edit(c);
+    } else {
       c = w->edit_commodity;
+      gnc_commodity_begin_edit(c);
 
       gnc_commodity_table_remove (gnc_get_current_commodities(), c);
 
@@ -1225,6 +1228,7 @@
     selection = gnc_option_menu_get_active (w->quote_tz_menu);
     string = gnc_timezone_menu_position_to_string(selection);
     gnc_commodity_set_quote_tz(c, string);
+    gnc_commodity_commit_edit(c);
 
     /* remember the commodity */
     c = gnc_commodity_table_insert(gnc_get_current_commodities(), c);



More information about the gnucash-changes mailing list