gnucash maint: Bug 745101 - No warning when quitting with unsaved file

Geert Janssens gjanssens at code.gnucash.org
Thu Dec 10 12:45:07 EST 2015


Updated	 via  https://github.com/Gnucash/gnucash/commit/568bfa02 (commit)
	from  https://github.com/Gnucash/gnucash/commit/243bfd1e (commit)



commit 568bfa0282ca9c8d196f69df7dfa98982530214d
Author: Geert Janssens <janssens-geert at telenet.be>
Date:   Thu Dec 10 18:44:51 2015 +0100

    Bug 745101 - No warning when quitting with unsaved file
    
    Current workaround is to force-use a default backend on new sessions.
    This works pretty well as the backend to use is retested when a file
    is opened anyway, dropping the default backend. The default backend
    should be able to handle the case where no real file/db is specified yet.
    I think so far only the xml backend can do this, so I have chosen that one
    as default.
    
    For this to work I also had to prevent the python integration from querying
    the current root account at startup. This query does create a root account
    if it doesn't exist yet in the new session, triggering a dirty state. As
    a result gnucash would ask to save the new session right before loading the
    real file/db (the one that was open in the previous gnucash session).
    
    This will probably still happen when python is initialized with the 'noisy'
    flag (which is when --debug is set).

diff --git a/src/libqof/qof/qofsession.c b/src/libqof/qof/qofsession.c
index 76e085b..7d936c4 100644
--- a/src/libqof/qof/qofsession.c
+++ b/src/libqof/qof/qofsession.c
@@ -96,6 +96,12 @@ unregister_all_providers (void)
     }
 }
 
+#define DEFAULT_BACKEND "xml"
+
+static void
+qof_session_load_backend(QofSession * session, const char * access_method);
+
+
 /* ====================================================================== */
 
 void
@@ -258,6 +264,7 @@ qof_session_init (QofSession *session)
     session->backend = NULL;
     session->lock = 1;
 
+    qof_session_load_backend(session, DEFAULT_BACKEND);
     qof_session_clear_error (session);
 }
 
@@ -355,25 +362,34 @@ qof_session_load_backend(QofSession * session, const char * access_method)
         /* Does this provider handle the desired access method? */
         if (0 == g_ascii_strcasecmp (access_method, prov->access_method))
         {
-            /* More than one backend could provide this
-            access method, check file type compatibility. */
-            type_check = (gboolean (*)(const char*)) prov->check_data_type;
-            if (type_check)
+            /* If this is a completely new session (that is, not associated with a file or db yet)
+             * go for the default backend and skip further type checking.
+             * This should prevent unintended data loss when a user starts a new book without
+             * going via the hierarchy assistant.
+             * See https://bugzilla.gnome.org/show_bug.cgi?id=745101
+             */
+            if (session->book_id || (0 != g_ascii_strcasecmp (DEFAULT_BACKEND, prov->access_method)))
             {
-                prov_type = (type_check)(session->book_id);
-                if (!prov_type)
+                /* More than one backend could provide this
+                   access method, check file type compatibility. */
+                type_check = (gboolean (*)(const char*)) prov->check_data_type;
+                if (type_check)
+                {
+                    prov_type = (type_check)(session->book_id);
+                    if (!prov_type)
+                    {
+                        PINFO(" %s not usable", prov->provider_name);
+                        p = p->next;
+                        continue;
+                    }
+                }
+                PINFO (" selected %s", prov->provider_name);
+                if (NULL == prov->backend_new)
                 {
-                    PINFO(" %s not usable", prov->provider_name);
                     p = p->next;
                     continue;
                 }
             }
-            PINFO (" selected %s", prov->provider_name);
-            if (NULL == prov->backend_new)
-            {
-                p = p->next;
-                continue;
-            }
             /* Use the providers creation callback */
             session->backend = (*(prov->backend_new))();
             session->backend->provider = prov;
diff --git a/src/python/init.py b/src/python/init.py
index 59a49c1..da9c1a0 100644
--- a/src/python/init.py
+++ b/src/python/init.py
@@ -24,15 +24,13 @@ if noisy:
     print "test", sys.modules.keys()
     print "test2", dir(_sw_app_utils)
 
-root = _sw_app_utils.gnc_get_current_root_account()
+    root = _sw_app_utils.gnc_get_current_root_account()
 
-if noisy:
     print "test", dir(root), root.__class__
     print "test2", dir(gnucash_core_c)
 
-acct = Account(instance = root)
+    acct = Account(instance = root)
 
-if noisy:
     print "test3", dir(acct)
    #print acct.GetName()
    #print acct.GetBalance()



Summary of changes:
 src/libqof/qof/qofsession.c | 42 +++++++++++++++++++++++++++++-------------
 src/python/init.py          |  6 ++----
 2 files changed, 31 insertions(+), 17 deletions(-)



More information about the gnucash-changes mailing list