diff --git a/src/config/generalconf.cpp b/src/config/generalconf.cpp index 91f068ab..f1e5c10c 100644 --- a/src/config/generalconf.cpp +++ b/src/config/generalconf.cpp @@ -38,6 +38,7 @@ GeneralConf::GeneralConf(QWidget* parent) initShowSidePanelButton(); initShowDesktopNotification(); initShowTrayIcon(); + initCheckForUpdates(); initAutostart(); initUseJpgForClipboard(); initSaveAfterCopy(); @@ -93,6 +94,12 @@ void GeneralConf::showTrayIconChanged(bool checked) } } +void GeneralConf::checkForUpdatesChanged(bool checked) +{ + ConfigHandler().setCheckForUpdates(checked); + Controller::getInstance()->setCheckForUpdatesEnabled(checked); +} + void GeneralConf::autostartChanged(bool checked) { ConfigHandler().setStartupLaunch(checked); @@ -247,6 +254,19 @@ void GeneralConf::initConfigButtons() &GeneralConf::resetConfiguration); } +void GeneralConf::initCheckForUpdates() +{ + m_checkForUpdates = new QCheckBox(tr("Automatic check for updates"), this); + m_checkForUpdates->setChecked(ConfigHandler().checkForUpdates()); + m_checkForUpdates->setToolTip(tr("Automatic check for updates")); + m_layout->addWidget(m_checkForUpdates); + + connect(m_checkForUpdates, + &QCheckBox::clicked, + this, + &GeneralConf::checkForUpdatesChanged); +} + void GeneralConf::initAutostart() { m_autostart = new QCheckBox(tr("Launch at startup"), this); diff --git a/src/config/generalconf.h b/src/config/generalconf.h index 84848a3d..4180b8c2 100644 --- a/src/config/generalconf.h +++ b/src/config/generalconf.h @@ -39,6 +39,7 @@ private slots: void showSidePanelButtonChanged(bool checked); void showDesktopNotificationChanged(bool checked); void showTrayIconChanged(bool checked); + void checkForUpdatesChanged(bool checked); void autostartChanged(bool checked); void saveAfterCopyChanged(bool checked); void changeSavePath(); @@ -56,6 +57,7 @@ private: void initShowDesktopNotification(); void initShowTrayIcon(); void initConfigButtons(); + void initCheckForUpdates(); void initAutostart(); void initSaveAfterCopy(); void initUseJpgForClipboard(); @@ -66,6 +68,7 @@ private: QCheckBox* m_showTray; QCheckBox* m_helpMessage; QCheckBox* m_sidePanelButton; + QCheckBox* m_checkForUpdates; QCheckBox* m_autostart; QPushButton* m_importButton; QPushButton* m_exportButton; diff --git a/src/core/controller.cpp b/src/core/controller.cpp index 882a1e42..d35a2c13 100644 --- a/src/core/controller.cpp +++ b/src/core/controller.cpp @@ -135,6 +135,15 @@ void Controller::enableExports() this, &Controller::captureFailed, this, &Controller::handleCaptureFailed); } +void Controller::setCheckForUpdatesEnabled(const bool enabled) +{ + m_appUpdates->setVisible(enabled); + m_appUpdates->setEnabled(enabled); + if (enabled) { + getLatestAvailableVersion(); + } +} + void Controller::getLatestAvailableVersion() { // This features is required for MacOS and Windows user and for Linux users @@ -149,12 +158,17 @@ void Controller::getLatestAvailableVersion() // check for updates each 24 hours doLater(1000 * 60 * 60 * 24, this, [this]() { - this->getLatestAvailableVersion(); + if (ConfigHandler().checkForUpdates()) { + this->getLatestAvailableVersion(); + } }); } void Controller::handleReplyCheckUpdates(QNetworkReply* reply) { + if (!ConfigHandler().checkForUpdates()) { + return; + } if (reply->error() == QNetworkReply::NoError) { QJsonDocument response = QJsonDocument::fromJson(reply->readAll()); QJsonObject json = response.object(); @@ -402,6 +416,7 @@ void Controller::enableTrayIcon() m_trayIconMenu->addAction(infoAction); m_trayIconMenu->addSeparator(); m_trayIconMenu->addAction(quitAction); + setCheckForUpdatesEnabled(ConfigHandler().checkForUpdates()); m_trayIcon = new QSystemTrayIcon(); m_trayIcon->setToolTip(QStringLiteral("Flameshot")); diff --git a/src/core/controller.h b/src/core/controller.h index 73c4f217..ec6f2bb9 100644 --- a/src/core/controller.h +++ b/src/core/controller.h @@ -54,6 +54,8 @@ public: void enableExports(); void updateRecentScreenshots(); + void setCheckForUpdatesEnabled(const bool enabled); + signals: void captureTaken(uint id, QPixmap p, QRect selection); void captureFailed(uint id); diff --git a/src/utils/confighandler.cpp b/src/utils/confighandler.cpp index 541ea3cc..323f31a6 100644 --- a/src/utils/confighandler.cpp +++ b/src/utils/confighandler.cpp @@ -309,6 +309,20 @@ void ConfigHandler::setKeepOpenAppLauncher(const bool keepOpen) m_settings.setValue(QStringLiteral("keepOpenAppLauncher"), keepOpen); } +bool ConfigHandler::checkForUpdates() +{ + bool res = true; + if (m_settings.contains(QStringLiteral("checkForUpdates"))) { + res = m_settings.value(QStringLiteral("checkForUpdates")).toBool(); + } + return res; +} + +void ConfigHandler::setCheckForUpdates(const bool checkForUpdates) +{ + m_settings.setValue(QStringLiteral("checkForUpdates"), checkForUpdates); +} + bool ConfigHandler::startupLaunchValue() { #if (defined(Q_OS_MAC) || defined(Q_OS_MAC64) || defined(Q_OS_MACOS) || \ diff --git a/src/utils/confighandler.h b/src/utils/confighandler.h index 2e9080b0..c09d7d8f 100644 --- a/src/utils/confighandler.h +++ b/src/utils/confighandler.h @@ -70,6 +70,9 @@ public: bool keepOpenAppLauncherValue(); void setKeepOpenAppLauncher(const bool); + bool checkForUpdates(); + void setCheckForUpdates(const bool); + bool verifyLaunchFile(); bool startupLaunchValue(); void setStartupLaunch(const bool); diff --git a/src/widgets/capture/capturewidget.cpp b/src/widgets/capture/capturewidget.cpp index dfd4c4d9..10c5cefb 100644 --- a/src/widgets/capture/capturewidget.cpp +++ b/src/widgets/capture/capturewidget.cpp @@ -808,6 +808,10 @@ void CaptureWidget::initPanel() void CaptureWidget::showAppUpdateNotification(const QString& appLatestVersion, const QString& appLatestUrl) { + if (!ConfigHandler().checkForUpdates()) { + // option check for updates disabled + return; + } if (nullptr == m_updateNotificationWidget) { m_updateNotificationWidget = new UpdateNotificationWidget(this, appLatestVersion, appLatestUrl);