AUDIT: r21978 - gnucash/trunk - Move the features tests to its own source files.

Geert Janssens gjanssens at code.gnucash.org
Thu Feb 9 12:18:00 EST 2012


Author: gjanssens
Date: 2012-02-09 12:17:59 -0500 (Thu, 09 Feb 2012)
New Revision: 21978
Trac: http://svn.gnucash.org/trac/changeset/21978

Added:
   gnucash/trunk/src/app-utils/gnc-features.c
   gnucash/trunk/src/app-utils/gnc-features.h
Modified:
   gnucash/trunk/po/POTFILES.in
   gnucash/trunk/src/app-utils/Makefile.am
   gnucash/trunk/src/gnome-utils/gnc-file.c
Log:
Move the features tests to its own source files.
This allows for
- other engine consumers to use the features test as well (think
CuteCash, python bindings,...)
- a central point for developers to check for feature definitions
- a central point to manage all feature related code

BP

Modified: gnucash/trunk/po/POTFILES.in
===================================================================
--- gnucash/trunk/po/POTFILES.in	2012-02-09 01:49:49 UTC (rev 21977)
+++ gnucash/trunk/po/POTFILES.in	2012-02-09 17:17:59 UTC (rev 21978)
@@ -10,6 +10,7 @@
 src/app-utils/gnc-entry-quickfill.c
 src/app-utils/gnc-euro.c
 src/app-utils/gnc-exp-parser.c
+src/app-utils/gnc-features.c
 src/app-utils/gnc-gettext-util.c
 src/app-utils/gnc-helpers.c
 src/app-utils/gnc-help-utils.c
@@ -424,11 +425,12 @@
 src/libqof/qof/qofutil.c
 src/libqof/qof/qof-win32.c
 src/plugins/bi_import/dialog-bi-import.c
-src/plugins/bi_import/gtkbuilder/dialog-bi-import-gui.glade
+src/plugins/bi_import/dialog-bi-import-gui.c
+src/plugins/bi_import/dialog-bi-import-helper.c
+src/plugins/bi_import/glade/bi_import.glade
 src/plugins/bi_import/gncmod-bi-import.c
 src/plugins/bi_import/gnc-plugin-bi-import.c
-src/plugins/bi_import/dialog-bi-import-gui.c
-src/plugins/bi_import/dialog-bi-import-helper.c
+src/plugins/bi_import/gtkbuilder/dialog-bi-import-gui.glade
 src/python/gncmod-python.c
 src/register/ledger-core/gnc-ledger-display.c
 src/register/ledger-core/gncmod-ledger-core.c

Modified: gnucash/trunk/src/app-utils/Makefile.am
===================================================================
--- gnucash/trunk/src/app-utils/Makefile.am	2012-02-09 01:49:49 UTC (rev 21977)
+++ gnucash/trunk/src/app-utils/Makefile.am	2012-02-09 17:17:59 UTC (rev 21978)
@@ -47,6 +47,7 @@
   gnc-entry-quickfill.c \
   gnc-euro.c \
   gnc-exp-parser.c \
+  gnc-features.c \
   gnc-gettext-util.c \
   gnc-helpers.c \
   gnc-sx-instance-model.c \
@@ -70,6 +71,7 @@
   gnc-entry-quickfill.h \
   gnc-euro.h \
   gnc-exp-parser.h \
+  gnc-features.h \
   gnc-gettext-util.h \
   gnc-help-utils.h \
   gnc-helpers.h \

Added: gnucash/trunk/src/app-utils/gnc-features.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-features.c	                        (rev 0)
+++ gnucash/trunk/src/app-utils/gnc-features.c	2012-02-09 17:17:59 UTC (rev 21978)
@@ -0,0 +1,103 @@
+/********************************************************************\
+ * gnc-features.c -- manage GnuCash features table                  *
+ * Copyright (C) 2011 Derek Atkins <derek at ihtfp.com>                *
+ * Copyright (C) 2012 Geert Janssens <geert at kobaltwit.be>           *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, write to the Free Software      *
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.        *
+ *                                                                  *
+\********************************************************************/
+
+#include "config.h"
+
+#include <glib.h>
+#include <glib/gi18n.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <string.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include "gnc-engine.h"
+#include "gnc-features.h"
+
+/* This static indicates the debugging module that this .o belongs to.  */
+static QofLogModule log_module = GNC_MOD_GUI;
+
+/********************************************************************\
+\********************************************************************/
+static void features_test(const gchar *key, KvpValue *value, gpointer data)
+{
+    GList** unknown_features = (GList**) data;
+    char* feature_desc;
+
+    g_assert(data);
+
+    /* XXX: test if 'key' is an unknown feature. */
+
+    /* Yes, it is unknown, so add the description to the list: */
+    feature_desc = kvp_value_get_string(value);
+    g_assert(feature_desc);
+
+    *unknown_features = g_list_prepend(*unknown_features, feature_desc);
+}
+
+/*
+ * Right now this is done by a KVP check for a features table.
+ * Currently we don't know about any features, so the mere
+ * existence of this KVP frame means we have a problem and
+ * need to tell the user.
+ *
+ * returns a message to display if we found unknown features, NULL if we're okay.
+ */
+gchar *test_unknown_features(QofSession* new_session)
+{
+    KvpFrame *frame = qof_book_get_slots (qof_session_get_book (new_session));
+    KvpValue *value;
+
+    g_assert(frame);
+    value = kvp_frame_get_value(frame, "features");
+
+    if (value)
+    {
+        GList* features_list = NULL;
+        frame = kvp_value_get_frame(value);
+        g_assert(frame);
+
+        /* Iterate over the members of this frame for unknown features */
+        kvp_frame_for_each_slot(frame, &features_test, &features_list);
+        if (features_list)
+        {
+            GList *i;
+            char* msg = g_strdup(
+                            _("This Dataset contains features not supported by this "
+                              "version of GnuCash.  You must use a newer version of "
+                              "GnuCash in order to support the following features:"
+                             ));
+
+            for (i = features_list; i; i = i->next)
+            {
+                char *tmp = g_strconcat(msg, "\n* ", _(i->data), NULL);
+                g_free (msg);
+                msg = tmp;
+            }
+
+            g_free(msg);
+            g_list_free(features_list);
+            return msg;
+        }
+    }
+
+    return NULL;
+}

Added: gnucash/trunk/src/app-utils/gnc-features.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-features.h	                        (rev 0)
+++ gnucash/trunk/src/app-utils/gnc-features.h	2012-02-09 17:17:59 UTC (rev 21978)
@@ -0,0 +1,50 @@
+/********************************************************************\
+ * gnc-features.h -- manage GnuCash features table                  *
+ * Copyright (C) 2011 Derek Atkins <derek at ihtfp.com>                *
+ * Copyright (C) 2012 Geert Janssens <geert at kobaltwit.be>           *
+ *                                                                  *
+ * This program is free software; you can redistribute it and/or    *
+ * modify it under the terms of the GNU General Public License as   *
+ * published by the Free Software Foundation; either version 2 of   *
+ * the License, or (at your option) any later version.              *
+ *                                                                  *
+ * This program is distributed in the hope that it will be useful,  *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of   *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    *
+ * GNU General Public License for more details.                     *
+ *                                                                  *
+ * You should have received a copy of the GNU General Public License*
+ * along with this program; if not, write to the Free Software      *
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.        *
+ *                                                                  *
+\********************************************************************/
+
+/** @addtogroup Utils Utility functions
+    @{ */
+/** @addtogroup UtilFeature Features
+ * @{ */
+/** @file gnc-features.h
+ *  @brief  Utility functions for file access
+ *  @author Copyright (C) 2011 Derek Atkins <derek at ihtfp.com>
+ *  @author Copyright (C) 2012 Geert Janssens <geert at kobaltwit.be>
+ *
+ *  These functions help you to manage features that GnuCash supports.
+ *  This is mainly used to prevent older GnuCash versions from opening
+ *  datasets with data they aren't capable of processing properly.
+ */
+
+#ifndef GNC_FEATURES_H
+#define GNC_FEATURES_H
+
+
+/**
+ * Test if the current session relies on features we don't know.
+ *
+ * Returns a message to display if we found unknown features, NULL if we're okay.
+ */
+gchar *test_unknown_features(QofSession* new_session);
+
+#endif /* GNC_FEATURES_H */
+/** @} */
+/** @} */
+

Modified: gnucash/trunk/src/gnome-utils/gnc-file.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-file.c	2012-02-09 01:49:49 UTC (rev 21977)
+++ gnucash/trunk/src/gnome-utils/gnc-file.c	2012-02-09 17:17:59 UTC (rev 21978)
@@ -34,6 +34,7 @@
 #include "gnc-engine.h"
 #include "Account.h"
 #include "gnc-file.h"
+#include "gnc-features.h"
 #include "gnc-filepath-utils.h"
 #include "gnc-gui-query.h"
 #include "gnc-hooks.h"
@@ -619,76 +620,6 @@
 }
 
 
-
-static void features_test(const gchar *key, KvpValue *value, gpointer data)
-{
-    GList** unknown_features = (GList**) data;
-    char* feature_desc;
-
-    g_assert(data);
-
-    /* XXX: test if 'key' is an unknown feature. */
-
-    /* Yes, it is unknown, so add the description to the list: */
-    feature_desc = kvp_value_get_string(value);
-    g_assert(feature_desc);
-
-    *unknown_features = g_list_prepend(*unknown_features, feature_desc);
-}
-
-/*
- * Right now this is done by a KVP check for a features table.
- * Currently we don't know about any features, so the mere
- * existence of this KVP frame means we have a problem and
- * need to tell the user.
- *
- * returns true if we found unknown features, false if we're okay.
- */
-static gboolean test_unknown_features(QofSession* new_session)
-{
-    KvpFrame *frame = qof_book_get_slots (qof_session_get_book (new_session));
-    KvpValue *value;
-
-    g_assert(frame);
-    value = kvp_frame_get_value(frame, "features");
-
-    if (value)
-    {
-        GList* features_list = NULL;
-        frame = kvp_value_get_frame(value);
-        g_assert(frame);
-
-        /* Iterate over the members of this frame for unknown features */
-        kvp_frame_for_each_slot(frame, &features_test, &features_list);
-        if (features_list)
-        {
-            GList *i;
-            char* msg = g_strdup(
-                            _("This Dataset contains features not supported by this "
-                              "version of GnuCash.  You must use a newer version of "
-                              "GnuCash in order to support the following features:"
-                             ));
-
-            for (i = features_list; i; i = i->next)
-            {
-                char *tmp = g_strconcat(msg, "\n* ", _(i->data), NULL);
-                g_free (msg);
-                msg = tmp;
-            }
-
-            // XXX: should pull out the file name here */
-            gnc_error_dialog(gnc_ui_get_toplevel(), msg, "");
-
-            g_free(msg);
-            g_list_free(features_list);
-            return TRUE;
-        }
-    }
-
-    return FALSE;
-}
-
-
 /* private utilities for file open; done in two stages */
 
 #define RESPONSE_NEW  1
@@ -988,7 +919,16 @@
         /* test for unknown features. */
         if (!uh_oh)
         {
-            uh_oh = test_unknown_features(new_session);
+            gchar *msg = test_unknown_features(new_session);
+
+            if (msg)
+            {
+                uh_oh = TRUE;
+
+                // XXX: should pull out the file name here */
+                gnc_error_dialog(gnc_ui_get_toplevel(), msg, "");
+                g_free (msg);
+            }
         }
     }
 



More information about the gnucash-changes mailing list