1/*
2 SPDX-FileCopyrightText: 2018 Nicolas Fella <nicolas.fella@gmx.de>
3
4 SPDX-License-Identifier: LGPL-2.1-or-later
5*/
6
7#include <KIO/CommandLauncherJob>
8#include <KLocalizedString>
9#include <KPluginFactory>
10
11#include <QJsonArray>
12#include <QProcess>
13#include <QStandardPaths>
14#include <QTimer>
15#include <purpose/pluginbase.h>
16
17class KDEConnectSMSJob : public Purpose::Job
18{
19 Q_OBJECT
20public:
21 KDEConnectSMSJob(QObject *parent)
22 : Purpose::Job(parent)
23 {
24 }
25
26 QStringList arrayToList(const QJsonArray &array)
27 {
28 QStringList ret;
29 for (const QJsonValue &val : array) {
30 ret += val.toString();
31 }
32 return ret;
33 }
34
35 void start() override
36 {
37 QJsonArray urlsJson = data().value(key: QLatin1String("urls")).toArray();
38 QString title = data().value(key: QLatin1String("title")).toString();
39 QString message = i18n("%1 - %2").arg(a: title).arg(a: arrayToList(array: urlsJson).join(sep: QLatin1Char(' ')));
40
41 auto *job = new KIO::CommandLauncherJob(QStringLiteral("kdeconnect-sms"), {QStringLiteral("--message"), message});
42 job->setDesktopName(QStringLiteral("org.kde.kdeconnect.sms"));
43 connect(sender: job, signal: &KJob::finished, context: this, slot: &KDEConnectSMSJob::emitResult);
44 job->start();
45 }
46};
47
48class KDEConnectSMSPlugin : public Purpose::PluginBase
49{
50 Q_OBJECT
51public:
52 using PluginBase::PluginBase;
53 Purpose::Job *createJob() const override
54 {
55 return new KDEConnectSMSJob(nullptr);
56 }
57};
58
59K_PLUGIN_FACTORY_WITH_JSON(KDEConnectSMS, "kdeconnectsmsplugin.json", registerPlugin<KDEConnectSMSPlugin>();)
60
61#include "kdeconnectsmsplugin.moc"
62

source code of purpose/src/plugins/kdeconnect_sms/kdeconnectsmsplugin.cpp