From 5174f8dc1b090cb6db687c83689e71223c3db247 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Gro=C3=9F?= Date: Wed, 20 Mar 2019 22:41:55 +0100 Subject: [PATCH] Allow notification to be dragged and dropped (#473) * Set x-kde-urls for notifications The x-kde-urls field in the hints map allows us to provide a direct URL to the saved screenshot. The notification server may then use this hint to provide extra functionality, such as drag and drop support and thumbnails. For more information see https://community.kde.org/Plasma/Notifications#File_Path Fixes #256 Note that other notification servers may ignore this hint. * Avoid branching twice for ok --- src/utils/screenshotsaver.cpp | 6 ++++-- src/utils/systemnotification.cpp | 14 +++++++++++--- src/utils/systemnotification.h | 4 +++- 3 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/utils/screenshotsaver.cpp b/src/utils/screenshotsaver.cpp index 898b010a..6c9bd989 100644 --- a/src/utils/screenshotsaver.cpp +++ b/src/utils/screenshotsaver.cpp @@ -41,15 +41,17 @@ bool ScreenshotSaver::saveToFilesystem(const QPixmap &capture, completePath += QLatin1String(".png"); bool ok = capture.save(completePath); QString saveMessage; + QString notificationPath = completePath; if (ok) { ConfigHandler().setSavePath(path); saveMessage = QObject::tr("Capture saved as ") + completePath; } else { saveMessage = QObject::tr("Error trying to save as ") + completePath; + notificationPath = ""; } - SystemNotification().sendMessage(saveMessage); + SystemNotification().sendMessage(saveMessage, notificationPath); return ok; } @@ -80,7 +82,7 @@ bool ScreenshotSaver::saveToFilesystemGUI(const QPixmap &capture) { QString pathNoFile = savePath.left(savePath.lastIndexOf(QLatin1String("/"))); ConfigHandler().setSavePath(pathNoFile); QString msg = QObject::tr("Capture saved as ") + savePath; - SystemNotification().sendMessage(msg); + SystemNotification().sendMessage(msg, savePath); } else { QString msg = QObject::tr("Error trying to save as ") + savePath; QMessageBox saveErrBox( diff --git a/src/utils/systemnotification.cpp b/src/utils/systemnotification.cpp index c35a4574..41a549d2 100644 --- a/src/utils/systemnotification.cpp +++ b/src/utils/systemnotification.cpp @@ -1,6 +1,7 @@ #include "systemnotification.h" #include "src/utils/confighandler.h" #include +#include #ifndef Q_OS_WIN #include @@ -24,13 +25,14 @@ SystemNotification::SystemNotification(QObject *parent) : QObject(parent) { } #endif -void SystemNotification::sendMessage(const QString &text) { - sendMessage(text, tr("Flameshot Info")); +void SystemNotification::sendMessage(const QString &text, const QString &savePath) { + sendMessage(text, tr("Flameshot Info"), savePath); } void SystemNotification::sendMessage( const QString &text, const QString &title, + const QString &savePath, const int timeout) { if(!ConfigHandler().desktopNotificationValue()) { @@ -39,13 +41,19 @@ void SystemNotification::sendMessage( #ifndef Q_OS_WIN QList args; + QVariantMap hintsMap; + if (!savePath.isEmpty()) { + QUrl fullPath = QUrl::fromLocalFile(savePath); + // allows the notification to be dragged and dropped + hintsMap[QStringLiteral("x-kde-urls")] = QStringList({fullPath.toString()}); + } args << (qAppName()) //appname << static_cast(0) //id << "flameshot" //icon << title //summary << text //body << QStringList() //actions - << QVariantMap() //hints + << hintsMap //hints << timeout; //timeout m_interface->callWithArgumentList(QDBus::AutoDetect, QStringLiteral("Notify"), args); #else diff --git a/src/utils/systemnotification.h b/src/utils/systemnotification.h index 5c2ecb3f..b018246b 100644 --- a/src/utils/systemnotification.h +++ b/src/utils/systemnotification.h @@ -26,10 +26,12 @@ class SystemNotification : public QObject { public: explicit SystemNotification(QObject *parent = nullptr); - void sendMessage(const QString &text); + void sendMessage(const QString &text, + const QString &savePath = {}); void sendMessage(const QString &text, const QString &title, + const QString &savePath, const int timeout = 5000); private: