diff --git a/libgnucash/app-utils/CMakeLists.txt b/libgnucash/app-utils/CMakeLists.txt index 0f05e930a8..e384adb2c0 100644 --- a/libgnucash/app-utils/CMakeLists.txt +++ b/libgnucash/app-utils/CMakeLists.txt @@ -92,6 +92,7 @@ set(app_utils_ALL_LIBRARIES gnc-engine gnc-locale-tax gnucash-guile + ${GLIB_LDFLAGS} ${GIO_LDFLAGS} ${LIBXML2_LDFLAGS} ${LIBXSLT_LDFLAGS} diff --git a/libgnucash/app-utils/gnc-option-impl.cpp b/libgnucash/app-utils/gnc-option-impl.cpp index 7ab4584132..d561ba6655 100644 --- a/libgnucash/app-utils/gnc-option-impl.cpp +++ b/libgnucash/app-utils/gnc-option-impl.cpp @@ -48,6 +48,24 @@ GncOptionAccountValue::validate(const GncOptionAccountList& values) const return true; } +/** + * Create a GList of account types to pass to gnc_account_sel_set_acct_filters. + * gnc_account_sel_set_acct_filters copies the list so the intermediary caller + * is responsible for freeing the list. + * + * @return an allocated GList* or nullptr if the list is empty. + */ +GList* +GncOptionAccountValue::account_type_list() const noexcept +{ + if (m_allowed.empty()) + return nullptr; + GList* retval; + for (auto type : m_allowed) + retval = g_list_prepend(retval, GINT_TO_POINTER(type)); + return g_list_reverse(retval); +} + static constexpr int days_in_month[12]{31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}; static void diff --git a/libgnucash/app-utils/gnc-option-impl.hpp b/libgnucash/app-utils/gnc-option-impl.hpp index 700efaa343..5d221011a5 100644 --- a/libgnucash/app-utils/gnc-option-impl.hpp +++ b/libgnucash/app-utils/gnc-option-impl.hpp @@ -584,6 +584,7 @@ public: //throw! m_value = values; } + GList* account_type_list() const noexcept; bool is_changed() const noexcept { return m_value != m_default_value; } GncOptionUIType get_ui_type() const noexcept { return m_ui_type; } void make_internal() { m_ui_type = GncOptionUIType::INTERNAL; } diff --git a/libgnucash/app-utils/gnc-option.cpp b/libgnucash/app-utils/gnc-option.cpp index 4bedeb4a2a..a833fdab33 100644 --- a/libgnucash/app-utils/gnc-option.cpp +++ b/libgnucash/app-utils/gnc-option.cpp @@ -256,6 +256,18 @@ GncOption::permissible_value_description(std::size_t index) const }, *m_option); } +GList* +GncOption::account_type_list() const noexcept +{ + return std::visit([] (const auto& option) -> GList* { + if constexpr (std::is_same_v, + GncOptionAccountValue>) + return option.account_type_list(); + else + return nullptr; + }, *m_option); +} + std::ostream& GncOption::out_stream(std::ostream& oss) const { diff --git a/libgnucash/app-utils/gnc-option.hpp b/libgnucash/app-utils/gnc-option.hpp index 8a990e3ba4..548690dbb2 100644 --- a/libgnucash/app-utils/gnc-option.hpp +++ b/libgnucash/app-utils/gnc-option.hpp @@ -24,6 +24,11 @@ #ifndef GNC_OPTION_HPP_ #define GNC_OPTION_HPP_ +extern "C" +{ +#include +} + #include #include #include @@ -86,6 +91,7 @@ public: const std::string& permissible_value(std::size_t index) const; const std::string& permissible_value_name(std::size_t index) const; const std::string& permissible_value_description(std::size_t index) const; + GList* account_type_list() const noexcept; std::ostream& out_stream(std::ostream& oss) const; std::istream& in_stream(std::istream& iss); std::ostream& to_scheme(std::ostream& oss) const;