diff --git a/.clang-format b/.clang-format
new file mode 100644
index 00000000..c4ac57ae
--- /dev/null
+++ b/.clang-format
@@ -0,0 +1,6 @@
+Language: Cpp
+BasedOnStyle: Mozilla
+IndentWidth: 4
+AccessModifierOffset: -4
+AlwaysBreakAfterDefinitionReturnType: None
+AlwaysBreakAfterReturnType: None
diff --git a/flameshot.pro b/flameshot.pro
index cd80d8c9..11b7b0c7 100644
--- a/flameshot.pro
+++ b/flameshot.pro
@@ -87,7 +87,7 @@ SOURCES += src/main.cpp \
src/config/filepathconfiguration.cpp \
src/config/setshortcutwidget.cpp \
src/config/shortcutswidget.cpp \
- src/tools/imgs3/imgs3settings.cpp \
+ src/tools/storage/storagemanager.cpp \
src/utils/configshortcuts.cpp \
src/widgets/historywidget.cpp \
src/utils/configenterprise.cpp \
@@ -112,8 +112,6 @@ SOURCES += src/main.cpp \
src/tools/circle/circletool.cpp \
src/tools/copy/copytool.cpp \
src/tools/exit/exittool.cpp \
- src/tools/imgur/imguruploadertool.cpp \
- src/tools/imgs3/imgs3uploadertool.cpp \
src/tools/line/linetool.cpp \
src/tools/marker/markertool.cpp \
src/tools/move/movetool.cpp \
@@ -130,8 +128,12 @@ SOURCES += src/main.cpp \
src/cli/commandoption.cpp \
src/cli/commandargument.cpp \
src/utils/screenshotsaver.cpp \
- src/tools/imgur/imguruploader.cpp \
- src/tools/imgs3/imgs3uploader.cpp \
+ src/tools/storage/imguploader.cpp \
+ src/tools/storage/imgur/imguruploadertool.cpp \
+ src/tools/storage/imgur/imguruploader.cpp \
+ src/tools/storage/s3/imgs3uploadertool.cpp \
+ src/tools/storage/s3/imgs3uploader.cpp \
+ src/tools/storage/s3/imgs3settings.cpp \
src/widgets/loadspinner.cpp \
src/widgets/imagelabel.cpp \
src/widgets/notificationwidget.cpp \
@@ -170,7 +172,8 @@ HEADERS += src/widgets/capture/buttonhandler.h \
src/config/filepathconfiguration.h \
src/config/setshortcutwidget.h \
src/config/shortcutswidget.h \
- src/tools/imgs3/imgs3settings.h \
+ src/tools/storage/imgstorages.h \
+ src/tools/storage/storagemanager.h \
src/utils/configshortcuts.h \
src/widgets/historywidget.h \
src/utils/configenterprise.h \
@@ -196,8 +199,6 @@ HEADERS += src/widgets/capture/buttonhandler.h \
src/tools/circle/circletool.h \
src/tools/copy/copytool.h \
src/tools/exit/exittool.h \
- src/tools/imgur/imguruploadertool.h \
- src/tools/imgs3/imgs3uploadertool.h \
src/tools/line/linetool.h \
src/tools/marker/markertool.h \
src/tools/move/movetool.h \
@@ -213,8 +214,12 @@ HEADERS += src/widgets/capture/buttonhandler.h \
src/cli/commandoption.h \
src/cli/commandargument.h \
src/utils/screenshotsaver.h \
- src/tools/imgur/imguruploader.h \
- src/tools/imgs3/imgs3uploader.h \
+ src/tools/storage/imguploader.h \
+ src/tools/storage/imgur/imguruploadertool.h \
+ src/tools/storage/imgur/imguruploader.h \
+ src/tools/storage/s3/imgs3uploader.h \
+ src/tools/storage/s3/imgs3uploadertool.h \
+ src/tools/storage/s3/imgs3settings.h \
src/widgets/loadspinner.h \
src/widgets/imagelabel.h \
src/widgets/notificationwidget.h \
diff --git a/src/config/configwindow.cpp b/src/config/configwindow.cpp
index 26cbea4e..c3c2aa14 100644
--- a/src/config/configwindow.cpp
+++ b/src/config/configwindow.cpp
@@ -16,32 +16,35 @@
// along with Flameshot. If not, see .
#include "configwindow.h"
-#include "src/utils/colorutils.h"
-#include "src/utils/confighandler.h"
-#include "src/utils/pathinfo.h"
-#include "src/widgets/capture/capturebutton.h"
-#include "src/config/geneneralconf.h"
#include "src/config/filenameeditor.h"
#include "src/config/filepathconfiguration.h"
+#include "src/config/geneneralconf.h"
#include "src/config/shortcutswidget.h"
#include "src/config/strftimechooserwidget.h"
#include "src/config/visualseditor.h"
+#include "src/utils/colorutils.h"
+#include "src/utils/confighandler.h"
#include "src/utils/globalvalues.h"
-#include
-#include
-#include
-#include
+#include "src/utils/pathinfo.h"
+#include "src/widgets/capture/capturebutton.h"
#include
+#include
+#include
+#include
+#include
// ConfigWindow contains the menus where you can configure the application
-ConfigWindow::ConfigWindow(QWidget *parent) : QTabWidget(parent) {
+ConfigWindow::ConfigWindow(QWidget* parent)
+ : QTabWidget(parent)
+{
setAttribute(Qt::WA_DeleteOnClose);
- setMinimumSize(GlobalValues::buttonBaseSize() * 14, GlobalValues::buttonBaseSize() * 12);
+ setMinimumSize(GlobalValues::buttonBaseSize() * 14,
+ GlobalValues::buttonBaseSize() * 12);
setWindowIcon(QIcon(":img/app/flameshot.svg"));
setWindowTitle(tr("Configuration"));
- auto changedSlot = [this](QString s){
+ auto changedSlot = [this](QString s) {
QStringList files = m_configWatcher->files();
if (!files.contains(s)) {
this->m_configWatcher->addPath(s);
@@ -50,50 +53,50 @@ ConfigWindow::ConfigWindow(QWidget *parent) : QTabWidget(parent) {
};
m_configWatcher = new QFileSystemWatcher(this);
m_configWatcher->addPath(ConfigHandler().configFilePath());
- connect(m_configWatcher, &QFileSystemWatcher::fileChanged,
- this, changedSlot);
+ connect(
+ m_configWatcher, &QFileSystemWatcher::fileChanged, this, changedSlot);
QColor background = this->palette().background().color();
bool isDark = ColorUtils::colorIsDark(background);
- QString modifier = isDark ? PathInfo::whiteIconPath() :
- PathInfo::blackIconPath();
+ QString modifier =
+ isDark ? PathInfo::whiteIconPath() : PathInfo::blackIconPath();
// visuals
m_visuals = new VisualsEditor();
- addTab(m_visuals, QIcon(modifier + "graphics.svg"),
- tr("Interface"));
+ addTab(m_visuals, QIcon(modifier + "graphics.svg"), tr("Interface"));
// filename
m_filenameEditor = new FileNameEditor();
- addTab(m_filenameEditor, QIcon(modifier + "name_edition.svg"),
+ addTab(m_filenameEditor,
+ QIcon(modifier + "name_edition.svg"),
tr("Filename Editor"));
// general
m_generalConfig = new GeneneralConf();
- addTab(m_generalConfig, QIcon(modifier + "config.svg"),
- tr("General"));
+ addTab(m_generalConfig, QIcon(modifier + "config.svg"), tr("General"));
// shortcuts
m_shortcuts = new ShortcutsWidget();
- addTab(m_shortcuts, QIcon(modifier + "shortcut.svg"),
- tr("Shortcuts"));
-
- // filepath
- m_filePathConfiguration = new FilePathConfiguration();
- addTab(m_filePathConfiguration, QIcon(modifier + "filepath.svg"),
- tr("Path Default"));
+ addTab(m_shortcuts, QIcon(modifier + "shortcut.svg"), tr("Shortcuts"));
// connect update sigslots
- connect(this, &ConfigWindow::updateChildren,
- m_filenameEditor, &FileNameEditor::updateComponents);
- connect(this, &ConfigWindow::updateChildren,
- m_visuals, &VisualsEditor::updateComponents);
- connect(this, &ConfigWindow::updateChildren,
- m_generalConfig, &GeneneralConf::updateComponents);
+ connect(this,
+ &ConfigWindow::updateChildren,
+ m_filenameEditor,
+ &FileNameEditor::updateComponents);
+ connect(this,
+ &ConfigWindow::updateChildren,
+ m_visuals,
+ &VisualsEditor::updateComponents);
+ connect(this,
+ &ConfigWindow::updateChildren,
+ m_generalConfig,
+ &GeneneralConf::updateComponents);
}
-void ConfigWindow::keyPressEvent(QKeyEvent *e) {
+void ConfigWindow::keyPressEvent(QKeyEvent* e)
+{
if (e->key() == Qt::Key_Escape) {
- close();
+ close();
}
}
diff --git a/src/config/configwindow.h b/src/config/configwindow.h
index 7bdc36be..088e363d 100644
--- a/src/config/configwindow.h
+++ b/src/config/configwindow.h
@@ -26,22 +26,22 @@ class GeneneralConf;
class QFileSystemWatcher;
class VisualsEditor;
-class ConfigWindow : public QTabWidget {
+class ConfigWindow : public QTabWidget
+{
Q_OBJECT
public:
- explicit ConfigWindow(QWidget *parent = nullptr);
+ explicit ConfigWindow(QWidget* parent = nullptr);
signals:
void updateChildren();
protected:
- void keyPressEvent(QKeyEvent *);
+ void keyPressEvent(QKeyEvent*);
private:
- FileNameEditor *m_filenameEditor;
- FilePathConfiguration *m_filePathConfiguration;
- ShortcutsWidget *m_shortcuts;
- GeneneralConf *m_generalConfig;
- VisualsEditor *m_visuals;
- QFileSystemWatcher *m_configWatcher;
+ FileNameEditor* m_filenameEditor;
+ ShortcutsWidget* m_shortcuts;
+ GeneneralConf* m_generalConfig;
+ VisualsEditor* m_visuals;
+ QFileSystemWatcher* m_configWatcher;
};
diff --git a/src/config/geneneralconf.cpp b/src/config/geneneralconf.cpp
index 0732d631..58e55687 100644
--- a/src/config/geneneralconf.cpp
+++ b/src/config/geneneralconf.cpp
@@ -16,20 +16,24 @@
// along with Flameshot. If not, see .
#include "geneneralconf.h"
-#include "src/utils/confighandler.h"
-#include "src/utils/confighandler.h"
+#include "filepathconfiguration.h"
#include "src/core/controller.h"
-#include
-#include
+#include "src/tools/storage/imgstorages.h"
+#include "src/utils/confighandler.h"
#include
-#include
-#include
-#include
#include
-#include
+#include
#include
+#include
+#include
+#include
+#include
+#include
+#include
-GeneneralConf::GeneneralConf(QWidget *parent) : QWidget(parent) {
+GeneneralConf::GeneneralConf(QWidget* parent)
+ : QWidget(parent)
+{
m_layout = new QVBoxLayout(this);
m_layout->setAlignment(Qt::AlignTop);
initShowHelp();
@@ -40,19 +44,23 @@ GeneneralConf::GeneneralConf(QWidget *parent) : QWidget(parent) {
initCloseAfterCapture();
initCopyAndCloseAfterUpload();
initCopyPathAfterSave();
+ initUploadStorage();
+ initFilePathConfiguration();
// this has to be at the end
initConfingButtons();
updateComponents();
}
-void GeneneralConf::updateComponents() {
+void GeneneralConf::updateComponents()
+{
ConfigHandler config;
m_helpMessage->setChecked(config.showHelpValue());
m_sysNotifications->setChecked(config.desktopNotificationValue());
m_autostart->setChecked(config.startupLaunchValue());
m_closeAfterCapture->setChecked(config.closeAfterScreenshotValue());
- m_copyAndCloseAfterUpload->setChecked(config.copyAndCloseAfterUploadEnabled());
+ m_copyAndCloseAfterUpload->setChecked(
+ config.copyAndCloseAfterUploadEnabled());
m_copyPathAfterSave->setChecked(config.copyPathAfterSaveEnabled());
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
@@ -60,15 +68,18 @@ void GeneneralConf::updateComponents() {
#endif
}
-void GeneneralConf::showHelpChanged(bool checked) {
+void GeneneralConf::showHelpChanged(bool checked)
+{
ConfigHandler().setShowHelp(checked);
}
-void GeneneralConf::showDesktopNotificationChanged(bool checked) {
+void GeneneralConf::showDesktopNotificationChanged(bool checked)
+{
ConfigHandler().setDesktopNotification(checked);
}
-void GeneneralConf::showTrayIconChanged(bool checked) {
+void GeneneralConf::showTrayIconChanged(bool checked)
+{
auto controller = Controller::getInstance();
if (checked) {
controller->enableTrayIcon();
@@ -77,25 +88,29 @@ void GeneneralConf::showTrayIconChanged(bool checked) {
}
}
-void GeneneralConf::autostartChanged(bool checked) {
+void GeneneralConf::autostartChanged(bool checked)
+{
ConfigHandler().setStartupLaunch(checked);
}
-void GeneneralConf::showStartupLaunchMessageChanged(bool checked) {
+void GeneneralConf::showStartupLaunchMessageChanged(bool checked)
+{
ConfigHandler().setShowStartupLaunchMessage(checked);
}
-void GeneneralConf::closeAfterCaptureChanged(bool checked) {
+void GeneneralConf::closeAfterCaptureChanged(bool checked)
+{
ConfigHandler().setCloseAfterScreenshot(checked);
}
-void GeneneralConf::importConfiguration() {
+void GeneneralConf::importConfiguration()
+{
QString fileName = QFileDialog::getOpenFileName(this, tr("Import"));
if (fileName.isEmpty()) {
return;
}
QFile file(fileName);
- QTextCodec *codec = QTextCodec::codecForLocale();
+ QTextCodec* codec = QTextCodec::codecForLocale();
if (!file.open(QFile::ReadOnly)) {
QMessageBox::about(this, tr("Error"), tr("Unable to read file."));
return;
@@ -105,16 +120,17 @@ void GeneneralConf::importConfiguration() {
QFile config(ConfigHandler().configFilePath());
if (!config.open(QFile::WriteOnly)) {
- QMessageBox::about(this, tr("Error"), tr("Unable to write file."));
- return;
+ QMessageBox::about(this, tr("Error"), tr("Unable to write file."));
+ return;
}
config.write(codec->fromUnicode(text));
config.close();
}
-void GeneneralConf::exportFileConfiguration() {
- QString fileName = QFileDialog::getSaveFileName(this, tr("Save File"),
- QStringLiteral("flameshot.conf"));
+void GeneneralConf::exportFileConfiguration()
+{
+ QString fileName = QFileDialog::getSaveFileName(
+ this, tr("Save File"), QStringLiteral("flameshot.conf"));
// Cancel button
if (fileName.isNull()) {
@@ -131,45 +147,52 @@ void GeneneralConf::exportFileConfiguration() {
}
}
-void GeneneralConf::resetConfiguration() {
+void GeneneralConf::resetConfiguration()
+{
QMessageBox::StandardButton reply;
reply = QMessageBox::question(
- this, tr("Confirm Reset"),
- tr("Are you sure you want to reset the configuration?"),
- QMessageBox::Yes | QMessageBox::No);
+ this,
+ tr("Confirm Reset"),
+ tr("Are you sure you want to reset the configuration?"),
+ QMessageBox::Yes | QMessageBox::No);
if (reply == QMessageBox::Yes) {
ConfigHandler().setDefaults();
}
}
-
-void GeneneralConf::initShowHelp() {
+void GeneneralConf::initShowHelp()
+{
m_helpMessage = new QCheckBox(tr("Show help message"), this);
ConfigHandler config;
bool checked = config.showHelpValue();
m_helpMessage->setChecked(checked);
m_helpMessage->setToolTip(tr("Show the help message at the beginning "
- "in the capture mode."));
+ "in the capture mode."));
m_layout->addWidget(m_helpMessage);
- connect(m_helpMessage, &QCheckBox::clicked, this,
+ connect(m_helpMessage,
+ &QCheckBox::clicked,
+ this,
&GeneneralConf::showHelpChanged);
}
-void GeneneralConf::initShowDesktopNotification() {
- m_sysNotifications =
- new QCheckBox(tr("Show desktop notifications"), this);
+void GeneneralConf::initShowDesktopNotification()
+{
+ m_sysNotifications = new QCheckBox(tr("Show desktop notifications"), this);
ConfigHandler config;
bool checked = config.desktopNotificationValue();
m_sysNotifications->setChecked(checked);
m_sysNotifications->setToolTip(tr("Show desktop notifications"));
m_layout->addWidget(m_sysNotifications);
- connect(m_sysNotifications, &QCheckBox::clicked, this,
+ connect(m_sysNotifications,
+ &QCheckBox::clicked,
+ this,
&GeneneralConf::showDesktopNotificationChanged);
}
-void GeneneralConf::initShowTrayIcon() {
+void GeneneralConf::initShowTrayIcon()
+{
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
m_showTray = new QCheckBox(tr("Show tray icon"), this);
ConfigHandler config;
@@ -178,36 +201,46 @@ void GeneneralConf::initShowTrayIcon() {
m_showTray->setToolTip(tr("Show the systemtray icon"));
m_layout->addWidget(m_showTray);
- connect(m_showTray, &QCheckBox::stateChanged, this,
+ connect(m_showTray,
+ &QCheckBox::stateChanged,
+ this,
&GeneneralConf::showTrayIconChanged);
#endif
}
-void GeneneralConf::initConfingButtons() {
- QHBoxLayout *buttonLayout = new QHBoxLayout();
+void GeneneralConf::initConfingButtons()
+{
+ QHBoxLayout* buttonLayout = new QHBoxLayout();
m_layout->addStretch();
- QGroupBox *box = new QGroupBox(tr("Configuration File"));
+ QGroupBox* box = new QGroupBox(tr("Configuration File"));
box->setFlat(true);
box->setLayout(buttonLayout);
m_layout->addWidget(box);
m_exportButton = new QPushButton(tr("Export"));
buttonLayout->addWidget(m_exportButton);
- connect(m_exportButton, &QPushButton::clicked, this,
+ connect(m_exportButton,
+ &QPushButton::clicked,
+ this,
&GeneneralConf::exportFileConfiguration);
m_importButton = new QPushButton(tr("Import"));
buttonLayout->addWidget(m_importButton);
- connect(m_importButton, &QPushButton::clicked, this,
+ connect(m_importButton,
+ &QPushButton::clicked,
+ this,
&GeneneralConf::importConfiguration);
m_resetButton = new QPushButton(tr("Reset"));
buttonLayout->addWidget(m_resetButton);
- connect(m_resetButton, &QPushButton::clicked, this,
+ connect(m_resetButton,
+ &QPushButton::clicked,
+ this,
&GeneneralConf::resetConfiguration);
}
-void GeneneralConf::initAutostart() {
+void GeneneralConf::initAutostart()
+{
m_autostart = new QCheckBox(tr("Launch at startup"), this);
ConfigHandler config;
bool checked = config.startupLaunchValue();
@@ -215,12 +248,14 @@ void GeneneralConf::initAutostart() {
m_autostart->setToolTip(tr("Launch Flameshot"));
m_layout->addWidget(m_autostart);
- connect(m_autostart, &QCheckBox::clicked, this,
- &GeneneralConf::autostartChanged);
+ connect(
+ m_autostart, &QCheckBox::clicked, this, &GeneneralConf::autostartChanged);
}
-void GeneneralConf::initShowStartupLaunchMessage() {
- m_showStartupLaunchMessage = new QCheckBox(tr("Show welcome message on launch"), this);
+void GeneneralConf::initShowStartupLaunchMessage()
+{
+ m_showStartupLaunchMessage =
+ new QCheckBox(tr("Show welcome message on launch"), this);
ConfigHandler config;
bool checked = config.showStartupLaunchMessage();
m_showStartupLaunchMessage->setChecked(checked);
@@ -232,23 +267,31 @@ void GeneneralConf::initShowStartupLaunchMessage() {
});
}
-void GeneneralConf::initCloseAfterCapture() {
- m_closeAfterCapture = new QCheckBox(tr("Close application after capture"), this);
+void GeneneralConf::initCloseAfterCapture()
+{
+ m_closeAfterCapture =
+ new QCheckBox(tr("Close application after capture"), this);
ConfigHandler config;
bool checked = config.closeAfterScreenshotValue();
m_closeAfterCapture->setChecked(checked);
m_closeAfterCapture->setToolTip(tr("Close after taking a screenshot"));
m_layout->addWidget(m_closeAfterCapture);
- connect(m_closeAfterCapture, &QCheckBox::clicked, this,
+ connect(m_closeAfterCapture,
+ &QCheckBox::clicked,
+ this,
&GeneneralConf::closeAfterCaptureChanged);
}
-void GeneneralConf::initCopyAndCloseAfterUpload() {
- m_copyAndCloseAfterUpload = new QCheckBox(tr("Copy URL after upload"), this);
+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_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) {
@@ -256,7 +299,8 @@ void GeneneralConf::initCopyAndCloseAfterUpload() {
});
}
-void GeneneralConf::initCopyPathAfterSave() {
+void GeneneralConf::initCopyPathAfterSave()
+{
m_copyPathAfterSave = new QCheckBox(tr("Copy file path after save"), this);
ConfigHandler config;
m_copyPathAfterSave->setChecked(config.copyPathAfterSaveEnabled());
@@ -266,3 +310,44 @@ void GeneneralConf::initCopyPathAfterSave() {
ConfigHandler().setCopyPathAfterSaveEnabled(checked);
});
}
+
+void GeneneralConf::initUploadStorage()
+{
+ QGroupBox* groupBox = new QGroupBox(tr("Upload storage"));
+
+ // TODO - remove dependency injection (s3 & imgur)
+ // imgur
+ QRadioButton* storageImgUr = new QRadioButton(tr("Imgur storage"));
+ connect(storageImgUr, &QCheckBox::clicked, [](bool checked) {
+ ConfigHandler().setUploadStorage(SCREENSHOT_STORAGE_TYPE_IMGUR);
+ });
+
+ // s3
+ QRadioButton* storageImgS3 = new QRadioButton(
+ tr("S3 storage (require config.ini file with s3 credentials)"));
+ connect(storageImgS3, &QCheckBox::clicked, [](bool checked) {
+ ConfigHandler().setUploadStorage(SCREENSHOT_STORAGE_TYPE_S3);
+ });
+
+ // set current storage radiobutton active
+ if (ConfigHandler().uploadStorage() == SCREENSHOT_STORAGE_TYPE_IMGUR) {
+ storageImgUr->setChecked(true);
+
+ } else {
+ storageImgS3->setChecked(true);
+ }
+
+ // draw configuration options for uploadStorage
+ QVBoxLayout* vbox = new QVBoxLayout;
+ vbox->addWidget(storageImgUr);
+ vbox->addWidget(storageImgS3);
+ vbox->addStretch(1);
+ groupBox->setLayout(vbox);
+ m_layout->addWidget(groupBox);
+}
+
+void GeneneralConf::initFilePathConfiguration()
+{
+ m_filePathConfiguration = new FilePathConfiguration();
+ m_layout->addWidget(m_filePathConfiguration);
+}
diff --git a/src/config/geneneralconf.h b/src/config/geneneralconf.h
index e387a750..e5d881f7 100644
--- a/src/config/geneneralconf.h
+++ b/src/config/geneneralconf.h
@@ -22,39 +22,42 @@
class QVBoxLayout;
class QCheckBox;
class QPushButton;
+class FilePathConfiguration;
-class GeneneralConf : public QWidget {
+class GeneneralConf : public QWidget
+{
Q_OBJECT
public:
- explicit GeneneralConf(QWidget *parent = nullptr);
+ explicit GeneneralConf(QWidget* parent = nullptr);
public slots:
void updateComponents();
private slots:
- void showHelpChanged(bool checked);
- void showDesktopNotificationChanged(bool checked);
- void showTrayIconChanged(bool checked);
- void autostartChanged(bool checked);
- void showStartupLaunchMessageChanged(bool checked);
- void closeAfterCaptureChanged(bool checked);
- void importConfiguration();
- void exportFileConfiguration();
- void resetConfiguration();
+ void showHelpChanged(bool checked);
+ void showDesktopNotificationChanged(bool checked);
+ void showTrayIconChanged(bool checked);
+ void autostartChanged(bool checked);
+ void showStartupLaunchMessageChanged(bool checked);
+ void closeAfterCaptureChanged(bool checked);
+ void importConfiguration();
+ void exportFileConfiguration();
+ void resetConfiguration();
private:
- QVBoxLayout *m_layout;
- QCheckBox *m_sysNotifications;
- QCheckBox *m_showTray;
- QCheckBox *m_helpMessage;
- QCheckBox *m_autostart;
- QCheckBox *m_showStartupLaunchMessage;
- QCheckBox *m_closeAfterCapture;
- QCheckBox *m_copyAndCloseAfterUpload;
- QCheckBox *m_copyPathAfterSave;
- QPushButton *m_importButton;
- QPushButton *m_exportButton;
- QPushButton *m_resetButton;
+ QVBoxLayout* m_layout;
+ QCheckBox* m_sysNotifications;
+ QCheckBox* m_showTray;
+ QCheckBox* m_helpMessage;
+ QCheckBox* m_autostart;
+ QCheckBox* m_showStartupLaunchMessage;
+ QCheckBox* m_closeAfterCapture;
+ QCheckBox* m_copyAndCloseAfterUpload;
+ QCheckBox* m_copyPathAfterSave;
+ QPushButton* m_importButton;
+ QPushButton* m_exportButton;
+ QPushButton* m_resetButton;
+ FilePathConfiguration* m_filePathConfiguration;
void initShowHelp();
void initShowDesktopNotification();
@@ -65,4 +68,6 @@ private:
void initCloseAfterCapture();
void initCopyAndCloseAfterUpload();
void initCopyPathAfterSave();
+ void initUploadStorage();
+ void initFilePathConfiguration();
};
diff --git a/src/tools/imgs3/imgs3uploader.cpp b/src/tools/imgs3/imgs3uploader.cpp
deleted file mode 100644
index a6afaa14..00000000
--- a/src/tools/imgs3/imgs3uploader.cpp
+++ /dev/null
@@ -1,467 +0,0 @@
-// Copyright(c) 2017-2019 Alejandro Sirgo Rica & Contributors
-//
-// This file is part of Flameshot.
-//
-// Flameshot is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Flameshot is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Flameshot. If not, see .
-
-#include "imgs3uploader.h"
-#include "src/utils/filenamehandler.h"
-#include "src/utils/systemnotification.h"
-#include "src/widgets/loadspinner.h"
-#include "src/widgets/imagelabel.h"
-#include "src/widgets/notificationwidget.h"
-#include "src/utils/confighandler.h"
-#include "src/utils/history.h"
-#include "src/utils/configenterprise.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-
-ImgS3Uploader::ImgS3Uploader(const QPixmap &capture, QWidget *parent) :
- QWidget(parent), m_pixmap(capture)
-{
- init(tr("Upload image to S3"), tr("Uploading Image"));
-}
-
-ImgS3Uploader::ImgS3Uploader(QWidget *parent) :
- QWidget(parent)
-{
- init(tr("Delete image from S3"), tr("Deleting image..."));
-}
-
-void ImgS3Uploader::init(const QString &title, const QString &label) {
- m_imageLabel = nullptr;
- m_spinner = nullptr;
-
- m_proxy = nullptr;
- m_NetworkAMUpload = nullptr;
- m_NetworkAMGetCreds = nullptr;
- m_NetworkAMRemove = nullptr;
-
- m_success = false;
- setWindowTitle(title);
- setWindowIcon(QIcon(":img/app/flameshot.svg"));
-
- m_spinner = new LoadSpinner(this);
- m_spinner->setColor(ConfigHandler().uiMainColorValue());
- m_spinner->start();
-
- m_infoLabel = new QLabel(label);
- m_infoLabel->setAlignment(Qt::AlignCenter);
-
- m_vLayout = new QVBoxLayout();
- setLayout(m_vLayout);
- m_vLayout->addWidget(m_spinner, 0, Qt::AlignHCenter);
- m_vLayout->addWidget(m_infoLabel);
-
- setAttribute(Qt::WA_DeleteOnClose);
-}
-
-QNetworkProxy *ImgS3Uploader::proxy() {
- if(m_proxy == nullptr) {
- initProxy();
- }
- return m_proxy;
-}
-
-QNetworkProxy *ImgS3Uploader::initProxy() {
- // get enterprise settings
- ConfigEnterprise *configEnterprise = new ConfigEnterprise();
-
- // get proxy settings from "config.ini" file
- QSettings *settings = configEnterprise->settings();
- QString httpProxyHost = settings->value("HTTP_PROXY_HOST").toString();
-
- if(httpProxyHost.length() > 0) {
- m_proxy = new QNetworkProxy();
-
- if(settings->contains("HTTP_PROXY_TYPE")) {
- switch (settings->value("HTTP_PROXY_TYPE").toInt()) {
- case 0:
- m_proxy->setType(QNetworkProxy::DefaultProxy);
- break;
- case 1:
- m_proxy->setType(QNetworkProxy::Socks5Proxy);
- break;
- case 2:
- m_proxy->setType(QNetworkProxy::NoProxy);
- break;
- case 4:
- m_proxy->setType(QNetworkProxy::HttpCachingProxy);
- break;
- case 5:
- m_proxy->setType(QNetworkProxy::FtpCachingProxy);
- break;
- case 3:
- default:
- m_proxy->setType(QNetworkProxy::HttpProxy);
- break;
- }
- }
-
- m_proxy->setHostName(httpProxyHost);
- int nProxyPort = 3128;
- if(settings->contains("HTTP_PROXY_PORT")) {
- nProxyPort = settings->value("HTTP_PROXY_PORT").toInt();
- }
- m_proxy->setPort(nProxyPort);
-
- if(settings->contains("HTTP_PROXY_USER")) {
- qDebug() << "Proxy user" << settings->value("HTTP_PROXY_PASSWORD").toString();
- m_proxy->setUser(settings->value("HTTP_PROXY_USER").toString());
- }
- if(settings->contains("HTTP_PROXY_PASSWORD")) {
- qDebug() << "Proxy password is not empty";
- m_proxy->setPassword(settings->value("HTTP_PROXY_PASSWORD").toString());
- }
- }
- else {
- // Get proxy settings from OS settings
- QNetworkProxyQuery q(QUrl(m_s3Settings.credsUrl().toUtf8()));
- q.setQueryType(QNetworkProxyQuery::UrlRequest);
- q.setProtocolTag("http");
-
- QList proxies = QNetworkProxyFactory::systemProxyForQuery(q);
- if( proxies.size() > 0 && proxies[0].type() != QNetworkProxy::NoProxy ){
- m_proxy = new QNetworkProxy();
- m_proxy->setHostName(proxies[0].hostName());
- m_proxy->setPort(proxies[0].port());
- m_proxy->setType(proxies[0].type());
- m_proxy->setUser(proxies[0].user());
- m_proxy->setPassword(proxies[0].password());
- }
- }
-#ifdef QT_DEBUG
- if(m_proxy != nullptr) {
- qDebug() << "Using proxy server";
- qDebug() << "proxy host:" << m_proxy->hostName();
- qDebug() << "proxy port:" << m_proxy->port();
- qDebug() << "proxy type:" << m_proxy->type();
- qDebug() << "proxy user:" << (m_proxy->user().length() > 0 ? m_proxy->user() : "no user");
- qDebug() << "proxy password:" << (m_proxy->password().length() > 0 ? "***" : "no password");
- }
- else {
- qDebug() << "No proxy";
- }
-#endif
- return m_proxy;
-}
-
-void ImgS3Uploader::clearProxy() {
- if(m_proxy != nullptr) {
- delete m_proxy;
- m_proxy = nullptr;
- }
-}
-
-
-void ImgS3Uploader::handleReplyUpload(QNetworkReply *reply) {
- hideSpinner();
- m_s3ImageName.clear();
- if (reply->error() == QNetworkReply::NoError) {
- // save history
- QString imageName = m_imageURL.toString();
- int lastSlash = imageName.lastIndexOf("/");
- if (lastSlash >= 0) {
- imageName = imageName.mid(lastSlash + 1);
- }
- m_s3ImageName = imageName;
- History history;
- imageName = history.packFileName(SCREENSHOT_STORAGE_TYPE_S3, m_deleteToken, imageName);
- history.save(m_pixmap, imageName);
- m_success = true;
-
- // Copy url to clipboard if required
- if (ConfigHandler().copyAndCloseAfterUploadEnabled()) {
- QApplication::clipboard()->setText(m_imageURL.toString());
- SystemNotification().sendMessage(tr("URL copied to clipboard."));
- close();
- } else {
- onUploadOk();
- }
- } else {
- QString reason = reply->attribute( QNetworkRequest::HttpReasonPhraseAttribute ).toString();
- setInfoLabelText(reply->errorString());
- }
- new QShortcut(Qt::Key_Escape, this, SLOT(close()));
-}
-
-void ImgS3Uploader::removeImagePreview() {
- // remove local file
- History history;
- QString packedFileName = history.packFileName(SCREENSHOT_STORAGE_TYPE_S3, m_deleteToken, m_s3ImageName);
- QString fullFileName = history.path() + packedFileName;
-
- QFile file(fullFileName);
- if (file.exists()) {
- file.remove();
- }
- m_deleteToken.clear();
- m_s3ImageName.clear();
- m_success = true;
-}
-
-void ImgS3Uploader::handleReplyDeleteResource(QNetworkReply *reply) {
- auto replyError = reply->error();
- if (replyError == QNetworkReply::NoError) {
- removeImagePreview();
- } else {
- hide();
-
- // generate error message
- QString message = tr("Unable to remove screenshot from the remote storage.");
- if(replyError == QNetworkReply::UnknownNetworkError) {
- message += "\n" + tr("Network error");
- }
- else if(replyError == QNetworkReply::UnknownServerError) {
- message += "\n" + tr("Possibly it doesn't exist anymore");
- }
- message += "\n\n" + reply->errorString();
- message += "\n\n" + tr("Do you want to remove screenshot from local history anyway?");
-
- if (QMessageBox::Yes == QMessageBox::question(NULL,
- tr("Remove screenshot from history?"),
- message,
- QMessageBox::Yes|QMessageBox::No)) {
- removeImagePreview();
- }
- }
- close();
-}
-
-void ImgS3Uploader::startDrag() {
- QMimeData *mimeData = new QMimeData;
- mimeData->setUrls(QList { m_imageURL });
- mimeData->setImageData(m_pixmap);
-
- QDrag *dragHandler = new QDrag(this);
- dragHandler->setMimeData(mimeData);
- dragHandler->setPixmap(m_pixmap.scaled(256, 256, Qt::KeepAspectRatioByExpanding,
- Qt::SmoothTransformation));
- dragHandler->exec();
-}
-
-void ImgS3Uploader::handleReplyGetCreds(QNetworkReply *reply){
- if (reply->error() == QNetworkReply::NoError) {
- QJsonDocument response = QJsonDocument::fromJson(reply->readAll());
- uploadToS3(response);
- } else {
- if(m_s3Settings.credsUrl().length() == 0){
- setInfoLabelText(tr("S3 Creds URL is not found in your configuration file"));
- }
- else {
- setInfoLabelText(reply->errorString());
- }
- }
- new QShortcut(Qt::Key_Escape, this, SLOT(close()));
-}
-
-void ImgS3Uploader::uploadToS3(QJsonDocument &response) {
- // set paramets from "fields"
- QHttpMultiPart *multiPart = new QHttpMultiPart(QHttpMultiPart::FormDataType);
-
- // read JSON response
- QJsonObject json = response.object();
- QString resultURL = json["resultURL"].toString();
- QJsonObject formData = json["formData"].toObject();
- QString url = formData["url"].toString();
- m_deleteToken = json["deleteToken"].toString();
-
- QJsonObject fields = formData["fields"].toObject();
- foreach (auto key, fields.keys()) {
- QString field = fields[key].toString();
- QHttpPart part;
- part.setHeader(QNetworkRequest::ContentDispositionHeader, QVariant("form-data; name=\"" + key + "\""));
- part.setBody(field.toLatin1());
- multiPart->append(part);
- }
-
- QHttpPart imagePart;
- imagePart.setHeader(QNetworkRequest::ContentTypeHeader, QVariant("image/png"));
- imagePart.setHeader(QNetworkRequest::ContentDispositionHeader,
- QVariant("form-data; name=\"file\""));
-
- QByteArray byteArray;
- QBuffer buffer(&byteArray);
- buffer.open(QIODevice::WriteOnly);
- m_pixmap.save(&buffer, "PNG");
-
- imagePart.setBody(byteArray);
- multiPart->append(imagePart);
-
- m_imageURL.setUrl(resultURL);
-
- QUrl qUrl(url);
- QNetworkRequest request(qUrl);
-
- // upload
- m_NetworkAMUpload->post(request, multiPart);
-}
-
-void ImgS3Uploader::deleteResource(const QString &fileName, const QString &deleteToken) {
- // read network settings on each call to simplify configuration management without restarting
- clearProxy();
- if(m_NetworkAMRemove != nullptr) {
- delete m_NetworkAMRemove;
- m_NetworkAMRemove = nullptr;
- }
- m_NetworkAMRemove = new QNetworkAccessManager(this);
- connect(m_NetworkAMRemove, &QNetworkAccessManager::finished, this, &ImgS3Uploader::handleReplyDeleteResource);
- if(proxy() != nullptr) {
- m_NetworkAMRemove->setProxy(*proxy());
- }
-
- QNetworkRequest request;
- m_s3ImageName = fileName;
- m_deleteToken = deleteToken;
- request.setUrl(m_s3Settings.credsUrl().toUtf8() + fileName);
- request.setRawHeader("X-API-Key", m_s3Settings.xApiKey().toLatin1());
- request.setRawHeader("Authorization", "Bearer " + deleteToken.toLatin1());
- m_NetworkAMRemove->deleteResource(request);
-}
-
-void ImgS3Uploader::upload() {
- m_deleteToken.clear();
- m_s3ImageName.clear();
-
- // read network settings on each call to simplify configuration management without restarting
- // init creds and upload network access managers
- clearProxy();
- if(m_NetworkAMGetCreds != nullptr) {
- delete m_NetworkAMGetCreds;
- m_NetworkAMGetCreds = nullptr;
- }
- m_NetworkAMGetCreds = new QNetworkAccessManager(this);
- connect(m_NetworkAMGetCreds, &QNetworkAccessManager::finished, this, &ImgS3Uploader::handleReplyGetCreds);
-
- if(m_NetworkAMUpload != nullptr) {
- delete m_NetworkAMUpload;
- m_NetworkAMUpload = nullptr;
- }
- m_NetworkAMUpload = new QNetworkAccessManager(this);
- connect(m_NetworkAMUpload, &QNetworkAccessManager::finished, this, &ImgS3Uploader::handleReplyUpload);
- if(proxy() != nullptr) {
- m_NetworkAMGetCreds->setProxy(*proxy());
- m_NetworkAMUpload->setProxy(*proxy());
- }
-
- // get creads
- QUrl creds(m_s3Settings.credsUrl());
- QNetworkRequest requestCreds(creds);
- if(m_s3Settings.xApiKey().length() > 0) {
- requestCreds.setRawHeader(QByteArray("X-API-Key"), QByteArray(m_s3Settings.xApiKey().toLocal8Bit()));
- }
- m_NetworkAMGetCreds->get(requestCreds);
-}
-
-void ImgS3Uploader::onUploadOk() {
- hideSpinner();
-
- m_notification = new NotificationWidget();
- m_vLayout->addWidget(m_notification);
-
- if(nullptr == m_imageLabel) {
- m_imageLabel = new ImageLabel();
- m_imageLabel->setScreenshot(m_pixmap);
- m_imageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- connect(m_imageLabel, &ImageLabel::dragInitiated, this, &ImgS3Uploader::startDrag);
- m_vLayout->addWidget(m_imageLabel);
- }
-
- m_hLayout = new QHBoxLayout();
- m_vLayout->addLayout(m_hLayout);
-
- m_copyUrlButton = new QPushButton(tr("Copy URL"));
- m_openUrlButton = new QPushButton(tr("Open URL"));
- m_deleteImageOnS3 = new QPushButton(tr("Delete image"));
- m_toClipboardButton = new QPushButton(tr("Image to Clipboard."));
- m_hLayout->addWidget(m_copyUrlButton);
- m_hLayout->addWidget(m_openUrlButton);
- m_hLayout->addWidget(m_deleteImageOnS3);
- m_hLayout->addWidget(m_toClipboardButton);
-
- connect(m_copyUrlButton, &QPushButton::clicked,
- this, &ImgS3Uploader::copyURL);
- connect(m_openUrlButton, &QPushButton::clicked,
- this, &ImgS3Uploader::openURL);
- connect(m_deleteImageOnS3, &QPushButton::clicked,
- this, &ImgS3Uploader::deleteImageOnS3);
- connect(m_toClipboardButton, &QPushButton::clicked,
- this, &ImgS3Uploader::copyImage);
-}
-
-void ImgS3Uploader::openURL() {
- bool successful = QDesktopServices::openUrl(m_imageURL);
- if (!successful) {
- m_notification->showMessage(tr("Unable to open the URL."));
- }
-}
-
-void ImgS3Uploader::copyURL() {
- QApplication::clipboard()->setText(m_imageURL.toString());
- m_notification->showMessage(tr("URL copied to clipboard."));
-}
-
-void ImgS3Uploader::copyImage() {
- QApplication::clipboard()->setPixmap(m_pixmap);
- m_notification->showMessage(tr("Screenshot copied to clipboard."));
-}
-
-void ImgS3Uploader::deleteImageOnS3() {
- if(nullptr != m_imageLabel) {
- m_imageLabel->hide();
- }
- m_spinner->show();
- setInfoLabelText(tr("Deleting image..."));
- deleteResource(m_s3ImageName, m_deleteToken);
-}
-
-bool ImgS3Uploader::success() {
- return m_success;
-}
-
-void ImgS3Uploader::hideSpinner() {
- if(nullptr != m_spinner) {
- m_spinner->hide();
- }
- if(nullptr != m_imageLabel) {
- m_imageLabel->hide();
- }
-}
-
-void ImgS3Uploader::setInfoLabelText(const QString &infoText) {
- m_infoLabel->setText(infoText);
- m_infoLabel->show();
-}
diff --git a/src/tools/imgs3/imgs3uploader.h b/src/tools/imgs3/imgs3uploader.h
deleted file mode 100644
index 755fa01b..00000000
--- a/src/tools/imgs3/imgs3uploader.h
+++ /dev/null
@@ -1,103 +0,0 @@
-// Copyright(c) 2017-2019 Alejandro Sirgo Rica & Contributors
-//
-// This file is part of Flameshot.
-//
-// Flameshot is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Flameshot is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Flameshot. If not, see .
-
-#pragma once
-
-#define S3_API_IMG_PATH "v2/image/"
-
-#include "imgs3settings.h"
-#include
-#include
-
-class QNetworkReply;
-class QNetworkProxy;
-class QNetworkAccessManager;
-class QHBoxLayout;
-class QVBoxLayout;
-class QLabel;
-class LoadSpinner;
-class QPushButton;
-class QUrl;
-class NotificationWidget;
-class ConfigEnterprise;
-class ImageLabel;
-
-class ImgS3Uploader : public QWidget {
- Q_OBJECT
-public:
- explicit ImgS3Uploader(const QPixmap &capture, QWidget *parent = nullptr);
- explicit ImgS3Uploader(QWidget *parent = nullptr);
- void upload();
- void deleteResource(const QString &, const QString &);
- bool success();
-
-private slots:
- void handleReplyUpload(QNetworkReply *reply);
- void handleReplyGetCreds(QNetworkReply *reply);
- void handleReplyDeleteResource(QNetworkReply *reply);
- void startDrag();
-
- void openURL();
- void copyURL();
- void copyImage();
- void deleteImageOnS3();
-
-private:
- void init(const QString &title, const QString &label);
- void uploadToS3(QJsonDocument &response);
- QNetworkProxy *initProxy();
- void clearProxy();
- void removeImagePreview();
-
- void onUploadOk();
-
- void hideSpinner();
- void setInfoLabelText(const QString &);
- QNetworkProxy *proxy();
-
-
-// class members
-private:
- bool m_success;
- ImgS3Settings m_s3Settings;
-
- ImageLabel *m_imageLabel;
-
- QString m_hostName;
- QPixmap m_pixmap;
- QNetworkProxy *m_proxy;
- QNetworkAccessManager *m_NetworkAMUpload;
- QNetworkAccessManager *m_NetworkAMGetCreds;
- QNetworkAccessManager *m_NetworkAMRemove;
-
- QVBoxLayout *m_vLayout;
- QHBoxLayout *m_hLayout;
- // loading
- QLabel *m_infoLabel;
- LoadSpinner *m_spinner;
- // uploaded
- QPushButton *m_openUrlButton;
- QPushButton *m_copyUrlButton;
- QPushButton *m_toClipboardButton;
- QPushButton *m_deleteImageOnS3;
- QUrl m_imageURL;
- NotificationWidget *m_notification;
-
- // Temporary variables
- QString m_deleteToken;
- QString m_s3ImageName;
-};
diff --git a/src/tools/imgur/imguruploader.cpp b/src/tools/imgur/imguruploader.cpp
deleted file mode 100644
index cd0dfc63..00000000
--- a/src/tools/imgur/imguruploader.cpp
+++ /dev/null
@@ -1,182 +0,0 @@
-// Copyright(c) 2017-2019 Alejandro Sirgo Rica & Contributors
-//
-// This file is part of Flameshot.
-//
-// Flameshot is free software: you can redistribute it and/or modify
-// it under the terms of the GNU General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// Flameshot is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU General Public License for more details.
-//
-// You should have received a copy of the GNU General Public License
-// along with Flameshot. If not, see .
-
-#include "imguruploader.h"
-#include "src/utils/filenamehandler.h"
-#include "src/utils/systemnotification.h"
-#include "src/widgets/loadspinner.h"
-#include "src/widgets/imagelabel.h"
-#include "src/widgets/notificationwidget.h"
-#include "src/utils/confighandler.h"
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-#include
-
-ImgurUploader::ImgurUploader(const QPixmap &capture, QWidget *parent) :
- QWidget(parent), m_pixmap(capture)
-{
- setWindowTitle(tr("Upload to Imgur"));
- setWindowIcon(QIcon(":img/app/flameshot.svg"));
-
- m_spinner = new LoadSpinner(this);
- m_spinner->setColor(ConfigHandler().uiMainColorValue());
- m_spinner->start();
-
- m_infoLabel = new QLabel(tr("Uploading Image"));
-
- m_vLayout = new QVBoxLayout();
- setLayout(m_vLayout);
- m_vLayout->addWidget(m_spinner, 0, Qt::AlignHCenter);
- m_vLayout->addWidget(m_infoLabel);
-
- m_NetworkAM = new QNetworkAccessManager(this);
- connect(m_NetworkAM, &QNetworkAccessManager::finished, this,
- &ImgurUploader::handleReply);
-
- setAttribute(Qt::WA_DeleteOnClose);
-
- upload();
- // QTimer::singleShot(2000, this, &ImgurUploader::onUploadOk); // testing
-}
-
-void ImgurUploader::handleReply(QNetworkReply *reply) {
- m_spinner->deleteLater();
- if (reply->error() == QNetworkReply::NoError) {
- QJsonDocument response = QJsonDocument::fromJson(reply->readAll());
- QJsonObject json = response.object();
- QJsonObject data = json[QStringLiteral("data")].toObject();
- m_imageURL.setUrl(data[QStringLiteral("link")].toString());
- m_deleteImageURL.setUrl(QStringLiteral("https://imgur.com/delete/%1").arg(
- data[QStringLiteral("deletehash")].toString()));
- 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());
- }
- new QShortcut(Qt::Key_Escape, this, SLOT(close()));
-}
-
-void ImgurUploader::startDrag() {
- QMimeData *mimeData = new QMimeData;
- mimeData->setUrls(QList { m_imageURL });
- mimeData->setImageData(m_pixmap);
-
- QDrag *dragHandler = new QDrag(this);
- dragHandler->setMimeData(mimeData);
- dragHandler->setPixmap(m_pixmap.scaled(256, 256, Qt::KeepAspectRatioByExpanding,
- Qt::SmoothTransformation));
- dragHandler->exec();
-}
-
-void ImgurUploader::upload() {
- QByteArray byteArray;
- QBuffer buffer(&byteArray);
- m_pixmap.save(&buffer, "PNG");
-
- QUrlQuery urlQuery;
- urlQuery.addQueryItem(QStringLiteral("title"), QStringLiteral("flameshot_screenshot"));
- QString description = FileNameHandler().parsedPattern();
- urlQuery.addQueryItem(QStringLiteral("description"), description);
-
- QUrl url(QStringLiteral("https://api.imgur.com/3/image"));
- url.setQuery(urlQuery);
- QNetworkRequest request(url);
- request.setHeader(QNetworkRequest::ContentTypeHeader,
- "application/application/x-www-form-urlencoded");
- request.setRawHeader("Authorization", QStringLiteral("Client-ID %1").arg(IMGUR_CLIENT_ID).toUtf8());
-
- m_NetworkAM->post(request, byteArray);
-}
-
-void ImgurUploader::onUploadOk() {
- m_infoLabel->deleteLater();
-
- m_notification = new NotificationWidget();
- m_vLayout->addWidget(m_notification);
-
- ImageLabel *imageLabel = new ImageLabel();
- imageLabel->setScreenshot(m_pixmap);
- imageLabel->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
- connect(imageLabel, &ImageLabel::dragInitiated, this, &ImgurUploader::startDrag);
- m_vLayout->addWidget(imageLabel);
-
- m_hLayout = new QHBoxLayout();
- m_vLayout->addLayout(m_hLayout);
-
- m_copyUrlButton = new QPushButton(tr("Copy URL"));
- m_openUrlButton = new QPushButton(tr("Open URL"));
- m_openDeleteUrlButton = new QPushButton(tr("Delete image"));
- m_toClipboardButton = new QPushButton(tr("Image to Clipboard."));
- m_hLayout->addWidget(m_copyUrlButton);
- m_hLayout->addWidget(m_openUrlButton);
- m_hLayout->addWidget(m_openDeleteUrlButton);
- m_hLayout->addWidget(m_toClipboardButton);
-
- connect(m_copyUrlButton, &QPushButton::clicked,
- this, &ImgurUploader::copyURL);
- connect(m_openUrlButton, &QPushButton::clicked,
- this, &ImgurUploader::openURL);
- connect(m_openDeleteUrlButton, &QPushButton::clicked,
- this, &ImgurUploader::openDeleteURL);
- connect(m_toClipboardButton, &QPushButton::clicked,
- this, &ImgurUploader::copyImage);
-}
-
-void ImgurUploader::openURL() {
- bool successful = QDesktopServices::openUrl(m_imageURL);
- if (!successful) {
- m_notification->showMessage(tr("Unable to open the URL."));
- }
-}
-
-void ImgurUploader::copyURL() {
- QApplication::clipboard()->setText(m_imageURL.toString());
- m_notification->showMessage(tr("URL copied to clipboard."));
-}
-
-void ImgurUploader::openDeleteURL()
-{
- bool successful = QDesktopServices::openUrl(m_deleteImageURL);
- if (!successful) {
- m_notification->showMessage(tr("Unable to open the URL."));
- }
-}
-
-void ImgurUploader::copyImage() {
- QApplication::clipboard()->setPixmap(m_pixmap);
- m_notification->showMessage(tr("Screenshot copied to clipboard."));
-}
diff --git a/src/tools/storage/imgstorages.h b/src/tools/storage/imgstorages.h
new file mode 100644
index 00000000..ad7822f7
--- /dev/null
+++ b/src/tools/storage/imgstorages.h
@@ -0,0 +1,8 @@
+#ifndef IMGSTORAGES_H
+#define IMGSTORAGES_H
+
+#define SCREENSHOT_STORAGE_TYPE_LOCAL ""
+#define SCREENSHOT_STORAGE_TYPE_S3 "s3"
+#define SCREENSHOT_STORAGE_TYPE_IMGUR "imgur"
+
+#endif // IMGSTORAGES_H
diff --git a/src/tools/storage/imguploader.cpp b/src/tools/storage/imguploader.cpp
new file mode 100644
index 00000000..1e2b160a
--- /dev/null
+++ b/src/tools/storage/imguploader.cpp
@@ -0,0 +1,209 @@
+// Copyright(c) 2017-2019 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "imguploader.h"
+#include "src/utils/configenterprise.h"
+#include "src/utils/confighandler.h"
+#include "src/utils/filenamehandler.h"
+#include "src/utils/history.h"
+#include "src/utils/systemnotification.h"
+#include "src/widgets/imagelabel.h"
+#include "src/widgets/loadspinner.h"
+#include "src/widgets/notificationwidget.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+ImgUploader::ImgUploader(const QPixmap& capture, QWidget* parent)
+ : QWidget(parent)
+ , m_pixmap(capture)
+{
+ init(tr("Upload image to S3"), tr("Uploading Image"));
+}
+
+ImgUploader::ImgUploader(QWidget* parent)
+ : QWidget(parent)
+{
+ init(tr("Upload image"), tr("Uploading Image"));
+}
+
+void ImgUploader::init(const QString& title, const QString& label)
+{
+ m_imageLabel = nullptr;
+ m_spinner = nullptr;
+
+ resultStatus = false;
+ setWindowTitle(title);
+ setWindowIcon(QIcon(":img/app/flameshot.svg"));
+
+ m_spinner = new LoadSpinner(this);
+ m_spinner->setColor(ConfigHandler().uiMainColorValue());
+ m_spinner->start();
+
+ m_infoLabel = new QLabel(label);
+ m_infoLabel->setAlignment(Qt::AlignCenter);
+
+ m_vLayout = new QVBoxLayout();
+ setLayout(m_vLayout);
+ m_vLayout->addWidget(m_spinner, 0, Qt::AlignHCenter);
+ m_vLayout->addWidget(m_infoLabel);
+
+ setAttribute(Qt::WA_DeleteOnClose);
+}
+
+void ImgUploader::openURL()
+{
+ bool successful = QDesktopServices::openUrl(imageUrl());
+ if (!successful) {
+ m_notification->showMessage(tr("Unable to open the URL."));
+ }
+}
+
+void ImgUploader::copyURL()
+{
+ QApplication::clipboard()->setText(imageUrl().toString());
+ m_notification->showMessage(tr("URL copied to clipboard."));
+}
+
+void ImgUploader::copyImage()
+{
+ QApplication::clipboard()->setPixmap(m_pixmap);
+ m_notification->showMessage(tr("Screenshot copied to clipboard."));
+}
+
+void ImgUploader::deleteImageOnStorage()
+{
+ if (nullptr != m_imageLabel) {
+ m_imageLabel->hide();
+ }
+ m_spinner->show();
+ setInfoLabelText(tr("Deleting image..."));
+ deleteResource(m_storageImageName, m_deleteToken);
+}
+
+void ImgUploader::startDrag()
+{
+ QMimeData* mimeData = new QMimeData;
+ mimeData->setUrls(QList{ imageUrl() });
+ mimeData->setImageData(m_pixmap);
+
+ QDrag* dragHandler = new QDrag(this);
+ dragHandler->setMimeData(mimeData);
+ dragHandler->setPixmap(m_pixmap.scaled(
+ 256, 256, Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation));
+ dragHandler->exec();
+}
+
+void ImgUploader::hideSpinner()
+{
+ if (nullptr != m_spinner) {
+ m_spinner->hide();
+ }
+ if (nullptr != m_imageLabel) {
+ m_imageLabel->hide();
+ }
+}
+
+void ImgUploader::setInfoLabelText(const QString& infoText)
+{
+ m_infoLabel->setText(infoText);
+ m_infoLabel->show();
+}
+
+const QPixmap& ImgUploader::pixmap()
+{
+ return m_pixmap;
+}
+
+void ImgUploader::onUploadOk()
+{
+ hideSpinner();
+
+ m_notification = new NotificationWidget();
+ m_vLayout->addWidget(m_notification);
+
+ if (nullptr == m_imageLabel) {
+ m_imageLabel = new ImageLabel();
+ m_imageLabel->setScreenshot(pixmap());
+ m_imageLabel->setSizePolicy(QSizePolicy::Expanding,
+ QSizePolicy::Expanding);
+ connect(m_imageLabel,
+ &ImageLabel::dragInitiated,
+ this,
+ &ImgUploader::startDrag);
+ m_vLayout->addWidget(m_imageLabel);
+ }
+
+ m_hLayout = new QHBoxLayout();
+ m_vLayout->addLayout(m_hLayout);
+
+ m_copyUrlButton = new QPushButton(tr("Copy URL"));
+ m_openUrlButton = new QPushButton(tr("Open URL"));
+ m_deleteImageOnStorage = new QPushButton(tr("Delete image"));
+ m_toClipboardButton = new QPushButton(tr("Image to Clipboard."));
+ m_hLayout->addWidget(m_copyUrlButton);
+ m_hLayout->addWidget(m_openUrlButton);
+ m_hLayout->addWidget(m_deleteImageOnStorage);
+ m_hLayout->addWidget(m_toClipboardButton);
+
+ connect(
+ m_copyUrlButton, &QPushButton::clicked, this, &ImgUploader::copyURL);
+ connect(
+ m_openUrlButton, &QPushButton::clicked, this, &ImgUploader::openURL);
+ connect(m_deleteImageOnStorage,
+ &QPushButton::clicked,
+ this,
+ &ImgUploader::deleteImageOnStorage);
+ connect(m_toClipboardButton,
+ &QPushButton::clicked,
+ this,
+ &ImgUploader::copyImage);
+}
+
+void ImgUploader::setImageUrl(const QUrl& imageURL)
+{
+ m_imageURL = imageURL;
+}
+const QUrl& ImgUploader::imageUrl()
+{
+ return m_imageURL;
+}
+
+void ImgUploader::showNotificationMessage(const QString& notificationMessage) {
+ m_notification->showMessage(notificationMessage);
+}
+
diff --git a/src/tools/storage/imguploader.h b/src/tools/storage/imguploader.h
new file mode 100644
index 00000000..5369f183
--- /dev/null
+++ b/src/tools/storage/imguploader.h
@@ -0,0 +1,96 @@
+// Copyright(c) 2017-2019 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#pragma once
+
+#include "imgstorages.h"
+#include "s3/imgs3settings.h"
+#include
+#include
+
+class QNetworkReply;
+class QNetworkProxy;
+class QNetworkAccessManager;
+class QHBoxLayout;
+class QVBoxLayout;
+class QLabel;
+class LoadSpinner;
+class QPushButton;
+class QUrl;
+class NotificationWidget;
+class ConfigEnterprise;
+class ImageLabel;
+
+class ImgUploader : public QWidget
+{
+ Q_OBJECT
+public:
+ explicit ImgUploader(const QPixmap& capture, QWidget* parent = nullptr);
+ explicit ImgUploader(QWidget* parent = nullptr);
+
+ virtual void upload(){};
+ virtual void deleteResource(const QString&, const QString&){};
+
+protected:
+ const QPixmap& pixmap();
+ void setImageUrl(const QUrl&);
+ const QUrl& imageUrl();
+ void onUploadOk();
+ void hideSpinner();
+ void setInfoLabelText(const QString&);
+ void showNotificationMessage(const QString&);
+
+public slots:
+ virtual void openURL();
+ virtual void copyURL();
+ virtual void copyImage();
+ virtual void deleteImageOnStorage();
+ virtual void startDrag();
+
+private:
+ void init(const QString& title, const QString& label);
+
+ // class members
+private:
+ QPixmap m_pixmap;
+
+ QUrl m_imageURL;
+ ImageLabel* m_imageLabel;
+
+ NotificationWidget* m_notification;
+
+ QVBoxLayout* m_vLayout;
+ QHBoxLayout* m_hLayout;
+ // loading
+ LoadSpinner* m_spinner;
+ QLabel* m_infoLabel;
+ // uploaded
+ QPushButton* m_openUrlButton;
+ QPushButton* m_copyUrlButton;
+ QPushButton* m_toClipboardButton;
+ QPushButton* m_deleteImageOnStorage;
+
+protected:
+ // bool m_success;
+
+ // Temporary variables
+ QString m_deleteToken;
+ QString m_storageImageName;
+
+public:
+ bool resultStatus;
+};
diff --git a/src/tools/storage/imgur/imguruploader.cpp b/src/tools/storage/imgur/imguruploader.cpp
new file mode 100644
index 00000000..02bff6d8
--- /dev/null
+++ b/src/tools/storage/imgur/imguruploader.cpp
@@ -0,0 +1,129 @@
+// Copyright(c) 2017-2019 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "imguruploader.h"
+#include "src/utils/confighandler.h"
+#include "src/utils/filenamehandler.h"
+#include "src/utils/history.h"
+#include "src/utils/systemnotification.h"
+#include "src/widgets/imagelabel.h"
+#include "src/widgets/loadspinner.h"
+#include "src/widgets/notificationwidget.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+ImgurUploader::ImgurUploader(const QPixmap& capture, QWidget* parent)
+ : ImgUploader(capture, parent)
+{
+ setWindowTitle(tr("Upload to Imgur"));
+
+ m_NetworkAM = new QNetworkAccessManager(this);
+ connect(m_NetworkAM,
+ &QNetworkAccessManager::finished,
+ this,
+ &ImgurUploader::handleReply);
+ // QTimer::singleShot(2000, this, &ImgurUploader::onUploadOk); // testing
+}
+
+void ImgurUploader::handleReply(QNetworkReply* reply)
+{
+ if (reply->error() == QNetworkReply::NoError) {
+ QJsonDocument response = QJsonDocument::fromJson(reply->readAll());
+ QJsonObject json = response.object();
+ QJsonObject data = json[QStringLiteral("data")].toObject();
+ setImageUrl(data[QStringLiteral("link")].toString());
+ m_deleteToken = data[QStringLiteral("deletehash")].toString();
+
+ m_deleteImageURL.setUrl(
+ QStringLiteral("https://imgur.com/delete/%1").arg(m_deleteToken));
+
+ // save history
+ QString imageName = imageUrl().toString();
+ int lastSlash = imageName.lastIndexOf("/");
+ if (lastSlash >= 0) {
+ imageName = imageName.mid(lastSlash + 1);
+ }
+ m_storageImageName = imageName;
+
+ // save image to history
+ History history;
+ imageName = history.packFileName(
+ SCREENSHOT_STORAGE_TYPE_IMGUR, m_deleteToken, imageName);
+ history.save(pixmap(), imageName);
+ resultStatus = true;
+
+ if (ConfigHandler().copyAndCloseAfterUploadEnabled()) {
+ QApplication::clipboard()->setText(imageUrl().toString());
+ SystemNotification().sendMessage(
+ QObject::tr("URL copied to clipboard."));
+ close();
+ } else {
+ onUploadOk();
+ }
+ } else {
+ setInfoLabelText(reply->errorString());
+ }
+ new QShortcut(Qt::Key_Escape, this, SLOT(close()));
+}
+
+void ImgurUploader::upload()
+{
+ QByteArray byteArray;
+ QBuffer buffer(&byteArray);
+ pixmap().save(&buffer, "PNG");
+
+ QUrlQuery urlQuery;
+ urlQuery.addQueryItem(QStringLiteral("title"),
+ QStringLiteral("flameshot_screenshot"));
+ QString description = FileNameHandler().parsedPattern();
+ urlQuery.addQueryItem(QStringLiteral("description"), description);
+
+ QUrl url(QStringLiteral("https://api.imgur.com/3/image"));
+ url.setQuery(urlQuery);
+ QNetworkRequest request(url);
+ request.setHeader(QNetworkRequest::ContentTypeHeader,
+ "application/application/x-www-form-urlencoded");
+ request.setRawHeader(
+ "Authorization",
+ QStringLiteral("Client-ID %1").arg(IMGUR_CLIENT_ID).toUtf8());
+
+ m_NetworkAM->post(request, byteArray);
+}
+
+void ImgurUploader::deleteImageOnStorage()
+{
+ bool successful = QDesktopServices::openUrl(m_deleteImageURL);
+ if (!successful) {
+ showNotificationMessage(tr("Unable to open the URL."));
+ }
+}
diff --git a/src/tools/imgur/imguruploader.h b/src/tools/storage/imgur/imguruploader.h
similarity index 61%
rename from src/tools/imgur/imguruploader.h
rename to src/tools/storage/imgur/imguruploader.h
index 94458655..89145011 100644
--- a/src/tools/imgur/imguruploader.h
+++ b/src/tools/storage/imgur/imguruploader.h
@@ -17,8 +17,9 @@
#pragma once
-#include
+#include "../imguploader.h"
#include
+#include
class QNetworkReply;
class QNetworkAccessManager;
@@ -30,38 +31,21 @@ class QPushButton;
class QUrl;
class NotificationWidget;
-class ImgurUploader : public QWidget {
+class ImgurUploader : public ImgUploader
+{
Q_OBJECT
public:
- explicit ImgurUploader(const QPixmap &capture, QWidget *parent = nullptr);
+ explicit ImgurUploader(const QPixmap& capture, QWidget* parent = nullptr);
+ void upload();
private slots:
- void handleReply(QNetworkReply *reply);
- void startDrag();
+ void handleReply(QNetworkReply* reply);
- void openURL();
- void copyURL();
- void openDeleteURL();
- void copyImage();
+protected slots:
+ void deleteImageOnStorage();
+ // class members
private:
- QPixmap m_pixmap;
- QNetworkAccessManager *m_NetworkAM;
-
- QVBoxLayout *m_vLayout;
- QHBoxLayout *m_hLayout;
- // loading
- QLabel *m_infoLabel;
- LoadSpinner *m_spinner;
- // uploaded
- QPushButton *m_openUrlButton;
- QPushButton *m_openDeleteUrlButton;
- QPushButton *m_copyUrlButton;
- QPushButton *m_toClipboardButton;
- QUrl m_imageURL;
+ QNetworkAccessManager* m_NetworkAM;
QUrl m_deleteImageURL;
- NotificationWidget *m_notification;
-
- void upload();
- void onUploadOk();
};
diff --git a/src/tools/imgur/imguruploadertool.cpp b/src/tools/storage/imgur/imguruploadertool.cpp
similarity index 65%
rename from src/tools/imgur/imguruploadertool.cpp
rename to src/tools/storage/imgur/imguruploadertool.cpp
index ea68303c..44dabf4a 100644
--- a/src/tools/imgur/imguruploadertool.cpp
+++ b/src/tools/storage/imgur/imguruploadertool.cpp
@@ -19,39 +19,55 @@
#include "imguruploader.h"
#include
-ImgurUploaderTool::ImgurUploaderTool(QObject *parent) : AbstractActionTool(parent) {
+ImgurUploaderTool::ImgurUploaderTool(QObject* parent)
+ : AbstractActionTool(parent)
+{}
-}
-
-bool ImgurUploaderTool::closeOnButtonPressed() const {
+bool ImgurUploaderTool::closeOnButtonPressed() const
+{
return true;
}
-QIcon ImgurUploaderTool::icon(const QColor &background, bool inEditor) const {
+QIcon ImgurUploaderTool::icon(const QColor& background, bool inEditor) const
+{
Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "cloud-upload.svg");
}
-QString ImgurUploaderTool::name() const {
+
+QString ImgurUploaderTool::name() const
+{
return tr("Image Uploader");
}
-QString ImgurUploaderTool::nameID() {
+QString ImgurUploaderTool::nameID()
+{
return QLatin1String("");
}
-QString ImgurUploaderTool::description() const {
+QString ImgurUploaderTool::description() const
+{
return tr("Upload the selection to Imgur");
}
-QWidget* ImgurUploaderTool::widget() {
- return new ImgurUploader(capture);
+QWidget* ImgurUploaderTool::widget()
+{
+ ImgurUploader* p = new ImgurUploader(capture);
+ p->upload();
+ return p;
}
-CaptureTool* ImgurUploaderTool::copy(QObject *parent) {
+void ImgurUploaderTool::setCapture(const QPixmap& pixmap)
+{
+ capture = pixmap;
+}
+
+CaptureTool* ImgurUploaderTool::copy(QObject* parent)
+{
return new ImgurUploaderTool(parent);
}
-void ImgurUploaderTool::pressed(const CaptureContext &context) {
+void ImgurUploaderTool::pressed(const CaptureContext& context)
+{
capture = context.selectedScreenshotArea();
emit requestAction(REQ_CAPTURE_DONE_OK);
emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
diff --git a/src/tools/imgur/imguruploadertool.h b/src/tools/storage/imgur/imguruploadertool.h
similarity index 76%
rename from src/tools/imgur/imguruploadertool.h
rename to src/tools/storage/imgur/imguruploadertool.h
index e0e49617..8ce93082 100644
--- a/src/tools/imgur/imguruploadertool.h
+++ b/src/tools/storage/imgur/imguruploadertool.h
@@ -19,24 +19,26 @@
#include "src/tools/abstractactiontool.h"
-class ImgurUploaderTool : public AbstractActionTool {
+class ImgurUploaderTool : public AbstractActionTool
+{
Q_OBJECT
public:
- explicit ImgurUploaderTool(QObject *parent = nullptr);
+ explicit ImgurUploaderTool(QObject* parent = nullptr);
bool closeOnButtonPressed() const;
- QIcon icon(const QColor &background, bool inEditor) const override;
+ QIcon icon(const QColor& background, bool inEditor) const override;
QString name() const override;
static QString nameID();
QString description() const override;
QWidget* widget() override;
- CaptureTool* copy(QObject *parent = nullptr) override;
+ CaptureTool* copy(QObject* parent = nullptr) override;
+ void setCapture(const QPixmap&);
public slots:
- void pressed(const CaptureContext &context) override;
+ void pressed(const CaptureContext& context) override;
private:
QPixmap capture;
diff --git a/src/tools/imgs3/imgs3settings.cpp b/src/tools/storage/s3/imgs3settings.cpp
similarity index 52%
rename from src/tools/imgs3/imgs3settings.cpp
rename to src/tools/storage/s3/imgs3settings.cpp
index 41695aee..fcf23ec0 100644
--- a/src/tools/imgs3/imgs3settings.cpp
+++ b/src/tools/storage/s3/imgs3settings.cpp
@@ -7,28 +7,38 @@ ImgS3Settings::ImgS3Settings()
m_configEnterprise = new ConfigEnterprise();
// get s3 credentials
- QSettings *settings = m_configEnterprise->settings();
+ QSettings* settings = m_configEnterprise->settings();
settings->beginGroup("S3");
m_credsUrl = settings->value("S3_CREDS_URL").toString();
- m_credsUrl = m_credsUrl + ((m_credsUrl.length() > 0 && m_credsUrl[m_credsUrl.length() - 1] == '/') ? "" : "/") + S3_API_IMG_PATH;
+ m_credsUrl =
+ m_credsUrl +
+ ((m_credsUrl.length() > 0 && m_credsUrl[m_credsUrl.length() - 1] == '/')
+ ? ""
+ : "/") +
+ S3_API_IMG_PATH;
m_xApiKey = settings->value("S3_X_API_KEY").toString();
m_url = settings->value("S3_URL").toString();
- m_url = m_url + ((m_url.length() > 0 && m_url[m_url.length() - 1] == '/') ? "" : "/");
+ m_url =
+ m_url +
+ ((m_url.length() > 0 && m_url[m_url.length() - 1] == '/') ? "" : "/");
settings->endGroup();
}
-const QString &ImgS3Settings::credsUrl() {
+const QString& ImgS3Settings::credsUrl()
+{
return m_credsUrl;
}
-const QString &ImgS3Settings::xApiKey() {
+const QString& ImgS3Settings::xApiKey()
+{
return m_xApiKey;
}
-const QString &ImgS3Settings::url() {
+const QString& ImgS3Settings::url()
+{
return m_url;
}
diff --git a/src/tools/imgs3/imgs3settings.h b/src/tools/storage/s3/imgs3settings.h
similarity index 68%
rename from src/tools/imgs3/imgs3settings.h
rename to src/tools/storage/s3/imgs3settings.h
index d44b79e2..c4b8689b 100644
--- a/src/tools/imgs3/imgs3settings.h
+++ b/src/tools/storage/s3/imgs3settings.h
@@ -3,7 +3,6 @@
#define S3_API_IMG_PATH "v2/image/"
-
#include
class ConfigEnterprise;
@@ -13,12 +12,12 @@ class ImgS3Settings
public:
ImgS3Settings();
- const QString &credsUrl();
- const QString &xApiKey();
- const QString &url();
+ const QString& credsUrl();
+ const QString& xApiKey();
+ const QString& url();
private:
- ConfigEnterprise *m_configEnterprise;
+ ConfigEnterprise* m_configEnterprise;
QString m_credsUrl;
QString m_xApiKey;
QString m_url;
diff --git a/src/tools/storage/s3/imgs3uploader.cpp b/src/tools/storage/s3/imgs3uploader.cpp
new file mode 100644
index 00000000..09b53795
--- /dev/null
+++ b/src/tools/storage/s3/imgs3uploader.cpp
@@ -0,0 +1,396 @@
+// Copyright(c) 2017-2019 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#include "imgs3uploader.h"
+#include "src/utils/configenterprise.h"
+#include "src/utils/confighandler.h"
+#include "src/utils/filenamehandler.h"
+#include "src/utils/history.h"
+#include "src/utils/systemnotification.h"
+#include "src/widgets/imagelabel.h"
+#include "src/widgets/loadspinner.h"
+#include "src/widgets/notificationwidget.h"
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+ImgS3Uploader::ImgS3Uploader(const QPixmap& capture, QWidget* parent)
+ : ImgUploader(capture, parent)
+{
+ init(tr("Upload image to S3"), tr("Uploading Image"));
+}
+
+ImgS3Uploader::ImgS3Uploader(QWidget* parent)
+ : ImgUploader(parent)
+{
+ init(tr("Delete image from S3"), tr("Deleting image..."));
+}
+
+void ImgS3Uploader::init(const QString& title, const QString& label)
+{
+ m_proxy = nullptr;
+ m_NetworkAMUpload = nullptr;
+ m_NetworkAMGetCreds = nullptr;
+ m_NetworkAMRemove = nullptr;
+
+ resultStatus = false;
+ setWindowTitle(title);
+ setWindowIcon(QIcon(":img/app/flameshot.svg"));
+}
+
+QNetworkProxy* ImgS3Uploader::proxy()
+{
+ if (m_proxy == nullptr) {
+ initProxy();
+ }
+ return m_proxy;
+}
+
+QNetworkProxy* ImgS3Uploader::initProxy()
+{
+ // get enterprise settings
+ ConfigEnterprise* configEnterprise = new ConfigEnterprise();
+
+ // get proxy settings from "config.ini" file
+ QSettings* settings = configEnterprise->settings();
+ QString httpProxyHost = settings->value("HTTP_PROXY_HOST").toString();
+
+ if (httpProxyHost.length() > 0) {
+ m_proxy = new QNetworkProxy();
+
+ if (settings->contains("HTTP_PROXY_TYPE")) {
+ switch (settings->value("HTTP_PROXY_TYPE").toInt()) {
+ case 0:
+ m_proxy->setType(QNetworkProxy::DefaultProxy);
+ break;
+ case 1:
+ m_proxy->setType(QNetworkProxy::Socks5Proxy);
+ break;
+ case 2:
+ m_proxy->setType(QNetworkProxy::NoProxy);
+ break;
+ case 4:
+ m_proxy->setType(QNetworkProxy::HttpCachingProxy);
+ break;
+ case 5:
+ m_proxy->setType(QNetworkProxy::FtpCachingProxy);
+ break;
+ case 3:
+ default:
+ m_proxy->setType(QNetworkProxy::HttpProxy);
+ break;
+ }
+ }
+
+ m_proxy->setHostName(httpProxyHost);
+ int nProxyPort = 3128;
+ if (settings->contains("HTTP_PROXY_PORT")) {
+ nProxyPort = settings->value("HTTP_PROXY_PORT").toInt();
+ }
+ m_proxy->setPort(nProxyPort);
+
+ if (settings->contains("HTTP_PROXY_USER")) {
+ qDebug() << "Proxy user"
+ << settings->value("HTTP_PROXY_PASSWORD").toString();
+ m_proxy->setUser(settings->value("HTTP_PROXY_USER").toString());
+ }
+ if (settings->contains("HTTP_PROXY_PASSWORD")) {
+ qDebug() << "Proxy password is not empty";
+ m_proxy->setPassword(
+ settings->value("HTTP_PROXY_PASSWORD").toString());
+ }
+ } else {
+ // Get proxy settings from OS settings
+ QNetworkProxyQuery q(QUrl(m_s3Settings.credsUrl().toUtf8()));
+ q.setQueryType(QNetworkProxyQuery::UrlRequest);
+ q.setProtocolTag("http");
+
+ QList proxies =
+ QNetworkProxyFactory::systemProxyForQuery(q);
+ if (proxies.size() > 0 && proxies[0].type() != QNetworkProxy::NoProxy) {
+ m_proxy = new QNetworkProxy();
+ m_proxy->setHostName(proxies[0].hostName());
+ m_proxy->setPort(proxies[0].port());
+ m_proxy->setType(proxies[0].type());
+ m_proxy->setUser(proxies[0].user());
+ m_proxy->setPassword(proxies[0].password());
+ }
+ }
+#ifdef QT_DEBUG
+ if (m_proxy != nullptr) {
+ qDebug() << "Using proxy server";
+ qDebug() << "proxy host:" << m_proxy->hostName();
+ qDebug() << "proxy port:" << m_proxy->port();
+ qDebug() << "proxy type:" << m_proxy->type();
+ qDebug() << "proxy user:"
+ << (m_proxy->user().length() > 0 ? m_proxy->user()
+ : "no user");
+ qDebug() << "proxy password:"
+ << (m_proxy->password().length() > 0 ? "***" : "no password");
+ } else {
+ qDebug() << "No proxy";
+ }
+#endif
+ return m_proxy;
+}
+
+void ImgS3Uploader::clearProxy()
+{
+ if (m_proxy != nullptr) {
+ delete m_proxy;
+ m_proxy = nullptr;
+ }
+}
+
+void ImgS3Uploader::handleReplyUpload(QNetworkReply* reply)
+{
+ hideSpinner();
+ m_storageImageName.clear();
+ if (reply->error() == QNetworkReply::NoError) {
+ // save history
+ QString imageName = imageUrl().toString();
+ int lastSlash = imageName.lastIndexOf("/");
+ if (lastSlash >= 0) {
+ imageName = imageName.mid(lastSlash + 1);
+ }
+ m_storageImageName = imageName;
+
+ // save image to history
+ History history;
+ imageName = history.packFileName(
+ SCREENSHOT_STORAGE_TYPE_S3, m_deleteToken, imageName);
+ history.save(pixmap(), imageName);
+ resultStatus = true;
+
+ // Copy url to clipboard if required
+ if (ConfigHandler().copyAndCloseAfterUploadEnabled()) {
+ QApplication::clipboard()->setText(imageUrl().toString());
+ SystemNotification().sendMessage(tr("URL copied to clipboard."));
+ close();
+ } else {
+ onUploadOk();
+ }
+ } else {
+ QString reason =
+ reply->attribute(QNetworkRequest::HttpReasonPhraseAttribute)
+ .toString();
+ setInfoLabelText(reply->errorString());
+ }
+ new QShortcut(Qt::Key_Escape, this, SLOT(close()));
+}
+
+void ImgS3Uploader::handleReplyDeleteResource(QNetworkReply* reply)
+{
+ auto replyError = reply->error();
+ if (replyError == QNetworkReply::NoError) {
+ removeImagePreview();
+ } else {
+ hide();
+
+ // generate error message
+ QString message =
+ tr("Unable to remove screenshot from the remote storage.");
+ if (replyError == QNetworkReply::UnknownNetworkError) {
+ message += "\n" + tr("Network error");
+ } else if (replyError == QNetworkReply::UnknownServerError) {
+ message += "\n" + tr("Possibly it doesn't exist anymore");
+ }
+ message += "\n\n" + reply->errorString();
+ message +=
+ "\n\n" +
+ tr("Do you want to remove screenshot from local history anyway?");
+
+ if (QMessageBox::Yes ==
+ QMessageBox::question(NULL,
+ tr("Remove screenshot from history?"),
+ message,
+ QMessageBox::Yes | QMessageBox::No)) {
+ removeImagePreview();
+ }
+ }
+ close();
+}
+
+void ImgS3Uploader::handleReplyGetCreds(QNetworkReply* reply)
+{
+ if (reply->error() == QNetworkReply::NoError) {
+ QJsonDocument response = QJsonDocument::fromJson(reply->readAll());
+ uploadToS3(response);
+ } else {
+ if (m_s3Settings.credsUrl().length() == 0) {
+ setInfoLabelText(
+ tr("S3 Creds URL is not found in your configuration file"));
+ } else {
+ setInfoLabelText(reply->errorString());
+ }
+ }
+ new QShortcut(Qt::Key_Escape, this, SLOT(close()));
+}
+
+void ImgS3Uploader::uploadToS3(QJsonDocument& response)
+{
+ // set paramets from "fields"
+ QHttpMultiPart* multiPart =
+ new QHttpMultiPart(QHttpMultiPart::FormDataType);
+
+ // read JSON response
+ QJsonObject json = response.object();
+ QString resultUrl = json["resultURL"].toString();
+ QJsonObject formData = json["formData"].toObject();
+ QString url = formData["url"].toString();
+ m_deleteToken = json["deleteToken"].toString();
+
+ QJsonObject fields = formData["fields"].toObject();
+ foreach (auto key, fields.keys()) {
+ QString field = fields[key].toString();
+ QHttpPart part;
+ part.setHeader(QNetworkRequest::ContentDispositionHeader,
+ QVariant("form-data; name=\"" + key + "\""));
+ part.setBody(field.toLatin1());
+ multiPart->append(part);
+ }
+
+ QHttpPart imagePart;
+ imagePart.setHeader(QNetworkRequest::ContentTypeHeader,
+ QVariant("image/png"));
+ imagePart.setHeader(QNetworkRequest::ContentDispositionHeader,
+ QVariant("form-data; name=\"file\""));
+
+ QByteArray byteArray;
+ QBuffer buffer(&byteArray);
+ buffer.open(QIODevice::WriteOnly);
+ pixmap().save(&buffer, "PNG");
+
+ imagePart.setBody(byteArray);
+ multiPart->append(imagePart);
+
+ setImageUrl(QUrl(resultUrl));
+
+ QUrl qUrl(url);
+ QNetworkRequest request(qUrl);
+
+ // upload
+ m_NetworkAMUpload->post(request, multiPart);
+}
+
+void ImgS3Uploader::deleteResource(const QString& fileName,
+ const QString& deleteToken)
+{
+ // read network settings on each call to simplify configuration management
+ // without restarting
+ clearProxy();
+ if (m_NetworkAMRemove != nullptr) {
+ delete m_NetworkAMRemove;
+ m_NetworkAMRemove = nullptr;
+ }
+ m_NetworkAMRemove = new QNetworkAccessManager(this);
+ connect(m_NetworkAMRemove,
+ &QNetworkAccessManager::finished,
+ this,
+ &ImgS3Uploader::handleReplyDeleteResource);
+ if (proxy() != nullptr) {
+ m_NetworkAMRemove->setProxy(*proxy());
+ }
+
+ QNetworkRequest request;
+ m_storageImageName = fileName;
+ m_deleteToken = deleteToken;
+ request.setUrl(m_s3Settings.credsUrl().toUtf8() + fileName);
+ request.setRawHeader("X-API-Key", m_s3Settings.xApiKey().toLatin1());
+ request.setRawHeader("Authorization", "Bearer " + deleteToken.toLatin1());
+ m_NetworkAMRemove->deleteResource(request);
+}
+
+void ImgS3Uploader::upload()
+{
+ m_deleteToken.clear();
+ m_storageImageName.clear();
+
+ // read network settings on each call to simplify configuration management
+ // without restarting init creds and upload network access managers
+ clearProxy();
+ if (m_NetworkAMGetCreds != nullptr) {
+ delete m_NetworkAMGetCreds;
+ m_NetworkAMGetCreds = nullptr;
+ }
+ m_NetworkAMGetCreds = new QNetworkAccessManager(this);
+ connect(m_NetworkAMGetCreds,
+ &QNetworkAccessManager::finished,
+ this,
+ &ImgS3Uploader::handleReplyGetCreds);
+
+ if (m_NetworkAMUpload != nullptr) {
+ delete m_NetworkAMUpload;
+ m_NetworkAMUpload = nullptr;
+ }
+ m_NetworkAMUpload = new QNetworkAccessManager(this);
+ connect(m_NetworkAMUpload,
+ &QNetworkAccessManager::finished,
+ this,
+ &ImgS3Uploader::handleReplyUpload);
+ if (proxy() != nullptr) {
+ m_NetworkAMGetCreds->setProxy(*proxy());
+ m_NetworkAMUpload->setProxy(*proxy());
+ }
+
+ // get creads
+ QUrl creds(m_s3Settings.credsUrl());
+ QNetworkRequest requestCreds(creds);
+ if (m_s3Settings.xApiKey().length() > 0) {
+ requestCreds.setRawHeader(
+ QByteArray("X-API-Key"),
+ QByteArray(m_s3Settings.xApiKey().toLocal8Bit()));
+ }
+ m_NetworkAMGetCreds->get(requestCreds);
+}
+
+void ImgS3Uploader::removeImagePreview()
+{
+ // remove local file
+ History history;
+ QString packedFileName = history.packFileName(
+ SCREENSHOT_STORAGE_TYPE_S3, m_deleteToken, m_storageImageName);
+ QString fullFileName = history.path() + packedFileName;
+
+ QFile file(fullFileName);
+ if (file.exists()) {
+ file.remove();
+ }
+ m_deleteToken.clear();
+ m_storageImageName.clear();
+ resultStatus = true;
+}
diff --git a/src/tools/storage/s3/imgs3uploader.h b/src/tools/storage/s3/imgs3uploader.h
new file mode 100644
index 00000000..3168bf29
--- /dev/null
+++ b/src/tools/storage/s3/imgs3uploader.h
@@ -0,0 +1,70 @@
+// Copyright(c) 2017-2019 Alejandro Sirgo Rica & Contributors
+//
+// This file is part of Flameshot.
+//
+// Flameshot is free software: you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// Flameshot is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with Flameshot. If not, see .
+
+#pragma once
+
+#define S3_API_IMG_PATH "v2/image/"
+
+#include "../imguploader.h"
+#include "imgs3settings.h"
+#include
+#include
+
+class QNetworkReply;
+class QNetworkProxy;
+class QNetworkAccessManager;
+class QHBoxLayout;
+class QVBoxLayout;
+class QLabel;
+class QPushButton;
+class QUrl;
+class NotificationWidget;
+class ConfigEnterprise;
+class ImageLabel;
+
+class ImgS3Uploader : public ImgUploader
+{
+ Q_OBJECT
+public:
+ explicit ImgS3Uploader(const QPixmap& capture, QWidget* parent = nullptr);
+ explicit ImgS3Uploader(QWidget* parent = nullptr);
+ void upload();
+ void deleteResource(const QString&, const QString&);
+
+private slots:
+ void handleReplyUpload(QNetworkReply* reply);
+ void handleReplyGetCreds(QNetworkReply* reply);
+ void handleReplyDeleteResource(QNetworkReply* reply);
+
+private:
+ void init(const QString& title, const QString& label);
+ void uploadToS3(QJsonDocument& response);
+ void removeImagePreview();
+
+ QNetworkProxy* initProxy();
+ void clearProxy();
+ QNetworkProxy* proxy();
+
+ // class members
+private:
+ ImgS3Settings m_s3Settings;
+
+ QNetworkProxy* m_proxy;
+ QNetworkAccessManager* m_NetworkAMUpload;
+ QNetworkAccessManager* m_NetworkAMGetCreds;
+ QNetworkAccessManager* m_NetworkAMRemove;
+};
diff --git a/src/tools/imgs3/imgs3uploadertool.cpp b/src/tools/storage/s3/imgs3uploadertool.cpp
similarity index 66%
rename from src/tools/imgs3/imgs3uploadertool.cpp
rename to src/tools/storage/s3/imgs3uploadertool.cpp
index 45f04aaf..e1694470 100644
--- a/src/tools/imgs3/imgs3uploadertool.cpp
+++ b/src/tools/storage/s3/imgs3uploadertool.cpp
@@ -18,49 +18,56 @@
#include "imgs3uploadertool.h"
#include "imgs3uploader.h"
#include
-#include
-#include
+ImgS3UploaderTool::ImgS3UploaderTool(QObject* parent)
+ : AbstractActionTool(parent)
+{}
-ImgS3UploaderTool::ImgS3UploaderTool(QObject *parent) : AbstractActionTool(parent) {
-}
-
-bool ImgS3UploaderTool::closeOnButtonPressed() const {
+bool ImgS3UploaderTool::closeOnButtonPressed() const
+{
return true;
}
-QIcon ImgS3UploaderTool::icon(const QColor &background, bool inEditor) const {
+QIcon ImgS3UploaderTool::icon(const QColor& background, bool inEditor) const
+{
Q_UNUSED(inEditor);
return QIcon(iconPath(background) + "cloud-upload.svg");
}
-QString ImgS3UploaderTool::name() const {
+QString ImgS3UploaderTool::name() const
+{
return tr("Image Uploader");
}
-QString ImgS3UploaderTool::nameID() {
+QString ImgS3UploaderTool::nameID()
+{
return QLatin1String("");
}
-QString ImgS3UploaderTool::description() const {
+QString ImgS3UploaderTool::description() const
+{
return tr("Upload the selection to S3 bucket");
}
-QWidget *ImgS3UploaderTool::widget() {
- ImgS3Uploader *p = new ImgS3Uploader(capture);
+QWidget* ImgS3UploaderTool::widget()
+{
+ ImgS3Uploader* p = new ImgS3Uploader(capture);
p->upload();
return p;
}
-void ImgS3UploaderTool::setCapture(const QPixmap &pixmap) {
+void ImgS3UploaderTool::setCapture(const QPixmap& pixmap)
+{
capture = pixmap;
}
-CaptureTool *ImgS3UploaderTool::copy(QObject *parent) {
+CaptureTool* ImgS3UploaderTool::copy(QObject* parent)
+{
return new ImgS3UploaderTool(parent);
}
-void ImgS3UploaderTool::pressed(const CaptureContext &context) {
+void ImgS3UploaderTool::pressed(const CaptureContext& context)
+{
capture = context.selectedScreenshotArea();
emit requestAction(REQ_CAPTURE_DONE_OK);
emit requestAction(REQ_ADD_EXTERNAL_WIDGETS);
diff --git a/src/tools/imgs3/imgs3uploadertool.h b/src/tools/storage/s3/imgs3uploadertool.h
similarity index 76%
rename from src/tools/imgs3/imgs3uploadertool.h
rename to src/tools/storage/s3/imgs3uploadertool.h
index 8b1846ce..4d5bdbc9 100644
--- a/src/tools/imgs3/imgs3uploadertool.h
+++ b/src/tools/storage/s3/imgs3uploadertool.h
@@ -19,25 +19,26 @@
#include "src/tools/abstractactiontool.h"
-class ImgS3UploaderTool : public AbstractActionTool {
+class ImgS3UploaderTool : public AbstractActionTool
+{
Q_OBJECT
public:
- explicit ImgS3UploaderTool(QObject *parent = nullptr);
+ explicit ImgS3UploaderTool(QObject* parent = nullptr);
bool closeOnButtonPressed() const;
- QIcon icon(const QColor &background, bool inEditor) const override;
+ QIcon icon(const QColor& background, bool inEditor) const override;
QString name() const override;
static QString nameID();
QString description() const override;
QWidget* widget() override;
- CaptureTool* copy(QObject *parent = nullptr) override;
- void setCapture(const QPixmap &pixmap);
+ CaptureTool* copy(QObject* parent = nullptr) override;
+ void setCapture(const QPixmap& pixmap);
public slots:
- void pressed(const CaptureContext &context) override;
+ void pressed(const CaptureContext& context) override;
private:
QPixmap capture;
diff --git a/src/tools/storage/storagemanager.cpp b/src/tools/storage/storagemanager.cpp
new file mode 100644
index 00000000..d8231650
--- /dev/null
+++ b/src/tools/storage/storagemanager.cpp
@@ -0,0 +1,33 @@
+#include "storagemanager.h"
+#include "imguploader.h"
+#include "imgur/imguruploader.h"
+#include "imgur/imguruploadertool.h"
+#include "s3/imgs3uploader.h"
+#include "s3/imgs3uploadertool.h"
+#include "src/tools/storage/s3/imgs3settings.h"
+#include "src/tools/capturetool.h"
+
+#include
+
+StorageManager::StorageManager() {}
+
+CaptureTool* StorageManager::imgUploaderTool(const QString& imgUploaderType,
+ QObject* parent)
+{
+ if (imgUploaderType == SCREENSHOT_STORAGE_TYPE_S3) {
+ return new ImgS3UploaderTool(parent);
+ } else if (imgUploaderType == SCREENSHOT_STORAGE_TYPE_IMGUR) {
+ return new ImgurUploaderTool(parent);
+ }
+ return nullptr;
+}
+
+const QString& StorageManager::storageUrl(const QString& imgUploaderType) {
+ if (imgUploaderType == SCREENSHOT_STORAGE_TYPE_S3) {
+ ImgS3Settings s3Settings;
+ m_qstr = s3Settings.url();
+ } else if (imgUploaderType == SCREENSHOT_STORAGE_TYPE_IMGUR) {
+ m_qstr = "https://i.imgur.com/";
+ }
+ return m_qstr;
+}
diff --git a/src/tools/storage/storagemanager.h b/src/tools/storage/storagemanager.h
new file mode 100644
index 00000000..4d1c4a7d
--- /dev/null
+++ b/src/tools/storage/storagemanager.h
@@ -0,0 +1,25 @@
+#ifndef STORAGEMANAGER_H
+#define STORAGEMANAGER_H
+
+#include
+#include
+
+class QObject;
+class ImgUploader;
+class CaptureTool;
+
+class StorageManager
+{
+public:
+ explicit StorageManager();
+
+ CaptureTool* imgUploaderTool(const QString& imgUploaderType,
+ QObject* parent = nullptr);
+ const QString& storageUrl(const QString& imgUploaderType);
+
+// class members
+private:
+ QString m_qstr;
+};
+
+#endif // STORAGEMANAGER_H
diff --git a/src/tools/toolfactory.cpp b/src/tools/toolfactory.cpp
index f76d7ca8..682e81b1 100644
--- a/src/tools/toolfactory.cpp
+++ b/src/tools/toolfactory.cpp
@@ -17,97 +17,98 @@
#include "toolfactory.h"
#include "arrow/arrowtool.h"
+#include "blur/blurtool.h"
#include "circle/circletool.h"
#include "copy/copytool.h"
#include "exit/exittool.h"
-#include "imgur/imguruploadertool.h"
-#include "imgs3/imgs3uploadertool.h"
+#include "launcher/applaunchertool.h"
#include "line/linetool.h"
#include "marker/markertool.h"
#include "move/movetool.h"
#include "pencil/penciltool.h"
+#include "pin/pintool.h"
#include "rectangle/rectangletool.h"
+#include "redo/redotool.h"
#include "save/savetool.h"
#include "selection/selectiontool.h"
#include "sizeindicator/sizeindicatortool.h"
-#include "undo/undotool.h"
-#include "launcher/applaunchertool.h"
-#include "blur/blurtool.h"
-#include "redo/redotool.h"
-#include "pin/pintool.h"
+#include "src/utils/confighandler.h"
+#include "storage/storagemanager.h"
#include "text/texttool.h"
+#include "undo/undotool.h"
-ToolFactory::ToolFactory(QObject *parent) : QObject(parent) {
+ToolFactory::ToolFactory(QObject* parent)
+ : QObject(parent)
+{}
-}
-
-CaptureTool* ToolFactory::CreateTool(
- CaptureButton::ButtonType t,
- QObject *parent)
+CaptureTool* ToolFactory::CreateTool(CaptureButton::ButtonType t,
+ QObject* parent)
{
- CaptureTool *tool;
+ StorageManager storageManager;
+
+ CaptureTool* tool;
switch (t) {
- case CaptureButton::TYPE_ARROW:
- tool = new ArrowTool(parent);
- break;
- case CaptureButton::TYPE_CIRCLE:
- tool = new CircleTool(parent);
- break;
- case CaptureButton::TYPE_COPY:
- tool = new CopyTool(parent);
- break;
- case CaptureButton::TYPE_EXIT:
- tool = new ExitTool(parent);
- break;
- case CaptureButton::TYPE_IMAGEUPLOADER:
-// tool = new ImgurUploaderTool(parent);
- tool = new ImgS3UploaderTool(parent);
- break;
- case CaptureButton::TYPE_DRAWER:
- tool = new LineTool(parent);
- break;
- case CaptureButton::TYPE_MARKER:
- tool = new MarkerTool(parent);
- break;
- case CaptureButton::TYPE_MOVESELECTION:
- tool = new MoveTool(parent);
- break;
- case CaptureButton::TYPE_PENCIL:
- tool = new PencilTool(parent);
- break;
- case CaptureButton::TYPE_RECTANGLE:
- tool = new RectangleTool(parent);
- break;
- case CaptureButton::TYPE_SAVE:
- tool = new SaveTool(parent);
- break;
- case CaptureButton::TYPE_SELECTION:
- tool = new SelectionTool(parent);
- break;
- case CaptureButton::TYPE_SELECTIONINDICATOR:
- tool = new SizeIndicatorTool(parent);
- break;
- case CaptureButton::TYPE_UNDO:
- tool = new UndoTool(parent);
- break;
- case CaptureButton::TYPE_REDO:
- tool = new RedoTool(parent);
- break;
- case CaptureButton::TYPE_OPEN_APP:
- tool = new AppLauncher(parent);
- break;
- case CaptureButton::TYPE_BLUR:
- tool = new BlurTool(parent);
- break;
- case CaptureButton::TYPE_PIN:
- tool = new PinTool(parent);
- break;
- case CaptureButton::TYPE_TEXT:
- tool = new TextTool(parent);
- break;
- default:
- tool = nullptr;
- break;
+ case CaptureButton::TYPE_ARROW:
+ tool = new ArrowTool(parent);
+ break;
+ case CaptureButton::TYPE_CIRCLE:
+ tool = new CircleTool(parent);
+ break;
+ case CaptureButton::TYPE_COPY:
+ tool = new CopyTool(parent);
+ break;
+ case CaptureButton::TYPE_EXIT:
+ tool = new ExitTool(parent);
+ break;
+ case CaptureButton::TYPE_IMAGEUPLOADER:
+ tool = storageManager.imgUploaderTool(
+ ConfigHandler().uploadStorage(), parent);
+ break;
+ case CaptureButton::TYPE_DRAWER:
+ tool = new LineTool(parent);
+ break;
+ case CaptureButton::TYPE_MARKER:
+ tool = new MarkerTool(parent);
+ break;
+ case CaptureButton::TYPE_MOVESELECTION:
+ tool = new MoveTool(parent);
+ break;
+ case CaptureButton::TYPE_PENCIL:
+ tool = new PencilTool(parent);
+ break;
+ case CaptureButton::TYPE_RECTANGLE:
+ tool = new RectangleTool(parent);
+ break;
+ case CaptureButton::TYPE_SAVE:
+ tool = new SaveTool(parent);
+ break;
+ case CaptureButton::TYPE_SELECTION:
+ tool = new SelectionTool(parent);
+ break;
+ case CaptureButton::TYPE_SELECTIONINDICATOR:
+ tool = new SizeIndicatorTool(parent);
+ break;
+ case CaptureButton::TYPE_UNDO:
+ tool = new UndoTool(parent);
+ break;
+ case CaptureButton::TYPE_REDO:
+ tool = new RedoTool(parent);
+ break;
+ case CaptureButton::TYPE_OPEN_APP:
+ tool = new AppLauncher(parent);
+ break;
+ case CaptureButton::TYPE_BLUR:
+ tool = new BlurTool(parent);
+ break;
+ case CaptureButton::TYPE_PIN:
+ tool = new PinTool(parent);
+ break;
+ case CaptureButton::TYPE_TEXT:
+ tool = new TextTool(parent);
+ break;
+ default:
+ tool = nullptr;
+ break;
}
return tool;
}
diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp
index 849289a1..c9836247 100644
--- a/src/utils/confighandler.cpp
+++ b/src/utils/confighandler.cpp
@@ -17,92 +17,82 @@
#include "confighandler.h"
#include "src/tools/capturetool.h"
+#include "src/tools/storage/imgstorages.h"
#include "src/utils/configshortcuts.h"
-#include
-#include
-#include
#include
+#include
+#include
#include
+#include
-ConfigHandler::ConfigHandler(){
+ConfigHandler::ConfigHandler()
+{
m_settings.setDefaultFormat(QSettings::IniFormat);
}
-QVector ConfigHandler::getButtons() {
+QVector ConfigHandler::getButtons()
+{
QVector buttons;
if (m_settings.contains(QStringLiteral("buttons"))) {
// TODO: remove toList in v1.0
- QVector buttonsInt =
- m_settings.value(QStringLiteral("buttons")).value >().toVector();
+ QVector buttonsInt = m_settings.value(QStringLiteral("buttons"))
+ .value>()
+ .toVector();
bool modified = normalizeButtons(buttonsInt);
if (modified) {
- m_settings.setValue(QStringLiteral("buttons"), QVariant::fromValue(buttonsInt.toList()));
+ m_settings.setValue(QStringLiteral("buttons"),
+ QVariant::fromValue(buttonsInt.toList()));
}
buttons = fromIntToButton(buttonsInt);
} else {
// Default tools
- buttons << CaptureButton::TYPE_PENCIL
- << CaptureButton::TYPE_DRAWER
- << CaptureButton::TYPE_ARROW
- << CaptureButton::TYPE_SELECTION
- << CaptureButton::TYPE_RECTANGLE
- << CaptureButton::TYPE_CIRCLE
- << CaptureButton::TYPE_MARKER
- << CaptureButton::TYPE_BLUR
+ buttons << CaptureButton::TYPE_PENCIL << CaptureButton::TYPE_DRAWER
+ << CaptureButton::TYPE_ARROW << CaptureButton::TYPE_SELECTION
+ << CaptureButton::TYPE_RECTANGLE << CaptureButton::TYPE_CIRCLE
+ << CaptureButton::TYPE_MARKER << CaptureButton::TYPE_BLUR
<< CaptureButton::TYPE_SELECTIONINDICATOR
- << CaptureButton::TYPE_MOVESELECTION
- << CaptureButton::TYPE_UNDO
- << CaptureButton::TYPE_REDO
- << CaptureButton::TYPE_COPY
- << CaptureButton::TYPE_SAVE
- << CaptureButton::TYPE_EXIT
+ << CaptureButton::TYPE_MOVESELECTION << CaptureButton::TYPE_UNDO
+ << CaptureButton::TYPE_REDO << CaptureButton::TYPE_COPY
+ << CaptureButton::TYPE_SAVE << CaptureButton::TYPE_EXIT
<< CaptureButton::TYPE_IMAGEUPLOADER
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
<< CaptureButton::TYPE_OPEN_APP
#endif
- << CaptureButton::TYPE_PIN
- << CaptureButton::TYPE_TEXT;
+ << CaptureButton::TYPE_PIN << CaptureButton::TYPE_TEXT;
}
using bt = CaptureButton::ButtonType;
- std::sort(buttons.begin(), buttons.end(), [](bt a, bt b){
+ std::sort(buttons.begin(), buttons.end(), [](bt a, bt b) {
return CaptureButton::getPriorityByButton(a) <
- CaptureButton::getPriorityByButton(b);
+ CaptureButton::getPriorityByButton(b);
});
return buttons;
}
-void ConfigHandler::setButtons(const QVector &buttons) {
+void ConfigHandler::setButtons(
+ const QVector& buttons)
+{
QVector l = fromButtonToInt(buttons);
normalizeButtons(l);
// TODO: remove toList in v1.0
- m_settings.setValue(QStringLiteral("buttons"), QVariant::fromValue(l.toList()));
+ m_settings.setValue(QStringLiteral("buttons"),
+ QVariant::fromValue(l.toList()));
}
-QVector ConfigHandler::getUserColors() {
+QVector ConfigHandler::getUserColors()
+{
QVector colors;
- const QVector &defaultColors = {
- Qt::white,
- Qt::red,
- Qt::green,
- Qt::blue,
- Qt::black,
- Qt::darkRed,
- Qt::darkGreen,
- Qt::darkBlue,
- Qt::darkGray,
- Qt::cyan,
- Qt::magenta,
- Qt::yellow,
- Qt::lightGray,
- Qt::darkCyan,
- Qt::darkMagenta,
- Qt::darkYellow,
+ const QVector& defaultColors = {
+ Qt::white, Qt::red, Qt::green, Qt::blue,
+ Qt::black, Qt::darkRed, Qt::darkGreen, Qt::darkBlue,
+ Qt::darkGray, Qt::cyan, Qt::magenta, Qt::yellow,
+ Qt::lightGray, Qt::darkCyan, Qt::darkMagenta, Qt::darkYellow,
QColor()
};
if (m_settings.contains(QStringLiteral("userColors"))) {
- for (const QString &hex : m_settings.value(QStringLiteral("userColors")).toStringList()) {
+ for (const QString& hex :
+ m_settings.value(QStringLiteral("userColors")).toStringList()) {
if (QColor::isValidColor(hex)) {
colors.append(QColor(hex));
}
@@ -118,40 +108,49 @@ QVector ConfigHandler::getUserColors() {
return colors;
}
-void ConfigHandler::setUserColors(const QVector &l) {
+void ConfigHandler::setUserColors(const QVector& l)
+{
QStringList hexColors;
- for (const QColor &color : l) {
+ for (const QColor& color : l) {
hexColors.append(color.name());
}
- m_settings.setValue(QStringLiteral("userColors"), QVariant::fromValue(hexColors));
+ m_settings.setValue(QStringLiteral("userColors"),
+ QVariant::fromValue(hexColors));
}
-QString ConfigHandler::savePathValue() {
- QString savePath = m_settings.value(QStringLiteral("savePathFixed")).toString();
- if( savePath.isEmpty() ) {
+QString ConfigHandler::savePathValue()
+{
+ QString savePath =
+ m_settings.value(QStringLiteral("savePathFixed")).toString();
+ if (savePath.isEmpty()) {
savePath = m_settings.value(QStringLiteral("savePath")).toString();
}
return savePath;
}
-void ConfigHandler::setSavePath(const QString &savePath) {
- QString savePathFixed = m_settings.value(QStringLiteral("savePathFixed")).toString();
- if( savePathFixed.isEmpty() ) {
+void ConfigHandler::setSavePath(const QString& savePath)
+{
+ QString savePathFixed =
+ m_settings.value(QStringLiteral("savePathFixed")).toString();
+ if (savePathFixed.isEmpty()) {
m_settings.setValue(QStringLiteral("savePath"), savePath);
}
}
-QString ConfigHandler::savePathFixed() {
+QString ConfigHandler::savePathFixed()
+{
return m_settings.value(QStringLiteral("savePathFixed")).toString();
}
-void ConfigHandler::setSavePathFixed(const QString &savePathFixed) {
+void ConfigHandler::setSavePathFixed(const QString& savePathFixed)
+{
m_settings.setValue(QStringLiteral("savePathFixed"), savePathFixed);
}
-QColor ConfigHandler::uiMainColorValue() {
+QColor ConfigHandler::uiMainColorValue()
+{
QColor res = QColor(116, 0, 150);
if (m_settings.contains(QStringLiteral("uiColor"))) {
@@ -164,15 +163,18 @@ QColor ConfigHandler::uiMainColorValue() {
return res;
}
-void ConfigHandler::setUIMainColor(const QColor &c) {
+void ConfigHandler::setUIMainColor(const QColor& c)
+{
m_settings.setValue(QStringLiteral("uiColor"), c.name());
}
-QColor ConfigHandler::uiContrastColorValue() {
+QColor ConfigHandler::uiContrastColorValue()
+{
QColor res = QColor(39, 0, 50);
if (m_settings.contains(QStringLiteral("contastUiColor"))) {
- QString hex = m_settings.value(QStringLiteral("contastUiColor")).toString();
+ QString hex =
+ m_settings.value(QStringLiteral("contastUiColor")).toString();
if (QColor::isValidColor(hex)) {
res = QColor(hex);
@@ -182,11 +184,13 @@ QColor ConfigHandler::uiContrastColorValue() {
return res;
}
-void ConfigHandler::setUIContrastColor(const QColor &c) {
+void ConfigHandler::setUIContrastColor(const QColor& c)
+{
m_settings.setValue(QStringLiteral("contastUiColor"), c.name());
}
-QColor ConfigHandler::drawColorValue() {
+QColor ConfigHandler::drawColorValue()
+{
QColor res(Qt::red);
if (m_settings.contains(QStringLiteral("drawColor"))) {
@@ -200,11 +204,13 @@ QColor ConfigHandler::drawColorValue() {
return res;
}
-void ConfigHandler::setDrawColor(const QColor &c) {
+void ConfigHandler::setDrawColor(const QColor& c)
+{
m_settings.setValue(QStringLiteral("drawColor"), c.name());
}
-bool ConfigHandler::showHelpValue() {
+bool ConfigHandler::showHelpValue()
+{
bool res = true;
if (m_settings.contains(QStringLiteral("showHelp"))) {
res = m_settings.value(QStringLiteral("showHelp")).toBool();
@@ -212,31 +218,39 @@ bool ConfigHandler::showHelpValue() {
return res;
}
-void ConfigHandler::setShowHelp(const bool showHelp) {
+void ConfigHandler::setShowHelp(const bool showHelp)
+{
m_settings.setValue(QStringLiteral("showHelp"), showHelp);
}
-bool ConfigHandler::desktopNotificationValue() {
+bool ConfigHandler::desktopNotificationValue()
+{
bool res = true;
if (m_settings.contains(QStringLiteral("showDesktopNotification"))) {
- res = m_settings.value(QStringLiteral("showDesktopNotification")).toBool();
+ res =
+ m_settings.value(QStringLiteral("showDesktopNotification")).toBool();
}
return res;
}
-void ConfigHandler::setDesktopNotification(const bool showDesktopNotification) {
- m_settings.setValue(QStringLiteral("showDesktopNotification"), showDesktopNotification);
+void ConfigHandler::setDesktopNotification(const bool showDesktopNotification)
+{
+ m_settings.setValue(QStringLiteral("showDesktopNotification"),
+ showDesktopNotification);
}
-QString ConfigHandler::filenamePatternValue() {
+QString ConfigHandler::filenamePatternValue()
+{
return m_settings.value(QStringLiteral("filenamePattern")).toString();
}
-void ConfigHandler::setFilenamePattern(const QString &pattern) {
+void ConfigHandler::setFilenamePattern(const QString& pattern)
+{
return m_settings.setValue(QStringLiteral("filenamePattern"), pattern);
}
-bool ConfigHandler::disabledTrayIconValue() {
+bool ConfigHandler::disabledTrayIconValue()
+{
bool res = false;
if (m_settings.contains(QStringLiteral("disabledTrayIcon"))) {
res = m_settings.value(QStringLiteral("disabledTrayIcon")).toBool();
@@ -244,11 +258,13 @@ bool ConfigHandler::disabledTrayIconValue() {
return res;
}
-void ConfigHandler::setDisabledTrayIcon(const bool disabledTrayIcon) {
+void ConfigHandler::setDisabledTrayIcon(const bool disabledTrayIcon)
+{
m_settings.setValue(QStringLiteral("disabledTrayIcon"), disabledTrayIcon);
}
-int ConfigHandler::drawThicknessValue() {
+int ConfigHandler::drawThicknessValue()
+{
int res = 0;
if (m_settings.contains(QStringLiteral("drawThickness"))) {
res = m_settings.value(QStringLiteral("drawThickness")).toInt();
@@ -256,19 +272,23 @@ int ConfigHandler::drawThicknessValue() {
return res;
}
-void ConfigHandler::setdrawThickness(const int thickness) {
+void ConfigHandler::setdrawThickness(const int thickness)
+{
m_settings.setValue(QStringLiteral("drawThickness"), thickness);
}
-bool ConfigHandler::keepOpenAppLauncherValue() {
+bool ConfigHandler::keepOpenAppLauncherValue()
+{
return m_settings.value(QStringLiteral("keepOpenAppLauncher")).toBool();
}
-void ConfigHandler::setKeepOpenAppLauncher(const bool keepOpen) {
+void ConfigHandler::setKeepOpenAppLauncher(const bool keepOpen)
+{
m_settings.setValue(QStringLiteral("keepOpenAppLauncher"), keepOpen);
}
-bool ConfigHandler::startupLaunchValue() {
+bool ConfigHandler::startupLaunchValue()
+{
bool res = false;
if (m_settings.contains(QStringLiteral("startupLaunch"))) {
@@ -282,7 +302,8 @@ bool ConfigHandler::startupLaunchValue() {
return res;
}
-bool ConfigHandler::verifyLaunchFile() {
+bool ConfigHandler::verifyLaunchFile()
+{
bool res = false;
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
@@ -290,15 +311,16 @@ bool ConfigHandler::verifyLaunchFile() {
res = QFile(path).exists();
#elif defined(Q_OS_WIN)
QSettings bootUpSettings(
- "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
- QSettings::NativeFormat);
+ "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
+ QSettings::NativeFormat);
res = bootUpSettings.value("Flameshot").toString() ==
- QDir::toNativeSeparators(QCoreApplication::applicationFilePath());
+ QDir::toNativeSeparators(QCoreApplication::applicationFilePath());
#endif
return res;
}
-void ConfigHandler::setStartupLaunch(const bool start) {
+void ConfigHandler::setStartupLaunch(const bool start)
+{
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
QString path = QDir::homePath() + "/.config/autostart/";
QDir autostartDir(path);
@@ -319,15 +341,16 @@ void ConfigHandler::setStartupLaunch(const bool start) {
}
#elif defined(Q_OS_WIN)
QSettings bootUpSettings(
- "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
- QSettings::NativeFormat);
+ "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
+ QSettings::NativeFormat);
// set workdir for flameshot on startup
QSettings bootUpPath(
- "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths",
- QSettings::NativeFormat);
+ "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App "
+ "Paths",
+ QSettings::NativeFormat);
if (start) {
QString app_path =
- QDir::toNativeSeparators(QCoreApplication::applicationFilePath());
+ QDir::toNativeSeparators(QCoreApplication::applicationFilePath());
bootUpSettings.setValue("Flameshot", app_path);
// set application workdir
@@ -347,18 +370,24 @@ void ConfigHandler::setStartupLaunch(const bool start) {
m_settings.setValue(QStringLiteral("startupLaunch"), start);
}
-bool ConfigHandler::showStartupLaunchMessage() {
+bool ConfigHandler::showStartupLaunchMessage()
+{
if (!m_settings.contains(QStringLiteral("showStartupLaunchMessage"))) {
m_settings.setValue(QStringLiteral("showStartupLaunchMessage"), true);
}
- return m_settings.value(QStringLiteral("showStartupLaunchMessage")).toBool();
+ return m_settings.value(QStringLiteral("showStartupLaunchMessage"))
+ .toBool();
}
-void ConfigHandler::setShowStartupLaunchMessage(const bool showStartupLaunchMessage){
- m_settings.setValue(QStringLiteral("showStartupLaunchMessage"), showStartupLaunchMessage);
+void ConfigHandler::setShowStartupLaunchMessage(
+ const bool showStartupLaunchMessage)
+{
+ m_settings.setValue(QStringLiteral("showStartupLaunchMessage"),
+ showStartupLaunchMessage);
}
-int ConfigHandler::contrastOpacityValue() {
+int ConfigHandler::contrastOpacityValue()
+{
int opacity = 190;
if (m_settings.contains(QStringLiteral("contrastOpacity"))) {
opacity = m_settings.value(QStringLiteral("contrastOpacity")).toInt();
@@ -367,31 +396,38 @@ int ConfigHandler::contrastOpacityValue() {
return opacity;
}
-void ConfigHandler::setContrastOpacity(const int transparency) {
+void ConfigHandler::setContrastOpacity(const int transparency)
+{
m_settings.setValue(QStringLiteral("contrastOpacity"), transparency);
}
-bool ConfigHandler::closeAfterScreenshotValue() {
+bool ConfigHandler::closeAfterScreenshotValue()
+{
return m_settings.value(QStringLiteral("closeAfterScreenshot")).toBool();
}
-void ConfigHandler::setCloseAfterScreenshot(const bool close) {
+void ConfigHandler::setCloseAfterScreenshot(const bool close)
+{
m_settings.setValue(QStringLiteral("closeAfterScreenshot"), close);
}
-bool ConfigHandler::copyAndCloseAfterUploadEnabled() {
+bool ConfigHandler::copyAndCloseAfterUploadEnabled()
+{
bool res = true;
if (m_settings.contains(QStringLiteral("copyAndCloseAfterUpload"))) {
- res = m_settings.value(QStringLiteral("copyAndCloseAfterUpload")).toBool();
+ res =
+ m_settings.value(QStringLiteral("copyAndCloseAfterUpload")).toBool();
}
return res;
}
-void ConfigHandler::setCopyAndCloseAfterUploadEnabled(const bool value) {
+void ConfigHandler::setCopyAndCloseAfterUploadEnabled(const bool value)
+{
m_settings.setValue(QStringLiteral("copyAndCloseAfterUpload"), value);
}
-bool ConfigHandler::copyPathAfterSaveEnabled() {
+bool ConfigHandler::copyPathAfterSaveEnabled()
+{
bool res = false;
if (m_settings.contains(QStringLiteral("copyPathAfterSave"))) {
res = m_settings.value(QStringLiteral("copyPathAfterSave")).toBool();
@@ -399,32 +435,53 @@ bool ConfigHandler::copyPathAfterSaveEnabled() {
return res;
}
-void ConfigHandler::setCopyPathAfterSaveEnabled(const bool value) {
+void ConfigHandler::setCopyPathAfterSaveEnabled(const bool value)
+{
m_settings.setValue(QStringLiteral("copyPathAfterSave"), value);
}
-void ConfigHandler::setDefaults() {
+void ConfigHandler::setUploadStorage(const QString& uploadStorage)
+{
+ m_settings.setValue(QStringLiteral("uploadStorage"), uploadStorage);
+}
+
+const QString& ConfigHandler::uploadStorage()
+{
+ m_strRes = m_settings.value(QStringLiteral("uploadStorage")).toString();
+ if (m_strRes.isEmpty()) {
+ m_strRes = SCREENSHOT_STORAGE_TYPE_IMGUR;
+ setUploadStorage(m_strRes);
+ }
+ return m_strRes;
+}
+
+void ConfigHandler::setDefaults()
+{
m_settings.clear();
}
-void ConfigHandler::setAllTheButtons() {
+void ConfigHandler::setAllTheButtons()
+{
QVector buttons;
auto listTypes = CaptureButton::getIterableButtonTypes();
- for (const CaptureButton::ButtonType t: listTypes) {
+ for (const CaptureButton::ButtonType t : listTypes) {
buttons << static_cast(t);
}
// TODO: remove toList in v1.0
- m_settings.setValue(QStringLiteral("buttons"), QVariant::fromValue(buttons.toList()));
+ m_settings.setValue(QStringLiteral("buttons"),
+ QVariant::fromValue(buttons.toList()));
}
-QString ConfigHandler::configFilePath() const {
+QString ConfigHandler::configFilePath() const
+{
return m_settings.fileName();
}
-bool ConfigHandler::normalizeButtons(QVector &buttons) {
+bool ConfigHandler::normalizeButtons(QVector& buttons)
+{
auto listTypes = CaptureButton::getIterableButtonTypes();
QVector listTypesInt;
- for(auto i: listTypes)
+ for (auto i : listTypes)
listTypesInt << static_cast(i);
bool hasChanged = false;
@@ -438,32 +495,34 @@ bool ConfigHandler::normalizeButtons(QVector &buttons) {
}
QVector ConfigHandler::fromIntToButton(
- const QVector &l)
+ const QVector& l)
{
QVector buttons;
- for (auto const i: l)
+ for (auto const i : l)
buttons << static_cast(i);
return buttons;
}
QVector ConfigHandler::fromButtonToInt(
- const QVector &l)
+ const QVector& l)
{
QVector buttons;
- for (auto const i: l)
+ for (auto const i : l)
buttons << static_cast(i);
return buttons;
}
-QVector ConfigHandler::shortcuts() {
+QVector ConfigHandler::shortcuts()
+{
ConfigShortcuts configShortcuts;
m_shortcuts = configShortcuts.captureShortcutsDefault(getButtons());
return m_shortcuts;
}
-void ConfigHandler::setShortcutsDefault() {
+void ConfigHandler::setShortcutsDefault()
+{
ConfigShortcuts configShortcuts;
- for (auto shortcutItem: shortcuts()) {
+ for (auto shortcutItem : shortcuts()) {
QString shortcutName = shortcutItem.at(0);
QString shortcutDescription = shortcutItem.at(1);
QString shortcutValueDefault = shortcutItem.at(2);
@@ -471,49 +530,48 @@ void ConfigHandler::setShortcutsDefault() {
QString shortcutValue = shortcut(shortcutName);
QKeySequence ks = QKeySequence();
- if(shortcutValue.isNull()) {
+ if (shortcutValue.isNull()) {
ks = QKeySequence(shortcutValueDefault);
if (!setShortcut(shortcutName, ks.toString())) {
shortcutValue = shortcutValueDefault;
}
}
- m_shortcuts << (QStringList()
- << shortcutName
- << shortcutDescription
- << shortcutValue);
+ m_shortcuts << (QStringList() << shortcutName << shortcutDescription
+ << shortcutValue);
}
}
-bool ConfigHandler::setShortcut(const QString& shortcutName, const QString& shortutValue) {
+bool ConfigHandler::setShortcut(const QString& shortcutName,
+ const QString& shortutValue)
+{
bool error = false;
m_settings.beginGroup("Shortcuts");
QVector reservedShortcuts;
- reservedShortcuts << QKeySequence(Qt::Key_Backspace) << QKeySequence(Qt::Key_Escape);
- if(shortutValue.isEmpty()){
+ reservedShortcuts << QKeySequence(Qt::Key_Backspace)
+ << QKeySequence(Qt::Key_Escape);
+ if (shortutValue.isEmpty()) {
m_settings.setValue(shortcutName, "");
- }
- else if (reservedShortcuts.contains(QKeySequence(shortutValue))) {
+ } else if (reservedShortcuts.contains(QKeySequence(shortutValue))) {
// do not allow to set reserved shortcuts
error = true;
- }
- else {
+ } else {
// Make no difference for Return and Enter keys
QString shortcutItem = shortutValue;
- if(shortcutItem == "Enter") {
+ if (shortcutItem == "Enter") {
shortcutItem = QKeySequence(Qt::Key_Return).toString();
}
// do not allow to set overlapped shortcuts
foreach (auto currentShortcutName, m_settings.allKeys()) {
- if(m_settings.value(currentShortcutName) == shortcutItem) {
+ if (m_settings.value(currentShortcutName) == shortcutItem) {
m_settings.setValue(shortcutName, "");
error = true;
break;
}
}
- if(!error) {
+ if (!error) {
m_settings.setValue(shortcutName, shortcutItem);
}
}
@@ -521,7 +579,8 @@ bool ConfigHandler::setShortcut(const QString& shortcutName, const QString& shor
return !error;
}
-const QString& ConfigHandler::shortcut(const QString& shortcutName) {
+const QString& ConfigHandler::shortcut(const QString& shortcutName)
+{
m_settings.beginGroup("Shortcuts");
m_strRes = m_settings.value(shortcutName).toString();
m_settings.endGroup();
diff --git a/src/utils/confighandler.h b/src/utils/confighandler.h
index 58367610..f720d16d 100644
--- a/src/utils/confighandler.h
+++ b/src/utils/confighandler.h
@@ -18,34 +18,35 @@
#pragma once
#include "src/widgets/capture/capturebutton.h"
-#include
-#include
#include
+#include
+#include
-class ConfigHandler : public QObject {
+class ConfigHandler : public QObject
+{
public:
explicit ConfigHandler();
QVector getButtons();
- void setButtons(const QVector &);
+ void setButtons(const QVector&);
QVector getUserColors();
- void setUserColors(const QVector &);
+ void setUserColors(const QVector&);
QString savePathValue();
- void setSavePath(const QString &);
+ void setSavePath(const QString&);
QString savePathFixed();
- void setSavePathFixed(const QString &);
+ void setSavePathFixed(const QString&);
QColor uiMainColorValue();
- void setUIMainColor(const QColor &);
+ void setUIMainColor(const QColor&);
QColor uiContrastColorValue();
- void setUIContrastColor(const QColor &);
+ void setUIContrastColor(const QColor&);
QColor drawColorValue();
- void setDrawColor(const QColor &);
+ void setDrawColor(const QColor&);
bool showHelpValue();
void setShowHelp(const bool);
@@ -54,7 +55,7 @@ public:
void setDesktopNotification(const bool);
QString filenamePatternValue();
- void setFilenamePattern(const QString &);
+ void setFilenamePattern(const QString&);
bool disabledTrayIconValue();
void setDisabledTrayIcon(const bool);
@@ -84,6 +85,9 @@ public:
bool copyPathAfterSaveEnabled();
void setCopyPathAfterSaveEnabled(const bool);
+ void setUploadStorage(const QString&);
+ const QString& uploadStorage();
+
void setDefaults();
void setAllTheButtons();
@@ -99,8 +103,8 @@ private:
QSettings m_settings;
QVector m_shortcuts;
- bool normalizeButtons(QVector &);
+ bool normalizeButtons(QVector&);
- QVector fromIntToButton(const QVector &l);
- QVector fromButtonToInt(const QVector &l);
+ QVector fromIntToButton(const QVector& l);
+ QVector fromButtonToInt(const QVector& l);
};
diff --git a/src/utils/history.cpp b/src/utils/history.cpp
index d3a4ba33..f5ce6ae6 100644
--- a/src/utils/history.cpp
+++ b/src/utils/history.cpp
@@ -4,7 +4,6 @@
#include
#include
-
History::History()
{
// Get cache history path
@@ -21,27 +20,32 @@ History::History()
dir.mkpath(".");
}
-const QString &History::path() {
+const QString& History::path()
+{
return m_historyPath;
}
-void History::save(const QPixmap &pixmap, const QString &fileName) {
+void History::save(const QPixmap& pixmap, const QString& fileName)
+{
QFile file(path() + fileName);
file.open(QIODevice::WriteOnly);
pixmap.save(&file, "PNG");
history();
}
-const QList &History::history() {
+const QList& History::history()
+{
QDir directory(path());
- QStringList images = directory.entryList(QStringList() << "*.png" << "*.PNG", QDir::Files, QDir::Time);
+ QStringList images = directory.entryList(QStringList() << "*.png"
+ << "*.PNG",
+ QDir::Files,
+ QDir::Time);
int cnt = 0;
m_thumbs.clear();
- foreach(QString fileName, images) {
- if(++cnt <= HISTORY_MAX_SIZE) {
+ foreach (QString fileName, images) {
+ if (++cnt <= HISTORY_MAX_SIZE) {
m_thumbs.append(fileName);
- }
- else {
+ } else {
QFile file(path() + fileName);
file.remove();
}
@@ -49,42 +53,46 @@ const QList &History::history() {
return m_thumbs;
}
-const HISTORY_FILE_NAME &History::unpackFileName(const QString &fileNamePacked) {
+const HISTORY_FILE_NAME& History::unpackFileName(const QString& fileNamePacked)
+{
int nPathIndex = fileNamePacked.lastIndexOf("/");
QStringList unpackedFileName;
- if(nPathIndex == -1) {
+ if (nPathIndex == -1) {
unpackedFileName = fileNamePacked.split("-");
} else {
unpackedFileName = fileNamePacked.mid(nPathIndex + 1).split("-");
}
switch (unpackedFileName.length()) {
- case 3:
- m_unpackedFileName.file = unpackedFileName[2];
- m_unpackedFileName.token = unpackedFileName[1];
- m_unpackedFileName.type = unpackedFileName[0];
- break;
- case 2:
- m_unpackedFileName.file = unpackedFileName[1];
- m_unpackedFileName.token = "";
- m_unpackedFileName.type = unpackedFileName[0];
- break;
- default:
- m_unpackedFileName.file = unpackedFileName[0];
- m_unpackedFileName.token = "";
- m_unpackedFileName.type = SCREENSHOT_STORAGE_TYPE_LOCAL;
- break;
+ case 3:
+ m_unpackedFileName.file = unpackedFileName[2];
+ m_unpackedFileName.token = unpackedFileName[1];
+ m_unpackedFileName.type = unpackedFileName[0];
+ break;
+ case 2:
+ m_unpackedFileName.file = unpackedFileName[1];
+ m_unpackedFileName.token = "";
+ m_unpackedFileName.type = unpackedFileName[0];
+ break;
+ default:
+ m_unpackedFileName.file = unpackedFileName[0];
+ m_unpackedFileName.token = "";
+ m_unpackedFileName.type = "";
+ break;
}
return m_unpackedFileName;
}
-const QString &History::packFileName(const QString &storageType, const QString &deleteToken, const QString &fileName) {
+const QString& History::packFileName(const QString& storageType,
+ const QString& deleteToken,
+ const QString& fileName)
+{
m_packedFileName = fileName;
- if(storageType.length() > 0) {
- if(deleteToken.length() > 0) {
- m_packedFileName = storageType + "-" + deleteToken + "-" + m_packedFileName;
- }
- else {
+ if (storageType.length() > 0) {
+ if (deleteToken.length() > 0) {
+ m_packedFileName =
+ storageType + "-" + deleteToken + "-" + m_packedFileName;
+ } else {
m_packedFileName = storageType + "-" + m_packedFileName;
}
}
diff --git a/src/utils/history.h b/src/utils/history.h
index fc111615..a4569175 100644
--- a/src/utils/history.h
+++ b/src/utils/history.h
@@ -4,15 +4,11 @@
#define HISTORY_MAX_SIZE 25
#include
-#include
#include
+#include
-
-#define SCREENSHOT_STORAGE_TYPE_LOCAL ""
-#define SCREENSHOT_STORAGE_TYPE_S3 "s3"
-#define SCREENSHOT_STORAGE_TYPE_IMGUR "imgur"
-
-struct HISTORY_FILE_NAME {
+struct HISTORY_FILE_NAME
+{
QString file;
QString token;
QString type;
@@ -23,12 +19,12 @@ class History
public:
History();
- void save(const QPixmap &, const QString &);
- const QList &history();
- const QString &path();
+ void save(const QPixmap&, const QString&);
+ const QList& history();
+ const QString& path();
- const HISTORY_FILE_NAME &unpackFileName(const QString &);
- const QString &packFileName(const QString &, const QString &, const QString &);
+ const HISTORY_FILE_NAME& unpackFileName(const QString&);
+ const QString& packFileName(const QString&, const QString&, const QString&);
private:
QString m_historyPath;
diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp
index b4799890..21214f24 100644
--- a/src/widgets/capture/capturewidget.cpp
+++ b/src/widgets/capture/capturewidget.cpp
@@ -15,55 +15,71 @@
// You should have received a copy of the GNU General Public License
// along with Flameshot. If not, see .
-// Based on Lightscreen areadialog.cpp, Copyright 2017 Christian Kaiser
-// released under the GNU GPL2
+// Based on Lightscreen areadialog.cpp, Copyright 2017 Christian Kaiser
+// released under the GNU GPL2
+//
-// Based on KDE's KSnapshot regiongrabber.cpp, revision 796531, Copyright 2007 Luca Gugelmann
-// released under the GNU LGPL
+// Based on KDE's KSnapshot regiongrabber.cpp, revision 796531, Copyright 2007
+// Luca Gugelmann released under the GNU LGPL
+//
#include "capturewidget.h"
-#include "src/widgets/capture/hovereventfilter.h"
-#include "src/widgets/panel/sidepanelwidget.h"
+#include "src/core/controller.h"
+#include "src/tools/storage/storagemanager.h"
+#include "src/tools/toolfactory.h"
#include "src/utils/colorutils.h"
#include "src/utils/globalvalues.h"
-#include "src/widgets/capture/notifierbox.h"
-#include "src/widgets/capture/colorpicker.h"
#include "src/utils/screengrabber.h"
-#include "src/utils/systemnotification.h"
#include "src/utils/screenshotsaver.h"
-#include "src/core/controller.h"
+#include "src/utils/systemnotification.h"
+#include "src/widgets/capture/colorpicker.h"
+#include "src/widgets/capture/hovereventfilter.h"
#include "src/widgets/capture/modificationcommand.h"
-#include "src/tools/imgs3/imgs3uploadertool.h"
-#include "src/tools/toolfactory.h"
-#include
-#include
-#include
+#include "src/widgets/capture/notifierbox.h"
+#include "src/widgets/panel/sidepanelwidget.h"
#include
-#include
-#include
-#include
-#include
#include
#include
+#include
+#include
+#include
+#include
+#include
+#include