Skip to content

Commit

Permalink
Add config flag to disable online update check
Browse files Browse the repository at this point in the history
  • Loading branch information
fkubicek committed Dec 9, 2023
1 parent e37c8ea commit 19f08b0
Show file tree
Hide file tree
Showing 7 changed files with 48 additions and 6 deletions.
9 changes: 9 additions & 0 deletions qView.pro
Original file line number Diff line number Diff line change
Expand Up @@ -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)


Expand Down
9 changes: 8 additions & 1 deletion src/qvaboutdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -87,6 +89,7 @@ QVAboutDialog::~QVAboutDialog()

void QVAboutDialog::updateText()
{
#ifndef QV_DISABLE_ONLINE_VERSION_CHECK
QString updateText = tr("Checking for updates...");
if (latestVersionNum > VERSION)
{
Expand All @@ -101,8 +104,12 @@ void QVAboutDialog::updateText()
{
updateText = tr("Error checking for updates");
}
updateText += + "<br>";
#else
QString updateText = "";
#endif //QV_DISABLE_ONLINE_VERSION_CHECK
ui->updateLabel->setText(updateText +
R"(<br><a style="color: #03A9F4; text-decoration:none;" href="https://interversehq.com/qview/">interversehq.com/qview</a>)");
R"(<a style="color: #03A9F4; text-decoration:none;" href="https://interversehq.com/qview/">interversehq.com/qview</a>)");
}

double QVAboutDialog::getLatestVersionNum() const
Expand Down
13 changes: 12 additions & 1 deletion src/qvapplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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();
Expand Down Expand Up @@ -192,6 +197,7 @@ MainWindow *QVApplication::getMainWindow(bool shouldBeEmpty)
return window;
}

#ifndef QV_DISABLE_ONLINE_VERSION_CHECK
void QVApplication::checkUpdates()
{
updateChecker.check();
Expand All @@ -209,6 +215,7 @@ void QVApplication::checkedUpdates()
updateChecker.openDialog();
}
}
#endif //QV_DISABLE_ONLINE_VERSION_CHECK

void QVApplication::recentsMenuUpdated()
{
Expand Down Expand Up @@ -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();
}

Expand Down
4 changes: 4 additions & 0 deletions src/qvapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -99,7 +101,9 @@ class QVApplication : public QApplication
QPointer<QVWelcomeDialog> welcomeDialog;
QPointer<QVAboutDialog> aboutDialog;

#ifndef QV_DISABLE_ONLINE_VERSION_CHECK
UpdateChecker updateChecker;
#endif //QV_DISABLE_ONLINE_VERSION_CHECK
};

#endif // QVAPPLICATION_H
4 changes: 4 additions & 0 deletions src/qvoptionsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 4 additions & 0 deletions src/qvwelcomedialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,17 @@ 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;
settings.beginGroup("options");
settings.setValue("updatenotifications", state > 0);
qvApp->getSettingsManager().loadSettings();
});
#endif //QV_DISABLE_ONLINE_VERSION_CHECK
}

QVWelcomeDialog::~QVWelcomeDialog()
Expand Down
11 changes: 7 additions & 4 deletions src/src.pri
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit 19f08b0

Please sign in to comment.