From 538910f00b2346b66ccc1262a37b9904b10ac3f5 Mon Sep 17 00:00:00 2001 From: Derek Atkins Date: Tue, 20 Dec 2011 21:12:22 +0000 Subject: [PATCH] Add a "features" table to the KVP frame, and pop up an error message if we find a feature we don't know about. Currently there are no known features, so essentially we will error out if we see anything. The format for the slots table is: Book Slots -> features (frame) -> (string) -> ... The feature description is printed to the user: it should be stored in the slots table in English but it should be defined as a translatable string. BP git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21767 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/gnome-utils/gnc-file.c | 77 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/src/gnome-utils/gnc-file.c b/src/gnome-utils/gnc-file.c index 1d46f70d0d..2c3a474f6c 100644 --- a/src/gnome-utils/gnc-file.c +++ b/src/gnome-utils/gnc-file.c @@ -607,6 +607,77 @@ gnc_file_query_save (gboolean can_cancel) return TRUE; } + + +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 @@ -902,6 +973,12 @@ RESTART: uh_oh = show_session_error (ERR_BACKEND_MISC, newfile, GNC_FILE_DIALOG_OPEN); } + + /* test for unknown features. */ + if (!uh_oh) + { + uh_oh = test_unknown_features(new_session); + } } gnc_unset_busy_cursor (NULL);