Skip to content

Commit

Permalink
Add basic migration tool.
Browse files Browse the repository at this point in the history
Fix #12, Fix #13, Fix #14, Fix #15
  • Loading branch information
wengxt committed Sep 12, 2020
1 parent 734741d commit 8f113a7
Show file tree
Hide file tree
Showing 68 changed files with 2,727 additions and 1 deletion.
6 changes: 5 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,15 @@ include(KDEInstallDirs)
include(KDECMakeSettings)
include(KDECompilerSettings)
include(FeatureSummary)
include(ECMSetupVersion)
include(GenerateExportHeader)
option(ENABLE_KCM "Enable KDE Config Module" On)
option(ENABLE_CONFIG_QT "Enable fcitx5-config-qt" On)
option(ENABLE_TEST "Enable test" Off)
add_definitions(-DTRANSLATION_DOMAIN=\"org.fcitx.fcitx5.kcm\")
add_definitions(-DFCITX_GETTEXT_DOMAIN=\"fcitx5-configtool\")

find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Gui Widgets X11Extras)
find_package(Qt5 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS Core Gui Widgets X11Extras Concurrent)

if (ENABLE_CONFIG_QT)
find_package(KF5 REQUIRED COMPONENTS
Expand All @@ -34,9 +36,11 @@ if (ENABLE_KCM)
endif()

find_package(Fcitx5Core REQUIRED)
find_package(Fcitx5Config REQUIRED)
find_package(Fcitx5Utils REQUIRED)
find_package(Fcitx5Qt5DBusAddons REQUIRED)
find_package(IsoCodes REQUIRED)
kde_enable_exceptions()

include("${FCITX_INSTALL_CMAKECONFIG_DIR}/Fcitx5Utils/Fcitx5CompilerSettings.cmake")

Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ add_subdirectory(lib)
if (ENABLE_CONFIG_QT)
add_subdirectory(configtool)
endif()

add_subdirectory(migrator)
8 changes: 8 additions & 0 deletions src/migrator/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
add_subdirectory(app)
add_subdirectory(lib)
add_subdirectory(pinyin)
add_subdirectory(skk)
add_subdirectory(kkc)
add_subdirectory(rime)
add_subdirectory(global)
add_subdirectory(table)
4 changes: 4 additions & 0 deletions src/migrator/app/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
add_executable(fcitx5-migrator main.cpp mainwindow.cpp welcomepage.cpp taskpage.cpp progresspage.cpp)
set_target_properties(fcitx5-migrator PROPERTIES AUTOMOC TRUE AUTOUIC TRUE)
target_link_libraries(fcitx5-migrator pinyinmigrator skkmigrator rimemigrator kkcmigrator globalconfigmigrator tablemigrator Qt5::Widgets KF5::WidgetsAddons configlib migrator Fcitx5Qt5::DBusAddons)

20 changes: 20 additions & 0 deletions src/migrator/app/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "mainwindow.h"
#include <QApplication>
#include <QDebug>
#include <QPluginLoader>
#include <QtPlugin>

Q_IMPORT_PLUGIN(PinyinMigratorPlugin);
Q_IMPORT_PLUGIN(SkkMigratorPlugin);
Q_IMPORT_PLUGIN(KkcMigratorPlugin);
Q_IMPORT_PLUGIN(RimeMigratorPlugin);
Q_IMPORT_PLUGIN(GlobalConfigMigratorPlugin);
Q_IMPORT_PLUGIN(TableMigratorPlugin);

int main(int argc, char *argv[]) {
QApplication app(argc, argv);

fcitx::MainWindow window;
window.show();
return app.exec();
}
28 changes: 28 additions & 0 deletions src/migrator/app/mainwindow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* SPDX-FileCopyrightText: 2020~2020 CSSlayer <wengxt@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
*/
#include "mainwindow.h"
#include "progresspage.h"
#include "taskpage.h"
#include "welcomepage.h"
#include <fcitx-utils/i18n.h>

namespace fcitx {

MainWindow::MainWindow(QWidget *parent)
: QWizard(parent), dbus_(this), welcomePage_(new WelcomePage(this)),
taskPage_(new TaskPage(this)), progressPage_(new ProgressPage(this)) {
addPage(welcomePage_);
addPage(taskPage_);
addPage(progressPage_);
setMinimumSize(QSize(700, 480));
setWindowIcon(QIcon::fromTheme("fcitx"));
setWindowTitle(_("Migration Tool"));
}

Pipeline *MainWindow::createPipeline() { return taskPage_->createPipeline(); }

} // namespace fcitx
41 changes: 41 additions & 0 deletions src/migrator/app/mainwindow.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
* SPDX-FileCopyrightText: 2020~2020 CSSlayer <wengxt@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
*/
#ifndef _FCITX5_CONFIGTOOL_MIGRATOR_APP_MAINWINDOW_H_
#define _FCITX5_CONFIGTOOL_MIGRATOR_APP_MAINWINDOW_H_

#include "dbusprovider.h"
#include "migratorfactory.h"
#include "pipeline.h"
#include <QWizard>
#include <fcitxqtwatcher.h>

namespace fcitx {

class WelcomePage;
class TaskPage;
class ProgressPage;

class MainWindow : public QWizard {
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = nullptr);

auto *dbus() { return &dbus_; }
auto *factory() const { return &factory_; }
Pipeline *createPipeline();

private:
kcm::DBusProvider dbus_;
MigratorFactory factory_;
WelcomePage *welcomePage_;
TaskPage *taskPage_;
ProgressPage *progressPage_;
};

} // namespace fcitx

#endif // _FCITX5_CONFIGTOOL_MIGRATOR_APP_MAINWINDOW_H_
55 changes: 55 additions & 0 deletions src/migrator/app/progresspage.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* SPDX-FileCopyrightText: 2020~2020 CSSlayer <wengxt@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
*/
#include "progresspage.h"
#include "mainwindow.h"
#include <QAbstractButton>
#include <fcitx-utils/i18n.h>

namespace fcitx {

ProgressPage::ProgressPage(MainWindow *parent)
: QWizardPage(parent), parent_(parent) {
setupUi(this);
setFinalPage(true);
}

bool ProgressPage::isComplete() const { return done_; }

void ProgressPage::appendMessage(const QString &icon, const QString &message) {
QListWidgetItem *item =
new QListWidgetItem(QIcon::fromTheme(icon), message, listWidget);
listWidget->addItem(item);
listWidget->scrollToItem(item);
}

void ProgressPage::initializePage() {
if (pipeline_) {
delete pipeline_;
}
listWidget->clear();
pipeline_ = parent_->createPipeline();
done_ = false;

connect(pipeline_, &Pipeline::message, this, &ProgressPage::appendMessage);

connect(pipeline_, &Pipeline::finished, this, [this](bool success) {
if (success) {
done_ = true;
parent_->button(QWizard::CancelButton)->setEnabled(false);
appendMessage("dialog-positive",
_("All migration tasks are completed successfully."));
emit completeChanged();
} else {
appendMessage(
"dialog-error",
_("One of the task is failed. Terminating the migration."));
}
});
pipeline_->start();
}

} // namespace fcitx
36 changes: 36 additions & 0 deletions src/migrator/app/progresspage.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* SPDX-FileCopyrightText: 2020~2020 CSSlayer <wengxt@gmail.com>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*
*/
#ifndef _FCITX5_CONFIGTOOL_MIGRATOR_APP_PROGRESSPAGE_H_
#define _FCITX5_CONFIGTOOL_MIGRATOR_APP_PROGRESSPAGE_H_

#include "pipeline.h"
#include "ui_progresspage.h"
#include <QWizardPage>

namespace fcitx {

class MainWindow;

class ProgressPage : public QWizardPage, public Ui::ProgressPage {
Q_OBJECT
public:
explicit ProgressPage(MainWindow *parent);

bool isComplete() const override;
void initializePage() override;

void appendMessage(const QString &icon, const QString &message);

private:
MainWindow *parent_;
Pipeline *pipeline_ = nullptr;
bool done_ = false;
};

} // namespace fcitx

#endif // _FCITX5_CONFIGTOOL_MIGRATOR_APP_PROGRESSPAGE_H_
24 changes: 24 additions & 0 deletions src/migrator/app/progresspage.ui
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>ProgressPage</class>
<widget class="QWizardPage" name="ProgressPage">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string/>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QListWidget" name="listWidget"/>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>
Loading

0 comments on commit 8f113a7

Please sign in to comment.