Added guiwrapper for fcitx-qt5 (#19)
This commit is contained in:
parent
6cc5e86b1c
commit
49328e1da8
|
@ -6,3 +6,4 @@ build/*
|
|||
*.kate-swp
|
||||
*.orig
|
||||
tags
|
||||
run.sh
|
||||
|
|
|
@ -36,5 +36,6 @@ set(FcitxQt5_INCLUDE_INSTALL_DIR ${CMAKE_INSTALL_FULL_INCLUDEDIR}/FcitxQt5)
|
|||
add_subdirectory(dbusaddons)
|
||||
add_subdirectory(widgetsaddons)
|
||||
add_subdirectory(platforminputcontext)
|
||||
add_subdirectory(guiwrapper)
|
||||
|
||||
feature_summary(WHAT ALL FATAL_ON_MISSING_REQUIRED_PACKAGES)
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
find_package(Fcitx 4.2.8 REQUIRED)
|
||||
|
||||
set(QT_WRAPPER_SRCS
|
||||
main.cpp
|
||||
wrapperapp.cpp
|
||||
mainwindow.cpp
|
||||
)
|
||||
|
||||
fcitx_translate_add_sources(
|
||||
${QT_WRAPPER_SRCS}
|
||||
)
|
||||
|
||||
include_directories(
|
||||
${LIBINTL_INCLUDE_DIR}
|
||||
${CMAKE_CURRENT_BINARY_DIR}
|
||||
)
|
||||
|
||||
link_directories(${FCITX4_FCITX_UTILS_LIBRARY_DIRS})
|
||||
|
||||
qt5_wrap_ui(QT_WRAPPER_SRCS mainwindow.ui)
|
||||
|
||||
add_executable(fcitx-qt5-gui-wrapper ${QT_WRAPPER_SRCS})
|
||||
|
||||
set_target_properties(fcitx-qt5-gui-wrapper
|
||||
PROPERTIES VERSION 1.0
|
||||
AUTOMOC TRUE)
|
||||
|
||||
target_link_libraries(fcitx-qt5-gui-wrapper
|
||||
Qt5::Core
|
||||
Qt5::Gui
|
||||
Qt5::Widgets
|
||||
FcitxQt5::DBusAddons
|
||||
FcitxQt5::WidgetsAddons
|
||||
${FCITX4_FCITX_UTILS_LIBRARIES}
|
||||
)
|
||||
|
||||
install(TARGETS fcitx-qt5-gui-wrapper DESTINATION "${CMAKE_INSTALL_LIBDIR}/libexec")
|
|
@ -0,0 +1,29 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2012~2012 by CSSlayer *
|
||||
* wengxt@gmail.com *
|
||||
* Copyright (C) 2017~2017 by xzhao *
|
||||
* i@xuzhao.net *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef FCITX_QT5_GUIWRAPPER_COMMON_H
|
||||
#define FCITX_QT5_GUIWRAPPER_COMMON_H
|
||||
|
||||
#include <libintl.h>
|
||||
|
||||
#define _(x) QString::fromUtf8(dgettext("fcitx", x))
|
||||
|
||||
#endif // FCITX_QT5_GUIWRAPPER_COMMON_H
|
|
@ -0,0 +1,30 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2012~2012 by CSSlayer *
|
||||
* wengxt@gmail.com *
|
||||
* Copyright (C) 2017~2017 by xzhao *
|
||||
* i@xuzhao.net *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include <libintl.h>
|
||||
#include "fcitx-utils/utils.h"
|
||||
#include "wrapperapp.h"
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
{
|
||||
WrapperApp app(argc, argv);
|
||||
return app.exec();
|
||||
}
|
|
@ -0,0 +1,102 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2012~2013 by CSSlayer *
|
||||
* wengxt@gmail.com *
|
||||
* Copyright (C) 2017~2017 by xzhao *
|
||||
* i@xuzhao.net *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include <libintl.h>
|
||||
#include <QPushButton>
|
||||
#include <QLocale>
|
||||
#include <QDebug>
|
||||
|
||||
#include "common.h"
|
||||
#include "mainwindow.h"
|
||||
#include "fcitxqtconnection.h"
|
||||
#include "fcitxqtinputmethodproxy.h"
|
||||
#include "fcitxqtconfiguifactory.h"
|
||||
#include "fcitx-utils/utils.h"
|
||||
|
||||
MainWindow::MainWindow(FcitxQtConfigUIWidget* pluginWidget, QWidget* parent): QMainWindow(parent)
|
||||
,m_ui(new Ui::MainWindow)
|
||||
,m_connection(new FcitxQtConnection(this))
|
||||
,m_pluginWidget(pluginWidget)
|
||||
,m_proxy(0)
|
||||
{
|
||||
m_ui->setupUi(this);
|
||||
m_ui->verticalLayout->insertWidget(0, m_pluginWidget);
|
||||
m_ui->buttonBox->button(QDialogButtonBox::Save)->setText(_("&Save"));
|
||||
m_ui->buttonBox->button(QDialogButtonBox::Reset)->setText(_("&Reset"));
|
||||
m_ui->buttonBox->button(QDialogButtonBox::Close)->setText(_("&Close"));
|
||||
m_ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(false);
|
||||
m_ui->buttonBox->button(QDialogButtonBox::Reset)->setEnabled(false);
|
||||
setWindowIcon(QIcon::fromTheme(m_pluginWidget->icon()));
|
||||
setWindowTitle(m_pluginWidget->title());
|
||||
|
||||
connect(m_pluginWidget, SIGNAL(changed(bool)), this, SLOT(changed(bool)));
|
||||
if (m_pluginWidget->asyncSave())
|
||||
connect(m_pluginWidget, SIGNAL(saveFinished()), this, SLOT(saveFinished()));
|
||||
connect(m_ui->buttonBox, SIGNAL(clicked(QAbstractButton*)), this, SLOT(clicked(QAbstractButton*)));
|
||||
connect(m_connection, SIGNAL(connected()), this, SLOT(connected()));
|
||||
|
||||
m_connection->startConnection();
|
||||
}
|
||||
|
||||
void MainWindow::connected()
|
||||
{
|
||||
if (m_proxy) {
|
||||
delete m_proxy;
|
||||
}
|
||||
m_proxy = new FcitxQtInputMethodProxy(m_connection->serviceName(), QLatin1String("/inputmethod"), *m_connection->connection(), this);
|
||||
}
|
||||
|
||||
void MainWindow::clicked(QAbstractButton* button)
|
||||
{
|
||||
QDialogButtonBox::StandardButton standardButton = m_ui->buttonBox->standardButton(button);
|
||||
if (standardButton == QDialogButtonBox::Save) {
|
||||
if (m_pluginWidget->asyncSave())
|
||||
m_pluginWidget->setEnabled(false);
|
||||
m_pluginWidget->save();
|
||||
if (!m_pluginWidget->asyncSave())
|
||||
saveFinished();
|
||||
} else if (standardButton == QDialogButtonBox::Close) {
|
||||
qApp->quit();
|
||||
}
|
||||
else if (standardButton == QDialogButtonBox::Reset) {
|
||||
m_pluginWidget->load();
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::saveFinished()
|
||||
{
|
||||
if (m_pluginWidget->asyncSave())
|
||||
m_pluginWidget->setEnabled(true);
|
||||
if (m_proxy) {
|
||||
m_proxy->ReloadAddonConfig(m_pluginWidget->addon());
|
||||
}
|
||||
}
|
||||
|
||||
void MainWindow::changed(bool changed)
|
||||
{
|
||||
m_ui->buttonBox->button(QDialogButtonBox::Save)->setEnabled(changed);
|
||||
m_ui->buttonBox->button(QDialogButtonBox::Reset)->setEnabled(changed);
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow()
|
||||
{
|
||||
delete m_ui;
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2012~2012 by CSSlayer *
|
||||
* wengxt@gmail.com *
|
||||
* Copyright (C) 2017~2017 by xzhao *
|
||||
* i@xuzhao.net *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef FCITXQT5_GUIWRAPPER_MAINWINDOW_H
|
||||
#define FCITXQT5_GUIWRAPPER_MAINWINDOW_H
|
||||
|
||||
#include <QMainWindow>
|
||||
|
||||
#include "ui_mainwindow.h"
|
||||
#include "fcitxqtconfiguiwidget.h"
|
||||
|
||||
class FcitxQtInputMethodProxy;
|
||||
class FcitxQtConnection;
|
||||
class MainWindow : public QMainWindow {
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit MainWindow(FcitxQtConfigUIWidget* pluginWidget, QWidget* parent = 0);
|
||||
virtual ~MainWindow();
|
||||
public slots:
|
||||
void changed(bool changed);
|
||||
void clicked(QAbstractButton* button);
|
||||
void connected();
|
||||
void saveFinished();
|
||||
|
||||
private:
|
||||
Ui::MainWindow* m_ui;
|
||||
FcitxQtConnection* m_connection;
|
||||
FcitxQtConfigUIWidget* m_pluginWidget;
|
||||
FcitxQtInputMethodProxy* m_proxy;
|
||||
};
|
||||
|
||||
#endif // FCITXQT5_GUIWRAPPER_MAINWINDOW_H
|
|
@ -0,0 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<ui version="4.0">
|
||||
<class>MainWindow</class>
|
||||
<widget class="QMainWindow" name="MainWindow">
|
||||
<widget class="QWidget" name="centralwidget">
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QDialogButtonBox" name="buttonBox">
|
||||
<property name="standardButtons">
|
||||
<set>QDialogButtonBox::Close|QDialogButtonBox::Reset|QDialogButtonBox::Save</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
</widget>
|
||||
<resources/>
|
||||
<connections/>
|
||||
</ui>
|
|
@ -0,0 +1,77 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2012~2012 by CSSlayer *
|
||||
* wengxt@gmail.com *
|
||||
* Copyright (C) 2017~2017 by xzhao *
|
||||
* i@xuzhao.net *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#include <libintl.h>
|
||||
#include <locale.h>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
#include "wrapperapp.h"
|
||||
#include "mainwindow.h"
|
||||
#include "fcitxqtconfiguifactory.h"
|
||||
#include "fcitxqtconnection.h"
|
||||
#include "fcitx-utils/utils.h"
|
||||
|
||||
WrapperApp::WrapperApp(int& argc, char** argv): QApplication(argc, argv)
|
||||
,m_factory(new FcitxQtConfigUIFactory(this))
|
||||
,m_mainWindow(0)
|
||||
{
|
||||
char* localedir = fcitx_utils_get_fcitx_path("localedir");
|
||||
setlocale(LC_ALL, "");
|
||||
bindtextdomain("fcitx", localedir);
|
||||
free(localedir);
|
||||
bind_textdomain_codeset("fcitx", "UTF-8");
|
||||
textdomain("fcitx");
|
||||
|
||||
FcitxQtConfigUIWidget* widget = 0;
|
||||
|
||||
if (argc == 3 && strcmp(argv[1], "--test") == 0) {
|
||||
if (m_factory->test(QString::fromLocal8Bit(argv[2]))) {
|
||||
QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection);
|
||||
} else {
|
||||
QMetaObject::invokeMethod(this, "errorExit", Qt::QueuedConnection);
|
||||
}
|
||||
} else {
|
||||
if (argc == 2) {
|
||||
widget = m_factory->create(QString::fromLocal8Bit(argv[1]));
|
||||
}
|
||||
if (!widget) {
|
||||
qWarning("Could not find plugin for file.");
|
||||
QMetaObject::invokeMethod(this, "errorExit", Qt::QueuedConnection);
|
||||
} else {
|
||||
m_mainWindow = new MainWindow(widget);
|
||||
m_mainWindow->show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
WrapperApp::~WrapperApp()
|
||||
{
|
||||
if (m_mainWindow) {
|
||||
delete m_mainWindow;
|
||||
}
|
||||
}
|
||||
|
||||
void WrapperApp::errorExit()
|
||||
{
|
||||
exit(1);
|
||||
}
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2012~2012 by CSSlayer *
|
||||
* wengxt@gmail.com *
|
||||
* Copyright (C) 2017~2017 by xzhao *
|
||||
* i@xuzhao.net *
|
||||
* *
|
||||
* This program is free software: you can redistribute it and/or modify *
|
||||
* it under the terms of the GNU General Public License as published by *
|
||||
* the Free Software Foundation, either version 3 of the License, or *
|
||||
* (at your option) any later version. *
|
||||
* *
|
||||
* This program is distributed in the hope that it will be useful, *
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
|
||||
* GNU General Public License for more details. *
|
||||
* *
|
||||
* You should have received a copy of the GNU General Public License *
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
|
||||
* *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef FCITXQT5_GUIWRAPPER_WRAPPERAPP_H
|
||||
#define FCITXQT5_GUIWRAPPER_WRAPPERAPP_H
|
||||
|
||||
#include <QApplication>
|
||||
#include "mainwindow.h"
|
||||
|
||||
class FcitxQtConfigUIFactory;
|
||||
class WrapperApp : public QApplication {
|
||||
Q_OBJECT
|
||||
public:
|
||||
WrapperApp(int& argc, char** argv);
|
||||
virtual ~WrapperApp();
|
||||
|
||||
private slots:
|
||||
void errorExit();
|
||||
private:
|
||||
FcitxQtConfigUIFactory* m_factory;
|
||||
MainWindow* m_mainWindow;
|
||||
};
|
||||
|
||||
#endif // FCITXQT5_GUIWRAPPER_WRAPPERAPP_H
|
Loading…
Reference in New Issue