diff --git a/src/config/geneneralconf.cpp b/src/config/geneneralconf.cpp index 92bcb0eb..ec480793 100644 --- a/src/config/geneneralconf.cpp +++ b/src/config/geneneralconf.cpp @@ -18,16 +18,18 @@ #include "geneneralconf.h" #include "src/core/controller.h" #include "src/utils/confighandler.h" +#include "src/utils/filenamehandler.h" #include #include #include #include #include +#include #include #include +#include #include #include - GeneneralConf::GeneneralConf(QWidget* parent) : QWidget(parent) { @@ -39,6 +41,7 @@ GeneneralConf::GeneneralConf(QWidget* parent) initAutostart(); initCloseAfterCapture(); initCopyAndCloseAfterUpload(); + initSaveAfterCopy(); // this has to be at the end initConfingButtons(); @@ -55,6 +58,14 @@ GeneneralConf::updateComponents() m_closeAfterCapture->setChecked(config.closeAfterScreenshotValue()); m_copyAndCloseAfterUpload->setChecked( config.copyAndCloseAfterUploadEnabled()); + 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()); @@ -281,4 +292,62 @@ GeneneralConf::initCopyAndCloseAfterUpload() connect(m_copyAndCloseAfterUpload, &QCheckBox::clicked, [](bool checked) { ConfigHandler().setCopyAndCloseAfterUploadEnabled(checked); }); -} \ No newline at end of file +} + +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); +} diff --git a/src/config/geneneralconf.h b/src/config/geneneralconf.h index 2bc6e436..7dfe47a1 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 { @@ -38,6 +40,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(); @@ -53,6 +57,9 @@ private: QPushButton* m_importButton; QPushButton* m_exportButton; QPushButton* m_resetButton; + QCheckBox* m_saveAfterCopy; + QLineEdit* m_savePath; + QPushButton* m_changeSaveButton; void initShowHelp(); void initShowDesktopNotification(); @@ -61,4 +68,5 @@ private: void initAutostart(); void initCloseAfterCapture(); void initCopyAndCloseAfterUpload(); + void initSaveAfterCopy(); }; diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp index 04f1a2ad..cc33fdd6 100644 --- a/src/utils/confighandler.cpp +++ b/src/utils/confighandler.cpp @@ -391,6 +391,29 @@ ConfigHandler::setCopyAndCloseAfterUploadEnabled(const bool value) { m_settings.setValue(QStringLiteral("copyAndCloseAfterUpload"), value); } +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() diff --git a/src/utils/confighandler.h b/src/utils/confighandler.h index dc995762..1e58b0f4 100644 --- a/src/utils/confighandler.h +++ b/src/utils/confighandler.h @@ -74,6 +74,11 @@ public: bool copyAndCloseAfterUploadEnabled(); void setCopyAndCloseAfterUploadEnabled(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 41615071..79c8ad7b 100644 --- a/src/utils/screenshotsaver.cpp +++ b/src/utils/screenshotsaver.cpp @@ -30,7 +30,14 @@ ScreenshotSaver::ScreenshotSaver() {} void ScreenshotSaver::saveToClipboard(const QPixmap& capture) { - SystemNotification().sendMessage(QObject::tr("Capture saved to clipboard")); + if (ConfigHandler().saveAfterCopyValue()) { + if (!ConfigHandler().saveAfterCopyPathValue().isEmpty()) { + saveToFilesystem(capture, ConfigHandler().saveAfterCopyPathValue()); + } + } else { + SystemNotification().sendMessage(QObject::tr("Capture saved to clipboard")); + } + QApplication::clipboard()->setPixmap(capture); }