Skip to content

Commit 0ebea29

Browse files
committed
Port to StandardPaths and drop Qt 5
1 parent 3c2f871 commit 0ebea29

File tree

5 files changed

+74
-59
lines changed

5 files changed

+74
-59
lines changed

CMakeLists.txt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ set(REQUIRED_FCITX_VERSION 5.1.13)
55
find_package(ECM 1.0.0 REQUIRED)
66
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} "${CMAKE_CURRENT_SOURCE_DIR}/cmake" ${CMAKE_MODULE_PATH})
77
option(ENABLE_QT "Enable Qt for GUI configuration" On)
8-
option(USE_QT6 "Build against Qt6" On)
98

109
include(ECMUninstallTarget)
1110
include(FeatureSummary)
@@ -16,21 +15,20 @@ find_package(Gettext REQUIRED)
1615
pkg_check_modules(GObject2 IMPORTED_TARGET "gobject-2.0" REQUIRED)
1716
find_package(LibSKK REQUIRED)
1817

18+
set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
19+
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
20+
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
21+
1922
include("${FCITX_INSTALL_CMAKECONFIG_DIR}/Fcitx5Utils/Fcitx5CompilerSettings.cmake")
2023

2124
set(SKK_DEFAULT_PATH "/usr/share/skk/SKK-JISYO.L" CACHE STRING "Default path of SKK")
2225

2326
include(GNUInstallDirs)
2427

2528
if (ENABLE_QT)
26-
if (USE_QT6)
27-
set(QT_MAJOR_VERSION 6)
28-
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
29-
else()
30-
set(QT_MAJOR_VERSION 5)
31-
find_package(Qt5 5.7 REQUIRED COMPONENTS Core Gui Widgets)
32-
endif()
33-
find_package(Fcitx5Qt${QT_MAJOR_VERSION}WidgetsAddons REQUIRED)
29+
set(QT_MAJOR_VERSION 6)
30+
find_package(Qt6 REQUIRED COMPONENTS Core Gui Widgets)
31+
find_package(Fcitx5Qt${QT_MAJOR_VERSION}WidgetsAddons REQUIRED)
3432
endif()
3533

3634
configure_file("${CMAKE_CURRENT_SOURCE_DIR}/config.h.in"

gui/adddictdialog.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,24 @@
66
*/
77

88
#include "adddictdialog.h"
9+
#include <memory>
10+
#include <QComboBox>
911
#include <QDebug>
12+
#include <QDialogButtonBox>
13+
#include <QDir>
1014
#include <QFileDialog>
11-
#include <fcitx-utils/standardpath.h>
15+
#include <QFileInfo>
16+
#include <QLabel>
17+
#include <QLineEdit>
18+
#include <QPushButton>
19+
#include <QSpinBox>
20+
#include <QWidget>
21+
#include <fcitx-utils/fs.h>
22+
#include <fcitx-utils/i18n.h>
23+
#include <fcitx-utils/standardpaths.h>
1224
#include <fcitxqti18nhelper.h>
1325
#include "config.h"
26+
#include "ui_adddictdialog.h"
1427

1528
#define FCITX_CONFIG_DIR "$FCITX_CONFIG_DIR"
1629

@@ -104,9 +117,9 @@ void AddDictDialog::browseClicked() {
104117
path = QFileDialog::getOpenFileName(this, _("Select Dictionary File"),
105118
info.path());
106119
} else {
107-
auto fcitxBasePath = stringutils::joinPath(
108-
StandardPath::global().userDirectory(StandardPath::Type::PkgData),
109-
"skk");
120+
auto fcitxBasePath =
121+
StandardPaths::global().userDirectory(StandardPathsType::PkgData) /
122+
"skk";
110123
fs::makePath(fcitxBasePath);
111124
QString basePath =
112125
QDir::cleanPath(QString::fromStdString(fcitxBasePath));

gui/dictmodel.cpp

Lines changed: 21 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,18 @@
55
*
66
*/
77

8+
#include "dictmodel.h"
9+
#include <QAbstractListModel>
10+
#include <QByteArray>
811
#include <QDebug>
912
#include <QFile>
13+
#include <QObject>
1014
#include <QSet>
1115
#include <QStringList>
1216
#include <QTemporaryFile>
17+
#include <Qt>
1318
#include <QtGlobal>
14-
#include <fcitx-utils/standardpath.h>
15-
16-
#include <fcntl.h>
17-
#include "dictmodel.h"
19+
#include <fcitx-utils/standardpaths.h>
1820

1921
namespace fcitx {
2022

@@ -28,17 +30,16 @@ SkkDictModel::SkkDictModel(QObject *parent) : QAbstractListModel(parent) {
2830
}
2931

3032
void SkkDictModel::defaults() {
31-
auto path =
32-
StandardPath::global().fcitxPath("pkgdatadir", "skk/dictionary_list");
33-
QFile f(path.data());
33+
auto path = StandardPaths::fcitxPath("pkgdatadir", "skk/dictionary_list");
34+
QFile f(path);
3435
if (f.open(QIODevice::ReadOnly)) {
3536
load(f);
3637
}
3738
}
3839

3940
void SkkDictModel::load() {
40-
auto file = StandardPath::global().open(StandardPath::Type::PkgData,
41-
"skk/dictionary_list", O_RDONLY);
41+
auto file = StandardPaths::global().open(StandardPathsType::PkgData,
42+
"skk/dictionary_list");
4243
if (file.fd() < 0) {
4344
return;
4445
}
@@ -66,7 +67,7 @@ void SkkDictModel::load(QFile &file) {
6667

6768
bool failed = false;
6869
QMap<QString, QString> dict;
69-
Q_FOREACH (const QString &item, items) {
70+
for (const QString &item : items) {
7071
if (!item.contains('=')) {
7172
failed = true;
7273
break;
@@ -89,18 +90,18 @@ void SkkDictModel::load(QFile &file) {
8990
}
9091

9192
bool SkkDictModel::save() {
92-
return StandardPath::global().safeSave(
93-
StandardPath::Type::PkgData, "skk/dictionary_list", [this](int fd) {
93+
return StandardPaths::global().safeSave(
94+
StandardPathsType::PkgData, "skk/dictionary_list", [this](int fd) {
9495
QFile tempFile;
9596
if (!tempFile.open(fd, QIODevice::WriteOnly)) {
9697
return false;
9798
}
9899

99-
typedef QMap<QString, QString> DictType;
100+
using DictType = QMap<QString, QString>;
100101

101-
Q_FOREACH (const DictType &dict, m_dicts) {
102+
for (const DictType &dict : m_dicts) {
102103
bool first = true;
103-
Q_FOREACH (const QString &key, dict.keys()) {
104+
for (const QString &key : dict.keys()) {
104105
if (first) {
105106
first = false;
106107
} else {
@@ -141,11 +142,11 @@ bool SkkDictModel::removeRows(int row, int count, const QModelIndex &parent) {
141142

142143
QVariant SkkDictModel::data(const QModelIndex &index, int role) const {
143144
if (!index.isValid()) {
144-
return QVariant();
145+
return {};
145146
}
146147

147148
if (index.row() >= m_dicts.size() || index.column() != 0) {
148-
return QVariant();
149+
return {};
149150
}
150151

151152
switch (role) {
@@ -156,18 +157,16 @@ QVariant SkkDictModel::data(const QModelIndex &index, int role) const {
156157
return QString("%1:%2").arg(m_dicts[index.row()]["host"],
157158
m_dicts[index.row()]["port"]);
158159
}
160+
default:
161+
break;
159162
}
160-
return QVariant();
163+
return {};
161164
}
162165

163166
bool SkkDictModel::moveUp(const QModelIndex &currentIndex) {
164167
if (currentIndex.row() > 0 && currentIndex.row() < m_dicts.size()) {
165168
beginResetModel();
166-
#if (QT_VERSION < QT_VERSION_CHECK(5, 13, 0))
167-
m_dicts.swap(currentIndex.row() - 1, currentIndex.row());
168-
#else
169169
m_dicts.swapItemsAt(currentIndex.row() - 1, currentIndex.row());
170-
#endif
171170
endResetModel();
172171
return true;
173172
}
@@ -177,11 +176,7 @@ bool SkkDictModel::moveUp(const QModelIndex &currentIndex) {
177176
bool SkkDictModel::moveDown(const QModelIndex &currentIndex) {
178177
if (currentIndex.row() >= 0 && currentIndex.row() + 1 < m_dicts.size()) {
179178
beginResetModel();
180-
#if (QT_VERSION < QT_VERSION_CHECK(5, 13, 0))
181-
m_dicts.swap(currentIndex.row() + 1, currentIndex.row());
182-
#else
183179
m_dicts.swapItemsAt(currentIndex.row() + 1, currentIndex.row());
184-
#endif
185180
endResetModel();
186181
return true;
187182
}

gui/dictwidget.cpp

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,21 @@
66
*/
77
#include "dictwidget.h"
88
#include <fcntl.h>
9+
#include <memory>
10+
#include <QDialog>
11+
#include <QItemSelectionModel>
12+
#include <QPushButton>
13+
#include <QString>
14+
#include <QWidget>
915
#include <fcitx-utils/fs.h>
10-
#include <fcitx-utils/standardpath.h>
16+
#include <fcitx-utils/i18n.h>
17+
#include <fcitx-utils/standardpaths.h>
1118
#include <fcitx-utils/stringutils.h>
19+
#include <fcitxqtconfiguiwidget.h>
1220
#include <fcitxqti18nhelper.h>
1321
#include "adddictdialog.h"
1422
#include "dictmodel.h"
23+
#include "ui_dictwidget.h"
1524

1625
namespace fcitx {
1726

@@ -20,9 +29,9 @@ SkkDictWidget::SkkDictWidget(QWidget *parent)
2029
m_ui(std::make_unique<Ui::SkkDictWidget>()) {
2130
m_ui->setupUi(this);
2231
m_dictModel = new SkkDictModel(this);
23-
auto fcitxBasePath = stringutils::joinPath(
24-
StandardPath::global().userDirectory(StandardPath::Type::PkgData),
25-
"skk");
32+
auto fcitxBasePath =
33+
StandardPaths::global().userDirectory(StandardPathsType::PkgData) /
34+
"skk";
2635
fs::makePath(fcitxBasePath);
2736

2837
m_ui->dictionaryView->setModel(m_dictModel);
@@ -47,32 +56,32 @@ QString SkkDictWidget::icon() { return "fcitx-skk"; }
4756

4857
void SkkDictWidget::load() {
4958
m_dictModel->load();
50-
emit changed(false);
59+
Q_EMIT changed(false);
5160
}
5261

5362
void SkkDictWidget::save() {
5463
m_dictModel->save();
55-
emit changed(false);
64+
Q_EMIT changed(false);
5665
}
5766

5867
void SkkDictWidget::addDictClicked() {
5968
AddDictDialog dialog;
6069
int result = dialog.exec();
6170
if (result == QDialog::Accepted) {
6271
m_dictModel->add(dialog.dictionary());
63-
emit changed(true);
72+
Q_EMIT changed(true);
6473
}
6574
}
6675

6776
void SkkDictWidget::defaultDictClicked() {
6877
m_dictModel->defaults();
69-
emit changed(true);
78+
Q_EMIT changed(true);
7079
}
7180

7281
void SkkDictWidget::removeDictClicked() {
7382
if (m_ui->dictionaryView->currentIndex().isValid()) {
7483
m_dictModel->removeRow(m_ui->dictionaryView->currentIndex().row());
75-
emit changed(true);
84+
Q_EMIT changed(true);
7685
}
7786
}
7887

@@ -81,7 +90,7 @@ void SkkDictWidget::moveUpDictClicked() {
8190
if (m_dictModel->moveUp(m_ui->dictionaryView->currentIndex())) {
8291
m_ui->dictionaryView->selectionModel()->setCurrentIndex(
8392
m_dictModel->index(row - 1), QItemSelectionModel::ClearAndSelect);
84-
emit changed(true);
93+
Q_EMIT changed(true);
8594
}
8695
}
8796

@@ -90,7 +99,7 @@ void SkkDictWidget::moveDownClicked() {
9099
if (m_dictModel->moveDown(m_ui->dictionaryView->currentIndex())) {
91100
m_ui->dictionaryView->selectionModel()->setCurrentIndex(
92101
m_dictModel->index(row + 1), QItemSelectionModel::ClearAndSelect);
93-
emit changed(true);
102+
Q_EMIT changed(true);
94103
}
95104
}
96105

src/skk.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <memory>
1717
#include <stdexcept>
1818
#include <string>
19+
#include <string_view>
1920
#include <utility>
2021
#include <vector>
2122
#include <fcitx-config/iniparser.h>
@@ -27,7 +28,7 @@
2728
#include <fcitx-utils/log.h>
2829
#include <fcitx-utils/macros.h>
2930
#include <fcitx-utils/misc.h>
30-
#include <fcitx-utils/standardpath.h>
31+
#include <fcitx-utils/standardpaths.h>
3132
#include <fcitx-utils/stringutils.h>
3233
#include <fcitx-utils/textformatflags.h>
3334
#include <fcitx-utils/utf8.h>
@@ -465,8 +466,8 @@ enum class FcitxSkkDictType { FSDT_Invalid, FSDT_File, FSTD_Server };
465466

466467
void SkkEngine::loadDictionary() {
467468
dictionaries_.clear();
468-
auto file = StandardPath::global().open(StandardPath::Type::PkgData,
469-
"skk/dictionary_list", O_RDONLY);
469+
auto file = StandardPaths::global().open(StandardPathsType::PkgData,
470+
"skk/dictionary_list");
470471

471472
if (!file.isValid()) {
472473
return;
@@ -537,8 +538,8 @@ void SkkEngine::loadDictionary() {
537538
std::string_view partialpath = path;
538539
if (stringutils::consumePrefix(partialpath,
539540
"$XDG_DATA_DIRS/")) {
540-
path = StandardPath::global().locate(
541-
StandardPath::Type::Data, std::string(partialpath));
541+
path = StandardPaths::global().locate(
542+
StandardPathsType::Data, partialpath);
542543
}
543544
if (stringutils::endsWith(path, ".cdb")) {
544545
SkkCdbDict *dict =
@@ -559,10 +560,9 @@ void SkkEngine::loadDictionary() {
559560
std::string_view partialpath = path;
560561
if (stringutils::consumePrefix(partialpath,
561562
"$FCITX_CONFIG_DIR/")) {
562-
path = stringutils::joinPath(
563-
StandardPath::global().userDirectory(
564-
StandardPath::Type::PkgData),
565-
partialpath);
563+
path = StandardPaths::global().userDirectory(
564+
StandardPathsType::PkgData) /
565+
partialpath;
566566
}
567567
SkkUserDict *userdict =
568568
skk_user_dict_new(path.data(), encoding.data(), nullptr);

0 commit comments

Comments
 (0)