From 19f08b01dbdf4f71ef845cff97a9e2434ea0be5f Mon Sep 17 00:00:00 2001 From: fkubicek <66724409+fkubicek@users.noreply.github.com> Date: Sat, 9 Dec 2023 13:17:52 +0100 Subject: [PATCH] Add config flag to disable online update check --- qView.pro | 9 +++++++++ src/qvaboutdialog.cpp | 9 ++++++++- src/qvapplication.cpp | 13 ++++++++++++- src/qvapplication.h | 4 ++++ src/qvoptionsdialog.cpp | 4 ++++ src/qvwelcomedialog.cpp | 4 ++++ src/src.pri | 11 +++++++---- 7 files changed, 48 insertions(+), 6 deletions(-) diff --git a/qView.pro b/qView.pro index 0e3223f5..31348af3 100644 --- a/qView.pro +++ b/qView.pro @@ -136,6 +136,15 @@ DEFINES += QT_DEPRECATED_WARNINGS # Ban usage of Qt's built in foreach utility for better code style DEFINES += QT_NO_FOREACH +# To disables both manual and automatic checking for updates either uncomment line below or +# add config flag while building from the commad line. +#CONFIG += qv_disable_online_version_check + +qv_disable_online_version_check { + DEFINES += QV_DISABLE_ONLINE_VERSION_CHECK +} + + include(src/src.pri) diff --git a/src/qvaboutdialog.cpp b/src/qvaboutdialog.cpp index cca75682..9bb26e93 100644 --- a/src/qvaboutdialog.cpp +++ b/src/qvaboutdialog.cpp @@ -71,11 +71,13 @@ QVAboutDialog::QVAboutDialog(double givenLatestVersionNum, QWidget *parent) : ui->infoLabel2->setTextInteractionFlags(Qt::TextBrowserInteraction); ui->infoLabel2->setOpenExternalLinks(true); +#ifndef QV_DISABLE_ONLINE_VERSION_CHECK if (latestVersionNum < 0.0) { qvApp->checkUpdates(); latestVersionNum = 0.0; } +#endif //QV_DISABLE_ONLINE_VERSION_CHECK updateText(); } @@ -87,6 +89,7 @@ QVAboutDialog::~QVAboutDialog() void QVAboutDialog::updateText() { +#ifndef QV_DISABLE_ONLINE_VERSION_CHECK QString updateText = tr("Checking for updates..."); if (latestVersionNum > VERSION) { @@ -101,8 +104,12 @@ void QVAboutDialog::updateText() { updateText = tr("Error checking for updates"); } + updateText += + "
"; +#else + QString updateText = ""; +#endif //QV_DISABLE_ONLINE_VERSION_CHECK ui->updateLabel->setText(updateText + - R"(
interversehq.com/qview)"); + R"(interversehq.com/qview)"); } double QVAboutDialog::getLatestVersionNum() const diff --git a/src/qvapplication.cpp b/src/qvapplication.cpp index e4369e29..3ec79f81 100644 --- a/src/qvapplication.cpp +++ b/src/qvapplication.cpp @@ -14,7 +14,10 @@ QVApplication::QVApplication(int &argc, char **argv) : QApplication(argc, argv) // Connections connect(&actionManager, &ActionManager::recentsMenuUpdated, this, &QVApplication::recentsMenuUpdated); - connect(&updateChecker, &UpdateChecker::checkedUpdates, this, &QVApplication::checkedUpdates); + +#ifndef QV_DISABLE_ONLINE_VERSION_CHECK +connect(&updateChecker, &UpdateChecker::checkedUpdates, this, &QVApplication::checkedUpdates); +#endif //QV_DISABLE_ONLINE_VERSION_CHECK // Add fallback fromTheme icon search on linux with qt >5.11 #if defined Q_OS_UNIX && !defined Q_OS_MACOS && QT_VERSION >= QT_VERSION_CHECK(5, 11, 0) @@ -23,10 +26,12 @@ QVApplication::QVApplication(int &argc, char **argv) : QApplication(argc, argv) defineFilterLists(); +#ifndef QV_DISABLE_ONLINE_VERSION_CHECK // Check for updates // TODO: move this to after first window show event if (getSettingsManager().getBoolean("updatenotifications")) checkUpdates(); +#endif //QV_DISABLE_ONLINE_VERSION_CHECK // Setup macOS dock menu dockMenu = new QMenu(); @@ -192,6 +197,7 @@ MainWindow *QVApplication::getMainWindow(bool shouldBeEmpty) return window; } +#ifndef QV_DISABLE_ONLINE_VERSION_CHECK void QVApplication::checkUpdates() { updateChecker.check(); @@ -209,6 +215,7 @@ void QVApplication::checkedUpdates() updateChecker.openDialog(); } } +#endif //QV_DISABLE_ONLINE_VERSION_CHECK void QVApplication::recentsMenuUpdated() { @@ -295,7 +302,11 @@ void QVApplication::openAboutDialog(QWidget *parent) return; } +#ifndef QV_DISABLE_ONLINE_VERSION_CHECK aboutDialog = new QVAboutDialog(updateChecker.getLatestVersionNum(), parent); +#else + aboutDialog = new QVAboutDialog(-1, parent); +#endif //QV_DISABLE_ONLINE_VERSION_CHECK aboutDialog->show(); } diff --git a/src/qvapplication.h b/src/qvapplication.h index 0ec37d5b..b6231377 100644 --- a/src/qvapplication.h +++ b/src/qvapplication.h @@ -41,9 +41,11 @@ class QVApplication : public QApplication MainWindow *getMainWindow(bool shouldBeEmpty); +#ifndef QV_DISABLE_ONLINE_VERSION_CHECK void checkUpdates(); void checkedUpdates(); +#endif //QV_DISABLE_ONLINE_VERSION_CHECK void recentsMenuUpdated(); @@ -99,7 +101,9 @@ class QVApplication : public QApplication QPointer welcomeDialog; QPointer aboutDialog; +#ifndef QV_DISABLE_ONLINE_VERSION_CHECK UpdateChecker updateChecker; +#endif //QV_DISABLE_ONLINE_VERSION_CHECK }; #endif // QVAPPLICATION_H diff --git a/src/qvoptionsdialog.cpp b/src/qvoptionsdialog.cpp index 8e61a3fb..3e3d4e17 100644 --- a/src/qvoptionsdialog.cpp +++ b/src/qvoptionsdialog.cpp @@ -43,6 +43,10 @@ QVOptionsDialog::QVOptionsDialog(QWidget *parent) : setWindowTitle("Preferences"); } +#ifdef QV_DISABLE_ONLINE_VERSION_CHECK + ui->updateCheckbox->hide(); +#endif //QV_DISABLE_ONLINE_VERSION_CHECK + // Platform specific settings #ifdef Q_OS_MACOS ui->menubarCheckbox->hide(); diff --git a/src/qvwelcomedialog.cpp b/src/qvwelcomedialog.cpp index 572ada05..235e372d 100644 --- a/src/qvwelcomedialog.cpp +++ b/src/qvwelcomedialog.cpp @@ -53,6 +53,9 @@ QVWelcomeDialog::QVWelcomeDialog(QWidget *parent) : ui->infoLabel->setTextInteractionFlags(Qt::TextBrowserInteraction); ui->infoLabel->setOpenExternalLinks(true); +#ifdef QV_DISABLE_ONLINE_VERSION_CHECK + ui->updateCheckBox->hide(); +#else ui->updateCheckBox->setChecked(qvApp->getSettingsManager().getBoolean("updatenotifications")); connect(ui->updateCheckBox, &QCheckBox::stateChanged, qvApp, [](int state){ QSettings settings; @@ -60,6 +63,7 @@ QVWelcomeDialog::QVWelcomeDialog(QWidget *parent) : settings.setValue("updatenotifications", state > 0); qvApp->getSettingsManager().loadSettings(); }); +#endif //QV_DISABLE_ONLINE_VERSION_CHECK } QVWelcomeDialog::~QVWelcomeDialog() diff --git a/src/src.pri b/src/src.pri index 18b2e798..33fd6c3f 100644 --- a/src/src.pri +++ b/src/src.pri @@ -13,8 +13,9 @@ SOURCES += \ $$PWD/qvshortcutdialog.cpp \ $$PWD/actionmanager.cpp \ $$PWD/settingsmanager.cpp \ - $$PWD/shortcutmanager.cpp \ - $$PWD/updatechecker.cpp + $$PWD/shortcutmanager.cpp + +!qv_disable_online_version_check:SOURCES += $$PWD/updatechecker.cpp macx:!CONFIG(NO_COCOA):SOURCES += $$PWD/qvcocoafunctions.mm win32:!CONFIG(NO_WIN32):SOURCES += $$PWD/qvwin32functions.cpp @@ -34,8 +35,10 @@ HEADERS += \ $$PWD/qvshortcutdialog.h \ $$PWD/actionmanager.h \ $$PWD/settingsmanager.h \ - $$PWD/shortcutmanager.h \ - $$PWD/updatechecker.h + $$PWD/shortcutmanager.h + +!qv_disable_online_version_check:HEADERS += $$PWD/updatechecker.h + macx:!CONFIG(NO_COCOA):HEADERS += $$PWD/qvcocoafunctions.h win32:!CONFIG(NO_WIN32):HEADERS += $$PWD/qvwin32functions.h