diff --git a/CMakeLists.txt b/CMakeLists.txt index c7433aaf..1cadbbd2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -68,6 +68,10 @@ option(GENERATE_TS "Regenerate translation source files" OFF) option(USE_EXTERNAL_SINGLEAPPLICATION "Use external QtSingleApplication library" OFF) option(USE_LAUNCHER_ABSOLUTE_PATH "Use absolute path for the desktop launcher" ON) option(USE_WAYLAND_CLIPBOARD "USE KF Gui Wayland Clipboard" OFF) +option(DISABLE_UPDATE_CHECKER "Disable check for updates" OFF) +if (DISABLE_UPDATE_CHECKER) + add_compile_definitions(DISABLE_UPDATE_CHECKER) +endif () include(cmake/StandardProjectSettings.cmake) diff --git a/src/config/generalconf.cpp b/src/config/generalconf.cpp index c8c1cad0..3de49881 100644 --- a/src/config/generalconf.cpp +++ b/src/config/generalconf.cpp @@ -38,7 +38,9 @@ GeneralConf::GeneralConf(QWidget* parent) #endif initShowTrayIcon(); initShowDesktopNotification(); +#if !defined(DISABLE_UPDATE_CHECKER) initCheckForUpdates(); +#endif initShowStartupLaunchMessage(); initAllowMultipleGuiInstances(); initSaveLastRegion(); @@ -82,7 +84,9 @@ void GeneralConf::_updateComponents(bool allowEmptySavePath) m_uploadWithoutConfirmation->setChecked(config.uploadWithoutConfirmation()); m_historyConfirmationToDelete->setChecked( config.historyConfirmationToDelete()); +#if !defined(DISABLE_UPDATE_CHECKER) m_checkForUpdates->setChecked(config.checkForUpdates()); +#endif m_allowMultipleGuiInstances->setChecked(config.allowMultipleGuiInstances()); m_showMagnifier->setChecked(config.showMagnifier()); m_squareMagnifier->setChecked(config.squareMagnifier()); @@ -132,10 +136,12 @@ void GeneralConf::showDesktopNotificationChanged(bool checked) ConfigHandler().setShowDesktopNotification(checked); } +#if !defined(DISABLE_UPDATE_CHECKER) void GeneralConf::checkForUpdatesChanged(bool checked) { ConfigHandler().setCheckForUpdates(checked); } +#endif void GeneralConf::allowMultipleGuiInstancesChanged(bool checked) { @@ -339,6 +345,7 @@ void GeneralConf::initConfigButtons() &GeneralConf::resetConfiguration); } +#if !defined(DISABLE_UPDATE_CHECKER) void GeneralConf::initCheckForUpdates() { m_checkForUpdates = new QCheckBox(tr("Automatic check for updates"), this); @@ -350,6 +357,7 @@ void GeneralConf::initCheckForUpdates() this, &GeneralConf::checkForUpdatesChanged); } +#endif void GeneralConf::initAllowMultipleGuiInstances() { diff --git a/src/config/generalconf.h b/src/config/generalconf.h index 278ab0e7..2ff495e4 100644 --- a/src/config/generalconf.h +++ b/src/config/generalconf.h @@ -37,7 +37,9 @@ private slots: void saveLastRegion(bool checked); void showSidePanelButtonChanged(bool checked); void showDesktopNotificationChanged(bool checked); +#if !defined(DISABLE_UPDATE_CHECKER) void checkForUpdatesChanged(bool checked); +#endif void allowMultipleGuiInstancesChanged(bool checked); void autoCloseIdleDaemonChanged(bool checked); void autostartChanged(bool checked); @@ -63,7 +65,9 @@ private: void initAntialiasingPinZoom(); void initAutoCloseIdleDaemon(); void initAutostart(); +#if !defined(DISABLE_UPDATE_CHECKER) void initCheckForUpdates(); +#endif void initConfigButtons(); void initCopyAndCloseAfterUpload(); void initCopyOnDoubleClick(); @@ -97,7 +101,9 @@ private: QCheckBox* m_showTray; QCheckBox* m_helpMessage; QCheckBox* m_sidePanelButton; +#if !defined(DISABLE_UPDATE_CHECKER) QCheckBox* m_checkForUpdates; +#endif QCheckBox* m_allowMultipleGuiInstances; QCheckBox* m_autoCloseIdleDaemon; QCheckBox* m_autostart; diff --git a/src/core/flameshotdaemon.cpp b/src/core/flameshotdaemon.cpp index 72254903..c95b23b7 100644 --- a/src/core/flameshotdaemon.cpp +++ b/src/core/flameshotdaemon.cpp @@ -12,15 +12,18 @@ #include #include #include +#include +#include + +#if !defined(DISABLE_UPDATE_CHECKER) #include #include #include #include #include -#include -#include #include #include +#endif #ifdef Q_OS_WIN #include "src/core/globalshortcutfilter.h" @@ -57,9 +60,11 @@ FlameshotDaemon::FlameshotDaemon() , m_hostingClipboard(false) , m_clipboardSignalBlocked(false) , m_trayIcon(nullptr) +#if !defined(DISABLE_UPDATE_CHECKER) , m_networkCheckUpdates(nullptr) , m_showCheckAppUpdateStatus(false) , m_appLatestVersion(QStringLiteral(APP_VERSION).replace("v", "")) +#endif { connect( QApplication::clipboard(), &QClipboard::dataChanged, this, [this]() { @@ -87,9 +92,12 @@ FlameshotDaemon::FlameshotDaemon() m_persist = !config.autoCloseIdleDaemon(); }); #endif + +#if !defined(DISABLE_UPDATE_CHECKER) if (ConfigHandler().checkForUpdates()) { getLatestAvailableVersion(); } +#endif } void FlameshotDaemon::start() @@ -169,6 +177,7 @@ void FlameshotDaemon::sendTrayNotification(const QString& text, } } +#if !defined(DISABLE_UPDATE_CHECKER) void FlameshotDaemon::showUpdateNotificationIfAvailable(CaptureWidget* widget) { if (!m_appLatestUrl.isEmpty() && @@ -207,6 +216,7 @@ void FlameshotDaemon::checkForUpdates() QDesktopServices::openUrl(QUrl(m_appLatestUrl)); } } +#endif /** * @brief Return the daemon instance. @@ -344,6 +354,7 @@ void FlameshotDaemon::enableTrayIcon(bool enable) } } +#if !defined(DISABLE_UPDATE_CHECKER) void FlameshotDaemon::handleReplyCheckUpdates(QNetworkReply* reply) { if (!ConfigHandler().checkForUpdates()) { @@ -382,6 +393,7 @@ void FlameshotDaemon::handleReplyCheckUpdates(QNetworkReply* reply) } m_showCheckAppUpdateStatus = false; } +#endif QDBusMessage FlameshotDaemon::createMethodCall(QString method) { diff --git a/src/core/flameshotdaemon.h b/src/core/flameshotdaemon.h index 2bfdf9c7..c729ce8a 100644 --- a/src/core/flameshotdaemon.h +++ b/src/core/flameshotdaemon.h @@ -9,10 +9,13 @@ class QRect; class QDBusMessage; class QDBusConnection; class TrayIcon; +class CaptureWidget; + +#if !defined(DISABLE_UPDATE_CHECKER) class QNetworkAccessManager; class QNetworkReply; class QVersionNumber; -class CaptureWidget; +#endif class FlameshotDaemon : public QObject { @@ -30,14 +33,19 @@ public: const QString& title = QStringLiteral("Flameshot Info"), const int timeout = 5000); +#if !defined(DISABLE_UPDATE_CHECKER) void showUpdateNotificationIfAvailable(CaptureWidget* widget); public slots: void checkForUpdates(); void getLatestAvailableVersion(); +private slots: + void handleReplyCheckUpdates(QNetworkReply* reply); + signals: void newVersionAvailable(QVersionNumber version); +#endif private: FlameshotDaemon(); @@ -52,10 +60,6 @@ private: void initTrayIcon(); void enableTrayIcon(bool enable); -private slots: - void handleReplyCheckUpdates(QNetworkReply* reply); - -private: static QDBusMessage createMethodCall(QString method); static void checkDBusConnection(const QDBusConnection& connection); static void call(const QDBusMessage& m); @@ -66,10 +70,12 @@ private: QList m_widgets; TrayIcon* m_trayIcon; +#if !defined(DISABLE_UPDATE_CHECKER) QString m_appLatestUrl; QString m_appLatestVersion; bool m_showCheckAppUpdateStatus; QNetworkAccessManager* m_networkCheckUpdates; +#endif static FlameshotDaemon* m_instance; diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp index 34d00d73..9882d23f 100644 --- a/src/utils/confighandler.cpp +++ b/src/utils/confighandler.cpp @@ -79,7 +79,9 @@ static QMap> OPTION("showDesktopNotification" ,Bool ( true )), OPTION("disabledTrayIcon" ,Bool ( false )), OPTION("historyConfirmationToDelete" ,Bool ( true )), +#if !defined(DISABLE_UPDATE_CHECKER) OPTION("checkForUpdates" ,Bool ( true )), +#endif OPTION("allowMultipleGuiInstances" ,Bool ( false )), OPTION("showMagnifier" ,Bool ( false )), OPTION("squareMagnifier" ,Bool ( false )), diff --git a/src/utils/confighandler.h b/src/utils/confighandler.h index 73e51cea..1e9f9a4c 100644 --- a/src/utils/confighandler.h +++ b/src/utils/confighandler.h @@ -86,7 +86,9 @@ public: CONFIG_GETTER_SETTER(drawThickness, setDrawThickness, int) CONFIG_GETTER_SETTER(drawFontSize, setDrawFontSize, int) CONFIG_GETTER_SETTER(keepOpenAppLauncher, setKeepOpenAppLauncher, bool) +#if !defined(DISABLE_UPDATE_CHECKER) CONFIG_GETTER_SETTER(checkForUpdates, setCheckForUpdates, bool) +#endif CONFIG_GETTER_SETTER(allowMultipleGuiInstances, setAllowMultipleGuiInstances, bool) diff --git a/src/widgets/CMakeLists.txt b/src/widgets/CMakeLists.txt index 95902559..c9107bff 100644 --- a/src/widgets/CMakeLists.txt +++ b/src/widgets/CMakeLists.txt @@ -20,7 +20,6 @@ target_sources( orientablepushbutton.h uploadhistory.h uploadlineitem.h - updatenotificationwidget.h colorpickerwidget.h imguploaddialog.h capture/capturetoolobjects.h @@ -28,7 +27,8 @@ target_sources( target_sources( flameshot - PRIVATE capturelauncher.cpp + PRIVATE + capturelauncher.cpp draggablewidgetmaker.cpp imagelabel.cpp trayicon.cpp @@ -38,8 +38,16 @@ target_sources( orientablepushbutton.cpp uploadhistory.cpp uploadlineitem.cpp - updatenotificationwidget.cpp colorpickerwidget.cpp imguploaddialog.cpp capture/capturetoolobjects.cpp ) + +if (NOT DISABLE_UPDATE_CHECKER) + target_sources( + flameshot + PRIVATE + updatenotificationwidget.h + updatenotificationwidget.cpp + ) +endif() \ No newline at end of file diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index 0fd9524d..3749784f 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -29,7 +29,6 @@ #include "src/widgets/orientablepushbutton.h" #include "src/widgets/panel/sidepanelwidget.h" #include "src/widgets/panel/utilitypanel.h" -#include "src/widgets/updatenotificationwidget.h" #include #include #include @@ -42,6 +41,10 @@ #include #include +#if !defined(DISABLE_UPDATE_CHECKER) +#include "src/widgets/updatenotificationwidget.h" +#endif + #define MOUSE_DISTANCE_TO_START_MOVING 3 // CaptureWidget is the main component used to capture the screen. It contains @@ -64,7 +67,9 @@ CaptureWidget::CaptureWidget(const CaptureRequest& req, , m_toolWidget(nullptr) , m_colorPicker(nullptr) , m_lastMouseWheel(0) +#if !defined(DISABLE_UPDATE_CHECKER) , m_updateNotificationWidget(nullptr) +#endif , m_activeToolIsMoved(false) , m_panel(nullptr) , m_sidePanel(nullptr) @@ -1127,6 +1132,7 @@ void CaptureWidget::initPanel() m_panel->fillCaptureTools(m_captureToolObjects.captureToolObjects()); } +#if !defined(DISABLE_UPDATE_CHECKER) void CaptureWidget::showAppUpdateNotification(const QString& appLatestVersion, const QString& appLatestUrl) { @@ -1159,6 +1165,7 @@ void CaptureWidget::showAppUpdateNotification(const QString& appLatestVersion, makeChild(m_updateNotificationWidget); m_updateNotificationWidget->show(); } +#endif void CaptureWidget::initSelection() { diff --git a/src/widgets/capture/capturewidget.h b/src/widgets/capture/capturewidget.h index b994c346..ece0047c 100644 --- a/src/widgets/capture/capturewidget.h +++ b/src/widgets/capture/capturewidget.h @@ -35,7 +35,9 @@ class QNetworkReply; class ColorPicker; class NotifierBox; class HoverEventFilter; +#if !defined(DISABLE_UPDATE_CHECKER) class UpdateNotificationWidget; +#endif class UtilityPanel; class SidePanelWidget; @@ -50,9 +52,11 @@ public: ~CaptureWidget(); QPixmap pixmap(); + void setCaptureToolObjects(const CaptureToolObjects& captureToolObjects); +#if !defined(DISABLE_UPDATE_CHECKER) void showAppUpdateNotification(const QString& appLatestVersion, const QString& appLatestUrl); - void setCaptureToolObjects(const CaptureToolObjects& captureToolObjects); +#endif public slots: bool commitCurrentTool(); @@ -168,7 +172,9 @@ private: bool m_configError; bool m_configErrorResolved; +#if !defined(DISABLE_UPDATE_CHECKER) UpdateNotificationWidget* m_updateNotificationWidget; +#endif quint64 m_lastMouseWheel; QPointer m_sizeIndButton; // Last pressed button diff --git a/src/widgets/trayicon.cpp b/src/widgets/trayicon.cpp index 3221118f..cb4de571 100644 --- a/src/widgets/trayicon.cpp +++ b/src/widgets/trayicon.cpp @@ -86,10 +86,12 @@ TrayIcon::~TrayIcon() delete m_menu; } +#if !defined(DISABLE_UPDATE_CHECKER) QAction* TrayIcon::appUpdates() { return m_appUpdates; } +#endif void TrayIcon::initMenu() { @@ -127,6 +129,7 @@ void TrayIcon::initMenu() connect( infoAction, &QAction::triggered, Flameshot::instance(), &Flameshot::info); +#if !defined(DISABLE_UPDATE_CHECKER) m_appUpdates = new QAction(tr("Check for updates"), this); connect(m_appUpdates, &QAction::triggered, @@ -141,6 +144,7 @@ void TrayIcon::initMenu() tr("New version %1 is available").arg(version.toString()); m_appUpdates->setText(newVersion); }); +#endif QAction* quitAction = new QAction(tr("&Quit"), this); connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit); @@ -159,12 +163,15 @@ void TrayIcon::initMenu() m_menu->addSeparator(); m_menu->addAction(configAction); m_menu->addSeparator(); +#if !defined(DISABLE_UPDATE_CHECKER) m_menu->addAction(m_appUpdates); +#endif m_menu->addAction(infoAction); m_menu->addSeparator(); m_menu->addAction(quitAction); } +#if !defined(DISABLE_UPDATE_CHECKER) void TrayIcon::enableCheckUpdatesAction(bool enable) { if (m_appUpdates != nullptr) { @@ -175,9 +182,12 @@ void TrayIcon::enableCheckUpdatesAction(bool enable) FlameshotDaemon::instance()->getLatestAvailableVersion(); } } +#endif void TrayIcon::startGuiCapture() { auto* widget = Flameshot::instance()->gui(); +#if !defined(DISABLE_UPDATE_CHECKER) FlameshotDaemon::instance()->showUpdateNotificationIfAvailable(widget); +#endif } diff --git a/src/widgets/trayicon.h b/src/widgets/trayicon.h index 386ece77..a73d6c0f 100644 --- a/src/widgets/trayicon.h +++ b/src/widgets/trayicon.h @@ -11,15 +11,21 @@ public: TrayIcon(QObject* parent = nullptr); virtual ~TrayIcon(); +#if !defined(DISABLE_UPDATE_CHECKER) QAction* appUpdates(); +#endif private: void initTrayIcon(); void initMenu(); +#if !defined(DISABLE_UPDATE_CHECKER) void enableCheckUpdatesAction(bool enable); +#endif void startGuiCapture(); QMenu* m_menu; +#if !defined(DISABLE_UPDATE_CHECKER) QAction* m_appUpdates; +#endif };