From 2e3afd5f1017fc441ecdc745e053fa0b6ec479d4 Mon Sep 17 00:00:00 2001 From: Alexandr Zarubkin Date: Fri, 19 Sep 2014 15:22:17 +0400 Subject: [PATCH 1/2] Added an option to use external QSettings object (default behaviour hasn't changed). Signed-off-by: Alexandr Zarubkin --- fvignoredversions.cpp | 30 ++++++++++-------------------- fvupdater.cpp | 33 ++++++++++++++++++++++++++++----- fvupdater.h | 10 +++++++--- 3 files changed, 45 insertions(+), 28 deletions(-) diff --git a/fvignoredversions.cpp b/fvignoredversions.cpp index c665f9c..026a82d 100644 --- a/fvignoredversions.cpp +++ b/fvignoredversions.cpp @@ -1,5 +1,6 @@ #include "fvignoredversions.h" #include "fvversioncomparator.h" +#include "fvupdater.h" #include #include #include @@ -9,7 +10,7 @@ FVIgnoredVersions::FVIgnoredVersions(QObject *parent) : -QObject(parent) + QObject(parent) { // noop } @@ -21,32 +22,27 @@ bool FVIgnoredVersions::VersionIsIgnored(QString version) // 2) The version that was skipped before and thus stored in QSettings (ignore) // 3) A newer version (don't ignore) // 'version' is not likely to contain an older version in any case. - + if (version == QCoreApplication::applicationVersion()) { return true; } - QSettings settings(QSettings::NativeFormat, - QSettings::UserScope, - QCoreApplication::organizationDomain(), - QCoreApplication::applicationName()); - - //QSettings settings; - if (settings.contains(FV_IGNORED_VERSIONS_LATEST_SKIPPED_VERSION_KEY)) { - QString lastSkippedVersion = settings.value(FV_IGNORED_VERSIONS_LATEST_SKIPPED_VERSION_KEY).toString(); + QSettings* settings = FvUpdater::getSettings(); + if (settings->contains(FV_IGNORED_VERSIONS_LATEST_SKIPPED_VERSION_KEY)) { + QString lastSkippedVersion = settings->value(FV_IGNORED_VERSIONS_LATEST_SKIPPED_VERSION_KEY).toString(); if (version == lastSkippedVersion) { // Implicitly skipped version - skip return true; } } - + std::string currentAppVersion = QCoreApplication::applicationVersion().toStdString(); std::string suggestedVersion = std::string(version.toStdString()); if (FvVersionComparator::CompareVersions(currentAppVersion, suggestedVersion) == FvVersionComparator::kAscending) { // Newer version - do not skip return false; } - + // Fallback - skip return true; } @@ -57,18 +53,12 @@ void FVIgnoredVersions::IgnoreVersion(QString version) // Don't ignore the current version return; } - + if (version.isEmpty()) { return; } - - QSettings settings(QSettings::NativeFormat, - QSettings::UserScope, - QCoreApplication::organizationDomain(), - QCoreApplication::applicationName()); - - settings.setValue(FV_IGNORED_VERSIONS_LATEST_SKIPPED_VERSION_KEY, version); + FvUpdater::getSettings()->setValue(FV_IGNORED_VERSIONS_LATEST_SKIPPED_VERSION_KEY, version); return; } \ No newline at end of file diff --git a/fvupdater.cpp b/fvupdater.cpp index 3fb99b3..92f51c3 100644 --- a/fvupdater.cpp +++ b/fvupdater.cpp @@ -28,9 +28,8 @@ # include "fvversioncomparatortest.h" #endif -extern QSettings* settings; - FvUpdater* FvUpdater::m_Instance = 0; +QSettings* FvUpdater::m_Settings = 0; FvUpdater* FvUpdater::sharedUpdater() { @@ -57,6 +56,31 @@ void FvUpdater::drop() mutex.unlock(); } +void FvUpdater::setSettings(QSettings* settings) +{ + m_Settings = settings; +} + +QSettings* FvUpdater::getSettings() +{ + static QMutex mutex; + if (! m_Settings) { + mutex.lock(); + + if (!m_Settings) { + QSettings settings(QSettings::NativeFormat, + QSettings::UserScope, + QCoreApplication::organizationDomain(), + QCoreApplication::applicationName()); + m_Settings = &settings; + } + + mutex.unlock(); + } + + return m_Settings; +} + FvUpdater::FvUpdater() : QObject(0) { m_reply = 0; @@ -891,10 +915,9 @@ bool FvUpdater::getRemindLaterAllowed() } #ifndef FV_GUI - void FvUpdater::decideWhatToDoWithCurrentUpdateProposal() { - QString policy = settings->value(FV_NEW_VERSION_POLICY_KEY).toString(); + QString policy = getSettings()->value(FV_NEW_VERSION_POLICY_KEY).toString(); if(policy == "install") InstallUpdate(); else if(policy == "skip") @@ -903,4 +926,4 @@ void FvUpdater::decideWhatToDoWithCurrentUpdateProposal() RemindMeLater(); } -#endif \ No newline at end of file +#endif diff --git a/fvupdater.h b/fvupdater.h index 48baf0c..63d4594 100644 --- a/fvupdater.h +++ b/fvupdater.h @@ -7,6 +7,7 @@ #include #include class QNetworkReply; +class QSettings; class FvUpdateWindow; class FvUpdateConfirmDialog; class FvAvailableUpdate; @@ -29,7 +30,7 @@ class FvUpdater : public QObject void finishUpdate(QString pathToFinish = ""); void setRequiredSslFingerPrint(QString md5); QString getRequiredSslFingerPrint(); // returns md5! - // HTTP Authentuication - for security reasons no getters are provided, only a setter + // HTTP Authentication - for security reasons no getters are provided, only a setter void setHtAuthCredentials(QString user, QString pass); void setHtAuthUsername(QString user); void setHtAuthPassword(QString pass); @@ -37,7 +38,10 @@ class FvUpdater : public QObject void setRemindLaterAllowed(bool allowed); bool getSkipVersionAllowed(); bool getRemindLaterAllowed(); - + // This is to set QSettings object which is shared with the rest of user application. + // We will use the settings, but we will not own it. Someone else should be responsible for freeing the object. + static void setSettings(QSettings *settings); + static QSettings* getSettings(); public slots: @@ -83,7 +87,7 @@ protected slots: FvUpdater& operator=(const FvUpdater&); // Hide assign op static FvUpdater* m_Instance; // Singleton instance - + static QSettings* m_Settings; // // Windows / dialogs From dc2cf7eda64bcad678799ba16630914805485daa Mon Sep 17 00:00:00 2001 From: Alexandr Zarubkin Date: Fri, 19 Sep 2014 15:23:24 +0400 Subject: [PATCH 2/2] Fixed compilation on Windows with Qt 5. Added an option to disable GUI, this time for both Qt 4 and Qt 5. Added automatic recompilation of affected files after GUI option changes. Removed unnecessary conditional define for Qt 5 - it compiles fine with #include . Signed-off-by: Alexandr Zarubkin --- Fervor.pri | 25 +++++++++++++++++++------ fvupdater.cpp | 6 +++--- fvupdatewindow.h | 6 +----- 3 files changed, 23 insertions(+), 14 deletions(-) diff --git a/Fervor.pri b/Fervor.pri index f4c3973..1985715 100644 --- a/Fervor.pri +++ b/Fervor.pri @@ -1,21 +1,34 @@ +QT += core network +!build_pass:message("If you want to enable GUI for Fervor, add CONFIG += fervor_gui to your .pro file") contains(QT_VERSION, ^5\\.[0-9]\\..*){ - QT += core widgets webkitwidgets network + fervor_gui { + DEFINES += FV_GUI + QT += webkitwidgets + } win32:INCLUDEPATH += $$[QT_INSTALL_PREFIX]/include/QtZlib }else{ - #QT += core gui webkit network - QT += core webkit network fervor_gui { DEFINES += FV_GUI - QT += gui + QT += gui webkit } win32:INCLUDEPATH += $$[QT_INSTALL_PREFIX]/../../../../QtSources/4.8.1/src/3rdparty/zlib } DEFINES += FV_APP_NAME=\\\"$$TARGET\\\" DEFINES += FV_APP_VERSION=\\\"$$VERSION\\\" +PREVIOUS_FERVOR_GUI = $$cat($$PWD/fervor.gui) +fervor_gui { + CURRENT_FERVOR_GUI = enabled +} else { + CURRENT_FERVOR_GUI = disabled +} +# if last build was with another GUI option, recompile some files +!equals(PREVIOUS_FERVOR_GUI, $$CURRENT_FERVOR_GUI) { + write_file($$PWD/fervor.gui, CURRENT_FERVOR_GUI) + touch($$PWD/fvupdater.h, $$PWD/fervor.gui) +} - -DEFINES +=QUAZIP_BUILD QUAZIP_STATIC +DEFINES += QUAZIP_BUILD QUAZIP_STATIC INCLUDEPATH += $$PWD/quazip HEADERS += $$PWD/quazip/crypt.h \ diff --git a/fvupdater.cpp b/fvupdater.cpp index 92f51c3..4c48775 100644 --- a/fvupdater.cpp +++ b/fvupdater.cpp @@ -810,12 +810,12 @@ void FvUpdater::finishUpdate(QString pathToFinish) void FvUpdater::restartApplication() { // Spawn a new instance of myApplication: - QString app = QApplication::applicationFilePath(); - QStringList arguments = QApplication::arguments(); + QString app = QCoreApplication::applicationFilePath(); + QStringList arguments = QCoreApplication::arguments(); QString wd = QDir::currentPath(); qDebug() << app << arguments << wd; QProcess::startDetached(app, arguments, wd); - QApplication::exit(); + QCoreApplication::exit(); } void FvUpdater::setRequiredSslFingerPrint(QString md5) diff --git a/fvupdatewindow.h b/fvupdatewindow.h index b2e3feb..f9b2fcb 100644 --- a/fvupdatewindow.h +++ b/fvupdatewindow.h @@ -1,11 +1,7 @@ #ifndef FVUPDATEWINDOW_H #define FVUPDATEWINDOW_H -#if QT_VERSION >= 0x050000 - #include -#else - #include -#endif +#include class QGraphicsScene;