From 13ff8832fb9729515afca0cd97fd70ebe6d6839e Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Sat, 12 Aug 2023 13:31:12 +0200 Subject: [PATCH] fileitemactionplugin: Use lambda connect to avoid ugly workarounds Setting properties and using QObject::sender is quite ugly API and not needed in modern code --- fileitemactionplugin/sendfileitemaction.cpp | 28 ++++++++------------- fileitemactionplugin/sendfileitemaction.h | 5 +--- 2 files changed, 12 insertions(+), 21 deletions(-) diff --git a/fileitemactionplugin/sendfileitemaction.cpp b/fileitemactionplugin/sendfileitemaction.cpp index 60ba0df8e..22a96c15e 100644 --- a/fileitemactionplugin/sendfileitemaction.cpp +++ b/fileitemactionplugin/sendfileitemaction.cpp @@ -54,9 +54,17 @@ QList SendFileItemAction::actions(const KFileItemListProperties &file } QAction *action = new QAction(QIcon::fromTheme(deviceIface.iconName()), deviceIface.name(), parentWidget); action->setProperty("id", id); - action->setProperty("urls", QVariant::fromValue(fileItemInfos.urlList())); - action->setProperty("parentWidget", QVariant::fromValue(parentWidget)); - connect(action, &QAction::triggered, this, &SendFileItemAction::sendFile); + const QList urls = fileItemInfos.urlList(); + connect(action, &QAction::triggered, this, [id, urls]() { + 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")); + msg.setArguments(QVariantList{url.toString()}); + QDBusConnection::sessionBus().asyncCall(msg); + } + }); actions += action; } @@ -74,19 +82,5 @@ QList SendFileItemAction::actions(const KFileItemListProperties &file } } -void SendFileItemAction::sendFile() -{ - const QList urls = sender()->property("urls").value>(); - QString id = sender()->property("id").toString(); - 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")); - msg.setArguments(QVariantList{url.toString()}); - QDBusConnection::sessionBus().asyncCall(msg); - } -} - #include "moc_sendfileitemaction.cpp" #include "sendfileitemaction.moc" diff --git a/fileitemactionplugin/sendfileitemaction.h b/fileitemactionplugin/sendfileitemaction.h index fe003b7e1..1899b260a 100644 --- a/fileitemactionplugin/sendfileitemaction.h +++ b/fileitemactionplugin/sendfileitemaction.h @@ -19,11 +19,8 @@ class SendFileItemAction : public KAbstractFileItemActionPlugin { Q_OBJECT public: - SendFileItemAction(QObject *parent, const QVariantList &args); + SendFileItemAction(QObject *parent, const QVariantList &args); // TODO KF6 remove args QList actions(const KFileItemListProperties &fileItemInfos, QWidget *parentWidget) override; - -private Q_SLOTS: - void sendFile(); }; #endif // SENDFILEITEMACTION_H