init
Some checks failed
Docker. / Ubuntu (push) Has been cancelled
User-agent updater. / User-agent (push) Failing after 15s
Lock Threads / lock (push) Failing after 10s
Waiting for answer. / waiting-for-answer (push) Failing after 22s
Needs user action. / needs-user-action (push) Failing after 8s
Can't reproduce. / cant-reproduce (push) Failing after 8s
Close stale issues and PRs / stale (push) Has been cancelled

This commit is contained in:
allhaileris
2026-02-16 15:50:16 +03:00
commit afb81b8278
13816 changed files with 3689732 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
set(QT_WRAPPER_SRCS
main.cpp
wrapperapp.cpp
mainwindow.cpp
)
add_executable(fcitx5-qt5-gui-wrapper ${QT_WRAPPER_SRCS})
set_target_properties(fcitx5-qt5-gui-wrapper
PROPERTIES AUTOMOC TRUE AUTOUIC TRUE AUTOUIC_OPTIONS "-tr=fcitx::tr2fcitx;--include=fcitxqti18nhelper.h")
target_link_libraries(fcitx5-qt5-gui-wrapper
Fcitx5::Utils
Qt5::Core
Qt5::Gui
Qt5::Widgets
Fcitx5Qt5::DBusAddons
Fcitx5Qt5::WidgetsAddons
)
install(TARGETS fcitx5-qt5-gui-wrapper DESTINATION "${CMAKE_INSTALL_LIBEXECDIR}")
configure_file(org.fcitx.fcitx5-qt5-gui-wrapper.desktop.in.in ${CMAKE_CURRENT_BINARY_DIR}/org.fcitx.fcitx5-qt5-gui-wrapper.desktop.in @ONLY)
fcitx5_translate_desktop_file(${CMAKE_CURRENT_BINARY_DIR}/org.fcitx.fcitx5-qt5-gui-wrapper.desktop.in
org.fcitx.fcitx5-qt5-gui-wrapper.desktop)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/org.fcitx.fcitx5-qt5-gui-wrapper.desktop DESTINATION ${CMAKE_INSTALL_DATADIR}/applications)

View File

@@ -0,0 +1,18 @@
/*
* SPDX-FileCopyrightText: 2012~2017 CSSlayer <wengxt@gmail.com>
* SPDX-FileCopyrightText: 2017~2017 xzhao <i@xuzhao.net>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "wrapperapp.h"
#include <QCommandLineParser>
#include <locale.h>
int main(int argc, char *argv[]) {
setlocale(LC_ALL, "");
QGuiApplication::setAttribute(Qt::AA_ShareOpenGLContexts);
fcitx::WrapperApp app(argc, argv);
app.init();
return app.exec();
}

View File

@@ -0,0 +1,150 @@
/*
* SPDX-FileCopyrightText: 2012~2017 CSSlayer <wengxt@gmail.com>
* SPDX-FileCopyrightText: 2017~2017 xzhao <i@xuzhao.net>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include "mainwindow.h"
#include "fcitxqtconfiguifactory.h"
#include "fcitxqtcontrollerproxy.h"
#include "fcitxqtwatcher.h"
#include <QDebug>
#include <QLocale>
#include <QMessageBox>
#include <QPushButton>
#include <QWindow>
#include <fcitx-utils/i18n.h>
namespace fcitx {
MainWindow::MainWindow(const QString &path, FcitxQtConfigUIWidget *pluginWidget,
QWidget *parent)
: QDialog(parent), path_(path), watcher_(new FcitxQtWatcher(this)),
pluginWidget_(pluginWidget), proxy_(0) {
setupUi(this);
watcher_->setConnection(QDBusConnection::sessionBus());
verticalLayout->insertWidget(0, pluginWidget_);
buttonBox->button(QDialogButtonBox::Ok)->setText(_("&Ok"));
buttonBox->button(QDialogButtonBox::Apply)->setText(_("&Apply"));
buttonBox->button(QDialogButtonBox::Reset)->setText(_("&Reset"));
buttonBox->button(QDialogButtonBox::Close)->setText(_("&Close"));
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);
buttonBox->button(QDialogButtonBox::Apply)->setEnabled(false);
buttonBox->button(QDialogButtonBox::Reset)->setEnabled(false);
setWindowIcon(QIcon::fromTheme(pluginWidget_->icon()));
setWindowTitle(pluginWidget_->title());
connect(pluginWidget_, &FcitxQtConfigUIWidget::changed, this,
&MainWindow::changed);
if (pluginWidget_->asyncSave()) {
connect(pluginWidget_, &FcitxQtConfigUIWidget::saveFinished, this,
&MainWindow::saveFinished);
}
connect(pluginWidget_, &FcitxQtConfigUIWidget::saveSubConfig, this,
&MainWindow::saveSubConfig);
connect(buttonBox, &QDialogButtonBox::clicked, this, &MainWindow::clicked);
connect(watcher_, &FcitxQtWatcher::availabilityChanged, this,
&MainWindow::availabilityChanged);
watcher_->watch();
}
void MainWindow::availabilityChanged(bool avail) {
if (!avail) {
return;
}
if (proxy_) {
delete proxy_;
}
proxy_ = new FcitxQtControllerProxy(watcher_->serviceName(),
QLatin1String("/controller"),
watcher_->connection(), this);
}
void MainWindow::clicked(QAbstractButton *button) {
QDialogButtonBox::StandardButton standardButton =
buttonBox->standardButton(button);
if (standardButton == QDialogButtonBox::Apply ||
standardButton == QDialogButtonBox::Ok) {
if (pluginWidget_->asyncSave())
pluginWidget_->setEnabled(false);
if (standardButton == QDialogButtonBox::Ok) {
closeAfterSave_ = true;
}
pluginWidget_->save();
if (!pluginWidget_->asyncSave())
saveFinished();
} else if (standardButton == QDialogButtonBox::Close) {
qApp->quit();
} else if (standardButton == QDialogButtonBox::Reset) {
pluginWidget_->load();
}
}
void MainWindow::saveFinished() {
if (proxy_) {
// Pass some arbitrary thing.
auto watcher = new QDBusPendingCallWatcher(
proxy_->SetConfig(path_, QDBusVariant(0)), this);
connect(watcher, &QDBusPendingCallWatcher::finished, this,
&MainWindow::saveFinishedPhase2);
} else {
saveFinishedPhase2(nullptr);
}
}
void MainWindow::saveFinishedPhase2(QDBusPendingCallWatcher *watcher) {
if (watcher) {
watcher->deleteLater();
}
if (pluginWidget_->asyncSave()) {
pluginWidget_->setEnabled(true);
}
if (!watcher || watcher->isError()) {
QMessageBox::warning(
this, _("Failed to notify Fcitx"),
_("Failed to notify Fcitx about the configuration change."));
closeAfterSave_ = false;
return;
}
if (closeAfterSave_) {
qApp->quit();
}
}
void MainWindow::saveSubConfig(const QString &path) {
if (proxy_) {
// Pass some arbitrary thing.
proxy_->SetConfig(path, QDBusVariant(0));
}
}
void MainWindow::changed(bool changed) {
buttonBox->button(QDialogButtonBox::Ok)->setEnabled(changed);
buttonBox->button(QDialogButtonBox::Apply)->setEnabled(changed);
buttonBox->button(QDialogButtonBox::Reset)->setEnabled(changed);
}
void MainWindow::setParentWindow(WId id) { wid_ = id; }
void MainWindow::showEvent(QShowEvent *event) {
if (!wid_) {
return;
}
setAttribute(Qt::WA_NativeWindow, true);
QWindow *subWindow = windowHandle();
Q_ASSERT(subWindow);
QWindow *mainWindow = QWindow::fromWinId(wid_);
wid_ = 0;
if (!mainWindow) {
// foreign windows not supported on all platforms
return;
}
connect(this, &QObject::destroyed, mainWindow, &QObject::deleteLater);
subWindow->setTransientParent(mainWindow);
QDialog::showEvent(event);
}
} // namespace fcitx

View File

@@ -0,0 +1,53 @@
/*
* SPDX-FileCopyrightText: 2012~2012 CSSlayer <wengxt@gmail.com>
* SPDX-FileCopyrightText: 2017~2017 xzhao
* i@xuzhao.net
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#ifndef FCITX5QT_GUIWRAPPER_MAINWINDOW_H
#define FCITX5QT_GUIWRAPPER_MAINWINDOW_H
#include <QDialog>
#include "fcitxqtconfiguiwidget.h"
#include "ui_mainwindow.h"
#include <QDBusPendingCallWatcher>
namespace fcitx {
class FcitxQtControllerProxy;
class FcitxQtWatcher;
class MainWindow : public QDialog, public Ui::MainWindow {
Q_OBJECT
public:
explicit MainWindow(const QString &path,
FcitxQtConfigUIWidget *pluginWidget,
QWidget *parent = 0);
void setParentWindow(WId id);
public Q_SLOTS:
void changed(bool changed);
void clicked(QAbstractButton *button);
void availabilityChanged(bool avail);
void saveSubConfig(const QString &path);
protected:
void showEvent(QShowEvent *event) override;
private Q_SLOTS:
void saveFinished();
void saveFinishedPhase2(QDBusPendingCallWatcher *watcher);
private:
QString path_;
FcitxQtWatcher *watcher_;
FcitxQtConfigUIWidget *pluginWidget_;
FcitxQtControllerProxy *proxy_;
WId wid_ = 0;
bool closeAfterSave_ = false;
};
} // namespace fcitx
#endif // FCITXQT5_GUIWRAPPER_MAINWINDOW_H

View File

@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>MainWindow</class>
<widget class="QWidget" name="MainWindow">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QDialogButtonBox" name="buttonBox">
<property name="standardButtons">
<set>QDialogButtonBox::Apply|QDialogButtonBox::Close|QDialogButtonBox::Ok|QDialogButtonBox::Reset</set>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@@ -0,0 +1,9 @@
[Desktop Entry]
Name=Fcitx 5 Qt5 Gui Wrapper
GenericName=Input Method Configuration helper
Comment=Load configuration plugin for Fcitx Addon
Icon=fcitx
Exec=@CMAKE_INSTALL_FULL_LIBEXECDIR@/fcitx5-qt5-gui-wrapper
Type=Application
Categories=Settings;
NoDisplay=true

View File

@@ -0,0 +1,89 @@
/*
* SPDX-FileCopyrightText: 2012~2012 CSSlayer <wengxt@gmail.com>
* SPDX-FileCopyrightText: 2017~2017 xzhao <i@xuzhao.net>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#include <QDebug>
#include "fcitxqtconfiguifactory.h"
#include "mainwindow.h"
#include "wrapperapp.h"
#include <QCommandLineParser>
#include <QWindow>
#include <fcitx-utils/i18n.h>
#include <fcitx-utils/standardpath.h>
namespace fcitx {
WrapperApp::WrapperApp(int &argc, char **argv)
: QApplication(argc, argv), factory_(new FcitxQtConfigUIFactory(this)),
mainWindow_(0) {
setApplicationName(QLatin1String(
"fcitx5-qt" QT_STRINGIFY(QT_VERSION_MAJOR) "-gui-wrapper"));
setApplicationVersion(QLatin1String(FCITX5_QT_VERSION));
setOrganizationDomain("fcitx.org");
}
void WrapperApp::init() {
QCommandLineParser parser;
parser.setApplicationDescription(_("A launcher for Fcitx Gui plugin."));
parser.addHelpOption();
parser.addOptions({
{{"w", "winid"}, _("Parent window ID"), _("winid")},
{{"t", "test"}, _("Test if config exists")},
});
parser.addPositionalArgument(_("path"), _("Config path"));
parser.process(*this);
auto args = parser.positionalArguments();
if (args.empty()) {
qWarning("Missing path argument.");
::exit(1);
return;
}
QString path = args[0];
if (!path.startsWith("fcitx://config/addon/")) {
path.prepend("fcitx://config/addon/");
}
if (parser.isSet("test")) {
if (factory_->test(path)) {
::exit(0);
} else {
::exit(1);
}
} else {
WId winid = 0;
bool ok = false;
if (parser.isSet("winid")) {
winid = parser.value("winid").toLong(&ok, 0);
}
FcitxQtConfigUIWidget *widget = factory_->create(path);
if (!widget) {
qWarning("Could not find plugin for file.");
QMetaObject::invokeMethod(this, "errorExit", Qt::QueuedConnection);
return;
}
mainWindow_ = new MainWindow(path, widget);
if (ok && winid) {
mainWindow_->setParentWindow(winid);
}
QMetaObject::invokeMethod(this, "run", Qt::QueuedConnection);
}
}
void WrapperApp::run() {
mainWindow_->exec();
QMetaObject::invokeMethod(this, "quit", Qt::QueuedConnection);
}
WrapperApp::~WrapperApp() {
if (mainWindow_) {
delete mainWindow_;
}
}
void WrapperApp::errorExit() { exit(1); }
} // namespace fcitx

View File

@@ -0,0 +1,35 @@
/*
* SPDX-FileCopyrightText: 2012~2012 CSSlayer <wengxt@gmail.com>
* SPDX-FileCopyrightText: 2017~2017 xzhao <i@xuzhao.net>
*
* SPDX-License-Identifier: LGPL-2.1-or-later
*/
#ifndef _GUIWRAPPER_WRAPPERAPP_H_
#define _GUIWRAPPER_WRAPPERAPP_H_
#include "mainwindow.h"
#include <QApplication>
namespace fcitx {
class FcitxQtConfigUIFactory;
class WrapperApp : public QApplication {
Q_OBJECT
public:
WrapperApp(int &argc, char **argv);
virtual ~WrapperApp();
void init();
public Q_SLOTS:
void run();
private Q_SLOTS:
void errorExit();
private:
FcitxQtConfigUIFactory *factory_;
MainWindow *mainWindow_;
};
} // namespace fcitx
#endif // _GUIWRAPPER_WRAPPERAPP_H_