Skip to content

Commit

Permalink
Use addon factory v2 and clang-tidy
Browse files Browse the repository at this point in the history
  • Loading branch information
wengxt committed Jan 18, 2025
1 parent ff3cdb8 commit 00bf817
Show file tree
Hide file tree
Showing 13 changed files with 163 additions and 45 deletions.
5 changes: 3 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
cmake_minimum_required(VERSION 3.4.0)
cmake_minimum_required(VERSION 3.12)

project(fcitx5-zhuyin VERSION 5.1.2)

set(REQUIRED_FCITX_VERSION 5.1.12)
find_package(ECM 1.0.0 REQUIRED)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
include(FeatureSummary)
Expand All @@ -10,7 +11,7 @@ include(ECMSetupVersion)
include(ECMUninstallTarget)

find_package(Gettext REQUIRED)
find_package(Fcitx5Core 5.0.2 REQUIRED)
find_package(Fcitx5Core ${REQUIRED_FCITX_VERSION} REQUIRED)
find_package(Fcitx5Module REQUIRED COMPONENTS Notifications QuickPhrase)
find_package(PkgConfig REQUIRED)
find_package(fmt REQUIRED)
Expand Down
4 changes: 2 additions & 2 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
add_library(zhuyin-lib STATIC
add_library(zhuyin-lib OBJECT
zhuyinbuffer.cpp
zhuyincandidate.cpp
zhuyinsection.cpp
Expand All @@ -7,7 +7,7 @@ add_library(zhuyin-lib STATIC
target_link_libraries(zhuyin-lib Fcitx5::Core PkgConfig::LibZhuyin)
set_property(TARGET zhuyin-lib PROPERTY POSITION_INDEPENDENT_CODE ON)

add_library(zhuyin MODULE zhuyinengine.cpp)
add_fcitx5_addon(zhuyin zhuyinengine.cpp)
target_link_libraries(zhuyin Fcitx5::Core Fcitx5::Config Fcitx5::Module::QuickPhrase PkgConfig::LibZhuyin ${FMT_TARGET} zhuyin-lib)
set_target_properties(zhuyin PROPERTIES PREFIX "")
install(TARGETS zhuyin DESTINATION "${CMAKE_INSTALL_LIBDIR}/fcitx5")
Expand Down
3 changes: 3 additions & 0 deletions src/zhuyin-addon.conf.in.in
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ Type=SharedLibrary
OnDemand=True
Configurable=True

[Addon/Dependencies]
0=core:@REQUIRED_FCITX_VERSION@

[Addon/OptionalDependencies]
0=fullwidth
1=chttrans
Expand Down
13 changes: 13 additions & 0 deletions src/zhuyinbuffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,22 @@
*/
#include "zhuyinbuffer.h"
#include "zhuyincandidate.h"
#include "zhuyinsection.h"
#include <cassert>
#include <cstddef>
#include <cstdint>
#include <fcitx-utils/charutils.h>
#include <fcitx-utils/textformatflags.h>
#include <fcitx/text.h>
#include <functional>
#include <glib.h>
#include <iterator>
#include <limits>
#include <memory>
#include <sstream>
#include <string>
#include <utility>
#include <zhuyin.h>

namespace fcitx {

Expand Down
6 changes: 5 additions & 1 deletion src/zhuyinbuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,14 @@

#include "zhuyinsection.h"
#include "zhuyinsymbol.h"
#include <cstddef>
#include <cstdint>
#include <fcitx-utils/misc.h>
#include <fcitx/text.h>
#include <functional>
#include <list>
#include <variant>
#include <memory>
#include <string>
#include <zhuyin.h>

namespace fcitx {
Expand Down
21 changes: 15 additions & 6 deletions src/zhuyincandidate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,36 @@
*/
#include "zhuyincandidate.h"
#include "zhuyinbuffer.h"
#include "zhuyinsection.h"
#include <cstddef>
#include <fcitx/candidatelist.h>
#include <fcitx/text.h>
#include <glib.h>
#include <stdexcept>
#include <string>
#include <utility>
#include <zhuyin.h>

namespace fcitx {

ZhuyinSectionCandidate::ZhuyinSectionCandidate(SectionIterator section,
unsigned int i)

: section_(section), index_(i) {
lookup_candidate_t *candidate = NULL;
lookup_candidate_t *candidate = nullptr;
if (!zhuyin_get_candidate(section->instance(), i, &candidate)) {
throw std::runtime_error("Failed to get candidate");
}

const gchar *word = NULL;
const gchar *word = nullptr;
if (!zhuyin_get_candidate_string(section->instance(), candidate, &word)) {
throw std::runtime_error("Failed to get string");
}
setText(Text(word));
}

void ZhuyinSectionCandidate::select(InputContext *) const {
lookup_candidate_t *candidate = NULL;
void ZhuyinSectionCandidate::select(InputContext * /*inputContext*/) const {
lookup_candidate_t *candidate = nullptr;
if (!zhuyin_get_candidate(section_->instance(), index_, &candidate)) {
return;
}
Expand All @@ -45,7 +54,7 @@ SymbolSectionCandidate::SymbolSectionCandidate(SectionIterator section,
setText(Text(symbol_));
}

void SymbolSectionCandidate::select(InputContext *) const {
void SymbolSectionCandidate::select(InputContext * /*inputContext*/) const {
section_->setSymbol(symbol_);
emit<ZhuyinCandidate::selected>();
}
Expand All @@ -55,7 +64,7 @@ SymbolZhuyinSectionCandidate::SymbolZhuyinSectionCandidate(

: SymbolSectionCandidate(section, std::move(symbol)), offset_(offset) {}

void SymbolZhuyinSectionCandidate::select(InputContext *) const {
void SymbolZhuyinSectionCandidate::select(InputContext * /*unused*/) const {
section_->buffer()->setZhuyinSymbolTo(section_, offset_, symbol_);
emit<ZhuyinCandidate::selected>();
}
Expand Down
8 changes: 5 additions & 3 deletions src/zhuyincandidate.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@
#define _FCITX5_ZHUYIN_ZHUYINCANDIDATE_H_

#include "zhuyinsection.h"
#include <cstddef>
#include <fcitx-utils/connectableobject.h>
#include <fcitx/candidatelist.h>
#include <string>

namespace fcitx {

Expand All @@ -28,7 +30,7 @@ class ZhuyinSectionCandidate : public ZhuyinCandidate {
public:
ZhuyinSectionCandidate(SectionIterator section, unsigned int i);
bool isZhuyin() const override { return true; }
void select(InputContext *) const override;
void select(InputContext * /*inputContext*/) const override;
FCITX_DECLARE_SIGNAL(ZhuyinSectionCandidate, selected,
void(SectionIterator));

Expand All @@ -42,7 +44,7 @@ class ZhuyinSectionCandidate : public ZhuyinCandidate {
class SymbolSectionCandidate : public ZhuyinCandidate {
public:
SymbolSectionCandidate(SectionIterator section, std::string symbol);
void select(InputContext *) const override;
void select(InputContext * /*inputContext*/) const override;

protected:
FCITX_DEFINE_SIGNAL(ZhuyinSectionCandidate, selected);
Expand All @@ -55,7 +57,7 @@ class SymbolZhuyinSectionCandidate : public SymbolSectionCandidate {
public:
SymbolZhuyinSectionCandidate(SectionIterator section, std::string symbol,
size_t offset);
void select(InputContext *) const override;
void select(InputContext * /*unused*/) const override;

private:
size_t offset_;
Expand Down
Loading

0 comments on commit 00bf817

Please sign in to comment.