r21981 - gnucash/trunk - Add function to set a feature as used and use it for a first feature:
Geert Janssens
gjanssens at code.gnucash.org
Fri Feb 10 09:40:52 EST 2012
Author: gjanssens
Date: 2012-02-10 09:40:52 -0500 (Fri, 10 Feb 2012)
New Revision: 21981
Trac: http://svn.gnucash.org/trac/changeset/21981
Added:
gnucash/trunk/src/core-utils/gnc-features.c
gnucash/trunk/src/core-utils/gnc-features.h
Removed:
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/core-utils/Makefile.am
gnucash/trunk/src/engine/gncInvoice.c
gnucash/trunk/src/gnome-utils/gnc-file.c
Log:
Add function to set a feature as used and use it for a first feature:
Credit Notes.
Other changes in this commit:
* The feature code moved to core-utils, because the engine can't use
app-utils.
* I remove the gettext wrapper around the feature description. As
mentioned on the mailing list, by definition unknown features can't have
translated descriptions.
Modified: gnucash/trunk/po/POTFILES.in
===================================================================
--- gnucash/trunk/po/POTFILES.in 2012-02-10 09:19:47 UTC (rev 21980)
+++ gnucash/trunk/po/POTFILES.in 2012-02-10 14:40:52 UTC (rev 21981)
@@ -10,7 +10,6 @@
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
@@ -125,6 +124,7 @@
src/calculation/gncmod-calculation.c
src/calculation/numeric_ops.c
src/core-utils/binreloc.c
+src/core-utils/gnc-features.c
src/core-utils/gnc-filepath-utils.c
src/core-utils/gnc-gconf-utils.c
src/core-utils/gnc-gdate-utils.c
Modified: gnucash/trunk/src/app-utils/Makefile.am
===================================================================
--- gnucash/trunk/src/app-utils/Makefile.am 2012-02-10 09:19:47 UTC (rev 21980)
+++ gnucash/trunk/src/app-utils/Makefile.am 2012-02-10 14:40:52 UTC (rev 21981)
@@ -47,7 +47,6 @@
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 \
@@ -71,7 +70,6 @@
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 \
Deleted: gnucash/trunk/src/app-utils/gnc-features.c
===================================================================
--- gnucash/trunk/src/app-utils/gnc-features.c 2012-02-10 09:19:47 UTC (rev 21980)
+++ gnucash/trunk/src/app-utils/gnc-features.c 2012-02-10 14:40:52 UTC (rev 21981)
@@ -1,103 +0,0 @@
-/********************************************************************\
- * 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;
-}
Deleted: gnucash/trunk/src/app-utils/gnc-features.h
===================================================================
--- gnucash/trunk/src/app-utils/gnc-features.h 2012-02-10 09:19:47 UTC (rev 21980)
+++ gnucash/trunk/src/app-utils/gnc-features.h 2012-02-10 14:40:52 UTC (rev 21981)
@@ -1,50 +0,0 @@
-/********************************************************************\
- * 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/core-utils/Makefile.am
===================================================================
--- gnucash/trunk/src/core-utils/Makefile.am 2012-02-10 09:19:47 UTC (rev 21980)
+++ gnucash/trunk/src/core-utils/Makefile.am 2012-02-10 14:40:52 UTC (rev 21981)
@@ -4,6 +4,7 @@
libgnc_core_utils_la_SOURCES = \
binreloc.c \
+ gnc-features.c \
gnc-filepath-utils.c \
gnc-gconf-utils.c \
gnc-gdate-utils.c \
@@ -28,6 +29,7 @@
noinst_HEADERS = \
binreloc.h \
gnc-main.h \
+ gnc-features.h \
gnc-filepath-utils.h \
gnc-gconf-utils.h \
gnc-gdate-utils.h \
Copied: gnucash/trunk/src/core-utils/gnc-features.c (from rev 21980, gnucash/trunk/src/app-utils/gnc-features.c)
===================================================================
--- gnucash/trunk/src/core-utils/gnc-features.c (rev 0)
+++ gnucash/trunk/src/core-utils/gnc-features.c 2012-02-10 14:40:52 UTC (rev 21981)
@@ -0,0 +1,159 @@
+/********************************************************************\
+ * 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 "libqof/qof/qof.h"
+#include "gnc-features.h"
+
+typedef struct {
+ const gchar *key;
+ const gchar *desc;
+} gncFeature;
+
+static GHashTable *features_table = NULL;
+static gncFeature known_features[] =
+{
+ { GNC_FEATURE_CREDIT_NOTES, "Customer and vendor credit notes (requires at least GnuCash 2.5.0)" },
+ { NULL },
+};
+
+/* This static indicates the debugging module that this .o belongs to. */
+static QofLogModule log_module = G_LOG_DOMAIN;
+
+/********************************************************************\
+\********************************************************************/
+
+static void gnc_features_init ()
+{
+ gint i;
+
+ if (features_table)
+ return;
+
+ features_table = g_hash_table_new (g_str_hash, g_str_equal);
+ for (i = 0; known_features[i].key; i++)
+ g_hash_table_insert (features_table,
+ g_strdup (known_features[i].key),
+ g_strdup (known_features[i].desc));
+}
+
+static void gnc_features_test_one(const gchar *key, KvpValue *value, gpointer data)
+{
+ GList **unknown_features;
+ gchar *feature_desc;
+
+ g_assert(data);
+ unknown_features = (GList**) data;
+
+ /* Check if this feature is in the known features list. */
+ if (g_hash_table_lookup_extended (features_table, key, NULL, NULL))
+ return;
+
+ /* It is unknown, so add the description to the unknown features list: */
+ feature_desc = kvp_value_get_string(value);
+ g_assert(feature_desc);
+
+ *unknown_features = g_list_prepend(*unknown_features, feature_desc);
+}
+
+/* Check if the session requires features unknown to this version of GnuCash.
+ *
+ * Returns a message to display if we found unknown features, NULL if we're okay.
+ */
+gchar *gnc_features_test_unknown (QofBook *book)
+{
+ KvpFrame *frame = qof_book_get_slots (book);
+ KvpValue *value;
+
+ /* Setup the known_features hash table */
+ gnc_features_init();
+
+ 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, &gnc_features_test_one, &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;
+}
+
+void gnc_features_set_used (QofBook *book, const gchar *feature)
+{
+ KvpFrame *frame;
+ const gchar *description;
+ gchar *kvp_path;
+
+ g_return_if_fail (book);
+ g_return_if_fail (feature);
+
+ gnc_features_init();
+
+ /* Can't set an unknown feature */
+ description = g_hash_table_lookup (features_table, feature);
+ if (!description)
+ {
+ PWARN("Tried to set unknown feature as used.");
+ return;
+ }
+
+ frame = qof_book_get_slots (book);
+ kvp_path = g_strconcat ("/features/", feature, NULL);
+ kvp_frame_set_string (frame, kvp_path, description);
+ qof_book_kvp_changed (book);
+
+
+}
Copied: gnucash/trunk/src/core-utils/gnc-features.h (from rev 21980, gnucash/trunk/src/app-utils/gnc-features.h)
===================================================================
--- gnucash/trunk/src/core-utils/gnc-features.h (rev 0)
+++ gnucash/trunk/src/core-utils/gnc-features.h 2012-02-10 14:40:52 UTC (rev 21981)
@@ -0,0 +1,64 @@
+/********************************************************************\
+ * 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
+ * book with data they aren't capable of processing properly.
+ */
+
+#ifndef GNC_FEATURES_H
+#define GNC_FEATURES_H
+
+/** @name Defined features
+@{
+ */
+#define GNC_FEATURE_CREDIT_NOTES "Credit Notes"
+
+/** @} */
+
+/**
+ * Test if the current book relies on features only introduced in a more
+ * recent version of GnuCash.
+ *
+ * Returns a message to display if we found unknown features, NULL if we're okay.
+ */
+gchar *gnc_features_test_unknown (QofBook *book);
+
+/**
+ * Indicate that the current book uses the given feature. This will prevent
+ * older versions of GnuCash that don't support this feature to refuse to load
+ * this book.
+ */
+void gnc_features_set_used (QofBook *book, const gchar *feature);
+
+#endif /* GNC_FEATURES_H */
+/** @} */
+/** @} */
+
Modified: gnucash/trunk/src/engine/gncInvoice.c
===================================================================
--- gnucash/trunk/src/engine/gncInvoice.c 2012-02-10 09:19:47 UTC (rev 21980)
+++ gnucash/trunk/src/engine/gncInvoice.c 2012-02-10 14:40:52 UTC (rev 21981)
@@ -37,6 +37,7 @@
#include "gncBillTermP.h"
#include "gncEntry.h"
#include "gncEntryP.h"
+#include "gnc-features.h"
#include "gncJobP.h"
#include "gncInvoice.h"
#include "gncInvoiceP.h"
@@ -533,6 +534,12 @@
credit_note ? 1 : 0);
mark_invoice (invoice);
gncInvoiceCommitEdit (invoice);
+
+ /* If this is a credit note, set a feature flag for it in the book
+ * This will prevent older GnuCash versions that don't support
+ * credit notes to open this file. */
+ if (credit_note)
+ gnc_features_set_used (gncInvoiceGetBook (invoice), GNC_FEATURE_CREDIT_NOTES);
}
void gncInvoiceSetCurrency (GncInvoice *invoice, gnc_commodity *currency)
Modified: gnucash/trunk/src/gnome-utils/gnc-file.c
===================================================================
--- gnucash/trunk/src/gnome-utils/gnc-file.c 2012-02-10 09:19:47 UTC (rev 21980)
+++ gnucash/trunk/src/gnome-utils/gnc-file.c 2012-02-10 14:40:52 UTC (rev 21981)
@@ -919,7 +919,7 @@
/* test for unknown features. */
if (!uh_oh)
{
- gchar *msg = test_unknown_features(new_session);
+ gchar *msg = gnc_features_test_unknown(qof_session_get_book (new_session));
if (msg)
{
More information about the gnucash-changes
mailing list