From a078921a33e3ea1e2f3427565fe8d348205b3f6a Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Thu, 2 Dec 2021 22:12:12 +0800 Subject: [PATCH] [qofbook.cpp] backport qof_book_unset_feature from master --- libgnucash/engine/qofbook.cpp | 16 ++++++++++++++++ libgnucash/engine/qofbook.h | 1 + 2 files changed, 17 insertions(+) diff --git a/libgnucash/engine/qofbook.cpp b/libgnucash/engine/qofbook.cpp index cbed9cb2d5..d963aa18c9 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 fbaf8a0202..47104bbf4b 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);