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:
parent
01300d8f47
commit
13ff8832fb
2 changed files with 12 additions and 21 deletions
|
@ -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"
|
||||||
|
|
|
@ -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
|
||||||
|
|
Loading…
Reference in a new issue