Skip to content

Commit 7a30947

Browse files
committed
Clang-tidy and use addon factory v2
1 parent 839d954 commit 7a30947

File tree

5 files changed

+109
-56
lines changed

5 files changed

+109
-56
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.6)
33
# The Project Name
44
project(fcitx5-kkc VERSION 5.1.5)
55

6+
set(REQUIRED_FCITX_VERSION 5.1.12)
67
find_package(ECM REQUIRED 1.0.0)
78
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
89
include(FeatureSummary)
@@ -13,7 +14,7 @@ option(ENABLE_QT "Enable Qt for GUI configuration" On)
1314
option(USE_QT6 "Build against Qt6" On)
1415

1516
find_package(PkgConfig REQUIRED)
16-
find_package(Fcitx5Core 5.0.6 REQUIRED)
17+
find_package(Fcitx5Core ${REQUIRED_FCITX_VERSION} REQUIRED)
1718
find_package(LibKKC REQUIRED)
1819
find_package(Gettext REQUIRED)
1920
pkg_check_modules(Gee IMPORTED_TARGET "gee-0.8" REQUIRED)

src/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set(KKC_SOURCES
22
kkc.cpp
33
)
4-
add_library(kkc MODULE ${KKC_SOURCES})
4+
add_fcitx5_addon(kkc ${KKC_SOURCES})
55
target_link_libraries(kkc Fcitx5::Core Fcitx5::Config LibKKC::LibKKC PkgConfig::GObject2 PkgConfig::JSonGlib PkgConfig::Gee)
66
target_include_directories(kkc PRIVATE ${PROJECT_BINARY_DIR})
77
set_target_properties(kkc PROPERTIES PREFIX "")

src/kkc-addon.conf.in.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ OnDemand=True
88
Configurable=True
99

1010
[Dependencies]
11-
0=core/5.0.6
11+
0=core:@REQUIRED_FCITX_VERSION@

src/kkc.cpp

Lines changed: 82 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,52 @@
77
*/
88

99
#include "kkc.h"
10+
#include <algorithm>
11+
#include <cstddef>
12+
#include <cstdint>
13+
#include <cstdio>
14+
#include <cstring>
15+
#include <fcitx-config/iniparser.h>
16+
#include <fcitx-utils/capabilityflags.h>
1017
#include <fcitx-utils/fs.h>
18+
#include <fcitx-utils/i18n.h>
19+
#include <fcitx-utils/key.h>
20+
#include <fcitx-utils/keysym.h>
21+
#include <fcitx-utils/keysymgen.h>
1122
#include <fcitx-utils/log.h>
23+
#include <fcitx-utils/macros.h>
24+
#include <fcitx-utils/misc.h>
1225
#include <fcitx-utils/standardpath.h>
26+
#include <fcitx-utils/stringutils.h>
27+
#include <fcitx-utils/textformatflags.h>
1328
#include <fcitx/action.h>
29+
#include <fcitx/addoninstance.h>
30+
#include <fcitx/candidatelist.h>
31+
#include <fcitx/event.h>
1432
#include <fcitx/inputcontextmanager.h>
33+
#include <fcitx/inputmethodentry.h>
1534
#include <fcitx/inputpanel.h>
1635
#include <fcitx/menu.h>
36+
#include <fcitx/statusarea.h>
37+
#include <fcitx/text.h>
38+
#include <fcitx/userinterface.h>
1739
#include <fcitx/userinterfacemanager.h>
1840
#include <fcntl.h>
41+
#include <glib-object.h>
42+
#include <glib.h>
43+
#include <libkkc/libkkc.h>
44+
#include <memory>
45+
#include <stdexcept>
46+
#include <string>
47+
#include <utility>
48+
#include <vector>
49+
50+
namespace {
1951

2052
FCITX_DEFINE_LOG_CATEGORY(kkc_logcategory, "kkc");
2153

54+
}
55+
2256
#define KKC_DEBUG() FCITX_LOGC(kkc_logcategory, Debug)
2357

2458
namespace fcitx {
@@ -49,8 +83,9 @@ class KkcState : public InputContextProperty {
4983
parent_->dummyEmptyDictionaries());
5084
}
5185

52-
static void inputModeChanged(GObject *, GParamSpec *, gpointer user_data) {
53-
auto that = static_cast<KkcState *>(user_data);
86+
static void inputModeChanged(GObject * /*unused*/, GParamSpec * /*unused*/,
87+
gpointer user_data) {
88+
auto *that = static_cast<KkcState *>(user_data);
5489
that->updateInputMode();
5590
}
5691

@@ -63,7 +98,7 @@ class KkcState : public InputContextProperty {
6398
}
6499
}
65100

66-
void applyConfig() {
101+
void applyConfig() const {
67102
KkcCandidateList *kkcCandidates =
68103
kkc_context_get_candidates(context_.get());
69104
kkc_candidate_list_set_page_start(
@@ -109,7 +144,7 @@ struct {
109144
};
110145

111146
auto inputModeStatus(KkcEngine *engine, InputContext *ic) {
112-
auto state = engine->state(ic);
147+
auto *state = engine->state(ic);
113148
auto mode = kkc_context_get_input_mode(state->context_.get());
114149
return (mode >= 0 && mode < FCITX_ARRAY_SIZE(input_mode_status))
115150
? &input_mode_status[mode]
@@ -121,20 +156,20 @@ class KkcModeAction : public Action {
121156
KkcModeAction(KkcEngine *engine) : engine_(engine) {}
122157

123158
std::string shortText(InputContext *ic) const override {
124-
if (auto status = inputModeStatus(engine_, ic)) {
159+
if (auto *status = inputModeStatus(engine_, ic)) {
125160
return stringutils::concat(status->label, " - ",
126161
_(status->description));
127162
}
128163
return "";
129164
}
130165
std::string longText(InputContext *ic) const override {
131-
if (auto status = inputModeStatus(engine_, ic)) {
166+
if (auto *status = inputModeStatus(engine_, ic)) {
132167
return _(status->description);
133168
}
134169
return "";
135170
}
136171
std::string icon(InputContext *ic) const override {
137-
if (auto status = inputModeStatus(engine_, ic)) {
172+
if (auto *status = inputModeStatus(engine_, ic)) {
138173
return status->icon;
139174
}
140175
return "";
@@ -156,11 +191,11 @@ class KkcModeSubAction : public SimpleAction {
156191
setCheckable(true);
157192
}
158193
bool isChecked(InputContext *ic) const override {
159-
auto state = engine_->state(ic);
194+
auto *state = engine_->state(ic);
160195
return mode_ == kkc_context_get_input_mode(state->context_.get());
161196
}
162197
void activate(InputContext *ic) override {
163-
auto state = engine_->state(ic);
198+
auto *state = engine_->state(ic);
164199
kkc_context_set_input_mode(state->context_.get(), mode_);
165200
}
166201

@@ -172,13 +207,13 @@ class KkcModeSubAction : public SimpleAction {
172207
class KkcCandidateWord : public CandidateWord {
173208
public:
174209
KkcCandidateWord(KkcEngine *engine, Text text, int idx)
175-
: CandidateWord(), engine_(engine), idx_(idx) {
210+
: engine_(engine), idx_(idx) {
176211
setText(std::move(text));
177212
}
178213

179214
void select(InputContext *inputContext) const override {
180-
auto state = engine_->state(inputContext);
181-
auto context = state->context_.get();
215+
auto *state = engine_->state(inputContext);
216+
auto *context = state->context_.get();
182217
KkcCandidateList *kkcCandidates = kkc_context_get_candidates(context);
183218
if (kkc_candidate_list_select_at(
184219
kkcCandidates,
@@ -200,8 +235,8 @@ class KkcFcitxCandidateList : public CandidateList,
200235
: engine_(engine), ic_(ic) {
201236
setPageable(this);
202237
setCursorMovable(this);
203-
auto kkcstate = engine_->state(ic_);
204-
auto context = kkcstate->context_.get();
238+
auto *kkcstate = engine_->state(ic_);
239+
auto *context = kkcstate->context_.get();
205240
KkcCandidateList *kkcCandidates = kkc_context_get_candidates(context);
206241
gint size = kkc_candidate_list_get_size(kkcCandidates);
207242
gint cursor_pos = kkc_candidate_list_get_cursor_pos(kkcCandidates);
@@ -215,7 +250,7 @@ class KkcFcitxCandidateList : public CandidateList,
215250
// 24~26 3nd page
216251
int currentPage = (cursor_pos - page_start) / page_size;
217252
int totalPage = (size - page_start + page_size - 1) / page_size;
218-
int pageFirst = currentPage * page_size + page_start;
253+
int pageFirst = (currentPage * page_size) + page_start;
219254
int pageLast = std::min(size, static_cast<int>(pageFirst + page_size));
220255

221256
for (int i = pageFirst; i < pageLast; i++) {
@@ -224,7 +259,7 @@ class KkcFcitxCandidateList : public CandidateList,
224259
Text text;
225260
text.append(kkc_candidate_get_text(kkcCandidate.get()));
226261
if (*engine->config().showAnnotation) {
227-
auto annotation =
262+
const auto *annotation =
228263
kkc_candidate_get_annotation(kkcCandidate.get());
229264
// Make sure annotation is not null, empty, or equal to "?".
230265
// ? seems to be a special debug purpose value.
@@ -252,15 +287,15 @@ class KkcFcitxCandidateList : public CandidateList,
252287

253288
bool hasNext() const override { return hasNext_; }
254289

255-
void prev() override { return paging(true); }
290+
void prev() override { paging(true); }
256291

257-
void next() override { return paging(false); }
292+
void next() override { paging(false); }
258293

259294
bool usedNextBefore() const override { return true; }
260295

261-
void prevCandidate() override { return moveCursor(true); }
296+
void prevCandidate() override { moveCursor(true); }
262297

263-
void nextCandidate() override { return moveCursor(false); }
298+
void nextCandidate() override { moveCursor(false); }
264299

265300
const Text &label(int idx) const override { return labels_[idx]; }
266301

@@ -278,8 +313,8 @@ class KkcFcitxCandidateList : public CandidateList,
278313

279314
private:
280315
void paging(bool prev) {
281-
auto kkcstate = engine_->state(ic_);
282-
auto context = kkcstate->context_.get();
316+
auto *kkcstate = engine_->state(ic_);
317+
auto *context = kkcstate->context_.get();
283318
KkcCandidateList *kkcCandidates = kkc_context_get_candidates(context);
284319
if (kkc_candidate_list_get_page_visible(kkcCandidates)) {
285320
if (prev) {
@@ -291,8 +326,8 @@ class KkcFcitxCandidateList : public CandidateList,
291326
}
292327
}
293328
void moveCursor(bool prev) {
294-
auto kkcstate = engine_->state(ic_);
295-
auto context = kkcstate->context_.get();
329+
auto *kkcstate = engine_->state(ic_);
330+
auto *context = kkcstate->context_.get();
296331
KkcCandidateList *kkcCandidates = kkc_context_get_candidates(context);
297332
if (kkc_candidate_list_get_page_visible(kkcCandidates)) {
298333
if (prev) {
@@ -396,24 +431,25 @@ KkcEngine::KkcEngine(Instance *instance)
396431
}
397432
instance_->inputContextManager().registerProperty("kkcState", &factory_);
398433
instance_->inputContextManager().foreach([this](InputContext *ic) {
399-
auto state = this->state(ic);
434+
auto *state = this->state(ic);
400435
kkc_context_set_input_mode(state->context_.get(), *config_.inputMode);
401436
return true;
402437
});
403438
}
404439

405440
KkcEngine::~KkcEngine() {}
406441

407-
void KkcEngine::activate(const InputMethodEntry &, InputContextEvent &event) {
442+
void KkcEngine::activate(const InputMethodEntry & /*entry*/,
443+
InputContextEvent &event) {
408444
auto &statusArea = event.inputContext()->statusArea();
409445
statusArea.addAction(StatusGroup::InputMethod, modeAction_.get());
410446
}
411447

412448
void KkcEngine::deactivate(const InputMethodEntry &entry,
413449
InputContextEvent &event) {
414450
if (event.type() == EventType::InputContextSwitchInputMethod) {
415-
auto kkcstate = this->state(event.inputContext());
416-
auto context = kkcstate->context_.get();
451+
auto *kkcstate = this->state(event.inputContext());
452+
auto *context = kkcstate->context_.get();
417453
auto text = kkcContextGetPreedit(context);
418454
auto str = text.toString();
419455
if (!str.empty()) {
@@ -423,7 +459,8 @@ void KkcEngine::deactivate(const InputMethodEntry &entry,
423459
reset(entry, event);
424460
}
425461

426-
void KkcEngine::keyEvent(const InputMethodEntry &, KeyEvent &keyEvent) {
462+
void KkcEngine::keyEvent(const InputMethodEntry & /*entry*/,
463+
KeyEvent &keyEvent) {
427464
auto state = static_cast<uint32_t>(keyEvent.rawKey().states());
428465
state &= static_cast<uint32_t>(KeyState::SimpleMask);
429466
if (keyEvent.isRelease()) {
@@ -434,8 +471,8 @@ void KkcEngine::keyEvent(const InputMethodEntry &, KeyEvent &keyEvent) {
434471
<< " isRelease: " << keyEvent.isRelease()
435472
<< " keycode: " << keyEvent.rawKey().code();
436473

437-
auto kkcstate = this->state(keyEvent.inputContext());
438-
auto context = kkcstate->context_.get();
474+
auto *kkcstate = this->state(keyEvent.inputContext());
475+
auto *context = kkcstate->context_.get();
439476
KkcCandidateList *kkcCandidates = kkc_context_get_candidates(context);
440477
if (kkc_candidate_list_get_page_visible(kkcCandidates) &&
441478
!keyEvent.isRelease()) {
@@ -499,23 +536,24 @@ void KkcEngine::reloadConfig() {
499536

500537
if (factory_.registered()) {
501538
instance_->inputContextManager().foreach([this](InputContext *ic) {
502-
auto state = this->state(ic);
539+
auto *state = this->state(ic);
503540
state->applyConfig();
504541
return true;
505542
});
506543
}
507544
}
508-
void KkcEngine::reset(const InputMethodEntry &, InputContextEvent &event) {
509-
auto state = this->state(event.inputContext());
510-
auto context = state->context_.get();
545+
void KkcEngine::reset(const InputMethodEntry & /*entry*/,
546+
InputContextEvent &event) {
547+
auto *state = this->state(event.inputContext());
548+
auto *context = state->context_.get();
511549
kkc_context_reset(context);
512550
updateUI(event.inputContext());
513551
}
514552
void KkcEngine::save() { kkc_dictionary_list_save(dictionaries_.get()); }
515553

516554
void KkcEngine::updateUI(InputContext *inputContext) {
517-
auto state = this->state(inputContext);
518-
auto context = state->context_.get();
555+
auto *state = this->state(inputContext);
556+
auto *context = state->context_.get();
519557

520558
auto &inputPanel = inputContext->inputPanel();
521559
inputPanel.reset();
@@ -633,7 +671,7 @@ void KkcEngine::loadDictionary() {
633671
}
634672

635673
void KkcEngine::loadRule() {
636-
auto meta = kkc_rule_metadata_find(config_.rule->data());
674+
auto *meta = kkc_rule_metadata_find(config_.rule->data());
637675
if (!meta) {
638676
meta = kkc_rule_metadata_find("default");
639677
}
@@ -647,16 +685,17 @@ void KkcEngine::loadRule() {
647685
kkc_user_rule_new(meta, basePath.c_str(), "fcitx-kkc", NULL));
648686
}
649687

650-
std::string KkcEngine::subMode(const InputMethodEntry &, InputContext &ic) {
651-
if (auto status = inputModeStatus(this, &ic)) {
688+
std::string KkcEngine::subMode(const InputMethodEntry & /*entry*/,
689+
InputContext &ic) {
690+
if (auto *status = inputModeStatus(this, &ic)) {
652691
return _(status->description);
653692
}
654693
return "";
655694
}
656695

657-
std::string KkcEngine::subModeLabelImpl(const InputMethodEntry &,
696+
std::string KkcEngine::subModeLabelImpl(const InputMethodEntry & /*unused*/,
658697
InputContext &ic) {
659-
if (auto status = inputModeStatus(this, &ic)) {
698+
if (auto *status = inputModeStatus(this, &ic)) {
660699
return _(status->label);
661700
}
662701
return "";
@@ -667,4 +706,4 @@ KkcState *KkcEngine::state(InputContext *ic) {
667706
}
668707
} // namespace fcitx
669708

670-
FCITX_ADDON_FACTORY(fcitx::KkcFactory);
709+
FCITX_ADDON_FACTORY_V2(kkc, fcitx::KkcFactory);

0 commit comments

Comments
 (0)