From 03a11451bd88debe666e2e79ed47cbd8de324787 Mon Sep 17 00:00:00 2001 From: Robert Fewell <14uBobIT@gmail.com> Date: Mon, 28 Nov 2016 19:39:10 +0000 Subject: [PATCH] Add the ability to delete a path from options There is a requirement to delete the "Fancy Date Format" book KVP data when set to unset. This was not possible as is as it would delete all the 'Business' options. This is still possible by passing a null list. --- src/engine/engine.i | 2 +- src/libqof/qof/qofbook.cpp | 12 ++++++++++-- src/libqof/qof/qofbook.h | 3 ++- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/engine/engine.i b/src/engine/engine.i index 48ab368c97..551ddfe594 100644 --- a/src/engine/engine.i +++ b/src/engine/engine.i @@ -247,7 +247,7 @@ Account * gnc_book_get_template_root(QofBook *book); %typemap(out) KvpValue * " $result = gnc_kvp_value_ptr_to_scm($1); " %typemap(in) GSList *key_path " $1 = gnc_scm_to_gslist_string($input);" -void qof_book_options_delete (QofBook *book); +void qof_book_options_delete (QofBook *book, GSList *key_path); void qof_book_set_option (QofBook *book, KvpValue *new_value, GSList *key_path); KvpValue* qof_book_get_option (QofBook *book, GSList *key_path); diff --git a/src/libqof/qof/qofbook.cpp b/src/libqof/qof/qofbook.cpp index 270fc8b045..09707d8516 100644 --- a/src/libqof/qof/qofbook.cpp +++ b/src/libqof/qof/qofbook.cpp @@ -1202,10 +1202,18 @@ qof_book_get_option (QofBook *book, GSList *path) } void -qof_book_options_delete (QofBook *book) +qof_book_options_delete (QofBook *book, GSList *path) { KvpFrame *root = qof_instance_get_slots(QOF_INSTANCE (book)); - delete root->set_path(KVP_OPTION_PATH, nullptr); + if (path != nullptr) + { + Path path_v {KVP_OPTION_PATH}; + for (auto item = path; item != nullptr; item = g_slist_next(item)) + path_v.push_back(static_cast(item->data)); + delete root->set_path(path_v, nullptr); + } + else + delete root->set_path(KVP_OPTION_PATH, nullptr); } /* QofObject function implementation and registration */ diff --git a/src/libqof/qof/qofbook.h b/src/libqof/qof/qofbook.h index 547f6b3b5b..aecd9e7583 100644 --- a/src/libqof/qof/qofbook.h +++ b/src/libqof/qof/qofbook.h @@ -409,8 +409,9 @@ KvpValue* qof_book_get_option (QofBook *book, GSList *path); * Primarily used from Scheme to clear out the options before saving a new set. * @param book: The book. * @param list: A GList of keys which from a path under KVP_OPTION_PATH. + * If GList is Null, the whole option is deleted. */ -void qof_book_options_delete (QofBook *book); +void qof_book_options_delete (QofBook *book, GSList *path); /** @} End of Doxygen Include */ /** deprecated */ #define qof_book_get_guid(X) qof_entity_get_guid (QOF_INSTANCE(X))