Commit b11376ea authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧 Committed by Aleix Pol Gonzalez
Browse files

Turn the emoji QML components into a plugin

This way they can be used from other components in turn.
parent 1b939460
......@@ -24,6 +24,7 @@ include(ECMMarkNonGuiExecutable)
include(ECMOptionalAddSubdirectory)
include(ECMQtDeclareLoggingCategory)
include(ECMSetupVersion)
include(ECMQtDeclareLoggingCategory)
include(FeatureSummary)
include(CheckIncludeFiles)
include(KDEClangFormat)
......
kconfig_add_kcfg_files(emojier_KCFG emojiersettings.kcfgc GENERATE_MOC)
add_executable(ibus-ui-emojier-plasma emojier.cpp resources.qrc ${emojier_KCFG})
target_link_libraries(ibus-ui-emojier-plasma Qt::Widgets GLIB2::GLIB2 PkgConfig::IBUS Qt::Quick Qt::X11Extras KF5::ConfigGui KF5::I18n KF5::CoreAddons KF5::Crash KF5::QuickAddons KF5::DBusAddons KF5::WindowSystem)
add_library(EmojierDeclarativePlugin SHARED emojierplugin.cpp ${emojier_KCFG})
target_link_libraries(EmojierDeclarativePlugin PRIVATE GLIB2::GLIB2 PkgConfig::IBUS Qt5::Qml Qt5::Gui KF5::ConfigGui)
install(TARGETS ibus-ui-emojier-plasma ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES org.kde.plasma.emojier.desktop DESTINATION ${KDE_INSTALL_DATADIR}/kglobalaccel)
install(PROGRAMS org.kde.plasma.emojier.desktop DESTINATION ${KDE_INSTALL_APPDIR} )
install (TARGETS EmojierDeclarativePlugin DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/emoji)
install (FILES qmldir DESTINATION ${KDE_INSTALL_QMLDIR}/org/kde/plasma/emoji)
add_subdirectory(app)
add_executable(ibus-ui-emojier-plasma emojier.cpp resources.qrc)
target_link_libraries(ibus-ui-emojier-plasma Qt::Widgets Qt::Quick Qt::X11Extras KF5::ConfigGui KF5::I18n KF5::CoreAddons KF5::Crash KF5::QuickAddons KF5::DBusAddons KF5::WindowSystem)
install(TARGETS ibus-ui-emojier-plasma ${KDE_INSTALL_TARGETS_DEFAULT_ARGS})
install(FILES org.kde.plasma.emojier.desktop DESTINATION ${KDE_INSTALL_DATADIR}/kglobalaccel)
install(PROGRAMS org.kde.plasma.emojier.desktop DESTINATION ${KDE_INSTALL_APPDIR} )
/*
* Copyright (C) 2019 Aleix Pol Gonzalez <aleixpol@kde.org>
*
* 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 2 of
* the License or (at your option) version 3 or any later version
* accepted by the membership of KDE e.V. (or its successor approved
* by the membership of KDE e.V.), which shall act as a proxy
* defined in Section 14 of version 3 of the license.
*
* 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 <KAboutData>
#include <KCrash>
#include <KDBusService>
#include <KLocalizedString>
#include <KQuickAddons/QtQuickSettings>
#include <KSharedConfig>
#include <KWindowConfig>
#include <QAbstractListModel>
#include <QApplication>
#include <QCommandLineParser>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusMessage>
#include <QDebug>
#include <QIcon>
#include <QLocale>
#include <QPainter>
#include <QQmlApplicationEngine>
#include <QQuickImageProvider>
#include <QQuickWindow>
#include <QSessionManager>
#include <QVector>
#include <QX11Info>
#include "config-workspace.h"
#include <kstartupinfo.h>
class EngineWatcher : public QObject
{
public:
EngineWatcher(QQmlApplicationEngine *engine)
: QObject(engine)
{
connect(engine, &QQmlApplicationEngine::objectCreated, this, &EngineWatcher::integrateObject);
}
void integrateObject(QObject *object)
{
QWindow *window = qobject_cast<QWindow *>(object);
auto conf = KSharedConfig::openConfig();
KWindowConfig::restoreWindowSize(window, conf->group("Window"));
object->installEventFilter(this);
}
bool eventFilter(QObject *object, QEvent *event) override
{
if (event->type() == QEvent::Close) {
QWindow *window = qobject_cast<QWindow *>(object);
auto conf = KSharedConfig::openConfig();
auto group = conf->group("Window");
KWindowConfig::saveWindowSize(window, group);
group.sync();
}
return false;
}
};
int main(int argc, char **argv)
{
QGuiApplication::setFallbackSessionManagementEnabled(false);
QApplication app(argc, argv);
app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
app.setWindowIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-emoticons")));
KCrash::initialize();
KQuickAddons::QtQuickSettings::init();
KLocalizedString::setApplicationDomain("org.kde.plasma.emojier");
KAboutData about(QStringLiteral("plasma.emojier"),
i18n("Emoji Selector"),
QStringLiteral(WORKSPACE_VERSION_STRING),
i18n("Emoji Selector"),
KAboutLicense::GPL,
i18n("(C) 2019 Aleix Pol i Gonzalez"));
about.addAuthor(QStringLiteral("Aleix Pol i Gonzalez"), QString(), QStringLiteral("aleixpol@kde.org"));
about.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"), i18nc("EMAIL OF TRANSLATORS", "Your emails"));
// about.setProductName("");
about.setProgramLogo(app.windowIcon());
KAboutData::setApplicationData(about);
auto disableSessionManagement = [](QSessionManager &sm) {
sm.setRestartHint(QSessionManager::RestartNever);
};
QObject::connect(&app, &QGuiApplication::commitDataRequest, disableSessionManagement);
QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement);
KDBusService::StartupOptions startup = {};
{
QCommandLineParser parser;
QCommandLineOption replaceOption({QStringLiteral("replace")}, i18n("Replace an existing instance"));
parser.addOption(replaceOption);
about.setupCommandLine(&parser);
parser.process(app);
about.processCommandLine(&parser);
if (parser.isSet(replaceOption)) {
startup |= KDBusService::Replace;
}
}
KDBusService *service = new KDBusService(KDBusService::Unique | startup, &app);
QQmlApplicationEngine engine;
new EngineWatcher(&engine);
engine.load(QUrl(QStringLiteral("qrc:/ui/emojier.qml")));
QObject::connect(service, &KDBusService::activateRequested, &engine, [&engine](const QStringList & /*arguments*/, const QString & /*workingDirectory*/) {
for (QObject *object : engine.rootObjects()) {
auto w = qobject_cast<QQuickWindow *>(object);
if (!w)
continue;
if (w && QX11Info::isPlatformX11())
KStartupInfo::setNewStartupId(w, QX11Info::nextStartupId());
w->setVisible(true);
w->raise();
}
});
return app.exec();
}
......@@ -18,41 +18,16 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <KAboutData>
#include <KCrash>
#include <KDBusService>
#include <KLocalizedString>
#include <KQuickAddons/QtQuickSettings>
#include <KWindowConfig>
#include <QAbstractListModel>
#include <QApplication>
#include <QByteArray>
#include "emojierplugin.h"
#undef signals
#include "emojiersettings.h"
#include <QClipboard>
#include <QCommandLineParser>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusMessage>
#include <QDebug>
#include <QFontMetrics>
#include <QIcon>
#include <QLocale>
#include <QPainter>
#include <QQmlApplicationEngine>
#include <QQuickImageProvider>
#include <QQuickWindow>
#include <QSessionManager>
#include <QGuiApplication>
#include <QSortFilterProxyModel>
#include <QStandardPaths>
#include <QVector>
#include <QX11Info>
#include <kstartupinfo.h>
#include "config-workspace.h"
#include "emojiersettings.h"
#undef signals
#include <ibus.h>
#include <qqml.h>
struct Emoji {
QString content;
......@@ -312,112 +287,17 @@ public:
}
};
class EngineWatcher : public QObject
void EmojierDeclarativePlugin::registerTypes(const char *uri)
{
public:
EngineWatcher(QQmlApplicationEngine *engine)
: QObject(engine)
{
connect(engine, &QQmlApplicationEngine::objectCreated, this, &EngineWatcher::integrateObject);
}
void integrateObject(QObject *object)
{
QWindow *window = qobject_cast<QWindow *>(object);
Q_ASSERT(uri == QByteArray("org.kde.plasma.emoji"));
auto conf = KSharedConfig::openConfig();
KWindowConfig::restoreWindowSize(window, conf->group("Window"));
object->installEventFilter(this);
}
bool eventFilter(QObject *object, QEvent *event) override
{
if (event->type() == QEvent::Close) {
QWindow *window = qobject_cast<QWindow *>(object);
auto conf = KSharedConfig::openConfig();
auto group = conf->group("Window");
KWindowConfig::saveWindowSize(window, group);
group.sync();
}
return false;
}
};
int main(int argc, char **argv)
{
QGuiApplication::setFallbackSessionManagementEnabled(false);
QApplication app(argc, argv);
app.setAttribute(Qt::AA_UseHighDpiPixmaps, true);
app.setWindowIcon(QIcon::fromTheme(QStringLiteral("preferences-desktop-emoticons")));
KCrash::initialize();
KQuickAddons::QtQuickSettings::init();
KLocalizedString::setApplicationDomain("org.kde.plasma.emojier");
KAboutData about(QStringLiteral("plasma.emojier"),
i18n("Emoji Selector"),
QStringLiteral(WORKSPACE_VERSION_STRING),
i18n("Emoji Selector"),
KAboutLicense::GPL,
i18n("(C) 2019 Aleix Pol i Gonzalez"));
about.addAuthor(QStringLiteral("Aleix Pol i Gonzalez"), QString(), QStringLiteral("aleixpol@kde.org"));
about.setTranslator(i18nc("NAME OF TRANSLATORS", "Your names"), i18nc("EMAIL OF TRANSLATORS", "Your emails"));
// about.setProductName("");
about.setProgramLogo(app.windowIcon());
KAboutData::setApplicationData(about);
auto disableSessionManagement = [](QSessionManager &sm) {
sm.setRestartHint(QSessionManager::RestartNever);
};
QObject::connect(&app, &QGuiApplication::commitDataRequest, disableSessionManagement);
QObject::connect(&app, &QGuiApplication::saveStateRequest, disableSessionManagement);
KDBusService::StartupOptions startup = {};
{
QCommandLineParser parser;
QCommandLineOption replaceOption({QStringLiteral("replace")}, i18n("Replace an existing instance"));
parser.addOption(replaceOption);
about.setupCommandLine(&parser);
parser.process(app);
about.processCommandLine(&parser);
if (parser.isSet(replaceOption)) {
startup |= KDBusService::Replace;
}
}
KDBusService *service = new KDBusService(KDBusService::Unique | startup, &app);
qmlRegisterType<EmojiModel>("org.kde.plasma.emoji", 1, 0, "EmojiModel");
qmlRegisterType<CategoryModelFilter>("org.kde.plasma.emoji", 1, 0, "CategoryModelFilter");
qmlRegisterType<SearchModelFilter>("org.kde.plasma.emoji", 1, 0, "SearchModelFilter");
qmlRegisterType<RecentEmojiModel>("org.kde.plasma.emoji", 1, 0, "RecentEmojiModel");
qmlRegisterSingletonType<CopyHelperPrivate>("org.kde.plasma.emoji", 1, 0, "CopyHelper", [](QQmlEngine *, QJSEngine *) -> QObject * {
qmlRegisterType<EmojiModel>(uri, 1, 0, "EmojiModel");
qmlRegisterType<CategoryModelFilter>(uri, 1, 0, "CategoryModelFilter");
qmlRegisterType<SearchModelFilter>(uri, 1, 0, "SearchModelFilter");
qmlRegisterType<RecentEmojiModel>(uri, 1, 0, "RecentEmojiModel");
qmlRegisterSingletonType<CopyHelperPrivate>(uri, 1, 0, "CopyHelper", [](QQmlEngine *, QJSEngine *) -> QObject * {
return new CopyHelperPrivate;
});
QQmlApplicationEngine engine;
new EngineWatcher(&engine);
engine.load(QUrl(QStringLiteral("qrc:/ui/emojier.qml")));
QObject::connect(service, &KDBusService::activateRequested, &engine, [&engine](const QStringList & /*arguments*/, const QString & /*workingDirectory*/) {
for (QObject *object : engine.rootObjects()) {
auto w = qobject_cast<QQuickWindow *>(object);
if (!w)
continue;
if (w && QX11Info::isPlatformX11())
KStartupInfo::setNewStartupId(w, QX11Info::nextStartupId());
w->setVisible(true);
w->raise();
}
});
return app.exec();
}
#include "emojier.moc"
#include "emojierplugin.moc"
/*
* SPDX-FileCopyrightText: 2021 Aleix Pol Gonzalez <aleixpol@blue-systems.com>
*
* SPDX-License-Identifier: LGPL-2.0-or-later
*/
#ifndef EMOJIERDECLARATIVEPLUGIN_H
#define EMOJIERDECLARATIVEPLUGIN_H
#include <QQmlExtensionPlugin>
class EmojierDeclarativePlugin : public QQmlExtensionPlugin
{
Q_OBJECT
Q_PLUGIN_METADATA(IID "org.kde.plasma.emoji")
public:
void registerTypes(const char *uri) override;
};
#endif
module org.kde.plasma.emoji
plugin EmojierDeclarativePlugin
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment