From d303c9dd629de5d0a5356070345bdab08302265e Mon Sep 17 00:00:00 2001 From: Joseph Charamut Date: Wed, 1 May 2019 12:56:45 -0400 Subject: [PATCH 1/3] Added feature & config to auto-save a screenshot after copying it --- src/config/geneneralconf.cpp | 62 +++++++++++++++++++++++++++++++++++ src/config/geneneralconf.h | 8 +++++ src/utils/confighandler.cpp | 16 +++++++++ src/utils/confighandler.h | 5 +++ src/utils/screenshotsaver.cpp | 5 +++ 5 files changed, 96 insertions(+) diff --git a/src/config/geneneralconf.cpp b/src/config/geneneralconf.cpp index 7ddce1a8..79adce2e 100644 --- a/src/config/geneneralconf.cpp +++ b/src/config/geneneralconf.cpp @@ -19,6 +19,7 @@ #include "src/utils/confighandler.h" #include "src/utils/confighandler.h" #include "src/core/controller.h" +#include "src/utils/filenamehandler.h" #include #include #include @@ -28,6 +29,8 @@ #include #include #include +#include +#include GeneneralConf::GeneneralConf(QWidget *parent) : QWidget(parent) { m_layout = new QVBoxLayout(this); @@ -37,6 +40,7 @@ GeneneralConf::GeneneralConf(QWidget *parent) : QWidget(parent) { initShowTrayIcon(); initAutostart(); initCloseAfterCapture(); + initSaveAfterCopy(); // this has to be at the end initConfingButtons(); @@ -49,6 +53,14 @@ void GeneneralConf::updateComponents() { m_sysNotifications->setChecked(config.desktopNotificationValue()); m_autostart->setChecked(config.startupLaunchValue()); m_closeAfterCapture->setChecked(config.closeAfterScreenshotValue()); + m_saveAfterCopy->setChecked(config.saveAfterCopyValue()); + + if (!config.saveAfterCopyPathValue().isEmpty()) { + m_savePath->setText(config.saveAfterCopyPathValue()); + } else { + ConfigHandler().setSaveAfterCopyPath( + QStandardPaths::writableLocation(QStandardPaths::PicturesLocation)); + } #if defined(Q_OS_LINUX) || defined(Q_OS_UNIX) m_showTray->setChecked(!config.disabledTrayIconValue()); @@ -222,3 +234,53 @@ void GeneneralConf::initCloseAfterCapture() { connect(m_closeAfterCapture, &QCheckBox::clicked, this, &GeneneralConf::closeAfterCaptureChanged); } + +void GeneneralConf::initSaveAfterCopy() { + m_saveAfterCopy = new QCheckBox(tr("Save image after copy"), this); + m_saveAfterCopy->setToolTip(tr("Save image file after copying it")); + m_layout->addWidget(m_saveAfterCopy); + connect(m_saveAfterCopy, &QCheckBox::clicked, this, + &GeneneralConf::saveAfterCopyChanged); + + QHBoxLayout *pathLayout = new QHBoxLayout(); + m_layout->addStretch(); + QGroupBox *box = new QGroupBox(tr("Save Path")); + box->setFlat(true); + box->setLayout(pathLayout); + m_layout->addWidget(box); + + m_savePath = new QLineEdit( + QStandardPaths::writableLocation(QStandardPaths::PicturesLocation), + this); + m_savePath->setDisabled(true); + QString foreground = this->palette().foreground().color().name(); + m_savePath->setStyleSheet(QStringLiteral("color: %1").arg(foreground)); + pathLayout->addWidget(m_savePath); + + m_changeSaveButton = new QPushButton(tr("Change..."), this); + pathLayout->addWidget(m_changeSaveButton); + connect(m_changeSaveButton, &QPushButton::clicked, this, + &GeneneralConf::changeSavePath); +} + +void GeneneralConf::saveAfterCopyChanged(bool checked) { + ConfigHandler().setSaveAfterCopy(checked); +} + +void GeneneralConf::changeSavePath() { + QString path = QFileDialog::getExistingDirectory( + this, + tr("Choose a Folder"), + QStandardPaths::writableLocation(QStandardPaths::PicturesLocation), + QFileDialog::ShowDirsOnly | QFileDialog::DontResolveSymlinks); + if (path.isEmpty()) { + return; + } + if (!QFileInfo(path).isWritable()) { + QMessageBox::about(this, tr("Error"), + tr("Unable to write to directory.")); + return; + } + m_savePath->setText(path); + ConfigHandler().setSaveAfterCopyPath(path); +} \ No newline at end of file diff --git a/src/config/geneneralconf.h b/src/config/geneneralconf.h index 96991ecd..0e1a103d 100644 --- a/src/config/geneneralconf.h +++ b/src/config/geneneralconf.h @@ -22,6 +22,8 @@ class QVBoxLayout; class QCheckBox; class QPushButton; +class QLabel; +class QLineEdit; class GeneneralConf : public QWidget { Q_OBJECT @@ -37,6 +39,8 @@ private slots: void showTrayIconChanged(bool checked); void autostartChanged(bool checked); void closeAfterCaptureChanged(bool checked); + void saveAfterCopyChanged(bool checked); + void changeSavePath(); void importConfiguration(); void exportFileConfiguration(); void resetConfiguration(); @@ -51,6 +55,9 @@ private: QPushButton *m_importButton; QPushButton *m_exportButton; QPushButton *m_resetButton; + QCheckBox *m_saveAfterCopy; + QLineEdit *m_savePath; + QPushButton *m_changeSaveButton; void initShowHelp(); void initShowDesktopNotification(); @@ -58,4 +65,5 @@ private: void initConfingButtons(); void initAutostart(); void initCloseAfterCapture(); + void initSaveAfterCopy(); }; diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp index 5aed0bf6..47080f5c 100644 --- a/src/utils/confighandler.cpp +++ b/src/utils/confighandler.cpp @@ -325,6 +325,22 @@ void ConfigHandler::setCloseAfterScreenshot(const bool close) { m_settings.setValue(QStringLiteral("closeAfterScreenshot"), close); } +bool ConfigHandler::saveAfterCopyValue() { + return m_settings.value(QStringLiteral("saveAfterCopy")).toBool(); +} + +void ConfigHandler::setSaveAfterCopy(const bool save) { + m_settings.setValue(QStringLiteral("saveAfterCopy"), save); +} + +QString ConfigHandler::saveAfterCopyPathValue() { + return m_settings.value(QStringLiteral("saveAfterCopyPath")).toString(); +} + +void ConfigHandler::setSaveAfterCopyPath(const QString &path) { + m_settings.setValue(QStringLiteral("saveAfterCopyPath"), path); +} + void ConfigHandler::setDefaults() { m_settings.clear(); } diff --git a/src/utils/confighandler.h b/src/utils/confighandler.h index 85d93612..cf7cdab4 100644 --- a/src/utils/confighandler.h +++ b/src/utils/confighandler.h @@ -71,6 +71,11 @@ public: bool closeAfterScreenshotValue(); void setCloseAfterScreenshot(const bool); + bool saveAfterCopyValue(); + void setSaveAfterCopy(const bool); + + QString saveAfterCopyPathValue(); + void setSaveAfterCopyPath(const QString &); void setDefaults(); void setAllTheButtons(); diff --git a/src/utils/screenshotsaver.cpp b/src/utils/screenshotsaver.cpp index 6c9bd989..514874fc 100644 --- a/src/utils/screenshotsaver.cpp +++ b/src/utils/screenshotsaver.cpp @@ -32,6 +32,11 @@ void ScreenshotSaver::saveToClipboard(const QPixmap &capture) { SystemNotification().sendMessage( QObject::tr("Capture saved to clipboard")); QApplication::clipboard()->setPixmap(capture); + if (ConfigHandler().saveAfterCopyValue()) { + if (!ConfigHandler().saveAfterCopyPathValue().isEmpty()) { + saveToFilesystem(capture, ConfigHandler().saveAfterCopyPathValue()); + } + } } bool ScreenshotSaver::saveToFilesystem(const QPixmap &capture, From 387adc3e356264ca1ff7cfbff6040402cf3bc893 Mon Sep 17 00:00:00 2001 From: Joseph Charamut Date: Wed, 1 May 2019 13:03:27 -0400 Subject: [PATCH 2/3] Added newline at end of file --- src/config/geneneralconf.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/config/geneneralconf.cpp b/src/config/geneneralconf.cpp index 79adce2e..1f221799 100644 --- a/src/config/geneneralconf.cpp +++ b/src/config/geneneralconf.cpp @@ -283,4 +283,4 @@ void GeneneralConf::changeSavePath() { } m_savePath->setText(path); ConfigHandler().setSaveAfterCopyPath(path); -} \ No newline at end of file +} From 93b03ee8f14cdb0be67c9e43bf811ad90c273f11 Mon Sep 17 00:00:00 2001 From: Joseph Charamut Date: Wed, 5 Feb 2020 23:14:43 -0500 Subject: [PATCH 3/3] Disable extra notification with save-after-copy --- src/utils/screenshotsaver.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/utils/screenshotsaver.cpp b/src/utils/screenshotsaver.cpp index 514874fc..b1242f53 100644 --- a/src/utils/screenshotsaver.cpp +++ b/src/utils/screenshotsaver.cpp @@ -29,14 +29,16 @@ ScreenshotSaver::ScreenshotSaver() { } void ScreenshotSaver::saveToClipboard(const QPixmap &capture) { - SystemNotification().sendMessage( - QObject::tr("Capture saved to clipboard")); - QApplication::clipboard()->setPixmap(capture); if (ConfigHandler().saveAfterCopyValue()) { if (!ConfigHandler().saveAfterCopyPathValue().isEmpty()) { saveToFilesystem(capture, ConfigHandler().saveAfterCopyPathValue()); } + } else { + SystemNotification().sendMessage( + QObject::tr("Capture saved to clipboard")); } + + QApplication::clipboard()->setPixmap(capture); } bool ScreenshotSaver::saveToFilesystem(const QPixmap &capture,