mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Move features hash creation to QofBook
So that the KVP stays private.
This commit is contained in:
parent
48df2d3569
commit
11aae5b2b9
@ -66,10 +66,12 @@ static void gnc_features_init ()
|
|||||||
g_strdup (known_features[i].desc));
|
g_strdup (known_features[i].desc));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void gnc_features_test_one(const gchar *key, KvpValue *value, gpointer data)
|
static void gnc_features_test_one(gpointer pkey, gpointer value,
|
||||||
|
gpointer data)
|
||||||
{
|
{
|
||||||
|
const gchar *key = (const gchar*)pkey;
|
||||||
|
const gchar *feature_desc = (const gchar*)value;
|
||||||
GList **unknown_features;
|
GList **unknown_features;
|
||||||
gchar *feature_desc;
|
|
||||||
|
|
||||||
g_assert(data);
|
g_assert(data);
|
||||||
unknown_features = (GList**) data;
|
unknown_features = (GList**) data;
|
||||||
@ -79,42 +81,36 @@ static void gnc_features_test_one(const gchar *key, KvpValue *value, gpointer da
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
/* It is unknown, so add the description to the unknown features list: */
|
/* It is unknown, so add the description to the unknown features list: */
|
||||||
feature_desc = kvp_value_get_string(value);
|
|
||||||
g_assert(feature_desc);
|
g_assert(feature_desc);
|
||||||
|
|
||||||
*unknown_features = g_list_prepend(*unknown_features, feature_desc);
|
*unknown_features = g_list_prepend(*unknown_features,
|
||||||
|
(gpointer)feature_desc);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Check if the session requires features unknown to this version of GnuCash.
|
/* 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 *gnc_features_test_unknown (QofBook *book)
|
gchar *gnc_features_test_unknown (QofBook *book)
|
||||||
{
|
{
|
||||||
KvpFrame *frame = qof_book_get_slots (book);
|
|
||||||
KvpValue *value;
|
|
||||||
|
|
||||||
/* Setup the known_features hash table */
|
/* Setup the known_features hash table */
|
||||||
gnc_features_init();
|
gnc_features_init();
|
||||||
|
|
||||||
g_assert(frame);
|
|
||||||
value = kvp_frame_get_value(frame, "features");
|
|
||||||
|
|
||||||
if (value)
|
|
||||||
{
|
|
||||||
GList* features_list = NULL;
|
GList* features_list = NULL;
|
||||||
frame = kvp_value_get_frame(value);
|
GHashTable *features_used = qof_book_get_features (book);
|
||||||
g_assert(frame);
|
|
||||||
|
|
||||||
/* Iterate over the members of this frame for unknown features */
|
/* Iterate over the members of this frame for unknown features */
|
||||||
kvp_frame_for_each_slot(frame, &gnc_features_test_one, &features_list);
|
g_hash_table_foreach (features_used, &gnc_features_test_one,
|
||||||
|
&features_list);
|
||||||
if (features_list)
|
if (features_list)
|
||||||
{
|
{
|
||||||
GList *i;
|
GList *i;
|
||||||
char* msg = g_strdup(
|
char* msg = g_strdup(_("This Dataset contains features not supported "
|
||||||
_("This Dataset contains features not supported by this "
|
"by this version of GnuCash. You must use a "
|
||||||
"version of GnuCash. You must use a newer version of "
|
"newer version of GnuCash in order to support "
|
||||||
"GnuCash in order to support the following features:"
|
"the following features:"
|
||||||
));
|
));
|
||||||
|
|
||||||
for (i = features_list; i; i = i->next)
|
for (i = features_list; i; i = i->next)
|
||||||
@ -127,16 +123,13 @@ gchar *gnc_features_test_unknown (QofBook *book)
|
|||||||
g_list_free(features_list);
|
g_list_free(features_list);
|
||||||
return msg;
|
return msg;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void gnc_features_set_used (QofBook *book, const gchar *feature)
|
void gnc_features_set_used (QofBook *book, const gchar *feature)
|
||||||
{
|
{
|
||||||
KvpFrame *frame;
|
|
||||||
const gchar *description;
|
const gchar *description;
|
||||||
gchar *kvp_path;
|
|
||||||
|
|
||||||
g_return_if_fail (book);
|
g_return_if_fail (book);
|
||||||
g_return_if_fail (feature);
|
g_return_if_fail (feature);
|
||||||
@ -151,10 +144,7 @@ void gnc_features_set_used (QofBook *book, const gchar *feature)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
frame = qof_book_get_slots (book);
|
qof_book_set_feature (book, feature, description);
|
||||||
kvp_path = g_strconcat ("/features/", feature, NULL);
|
|
||||||
kvp_frame_set_string (frame, kvp_path, description);
|
|
||||||
qof_book_kvp_changed (book);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -742,6 +742,36 @@ static void commit_err (QofInstance *inst, QofBackendError errcode)
|
|||||||
// gnc_engine_signal_commit_error( errcode );
|
// gnc_engine_signal_commit_error( errcode );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define GNC_FEATURES "/features/"
|
||||||
|
static void
|
||||||
|
add_feature_to_hash (const gchar *key, KvpValue *value, gpointer user_data)
|
||||||
|
{
|
||||||
|
gchar *descr = kvp_value_get_string (value);
|
||||||
|
g_hash_table_insert (*(GHashTable**)user_data, (gchar*)key, descr);
|
||||||
|
}
|
||||||
|
|
||||||
|
GHashTable *
|
||||||
|
qof_book_get_features (QofBook *book)
|
||||||
|
{
|
||||||
|
KvpFrame *frame = qof_instance_get_slots (QOF_INSTANCE (book));
|
||||||
|
GHashTable *features = g_hash_table_new (g_str_hash, g_str_equal);
|
||||||
|
|
||||||
|
frame = kvp_frame_get_frame (frame, GNC_FEATURES);
|
||||||
|
kvp_frame_for_each_slot (frame, &add_feature_to_hash, &features);
|
||||||
|
return features;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
qof_book_set_feature (QofBook *book, const gchar *key, const gchar *descr)
|
||||||
|
{
|
||||||
|
KvpFrame *frame = qof_instance_get_slots (QOF_INSTANCE (book));
|
||||||
|
gchar *path = g_strconcat (GNC_FEATURES, key, NULL);
|
||||||
|
qof_book_begin_edit (book);
|
||||||
|
kvp_frame_set_string (frame, path, descr);
|
||||||
|
qof_instance_set_dirty (QOF_INSTANCE (book));
|
||||||
|
qof_book_commit_edit (book);
|
||||||
|
}
|
||||||
|
|
||||||
static void noop (QofInstance *inst) {}
|
static void noop (QofInstance *inst) {}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -337,6 +337,11 @@ gchar *qof_book_get_counter_format (const QofBook *book, const char *counter_nam
|
|||||||
const char* qof_book_get_string_option(const QofBook* book, const char* opt_name);
|
const char* qof_book_get_string_option(const QofBook* book, const char* opt_name);
|
||||||
void qof_book_set_string_option(QofBook* book, const char* opt_name, const char* opt_val);
|
void qof_book_set_string_option(QofBook* book, const char* opt_name, const char* opt_val);
|
||||||
|
|
||||||
|
/** Access functions for reading and setting the used-features on this book.
|
||||||
|
*/
|
||||||
|
GHashTable *qof_book_get_features (QofBook *book);
|
||||||
|
void qof_book_set_feature (QofBook *book, const gchar *key, const gchar *descr);
|
||||||
|
|
||||||
void qof_book_begin_edit(QofBook *book);
|
void qof_book_begin_edit(QofBook *book);
|
||||||
void qof_book_commit_edit(QofBook *book);
|
void qof_book_commit_edit(QofBook *book);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user