Add purpose plugin

Implements #182
This commit is contained in:
Tobias Fella
2024-02-10 00:14:56 +01:00
parent 550dc43dc0
commit 6947fbc12a
11 changed files with 257 additions and 19 deletions

View File

@@ -0,0 +1,9 @@
# SPDX-FileCopyrightText: 2024 Tobias Fella <tobias.fella@kde.org>
# SPDX-License-Identifier: BSD-2-Clause
kcoreaddons_add_plugin(neochatplugin SOURCES purposeplugin.cpp INSTALL_NAMESPACE "kf6/purpose")
target_link_libraries(neochatplugin
Qt::DBus
KF6::Purpose
KF6::KIOGui
)

View File

@@ -0,0 +1,55 @@
// SPDX-FileCopyrightText: 2024 Tobias Fella <tobias.fella@kde.org>
// SPDX-License-Identifier: LGPL-2.1-or-later
#include <KIO/CommandLauncherJob>
#include <KPluginFactory>
#include <Purpose/PluginBase>
class NeoChatJob : public Purpose::Job
{
Q_OBJECT
public:
explicit NeoChatJob(QObject *parent)
: Purpose::Job(parent)
{
}
QStringList arrayToList(const QJsonArray &array)
{
QStringList ret;
for (const auto &val : array) {
ret += val.toString();
}
return ret;
}
void start() override
{
const QJsonArray urlsJson = data().value(QStringLiteral("urls")).toArray();
const QString title = data().value(QStringLiteral("title")).toString();
const QString message = QStringLiteral("%1 - %2").arg(title, arrayToList(urlsJson).join(QLatin1Char(' ')));
auto *job = new KIO::CommandLauncherJob(QStringLiteral("neochat"), {QStringLiteral("--share"), message});
connect(job, &KJob::finished, this, &NeoChatJob::emitResult);
job->start();
}
};
class Q_DECL_EXPORT PurposePlugin : public Purpose::PluginBase
{
Q_OBJECT
public:
PurposePlugin(QObject *p, const QVariantList &)
: Purpose::PluginBase(p)
{
}
Purpose::Job *createJob() const override
{
return new NeoChatJob(nullptr);
}
};
K_PLUGIN_CLASS_WITH_JSON(PurposePlugin, "purposeplugin.json")
#include "purposeplugin.moc"

View File

@@ -0,0 +1,18 @@
{
"KPlugin": {
"Authors": [
{
"Name": "Tobias Fella"
}
],
"Category": "Utilities",
"Description": "Share via NeoChat",
"Icon": "org.kde.neochat",
"License": "GPL",
"Name": "NeoChat",
"X-Purpose-ActionDisplay": "NeoChat"
},
"X-Purpose-PluginTypes": [
"ShareUrl"
]
}