gnucash maint: Multiple changes pushed

Christopher Lam clam at code.gnucash.org
Sat Oct 29 10:24:21 EDT 2022


Updated	 via  https://github.com/Gnucash/gnucash/commit/f2354d6b (commit)
	 via  https://github.com/Gnucash/gnucash/commit/1516bb18 (commit)
	 via  https://github.com/Gnucash/gnucash/commit/a078921a (commit)
	from  https://github.com/Gnucash/gnucash/commit/cf088f2a (commit)



commit f2354d6b2af329c5cc849fc9d7908884c4b7fdc2
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Sat Oct 29 13:47:33 2022 +0800

    [test-qofbook.c] add test for gnc_features_set_unused

diff --git a/libgnucash/engine/test/test-qofbook.c b/libgnucash/engine/test/test-qofbook.c
index a771c3d5e..4c6fe444e 100644
--- a/libgnucash/engine/test/test-qofbook.c
+++ b/libgnucash/engine/test/test-qofbook.c
@@ -782,6 +782,10 @@ test_book_features (Fixture *fixture, gconstpointer pData)
     g_assert_null (gnc_features_test_unknown (fixture->book));
     g_assert_true (gnc_features_check_used (fixture->book, "Credit Notes"));
 
+    gnc_features_set_unused (fixture->book, "Credit Notes");
+    g_assert_null (gnc_features_test_unknown (fixture->book));
+    g_assert_false (gnc_features_check_used (fixture->book, "Credit Notes"));
+
     /* cannot set an unknown feature: it bails out. */
     /* gnc_features_set_used (fixture->book, "Nanotech"); */
     /* g_assert_nonnull (gnc_features_test_unknown (fixture->book)); */

commit 1516bb18b070d6fbc0388791edb8cb1040ad0d6e
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu Dec 2 22:12:29 2021 +0800

    [gnc-features.cpp] backport gnc_features_set_unused from master

diff --git a/libgnucash/engine/gnc-features.cpp b/libgnucash/engine/gnc-features.cpp
index 5e2823a3c..07d3e59fe 100644
--- a/libgnucash/engine/gnc-features.cpp
+++ b/libgnucash/engine/gnc-features.cpp
@@ -91,6 +91,23 @@ void gnc_features_set_used (QofBook *book, const gchar *feature)
     qof_book_set_feature (book, feature, iter->second.c_str());
 }
 
+
+void gnc_features_set_unused (QofBook *book, const gchar *feature)
+{
+    g_return_if_fail (book);
+    g_return_if_fail (feature);
+
+    /* Can't set an unknown feature */
+    auto iter = features_table.find (feature);
+    if (iter == features_table.end ())
+    {
+        PWARN("Tried to set unknown feature as unused.");
+        return;
+    }
+
+    qof_book_unset_feature (book, feature);
+}
+
 gboolean gnc_features_check_used (QofBook *book, const gchar * feature)
 {
     return qof_book_test_feature (book, feature);
diff --git a/libgnucash/engine/gnc-features.h b/libgnucash/engine/gnc-features.h
index 030c02531..b5960ac7a 100644
--- a/libgnucash/engine/gnc-features.h
+++ b/libgnucash/engine/gnc-features.h
@@ -67,6 +67,13 @@ extern "C" {
  */
 gchar *gnc_features_test_unknown (QofBook *book);
 
+/**
+ * Indicate that the current book does not use the given feature. This
+ * will allow older versions of GnuCash that don't support this
+ * feature to load this book.
+ */
+void gnc_features_set_unused (QofBook *book, const gchar *feature);
+
 /**
  * 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

commit a078921a33e3ea1e2f3427565fe8d348205b3f6a
Author: Christopher Lam <christopher.lck at gmail.com>
Date:   Thu Dec 2 22:12:12 2021 +0800

    [qofbook.cpp] backport qof_book_unset_feature from master

diff --git a/libgnucash/engine/qofbook.cpp b/libgnucash/engine/qofbook.cpp
index cbed9cb2d..d963aa18c 100644
--- a/libgnucash/engine/qofbook.cpp
+++ b/libgnucash/engine/qofbook.cpp
@@ -1285,6 +1285,22 @@ qof_book_test_feature (QofBook *book, const char *feature)
     return (frame->get_slot({GNC_FEATURES, feature}) != nullptr);
 }
 
+void
+qof_book_unset_feature (QofBook *book, const gchar *key)
+{
+    KvpFrame *frame = qof_instance_get_slots (QOF_INSTANCE (book));
+    auto feature_slot = frame->get_slot({GNC_FEATURES, key});
+    if (!feature_slot)
+    {
+        PWARN ("no feature %s. bail out.", key);
+        return;
+    }
+    qof_book_begin_edit (book);
+    delete frame->set_path({GNC_FEATURES, key}, nullptr);
+    qof_instance_set_dirty (QOF_INSTANCE (book));
+    qof_book_commit_edit (book);
+}
+
 void
 qof_book_load_options (QofBook *book, GNCOptionLoad load_cb, GNCOptionDB *odb)
 {
diff --git a/libgnucash/engine/qofbook.h b/libgnucash/engine/qofbook.h
index fbaf8a020..47104bbf4 100644
--- a/libgnucash/engine/qofbook.h
+++ b/libgnucash/engine/qofbook.h
@@ -382,6 +382,7 @@ void qof_book_option_frame_delete (QofBook *book, const char* opt_name);
 /** Access functions for reading and setting the used-features on this book.
  */
 GHashTable *qof_book_get_features (QofBook *book);
+void qof_book_unset_feature (QofBook *book, const gchar *key);
 void qof_book_set_feature (QofBook *book, const gchar *key, const gchar *descr);
 
 void qof_book_begin_edit(QofBook *book);



Summary of changes:
 libgnucash/engine/gnc-features.cpp    | 17 +++++++++++++++++
 libgnucash/engine/gnc-features.h      |  7 +++++++
 libgnucash/engine/qofbook.cpp         | 16 ++++++++++++++++
 libgnucash/engine/qofbook.h           |  1 +
 libgnucash/engine/test/test-qofbook.c |  4 ++++
 5 files changed, 45 insertions(+)



More information about the gnucash-changes mailing list