2019-04-15 21:36:34 +01:00
|
|
|
/*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-FileCopyrightText: 2011 Alejandro Fiestas Olivares <afiestas@kde.org>
|
|
|
|
* SPDX-FileCopyrightText: 2014 Aleix Pol Gonzalez <aleixpol@kde.org>
|
2019-04-15 21:36:34 +01:00
|
|
|
*
|
2020-08-17 10:48:10 +01:00
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
2019-04-15 21:36:34 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "sendfileitemaction.h"
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QAction>
|
|
|
|
#include <QIcon>
|
2019-04-15 21:36:34 +01:00
|
|
|
#include <QList>
|
|
|
|
#include <QMenu>
|
|
|
|
#include <QUrl>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <QVariantList>
|
|
|
|
#include <QWidget>
|
2019-04-15 21:36:34 +01:00
|
|
|
|
|
|
|
#include <KLocalizedString>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <KPluginFactory>
|
2019-04-15 21:36:34 +01:00
|
|
|
|
|
|
|
#include <interfaces/dbusinterfaces.h>
|
2022-09-10 22:23:52 +01:00
|
|
|
#include <interfaces/devicesmodel.h>
|
2019-04-15 21:36:34 +01:00
|
|
|
|
2019-06-09 16:28:49 +01:00
|
|
|
#include <dbushelper.h>
|
|
|
|
|
2020-05-26 17:55:47 +01:00
|
|
|
#include "kdeconnect_fileitemaction_debug.h"
|
2019-04-15 21:36:34 +01:00
|
|
|
|
2020-05-26 17:55:47 +01:00
|
|
|
K_PLUGIN_CLASS_WITH_JSON(SendFileItemAction, "kdeconnectsendfile.json")
|
2019-04-15 21:36:34 +01:00
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
SendFileItemAction::SendFileItemAction(QObject *parent, const QVariantList &)
|
|
|
|
: KAbstractFileItemActionPlugin(parent)
|
2019-04-15 21:36:34 +01:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-09-10 22:23:52 +01:00
|
|
|
QList<QAction *> SendFileItemAction::actions(const KFileItemListProperties &fileItemInfos, QWidget *parentWidget)
|
2019-04-15 21:36:34 +01:00
|
|
|
{
|
2022-09-10 22:23:52 +01:00
|
|
|
QList<QAction *> actions;
|
2019-04-15 21:36:34 +01:00
|
|
|
|
|
|
|
DaemonDbusInterface iface;
|
|
|
|
if (!iface.isValid()) {
|
|
|
|
return actions;
|
|
|
|
}
|
|
|
|
|
|
|
|
QDBusPendingReply<QStringList> reply = iface.devices(true, true);
|
|
|
|
reply.waitForFinished();
|
|
|
|
const QStringList devices = reply.value();
|
2022-09-10 22:23:52 +01:00
|
|
|
for (const QString &id : devices) {
|
2019-04-15 21:36:34 +01:00
|
|
|
DeviceDbusInterface deviceIface(id);
|
|
|
|
if (!deviceIface.isValid()) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (!deviceIface.hasPlugin(QStringLiteral("kdeconnect_share"))) {
|
|
|
|
continue;
|
|
|
|
}
|
2022-09-10 22:23:52 +01:00
|
|
|
QAction *action = new QAction(QIcon::fromTheme(deviceIface.iconName()), deviceIface.name(), parentWidget);
|
2019-04-15 21:36:34 +01:00
|
|
|
action->setProperty("id", id);
|
|
|
|
action->setProperty("urls", QVariant::fromValue(fileItemInfos.urlList()));
|
|
|
|
action->setProperty("parentWidget", QVariant::fromValue(parentWidget));
|
|
|
|
connect(action, &QAction::triggered, this, &SendFileItemAction::sendFile);
|
|
|
|
actions += action;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (actions.count() > 1) {
|
2022-09-10 22:23:52 +01:00
|
|
|
QAction *menuAction = new QAction(QIcon::fromTheme(QStringLiteral("kdeconnect")), i18n("Send via KDE Connect"), parentWidget);
|
|
|
|
QMenu *menu = new QMenu(parentWidget);
|
2019-04-15 21:36:34 +01:00
|
|
|
menu->addActions(actions);
|
|
|
|
menuAction->setMenu(menu);
|
2022-09-10 22:23:52 +01:00
|
|
|
return QList<QAction *>() << menuAction;
|
2019-04-15 21:36:34 +01:00
|
|
|
} else {
|
2022-09-10 22:23:52 +01:00
|
|
|
if (actions.count() == 1) {
|
2019-04-15 21:36:34 +01:00
|
|
|
actions.first()->setText(i18n("Send to '%1' via KDE Connect", actions.first()->text()));
|
|
|
|
}
|
|
|
|
return actions;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SendFileItemAction::sendFile()
|
|
|
|
{
|
|
|
|
const QList<QUrl> urls = sender()->property("urls").value<QList<QUrl>>();
|
|
|
|
QString id = sender()->property("id").toString();
|
2022-09-10 22:23:52 +01:00
|
|
|
for (const QUrl &url : urls) {
|
|
|
|
QDBusMessage msg = QDBusMessage::createMethodCall(QStringLiteral("org.kde.kdeconnect"),
|
|
|
|
QStringLiteral("/modules/kdeconnect/devices/") + id + QStringLiteral("/share"),
|
|
|
|
QStringLiteral("org.kde.kdeconnect.device.share"),
|
|
|
|
QStringLiteral("shareUrl"));
|
2023-07-25 20:45:36 +01:00
|
|
|
msg.setArguments(QVariantList{url.toString()});
|
2022-04-12 06:40:03 +01:00
|
|
|
QDBusConnection::sessionBus().asyncCall(msg);
|
2019-04-15 21:36:34 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#include "sendfileitemaction.moc"
|