[Pkg-owncloud-commits] [owncloud-client] 11/33: Fix online state handling

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu Feb 27 19:44:24 UTC 2014


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

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

commit 8e7290b450e63987473a2f041300fc3a7d4dcb76
Author: Daniel Molkentin <danimo at owncloud.com>
Date:   Thu Feb 20 17:00:45 2014 +0100

    Fix online state handling
    
    Before this commit, parts of mirall were aware of the state, but not all.
    Also, the state was not set back to Connected again in all cases. This
    commit introduces the following changes:
    
    - Make QuotaInfo a member of Account
    - QuotaInfo and Folder (EtagJob) can put the client in disconnected mode
    - FolderMan now disables etag-polling when offline
    
    Fixes #1459
    Fixes #1441
---
 src/mirall/account.cpp         |  7 +++++++
 src/mirall/account.h           |  4 ++++
 src/mirall/accountsettings.cpp |  9 ++++++++-
 src/mirall/application.cpp     | 30 ++++++++++++++++++++++++++++--
 src/mirall/application.h       |  3 ++-
 src/mirall/folder.cpp          |  5 ++++-
 src/mirall/owncloudgui.cpp     |  8 --------
 src/mirall/owncloudgui.h       |  4 ----
 src/mirall/quotainfo.cpp       | 39 ++++++++++++++++++++++++---------------
 src/mirall/quotainfo.h         |  9 +++++++--
 src/mirall/settingsdialog.cpp  |  4 ----
 11 files changed, 84 insertions(+), 38 deletions(-)

diff --git a/src/mirall/account.cpp b/src/mirall/account.cpp
index f15f848..14843f9 100644
--- a/src/mirall/account.cpp
+++ b/src/mirall/account.cpp
@@ -15,6 +15,7 @@
 #include "mirall/theme.h"
 #include "mirall/networkjobs.h"
 #include "mirall/mirallconfigfile.h"
+#include "mirall/quotainfo.h"
 #include "creds/abstractcredentials.h"
 #include "creds/credentialsfactory.h"
 
@@ -62,6 +63,7 @@ Account::Account(AbstractSslErrorHandler *sslErrorHandler, QObject *parent)
     : QObject(parent)
     , _url(Theme::instance()->overrideServerUrl())
     , _sslErrorHandler(sslErrorHandler)
+    , _quotaInfo(new QuotaInfo(this))
     , _am(0)
     , _credentials(0)
     , _treatSslErrorsAsFailure(false)
@@ -298,6 +300,11 @@ void Account::setState(int state)
     }
 }
 
+QuotaInfo *Account::quotaInfo()
+{
+    return _quotaInfo;
+}
+
 void Account::slotHandleErrors(QNetworkReply *reply , QList<QSslError> errors)
 {
     NetworkJobTimeoutPauser pauser(reply);
diff --git a/src/mirall/account.h b/src/mirall/account.h
index 6c48a31..6d8df04 100644
--- a/src/mirall/account.h
+++ b/src/mirall/account.h
@@ -32,6 +32,7 @@ namespace Mirall {
 
 class AbstractCredentials;
 class Account;
+class QuotaInfo;
 
 class AccountManager : public QObject {
     Q_OBJECT
@@ -142,6 +143,8 @@ public:
 
     int state() const;
     void setState(int state);
+
+    QuotaInfo *quotaInfo();
 signals:
     void stateChanged(int state);
 
@@ -154,6 +157,7 @@ private:
     QList<QSslCertificate> _approvedCerts;
     QSslConfiguration _sslConfiguration;
     QScopedPointer<AbstractSslErrorHandler> _sslErrorHandler;
+    QuotaInfo *_quotaInfo;
     QNetworkAccessManager *_am;
     AbstractCredentials* _credentials;
     bool _treatSslErrorsAsFailure;
diff --git a/src/mirall/accountsettings.cpp b/src/mirall/accountsettings.cpp
index f320751..03553c7 100644
--- a/src/mirall/accountsettings.cpp
+++ b/src/mirall/accountsettings.cpp
@@ -25,6 +25,7 @@
 #include "mirall/mirallconfigfile.h"
 #include "mirall/ignorelisteditor.h"
 #include "mirall/account.h"
+#include "mirall/quotainfo.h"
 #include "creds/abstractcredentials.h"
 
 #include <math.h>
@@ -106,6 +107,11 @@ AccountSettings::AccountSettings(QWidget *parent) :
         slotAccountStateChanged(_account->state());
     }
 
+    QuotaInfo *quotaInfo = _account->quotaInfo();
+    connect( quotaInfo, SIGNAL(quotaUpdated(qint64,qint64)),
+             this, SLOT(slotUpdateQuota(qint64,qint64)));
+    slotUpdateQuota(quotaInfo->lastQuotaTotalBytes(), quotaInfo->lastQuotaUsedBytes());
+
     setFolderList(FolderMan::instance()->map());
 }
 
@@ -133,6 +139,7 @@ void AccountSettings::slotFolderActivated( const QModelIndex& indx )
     } else {
       ui->_buttonEnable->setText( tr( "Resume" ) );
     }
+    ui->_buttonEnable->setEnabled(_account && _account->state() == Account::Connected);
   }
 }
 
@@ -752,7 +759,7 @@ void AccountSettings::slotAccountStateChanged(int state)
                                  /*, tr("Version: %1 (%2)").arg(versionStr).arg(version) */ );
             }
         } else {
-            showConnectionLabel( tr("No connection to %1 at <a href=\"%1\">%2</a>.")
+            showConnectionLabel( tr("No connection to %1 at <a href=\"%2\">%3</a>.")
                                  .arg(Theme::instance()->appNameGUI(),
                                       _account->url().toString(),
                                       safeUrl.toString()) );
diff --git a/src/mirall/application.cpp b/src/mirall/application.cpp
index 054fcf1..de84466 100644
--- a/src/mirall/application.cpp
+++ b/src/mirall/application.cpp
@@ -135,7 +135,7 @@ Application::Application(int &argc, char **argv) :
     }
 
     if (account) {
-        connect(account, SIGNAL(stateChanged(int)), _gui, SLOT(slotAccountStateChanged()));
+        slotAccountChanged(account);
     }
     connect(AccountManager::instance(), SIGNAL(accountChanged(Account*,Account*)),
             this, SLOT(slotAccountChanged(Account*,Account*)));
@@ -189,8 +189,16 @@ void Application::slotLogout()
 
 void Application::slotAccountChanged(Account *newAccount, Account *oldAccount)
 {
-    disconnect(oldAccount, SIGNAL(stateChanged(int)), _gui, SLOT(slotAccountStateChanged()));
+    if (oldAccount) {
+        disconnect(oldAccount, SIGNAL(stateChanged(int)), _gui, SLOT(slotAccountStateChanged()));
+        disconnect(oldAccount, SIGNAL(stateChanged(int)), this, SLOT(slotToggleFolderman(int)));
+        connect(oldAccount->quotaInfo(), SIGNAL(quotaUpdated(qint64,qint64)),
+                _gui, SLOT(slotRefreshQuotaDisplay(qint64,qint64)));
+    }
     connect(newAccount, SIGNAL(stateChanged(int)), _gui, SLOT(slotAccountStateChanged()));
+    connect(newAccount, SIGNAL(stateChanged(int)), this, SLOT(slotToggleFolderman(int)));
+    connect(newAccount->quotaInfo(), SIGNAL(quotaUpdated(qint64,qint64)),
+            _gui, SLOT(slotRefreshQuotaDisplay(qint64,qint64)));
 }
 
 
@@ -262,6 +270,24 @@ void Application::slotCredentialsFetched()
     _conValidator->checkConnection();
 }
 
+void Application::slotToggleFolderman(int state)
+{
+    FolderMan* folderMan = FolderMan::instance();
+    switch (state) {
+    case Account::Connected:
+        folderMan->setSyncEnabled(true);
+        folderMan->slotScheduleAllFolders();
+        break;
+    case Account::Disconnected:
+    case Account::SignedOut:
+    case Account::InvalidCredidential:
+        folderMan->setSyncEnabled(false);
+        folderMan->terminateSyncProcess();
+        break;
+    }
+
+}
+
 void Application::slotConnectionValidatorResult(ConnectionValidator::Status status)
 {
     qDebug() << "Connection Validator Result: " << _conValidator->statusString(status);
diff --git a/src/mirall/application.h b/src/mirall/application.h
index 6d57fe5..74698b6 100644
--- a/src/mirall/application.h
+++ b/src/mirall/application.h
@@ -76,8 +76,9 @@ protected slots:
     void slotLogin();
     void slotLogout();
     void slotCleanup();
-    void slotAccountChanged(Account *newAccount, Account *oldAccount);
+    void slotAccountChanged(Account *newAccount, Account *oldAccount = 0);
     void slotCredentialsFetched();
+    void slotToggleFolderman(int state);
 
 private:
     void setHelp();
diff --git a/src/mirall/folder.cpp b/src/mirall/folder.cpp
index 330295a..765806c 100644
--- a/src/mirall/folder.cpp
+++ b/src/mirall/folder.cpp
@@ -291,7 +291,10 @@ void Folder::etagRetreived(const QString& etag)
 
 void Folder::slotNetworkUnavailable()
 {
-    AccountManager::instance()->account()->setState(Account::Disconnected);
+    Account *account = AccountManager::instance()->account();
+    if (account && account->state() == Account::Connected) {
+        account->setState(Account::Disconnected);
+    }
     _syncResult.setStatus(SyncResult::Unavailable);
     emit syncStateChange();
 }
diff --git a/src/mirall/owncloudgui.cpp b/src/mirall/owncloudgui.cpp
index 47e07f1..8cd33d1 100644
--- a/src/mirall/owncloudgui.cpp
+++ b/src/mirall/owncloudgui.cpp
@@ -38,7 +38,6 @@ ownCloudGui::ownCloudGui(Application *parent) :
     _logBrowser(0),
     _contextMenu(0),
     _recentActionsMenu(0),
-    _quotaInfo(0),
     _folderOpenActionMapper(new QSignalMapper(this)),
     _recentItemsMapper(new QSignalMapper(this)),
     _app(parent)
@@ -98,11 +97,6 @@ void ownCloudGui::slotOpenSettingsDialog( bool openSettings )
     }
 }
 
-QuotaInfo *ownCloudGui::quotaInfo() const
-{
-    return _quotaInfo;
-}
-
 void ownCloudGui::slotTrayClicked( QSystemTrayIcon::ActivationReason reason )
 {
     // A click on the tray icon should only open the status window on Win and
@@ -363,8 +357,6 @@ void ownCloudGui::setupActions()
     _actionLogout = new QAction(tr("Sign out"), this);
     connect(_actionLogout, SIGNAL(triggered()), _app, SLOT(slotLogout()));
 
-    _quotaInfo = new QuotaInfo(this);
-    connect(_quotaInfo, SIGNAL(quotaUpdated(qint64,qint64)), SLOT(slotRefreshQuotaDisplay(qint64,qint64)));
 }
 
 void ownCloudGui::slotRefreshQuotaDisplay( qint64 total, qint64 used )
diff --git a/src/mirall/owncloudgui.h b/src/mirall/owncloudgui.h
index 074433a..8211977 100644
--- a/src/mirall/owncloudgui.h
+++ b/src/mirall/owncloudgui.h
@@ -42,8 +42,6 @@ public:
 
     bool checkAccountExists(bool openSettings);
 
-    QuotaInfo *quotaInfo() const;
-
 signals:
     void setupProxy();
 
@@ -94,8 +92,6 @@ private:
     QAction *_actionHelp;
     QAction *_actionQuit;
 
-    QuotaInfo *_quotaInfo;
-
     QSignalMapper *_folderOpenActionMapper;
     QSignalMapper *_recentItemsMapper;
 
diff --git a/src/mirall/quotainfo.cpp b/src/mirall/quotainfo.cpp
index 4e08395..70dc3b1 100644
--- a/src/mirall/quotainfo.cpp
+++ b/src/mirall/quotainfo.cpp
@@ -27,18 +27,17 @@ static const int failIntervalT = 5*1000;
 static const int initialTimeT = 1*1000;
 }
 
-QuotaInfo::QuotaInfo(QObject *parent)
-    : QObject(parent)
-    , _account(AccountManager::instance()->account())
+QuotaInfo::QuotaInfo(Account *account)
+    : QObject(account)
+    , _account(account)
     , _lastQuotaTotalBytes(0)
     , _lastQuotaUsedBytes(0)
-    , _refreshTimer(new QTimer(this))
+    , _jobRestartTimer(new QTimer(this))
 {
-    connect(AccountManager::instance(), SIGNAL(accountChanged(Account*,Account*)),
-            SLOT(slotAccountChanged(Account*,Account*)));
-    connect(_refreshTimer, SIGNAL(timeout()), SLOT(slotCheckQuota()));
-    _refreshTimer->setSingleShot(true);
-    _refreshTimer->start(initialTimeT);
+    connect(_account, SIGNAL(stateChanged(int)), SLOT(slotAccountStateChanged(int)));
+    connect(_jobRestartTimer, SIGNAL(timeout()), SLOT(slotCheckQuota()));
+    _jobRestartTimer->setSingleShot(true);
+    _jobRestartTimer->start(initialTimeT);
 }
 
 void QuotaInfo::slotAccountChanged(Account *newAccount, Account *oldAccount)
@@ -50,22 +49,32 @@ void QuotaInfo::slotAccountChanged(Account *newAccount, Account *oldAccount)
 
 void QuotaInfo::slotAccountStateChanged(int state)
 {
-    if (state == Account::Connected) {
+    switch (state) {
+    case Account::SignedOut: // fall through
+    case Account::InvalidCredidential:
+        _jobRestartTimer->stop();
+        break;
+    case Account::Connected: // fall through
+    case Account::Disconnected:
         slotCheckQuota();
-    } else {
-        _refreshTimer->stop();
     }
 }
 
 void QuotaInfo::slotRequestFailed()
 {
-    _refreshTimer->start(failIntervalT);
+    if (!_account.isNull() && _account->state() == Account::Connected) {
+        _account->setState(Account::Disconnected);
+    }
+    _jobRestartTimer->start(failIntervalT);
 }
 
 void QuotaInfo::slotCheckQuota()
 {
     if (!_account.isNull() && _account->credentials() && _account->credentials()->ready()
             && _account->state() == Account::Connected) {
+        if(_account->state() == Account::Disconnected) {
+            _account->setState(Account::Connected);
+        }
         CheckQuotaJob *job = new CheckQuotaJob(_account, "/", this);
         connect(job, SIGNAL(quotaRetrieved(qint64,qint64)), SLOT(slotUpdateLastQuota(qint64,qint64)));
         connect(job, SIGNAL(networkError(QNetworkReply*)), SLOT(slotRequestFailed()));
@@ -73,7 +82,7 @@ void QuotaInfo::slotCheckQuota()
     } else {
         _lastQuotaTotalBytes = 0;
         _lastQuotaUsedBytes = 0;
-        _refreshTimer->start(failIntervalT);
+        _jobRestartTimer->start(failIntervalT);
     }
 }
 
@@ -82,7 +91,7 @@ void QuotaInfo::slotUpdateLastQuota(qint64 total, qint64 used)
     _lastQuotaTotalBytes = total;
     _lastQuotaUsedBytes = used;
     emit quotaUpdated(total, used);
-    _refreshTimer->start(defaultIntervalT);
+    _jobRestartTimer->start(defaultIntervalT);
 }
 
 }
diff --git a/src/mirall/quotainfo.h b/src/mirall/quotainfo.h
index 25b8c06..14ccbbf 100644
--- a/src/mirall/quotainfo.h
+++ b/src/mirall/quotainfo.h
@@ -11,6 +11,9 @@
  * for more details.
  */
 
+#ifndef QUOTAINFO_H
+#define QUOTAINFO_H
+
 #include <QObject>
 #include <QPointer>
 
@@ -23,7 +26,7 @@ class Account;
 class QuotaInfo : public QObject {
     Q_OBJECT
 public:
-    QuotaInfo(QObject *parent);
+    QuotaInfo(Account *account);
 
     qint64 lastQuotaTotalBytes() const { return _lastQuotaTotalBytes; }
     qint64 lastQuotaUsedBytes() const { return _lastQuotaUsedBytes; }
@@ -44,9 +47,11 @@ private:
     QPointer<Account> _account;
     qint64 _lastQuotaTotalBytes;
     qint64 _lastQuotaUsedBytes;
-    QTimer *_refreshTimer;
+    QTimer *_jobRestartTimer;
 };
 
 
 
 } // namespace Mirall
+
+#endif //QUOTAINFO_H
diff --git a/src/mirall/settingsdialog.cpp b/src/mirall/settingsdialog.cpp
index a6ad791..7b69af5 100644
--- a/src/mirall/settingsdialog.cpp
+++ b/src/mirall/settingsdialog.cpp
@@ -78,10 +78,6 @@ SettingsDialog::SettingsDialog(ownCloudGui *gui, QWidget *parent) :
     connect( folderMan, SIGNAL(folderSyncStateChange(QString)),
              this, SLOT(slotSyncStateChange(QString)));
 
-    QuotaInfo *quotaInfo = gui->quotaInfo();
-    connect( quotaInfo, SIGNAL(quotaUpdated(qint64,qint64)),
-             _accountSettings, SLOT(slotUpdateQuota(qint64,qint64)));
-    _accountSettings->slotUpdateQuota(quotaInfo->lastQuotaTotalBytes(), quotaInfo->lastQuotaUsedBytes());
     connect( _accountSettings, SIGNAL(folderChanged()), gui, SLOT(slotFoldersChanged()));
     connect( _accountSettings, SIGNAL(openFolderAlias(const QString&)),
              gui, SLOT(slotFolderOpenAction(QString)));

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