[Pkg-owncloud-commits] [owncloud-client] 375/498: Updater: Added a class UpdaterSchedule.

Sandro Knauß hefee-guest at moszumanska.debian.org
Tue Aug 11 14:49:08 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit c34641f4f7013ded6b73f43a9a6b22aac8c7c80a
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Wed Jul 22 13:44:19 2015 +0200

    Updater: Added a class UpdaterSchedule.
    
    It schedules the regular update checks. Keeps Application and
    other classes easy.
---
 src/gui/application.cpp       |  7 +++--
 src/gui/updater/ocupdater.cpp | 63 ++++++++++++++++++++++++++++++-------------
 src/gui/updater/ocupdater.h   | 54 +++++++++++++++++++++++++++++++++++--
 3 files changed, 100 insertions(+), 24 deletions(-)

diff --git a/src/gui/application.cpp b/src/gui/application.cpp
index acc19bf..1bbedd0 100644
--- a/src/gui/application.cpp
+++ b/src/gui/application.cpp
@@ -178,10 +178,9 @@ Application::Application(int &argc, char **argv) :
     QTimer::singleShot( 0, this, SLOT( slotCheckConnection() ));
 
     // Update checks
-    if (OCUpdater *updater = dynamic_cast<OCUpdater*>(Updater::instance())) {
-        connect(updater,  SIGNAL(newUpdateAvailable(QString,QString)),
-                _gui,     SLOT(slotShowTrayMessage(QString,QString)) );
-    }
+    UpdaterScheduler *updaterScheduler = new UpdaterScheduler(this);
+    connect(updaterScheduler, SIGNAL(updaterAnnouncement(QString, QString)),
+            _gui, SLOT(slotShowTrayMessage(QString, QString)));
 
     // Cleanup at Quit.
     connect (this, SIGNAL(aboutToQuit()), SLOT(slotCleanup()));
diff --git a/src/gui/updater/ocupdater.cpp b/src/gui/updater/ocupdater.cpp
index 97f8a06..8aecbb1 100644
--- a/src/gui/updater/ocupdater.cpp
+++ b/src/gui/updater/ocupdater.cpp
@@ -37,25 +37,59 @@ static const char seenVersionC[] = "Updater/seenVersion";
 static const char autoUpdateFailedVersionC[] = "Updater/autoUpdateFailedVersion";
 static const char autoUpdateAttemptedC[] = "Updater/autoUpdateAttempted";
 
+
+UpdaterScheduler::UpdaterScheduler(QObject *parent) :
+    QObject(parent)
+{
+    connect( &_updateCheckTimer, SIGNAL(timeout()),
+             this, SLOT(slotTimerFired()) );
+
+    // Note: the sparkle-updater is not an OCUpdater and thus the dynamic_cast
+    // returns NULL. Clever detail.
+    if (OCUpdater *updater = dynamic_cast<OCUpdater*>(Updater::instance())) {
+        connect(updater,  SIGNAL(newUpdateAvailable(QString,QString)),
+                this,     SIGNAL(updaterAnnouncement(QString,QString)) );
+    }
+
+    // at startup, do a check in any case.
+    QTimer::singleShot(3000, this, SLOT(slotTimerFired()));
+
+    ConfigFile cfg;
+    auto checkInterval = cfg.updateCheckInterval();
+    _updateCheckTimer.start(checkInterval);
+}
+
+void UpdaterScheduler::slotTimerFired()
+{
+    ConfigFile cfg;
+
+    // re-set the check interval if it changed in the config file meanwhile
+    auto checkInterval = cfg.updateCheckInterval();
+    if( checkInterval != _updateCheckTimer.interval() ) {
+        _updateCheckTimer.setInterval(checkInterval);
+        qDebug() << "Setting new update check interval " << checkInterval;
+    }
+
+    // consider the skipUpdateCheck flag in the config.
+    if( cfg.skipUpdateCheck() ) {
+        qDebug() << Q_FUNC_INFO << "Skipping update check because of config file";
+        return;
+    }
+
+    Updater::instance()->backgroundCheckForUpdate();
+}
+
+
+/* ----------------------------------------------------------------- */
+
 OCUpdater::OCUpdater(const QUrl &url, QObject *parent) :
     QObject(parent)
   , _updateUrl(url)
   , _state(Unknown)
   , _accessManager(new AccessManager(this))
   , _timeoutWatchdog(new QTimer(this))
-  , _updateCheckTimer(new QTimer(this))
 {
-    // at startup, do a check in any case.
-    QTimer::singleShot( 3000, this, SLOT( backgroundCheckForUpdate()));
 
-    // connect the timer to the check slot
-    connect( _updateCheckTimer, SIGNAL(timeout()), this, SLOT(backgroundCheckForUpdate()));
-    // and set the timer regular interval which is usually large, like 10 hours.
-    ConfigFile cfg;
-    auto checkInterval = cfg.updateCheckInterval();
-    qDebug() << "Setting up regular update check every " << checkInterval /1000/60 << "minutes ";
-   _updateCheckTimer->setInterval(checkInterval); // check every couple of hours as defined in config
-   _updateCheckTimer->start();
 }
 
 bool OCUpdater::performUpdate()
@@ -79,13 +113,6 @@ void OCUpdater::backgroundCheckForUpdate()
 {
     int dlState = downloadState();
 
-    ConfigFile cfg;
-
-    if( cfg.skipUpdateCheck() ) {
-        qDebug() << Q_FUNC_INFO << "Skipping update check because of config file";
-        return;
-    }
-
     // do the real update check depending on the internal state of updater.
     switch( dlState ) {
     case Unknown:
diff --git a/src/gui/updater/ocupdater.h b/src/gui/updater/ocupdater.h
index aed84f2..8425ef2 100644
--- a/src/gui/updater/ocupdater.h
+++ b/src/gui/updater/ocupdater.h
@@ -18,16 +18,67 @@
 #include <QObject>
 #include <QUrl>
 #include <QTemporaryFile>
+#include <QTimer>
 
 #include "updater/updateinfo.h"
 #include "updater/updater.h"
 
 class QNetworkAccessManager;
 class QNetworkReply;
-class QTimer;
 
 namespace OCC {
 
+/** @short Schedule update checks every couple of hours if the client runs.
+ *
+ * This class schedules regular update checks. It also checks the config
+ * if update checks are wanted at all.
+ *
+ * To reflect that all platforms have its own update scheme, a little
+ * complex class design was set up:
+ *
+ * For Windows and Linux, the updaters are inherited from OCUpdater, while
+ * the MacOSX SparkleUpdater directly uses the class Updater. On windows,
+ * NSISUpdater starts the update if a new version of the client is available.
+ * On MacOSX, the sparkle framework handles the installation of the new
+ * version. On Linux, the update capabilities by the underlying linux distro
+ * is relied on, and thus the PassiveUpdateNotifier just shows a notification
+ * if there is a new version once at every start of the application.
+ *
+ * Simple class diagram of the updater:
+ *
+ *           +---------------------------+
+ *     +-----+   UpdaterScheduler        +-----+
+ *     |     +------------+--------------+     |
+ *     v                  v                    v
+ * +------------+ +---------------------+ +----------------+
+ * |NSISUpdater | |PassiveUpdateNotifier| | SparkleUpdater |
+ * +-+----------+ +---+-----------------+ +-----+----------+
+ *   |                |                         |
+ *   |                v      +------------------+
+ *   |   +---------------+   v
+ *   +-->|   OCUpdater   +------+
+ *       +--------+------+      |
+ *                |   Updater   |
+ *                +-------------+
+ */
+
+class UpdaterScheduler : public QObject
+{
+    Q_OBJECT
+public:
+    UpdaterScheduler(QObject *parent);
+
+signals:
+    void updaterAnnouncement(const QString& title, const QString& msg);
+
+private slots:
+    void slotTimerFired();
+
+private:
+    QTimer _updateCheckTimer; /** Timer for the regular update check. */
+
+};
+
 /** @short Class that uses an ownCloud propritary XML format to fetch update information */
 class OCUpdater : public QObject, public Updater
 {
@@ -71,7 +122,6 @@ private:
     int _state;
     QNetworkAccessManager *_accessManager;
     QTimer *_timeoutWatchdog;  /** Timer to guard the timeout of an individual network request */
-    QTimer *_updateCheckTimer; /** Timer for the regular update check. */
     UpdateInfo _updateInfo;
 };
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list