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) :
dsLayout->addLayout(dsCLayout);
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
QGroupBox *lbGroup = new QGroupBox(i18n("Light Background For Rectangular Region"));
......@@ -131,6 +156,7 @@ void GeneralOptionsPage::saveChanges()
cfgManager->setUseDynamicSaveButton(mUseLastSaveAction->checkState() == Qt::Checked);
cfgManager->setUseLightRegionMaskColour(mUseLightBackground->checkState() == Qt::Checked);
cfgManager->setRememberLastRectangularRegion(mRememberRect->checkState() == Qt::Checked);
cfgManager->setCopySaveLocationToClipboard(mCopyPathToClipboard->checkState() == Qt::Checked);
mChangesMade = false;
}
......@@ -142,6 +168,7 @@ void GeneralOptionsPage::resetChanges()
mUseLastSaveAction->setChecked(cfgManager->useDynamicSaveButton());
mUseLightBackground->setChecked(cfgManager->useLightRegionMaskColour());
mRememberRect->setChecked(cfgManager->rememberLastRectangularRegion());
mCopyPathToClipboard->setChecked(cfgManager->copySaveLocationToClipboard());
mChangesMade = false;
}
......@@ -46,6 +46,7 @@ class GeneralOptionsPage : public SettingsPage
QCheckBox *mUseLastSaveAction;
QCheckBox *mRememberRect;
QCheckBox *mUseLightBackground;
QCheckBox *mCopyPathToClipboard;
};
#endif // GENERALOPTIONSPAGE_H
......@@ -31,6 +31,7 @@
#include "SpectacleCore.h"
#include "SpectacleDBusAdapter.h"
#include "ExportManager.h"
#include "Config.h"
int main(int argc, char **argv)
......@@ -150,8 +151,10 @@ int main(int argc, char **argv)
new KDBusService(KDBusService::Multiple, &core);
SpectacleDBusAdapter *dbusAdapter = new SpectacleDBusAdapter(&core);
QObject::connect(&core, &SpectacleCore::imageSaved, dbusAdapter, &SpectacleDBusAdapter::ScreenshotTaken);
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().registerService("org.kde.Spectacle");
......
......@@ -222,3 +222,16 @@ void SpectacleConfig::setAutoSaveLocation(const QString &location)
mGeneralConfig.writePathEntry(QStringLiteral("default-save-location"), location);
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
QString autoSaveLocation() const;
void setAutoSaveLocation(const QString &location);
bool copySaveLocationToClipboard() const;
void setCopySaveLocationToClipboard(bool enabled);
private:
KSharedConfigPtr mConfig;
......
......@@ -18,6 +18,7 @@
*/
#include "SpectacleCore.h"
#include "SpectacleConfig.h"
#include <KRun>
......@@ -63,9 +64,7 @@ SpectacleCore::SpectacleCore(StartMode startMode, ImageGrabber::GrabMode grabMod
connect(this, &SpectacleCore::errorMessage, this, &SpectacleCore::showErrorMessage);
connect(mImageGrabber, &ImageGrabber::pixmapChanged, this, &SpectacleCore::screenshotUpdated);
connect(mImageGrabber, &ImageGrabber::imageGrabFailed, this, &SpectacleCore::screenshotFailed);
connect(mExportManager, &ExportManager::imageSaved, [&](const QUrl &savedAt) {
emit imageSaved(savedAt.toLocalFile());
});
connect(mExportManager, &ExportManager::imageSaved, this, &SpectacleCore::doCopyPath);
switch (startMode) {
case DBusMode:
......@@ -240,6 +239,13 @@ void SpectacleCore::doNotify(const QUrl &savedAt)
notify->sendEvent();
}
void SpectacleCore::doCopyPath(const QUrl &savedAt)
{
if (SpectacleConfig::instance()->copySaveLocationToClipboard()) {
qApp->clipboard()->setText(savedAt.toLocalFile());
}
}
void SpectacleCore::doStartDragAndDrop()
{
QUrl tempFile = mExportManager->tempSave();
......
......@@ -98,7 +98,6 @@ class SpectacleCore : public QObject
void filenameChanged(QString filename);
void grabModeChanged(ImageGrabber::GrabMode mode);
void grabFailed();
void imageSaved(const QString &savedAt);
public slots:
......@@ -109,6 +108,7 @@ class SpectacleCore : public QObject
void dbusStartAgent();
void doStartDragAndDrop();
void doNotify(const QUrl &savedAt);
void doCopyPath(const QUrl &savedAt);
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