Merge pull request #878 from borgmanJeremy/joecharamut-save

Merge Conflicts for #516
This commit is contained in:
borgmanJeremy
2020-09-10 11:27:13 -05:00
committed by GitHub
9 changed files with 135 additions and 11 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

@@ -95,7 +95,7 @@ CaptureRequest::exportCapture(const QPixmap& p)
if (m_path.isEmpty()) {
ScreenshotSaver().saveToFilesystemGUI(p);
} else {
ScreenshotSaver().saveToFilesystem(p, m_path);
ScreenshotSaver().saveToFilesystem(p, m_path, "");
}
}

View File

@@ -71,7 +71,7 @@ SaveTool::pressed(const CaptureContext& context)
}
} else {
bool ok = ScreenshotSaver().saveToFilesystem(
context.selectedScreenshotArea(), context.savePath);
context.selectedScreenshotArea(), context.savePath, "");
if (ok) {
emit requestAction(REQ_CAPTURE_DONE_OK);
}

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,12 +30,27 @@ ScreenshotSaver::ScreenshotSaver() {}
void
ScreenshotSaver::saveToClipboard(const QPixmap& capture)
{
SystemNotification().sendMessage(QObject::tr("Capture saved to clipboard"));
QApplication::clipboard()->setPixmap(capture);
// If we are able to properly save the file, save the file and copy to
// clipboard.
if ((ConfigHandler().saveAfterCopyValue()) &&
(!ConfigHandler().saveAfterCopyPathValue().isEmpty())) {
QApplication::clipboard()->setPixmap(capture);
saveToFilesystem(capture,
ConfigHandler().saveAfterCopyPathValue(),
QObject::tr("Capture saved to clipboard. "));
}
// Otherwise only save to clipboard
else {
QApplication::clipboard()->setPixmap(capture);
SystemNotification().sendMessage(QObject::tr("Capture saved to clipboard"));
}
}
bool
ScreenshotSaver::saveToFilesystem(const QPixmap& capture, const QString& path)
ScreenshotSaver::saveToFilesystem(const QPixmap& capture,
const QString& path,
const QString& messagePrefix)
{
QString completePath = FileNameHandler().generateAbsolutePath(path);
completePath += QLatin1String(".png");
@@ -45,9 +60,11 @@ ScreenshotSaver::saveToFilesystem(const QPixmap& capture, const QString& path)
if (ok) {
ConfigHandler().setSavePath(path);
saveMessage = QObject::tr("Capture saved as ") + completePath;
saveMessage =
messagePrefix + QObject::tr("Capture saved as ") + completePath;
} else {
saveMessage = QObject::tr("Error trying to save as ") + completePath;
saveMessage =
messagePrefix + QObject::tr("Error trying to save as ") + completePath;
notificationPath = "";
}

View File

@@ -26,6 +26,8 @@ public:
ScreenshotSaver();
void saveToClipboard(const QPixmap& capture);
bool saveToFilesystem(const QPixmap& capture, const QString& path);
bool saveToFilesystem(const QPixmap& capture,
const QString& path,
const QString& messagePrefix);
bool saveToFilesystemGUI(const QPixmap& capture);
};

View File

@@ -1011,7 +1011,7 @@ CaptureWidget::saveScreenshot()
if (m_context.savePath.isEmpty()) {
ScreenshotSaver().saveToFilesystemGUI(pixmap());
} else {
ScreenshotSaver().saveToFilesystem(pixmap(), m_context.savePath);
ScreenshotSaver().saveToFilesystem(pixmap(), m_context.savePath, "");
}
close();
}