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);
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<QUrl> 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<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 "sendfileitemaction.moc"

View file

@ -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<QAction *> actions(const KFileItemListProperties &fileItemInfos, QWidget *parentWidget) override;
private Q_SLOTS:
void sendFile();
};
#endif // SENDFILEITEMACTION_H