From df1c4874642a46b42d0be17f493d294d22580169 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Wed, 27 Nov 2024 23:21:48 -0500 Subject: [PATCH 1/4] interpret dictionary path starting with $XDG_DATA_DIRS/ --- src/skk.cpp | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/src/skk.cpp b/src/skk.cpp index 2909ff1..98af2a7 100644 --- a/src/skk.cpp +++ b/src/skk.cpp @@ -501,18 +501,25 @@ void SkkEngine::loadDictionary() { continue; } if (mode == 1) { - if (stringutils::endsWith(path, ".cdb")) { - SkkCdbDict *dict = - skk_cdb_dict_new(path.data(), encoding.data(), nullptr); + constexpr char xdgDataDirs[] = "$XDG_DATA_DIRS/"; + constexpr auto len = sizeof(xdgDataDirs) - 1; + std::string realpath = path; + if (stringutils::startsWith(path, xdgDataDirs)) { + realpath = StandardPath::global().locate( + StandardPath::Type::Data, path.substr(len)); + } + if (stringutils::endsWith(realpath, ".cdb")) { + SkkCdbDict *dict = skk_cdb_dict_new( + realpath.data(), encoding.data(), nullptr); if (dict) { - SKK_DEBUG() << "Adding cdb dict: " << path; + SKK_DEBUG() << "Adding cdb dict: " << realpath; dictionaries_.emplace_back(SKK_DICT(dict)); } } else { SkkFileDict *dict = skk_file_dict_new( - path.data(), encoding.data(), nullptr); + realpath.data(), encoding.data(), nullptr); if (dict) { - SKK_DEBUG() << "Adding file dict: " << path; + SKK_DEBUG() << "Adding file dict: " << realpath; dictionaries_.emplace_back(SKK_DICT(dict)); } } From 76eaa0bf0ab2e380eb3233c2e1ef507e0c3d5e57 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Sat, 7 Dec 2024 22:03:25 -0500 Subject: [PATCH 2/4] use consumePrefix --- CMakeLists.txt | 2 +- src/skk.cpp | 40 +++++++++++++++++++--------------------- 2 files changed, 20 insertions(+), 22 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 53b05a9..a12d158 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -10,7 +10,7 @@ include(ECMUninstallTarget) include(FeatureSummary) find_package(PkgConfig REQUIRED) -find_package(Fcitx5Core 5.0.6 REQUIRED) +find_package(Fcitx5Core 5.1.12 REQUIRED) find_package(Gettext REQUIRED) pkg_check_modules(GObject2 IMPORTED_TARGET "gobject-2.0" REQUIRED) find_package(LibSKK REQUIRED) diff --git a/src/skk.cpp b/src/skk.cpp index 98af2a7..2d677b4 100644 --- a/src/skk.cpp +++ b/src/skk.cpp @@ -501,42 +501,40 @@ void SkkEngine::loadDictionary() { continue; } if (mode == 1) { - constexpr char xdgDataDirs[] = "$XDG_DATA_DIRS/"; - constexpr auto len = sizeof(xdgDataDirs) - 1; - std::string realpath = path; - if (stringutils::startsWith(path, xdgDataDirs)) { - realpath = StandardPath::global().locate( - StandardPath::Type::Data, path.substr(len)); + std::string_view partialpath = path; + if (stringutils::consumePrefix(partialpath, + "$XDG_DATA_DIRS/")) { + path = StandardPath::global().locate( + StandardPath::Type::Data, std::string(partialpath)); } - if (stringutils::endsWith(realpath, ".cdb")) { - SkkCdbDict *dict = skk_cdb_dict_new( - realpath.data(), encoding.data(), nullptr); + if (stringutils::endsWith(path, ".cdb")) { + SkkCdbDict *dict = + skk_cdb_dict_new(path.data(), encoding.data(), nullptr); if (dict) { - SKK_DEBUG() << "Adding cdb dict: " << realpath; + SKK_DEBUG() << "Adding cdb dict: " << path; dictionaries_.emplace_back(SKK_DICT(dict)); } } else { SkkFileDict *dict = skk_file_dict_new( - realpath.data(), encoding.data(), nullptr); + path.data(), encoding.data(), nullptr); if (dict) { - SKK_DEBUG() << "Adding file dict: " << realpath; + SKK_DEBUG() << "Adding file dict: " << path; dictionaries_.emplace_back(SKK_DICT(dict)); } } } else { - constexpr char configDir[] = "$FCITX_CONFIG_DIR/"; - constexpr auto len = sizeof(configDir) - 1; - std::string realpath = path; - if (stringutils::startsWith(path, configDir)) { - realpath = stringutils::joinPath( + std::string_view partialpath = path; + if (stringutils::consumePrefix(partialpath, + "$FCITX_CONFIG_DIR/")) { + path = stringutils::joinPath( StandardPath::global().userDirectory( StandardPath::Type::PkgData), - path.substr(len)); + std::string(partialpath)); } - SkkUserDict *userdict = skk_user_dict_new( - realpath.data(), encoding.data(), nullptr); + SkkUserDict *userdict = + skk_user_dict_new(path.data(), encoding.data(), nullptr); if (userdict) { - SKK_DEBUG() << "Adding user dict: " << realpath; + SKK_DEBUG() << "Adding user dict: " << path; dictionaries_.emplace_back(SKK_DICT(userdict)); } } From c4be86ab87ef89d0d39b8d2ec1066c045834b168 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Sat, 7 Dec 2024 22:18:30 -0500 Subject: [PATCH 3/4] disable fcitx5 test --- .github/workflows/check.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml index 5e8f8eb..64ddafd 100644 --- a/.github/workflows/check.yml +++ b/.github/workflows/check.yml @@ -47,15 +47,14 @@ jobs: uses: actions/cache@v4 with: path: 'fcitx5/**/*.tar.*' - key: ${{ runner.os }}-${{ hashFiles('fcitx5/src/modules/spell/CMakeLists.txt') - }} + key: ${{ runner.os }}-${{ hashFiles('fcitx5/src/modules/spell/CMakeLists.txt') }} - name: Build and Install fcitx5 uses: fcitx/github-actions@cmake with: path: fcitx5 cmake-option: >- -DENABLE_KEYBOARD=Off -DENABLE_X11=Off -DENABLE_WAYLAND=Off -DENABLE_ENCHANT=Off - -DENABLE_DBUS=Off -DENABLE_SERVER=Off -DENABLE_EMOJI=Off -DUSE_SYSTEMD=Off + -DENABLE_DBUS=Off -DENABLE_SERVER=Off -DENABLE_EMOJI=Off -DUSE_SYSTEMD=Off -DENABLE_TEST=Off - uses: actions/checkout@v4 with: repository: fcitx/fcitx5-qt From aa23b7da2b3e6b326c979d8b0e7841cd7fb15ad4 Mon Sep 17 00:00:00 2001 From: Qijia Liu Date: Sat, 7 Dec 2024 23:33:45 -0500 Subject: [PATCH 4/4] remove unnecessary construction --- src/skk.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/skk.cpp b/src/skk.cpp index 2d677b4..5af6288 100644 --- a/src/skk.cpp +++ b/src/skk.cpp @@ -529,7 +529,7 @@ void SkkEngine::loadDictionary() { path = stringutils::joinPath( StandardPath::global().userDirectory( StandardPath::Type::PkgData), - std::string(partialpath)); + partialpath); } SkkUserDict *userdict = skk_user_dict_new(path.data(), encoding.data(), nullptr);