Skip to content

Commit d057649

Browse files
authored
add cmake option DISABLE_UPDATE_CHECKER (flameshot-org#2793)
* add cmake option DISABLE_UPDATE_CHECKER * add cmake option DISABLE_UPDATE_CHECKER to compile out updatechecker * format code use `clang-format -i $(git ls-files "*.cpp" "*.h")` * fallback wrong code format * replace `add_definitions` with `add_compile_definitions`
1 parent 82b43cc commit d057649

File tree

12 files changed

+89
-12
lines changed

12 files changed

+89
-12
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ option(GENERATE_TS "Regenerate translation source files" OFF)
6868
option(USE_EXTERNAL_SINGLEAPPLICATION "Use external QtSingleApplication library" OFF)
6969
option(USE_LAUNCHER_ABSOLUTE_PATH "Use absolute path for the desktop launcher" ON)
7070
option(USE_WAYLAND_CLIPBOARD "USE KF Gui Wayland Clipboard" OFF)
71+
option(DISABLE_UPDATE_CHECKER "Disable check for updates" OFF)
72+
if (DISABLE_UPDATE_CHECKER)
73+
add_compile_definitions(DISABLE_UPDATE_CHECKER)
74+
endif ()
7175

7276
include(cmake/StandardProjectSettings.cmake)
7377

src/config/generalconf.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ GeneralConf::GeneralConf(QWidget* parent)
3838
#endif
3939
initShowTrayIcon();
4040
initShowDesktopNotification();
41+
#if !defined(DISABLE_UPDATE_CHECKER)
4142
initCheckForUpdates();
43+
#endif
4244
initShowStartupLaunchMessage();
4345
initAllowMultipleGuiInstances();
4446
initSaveLastRegion();
@@ -82,7 +84,9 @@ void GeneralConf::_updateComponents(bool allowEmptySavePath)
8284
m_uploadWithoutConfirmation->setChecked(config.uploadWithoutConfirmation());
8385
m_historyConfirmationToDelete->setChecked(
8486
config.historyConfirmationToDelete());
87+
#if !defined(DISABLE_UPDATE_CHECKER)
8588
m_checkForUpdates->setChecked(config.checkForUpdates());
89+
#endif
8690
m_allowMultipleGuiInstances->setChecked(config.allowMultipleGuiInstances());
8791
m_showMagnifier->setChecked(config.showMagnifier());
8892
m_squareMagnifier->setChecked(config.squareMagnifier());
@@ -132,10 +136,12 @@ void GeneralConf::showDesktopNotificationChanged(bool checked)
132136
ConfigHandler().setShowDesktopNotification(checked);
133137
}
134138

139+
#if !defined(DISABLE_UPDATE_CHECKER)
135140
void GeneralConf::checkForUpdatesChanged(bool checked)
136141
{
137142
ConfigHandler().setCheckForUpdates(checked);
138143
}
144+
#endif
139145

140146
void GeneralConf::allowMultipleGuiInstancesChanged(bool checked)
141147
{
@@ -339,6 +345,7 @@ void GeneralConf::initConfigButtons()
339345
&GeneralConf::resetConfiguration);
340346
}
341347

348+
#if !defined(DISABLE_UPDATE_CHECKER)
342349
void GeneralConf::initCheckForUpdates()
343350
{
344351
m_checkForUpdates = new QCheckBox(tr("Automatic check for updates"), this);
@@ -350,6 +357,7 @@ void GeneralConf::initCheckForUpdates()
350357
this,
351358
&GeneralConf::checkForUpdatesChanged);
352359
}
360+
#endif
353361

354362
void GeneralConf::initAllowMultipleGuiInstances()
355363
{

src/config/generalconf.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ private slots:
3737
void saveLastRegion(bool checked);
3838
void showSidePanelButtonChanged(bool checked);
3939
void showDesktopNotificationChanged(bool checked);
40+
#if !defined(DISABLE_UPDATE_CHECKER)
4041
void checkForUpdatesChanged(bool checked);
42+
#endif
4143
void allowMultipleGuiInstancesChanged(bool checked);
4244
void autoCloseIdleDaemonChanged(bool checked);
4345
void autostartChanged(bool checked);
@@ -63,7 +65,9 @@ private slots:
6365
void initAntialiasingPinZoom();
6466
void initAutoCloseIdleDaemon();
6567
void initAutostart();
68+
#if !defined(DISABLE_UPDATE_CHECKER)
6669
void initCheckForUpdates();
70+
#endif
6771
void initConfigButtons();
6872
void initCopyAndCloseAfterUpload();
6973
void initCopyOnDoubleClick();
@@ -97,7 +101,9 @@ private slots:
97101
QCheckBox* m_showTray;
98102
QCheckBox* m_helpMessage;
99103
QCheckBox* m_sidePanelButton;
104+
#if !defined(DISABLE_UPDATE_CHECKER)
100105
QCheckBox* m_checkForUpdates;
106+
#endif
101107
QCheckBox* m_allowMultipleGuiInstances;
102108
QCheckBox* m_autoCloseIdleDaemon;
103109
QCheckBox* m_autostart;

src/core/flameshotdaemon.cpp

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,18 @@
1212
#include <QClipboard>
1313
#include <QDBusConnection>
1414
#include <QDBusMessage>
15+
#include <QPixmap>
16+
#include <QRect>
17+
18+
#if !defined(DISABLE_UPDATE_CHECKER)
1519
#include <QDesktopServices>
1620
#include <QJsonDocument>
1721
#include <QJsonObject>
1822
#include <QNetworkAccessManager>
1923
#include <QNetworkReply>
20-
#include <QPixmap>
21-
#include <QRect>
2224
#include <QTimer>
2325
#include <QUrl>
26+
#endif
2427

2528
#ifdef Q_OS_WIN
2629
#include "src/core/globalshortcutfilter.h"
@@ -57,9 +60,11 @@ FlameshotDaemon::FlameshotDaemon()
5760
, m_hostingClipboard(false)
5861
, m_clipboardSignalBlocked(false)
5962
, m_trayIcon(nullptr)
63+
#if !defined(DISABLE_UPDATE_CHECKER)
6064
, m_networkCheckUpdates(nullptr)
6165
, m_showCheckAppUpdateStatus(false)
6266
, m_appLatestVersion(QStringLiteral(APP_VERSION).replace("v", ""))
67+
#endif
6368
{
6469
connect(
6570
QApplication::clipboard(), &QClipboard::dataChanged, this, [this]() {
@@ -87,9 +92,12 @@ FlameshotDaemon::FlameshotDaemon()
8792
m_persist = !config.autoCloseIdleDaemon();
8893
});
8994
#endif
95+
96+
#if !defined(DISABLE_UPDATE_CHECKER)
9097
if (ConfigHandler().checkForUpdates()) {
9198
getLatestAvailableVersion();
9299
}
100+
#endif
93101
}
94102

95103
void FlameshotDaemon::start()
@@ -169,6 +177,7 @@ void FlameshotDaemon::sendTrayNotification(const QString& text,
169177
}
170178
}
171179

180+
#if !defined(DISABLE_UPDATE_CHECKER)
172181
void FlameshotDaemon::showUpdateNotificationIfAvailable(CaptureWidget* widget)
173182
{
174183
if (!m_appLatestUrl.isEmpty() &&
@@ -207,6 +216,7 @@ void FlameshotDaemon::checkForUpdates()
207216
QDesktopServices::openUrl(QUrl(m_appLatestUrl));
208217
}
209218
}
219+
#endif
210220

211221
/**
212222
* @brief Return the daemon instance.
@@ -344,6 +354,7 @@ void FlameshotDaemon::enableTrayIcon(bool enable)
344354
}
345355
}
346356

357+
#if !defined(DISABLE_UPDATE_CHECKER)
347358
void FlameshotDaemon::handleReplyCheckUpdates(QNetworkReply* reply)
348359
{
349360
if (!ConfigHandler().checkForUpdates()) {
@@ -382,6 +393,7 @@ void FlameshotDaemon::handleReplyCheckUpdates(QNetworkReply* reply)
382393
}
383394
m_showCheckAppUpdateStatus = false;
384395
}
396+
#endif
385397

386398
QDBusMessage FlameshotDaemon::createMethodCall(QString method)
387399
{

src/core/flameshotdaemon.h

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,13 @@ class QRect;
99
class QDBusMessage;
1010
class QDBusConnection;
1111
class TrayIcon;
12+
class CaptureWidget;
13+
14+
#if !defined(DISABLE_UPDATE_CHECKER)
1215
class QNetworkAccessManager;
1316
class QNetworkReply;
1417
class QVersionNumber;
15-
class CaptureWidget;
18+
#endif
1619

1720
class FlameshotDaemon : public QObject
1821
{
@@ -30,14 +33,19 @@ class FlameshotDaemon : public QObject
3033
const QString& title = QStringLiteral("Flameshot Info"),
3134
const int timeout = 5000);
3235

36+
#if !defined(DISABLE_UPDATE_CHECKER)
3337
void showUpdateNotificationIfAvailable(CaptureWidget* widget);
3438

3539
public slots:
3640
void checkForUpdates();
3741
void getLatestAvailableVersion();
3842

43+
private slots:
44+
void handleReplyCheckUpdates(QNetworkReply* reply);
45+
3946
signals:
4047
void newVersionAvailable(QVersionNumber version);
48+
#endif
4149

4250
private:
4351
FlameshotDaemon();
@@ -52,10 +60,6 @@ public slots:
5260
void initTrayIcon();
5361
void enableTrayIcon(bool enable);
5462

55-
private slots:
56-
void handleReplyCheckUpdates(QNetworkReply* reply);
57-
58-
private:
5963
static QDBusMessage createMethodCall(QString method);
6064
static void checkDBusConnection(const QDBusConnection& connection);
6165
static void call(const QDBusMessage& m);
@@ -66,10 +70,12 @@ private slots:
6670
QList<QWidget*> m_widgets;
6771
TrayIcon* m_trayIcon;
6872

73+
#if !defined(DISABLE_UPDATE_CHECKER)
6974
QString m_appLatestUrl;
7075
QString m_appLatestVersion;
7176
bool m_showCheckAppUpdateStatus;
7277
QNetworkAccessManager* m_networkCheckUpdates;
78+
#endif
7379

7480
static FlameshotDaemon* m_instance;
7581

src/utils/confighandler.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ static QMap<class QString, QSharedPointer<ValueHandler>>
7979
OPTION("showDesktopNotification" ,Bool ( true )),
8080
OPTION("disabledTrayIcon" ,Bool ( false )),
8181
OPTION("historyConfirmationToDelete" ,Bool ( true )),
82+
#if !defined(DISABLE_UPDATE_CHECKER)
8283
OPTION("checkForUpdates" ,Bool ( true )),
84+
#endif
8385
OPTION("allowMultipleGuiInstances" ,Bool ( false )),
8486
OPTION("showMagnifier" ,Bool ( false )),
8587
OPTION("squareMagnifier" ,Bool ( false )),

src/utils/confighandler.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ class ConfigHandler : public QObject
8686
CONFIG_GETTER_SETTER(drawThickness, setDrawThickness, int)
8787
CONFIG_GETTER_SETTER(drawFontSize, setDrawFontSize, int)
8888
CONFIG_GETTER_SETTER(keepOpenAppLauncher, setKeepOpenAppLauncher, bool)
89+
#if !defined(DISABLE_UPDATE_CHECKER)
8990
CONFIG_GETTER_SETTER(checkForUpdates, setCheckForUpdates, bool)
91+
#endif
9092
CONFIG_GETTER_SETTER(allowMultipleGuiInstances,
9193
setAllowMultipleGuiInstances,
9294
bool)

src/widgets/CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,15 @@ target_sources(
2020
orientablepushbutton.h
2121
uploadhistory.h
2222
uploadlineitem.h
23-
updatenotificationwidget.h
2423
colorpickerwidget.h
2524
imguploaddialog.h
2625
capture/capturetoolobjects.h
2726
)
2827

2928
target_sources(
3029
flameshot
31-
PRIVATE capturelauncher.cpp
30+
PRIVATE
31+
capturelauncher.cpp
3232
draggablewidgetmaker.cpp
3333
imagelabel.cpp
3434
trayicon.cpp
@@ -38,8 +38,16 @@ target_sources(
3838
orientablepushbutton.cpp
3939
uploadhistory.cpp
4040
uploadlineitem.cpp
41-
updatenotificationwidget.cpp
4241
colorpickerwidget.cpp
4342
imguploaddialog.cpp
4443
capture/capturetoolobjects.cpp
4544
)
45+
46+
if (NOT DISABLE_UPDATE_CHECKER)
47+
target_sources(
48+
flameshot
49+
PRIVATE
50+
updatenotificationwidget.h
51+
updatenotificationwidget.cpp
52+
)
53+
endif()

src/widgets/capture/capturewidget.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "src/widgets/orientablepushbutton.h"
3030
#include "src/widgets/panel/sidepanelwidget.h"
3131
#include "src/widgets/panel/utilitypanel.h"
32-
#include "src/widgets/updatenotificationwidget.h"
3332
#include <QApplication>
3433
#include <QDateTime>
3534
#include <QDebug>
@@ -42,6 +41,10 @@
4241
#include <QShortcut>
4342
#include <draggablewidgetmaker.h>
4443

44+
#if !defined(DISABLE_UPDATE_CHECKER)
45+
#include "src/widgets/updatenotificationwidget.h"
46+
#endif
47+
4548
#define MOUSE_DISTANCE_TO_START_MOVING 3
4649

4750
// CaptureWidget is the main component used to capture the screen. It contains
@@ -64,7 +67,9 @@ CaptureWidget::CaptureWidget(const CaptureRequest& req,
6467
, m_toolWidget(nullptr)
6568
, m_colorPicker(nullptr)
6669
, m_lastMouseWheel(0)
70+
#if !defined(DISABLE_UPDATE_CHECKER)
6771
, m_updateNotificationWidget(nullptr)
72+
#endif
6873
, m_activeToolIsMoved(false)
6974
, m_panel(nullptr)
7075
, m_sidePanel(nullptr)
@@ -1127,6 +1132,7 @@ void CaptureWidget::initPanel()
11271132
m_panel->fillCaptureTools(m_captureToolObjects.captureToolObjects());
11281133
}
11291134

1135+
#if !defined(DISABLE_UPDATE_CHECKER)
11301136
void CaptureWidget::showAppUpdateNotification(const QString& appLatestVersion,
11311137
const QString& appLatestUrl)
11321138
{
@@ -1159,6 +1165,7 @@ void CaptureWidget::showAppUpdateNotification(const QString& appLatestVersion,
11591165
makeChild(m_updateNotificationWidget);
11601166
m_updateNotificationWidget->show();
11611167
}
1168+
#endif
11621169

11631170
void CaptureWidget::initSelection()
11641171
{

src/widgets/capture/capturewidget.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ class QNetworkReply;
3535
class ColorPicker;
3636
class NotifierBox;
3737
class HoverEventFilter;
38+
#if !defined(DISABLE_UPDATE_CHECKER)
3839
class UpdateNotificationWidget;
40+
#endif
3941
class UtilityPanel;
4042
class SidePanelWidget;
4143

@@ -50,9 +52,11 @@ class CaptureWidget : public QWidget
5052
~CaptureWidget();
5153

5254
QPixmap pixmap();
55+
void setCaptureToolObjects(const CaptureToolObjects& captureToolObjects);
56+
#if !defined(DISABLE_UPDATE_CHECKER)
5357
void showAppUpdateNotification(const QString& appLatestVersion,
5458
const QString& appLatestUrl);
55-
void setCaptureToolObjects(const CaptureToolObjects& captureToolObjects);
59+
#endif
5660

5761
public slots:
5862
bool commitCurrentTool();
@@ -168,7 +172,9 @@ private slots:
168172
bool m_configError;
169173
bool m_configErrorResolved;
170174

175+
#if !defined(DISABLE_UPDATE_CHECKER)
171176
UpdateNotificationWidget* m_updateNotificationWidget;
177+
#endif
172178
quint64 m_lastMouseWheel;
173179
QPointer<CaptureToolButton> m_sizeIndButton;
174180
// Last pressed button

0 commit comments

Comments
 (0)