[Pkg-owncloud-commits] [owncloud-client] 365/498: UpdateCheck: Clean up Application class and move most to updater.
Sandro Knauß
hefee-guest at moszumanska.debian.org
Tue Aug 11 14:49:07 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 adc239c9d05f5c91d74cb52ad55b8fa220f19435
Author: Klaas Freitag <freitag at owncloud.com>
Date: Mon Jul 20 12:10:54 2015 +0200
UpdateCheck: Clean up Application class and move most to updater.
Add the update timer also to the update class and remove all the
proxy slots from the Application class.
---
src/gui/application.cpp | 39 ++++++-------------------------
src/gui/application.h | 3 ---
src/gui/updater/ocupdater.cpp | 54 +++++++++++++++++++++++++++++++++----------
src/gui/updater/ocupdater.h | 7 ++++--
src/gui/updater/updater.cpp | 1 +
5 files changed, 55 insertions(+), 49 deletions(-)
diff --git a/src/gui/application.cpp b/src/gui/application.cpp
index c6b0371..1d27319 100644
--- a/src/gui/application.cpp
+++ b/src/gui/application.cpp
@@ -178,11 +178,14 @@ Application::Application(int &argc, char **argv) :
QTimer::singleShot( 0, this, SLOT( slotCheckConnection() ));
// Update checks
- _updaterTimer.setInterval(cfg.updateCheckInterval()); // check every couple of hours as defined in config
-
- connect(&_updaterTimer, SIGNAL(timeout()), this, SLOT(slotStartUpdateDetector()));
- QTimer::singleShot( 3000, this, SLOT( slotStartUpdateDetector() ));
+ if (OCUpdater *updater = dynamic_cast<OCUpdater*>(Updater::instance())) {
+ connect(updater, SIGNAL(downloadStateChanged()),
+ this, SLOT(slotNotifyAboutAvailableUpdate()), Qt::UniqueConnection);
+ connect(updater, SIGNAL(newUpdateAvailable(QString,QString)),
+ _gui, SLOT(slotShowTrayMessage(QString,QString)) );
+ }
+ // Cleanup at Quit.
connect (this, SIGNAL(aboutToQuit()), SLOT(slotCleanup()));
}
@@ -249,34 +252,6 @@ void Application::slotCleanup()
_gui->deleteLater();
}
-void Application::slotStartUpdateDetector()
-{
- ConfigFile cfg;
-
- if( cfg.skipUpdateCheck() ) {
- qDebug() << Q_FUNC_INFO << "Skipping update check because of config file";
- } else {
- if (OCUpdater *updater = dynamic_cast<OCUpdater*>(Updater::instance())) {
- connect(updater, SIGNAL(downloadStateChanged()), this,
- SLOT(slotNotifyAboutAvailableUpdate()), Qt::UniqueConnection);
-
- updater->backgroundCheckForUpdate();
- }
- }
-}
-
-void Application::slotNotifyAboutAvailableUpdate()
-{
- if( _gui ) {
- if (OCUpdater *updater = dynamic_cast<OCUpdater*>(Updater::instance())) {
- // Show a tray message if an Update is ready...
- if( updater->downloadState() == OCUpdater::DownloadComplete ) {
- _gui->slotShowTrayMessage( tr("Update Check"), updater->statusString() );
- }
- }
- }
-}
-
void Application::slotCheckConnection()
{
AccountState *accountState = AccountStateManager::instance()->accountState();
diff --git a/src/gui/application.h b/src/gui/application.h
index 4f596d8..c66bf8c 100644
--- a/src/gui/application.h
+++ b/src/gui/application.h
@@ -75,7 +75,6 @@ protected slots:
void slotParseMessage(const QString&, QObject*);
void slotCheckConnection();
void slotUpdateConnectionErrors(int accountState);
- void slotStartUpdateDetector();
void slotUseMonoIconsChanged( bool );
void slotLogin();
void slotLogout();
@@ -84,7 +83,6 @@ protected slots:
void slotAccountStateRemoved(AccountState *accountState);
void slotAccountStateChanged(int state);
void slotCrash();
- void slotNotifyAboutAvailableUpdate();
private:
void setHelp();
@@ -108,7 +106,6 @@ private:
ClientProxy _proxy;
QTimer _checkConnectionTimer;
- QTimer _updaterTimer;
#if defined(WITH_CRASHREPORTER)
QScopedPointer<CrashReporter::Handler> _crashHandler;
diff --git a/src/gui/updater/ocupdater.cpp b/src/gui/updater/ocupdater.cpp
index fe40801..35b9c6b 100644
--- a/src/gui/updater/ocupdater.cpp
+++ b/src/gui/updater/ocupdater.cpp
@@ -42,8 +42,19 @@ OCUpdater::OCUpdater(const QUrl &url, QObject *parent) :
, _updateUrl(url)
, _state(Unknown)
, _accessManager(new AccessManager(this))
- , _timer(new QTimer(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 << "seconds";
+ _updateCheckTimer->setInterval(checkInterval); // check every couple of hours as defined in config
}
bool OCUpdater::performUpdate()
@@ -67,14 +78,29 @@ void OCUpdater::backgroundCheckForUpdate()
{
int dlState = downloadState();
- if( dlState == Unknown ||
- dlState == UpToDate ||
- /* dlState == DownloadComplete || <- are we checking if a previous download was successful already? */
- dlState == DownloadFailed ||
- dlState == DownloadTimedOut ) {
- // how about UpdateOnlyAvailableThroughSystem?
- checkForUpdate();
- }
+ 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:
+ case UpToDate:
+ case DownloadFailed:
+ case DownloadTimedOut:
+ qDebug() << Q_FUNC_INFO << "checking for available update";
+ checkForUpdate();
+ break;
+ case DownloadComplete:
+ qDebug() << "Update is downloaded, skip new check.";
+ break;
+ case UpdateOnlyAvailableThroughSystem:
+ qDebug() << "Update is only available through system, skip check.";
+ break;
+ }
}
QString OCUpdater::statusString() const
@@ -112,6 +138,10 @@ void OCUpdater::setDownloadState(DownloadState state)
{
_state = state;
emit downloadStateChanged();
+
+ if( _state == OCUpdater::DownloadComplete ) {
+ emit newUpdateAvailable(tr("Update Check"), statusString() );
+ }
}
void OCUpdater::slotStartInstaller()
@@ -128,8 +158,8 @@ void OCUpdater::slotStartInstaller()
void OCUpdater::checkForUpdate()
{
QNetworkReply *reply = _accessManager->get(QNetworkRequest(_updateUrl));
- connect(_timer, SIGNAL(timeout()), this, SLOT(slotTimedOut()));
- _timer->start(30*1000);
+ connect(_timeoutWatchdog, SIGNAL(timeout()), this, SLOT(slotTimedOut()));
+ _timeoutWatchdog->start(30*1000);
connect(reply, SIGNAL(finished()), this, SLOT(slotVersionInfoArrived()));
setDownloadState(CheckingServer);
@@ -152,7 +182,7 @@ bool OCUpdater::updateSucceeded() const
void OCUpdater::slotVersionInfoArrived()
{
- _timer->stop();
+ _timeoutWatchdog->stop();
QNetworkReply *reply = qobject_cast<QNetworkReply*>(sender());
if( reply->error() != QNetworkReply::NoError ) {
qDebug() << "Failed to reach version check url: " << reply->errorString();
diff --git a/src/gui/updater/ocupdater.h b/src/gui/updater/ocupdater.h
index 9843a30..aed84f2 100644
--- a/src/gui/updater/ocupdater.h
+++ b/src/gui/updater/ocupdater.h
@@ -42,7 +42,6 @@ public:
bool performUpdate();
void checkForUpdate() Q_DECL_OVERRIDE;
- void backgroundCheckForUpdate() Q_DECL_OVERRIDE;
QString statusString() const;
int downloadState() const;
@@ -50,11 +49,14 @@ public:
signals:
void downloadStateChanged();
+ void newUpdateAvailable(const QString& header, const QString& message);
public slots:
void slotStartInstaller();
private slots:
+ void backgroundCheckForUpdate() Q_DECL_OVERRIDE;
+
void slotOpenUpdateUrl();
void slotVersionInfoArrived();
void slotTimedOut();
@@ -68,7 +70,8 @@ private:
QUrl _updateUrl;
int _state;
QNetworkAccessManager *_accessManager;
- QTimer *_timer;
+ QTimer *_timeoutWatchdog; /** Timer to guard the timeout of an individual network request */
+ QTimer *_updateCheckTimer; /** Timer for the regular update check. */
UpdateInfo _updateInfo;
};
diff --git a/src/gui/updater/updater.cpp b/src/gui/updater/updater.cpp
index f530191..d9d0a66 100644
--- a/src/gui/updater/updater.cpp
+++ b/src/gui/updater/updater.cpp
@@ -96,6 +96,7 @@ Updater *Updater::create()
#else
return new PassiveUpdateNotifier(QUrl(updateBaseUrl));
#endif
+
}
--
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