Fixed merge conflicts

This commit is contained in:
Jeremy Borgman
2020-09-09 19:58:32 -05:00
5 changed files with 115 additions and 3 deletions

View File

@@ -18,16 +18,18 @@
#include "geneneralconf.h"
#include "src/core/controller.h"
#include "src/utils/confighandler.h"
#include "src/utils/filenamehandler.h"
#include <QCheckBox>
#include <QFile>
#include <QFileDialog>
#include <QGroupBox>
#include <QHBoxLayout>
#include <QLineEdit>
#include <QMessageBox>
#include <QPushButton>
#include <QStandardPaths>
#include <QTextCodec>
#include <QVBoxLayout>
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);
});
}
}
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);
}

View File

@@ -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();
};

View File

@@ -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()

View File

@@ -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();

View File

@@ -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);
}