[Pkg-owncloud-commits] [owncloud-client] 230/333: Use QTimer as object member rather than pointer based.

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu Apr 17 23:16:57 UTC 2014


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 11bbad79e28eadcf57cfd90b6cec549ea26e999e
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Tue Mar 25 10:58:57 2014 +0100

    Use QTimer as object member rather than pointer based.
    
    Avoid crashes if timer is zero.
---
 src/mirall/networkjobs.cpp | 25 ++++++++++++-------------
 src/mirall/networkjobs.h   |  4 ++--
 2 files changed, 14 insertions(+), 15 deletions(-)

diff --git a/src/mirall/networkjobs.cpp b/src/mirall/networkjobs.cpp
index bd17f17..9b6f5b5 100644
--- a/src/mirall/networkjobs.cpp
+++ b/src/mirall/networkjobs.cpp
@@ -46,8 +46,10 @@ AbstractNetworkJob::AbstractNetworkJob(Account *account, const QString &path, QO
     , _reply(0)
     , _account(account)
     , _path(path)
-    , _timer(0)
 {
+    _timer.setSingleShot(true);
+    _timer.setInterval(10*1000); // default to 10 seconds.
+    connect(&_timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));
 }
 
 void AbstractNetworkJob::setReply(QNetworkReply *reply)
@@ -61,21 +63,15 @@ void AbstractNetworkJob::setReply(QNetworkReply *reply)
 void AbstractNetworkJob::setTimeout(qint64 msec)
 {
     qDebug() << Q_FUNC_INFO << msec;
-    if (_timer)
-        _timer->deleteLater();
-    _timer = new QTimer(this);
-    _timer->setSingleShot(true);
-    connect(_timer, SIGNAL(timeout()), this, SLOT(slotTimeout()));
-    _timer->start(msec);
+
+    _timer.start(msec);
 }
 
 void AbstractNetworkJob::resetTimeout()
 {
-    if( _timer ) {
-        qint64 interval = _timer->interval();
-        _timer->stop();
-        _timer->start(interval);
-    }
+    qint64 interval = _timer.interval();
+    _timer.stop();
+    _timer.start(interval);
 }
 
 void AbstractNetworkJob::setIgnoreCredentialFailure(bool ignore)
@@ -100,7 +96,7 @@ void AbstractNetworkJob::setupConnections(QNetworkReply *reply)
 
 QNetworkReply* AbstractNetworkJob::addTimer(QNetworkReply *reply)
 {
-    reply->setProperty("timer", QVariant::fromValue(_timer));
+    reply->setProperty("timer", QVariant::fromValue(&_timer));
     return reply;
 }
 
@@ -169,6 +165,9 @@ AbstractNetworkJob::~AbstractNetworkJob() {
 
 void AbstractNetworkJob::start()
 {
+    _timer.start();
+    _durationTimer.start();
+
     qDebug() << "!!!" << metaObject()->className() << "created for" << account()->url() << "querying" << path();
 }
 
diff --git a/src/mirall/networkjobs.h b/src/mirall/networkjobs.h
index 90394e0..9ca4157 100644
--- a/src/mirall/networkjobs.h
+++ b/src/mirall/networkjobs.h
@@ -20,9 +20,9 @@
 #include <QNetworkRequest>
 #include <QNetworkReply>
 #include <QPointer>
+#include <QTimer>
 
 class QUrl;
-class QTimer;
 
 namespace Mirall {
 
@@ -94,7 +94,7 @@ private:
     QNetworkReply *_reply;
     Account *_account;
     QString _path;
-    QTimer *_timer;
+    QTimer _timer;
 };
 
 /**

-- 
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