diff --git a/src/ExportManager.h b/src/ExportManager.h --- a/src/ExportManager.h +++ b/src/ExportManager.h @@ -26,6 +26,8 @@ #include #include +#include "PlatformBackends/ImageGrabber.h" + class QTemporaryDir; class ExportManager : public QObject @@ -52,14 +54,20 @@ Q_PROPERTY(QString saveLocation READ saveLocation WRITE setSaveLocation NOTIFY saveLocationChanged) Q_PROPERTY(QPixmap pixmap READ pixmap WRITE setPixmap NOTIFY pixmapChanged) + Q_PROPERTY(QString windowTitle READ windowTitle WRITE setWindowTitle) + Q_PROPERTY(ImageGrabber::GrabMode grabMode READ grabMode WRITE setGrabMode) 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; + void setWindowTitle(const QString &windowTitle); + QString windowTitle() const; + ImageGrabber::GrabMode grabMode() const; + void setGrabMode(const ImageGrabber::GrabMode &grabMode); signals: @@ -97,6 +105,8 @@ QUrl mTempFile; QTemporaryDir *mTempDir; QList mUsedTempFileNames; + QString mWindowTitle; + ImageGrabber::GrabMode mGrabMode; }; #endif // EXPORTMANAGER_H diff --git a/src/ExportManager.cpp b/src/ExportManager.cpp --- a/src/ExportManager.cpp +++ b/src/ExportManager.cpp @@ -87,6 +87,26 @@ return uri; } +void ExportManager::setWindowTitle(const QString &windowTitle) +{ + mWindowTitle = windowTitle; +} + +QString ExportManager::windowTitle() const +{ + return mWindowTitle; +} + +ImageGrabber::GrabMode ExportManager::grabMode() const +{ + return mGrabMode; +} + +void ExportManager::setGrabMode(const ImageGrabber::GrabMode &grabMode) +{ + mGrabMode = grabMode; +} + void ExportManager::setPixmap(const QPixmap &pixmap) { mSavePixmap = pixmap; @@ -159,15 +179,38 @@ KConfigGroup generalConfig = KConfigGroup(config, "General"); const QDateTime timestamp = QDateTime::currentDateTime(); - QString baseName = generalConfig.readEntry("save-filename-format", "Screenshot_%Y%M%D_%H%m%S"); + QString baseName = generalConfig.readEntry("save-filename-format", "%Y-%M-%D %H-%m-%S. %T"); + + QString title; + + switch (mGrabMode) { + case ImageGrabber::GrabMode::ActiveWindow: + case ImageGrabber::GrabMode::TransientWithParent: + case ImageGrabber::GrabMode::WindowUnderCursor: + title = mWindowTitle; + break; + case ImageGrabber::GrabMode::CurrentScreen: + title = QStringLiteral("Desktop"); + break; + case ImageGrabber::GrabMode::FullScreen: + title = QStringLiteral("Full screen"); + break; + case ImageGrabber::GrabMode::RectangularRegion: + title = QStringLiteral("Region"); + break; + default: + title = QStringLiteral("Screenshot"); + break; + } return baseName.replace(QLatin1String("%Y"), timestamp.toString(QStringLiteral("yyyy"))) .replace(QLatin1String("%y"), timestamp.toString(QStringLiteral("yy"))) .replace(QLatin1String("%M"), timestamp.toString(QStringLiteral("MM"))) .replace(QLatin1String("%D"), timestamp.toString(QStringLiteral("dd"))) .replace(QLatin1String("%H"), timestamp.toString(QStringLiteral("hh"))) .replace(QLatin1String("%m"), timestamp.toString(QStringLiteral("mm"))) - .replace(QLatin1String("%S"), timestamp.toString(QStringLiteral("ss"))); + .replace(QLatin1String("%S"), timestamp.toString(QStringLiteral("ss"))) + .replace(QLatin1String("%T"), title); } QString ExportManager::autoIncrementFilename(const QString &baseName, const QString &extension, diff --git a/src/Gui/SettingsDialog/SaveOptionsPage.cpp b/src/Gui/SettingsDialog/SaveOptionsPage.cpp --- a/src/Gui/SettingsDialog/SaveOptionsPage.cpp +++ b/src/Gui/SettingsDialog/SaveOptionsPage.cpp @@ -104,6 +104,7 @@ "%H: Hour
" "%m: Minute
" "%S: Second" + "%W: Window caption" "" ); diff --git a/src/PlatformBackends/ImageGrabber.h b/src/PlatformBackends/ImageGrabber.h --- a/src/PlatformBackends/ImageGrabber.h +++ b/src/PlatformBackends/ImageGrabber.h @@ -67,6 +67,7 @@ signals: void pixmapChanged(const QPixmap &pixmap); + void windowTitleChanged(const QString &windowTitle); void imageGrabFailed(); void capturePointerChanged(bool capturePointer); void captureDecorationsChanged(bool captureDecorations); @@ -91,6 +92,7 @@ bool mCaptureDecorations; GrabMode mGrabMode; QPixmap mPixmap; + QString mWindowTitle; }; #endif // IMAGEGRABBER_H diff --git a/src/PlatformBackends/X11ImageGrabber.cpp b/src/PlatformBackends/X11ImageGrabber.cpp --- a/src/PlatformBackends/X11ImageGrabber.cpp +++ b/src/PlatformBackends/X11ImageGrabber.cpp @@ -44,6 +44,9 @@ #include #include +#include +#include + X11ImageGrabber::X11ImageGrabber(QObject *parent) : ImageGrabber(parent) { @@ -422,6 +425,9 @@ void X11ImageGrabber::grabTransientWithParent() { xcb_window_t curWin = getRealWindowUnderCursor(); + QString windowTitle = KWindowSystem::readNameProperty(curWin, XA_WM_NAME); + emit windowTitleChanged(windowTitle); + // grab the image early @@ -514,6 +520,8 @@ void X11ImageGrabber::grabActiveWindow() { xcb_window_t activeWindow = KWindowSystem::activeWindow(); + QString windowTitle = KWindowSystem::readNameProperty(activeWindow, XA_WM_NAME); + emit windowTitleChanged(windowTitle); // if KWin is available, use the KWin DBus interfaces @@ -542,6 +550,9 @@ void X11ImageGrabber::grabWindowUnderCursor() { + QString windowTitle = KWindowSystem::readNameProperty(getRealWindowUnderCursor(), XA_WM_NAME); + emit windowTitleChanged(windowTitle); + // if KWin is available, use the KWin DBus interfaces if (mCaptureDecorations && isKWinAvailable()) { diff --git a/src/SpectacleConfig.cpp b/src/SpectacleConfig.cpp --- a/src/SpectacleConfig.cpp +++ b/src/SpectacleConfig.cpp @@ -213,7 +213,7 @@ QString SpectacleConfig::autoSaveFilenameFormat() const { return mGeneralConfig.readEntry(QStringLiteral("save-filename-format"), - QStringLiteral("Screenshot_%Y%M%D_%H%m%S")); + QStringLiteral("%Y-%M-%D %H-%m-%S. %T")); } void SpectacleConfig::setAutoSaveFilenameFormat(const QString &format) diff --git a/src/SpectacleCore.h b/src/SpectacleCore.h --- a/src/SpectacleCore.h +++ b/src/SpectacleCore.h @@ -63,6 +63,7 @@ void takeNewScreenshot(const ImageGrabber::GrabMode &mode, const int &timeout, const bool &includePointer, const bool &includeDecorations); void showErrorMessage(const QString &errString); void screenshotUpdated(const QPixmap &pixmap); + void windowTitleChanged(const QString &windowTitle); void screenshotFailed(); void dbusStartAgent(); void doStartDragAndDrop(); diff --git a/src/SpectacleCore.cpp b/src/SpectacleCore.cpp --- a/src/SpectacleCore.cpp +++ b/src/SpectacleCore.cpp @@ -75,7 +75,7 @@ mImageGrabber = new DummyImageGrabber; } - mImageGrabber->setGrabMode(grabMode); + setGrabMode(grabMode); mImageGrabber->setCapturePointer(guiConfig.readEntry("includePointer", true)); mImageGrabber->setCaptureDecorations(guiConfig.readEntry("includeDecorations", true)); @@ -86,6 +86,7 @@ connect(mExportManager, &ExportManager::errorMessage, this, &SpectacleCore::showErrorMessage); connect(this, &SpectacleCore::errorMessage, this, &SpectacleCore::showErrorMessage); connect(mImageGrabber, &ImageGrabber::pixmapChanged, this, &SpectacleCore::screenshotUpdated); + connect(mImageGrabber, &ImageGrabber::windowTitleChanged, this, &SpectacleCore::windowTitleChanged); connect(mImageGrabber, &ImageGrabber::imageGrabFailed, this, &SpectacleCore::screenshotFailed); connect(mExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doCopyPath); connect(mExportManager, &ExportManager::forceNotify, this, &SpectacleCore::doNotify); @@ -132,6 +133,7 @@ void SpectacleCore::setGrabMode(const ImageGrabber::GrabMode &grabMode) { mImageGrabber->setGrabMode(grabMode); + mExportManager->setGrabMode(grabMode); } // Slots @@ -148,7 +150,7 @@ void SpectacleCore::takeNewScreenshot(const ImageGrabber::GrabMode &mode, const int &timeout, const bool &includePointer, const bool &includeDecorations) { - mImageGrabber->setGrabMode(mode); + setGrabMode(mode); mImageGrabber->setCapturePointer(includePointer); mImageGrabber->setCaptureDecorations(includeDecorations); @@ -176,6 +178,11 @@ } } +void SpectacleCore::windowTitleChanged(const QString &windowTitle) +{ + mExportManager->setWindowTitle(windowTitle); +} + void SpectacleCore::screenshotUpdated(const QPixmap &pixmap) { mExportManager->setPixmap(pixmap);