Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow users to override imgur key #2503

Merged
merged 2 commits into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/controller.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 @@ -517,6 +517,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