File indexing completed on 2024-04-21 04:55:35

0001 /*
0002     SPDX-FileCopyrightText: 2019 Nicolas Fella <nicolas.fella@gmx.de>
0003 
0004     SPDX-License-Identifier: LGPL-2.1-or-later
0005 */
0006 
0007 #include <QDBusInterface>
0008 #include <QJsonArray>
0009 #include <QTimer>
0010 
0011 #include <KPluginFactory>
0012 
0013 #include <Purpose/PluginBase>
0014 
0015 #include "choqokinterface.h"
0016 EXPORT_SHARE_VERSION
0017 
0018 class ChoqokJob : public Purpose::Job
0019 {
0020     Q_OBJECT
0021     public:
0022         ChoqokJob(QObject* parent)
0023             : Purpose::Job(parent)
0024         {}
0025 
0026         QStringList arrayToList(const QJsonArray& array)
0027         {
0028             QStringList ret;
0029             for (const QJsonValue& val : array) {
0030                 ret += val.toString();
0031             }
0032             return ret;
0033         }
0034 
0035         void start() override
0036         {
0037             OrgKdeChoqokInterface iface(QStringLiteral("org.kde.choqok"), QStringLiteral("/"), QDBusConnection::sessionBus(), this);
0038             const QStringList urls = arrayToList(data().value(QStringLiteral("urls")).toArray());
0039 
0040             for (const QString &url : urls) {
0041                 iface.uploadFile(url);
0042             }
0043 
0044             QTimer::singleShot(0, this, [this]() {
0045                 emitResult();
0046             });
0047         }
0048 };
0049 
0050 
0051 class Q_DECL_EXPORT PurposePlugin : public Purpose::PluginBase
0052 {
0053 
0054     Q_OBJECT
0055 public:
0056     PurposePlugin(QObject* p, const QVariantList& ) : Purpose::PluginBase(p) {}
0057 
0058     Purpose::Job* createJob() const override
0059     {
0060         return new ChoqokJob(nullptr);
0061     }
0062 
0063 };
0064 
0065 K_PLUGIN_CLASS_WITH_JSON(PurposePlugin, "purposeplugin.json")
0066 
0067 #include "purposeplugin.moc"