Purpose

kdeconnectsmsplugin.cpp
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{
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(QLatin1String("urls")).toArray();
38 QString title = data().value(QLatin1String("title")).toString();
39 QString message = i18n("%1 - %2").arg(title).arg(arrayToList(urlsJson).join(QLatin1Char(' ')));
40
41 auto *job = new KIO::CommandLauncherJob(QStringLiteral("kdeconnect-sms"), {QStringLiteral("--message"), message});
42 job->setDesktopName(QStringLiteral("org.kde.kdeconnect.sms"));
44 job->start();
45 }
46};
47
48class KDEConnectSMSPlugin : public Purpose::PluginBase
49{
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"
void setDesktopName(const QString &desktopName)
void emitResult()
void finished(KJob *job)
#define K_PLUGIN_FACTORY_WITH_JSON(name, jsonFile, pluginRegistrations)
Job that will actually perform the sharing.
Definition job.h:34
QJsonObject data
Represents the data the job will have available to perform its task.
Definition job.h:39
Base class to implement by plugins.
Definition pluginbase.h:29
QString i18n(const char *text, const TYPE &arg...)
QJsonValue value(QLatin1StringView key) const const
QJsonArray toArray() const const
QString toString() const const
Q_OBJECTQ_OBJECT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
QString arg(Args &&... args) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:06 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.