Commit 7a177901 authored by Boudhayan Gupta's avatar Boudhayan Gupta

Optionally copy the save location to the clipboard

BUG: 357423
FIXED-IN: 16.08
parent 80b8fd88
...@@ -60,6 +60,31 @@ GeneralOptionsPage::GeneralOptionsPage(QWidget *parent) : ...@@ -60,6 +60,31 @@ GeneralOptionsPage::GeneralOptionsPage(QWidget *parent) :
dsLayout->addLayout(dsCLayout); dsLayout->addLayout(dsCLayout);
mainLayout->addWidget(dsGroup, 1); mainLayout->addWidget(dsGroup, 1);
// copy save path to clipboard
QGroupBox *cpGroup = new QGroupBox(i18n("Copy Save Location to Clipboard"));
QVBoxLayout *cpLayout = new QVBoxLayout;
cpGroup->setLayout(cpLayout);
cpGroup->setStyleSheet(QStringLiteral("QGroupBox { font-weight: bold; }"));
QLabel *cpHelpText = new QLabel;
cpHelpText->setWordWrap(true);
cpHelpText->setText(i18n("When a screenshot is saved, copy the location at which the file was saved "
"to the clipboard. You can then paste it anywhere that accepts text input. "
"Note that you must be running a clipboard manager in order to keep the path "
"in the clipboard after Spectacle quits."));
cpLayout->addWidget(cpHelpText);
mCopyPathToClipboard = new QCheckBox;
mCopyPathToClipboard->setText(i18n("Copy save location to the clipboard"));
connect(mCopyPathToClipboard, &QCheckBox::toggled, this, &GeneralOptionsPage::markDirty);
QVBoxLayout *cpCLayout = new QVBoxLayout;
cpCLayout->setContentsMargins(15, 10, 0, 10);
cpCLayout->addWidget(mCopyPathToClipboard);
cpLayout->addLayout(cpCLayout);
mainLayout->addWidget(cpGroup, 1);
// use a light background for the rectangular region grabber // use a light background for the rectangular region grabber
QGroupBox *lbGroup = new QGroupBox(i18n("Light Background For Rectangular Region")); QGroupBox *lbGroup = new QGroupBox(i18n("Light Background For Rectangular Region"));
...@@ -131,6 +156,7 @@ void GeneralOptionsPage::saveChanges() ...@@ -131,6 +156,7 @@ void GeneralOptionsPage::saveChanges()
cfgManager->setUseDynamicSaveButton(mUseLastSaveAction->checkState() == Qt::Checked); cfgManager->setUseDynamicSaveButton(mUseLastSaveAction->checkState() == Qt::Checked);
cfgManager->setUseLightRegionMaskColour(mUseLightBackground->checkState() == Qt::Checked); cfgManager->setUseLightRegionMaskColour(mUseLightBackground->checkState() == Qt::Checked);
cfgManager->setRememberLastRectangularRegion(mRememberRect->checkState() == Qt::Checked); cfgManager->setRememberLastRectangularRegion(mRememberRect->checkState() == Qt::Checked);
cfgManager->setCopySaveLocationToClipboard(mCopyPathToClipboard->checkState() == Qt::Checked);
mChangesMade = false; mChangesMade = false;
} }
...@@ -142,6 +168,7 @@ void GeneralOptionsPage::resetChanges() ...@@ -142,6 +168,7 @@ void GeneralOptionsPage::resetChanges()
mUseLastSaveAction->setChecked(cfgManager->useDynamicSaveButton()); mUseLastSaveAction->setChecked(cfgManager->useDynamicSaveButton());
mUseLightBackground->setChecked(cfgManager->useLightRegionMaskColour()); mUseLightBackground->setChecked(cfgManager->useLightRegionMaskColour());
mRememberRect->setChecked(cfgManager->rememberLastRectangularRegion()); mRememberRect->setChecked(cfgManager->rememberLastRectangularRegion());
mCopyPathToClipboard->setChecked(cfgManager->copySaveLocationToClipboard());
mChangesMade = false; mChangesMade = false;
} }
...@@ -46,6 +46,7 @@ class GeneralOptionsPage : public SettingsPage ...@@ -46,6 +46,7 @@ class GeneralOptionsPage : public SettingsPage
QCheckBox *mUseLastSaveAction; QCheckBox *mUseLastSaveAction;
QCheckBox *mRememberRect; QCheckBox *mRememberRect;
QCheckBox *mUseLightBackground; QCheckBox *mUseLightBackground;
QCheckBox *mCopyPathToClipboard;
}; };
#endif // GENERALOPTIONSPAGE_H #endif // GENERALOPTIONSPAGE_H
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "SpectacleCore.h" #include "SpectacleCore.h"
#include "SpectacleDBusAdapter.h" #include "SpectacleDBusAdapter.h"
#include "ExportManager.h"
#include "Config.h" #include "Config.h"
int main(int argc, char **argv) int main(int argc, char **argv)
...@@ -150,8 +151,10 @@ int main(int argc, char **argv) ...@@ -150,8 +151,10 @@ int main(int argc, char **argv)
new KDBusService(KDBusService::Multiple, &core); new KDBusService(KDBusService::Multiple, &core);
SpectacleDBusAdapter *dbusAdapter = new SpectacleDBusAdapter(&core); SpectacleDBusAdapter *dbusAdapter = new SpectacleDBusAdapter(&core);
QObject::connect(&core, &SpectacleCore::imageSaved, dbusAdapter, &SpectacleDBusAdapter::ScreenshotTaken);
QObject::connect(&core, &SpectacleCore::grabFailed, dbusAdapter, &SpectacleDBusAdapter::ScreenshotFailed); QObject::connect(&core, &SpectacleCore::grabFailed, dbusAdapter, &SpectacleDBusAdapter::ScreenshotFailed);
QObject::connect(ExportManager::instance(), &ExportManager::imageSaved, [&](const QUrl savedAt) {
emit dbusAdapter->ScreenshotTaken(savedAt.toLocalFile());
});
QDBusConnection::sessionBus().registerObject("/", &core); QDBusConnection::sessionBus().registerObject("/", &core);
QDBusConnection::sessionBus().registerService("org.kde.Spectacle"); QDBusConnection::sessionBus().registerService("org.kde.Spectacle");
......
...@@ -222,3 +222,16 @@ void SpectacleConfig::setAutoSaveLocation(const QString &location) ...@@ -222,3 +222,16 @@ void SpectacleConfig::setAutoSaveLocation(const QString &location)
mGeneralConfig.writePathEntry(QStringLiteral("default-save-location"), location); mGeneralConfig.writePathEntry(QStringLiteral("default-save-location"), location);
mGeneralConfig.sync(); mGeneralConfig.sync();
} }
// copy save location to clipboard
bool SpectacleConfig::copySaveLocationToClipboard() const
{
return mGeneralConfig.readEntry(QStringLiteral("copySaveLocation"), false);
}
void SpectacleConfig::setCopySaveLocationToClipboard(bool enabled)
{
mGeneralConfig.writeEntry(QStringLiteral("copySaveLocation"), enabled);
mGeneralConfig.sync();
}
...@@ -91,6 +91,9 @@ class SpectacleConfig : public QObject ...@@ -91,6 +91,9 @@ class SpectacleConfig : public QObject
QString autoSaveLocation() const; QString autoSaveLocation() const;
void setAutoSaveLocation(const QString &location); void setAutoSaveLocation(const QString &location);
bool copySaveLocationToClipboard() const;
void setCopySaveLocationToClipboard(bool enabled);
private: private:
KSharedConfigPtr mConfig; KSharedConfigPtr mConfig;
......
...@@ -18,6 +18,7 @@ ...@@ -18,6 +18,7 @@
*/ */
#include "SpectacleCore.h" #include "SpectacleCore.h"
#include "SpectacleConfig.h"
#include <KRun> #include <KRun>
...@@ -63,9 +64,7 @@ SpectacleCore::SpectacleCore(StartMode startMode, ImageGrabber::GrabMode grabMod ...@@ -63,9 +64,7 @@ SpectacleCore::SpectacleCore(StartMode startMode, ImageGrabber::GrabMode grabMod
connect(this, &SpectacleCore::errorMessage, this, &SpectacleCore::showErrorMessage); connect(this, &SpectacleCore::errorMessage, this, &SpectacleCore::showErrorMessage);
connect(mImageGrabber, &ImageGrabber::pixmapChanged, this, &SpectacleCore::screenshotUpdated); connect(mImageGrabber, &ImageGrabber::pixmapChanged, this, &SpectacleCore::screenshotUpdated);
connect(mImageGrabber, &ImageGrabber::imageGrabFailed, this, &SpectacleCore::screenshotFailed); connect(mImageGrabber, &ImageGrabber::imageGrabFailed, this, &SpectacleCore::screenshotFailed);
connect(mExportManager, &ExportManager::imageSaved, [&](const QUrl &savedAt) { connect(mExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doCopyPath);
emit imageSaved(savedAt.toLocalFile());
});
switch (startMode) { switch (startMode) {
case DBusMode: case DBusMode:
...@@ -240,6 +239,13 @@ void SpectacleCore::doNotify(const QUrl &savedAt) ...@@ -240,6 +239,13 @@ void SpectacleCore::doNotify(const QUrl &savedAt)
notify->sendEvent(); notify->sendEvent();
} }
void SpectacleCore::doCopyPath(const QUrl &savedAt)
{
if (SpectacleConfig::instance()->copySaveLocationToClipboard()) {
qApp->clipboard()->setText(savedAt.toLocalFile());
}
}
void SpectacleCore::doStartDragAndDrop() void SpectacleCore::doStartDragAndDrop()
{ {
QUrl tempFile = mExportManager->tempSave(); QUrl tempFile = mExportManager->tempSave();
......
...@@ -98,7 +98,6 @@ class SpectacleCore : public QObject ...@@ -98,7 +98,6 @@ class SpectacleCore : public QObject
void filenameChanged(QString filename); void filenameChanged(QString filename);
void grabModeChanged(ImageGrabber::GrabMode mode); void grabModeChanged(ImageGrabber::GrabMode mode);
void grabFailed(); void grabFailed();
void imageSaved(const QString &savedAt);
public slots: public slots:
...@@ -109,6 +108,7 @@ class SpectacleCore : public QObject ...@@ -109,6 +108,7 @@ class SpectacleCore : public QObject
void dbusStartAgent(); void dbusStartAgent();
void doStartDragAndDrop(); void doStartDragAndDrop();
void doNotify(const QUrl &savedAt); void doNotify(const QUrl &savedAt);
void doCopyPath(const QUrl &savedAt);
private: private:
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment