From 61e7d8f2f32966502cd64aff67a371e84e821c65 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABlle=20van=20Essen?= Date: Mon, 22 Jul 2024 22:24:53 +0000 Subject: [PATCH] indicator: Simplify sending files from systray icon Implements https://invent.kde.org/network/kdeconnect-meta/-/issues/10 --- indicator/deviceindicator.cpp | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/indicator/deviceindicator.cpp b/indicator/deviceindicator.cpp index 67a53345f..bda4ec512 100644 --- a/indicator/deviceindicator.cpp +++ b/indicator/deviceindicator.cpp @@ -92,14 +92,24 @@ DeviceIndicator::DeviceIndicator(DeviceDbusInterface *device) this); // Send file - const QString kdeconnectHandlerExecutable = QStandardPaths::findExecutable(QStringLiteral("kdeconnect-handler"), {QCoreApplication::applicationDirPath()}); - if (!kdeconnectHandlerExecutable.isEmpty()) { - auto handlerApp = addAction(QIcon::fromTheme(QStringLiteral("document-share")), i18n("Send a file/URL")); - QObject::connect(handlerApp, &QAction::triggered, device, [device, kdeconnectHandlerExecutable]() { - QProcess::startDetached(kdeconnectHandlerExecutable, {QStringLiteral("--device"), device->id()}); - }); - handlerApp->setVisible(true); - } + auto sendFile = addAction(QIcon::fromTheme(QStringLiteral("document-share")), i18n("Send files")); + connect(sendFile, &QAction::triggered, device, [device, this]() { + const QList urls = QFileDialog::getOpenFileUrls(this); + if (!urls.isEmpty()) { + QStringList urlsAsQStringList; + for (const QUrl &url : urls) + urlsAsQStringList.append(url.toString()); + ShareDbusInterface *iface = new ShareDbusInterface(device->id(), device); + iface->shareUrls(urlsAsQStringList); + iface->deleteLater(); + } + }); + setWhenAvailable( + device->hasPlugin(QStringLiteral("kdeconnect_share")), + [sendFile](bool available) { + sendFile->setVisible(available); + }, + this); // SMS Messages const QString kdeconnectsmsExecutable = QStandardPaths::findExecutable(QStringLiteral("kdeconnect-sms"), {QCoreApplication::applicationDirPath()});