Skip to content

Commit 1d774e3

Browse files
Make Imgur conditionally compiled in (flameshot-org#4034)
* Make Imgur conditionally compiled in * Fix Macos build issues * Fix windows and clang-format
1 parent a57f641 commit 1d774e3

16 files changed

+107
-29
lines changed

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ option(USE_SINGLEAPPLICATION "Use SingleApplication library" ON)
9595
option(USE_LAUNCHER_ABSOLUTE_PATH "Use absolute path for the desktop launcher" ON)
9696
option(USE_WAYLAND_CLIPBOARD "USE KF Gui Wayland Clipboard" OFF)
9797
option(DISABLE_UPDATE_CHECKER "Disable check for updates" OFF)
98+
option(ENABLE_IMGUR "Enable Imgur Uploader" OFF)
99+
100+
if (ENABLE_IMGUR)
101+
add_compile_definitions(ENABLE_IMGUR)
102+
endif()
103+
98104
if (DISABLE_UPDATE_CHECKER)
99105
add_compile_definitions(DISABLE_UPDATE_CHECKER)
100106
endif ()

src/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ target_include_directories(
173173
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tools/circlecount>
174174
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tools/copy>
175175
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tools/exit>
176+
if(ENABLE_IMGUR)
176177
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tools/imgur>
178+
endif()
177179
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tools/launcher>
178180
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tools/line>
179181
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/tools/marker>

src/config/generalconf.cpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,15 @@ GeneralConf::GeneralConf(QWidget* parent)
5353
initCopyOnDoubleClick();
5454
initSaveAfterCopy();
5555
initCopyPathAfterSave();
56+
initAntialiasingPinZoom();
57+
initUndoLimit();
58+
#ifdef ENABLE_IMGUR
5659
initCopyAndCloseAfterUpload();
5760
initUploadWithoutConfirmation();
5861
initHistoryConfirmationToDelete();
59-
initAntialiasingPinZoom();
6062
initUploadHistoryMax();
61-
initUndoLimit();
6263
initUploadClientSecret();
64+
#endif
6365
initPredefinedColorPaletteLarge();
6466
initShowSelectionGeometry();
6567

@@ -82,15 +84,19 @@ void GeneralConf::_updateComponents(bool allowEmptySavePath)
8284
m_sysNotifications->setChecked(config.showDesktopNotification());
8385
m_abortNotifications->setChecked(config.showAbortNotification());
8486
m_autostart->setChecked(config.startupLaunch());
85-
m_copyURLAfterUpload->setChecked(config.copyURLAfterUpload());
8687
m_saveAfterCopy->setChecked(config.saveAfterCopy());
8788
m_copyPathAfterSave->setChecked(config.copyPathAfterSave());
8889
m_antialiasingPinZoom->setChecked(config.antialiasingPinZoom());
8990
m_useJpgForClipboard->setChecked(config.useJpgForClipboard());
9091
m_copyOnDoubleClick->setChecked(config.copyOnDoubleClick());
92+
#ifdef ENABLE_IMGUR
9193
m_uploadWithoutConfirmation->setChecked(config.uploadWithoutConfirmation());
94+
m_copyURLAfterUpload->setChecked(config.copyURLAfterUpload());
9295
m_historyConfirmationToDelete->setChecked(
9396
config.historyConfirmationToDelete());
97+
98+
m_uploadHistoryMax->setValue(config.uploadHistoryMax());
99+
#endif
94100
#if !defined(DISABLE_UPDATE_CHECKER)
95101
m_checkForUpdates->setChecked(config.checkForUpdates());
96102
#endif
@@ -109,7 +115,6 @@ void GeneralConf::_updateComponents(bool allowEmptySavePath)
109115
m_showStartupLaunchMessage->setChecked(config.showStartupLaunchMessage());
110116
m_showQuitPrompt->setChecked(config.showQuitPrompt());
111117
m_screenshotPathFixedCheck->setChecked(config.savePathFixed());
112-
m_uploadHistoryMax->setValue(config.uploadHistoryMax());
113118
m_undoLimit->setValue(config.undoLimit());
114119

115120
if (allowEmptySavePath || !config.savePath().isEmpty()) {

src/config/setshortcutwidget.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,11 +41,19 @@ SetShortcutDialog::SetShortcutDialog(QDialog* parent,
4141
msg =
4242
tr("Press Esc to cancel or Backspace to disable the keyboard shortcut.");
4343
#endif
44-
if (shortcutName == "TAKE_SCREENSHOT" ||
45-
shortcutName == "SCREENSHOT_HISTORY") {
44+
45+
auto restartMessageAdded = false;
46+
if (shortcutName == "TAKE_SCREENSHOT" && restartMessageAdded == false) {
4647
msg +=
4748
"\n" + tr("Flameshot must be restarted for changes to take effect.");
49+
restartMessageAdded = true;
4850
}
51+
if (shortcutName == "SCREENSHOT_HISTORY" && restartMessageAdded == false) {
52+
msg +=
53+
"\n" + tr("Flameshot must be restarted for changes to take effect.");
54+
restartMessageAdded = true;
55+
}
56+
4957
auto* infoBottom = new QLabel(msg);
5058
infoBottom->setMargin(10);
5159
infoBottom->setAlignment(Qt::AlignCenter);

src/config/shortcutswidget.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,15 @@ void ShortcutsWidget::loadShortcuts()
197197
// Global hotkeys
198198
#if defined(Q_OS_MACOS)
199199
appendShortcut("TAKE_SCREENSHOT", tr("Capture screen"));
200+
#ifdef ENABLE_IMGUR
200201
appendShortcut("SCREENSHOT_HISTORY", tr("Screenshot history"));
202+
#endif
201203
#elif defined(Q_OS_WIN)
204+
205+
#ifdef ENABLE_IMGUR
202206
m_shortcuts << (QStringList() << "" << QObject::tr("Screenshot history")
203207
<< "Shift+Print Screen");
208+
#endif
204209
m_shortcuts << (QStringList()
205210
<< "" << QObject::tr("Capture screen") << "Print Screen");
206211
#else

src/core/flameshot.cpp

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@
1212
#include "src/config/configresolver.h"
1313
#include "src/config/configwindow.h"
1414
#include "src/core/qguiappcurrentscreen.h"
15+
16+
#ifdef ENABLE_IMGUR
1517
#include "src/tools/imgupload/imguploadermanager.h"
1618
#include "src/tools/imgupload/storages/imguploaderbase.h"
19+
#include "src/widgets/imguploaddialog.h"
20+
#include "src/widgets/uploadhistory.h"
21+
#endif
22+
1723
#include "src/utils/confighandler.h"
1824
#include "src/utils/screengrabber.h"
1925
#include "src/widgets/capture/capturewidget.h"
2026
#include "src/widgets/capturelauncher.h"
21-
#include "src/widgets/imguploaddialog.h"
2227
#include "src/widgets/infowindow.h"
23-
#include "src/widgets/uploadhistory.h"
2428
#include <QApplication>
2529
#include <QBuffer>
2630
#include <QDebug>
@@ -61,13 +65,15 @@ Flameshot::Flameshot()
6165
&QHotkey::activated,
6266
qApp,
6367
[this]() { gui(); });
68+
#ifdef ENABLE_IMGUR
6469
m_HotkeyScreenshotHistory = new QHotkey(
6570
QKeySequence(ConfigHandler().shortcut("SCREENSHOT_HISTORY")), true, this);
6671
QObject::connect(m_HotkeyScreenshotHistory,
6772
&QHotkey::activated,
6873
qApp,
6974
[this]() { history(); });
7075
#endif
76+
#endif
7177
}
7278

7379
Flameshot* Flameshot::instance()
@@ -245,6 +251,7 @@ void Flameshot::info()
245251
}
246252
}
247253

254+
#ifdef ENABLE_IMGUR
248255
void Flameshot::history()
249256
{
250257
static UploadHistory* historyWidget = nullptr;
@@ -269,6 +276,7 @@ void Flameshot::history()
269276
historyWidget->raise();
270277
#endif
271278
}
279+
#endif
272280

273281
void Flameshot::openSavePath()
274282
{
@@ -401,6 +409,7 @@ void Flameshot::exportCapture(const QPixmap& capture,
401409
}
402410
}
403411

412+
#ifdef ENABLE_IMGUR
404413
if (tasks & CR::UPLOAD) {
405414
if (!ConfigHandler().uploadWithoutConfirmation()) {
406415
auto* dialog = new ImgUploadDialog();
@@ -425,6 +434,7 @@ void Flameshot::exportCapture(const QPixmap& capture,
425434
}
426435
});
427436
}
437+
#endif
428438

429439
if (!(tasks & CR::UPLOAD)) {
430440
emit captureTaken(capture);

src/core/flameshot.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ class CaptureWidget;
1212
class ConfigWindow;
1313
class InfoWindow;
1414
class CaptureLauncher;
15+
#ifdef ENABLE_IMGUR
1516
class UploadHistory;
17+
#endif
1618
#if (defined(Q_OS_MAC) || defined(Q_OS_MACOS))
1719
class QHotkey;
1820
#endif
@@ -39,7 +41,10 @@ public slots:
3941
void config();
4042

4143
void info();
44+
45+
#ifdef ENABLE_IMGUR
4246
void history();
47+
#endif
4348

4449
void openSavePath();
4550

src/core/globalshortcutfilter.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,12 @@ bool GlobalShortcutFilter::nativeEventFilter(const QByteArray& eventType,
3131
// support would need custom shortcuts defined by the user.
3232
const quint32 keycode = HIWORD(msg->lParam);
3333
const quint32 modifiers = LOWORD(msg->lParam);
34-
34+
#ifdef ENABLE_IMGUR
3535
// Show screenshots history
3636
if (VK_SNAPSHOT == keycode && MOD_SHIFT == modifiers) {
3737
Flameshot::instance()->history();
3838
}
39-
39+
#endif
4040
// Capture screen
4141
if (VK_SNAPSHOT == keycode && 0 == modifiers) {
4242
Flameshot::instance()->requestCapture(

src/tools/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ target_sources(flameshot PRIVATE copy/copytool.h copy/copytool.cpp)
66
target_sources(flameshot PRIVATE exit/exittool.h exit/exittool.cpp)
77
target_sources(flameshot PRIVATE sizeincrease/sizeincreasetool.h sizeincrease/sizeincreasetool.cpp)
88
target_sources(flameshot PRIVATE sizedecrease/sizedecreasetool.h sizedecrease/sizedecreasetool.cpp)
9+
10+
if (ENABLE_IMGUR)
911
target_sources(
1012
flameshot
1113
PRIVATE imgupload/storages/imgur/imguruploader.h
@@ -17,6 +19,7 @@ target_sources(
1719
imgupload/imguploadermanager.h
1820
imgupload/imguploadermanager.cpp
1921
)
22+
endif()
2023
target_sources(
2124
flameshot
2225
PRIVATE launcher/applaunchertool.h

src/tools/capturetool.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,9 @@ class CaptureTool : public QObject
3636
TYPE_COPY = 10,
3737
TYPE_SAVE = 11,
3838
TYPE_EXIT = 12,
39+
#ifdef ENABLE_IMGUR
3940
TYPE_IMAGEUPLOADER = 13,
41+
#endif
4042
TYPE_OPEN_APP = 14,
4143
TYPE_PIXELATE = 15,
4244
TYPE_REDO = 16,

0 commit comments

Comments
 (0)