[spectacle] /: Add action to open screenshots folder to tools menu

Henrik Fehlauer null at kde.org
Wed Feb 14 22:48:30 UTC 2018


Git commit 7034b50c5c9ef9c97ec0b7741f3667a93d9a567a by Henrik Fehlauer.
Committed on 14/02/2018 at 22:46.
Pushed by rkflx into branch 'master'.

Add action to open screenshots folder to tools menu

Summary:
With {nav Quit after Save or Copy} checked, there is a desktop
notification when saving which allows to open the folder containing the
saved screenshot. However, when the user opts to let the window stay
open, only the title will reflect the filename of the saved screenshot.
It's quite hard to know in which folder it was saved and not that easy
to open that folder.

By introducing {nav Tools > Open Screenshots Folder}, usability in that
regard is much-improved. When no screenshot has been saved yet, it will
open the last {nav Save As} folder or the default {nav Save} location
depending on the button state. As soon as a screenshot is saved, the
new action will highlight the new screenshot in the filemanager.

BUG: 389695

Depends on D10467
Ref T7841

Test Plan:
For {nav Save} and {nav Save As} each, click on new menu entry after
starting Spectacle as well as after saving. Also test everything with
`fish:/` (but beware of Bug 390297).

{F5705490}

Reviewers: #spectacle, ngraham

Reviewed By: #spectacle, ngraham

Subscribers: ngraham

Maniphest Tasks: T7841

Differential Revision: https://phabricator.kde.org/D10470

M  +1    -1    doc/index.docbook
M  +11   -1    src/ExportManager.cpp
M  +3    -1    src/ExportManager.h
M  +29   -1    src/Gui/KSMainWindow.cpp
M  +1    -0    src/Gui/KSMainWindow.h

https://commits.kde.org/spectacle/7034b50c5c9ef9c97ec0b7741f3667a93d9a567a

diff --git a/doc/index.docbook b/doc/index.docbook
index f0630c3..b0af19f 100644
--- a/doc/index.docbook
+++ b/doc/index.docbook
@@ -207,7 +207,7 @@
 				<varlistentry>
 					<term><guibutton>Tools</guibutton></term>
 					<listitem>
-						<para>Clicking on this button shows a drop-down menu, offering access to the print dialog.</para>
+						<para>Clicking on this button shows a drop-down menu, offering access to various functions. You can open the <guimenuitem>Print</guimenuitem> dialog, and <guimenuitem>Open Screenshots Folder</guimenuitem> is a shortcut to highlight the last saved screenshot in the default file manager.</para>
 					</listitem>
 				</varlistentry>
 				<varlistentry>
diff --git a/src/ExportManager.cpp b/src/ExportManager.cpp
index 8f36a4a..fd06325 100644
--- a/src/ExportManager.cpp
+++ b/src/ExportManager.cpp
@@ -41,9 +41,14 @@
 ExportManager::ExportManager(QObject *parent) :
     QObject(parent),
     mSavePixmap(QPixmap()),
+    mLastSavePath(QUrl()),
     mTempFile(QUrl()),
     mTempDir(nullptr)
-{}
+{
+    connect(this, &ExportManager::imageSaved, [this](const QUrl savedAt) {
+        mLastSavePath = savedAt;
+    });
+}
 
 ExportManager::~ExportManager()
 {
@@ -118,6 +123,11 @@ QString ExportManager::saveLocation() const
     return savePath;
 }
 
+QUrl ExportManager::lastSavePath() const
+{
+    return isFileExists(mLastSavePath) ? mLastSavePath : QUrl();
+}
+
 void ExportManager::setSaveLocation(const QString &savePath)
 {
     KSharedConfigPtr config = KSharedConfig::openConfig(QStringLiteral("spectaclerc"));
diff --git a/src/ExportManager.h b/src/ExportManager.h
index 5b45070..8101267 100644
--- a/src/ExportManager.h
+++ b/src/ExportManager.h
@@ -55,6 +55,8 @@ class ExportManager : public QObject
 
     void setSaveLocation(const QString &location);
     QString saveLocation() const;
+    QUrl lastSavePath() const;
+    bool isFileExists(const QUrl &url) const;
     void setPixmap(const QPixmap &pixmap);
     QPixmap pixmap() const;
     QString pixmapDataUri() const;
@@ -88,10 +90,10 @@ class ExportManager : public QObject
     bool save(const QUrl &url);
     bool localSave(const QUrl &url, const QString &mimetype);
     bool remoteSave(const QUrl &url, const QString &mimetype);
-    bool isFileExists(const QUrl &url) const;
     bool isTempFileAlreadyUsed(const QUrl &url) const;
 
     QPixmap mSavePixmap;
+    QUrl mLastSavePath;
     QUrl mTempFile;
     QTemporaryDir *mTempDir;
     QList<QUrl> mUsedTempFileNames;
diff --git a/src/Gui/KSMainWindow.cpp b/src/Gui/KSMainWindow.cpp
index 6c7f37d..8c6aa5b 100644
--- a/src/Gui/KSMainWindow.cpp
+++ b/src/Gui/KSMainWindow.cpp
@@ -40,6 +40,7 @@
 #include <KHelpMenu>
 #include <KAboutData>
 #include <KWindowSystem>
+#include <KIO/OpenFileManagerWindowJob>
 
 #include "SettingsDialog/SettingsDialog.h"
 #include "ExportMenu.h"
@@ -149,7 +150,6 @@ void KSMainWindow::init()
     KGuiItem::assign(mToolsButton, KGuiItem(i18n("Tools")));
     mToolsButton->setIcon(QIcon::fromTheme(QStringLiteral("application-menu")));
     mDialogButtonBox->addButton(mToolsButton, QDialogButtonBox::ActionRole);
-    mToolsMenu->addAction(KStandardAction::print(this, SLOT(showPrintDialog()), this));
     mToolsButton->setMenu(mToolsMenu);
 
     KGuiItem::assign(mSendToButton, KGuiItem(i18n("Export")));
@@ -171,6 +171,13 @@ void KSMainWindow::init()
     KHelpMenu *helpMenu = new KHelpMenu(this, KAboutData::applicationData(), true);
     mDialogButtonBox->button(QDialogButtonBox::Help)->setMenu(helpMenu->menu());
 
+    // the tools menu
+    mToolsMenu->addAction(KStandardAction::print(this, &KSMainWindow::showPrintDialog, this));
+    mToolsMenu->addAction(
+                QIcon::fromTheme(QStringLiteral("document-open-folder")),
+                i18n("Open Screenshots Folder"),
+                this, &KSMainWindow::openScreenshotsFolder);
+
     // the save menu
     mSaveAsAction = KStandardAction::saveAs(this, &KSMainWindow::saveAs, this);
     mSaveAction = KStandardAction::save(this, &KSMainWindow::save, this);
@@ -286,6 +293,27 @@ void KSMainWindow::showPrintDialog()
     delete printer;
 }
 
+void KSMainWindow::openScreenshotsFolder()
+{
+    // Highlight last screenshot in file manager if user saved at least once,
+    // or open default directory as determined by save button
+    QUrl location = ExportManager::instance()->lastSavePath();
+    if (!ExportManager::instance()->isFileExists(location)) {
+        switch(saveButtonMode()) {
+        case SaveMode::Save:
+            location = QUrl::fromLocalFile(ExportManager::instance()->saveLocation() + QStringLiteral("/"));
+            break;
+        case SaveMode::SaveAs:
+            location = SpectacleConfig::instance()->lastSaveAsLocation();
+            break;
+        }
+        if (!ExportManager::instance()->isFileExists(location)) {
+            location = QUrl(QStandardPaths::writableLocation(QStandardPaths::PicturesLocation) + QStringLiteral("/"));
+        }
+    }
+    KIO::highlightInFileManager({location});
+}
+
 void KSMainWindow::showImageSharedFeedback(bool error, const QString &message)
 {
     if (error) {
diff --git a/src/Gui/KSMainWindow.h b/src/Gui/KSMainWindow.h
index 3d8d421..1fb0e1d 100644
--- a/src/Gui/KSMainWindow.h
+++ b/src/Gui/KSMainWindow.h
@@ -50,6 +50,7 @@ class KSMainWindow : public QDialog
 
     void captureScreenshot(ImageGrabber::GrabMode mode, int timeout, bool includePointer, bool includeDecorations);
     void showPrintDialog();
+    void openScreenshotsFolder();
     void showPreferencesDialog();
     void showImageSharedFeedback(bool error, const QString &message);
     void sendToClipboard();


More information about the kde-doc-english mailing list