Fcitx
inputmethodentry.cpp
1 /*
2  * SPDX-FileCopyrightText: 2017-2017 CSSlayer <wengxt@gmail.com>
3  *
4  * SPDX-License-Identifier: LGPL-2.1-or-later
5  *
6  */
7 
8 #include "inputmethodentry.h"
10 
11 namespace fcitx {
12 
14 public:
15  InputMethodEntryPrivate(const std::string &uniqueName,
16  const std::string &name,
17  const std::string &languageCode,
18  const std::string &addon)
19  : uniqueName_(uniqueName), name_(name), languageCode_(languageCode),
20  addon_(addon) {}
21 
22  std::string uniqueName_;
23  std::string name_;
24  std::string nativeName_;
25  std::string icon_;
26  std::string label_;
27  std::string languageCode_;
28  std::string addon_;
29  bool configurable_ = false;
30  std::unique_ptr<InputMethodEntryUserData> userData_;
31 };
32 
33 InputMethodEntry::InputMethodEntry(const std::string &uniqueName,
34  const std::string &name,
35  const std::string &languageCode,
36  const std::string &addon)
37  : d_ptr(std::make_unique<InputMethodEntryPrivate>(uniqueName, name,
38  languageCode, addon)) {}
39 
40 FCITX_DEFINE_DEFAULT_DTOR_AND_MOVE(InputMethodEntry)
41 
43 InputMethodEntry::setNativeName(const std::string &nativeName) {
44  FCITX_D();
45  d->nativeName_ = nativeName;
46  return *this;
47 }
48 
49 InputMethodEntry &InputMethodEntry::setIcon(const std::string &icon) {
50  FCITX_D();
51  d->icon_ = icon;
52  return *this;
53 }
54 
55 InputMethodEntry &InputMethodEntry::setLabel(const std::string &label) {
56  FCITX_D();
57  d->label_ = label;
58  return *this;
59 }
60 
61 InputMethodEntry &InputMethodEntry::setConfigurable(bool configurable) {
62  FCITX_D();
63  d->configurable_ = configurable;
64  return *this;
65 }
66 
67 void InputMethodEntry::setUserData(
68  std::unique_ptr<InputMethodEntryUserData> userData) {
69  FCITX_D();
70  d->userData_ = std::move(userData);
71 }
72 
73 const InputMethodEntryUserData *InputMethodEntry::userData() const {
74  FCITX_D();
75  return d->userData_.get();
76 }
77 
78 const std::string &InputMethodEntry::name() const {
79  FCITX_D();
80  return d->name_;
81 }
82 const std::string &InputMethodEntry::nativeName() const {
83  FCITX_D();
84  return d->nativeName_;
85 }
86 const std::string &InputMethodEntry::icon() const {
87  FCITX_D();
88  return d->icon_;
89 }
90 const std::string &InputMethodEntry::uniqueName() const {
91  FCITX_D();
92  return d->uniqueName_;
93 }
94 const std::string &InputMethodEntry::languageCode() const {
95  FCITX_D();
96  return d->languageCode_;
97 }
98 const std::string &InputMethodEntry::addon() const {
99  FCITX_D();
100  return d->addon_;
101 }
102 const std::string &InputMethodEntry::label() const {
103  FCITX_D();
104  return d->label_;
105 }
106 bool InputMethodEntry::isConfigurable() const {
107  FCITX_D();
108  return d->configurable_;
109 }
111  FCITX_D();
112  return stringutils::startsWith(d->uniqueName_, "keyboard-") &&
113  d->addon_ == "keyboard";
114 }
115 } // namespace fcitx
bool isKeyboard() const
Helper function to check if this is a keyboard input method.
const std::string & label() const
A compact label that intented to be shown in a compact space.
Definition: action.cpp:17
bool startsWith(std::string_view str, std::string_view prefix)
Check if a string starts with a prefix.
Definition: stringutils.cpp:86
String handle utilities.