Add option to auto copy URL after upload (#553)

This commit is contained in:
teryanik
2019-10-01 20:58:29 +03:00
committed by Dharkael
parent f648e88cca
commit 62dbabc341
5 changed files with 35 additions and 1 deletions

View File

@@ -37,6 +37,7 @@ GeneneralConf::GeneneralConf(QWidget *parent) : QWidget(parent) {
initShowTrayIcon();
initAutostart();
initCloseAfterCapture();
initCopyAndCloseAfterUpload();
// this has to be at the end
initConfingButtons();
@@ -49,6 +50,7 @@ void GeneneralConf::updateComponents() {
m_sysNotifications->setChecked(config.desktopNotificationValue());
m_autostart->setChecked(config.startupLaunchValue());
m_closeAfterCapture->setChecked(config.closeAfterScreenshotValue());
m_copyAndCloseAfterUpload->setChecked(config.copyAndCloseAfterUploadEnabled());
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
m_showTray->setChecked(!config.disabledTrayIconValue());
@@ -222,3 +224,16 @@ void GeneneralConf::initCloseAfterCapture() {
connect(m_closeAfterCapture, &QCheckBox::clicked, this,
&GeneneralConf::closeAfterCaptureChanged);
}
void GeneneralConf::initCopyAndCloseAfterUpload()
{
m_copyAndCloseAfterUpload = new QCheckBox(tr("Copy URL after upload"), this);
ConfigHandler config;
m_copyAndCloseAfterUpload->setChecked(config.copyAndCloseAfterUploadEnabled());
m_copyAndCloseAfterUpload->setToolTip(tr("Copy URL and close window after upload"));
m_layout->addWidget(m_copyAndCloseAfterUpload);
connect(m_copyAndCloseAfterUpload, &QCheckBox::clicked, [](bool checked) {
ConfigHandler().setCopyAndCloseAfterUploadEnabled(checked);
});
}

View File

@@ -48,6 +48,7 @@ private:
QCheckBox *m_helpMessage;
QCheckBox *m_autostart;
QCheckBox *m_closeAfterCapture;
QCheckBox *m_copyAndCloseAfterUpload;
QPushButton *m_importButton;
QPushButton *m_exportButton;
QPushButton *m_resetButton;
@@ -58,4 +59,5 @@ private:
void initConfingButtons();
void initAutostart();
void initCloseAfterCapture();
void initCopyAndCloseAfterUpload();
};

View File

@@ -77,7 +77,13 @@ void ImgurUploader::handleReply(QNetworkReply *reply) {
m_imageURL.setUrl(data[QStringLiteral("link")].toString());
m_deleteImageURL.setUrl(QStringLiteral("https://imgur.com/delete/%1").arg(
data[QStringLiteral("deletehash")].toString()));
onUploadOk();
if (ConfigHandler().copyAndCloseAfterUploadEnabled()) {
QApplication::clipboard()->setText(m_imageURL.toString());
SystemNotification().sendMessage(QObject::tr("URL copied to clipboard."));
close();
} else {
onUploadOk();
}
} else {
m_infoLabel->setText(reply->errorString());
}

View File

@@ -325,6 +325,14 @@ void ConfigHandler::setCloseAfterScreenshot(const bool close) {
m_settings.setValue(QStringLiteral("closeAfterScreenshot"), close);
}
bool ConfigHandler::copyAndCloseAfterUploadEnabled() {
return m_settings.value(QStringLiteral("copyAndCloseAfterUpload")).toBool();
}
void ConfigHandler::setCopyAndCloseAfterUploadEnabled(const bool value) {
m_settings.setValue(QStringLiteral("copyAndCloseAfterUpload"), value);
}
void ConfigHandler::setDefaults() {
m_settings.clear();
}

View File

@@ -71,6 +71,9 @@ public:
bool closeAfterScreenshotValue();
void setCloseAfterScreenshot(const bool);
bool copyAndCloseAfterUploadEnabled();
void setCopyAndCloseAfterUploadEnabled(const bool);
void setDefaults();
void setAllTheButtons();