Skip to content

Commit

Permalink
Merge pull request #650 from fkubicek/add-disable-update-option
Browse files Browse the repository at this point in the history
Add config flag to disable online update check
  • Loading branch information
jurplel authored May 6, 2024
2 parents 5f56ce1 + aa03cf0 commit 360fe7f
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 9 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
20 changes: 16 additions & 4 deletions 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);

#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 @@ -25,12 +28,13 @@ QVApplication::QVApplication(int &argc, char **argv) : QApplication(argc, argv)

// Check for updates
// TODO: move this to after first window show event
if (getSettingsManager().getBoolean("updatenotifications"))
if (getSettingsManager().getBoolean("updatenotifications")) {
checkUpdates();
}

// Setup macOS dock menu
dockMenu = new QMenu();
connect(dockMenu, &QMenu::triggered, this, [](QAction *triggeredAction){
connect(dockMenu, &QMenu::triggered, this, [](QAction *triggeredAction) {
ActionManager::actionTriggered(triggeredAction);
});

Expand All @@ -44,7 +48,7 @@ QVApplication::QVApplication(int &argc, char **argv) : QApplication(argc, argv)

// Build menu bar
menuBar = actionManager.buildMenuBar();
connect(menuBar, &QMenuBar::triggered, this, [](QAction *triggeredAction){
connect(menuBar, &QMenuBar::triggered, this, [](QAction *triggeredAction) {
ActionManager::actionTriggered(triggeredAction);
});

Expand Down Expand Up @@ -115,7 +119,7 @@ void QVApplication::pickFile(MainWindow *parent)
if (parent)
fileDialog->setWindowModality(Qt::WindowModal);

connect(fileDialog, &QFileDialog::filesSelected, fileDialog, [parent](const QStringList &selected){
connect(fileDialog, &QFileDialog::filesSelected, fileDialog, [parent](const QStringList &selected) {
bool isFirstLoop = true;
for (const auto &file : selected)
{
Expand Down Expand Up @@ -194,11 +198,14 @@ MainWindow *QVApplication::getMainWindow(bool shouldBeEmpty)

void QVApplication::checkUpdates()
{
#ifndef QV_DISABLE_ONLINE_VERSION_CHECK
updateChecker.check();
#endif // QV_DISABLE_ONLINE_VERSION_CHECK
}

void QVApplication::checkedUpdates()
{
#ifndef QV_DISABLE_ONLINE_VERSION_CHECK
if (aboutDialog)
{
aboutDialog->setLatestVersionNum(updateChecker.getLatestVersionNum());
Expand All @@ -208,6 +215,7 @@ void QVApplication::checkedUpdates()
{
updateChecker.openDialog();
}
#endif // QV_DISABLE_ONLINE_VERSION_CHECK
}

void QVApplication::recentsMenuUpdated()
Expand Down Expand Up @@ -295,7 +303,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
2 changes: 2 additions & 0 deletions src/qvapplication.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,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 360fe7f

Please sign in to comment.