diff --git a/src/ExportManager.h b/src/ExportManager.h --- a/src/ExportManager.h +++ b/src/ExportManager.h @@ -79,16 +79,16 @@ void errorMessage(const QString &str); void pixmapChanged(const QPixmap &pixmap); void imageSaved(const QUrl &savedAt); - void forceNotify(const QUrl &savedAt); + void imageCopied(); public Q_SLOTS: QUrl getAutosaveFilename(); QUrl tempSave(const QString &mimetype = QStringLiteral("png")); - void doSave(const QUrl &url = QUrl(), bool notify = false); - bool doSaveAs(QWidget *parentWindow = nullptr, bool notify = false); - void doCopyToClipboard(bool notify); + void doSave(const QUrl &url = QUrl()); + bool doSaveAs(QWidget *parentWindow = nullptr); + void doCopyToClipboard(); void doPrint(QPrinter *printer); private: diff --git a/src/ExportManager.cpp b/src/ExportManager.cpp --- a/src/ExportManager.cpp +++ b/src/ExportManager.cpp @@ -436,7 +436,7 @@ // save slots -void ExportManager::doSave(const QUrl &url, bool notify) +void ExportManager::doSave(const QUrl &url) { if (mSavePixmap.isNull()) { emit errorMessage(i18n("Cannot save an empty screenshot image.")); @@ -448,15 +448,11 @@ QDir dir(savePath.path()); dir.cdUp(); SpectacleConfig::instance()->setLastSaveFile(savePath); - emit imageSaved(savePath); - if (notify) { - emit forceNotify(savePath); - } } } -bool ExportManager::doSaveAs(QWidget *parentWindow, bool notify) +bool ExportManager::doSaveAs(QWidget *parentWindow) { QStringList supportedFilters; SpectacleConfig *config = SpectacleConfig::instance(); @@ -485,10 +481,6 @@ if (save(saveUrl)) { emit imageSaved(saveUrl); config->setLastSaveAsFile(saveUrl); - - if (notify) { - emit forceNotify(saveUrl); - } return true; } } @@ -498,16 +490,13 @@ // misc helpers -void ExportManager::doCopyToClipboard(bool notify) +void ExportManager::doCopyToClipboard() { auto data = new QMimeData(); data->setImageData(mSavePixmap.toImage()); data->setData(QStringLiteral("x-kde-force-image-copy"), QByteArray()); QApplication::clipboard()->setMimeData(data, QClipboard::Clipboard); - - if (notify) { - emit forceNotify(QUrl()); - } + emit imageCopied(); } void ExportManager::doPrint(QPrinter *printer) diff --git a/src/Gui/KSMainWindow.h b/src/Gui/KSMainWindow.h --- a/src/Gui/KSMainWindow.h +++ b/src/Gui/KSMainWindow.h @@ -46,12 +46,6 @@ private: - enum class QuitBehavior { - QuitImmediately, - QuitExternally - }; - void quit(const QuitBehavior quitBehavior = QuitBehavior::QuitImmediately); - enum class MessageDuration { AutoHide, Persistent diff --git a/src/Gui/KSMainWindow.cpp b/src/Gui/KSMainWindow.cpp --- a/src/Gui/KSMainWindow.cpp +++ b/src/Gui/KSMainWindow.cpp @@ -327,22 +327,6 @@ KIO::highlightInFileManager({location}); } -void KSMainWindow::quit(const QuitBehavior quitBehavior) -{ - qApp->setQuitOnLastWindowClosed(false); - hide(); - - if (quitBehavior == QuitBehavior::QuitImmediately) { - // Allow some time for clipboard content to transfer - // TODO: Find better solution - QTimer::singleShot(250, qApp, &QApplication::quit); - } - // TODO for else case: - // Currently it is expected that you emit forceNotify, and finally quit - // via a callback through KNotification::action1Activated. However, that - // is not working quite right, see Bug #389694 which needs fixing. -} - void KSMainWindow::showInlineMessage(const QString& message, const KMessageWidget::MessageType messageType, const MessageDuration messageDuration) { mMessageWidget->setText(message); @@ -389,13 +373,11 @@ void KSMainWindow::sendToClipboard() { - bool notify = false; - ExportManager::instance()->doCopyToClipboard(notify); - - SpectacleConfig::instance()->quitAfterSaveOrCopyChecked() - ? quit() - : showInlineMessage(i18n("The screenshot has been copied to the clipboard."), + ExportManager::instance()->doCopyToClipboard(); + if (!SpectacleConfig::instance()->quitAfterSaveOrCopyChecked()) { + showInlineMessage(i18n("The screenshot has been copied to the clipboard."), KMessageWidget::Information); + } } void KSMainWindow::showPreferencesDialog() @@ -414,21 +396,12 @@ { SpectacleConfig::instance()->setLastUsedSaveMode(SaveMode::Save); setDefaultSaveAction(); - - const bool quitChecked = SpectacleConfig::instance()->quitAfterSaveOrCopyChecked(); - ExportManager::instance()->doSave(QUrl(), /* notify */ quitChecked); - if (quitChecked) { - quit(QuitBehavior::QuitExternally); - } + ExportManager::instance()->doSave(QUrl()); } void KSMainWindow::saveAs() { SpectacleConfig::instance()->setLastUsedSaveMode(SaveMode::SaveAs); setDefaultSaveAction(); - - const bool quitChecked = SpectacleConfig::instance()->quitAfterSaveOrCopyChecked(); - if (ExportManager::instance()->doSaveAs(this, /* notify */ quitChecked) && quitChecked) { - quit(QuitBehavior::QuitExternally); - } + ExportManager::instance()->doSaveAs(this); } diff --git a/src/SpectacleCore.h b/src/SpectacleCore.h --- a/src/SpectacleCore.h +++ b/src/SpectacleCore.h @@ -72,6 +72,7 @@ private: void initGui(); + void imageExported(const QUrl &savedAt); ExportManager *mExportManager; StartMode mStartMode; diff --git a/src/SpectacleCore.cpp b/src/SpectacleCore.cpp --- a/src/SpectacleCore.cpp +++ b/src/SpectacleCore.cpp @@ -98,8 +98,6 @@ connect(mImageGrabber, &ImageGrabber::windowTitleChanged, mExportManager, &ExportManager::setWindowTitle); connect(mImageGrabber, &ImageGrabber::imageGrabFailed, this, &SpectacleCore::screenshotFailed); connect(mExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doCopyPath); - connect(mExportManager, &ExportManager::forceNotify, this, &SpectacleCore::doNotify); - switch (startMode) { case DBusMode: default: @@ -216,16 +214,16 @@ { if (mNotify) { connect(mExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doNotify); + connect(mExportManager, &ExportManager::imageCopied, this, [this]{doNotify(QUrl());}); } if (copyToClipboard) { - mExportManager->doCopyToClipboard(mNotify); + mExportManager->doCopyToClipboard(); } else { QUrl savePath = (mStartMode == BackgroundMode && mFileNameUrl.isValid() && mFileNameUrl.isLocalFile()) ? mFileNameUrl : QUrl(); - mExportManager->doSave(savePath); + mExportManager->doSave(savePath); } - // if we notify, we emit allDone only if the user either dismissed the notification or pressed // the "Open" button, otherwise the app closes before it can react to it. if (!mNotify) { @@ -339,8 +337,21 @@ connect(mMainWindow, &KSMainWindow::newScreenshotRequest, this, &SpectacleCore::takeNewScreenshot); connect(mMainWindow, &KSMainWindow::dragAndDropRequest, this, &SpectacleCore::doStartDragAndDrop); - + connect(mExportManager, &ExportManager::imageSaved, this, &SpectacleCore::imageExported); + connect(mExportManager, &ExportManager::imageCopied, this, [this] { + copyToClipboard = true; + imageExported(QUrl()); + }); isGuiInited = true; QMetaObject::invokeMethod(mImageGrabber, "doImageGrab", Qt::QueuedConnection); } } + +void SpectacleCore::imageExported(const QUrl &savedAt) +{ + if (SpectacleConfig::instance()->quitAfterSaveOrCopyChecked()) { + qApp->setQuitOnLastWindowClosed(false); + mMainWindow->hide(); + doNotify(savedAt); + } +}