diff --git a/src/plugins/CMakeLists.txt b/src/plugins/CMakeLists.txt --- a/src/plugins/CMakeLists.txt +++ b/src/plugins/CMakeLists.txt @@ -53,3 +53,4 @@ add_subdirectory(email) add_subdirectory(telegram) add_subdirectory(bluetooth) +add_subdirectory(kdeconnect_sms) diff --git a/src/plugins/kdeconnect_sms/CMakeLists.txt b/src/plugins/kdeconnect_sms/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/src/plugins/kdeconnect_sms/CMakeLists.txt @@ -0,0 +1,4 @@ +add_definitions(-DTRANSLATION_DOMAIN=\"purpose_kdeconnectsms\") +add_share_plugin(kdeconnectsmsplugin kdeconnectsmsplugin.cpp) +target_link_libraries(kdeconnectsmsplugin KF5::I18n) + diff --git a/src/plugins/kdeconnect_sms/Messages.sh b/src/plugins/kdeconnect_sms/Messages.sh new file mode 100644 --- /dev/null +++ b/src/plugins/kdeconnect_sms/Messages.sh @@ -0,0 +1,2 @@ +#!/bin/sh +$XGETTEXT `find . -not -path \*/tests/\* -name \*.cpp -o -name \*.qml -o -name \*.cc -o -name \*.h` -o $podir/purpose_kdeconnectsms.pot diff --git a/src/plugins/kdeconnect_sms/kdeconnectsmsplugin.cpp b/src/plugins/kdeconnect_sms/kdeconnectsmsplugin.cpp new file mode 100644 --- /dev/null +++ b/src/plugins/kdeconnect_sms/kdeconnectsmsplugin.cpp @@ -0,0 +1,73 @@ +/* + Copyright 2018 Nicolas Fella + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library 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 + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library. If not, see . +*/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +EXPORT_SHARE_VERSION + +class KDEConnectSMSJob : public Purpose::Job +{ + Q_OBJECT + public: + KDEConnectSMSJob(QObject* parent) + : Purpose::Job(parent) + {} + + QStringList arrayToList(const QJsonArray& array) + { + QStringList ret; + foreach(const QJsonValue& val, array) { + ret += val.toString(); + } + return ret; + } + + void start() override + { + QJsonArray urlsJson = data().value(QStringLiteral("urls")).toArray(); + QString title = data().value(QStringLiteral("title")).toString(); + QString message = i18n("%1 - %2").arg(title).arg(arrayToList(urlsJson).join(QLatin1Char(' '))); + + QProcess::startDetached(QStringLiteral("kdeconnect-sms"), QStringList(QStringLiteral("--message")) << message); + QTimer::singleShot(0, this, &KDEConnectSMSJob::emitResult); + } +}; + +class Q_DECL_EXPORT KDEConnectSMSPlugin : public Purpose::PluginBase +{ + Q_OBJECT + public: + KDEConnectSMSPlugin(QObject* p, const QVariantList& ) : Purpose::PluginBase(p) {} + + Purpose::Job* createJob() const override + { + return new KDEConnectSMSJob(nullptr); + } +}; + +K_PLUGIN_FACTORY_WITH_JSON(KDEConnectSMS, "kdeconnectsmsplugin.json", registerPlugin();) + +#include "kdeconnectsmsplugin.moc" diff --git a/src/plugins/kdeconnect_sms/kdeconnectsmsplugin.json b/src/plugins/kdeconnect_sms/kdeconnectsmsplugin.json new file mode 100644 --- /dev/null +++ b/src/plugins/kdeconnect_sms/kdeconnectsmsplugin.json @@ -0,0 +1,22 @@ +{ + "KPlugin": { + "Authors": [ + { + "Name": "Nicolas Fella" + } + ], + "Category": "Utilities", + "Description": "Send SMS via KDE Connect", + "Icon": "kdeconnect", + "License": "GPL", + "Name": "Send SMS via KDE Connect..." + }, + "X-Purpose-Configuration": [ + ], + "X-Purpose-Constraints": [ + "application:org.kde.kdeconnect.sms.desktop" + ], + "X-Purpose-PluginTypes": [ + "ShareUrl" + ] +}