fileitemactionplugin: Use lambda connect to avoid ugly workarounds

Setting properties and using QObject::sender is quite ugly API and not needed in modern code
This commit is contained in:
Alexander Lohnau 2023-08-12 13:31:12 +02:00 committed by Albert Vaca Cintora
parent 01300d8f47
commit 13ff8832fb
2 changed files with 12 additions and 21 deletions

View file

@ -54,9 +54,17 @@ QList<QAction *> SendFileItemAction::actions(const KFileItemListProperties &file
} }
QAction *action = new QAction(QIcon::fromTheme(deviceIface.iconName()), deviceIface.name(), parentWidget); QAction *action = new QAction(QIcon::fromTheme(deviceIface.iconName()), deviceIface.name(), parentWidget);
action->setProperty("id", id); action->setProperty("id", id);
action->setProperty("urls", QVariant::fromValue(fileItemInfos.urlList())); const QList<QUrl> urls = fileItemInfos.urlList();
action->setProperty("parentWidget", QVariant::fromValue(parentWidget)); connect(action, &QAction::triggered, this, [id, urls]() {
connect(action, &QAction::triggered, this, &SendFileItemAction::sendFile); 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; actions += action;
} }
@ -74,19 +82,5 @@ QList<QAction *> SendFileItemAction::actions(const KFileItemListProperties &file
} }
} }
void SendFileItemAction::sendFile()
{
const QList<QUrl> urls = sender()->property("urls").value<QList<QUrl>>();
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 "moc_sendfileitemaction.cpp"
#include "sendfileitemaction.moc" #include "sendfileitemaction.moc"

View file

@ -19,11 +19,8 @@ class SendFileItemAction : public KAbstractFileItemActionPlugin
{ {
Q_OBJECT Q_OBJECT
public: public:
SendFileItemAction(QObject *parent, const QVariantList &args); SendFileItemAction(QObject *parent, const QVariantList &args); // TODO KF6 remove args
QList<QAction *> actions(const KFileItemListProperties &fileItemInfos, QWidget *parentWidget) override; QList<QAction *> actions(const KFileItemListProperties &fileItemInfos, QWidget *parentWidget) override;
private Q_SLOTS:
void sendFile();
}; };
#endif // SENDFILEITEMACTION_H #endif // SENDFILEITEMACTION_H