Fcitx
option.cpp
1 /*
2  * SPDX-FileCopyrightText: 2015-2015 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 
8 #include "option.h"
9 #include <memory>
10 #include <stdexcept>
11 #include <string>
12 #include <utility>
13 #include "configuration.h"
14 #include "rawconfig.h"
15 
16 namespace fcitx {
17 
18 OptionBase::OptionBase(Configuration *parent, std::string path,
19  std::string description)
20  : parent_(parent), path_(std::move(path)),
21  description_(std::move(description)) {
22 
23  // Force the rule of "/" not allowed in option, so our life of GUI would be
24  // easier.
25  if (path_.find('/') != std::string::npos) {
26  throw std::invalid_argument(
27  "/ is not allowed in option, option path is " + path_);
28  }
29  parent_->addOption(this);
30 }
31 
32 OptionBase::~OptionBase() {}
33 
34 bool OptionBase::isDefault() const { return false; }
35 
36 const std::string &OptionBase::path() const { return path_; }
37 
38 const std::string &OptionBase::description() const { return description_; }
39 
40 void OptionBase::dumpDescription(RawConfig &config) const {
41  config.setValueByPath("Type", typeString());
42  config.setValueByPath("Description", description_);
43 }
44 
45 OptionBaseV3::~OptionBaseV3() {}
46 
47 ExternalOption::ExternalOption(Configuration *parent, std::string path,
48  std::string description, std::string uri)
49  : OptionBase(parent, std::move(path), std::move(description)),
50  externalUri_(std::move(uri)) {}
51 
52 std::string ExternalOption::typeString() const { return "External"; }
53 
54 void ExternalOption::reset() {}
55 bool ExternalOption::isDefault() const { return false; }
56 
57 void ExternalOption::marshall(RawConfig & /*config*/) const {}
58 bool ExternalOption::unmarshall(const RawConfig & /*config*/,
59  bool /*partial*/) {
60  return true;
61 }
62 std::unique_ptr<Configuration> ExternalOption::subConfigSkeleton() const {
63  return nullptr;
64 }
65 
66 bool ExternalOption::equalTo(const OptionBase & /*other*/) const {
67  return true;
68 }
69 void ExternalOption::copyFrom(const OptionBase & /*other*/) {}
70 
71 bool ExternalOption::skipDescription() const { return false; }
72 bool ExternalOption::skipSave() const { return true; }
73 void ExternalOption::dumpDescription(RawConfig &config) const {
74  OptionBase::dumpDescription(config);
75  config.setValueByPath("External", externalUri_);
76  // This field is required by dbus.
77  config.setValueByPath("DefaultValue", "");
78 }
79 
80 void SubConfigOption::dumpDescription(RawConfig &config) const {
81  ExternalOption::dumpDescription(config);
82  config.setValueByPath("LaunchSubConfig", "True");
83 }
84 } // namespace fcitx
Definition: action.cpp:17
Definition: matchrule.h:78