Skip to content

Commit

Permalink
Allow users to override imgur key (flameshot-org#2503)
Browse files Browse the repository at this point in the history
* Allow users to override imgur key

* Remove debug statements

(cherry picked from commit c01ffec)
  • Loading branch information
borgmanJeremy authored and Yuriy Puchkov committed May 13, 2022
1 parent 4bbe99e commit 6372df2
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 8 deletions.
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,6 @@ else()
endif ()
target_compile_definitions(flameshot PRIVATE APP_PREFIX="${CMAKE_INSTALL_PREFIX}")
target_compile_definitions(flameshot PRIVATE APP_VERSION="v${PROJECT_VERSION}")
target_compile_definitions(flameshot PRIVATE IMGUR_CLIENT_ID="313baf0c7b4d3ff")
#target_compile_definitions(flameshot PRIVATE QAPPLICATION_CLASS=QApplication)
target_compile_definitions(flameshot PRIVATE FLAMESHOT_APP_VERSION_URL="${GIT_API_URL}")
# Enable easier debugging of screenshot capture mode
Expand Down
28 changes: 27 additions & 1 deletion src/config/generalconf.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// SPDX-License-Identifier: GPL-3.0-or-later
// SPDX-FileCopyrightText: 2017-2019 Alejandro Sirgo Rica & Contributors

#include "generalconf.h"
#include "src/core/flameshot.h"
#include "src/utils/confighandler.h"
Expand Down Expand Up @@ -49,6 +48,7 @@ GeneralConf::GeneralConf(QWidget* parent)
initSaveAfterCopy();
initUploadHistoryMax();
initUndoLimit();
initUploadClientSecret();
initAllowMultipleGuiInstances();
#if !defined(Q_OS_WIN)
initAutoCloseIdleDaemon();
Expand Down Expand Up @@ -516,6 +516,32 @@ void GeneralConf::initUploadHistoryMax()
vboxLayout->addWidget(m_uploadHistoryMax);
}

void GeneralConf::initUploadClientSecret()
{
auto* box = new QGroupBox(tr("Imgur API Key"));
box->setFlat(true);
m_layout->addWidget(box);

auto* vboxLayout = new QVBoxLayout();
box->setLayout(vboxLayout);

m_uploadClientKey = new QLineEdit(this);
QString foreground = this->palette().windowText().color().name();
m_uploadClientKey->setStyleSheet(
QStringLiteral("color: %1").arg(foreground));
m_uploadClientKey->setText(ConfigHandler().uploadClientSecret());
connect(m_uploadClientKey,
SIGNAL(editingFinished()),
this,
SLOT(uploadClientKeyEdited()));
vboxLayout->addWidget(m_uploadClientKey);
}

void GeneralConf::uploadClientKeyEdited()
{
ConfigHandler().setUploadClientSecret(m_uploadClientKey->text());
}

void GeneralConf::uploadHistoryMaxChanged(int max)
{
ConfigHandler().setUploadHistoryMax(max);
Expand Down
3 changes: 3 additions & 0 deletions src/config/generalconf.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ private slots:
void exportFileConfiguration();
void resetConfiguration();
void togglePathFixed();
void uploadClientKeyEdited();
void useJpgForClipboardChanged(bool checked);
void setSaveAsFileExtension(QString extension);

Expand Down Expand Up @@ -70,6 +71,7 @@ private slots:
void initUploadWithoutConfirmation();
void initUseJpgForClipboard();
void initUploadHistoryMax();
void initUploadClientSecret();

void _updateComponents(bool allowEmptySavePath);

Expand All @@ -95,6 +97,7 @@ private slots:
QPushButton* m_resetButton;
QCheckBox* m_saveAfterCopy;
QLineEdit* m_savePath;
QLineEdit* m_uploadClientKey;
QPushButton* m_changeSaveButton;
QCheckBox* m_screenshotPathFixedCheck;
QCheckBox* m_historyConfirmationToDelete;
Expand Down
7 changes: 4 additions & 3 deletions src/tools/imgupload/storages/imgur/imguruploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,10 @@ void ImgurUploader::upload()
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());
request.setRawHeader("Authorization",
QStringLiteral("Client-ID %1")
.arg(ConfigHandler().uploadClientSecret())
.toUtf8());

m_NetworkAM->post(request, byteArray);
}
Expand Down
7 changes: 4 additions & 3 deletions src/utils/confighandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ static QMap<class QString, QSharedPointer<ValueHandler>>
OPTION("savePath" ,ExistingDir ( )),
OPTION("savePathFixed" ,Bool ( false )),
OPTION("saveAsFileExtension" ,SaveFileExtension ( )),
OPTION("uploadHistoryMax" ,LowerBoundedInt (0, 25 )),
OPTION("uploadHistoryMax" ,LowerBoundedInt (0, 25 )),
OPTION("undoLimit" ,BoundedInt (0, 999, 100 )),
// Interface tab
OPTION("uiColor" ,Color ( {116, 0, 150} )),
OPTION("contrastUiColor" ,Color ( {39, 0, 50} )),
OPTION("uiColor" ,Color ( {116, 0, 150} )),
OPTION("contrastUiColor" ,Color ( {39, 0, 50} )),
OPTION("contrastOpacity" ,BoundedInt ( 0, 255, 190 )),
OPTION("buttons" ,ButtonList ( {} )),
// Filename Editor tab
Expand All @@ -123,6 +123,7 @@ static QMap<class QString, QSharedPointer<ValueHandler>>
// NOTE: If another tool size is added besides drawThickness and
// drawFontSize, remember to update ConfigHandler::toolSize
OPTION("copyOnDoubleClick" ,Bool ( false )),
OPTION("uploadClientSecret" ,String ( "313baf0c7b4d3ff" )),
};

static QMap<QString, QSharedPointer<KeySequence>> recognizedShortcuts = {
Expand Down
1 change: 1 addition & 0 deletions src/utils/confighandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ class ConfigHandler : public QObject
CONFIG_GETTER_SETTER(showMagnifier, setShowMagnifier, bool)
CONFIG_GETTER_SETTER(squareMagnifier, setSquareMagnifier, bool)
CONFIG_GETTER_SETTER(copyOnDoubleClick, setCopyOnDoubleClick, bool)
CONFIG_GETTER_SETTER(uploadClientSecret, setUploadClientSecret, QString)

// SPECIAL CASES
bool startupLaunch();
Expand Down

0 comments on commit 6372df2

Please sign in to comment.