mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
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. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@21981 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
f5a1d18d65
commit
6e5e7b3a5e
@ -10,7 +10,6 @@ src/app-utils/gnc-component-manager.c
|
||||
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/fin-main.c
|
||||
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
|
||||
|
@ -47,7 +47,6 @@ libgncmod_app_utils_la_SOURCES = \
|
||||
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 @@ gncinclude_HEADERS = \
|
||||
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 \
|
||||
|
@ -4,6 +4,7 @@ lib_LTLIBRARIES = libgnc-core-utils.la
|
||||
|
||||
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 @@ libgnc_core_utils_la_LIBADD = \
|
||||
noinst_HEADERS = \
|
||||
binreloc.h \
|
||||
gnc-main.h \
|
||||
gnc-features.h \
|
||||
gnc-filepath-utils.h \
|
||||
gnc-gconf-utils.h \
|
||||
gnc-gdate-utils.h \
|
||||
|
@ -29,43 +29,72 @@
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "gnc-engine.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 = GNC_MOD_GUI;
|
||||
static QofLogModule log_module = G_LOG_DOMAIN;
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
static void features_test(const gchar *key, KvpValue *value, gpointer data)
|
||||
|
||||
static void gnc_features_init ()
|
||||
{
|
||||
GList** unknown_features = (GList**) data;
|
||||
char* feature_desc;
|
||||
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;
|
||||
|
||||
/* XXX: test if 'key' is an unknown feature. */
|
||||
/* Check if this feature is in the known features list. */
|
||||
if (g_hash_table_lookup_extended (features_table, key, NULL, NULL))
|
||||
return;
|
||||
|
||||
/* Yes, it is unknown, so add the description to the list: */
|
||||
/* 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);
|
||||
}
|
||||
|
||||
/*
|
||||
* 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.
|
||||
/* 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.
|
||||
* Returns a message to display if we found unknown features, NULL if we're okay.
|
||||
*/
|
||||
gchar *test_unknown_features(QofSession* new_session)
|
||||
gchar *gnc_features_test_unknown (QofBook *book)
|
||||
{
|
||||
KvpFrame *frame = qof_book_get_slots (qof_session_get_book (new_session));
|
||||
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");
|
||||
|
||||
@ -76,7 +105,7 @@ gchar *test_unknown_features(QofSession* new_session)
|
||||
g_assert(frame);
|
||||
|
||||
/* Iterate over the members of this frame for unknown features */
|
||||
kvp_frame_for_each_slot(frame, &features_test, &features_list);
|
||||
kvp_frame_for_each_slot(frame, &gnc_features_test_one, &features_list);
|
||||
if (features_list)
|
||||
{
|
||||
GList *i;
|
||||
@ -88,7 +117,7 @@ gchar *test_unknown_features(QofSession* new_session)
|
||||
|
||||
for (i = features_list; i; i = i->next)
|
||||
{
|
||||
char *tmp = g_strconcat(msg, "\n* ", _(i->data), NULL);
|
||||
char *tmp = g_strconcat(msg, "\n* ", i->data, NULL);
|
||||
g_free (msg);
|
||||
msg = tmp;
|
||||
}
|
||||
@ -101,3 +130,30 @@ gchar *test_unknown_features(QofSession* new_session)
|
||||
|
||||
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);
|
||||
|
||||
|
||||
}
|
@ -30,19 +30,33 @@
|
||||
*
|
||||
* 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.
|
||||
* 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 session relies on features we don't know.
|
||||
* 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 *test_unknown_features(QofSession* new_session);
|
||||
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 */
|
||||
/** @} */
|
@ -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 @@ void gncInvoiceSetIsCreditNote (GncInvoice *invoice, gboolean credit_note)
|
||||
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)
|
||||
|
@ -919,7 +919,7 @@ RESTART:
|
||||
/* 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)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user