r17667 - gnucash/trunk/src - Add a callback to gnc-engine which will be called when a qof commit

Phil Longstaff plongstaff at cvs.gnucash.org
Mon Oct 27 19:42:01 EDT 2008


Author: plongstaff
Date: 2008-10-27 19:42:01 -0400 (Mon, 27 Oct 2008)
New Revision: 17667
Trac: http://svn.gnucash.org/trac/changeset/17667

Modified:
   gnucash/trunk/src/engine/Account.c
   gnucash/trunk/src/engine/SchedXaction.c
   gnucash/trunk/src/engine/Split.c
   gnucash/trunk/src/engine/Transaction.c
   gnucash/trunk/src/engine/gnc-budget.c
   gnucash/trunk/src/engine/gnc-commodity.c
   gnucash/trunk/src/engine/gnc-engine.c
   gnucash/trunk/src/engine/gnc-engine.h
   gnucash/trunk/src/engine/gnc-lot.c
   gnucash/trunk/src/engine/gnc-pricedb.c
   gnucash/trunk/src/gnome-utils/gnc-main-window.c
Log:
Add a callback to gnc-engine which will be called when a qof commit 
fails.  Most engine objects catch the qof commit but then just log the 
problem to the trace log.  Now, the engine objects will invoke this 
callback.  gnc-main-window registers a callback and opens a dialog box 
to inform the user.  This is necessary because with an sql backend, 
commits happen whenever an object is created or modified, not just 
synchronously when the user selects to save the file.


Modified: gnucash/trunk/src/engine/Account.c
===================================================================
--- gnucash/trunk/src/engine/Account.c	2008-10-27 23:39:29 UTC (rev 17666)
+++ gnucash/trunk/src/engine/Account.c	2008-10-27 23:42:01 UTC (rev 17667)
@@ -1063,6 +1063,7 @@
 static void on_err (QofInstance *inst, QofBackendError errcode)
 {
   PERR("commit error: %d", errcode);
+  gnc_engine_signal_commit_error( errcode );
 }
 
 static void acc_free (QofInstance *inst)

Modified: gnucash/trunk/src/engine/SchedXaction.c
===================================================================
--- gnucash/trunk/src/engine/SchedXaction.c	2008-10-27 23:39:29 UTC (rev 17666)
+++ gnucash/trunk/src/engine/SchedXaction.c	2008-10-27 23:42:01 UTC (rev 17667)
@@ -219,6 +219,7 @@
 static void commit_err (QofInstance *inst, QofBackendError errcode)
 {
      g_critical("Failed to commit: %d", errcode);
+     gnc_engine_signal_commit_error( errcode );
 }
 
 static void commit_done(QofInstance *inst)

Modified: gnucash/trunk/src/engine/Split.c
===================================================================
--- gnucash/trunk/src/engine/Split.c	2008-10-27 23:39:29 UTC (rev 17666)
+++ gnucash/trunk/src/engine/Split.c	2008-10-27 23:42:01 UTC (rev 17667)
@@ -498,6 +498,12 @@
         xaccTransCommitEdit(trans);
 }
 
+static void commit_err (QofInstance *inst, QofBackendError errcode)
+{
+  PERR("commit error: %d", errcode);
+  gnc_engine_signal_commit_error( errcode );
+}
+
 /* An engine-private helper for completing xaccTransCommitEdit(). */
 void
 xaccSplitCommitEdit(Split *s)
@@ -551,7 +557,7 @@
        original and new transactions, for the _next_ begin/commit cycle. */
     s->orig_acc = s->acc;
     s->orig_parent = s->parent;
-    qof_commit_edit_part2(QOF_INSTANCE(s), NULL, NULL, 
+    qof_commit_edit_part2(QOF_INSTANCE(s), commit_err, NULL, 
                           (void (*) (QofInstance *)) xaccFreeSplit);
 
     if (acc) {

Modified: gnucash/trunk/src/engine/Transaction.c
===================================================================
--- gnucash/trunk/src/engine/Transaction.c	2008-10-27 23:39:29 UTC (rev 17666)
+++ gnucash/trunk/src/engine/Transaction.c	2008-10-27 23:42:01 UTC (rev 17667)
@@ -940,6 +940,7 @@
     }
 
     xaccTransRollbackEdit(trans);
+    gnc_engine_signal_commit_error( errcode );
 }
 
 static void trans_cleanup_commit(Transaction *trans)

Modified: gnucash/trunk/src/engine/gnc-budget.c
===================================================================
--- gnucash/trunk/src/engine/gnc-budget.c	2008-10-27 23:39:29 UTC (rev 17666)
+++ gnucash/trunk/src/engine/gnc-budget.c	2008-10-27 23:42:01 UTC (rev 17667)
@@ -232,6 +232,7 @@
 static void commit_err (QofInstance *inst, QofBackendError errcode)
 {
   PERR ("Failed to commit: %d", errcode);
+  gnc_engine_signal_commit_error( errcode );
 }
 
 static void

Modified: gnucash/trunk/src/engine/gnc-commodity.c
===================================================================
--- gnucash/trunk/src/engine/gnc-commodity.c	2008-10-27 23:39:29 UTC (rev 17666)
+++ gnucash/trunk/src/engine/gnc-commodity.c	2008-10-27 23:42:01 UTC (rev 17667)
@@ -519,6 +519,7 @@
 static void commit_err (QofInstance *inst, QofBackendError errcode)
 {
   PERR ("Failed to commit: %d", errcode);
+  gnc_engine_signal_commit_error( errcode );
 }
 
 static void noop (QofInstance *inst) {}

Modified: gnucash/trunk/src/engine/gnc-engine.c
===================================================================
--- gnucash/trunk/src/engine/gnc-engine.c	2008-10-27 23:39:29 UTC (rev 17666)
+++ gnucash/trunk/src/engine/gnc-engine.c	2008-10-27 23:42:01 UTC (rev 17667)
@@ -43,6 +43,10 @@
 
 static GList * engine_init_hooks = NULL;
 static int engine_is_initialized = 0;
+
+EngineCommitErrorCallback g_error_cb;
+gpointer g_error_cb_data;
+
 // static QofLogModule log_module = GNC_MOD_ENGINE;
 
 /* GnuCash version functions */
@@ -165,3 +169,17 @@
 	qof_log_set_level(GNC_MOD_TEST, QOF_LOG_DEBUG);
 }
 
+void
+gnc_engine_add_commit_error_callback( EngineCommitErrorCallback cb, gpointer data )
+{
+    g_error_cb = cb;
+    g_error_cb_data = data;
+}
+
+void
+gnc_engine_signal_commit_error( QofBackendError errcode )
+{
+    if( g_error_cb != NULL ) {
+	(*g_error_cb)( g_error_cb_data, errcode );
+    }
+}

Modified: gnucash/trunk/src/engine/gnc-engine.h
===================================================================
--- gnucash/trunk/src/engine/gnc-engine.h	2008-10-27 23:39:29 UTC (rev 17666)
+++ gnucash/trunk/src/engine/gnc-engine.h	2008-10-27 23:42:01 UTC (rev 17667)
@@ -208,6 +208,7 @@
 /** GList of GUIDs of a GNCBook */
 typedef GList                  BookGUIDList;
 
+typedef void (*EngineCommitErrorCallback)( gpointer data, QofBackendError errcode );
 
 typedef  gint (*SplitCallback)(Split *s, gpointer data);
 typedef  gint (*TransactionCallback)(Transaction *t, void *data);
@@ -244,5 +245,11 @@
  * it will be called during the evaluation of gnc_engine_init */
 void gnc_engine_add_init_hook(gnc_engine_init_hook_t hook);
 
+/** Set a callback function to be called in case an engine commit
+ * fails */
+void gnc_engine_add_commit_error_callback( EngineCommitErrorCallback cb, gpointer data );
+
+void gnc_engine_signal_commit_error( QofBackendError errcode );
+
 #endif
 /** @} */

Modified: gnucash/trunk/src/engine/gnc-lot.c
===================================================================
--- gnucash/trunk/src/engine/gnc-lot.c	2008-10-27 23:39:29 UTC (rev 17666)
+++ gnucash/trunk/src/engine/gnc-lot.c	2008-10-27 23:42:01 UTC (rev 17667)
@@ -143,6 +143,7 @@
 static void commit_err (QofInstance *inst, QofBackendError errcode)
 {
   PERR ("Failed to commit: %d", errcode);
+  gnc_engine_signal_commit_error( errcode );
 }
 
 static void lot_free(QofInstance* inst)

Modified: gnucash/trunk/src/engine/gnc-pricedb.c
===================================================================
--- gnucash/trunk/src/engine/gnc-pricedb.c	2008-10-27 23:39:29 UTC (rev 17666)
+++ gnucash/trunk/src/engine/gnc-pricedb.c	2008-10-27 23:42:01 UTC (rev 17667)
@@ -160,6 +160,7 @@
 static void commit_err (QofInstance *inst, QofBackendError errcode)
 {
   PERR ("Failed to commit: %d", errcode);
+  gnc_engine_signal_commit_error( errcode );
 }
 
 static void noop (QofInstance *inst) {}

Modified: gnucash/trunk/src/gnome-utils/gnc-main-window.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-main-window.c	2008-10-27 23:39:29 UTC (rev 17666)
+++ gnucash/trunk/src/gnome-utils/gnc-main-window.c	2008-10-27 23:42:01 UTC (rev 17667)
@@ -122,6 +122,7 @@
 #endif
 static void gnc_main_window_plugin_added (GncPlugin *manager, GncPlugin *plugin, GncMainWindow *window);
 static void gnc_main_window_plugin_removed (GncPlugin *manager, GncPlugin *plugin, GncMainWindow *window);
+static void gnc_main_window_engine_commit_error_callback( gpointer data, QofBackendError errcode );
 
 /* Command callbacks */
 #ifdef HAVE_GTK_2_10
@@ -2039,6 +2040,9 @@
     active_windows = g_list_append (active_windows, window);
     gnc_main_window_update_title(window);
     gnc_main_window_update_all_menu_items();
+
+    gnc_engine_add_commit_error_callback( gnc_main_window_engine_commit_error_callback, window );
+
     return window;
 }
 
@@ -2046,6 +2050,23 @@
  *                     Utility Functions                    *
  ************************************************************/
 
+static void
+gnc_main_window_engine_commit_error_callback( gpointer data,
+					QofBackendError errcode )
+{
+      GncMainWindow* window = GNC_MAIN_WINDOW(data);
+      GtkWidget* dialog;
+
+      dialog = gtk_message_dialog_new( GTK_WINDOW(window),
+                                       GTK_DIALOG_DESTROY_WITH_PARENT,
+                                       GTK_MESSAGE_ERROR,
+                                       GTK_BUTTONS_CLOSE,
+                                       "Unable to save to database" );
+      gtk_dialog_run(GTK_DIALOG (dialog));
+      gtk_widget_destroy(dialog);
+
+}
+
 /** Connect a GncPluginPage to the window.  This function will insert
  *  the page in to the window's notebook and its list of active pages.
  *  It will also emit the "inserted" signal on the page, and the



More information about the gnucash-changes mailing list