diff --git a/src/core/capturerequest.cpp b/src/core/capturerequest.cpp index 9aac9374..e493cb77 100644 --- a/src/core/capturerequest.cpp +++ b/src/core/capturerequest.cpp @@ -95,7 +95,7 @@ CaptureRequest::exportCapture(const QPixmap& p) if (m_path.isEmpty()) { ScreenshotSaver().saveToFilesystemGUI(p); } else { - ScreenshotSaver().saveToFilesystem(p, m_path); + ScreenshotSaver().saveToFilesystem(p, m_path, ""); } } diff --git a/src/tools/save/savetool.cpp b/src/tools/save/savetool.cpp index 28a5a629..80c6ceb5 100644 --- a/src/tools/save/savetool.cpp +++ b/src/tools/save/savetool.cpp @@ -71,7 +71,7 @@ SaveTool::pressed(const CaptureContext& context) } } else { bool ok = ScreenshotSaver().saveToFilesystem( - context.selectedScreenshotArea(), context.savePath); + context.selectedScreenshotArea(), context.savePath, ""); if (ok) { emit requestAction(REQ_CAPTURE_DONE_OK); } diff --git a/src/utils/screenshotsaver.cpp b/src/utils/screenshotsaver.cpp index 79c8ad7b..59470793 100644 --- a/src/utils/screenshotsaver.cpp +++ b/src/utils/screenshotsaver.cpp @@ -30,19 +30,27 @@ ScreenshotSaver::ScreenshotSaver() {} void ScreenshotSaver::saveToClipboard(const QPixmap& capture) { - if (ConfigHandler().saveAfterCopyValue()) { - if (!ConfigHandler().saveAfterCopyPathValue().isEmpty()) { - saveToFilesystem(capture, ConfigHandler().saveAfterCopyPathValue()); - } - } else { + + // If we are able to properly save the file, save the file and copy to + // clipboard. + if ((ConfigHandler().saveAfterCopyValue()) && + (!ConfigHandler().saveAfterCopyPathValue().isEmpty())) { + QApplication::clipboard()->setPixmap(capture); + saveToFilesystem(capture, + ConfigHandler().saveAfterCopyPathValue(), + QObject::tr("Capture saved to clipboard. ")); + } + // Otherwise only save to clipboard + else { + QApplication::clipboard()->setPixmap(capture); SystemNotification().sendMessage(QObject::tr("Capture saved to clipboard")); } - - QApplication::clipboard()->setPixmap(capture); } bool -ScreenshotSaver::saveToFilesystem(const QPixmap& capture, const QString& path) +ScreenshotSaver::saveToFilesystem(const QPixmap& capture, + const QString& path, + const QString& messagePrefix) { QString completePath = FileNameHandler().generateAbsolutePath(path); completePath += QLatin1String(".png"); @@ -52,9 +60,11 @@ ScreenshotSaver::saveToFilesystem(const QPixmap& capture, const QString& path) if (ok) { ConfigHandler().setSavePath(path); - saveMessage = QObject::tr("Capture saved as ") + completePath; + saveMessage = + messagePrefix + QObject::tr("Capture saved as ") + completePath; } else { - saveMessage = QObject::tr("Error trying to save as ") + completePath; + saveMessage = + messagePrefix + QObject::tr("Error trying to save as ") + completePath; notificationPath = ""; } diff --git a/src/utils/screenshotsaver.h b/src/utils/screenshotsaver.h index fdab15de..99410e94 100644 --- a/src/utils/screenshotsaver.h +++ b/src/utils/screenshotsaver.h @@ -26,6 +26,8 @@ public: ScreenshotSaver(); void saveToClipboard(const QPixmap& capture); - bool saveToFilesystem(const QPixmap& capture, const QString& path); + bool saveToFilesystem(const QPixmap& capture, + const QString& path, + const QString& messagePrefix); bool saveToFilesystemGUI(const QPixmap& capture); }; diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index 6a21e84a..52fd2207 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -1011,7 +1011,7 @@ CaptureWidget::saveScreenshot() if (m_context.savePath.isEmpty()) { ScreenshotSaver().saveToFilesystemGUI(pixmap()); } else { - ScreenshotSaver().saveToFilesystem(pixmap(), m_context.savePath); + ScreenshotSaver().saveToFilesystem(pixmap(), m_context.savePath, ""); } close(); }