r21979 - gnucash/branches/2.4 - [21978] Move the features tests to its own source files.
Geert Janssens
gjanssens at code.gnucash.org
Thu Feb 9 12:47:33 EST 2012
Author: gjanssens
Date: 2012-02-09 12:47:32 -0500 (Thu, 09 Feb 2012)
New Revision: 21979
Trac: http://svn.gnucash.org/trac/changeset/21979
Added:
gnucash/branches/2.4/src/app-utils/gnc-features.c
gnucash/branches/2.4/src/app-utils/gnc-features.h
Modified:
gnucash/branches/2.4/po/POTFILES.in
gnucash/branches/2.4/src/app-utils/Makefile.am
gnucash/branches/2.4/src/gnome-utils/gnc-file.c
Log:
[21978] 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
Modified: gnucash/branches/2.4/po/POTFILES.in
===================================================================
--- gnucash/branches/2.4/po/POTFILES.in 2012-02-09 17:17:59 UTC (rev 21978)
+++ gnucash/branches/2.4/po/POTFILES.in 2012-02-09 17:47:32 UTC (rev 21979)
@@ -18,6 +18,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
Modified: gnucash/branches/2.4/src/app-utils/Makefile.am
===================================================================
--- gnucash/branches/2.4/src/app-utils/Makefile.am 2012-02-09 17:17:59 UTC (rev 21978)
+++ gnucash/branches/2.4/src/app-utils/Makefile.am 2012-02-09 17:47:32 UTC (rev 21979)
@@ -54,6 +54,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 \
@@ -84,6 +85,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/branches/2.4/src/app-utils/gnc-features.c
===================================================================
--- gnucash/branches/2.4/src/app-utils/gnc-features.c (rev 0)
+++ gnucash/branches/2.4/src/app-utils/gnc-features.c 2012-02-09 17:47:32 UTC (rev 21979)
@@ -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/branches/2.4/src/app-utils/gnc-features.h
===================================================================
--- gnucash/branches/2.4/src/app-utils/gnc-features.h (rev 0)
+++ gnucash/branches/2.4/src/app-utils/gnc-features.h 2012-02-09 17:47:32 UTC (rev 21979)
@@ -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/branches/2.4/src/gnome-utils/gnc-file.c
===================================================================
--- gnucash/branches/2.4/src/gnome-utils/gnc-file.c 2012-02-09 17:17:59 UTC (rev 21978)
+++ gnucash/branches/2.4/src/gnome-utils/gnc-file.c 2012-02-09 17:47:32 UTC (rev 21979)
@@ -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"
@@ -615,76 +616,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
@@ -963,10 +894,19 @@
GNC_FILE_DIALOG_OPEN);
}
- /* test for unknown features. */
- if (!uh_oh)
- {
- uh_oh = test_unknown_features(new_session);
+ /* test for unknown features. */
+ if (!uh_oh)
+ {
+ 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