28 #include "kvp-value.hpp" 29 #include "qofbookslots.h" 34 #include "gnc-option-ui.hpp" 36 #include "gnc-session.h" 39 constexpr
auto stream_max = std::numeric_limits<std::streamsize>::max();
40 using AliasedOption = std::pair<const char*, const char*>;
41 using OptionAlias = std::pair<const char*, AliasedOption>;
42 using OptionAliases = std::vector<OptionAlias>;
45 static const OptionAliases c_option_aliases;
47 static const AliasedOption* find_alias (
const char* old_name)
49 if (!old_name)
return nullptr;
51 std::find_if(c_option_aliases.begin(), c_option_aliases.end(),
52 [old_name](
auto alias){
53 return std::strcmp(old_name, alias.first) == 0;
55 if (alias == c_option_aliases.end())
58 return &alias->second;
62 const OptionAliases Aliases::c_option_aliases
64 {
"Accounts to include", {
nullptr,
"Accounts"}},
65 {
"Exclude transactions between selected accounts?",
66 {
nullptr,
"Exclude transactions between selected accounts"}},
67 {
"Filter Accounts", {
nullptr,
"Filter By…"}},
68 {
"Flatten list to depth limit?",
69 {
nullptr,
"Flatten list to depth limit"}},
70 {
"From", {
nullptr,
"Start Date"}},
71 {
"Report Accounts", {
nullptr,
"Accounts"}},
72 {
"Report Currency", {
nullptr,
"Report's currency"}},
73 {
"Show Account Code?", {
nullptr,
"Show Account Code"}},
74 {
"Show Full Account Name?", {
nullptr,
"Show Full Account Name"}},
75 {
"Show Multi-currency Totals?",
76 {
nullptr,
"Show Multi-currency Totals"}},
77 {
"Show zero balance items?", {
nullptr,
"Show zero balance items"}},
78 {
"Sign Reverses?", {
nullptr,
"Sign Reverses"}},
79 {
"To", {
nullptr,
"End Date"}},
80 {
"Charge Type", {
nullptr,
"Action"}},
82 {
"Individual income columns", {
nullptr,
"Individual sales columns"}},
83 {
"Individual expense columns",
84 {
nullptr,
"Individual purchases columns"}},
85 {
"Remittance amount", {
nullptr,
"Gross Balance"}},
86 {
"Net Income", {
nullptr,
"Net Balance"}},
88 {
"Use Full Account Name?", {
nullptr,
"Use Full Account Name"}},
89 {
"Use Full Other Account Name?",
90 {
nullptr,
"Use Full Other Account Name"}},
91 {
"Void Transactions?", {
"Filter",
"Void Transactions"}},
92 {
"Void Transactions", {
"Filter",
"Void Transactions"}},
93 {
"Account Substring", {
"Filter",
"Account Name Filter"}},
94 {
"Enable links", {
nullptr,
"Enable Links"}},
96 {
"Common Currency", {
"Currency",
"Common Currency"}},
97 {
"Show original currency amount",
98 {
"Currency",
"Show original currency amount"}},
99 {
"Report's currency", {
"Currency",
"Report's currency"}},
100 {
"Reconcile Status", {
nullptr,
"Reconciled Status"}},
103 {
"Links", {
nullptr,
"Transaction Links"}},
105 {
"Individual Taxes", {
nullptr,
"Use Detailed Tax Summary"}},
106 {
"Show Accounts until level", {
nullptr,
"Levels of Subaccounts"}},
107 {
"Invoice number", {
nullptr,
"Invoice Number"}},
108 {
"Report title", {
nullptr,
"Report Title"}},
109 {
"Extra notes", {
nullptr,
"Extra Notes"}},
111 {
"default format", {
nullptr,
"Default Format"}},
112 {
"Report format", {
nullptr,
"Report Format"}},
114 {
"Filter By...", {
nullptr,
"Filter By…"}},
115 {
"Specify date to filter by...", {
nullptr,
"Specify date to filter by…"}},
119 operator==(
const std::string& str,
const char* cstr)
121 return strcmp(str.c_str(), cstr) == 0;
125 GncOptionSection::foreach_option(std::function<
void(
GncOption&)> func)
127 std::for_each(m_options.begin(), m_options.end(), func);
131 GncOptionSection::foreach_option(std::function<
void(
const GncOption&)> func)
const 133 std::for_each(m_options.begin(), m_options.end(), func);
137 GncOptionSection::add_option(
GncOption&& option)
139 m_options.push_back(std::move(option));
140 if (!std::is_sorted(m_options.begin(), m_options.end()))
141 std::sort(m_options.begin(), m_options.end());
145 GncOptionSection::remove_option(
const char* name)
147 m_options.erase(std::remove_if(m_options.begin(), m_options.end(),
148 [name](
const auto& option) ->
bool 150 return option.get_name() == name;
155 GncOptionSection::find_option(
const char* name)
const 157 auto option = std::find_if(m_options.begin(), m_options.end(),
158 [name](
auto& option) ->
bool {
159 return option.get_name() == name;
161 if (option != m_options.end())
164 auto alias = Aliases::find_alias(name);
165 if (!alias || alias->first)
167 return find_option(alias->second);
170 GncOptionDB::GncOptionDB() : m_default_section{} {}
172 GncOptionDB::GncOptionDB(QofBook* book) :
GncOptionDB() {}
175 GncOptionDB::register_option(
const char* sectname,
GncOption&& option)
177 auto section = find_section(sectname);
181 section->add_option(std::move(option));
185 m_sections.push_back(std::make_shared<GncOptionSection>(sectname));
186 m_sections.back()->add_option(std::move(option));
187 if (!std::is_sorted(m_sections.begin(), m_sections.end()))
188 std::sort(m_sections.begin(), m_sections.end());
192 GncOptionDB::register_option(
const char* sectname,
GncOption* option)
194 register_option(sectname, std::move(*option));
199 GncOptionDB::unregister_option(
const char* sectname,
const char* name)
201 auto section = find_section(sectname);
203 section->remove_option(name);
207 GncOptionDB::set_default_section(
const char* sectname)
209 m_default_section = find_section(sectname);
213 GncOptionDB::get_default_section() const noexcept
215 return m_default_section;
219 GncOptionDB::find_section(
const std::string& section)
const 221 auto db_section = std::find_if(m_sections.begin(), m_sections.end(),
222 [§ion](
auto& sect) ->
bool 224 return section == sect->get_name();
226 return db_section == m_sections.end() ? nullptr : db_section->get();
230 GncOptionDB::find_option(
const std::string& section,
const char* name)
const 232 auto db_section =
const_cast<GncOptionDB*
>(
this)->find_section(section);
235 option = db_section->find_option(name);
238 auto alias = Aliases::find_alias(name);
243 if (alias && alias->first && section != alias->first)
244 return find_option(alias->first, alias->second);
249 GncOptionDB::lookup_string_option(
const char* section,
const char* name)
251 static const std::string empty_string{};
253 auto db_opt = find_option(section, name);
256 return db_opt->get_value<std::string>();
260 GncOptionDB::make_internal(
const char* section,
const char* name)
263 auto db_opt = find_option(section, name);
265 db_opt->make_internal();
268 static inline bool constexpr
274 static inline bool constexpr
275 is_whitespace(
char c)
277 return c ==
' ' || c ==
'\n' || c ==
'\t';
280 static inline bool constexpr
281 is_begin_paren(
char c)
286 static inline bool constexpr
292 static inline bool constexpr
293 is_double_quote(
char c)
298 static inline bool constexpr
299 is_single_quote(
char c)
304 static inline bool constexpr
310 static inline bool constexpr
313 return is_begin_paren(c) || is_end_paren(c) || is_whitespace(c) ||
314 is_single_quote(c) || is_double_quote(c) || is_semicolon(c);
318 GncOptionDB::save_option_key_value(std::ostream& oss,
319 const std::string& section,
320 const std::string& name)
const noexcept
323 auto db_opt = find_option(section, name.c_str());
324 if (!db_opt || !db_opt->is_changed())
326 oss << section.substr(0, classifier_size_max) <<
":" <<
327 name.substr(0, classifier_size_max) <<
"=" << *db_opt <<
";";
332 GncOptionDB::load_option_key_value(std::istream& iss)
335 char section[classifier_size_max], name[classifier_size_max];
336 iss.getline(section, classifier_size_max,
':');
337 iss.getline(name, classifier_size_max,
'=');
339 throw std::invalid_argument(
"Section or name delimiter not found or values too long");
340 auto option = find_option(section, name);
342 iss.ignore(stream_max,
';');
346 std::getline(iss, value,
';');
347 std::istringstream item_iss{value};
354 GncOptionDB::save_to_key_value(std::ostream& oss)
const noexcept
358 [&oss](
const GncOptionSectionPtr& section)
360 oss <<
"[Options]\n";
361 section->foreach_option(
362 [&oss, §ion](
auto& option)
364 if (option.is_changed())
365 oss << section->get_name().substr(0, classifier_size_max) <<
366 ':' << option.get_name().substr(0, classifier_size_max) <<
367 '=' << option <<
'\n';
374 GncOptionDB::load_from_key_value(std::istream& iss)
376 if (iss.peek() ==
'[')
378 char buf[classifier_size_max];
379 iss.getline(buf, classifier_size_max);
380 if (strcmp(buf,
"[Options]") != 0)
381 throw std::runtime_error(
"Wrong secion header for options.");
384 while (iss.peek() !=
'[')
386 load_option_key_value(iss);
392 GncOptionDB::register_callback(GncOptionDBChangeCallback cb,
void* data)
394 constexpr std::hash<GncOptionDBChangeCallback> cb_hash;
395 auto id{cb_hash(cb)};
396 if (std::find_if(m_callbacks.begin(), m_callbacks.end(),
397 [id](
auto&cb)->
bool{
return cb.m_id == id; }) == m_callbacks.end())
398 m_callbacks.emplace_back(
id, cb, data);
403 GncOptionDB::unregister_callback(
size_t id)
405 std::remove_if(m_callbacks.begin(), m_callbacks.end(),
406 [id](
auto& cb)->
bool {
return cb.m_id == id; });
410 GncOptionDB::run_callbacks()
412 std::for_each(m_callbacks.begin(), m_callbacks.end(),
413 [](
auto& cb)->
void { cb.m_func(cb.m_data); });
417 counter_option_path(
const GncOption& option, GSList* list, std::string& name)
419 constexpr
const char* counters{
"counters"};
420 constexpr
const char* formats{
"counter_formats"};
421 auto key = option.get_key();
422 name = key.substr(0, key.size() - 1);
423 list->next->data = (
void*)name.c_str();
424 if (option.get_name().rfind(
"format")
425 != std::string::npos)
426 list->data = (
void*)formats;
428 list->data = (
void*)counters;
432 option_path(
const GncOption& option, GSList* list)
434 list->next->data = (
void*)option.get_name().c_str();
435 list->data = (
void*)option.get_section().c_str();
438 static inline KvpValue*
439 kvp_value_from_bool_option(
const GncOption& option)
441 auto val{option.template get_value<bool>()};
443 return new KvpValue(val ? g_strdup(
"t") : g_strdup(
"f"));
451 case GncOptionUIType::ACCOUNT_SEL:
452 case GncOptionUIType::BUDGET:
453 case GncOptionUIType::OWNER:
454 case GncOptionUIType::CUSTOMER:
455 case GncOptionUIType::VENDOR:
456 case GncOptionUIType::EMPLOYEE:
457 case GncOptionUIType::INVOICE:
458 case GncOptionUIType::TAX_TABLE:
459 case GncOptionUIType::QUERY:
466 static inline KvpValue*
467 kvp_value_from_qof_instance_option(
const GncOption& option)
469 const QofInstance* inst{QOF_INSTANCE(option.template get_value<const QofInstance*>())};
471 return new KvpValue(guid);
475 GncOptionDB::save_to_kvp(QofBook* book,
bool clear_options)
const noexcept
480 [book](GncOptionSectionPtr& section)
482 section->foreach_option(
483 [book, §ion](
auto& option) {
484 if (option.is_changed())
492 GSList list_tail{}, list_head{
nullptr, &list_tail};
493 if (strcmp(section->get_name().c_str(),
"Counters") == 0)
494 counter_option_path(option, &list_head, name);
496 option_path(option, &list_head);
497 auto type{option.get_ui_type()};
499 if (type == GncOptionUIType::BOOLEAN)
500 kvp = kvp_value_from_bool_option(option);
501 else if (is_qofinstance_ui_type(type))
502 kvp = kvp_value_from_qof_instance_option(option);
503 else if (type == GncOptionUIType::NUMBER_RANGE)
506 kvp =
new KvpValue(option.template get_value<double>());
508 kvp =
new KvpValue{g_strdup(option.template get_value<std::string>().c_str())};
516 fill_option_from_string_kvp(
GncOption& option, KvpValue* kvp)
518 auto str{kvp->get<
const char*>()};
519 if (option.get_ui_type() == GncOptionUIType::BOOLEAN)
520 option.set_value(*str ==
't' ?
true :
false);
522 option.set_value(std::string{str});
526 fill_option_from_guid_kvp(
GncOption& option, KvpValue* kvp)
528 auto guid{kvp->get<
GncGUID*>()};
530 (
const QofInstance*)qof_instance_from_guid(guid, option.get_ui_type()));
534 GncOptionDB::load_from_kvp(QofBook* book) noexcept
537 [book](GncOptionSectionPtr& section)
539 section->foreach_option(
546 GSList list_tail{}, list_head{
nullptr, &list_tail};
547 if (strcmp(section->get_name().c_str(),
"Counters") == 0)
548 counter_option_path(option, &list_head, name);
550 option_path(option, &list_head);
554 switch (kvp->get_type())
556 case KvpValue::Type::DOUBLE:
557 option.set_value(kvp->get<
double>());
559 case KvpValue::Type::INT64:
560 option.set_value(kvp->get<int64_t>());
562 case KvpValue::Type::STRING:
563 fill_option_from_string_kvp(option, kvp);
565 case KvpValue::Type::GUID:
566 fill_option_from_guid_kvp(option, kvp);
578 const char* name,
const char* key,
579 const char* doc_string, std::string value)
581 GncOption option{section, name, key, doc_string, value,
582 GncOptionUIType::STRING};
583 db->register_option(section, std::move(option));
588 const char* key,
const char* doc_string,
591 GncOption option{section, name, key, doc_string, value,
592 GncOptionUIType::TEXT};
593 db->register_option(section, std::move(option));
599 const char* name,
const char* key,
600 const char* doc_string, std::string value)
602 GncOption option{section, name, key, doc_string, value,
603 GncOptionUIType::FONT};
604 db->register_option(section, std::move(option));
609 const char* name,
const char* key,
610 const char* doc_string, GncBudget *value)
614 GncOptionUIType::BUDGET}};
615 db->register_option(section, std::move(option));
620 const char* name,
const char* key,
621 const char* doc_string, std::string value)
623 GncOption option{section, name, key, doc_string, value,
624 GncOptionUIType::COLOR};
625 db->register_option(section, std::move(option));
630 const char* name,
const char* key,
631 const char* doc_string, gnc_commodity *value)
635 GncOptionUIType::COMMODITY}};
636 db->register_option(section, std::move(option));
641 const char* name,
const char* key,
642 const char* doc_string,
const char* value)
644 gnc_commodity* commodity{};
648 for (
auto node = namespaces; node && commodity ==
nullptr;
649 node = g_list_next(node))
651 commodity = gnc_commodity_table_lookup(commodity_table,
652 (
const char*)(node->data),
659 GncOptionUIType::COMMODITY}};
660 db->register_option(section, std::move(option));
665 const char* section,
const char* name,
666 const char* key,
const char* doc_string,
669 GncOption option{section, name, key, doc_string, value,
670 GncOptionUIType::BOOLEAN};
671 db->register_option(section, std::move(option));
676 const char* name,
const char* key,
677 const char* doc_string, std::string value)
679 GncOption option{section, name, key, doc_string, value,
680 GncOptionUIType::PIXMAP};
681 db->register_option(section, std::move(option));
686 const char* name,
const char* key,
687 const char* doc_string,
688 const GncOptionAccountList& value)
691 GncOptionUIType::ACCOUNT_LIST, value}};
692 db->register_option(section, std::move(option));
697 const char* section,
const char* name,
699 const char* doc_string,
700 const GncOptionAccountList& value,
701 GncOptionAccountTypeList&& allowed)
706 GncOptionUIType::ACCOUNT_LIST, value, std::move(allowed)}};
707 db->register_option(section, std::move(option));
709 catch (
const std::invalid_argument& err)
711 PWARN(
"Account List Limited Option, value failed validation, option not registered.");
715 using AccountPair = std::pair<GncOptionAccountList&,
716 const GncOptionAccountTypeList&>;
718 find_children(
Account* account,
void* data)
722 GncOptionAccountList& list = datapair->first;
723 const GncOptionAccountTypeList& types = datapair->second;
724 if (std::find(types.begin(), types.end(),
731 const GncOptionAccountTypeList& types)
733 GncOptionAccountList list;
734 AccountPair funcdata{list, types};
735 Account* base_acct = gnc_book_get_root_account(book);
744 const char* section,
const char* name,
745 const char* key,
const char* doc_string,
747 GncOptionAccountTypeList&& allowed)
752 GncOptionUIType::ACCOUNT_SEL, value, std::move(allowed)}};
753 db->register_option(section, std::move(option));
755 catch (
const std::invalid_argument& err)
757 PWARN(
"Account Sel Limited Option, value failed validation, option not registerd.");
763 const char* name,
const char* key,
764 const char* doc_string,
const char* default_val,
765 GncMultichoiceOptionChoices&& choices)
767 std::string defval{default_val};
768 auto found{std::find_if(choices.begin(), choices.end(),
769 [&defval](
auto& choice)->
bool {
770 return defval == std::get<0>(choice);
772 if (found == choices.end())
773 defval = (choices.empty() ? std::string{
"None"} :
774 std::get<0>(choices.at(0)));
776 defval.c_str(), std::move(choices)}};
777 db->register_option(section, std::move(option));
782 const char* name,
const char* key,
783 const char* doc_string,
const char* value,
784 GncMultichoiceOptionChoices&& list)
787 value, std::move(list), GncOptionUIType::LIST}};
788 db->register_option(section, std::move(option));
794 template <
typename ValueType>
void 796 const char* name,
const char* key,
797 const char* doc_string, ValueType value,
798 ValueType min, ValueType max, ValueType step)
803 doc_string, value, min,
805 db->register_option(section, std::move(option));
807 catch(
const std::invalid_argument& err)
809 PWARN(
"Number Range Option %s, option not registerd.",
816 const char* section,
const char* name,
817 const char* key,
const char* doc_string,
823 db->register_option(section, std::move(option));
828 const char* name,
const QofQuery* value)
830 GncOption option{section, name,
"",
"", value,
831 GncOptionUIType::INTERNAL};
832 db->register_option(section, std::move(option));
837 const char* name,
const char* key,
838 const char* doc_string,
const GncOwner* value,
844 case GNC_OWNER_CUSTOMER:
845 uitype = GncOptionUIType::CUSTOMER;
847 case GNC_OWNER_EMPLOYEE:
848 uitype = GncOptionUIType::EMPLOYEE;
851 uitype = GncOptionUIType::JOB;
853 case GNC_OWNER_VENDOR:
854 uitype = GncOptionUIType::VENDOR;
857 uitype = GncOptionUIType::INTERNAL;
859 GncOption option{section, name, key, doc_string, value,
861 db->register_option(section, std::move(option));
866 const char* name,
const char* key,
867 const char* doc_string, GncInvoice* value)
871 GncOptionUIType::INVOICE}};
872 db->register_option(section, std::move(option));
877 const char* name,
const char* key,
882 GncOptionUIType::TAX_TABLE}};
883 db->register_option(section, std::move(option));
888 const char* name,
const char* key,
889 const char* doc_string, std::string value)
891 GncOption option{section, name, key, doc_string,
892 value, GncOptionUIType::INV_REPORT};
893 db->register_option(section, std::move(option));
898 const char* name,
const char* key,
899 const char* doc_string,
double value)
902 value, 0.0, 999999999.0, 1.0}};
903 db->register_option(section, std::move(option));
908 const char* section,
const char* name,
909 const char* key,
const char* doc_string,
912 GncOption option{section, name, key, doc_string, value,
913 GncOptionUIType::STRING};
914 db->register_option(section, std::move(option));
919 const char* name,
const char* key,
920 const char* doc_string, std::string value)
922 GncOption option{section, name, key, doc_string, value,
923 GncOptionUIType::DATE_FORMAT};
924 db->register_option(section, std::move(option));
929 const char* name,
const char* key,
930 const char* doc_string, gnc_commodity *value)
933 section, name, key, doc_string, value, GncOptionUIType::CURRENCY
935 db->register_option(section, std::move(option));
940 const char* name,
const char* key,
941 const char* doc_string,
const char* value)
945 const auto commodity = gnc_commodity_table_lookup(commodity_table,
949 section, name, key, doc_string, commodity, GncOptionUIType::CURRENCY
951 db->register_option(section, std::move(option));
956 const char* name,
const char* key,
957 const char* doc_string,
time64 time,
960 auto ui_type = ui == RelativeDateUI::BOTH ? GncOptionUIType::DATE_BOTH :
961 ui == RelativeDateUI::RELATIVE ? GncOptionUIType::DATE_RELATIVE :
962 GncOptionUIType::DATE_ABSOLUTE;
965 db->register_option(section, std::move(option));
970 const char* name,
const char* key,
974 auto ui_type = ui == RelativeDateUI::BOTH ? GncOptionUIType::DATE_BOTH :
975 ui == RelativeDateUI::RELATIVE ? GncOptionUIType::DATE_RELATIVE :
976 GncOptionUIType::DATE_ABSOLUTE;
979 db->register_option(section, std::move(option));
984 const char* section,
const char* name,
985 const char* key,
const char* doc_string,
986 RelativeDatePeriodVec& period_set,
989 auto is_absolute = period_set.size() == 1 &&
990 period_set.front() == RelativeDatePeriod::ABSOLUTE;
991 auto ui_type = both ? GncOptionUIType::DATE_BOTH :
992 is_absolute ? GncOptionUIType::DATE_ABSOLUTE : GncOptionUIType::DATE_RELATIVE;
994 ui_type, period_set)};
996 option.set_default_value(
gnc_time(
nullptr));
997 db->register_option(section, std::move(option));
1001 static const RelativeDatePeriodVec begin_dates
1003 RelativeDatePeriod::TODAY,
1004 RelativeDatePeriod::START_THIS_MONTH,
1005 RelativeDatePeriod::START_PREV_MONTH,
1006 RelativeDatePeriod::START_CURRENT_QUARTER,
1007 RelativeDatePeriod::START_PREV_QUARTER,
1008 RelativeDatePeriod::START_CAL_YEAR,
1009 RelativeDatePeriod::START_PREV_YEAR,
1010 RelativeDatePeriod::START_ACCOUNTING_PERIOD
1015 const char* name,
const char* key,
1016 const char* doc_string,
bool both)
1018 auto ui_type = both ? GncOptionUIType::DATE_BOTH :
1019 GncOptionUIType::DATE_RELATIVE;
1021 ui_type, begin_dates)};
1022 db->register_option(section, std::move(option));
1025 static const RelativeDatePeriodVec end_dates
1027 RelativeDatePeriod::TODAY,
1028 RelativeDatePeriod::END_THIS_MONTH,
1029 RelativeDatePeriod::END_PREV_MONTH,
1030 RelativeDatePeriod::END_CURRENT_QUARTER,
1031 RelativeDatePeriod::END_PREV_QUARTER,
1032 RelativeDatePeriod::END_CAL_YEAR,
1033 RelativeDatePeriod::END_PREV_YEAR,
1034 RelativeDatePeriod::END_ACCOUNTING_PERIOD
1039 const char* name,
const char* key,
1040 const char* doc_string,
bool both)
1042 auto ui_type = both ? GncOptionUIType::DATE_BOTH :
1043 GncOptionUIType::DATE_RELATIVE;
1045 ui_type, end_dates)};
1046 db->register_option(section, std::move(option));
1050 gnc_register_report_placement_option(GncOptionDBPtr& db,
1051 const char* section,
const char* name)
1056 GncOptionReportPlacementVec value;
1058 "no_key",
"nodoc_string",
1059 value,GncOptionUIType::REPORT_PLACEMENT}};
1060 db->register_option(section, std::move(option));
1064 gnc_register_internal_option(GncOptionDBPtr& db,
1065 const char* section,
const char* name,
1066 const std::string& value)
1070 GncOptionUIType::INTERNAL}};
1071 db->register_option(section, std::move(option));
1075 gnc_register_internal_option(GncOptionDBPtr& db,
1076 const char* section,
const char* name,
1081 GncOptionUIType::INTERNAL}};
1082 db->register_option(section, std::move(option));
1094 PWARN(
"Direct Destroy called on GncOptionDB %" G_GUINT64_FORMAT, (uint64_t)odb);
1101 odb->foreach_section(
1102 [&errors](GncOptionSectionPtr& section){
1103 section->foreach_option(
1107 option.set_option_from_ui_item();
1109 catch (
const std::invalid_argument& err)
1111 PWARN(
"Option %s:%s failed to set its value %s",
1112 option.get_section().c_str(),
1113 option.get_name().c_str(), err.what());
1114 errors = g_list_prepend(errors,
1115 (
void*)option.get_name().c_str());
1119 odb->run_callbacks();
1126 odb->foreach_section(
1127 [](GncOptionSectionPtr& section){
1128 section->foreach_option(
1130 option.set_ui_item_from_option();
1137 odb->load_from_kvp(book);
1142 gboolean clear_options)
1144 odb->save_to_kvp(book, static_cast<bool>(clear_options));
1150 constexpr
const char* business_section{N_(
"Business")};
1151 constexpr
const char* counter_section{N_(
"Counters")};
1152 static const std::string empty_string{
""};
1156 gnc_register_number_range_option<double>(odb, OPTION_SECTION_ACCOUNTS,
1157 OPTION_NAME_AUTO_READONLY_DAYS,
"a",
1158 N_(
"Choose the number of days after which transactions will be read-only and cannot be edited anymore. This threshold is marked by a red line in the account register windows. If zero, all transactions can be edited and none are read-only."),
1159 0.0, 0.0, 3650.0, 1.0);
1162 OPTION_NAME_NUM_FIELD_SOURCE,
"b",
1163 N_(
"Check to have split action field used in registers for 'Num' field in place of transaction number; transaction number shown as 'T-Num' on second line of register. Has corresponding effect on business features, reporting and imports/exports."),
1166 OPTION_NAME_TRADING_ACCOUNTS,
"a",
1167 N_(
"Check to have trading accounts used for transactions involving more than one currency or commodity."),
1173 OPTION_NAME_DEFAULT_BUDGET,
"a",
1174 N_(
"Budget to be used when none has been otherwise specified."),
1180 N_(
"Customer number"),
"gncCustomera",
1181 N_(
"The previous customer number generated. This number will be incremented to generate the next customer number."),
1184 N_(
"Customer number format"),
1186 N_(
"The format string to use for generating customer numbers. This is a printf-style format string."),
1189 N_(
"Employee number"),
"gncEmployeea",
1190 N_(
"The previous employee number generated. This number will be incremented to generate the next employee number."),
1193 N_(
"Employee number format"),
1195 N_(
"The format string to use for generating employee numbers. This is a printf-style format string."),
1198 N_(
"Invoice number"),
"gncInvoicea",
1199 N_(
"The previous invoice number generated. This number will be incremented to generate the next invoice number."),
1202 N_(
"Invoice number format"),
1204 N_(
"The format string to use for generating invoice numbers. This is a printf-style format string."),
1207 N_(
"Bill number"),
"gncBilla",
1208 N_(
"The previous bill number generated. This number will be incremented to generate the next bill number."),
1211 N_(
"Bill number format"),
"gncBillb",
1212 N_(
"The format string to use for generating bill numbers. This is a printf-style format string."),
1215 N_(
"Expense voucher number"),
"gncExpVouchera",
1216 N_(
"The previous expense voucher number generated. This number will be incremented to generate the next voucher number."),
1219 N_(
"Expense voucher number format"),
1221 N_(
"The format string to use for generating expense voucher numbers. This is a printf-style format string."),
1224 N_(
"Job number"),
"gncJoba",
1225 N_(
"The previous job number generated. This number will be incremented to generate the next job number."),
1228 N_(
"Job number format"),
"gncJobb",
1229 N_(
"The format string to use for generating job numbers. This is a printf-style format string."),
1232 N_(
"Order number"),
"gncOrdera",
1233 N_(
"The previous order number generated. This number will be incremented to generate the next order number."),
1236 N_(
"Order number format"),
"gncOrderb",
1237 N_(
"The format string to use for generating order numbers. This is a printf-style format string."),
1240 N_(
"Vendor number"),
"gncVendora",
1241 N_(
"The previous vendor number generated. This number will be incremented to generate the next vendor number."),
1244 N_(
"Vendor number format"),
"gncVendorb",
1245 N_(
"The format string to use for generating vendor numbers. This is a printf-style format string."),
1251 N_(
"The name of your business."),
1254 N_(
"The address of your business."),
1257 N_(
"Company Contact Person"),
"b2",
1258 N_(
"The contact person to print on invoices."),
1261 N_(
"Company Phone Number"),
"c1",
1262 N_(
"The contact person to print on invoices."),
1265 N_(
"Company Fax Number"),
"c2",
1266 N_(
"The fax number of your business."),
1269 N_(
"Company Email Address"),
"c3",
1270 N_ (
"The email address of your business."),
1273 N_(
"Company Website URL"),
"c4",
1274 N_(
"The URL address of your website."),
1277 N_(
"The ID for your company (eg 'Tax-ID: 00-000000)."),
1280 OPTION_NAME_DEFAULT_INVOICE_REPORT,
"e1",
1281 N_(
"The invoice report to be used for printing."),
1283 gnc_register_number_range_option<double>(odb, business_section,
1284 OPTION_NAME_DEFAULT_INVOICE_REPORT_TIMEOUT,
"e2",
1285 N_(
"Length of time to change the used invoice report. A value of 0 means disabled."),
1286 0.0, 0.0, 20.0, 1.0);
1288 N_(
"Default Customer TaxTable"),
"f1",
1289 N_(
"The default tax table to apply to customers."),
1292 N_(
"Default Vendor TaxTable"),
"f2",
1293 N_(
"The default tax table to apply to vendors."),
1296 N_(
"Fancy Date Format"),
"g",
1297 N_(
"The default date format used for fancy printed dates."),
1303 N_(
"The electronic tax number of your business"),
1310 auto value{odb->lookup_string_option(section, name)};
1313 return strdup(value.c_str());
1318 const char* name,
const char* value)
1320 odb->set_option<std::string>(section, name, value);
1327 auto option{odb->find_option(section, name)};
1336 const char* section,
const char* name,
1337 const char* key,
const char* doc_string,
1338 int value,
int min,
int max,
int step);
1340 const char* section,
const char* name,
1341 const char* key,
const char* doc_string,
1342 double value,
double min,
1343 double max,
double step);
Holds all of the options for a book, report, or stylesheet, organized by GncOptionSections.
gnc_commodity_table * gnc_commodity_table_get_table(QofBook *book)
Returns the commodity table associated with a book.
void gnc_option_db_clean(GncOptionDB *odb)
Reset all ui_items to the option value.
const QofInstance * gnc_option_db_lookup_qofinstance_value(GncOptionDB *odb, const char *section, const char *name)
Retrieve the string value of an option in the GncOptionDB.
const GncGUID * qof_instance_get_guid(gconstpointer inst)
Return the GncGUID of this instance.
void gnc_register_simple_boolean_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, bool value)
Create a new simple boolean option and register it in the options database.
KvpValue * qof_book_get_option(QofBook *book, GSList *path)
Read a single option value.
The generic option-value class.
void gnc_account_foreach_descendant(const Account *acc, AccountCb thunk, gpointer user_data)
This method will traverse all children of this accounts and their descendants, calling 'func' on each...
#define G_LOG_DOMAIN
Functions providing the SX List as a plugin page.
GNCAccountType xaccAccountGetType(const Account *acc)
Returns the account's account type.
void gnc_register_invoice_print_report_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new print report option and register it in the options database.
GncGUID * guid_copy(const GncGUID *guid)
Returns a newly allocated GncGUID that matches the passed-in GUID.
void gnc_register_number_range_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, ValueType value, ValueType min, ValueType max, ValueType step)
Create a new number range option and register it in the options database.
A legal date value is a pair of either a RelativeDatePeriod, the absolute flag and a time64...
C public interface for the Options Database.
void gnc_option_db_set_string_value(GncOptionDB *odb, const char *section, const char *name, const char *value)
Set the string value of an option in the GncOptionDB.
void gnc_option_db_save(GncOptionDB *odb, QofBook *book, gboolean clear_options)
Save the GncOptionDB contents into a book's options store.
void gnc_register_multichoice_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, const char *default_val, GncMultichoiceOptionChoices &&choices)
Create a new multichoice option and register it in the options database.
Represents the public interface for an option.
Set one or more accounts on which to report, optionally restricted to certain account types...
#define PWARN(format, args...)
Log a warning.
void gnc_register_query_option(GncOptionDB *db, const char *section, const char *name, const QofQuery *value)
Create a new QofQuery option and register it in the options database.
void gnc_register_number_plot_size_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, int value)
Create a new plot-size option and register it in the options database.
QofBook * qof_session_get_book(const QofSession *session)
Returns the QofBook of this session.
void gnc_register_date_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, time64 time, RelativeDateUI ui)
Create a new date option and register it in the options database.
Multichoice options have a vector of valid options (GncMultichoiceOptionChoices) and validate the sel...
void gnc_register_counter_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, double value)
Create a new counter option and register it in the options database.
void gnc_register_account_sel_limited_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, const Account *value, GncOptionAccountTypeList &&allowed)
Create a limited account selection option and register it in the options database.
GList * gnc_commodity_table_get_namespaces(const gnc_commodity_table *table)
Return a list of all namespaces in the commodity table.
void gnc_register_start_date_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, bool both)
Create a new start-date option and register it in the options database.
void gnc_option_db_load(GncOptionDB *odb, QofBook *book)
Load a book's options into the GncOptionDB.
void gnc_register_list_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, const char *value, GncMultichoiceOptionChoices &&list)
Create a new list option and register it in the options database.
void gnc_option_db_destroy(GncOptionDB *odb)
Destruct and release a GncOptionDB.
RelativeDatePeriod
Reporting periods relative to the current date.
void gnc_register_dateformat_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new date format option and register it in the options database.
void gnc_register_color_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new color option and register it in the options database.
class GncOptionSection The upper-level classification implmentation.
void gnc_register_string_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new string option and register it in the options database.
void gnc_register_account_list_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, const GncOptionAccountList &value)
Create a new account list option and register it in the options database.
void gnc_register_commodity_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, gnc_commodity *value)
Create a new commodity option and register it in the options database.
class GncOptionCommodityValue Commodities are stored with their namespace and mnemonic instead of the...
Used for numeric ranges and plot sizes.
const GncGUID * qof_entity_get_guid(gconstpointer ent)
void gnc_register_end_date_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, bool both)
Create a new end-date option and register it in the options database.
The primary C++ interface to options for books, reports, and stylesheets.
GList * gnc_option_db_commit(GncOptionDB *odb)
Write all changed ui_item values to their options.
const char * gnc_option_db_lookup_string_value(GncOptionDB *odb, const char *section, const char *name)
Retrieve the string value of an option in the GncOptionDB.
void gnc_register_taxtable_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, GncTaxTable *value)
Create a new taxtable option and register it in the options database.
void gnc_register_font_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new font option and register it in the options database.
time64 gnc_time(time64 *tbuf)
get the current local time
Implementation details for GncOptionDB.
void gnc_register_pixmap_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new pixmap option and register it in the options database.
gint64 time64
Many systems, including Microsoft Windows and BSD-derived Unixes like Darwin, are retaining the int-3...
void gnc_register_budget_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, GncBudget *value)
Create a new budget option and register it in the options database.
void gnc_register_currency_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, gnc_commodity *value)
Create a new currency option and register it in the options database.
void qof_book_set_option(QofBook *book, KvpValue *value, GSList *path)
Save a single option value.
void qof_book_options_delete(QofBook *book, GSList *path)
Delete the options.
void gnc_option_db_book_options(GncOptionDB *odb)
Register the standard option set for a QofBook.
The type used to store guids in C.
void gnc_register_invoice_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, GncInvoice *value)
Create a new invoice option and register it in the options database.
GncOptionAccountList gnc_account_list_from_types(QofBook *book, const GncOptionAccountTypeList &types)
Extract a list of accounts in the book having one of the GNCAccountTypes in types.
void gnc_register_counter_format_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new counter format option and register it in the options database.
void gnc_register_text_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, std::string value)
Create a new text option and register it in the options database.
GncOptionUIType
Used by GncOptionClassifier to indicate to dialog-options what control should be displayed for the op...
modtime is the internal date of the last modtime See src/doc/business.txt for an explanation of the f...
void gnc_register_owner_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, const GncOwner *value, GncOwnerType type)
Create a new GncOwner option and register it in the options database.
GncOptionDB * gnc_option_db_new(void)
Create an empty option database.
void gnc_register_account_list_limited_option(GncOptionDB *db, const char *section, const char *name, const char *key, const char *doc_string, const GncOptionAccountList &value, GncOptionAccountTypeList &&allowed)
Create a new limited account list option and register it in the options database. ...