diff --git a/src/SpectacleCore.cpp b/src/SpectacleCore.cpp --- a/src/SpectacleCore.cpp +++ b/src/SpectacleCore.cpp @@ -26,14 +26,16 @@ #include #include #include +#include #include #include #include #include #include #include -#include +#include +#include #include "Config.h" #include "PlatformBackends/DummyImageGrabber.h" @@ -242,22 +244,45 @@ break; } - const QString &path = savedAt.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash).path(); + const QUrl &pathURL = savedAt.adjusted(QUrl::RemoveFilename | QUrl::StripTrailingSlash); + const QString &path = pathURL.path(); // a speaking message is prettier than a URL, special case for the default pictures location if (path == QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)) { notify->setText(i18nc("Placeholder is filename", "A screenshot was saved as '%1' to your Pictures folder.", savedAt.fileName())); } else { notify->setText(i18n("A screenshot was saved as '%1' to '%2'.", savedAt.fileName(), path)); } - notify->setActions({i18nc("Open the screenshot we just saved", "Open")}); + const QStringList actions = { + i18nc("Open the screenshot we just saved", "Open"), + i18nc("Show the screenshot in the folder where it was saved", "Show in folder") + }; + notify->setActions(actions); notify->setUrls({savedAt}); + // "Open screenshot" action connect(notify, &KNotification::action1Activated, this, [this, savedAt] { new KRun(savedAt, nullptr); QTimer::singleShot(250, this, &SpectacleCore::allDone); }); + + // "Show in folder" action + connect(notify, &KNotification::action2Activated, this, [this, pathURL, savedAt] { + const KService::Ptr service = KMimeTypeTrader::self()->preferredService("inode/directory"); + const QString defaultFileManager = service->desktopEntryName(); + if (defaultFileManager.startsWith(QString("org.kde.dolphin"))) { + // Dolphin is the default file manager, so execute `dolphin --select [path to file]` + // Which will open Dolphin showing the containing directory with the file selected + const QStringList args = {QString("--select"), savedAt.path()}; + QProcess::startDetached(QString("dolphin"), args); + } else { + // Fall back to just opening the parent directory, and accept that the file won't be selected + new KRun(pathURL, nullptr); + } + + QTimer::singleShot(250, this, &SpectacleCore::allDone); + }); connect(notify, &QObject::destroyed, this, &SpectacleCore::allDone); notify->sendEvent();