15 #include "fcitx-config/configuration.h" 16 #include "fcitx-config/option.h" 17 #include "fcitx-config/rawconfig.h" 18 #include "fcitx-utils/i18nstring.h" 19 #include "fcitx-utils/macros.h" 20 #include "fcitx-utils/semver.h" 25 AddonConfigBase, Option<I18NString> name{
this,
"Name",
"Addon Name"};
26 Option<I18NString> comment{
this,
"Comment",
"Comment"};
27 Option<SemanticVersion> version{
this,
"Version",
"Addon Version"};
28 Option<std::string> type{
this,
"Type",
"Addon Type"};
29 Option<std::string> library{
this,
"Library",
"Addon Library"};
30 Option<bool> configurable{
this,
"Configurable",
"Configurable",
false};
31 Option<bool> enabled{
this,
"Enabled",
"Enabled",
true};
32 Option<AddonCategory> category{
this,
"Category",
"Category"};
33 Option<std::vector<std::string>> dependencies{
this,
"Dependencies",
35 Option<std::vector<std::string>> optionalDependencies{
36 this,
"OptionalDependencies",
"Optional Dependencies"};
37 Option<bool> onDemand{
this,
"OnDemand",
"Load only on request",
false};
38 Option<int> uiPriority{
this,
"UIPriority",
"User interface priority", 0};
39 Option<UIType> uiType{
this,
"UIType",
"User interface type",
40 UIType::PhyscialKeyboard};)
42 FCITX_CONFIGURATION(AddonConfig,
43 Option<AddonConfigBase> addon{
this,
"Addon",
"Addon"};)
47 void parseDependencies(
const std::vector<std::string> &data,
48 std::vector<std::string> &dependencies,
49 std::vector<std::tuple<std::string, SemanticVersion>>
50 &dependenciesWithVersion) {
52 dependenciesWithVersion.clear();
53 for (
const auto &item : data) {
55 if (tokens.size() == 1) {
56 dependencies.push_back(tokens[0]);
57 dependenciesWithVersion.emplace_back(tokens[0], SemanticVersion{});
58 }
else if (tokens.size() == 2) {
59 auto version = SemanticVersion::parse(tokens[1]);
61 dependencies.push_back(tokens[0]);
62 dependenciesWithVersion.emplace_back(tokens[0],
75 std::string uniqueName_;
76 OverrideEnabled overrideEnabled_ = OverrideEnabled::NotSet;
77 std::vector<std::string> dependencies_;
78 std::vector<std::string> optionalDependencies_;
79 std::vector<std::tuple<std::string, SemanticVersion>>
80 dependenciesWithVersion_;
81 std::vector<std::tuple<std::string, SemanticVersion>>
82 optionalDependenciesWithVersion_;
85 AddonInfo::AddonInfo(
const std::string &name)
86 : d_ptr(std::make_unique<AddonInfoPrivate>(name)) {}
88 AddonInfo::~AddonInfo() {}
90 bool AddonInfo::isValid()
const {
95 const std::string &AddonInfo::uniqueName()
const {
97 return d->uniqueName_;
102 return d->addon->name.value();
105 const I18NString &AddonInfo::comment()
const {
107 return d->addon->comment.value();
110 const std::string &AddonInfo::type()
const {
112 return d->addon->type.value();
115 AddonCategory AddonInfo::category()
const {
117 return d->addon->category.value();
120 const std::string &AddonInfo::library()
const {
122 return d->addon->library.value();
125 const std::vector<std::string> &AddonInfo::dependencies()
const {
127 return d->dependencies_;
130 const std::vector<std::string> &AddonInfo::optionalDependencies()
const {
132 return d->optionalDependencies_;
135 const std::vector<std::tuple<std::string, SemanticVersion>> &
136 AddonInfo::dependenciesWithVersion()
const {
138 return d->dependenciesWithVersion_;
141 const std::vector<std::tuple<std::string, SemanticVersion>> &
142 AddonInfo::optionalDependenciesWithVersion()
const {
144 return d->optionalDependenciesWithVersion_;
147 bool AddonInfo::onDemand()
const {
149 return d->addon->onDemand.value();
152 int AddonInfo::uiPriority()
const {
154 return d->addon->uiPriority.value();
157 UIType AddonInfo::uiType()
const {
159 return d->addon->uiType.value();
162 void AddonInfo::load(
const RawConfig &config) {
166 parseDependencies(*d->addon->dependencies, d->dependencies_,
167 d->dependenciesWithVersion_);
168 parseDependencies(*d->addon->optionalDependencies, d->optionalDependencies_,
169 d->optionalDependenciesWithVersion_);
172 d->valid_ = !(d->uniqueName_.empty()) &&
173 !(d->addon->type.value().empty()) &&
174 !(d->addon->library.value().empty());
177 bool AddonInfo::isEnabled()
const {
179 if (d->overrideEnabled_ == OverrideEnabled::NotSet) {
180 return *d->addon->enabled;
182 return d->overrideEnabled_ == OverrideEnabled::Enabled;
185 bool AddonInfo::isDefaultEnabled()
const {
187 return *d->addon->enabled;
190 bool AddonInfo::isConfigurable()
const {
192 return *d->addon->configurable;
197 return *d->addon->version;
200 void AddonInfo::setOverrideEnabled(OverrideEnabled overrideEnabled) {
202 d->overrideEnabled_ = overrideEnabled;
Provide a Semantic version 2.0 implementation.
std::vector< std::string > split(std::string_view str, std::string_view delim, SplitBehavior behavior)
Split the string by delim.