[Pkg-owncloud-commits] [owncloud-client] 14/484: Show a notification instead of a login window on startup #3350

Sandro Knauß hefee-guest at moszumanska.debian.org
Wed Dec 16 00:37:03 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 dcb687929f1323e9fea8a9e4bd48cdd3fa8312d9
Author: Jocelyn Turcotte <jturcotte at woboq.com>
Date:   Tue Sep 1 15:37:58 2015 +0200

    Show a notification instead of a login window on startup #3350
    
    The original problem is that showing a popup not originated
    from the main settings window while it's focused won't be
    shown in front to the user.
    
    This try not to highjack the user's attention of the user
    by showing a notification when checking the connection for
    valid credentials, and require the user to sign in through
    the UI. There are still issues with showing that popup from
    the tray icon, but the user will most likely be looking for
    the popup in that case. The new sign in button directly in
    the settings account works properly.
---
 src/gui/accountstate.cpp                | 11 +++++++----
 src/gui/accountstate.h                  |  2 +-
 src/gui/application.cpp                 |  2 +-
 src/gui/creds/shibbolethcredentials.cpp | 12 ++++++++++--
 src/gui/creds/shibbolethcredentials.h   |  3 ++-
 src/libsync/connectionvalidator.cpp     |  5 +++--
 src/libsync/connectionvalidator.h       |  4 +++-
 src/libsync/creds/abstractcredentials.h |  3 ++-
 src/libsync/creds/dummycredentials.cpp  |  2 +-
 src/libsync/creds/dummycredentials.h    |  2 +-
 src/libsync/creds/httpcredentials.cpp   | 18 +++++++++++++-----
 src/libsync/creds/httpcredentials.h     |  3 ++-
 src/libsync/creds/tokencredentials.cpp  |  2 +-
 src/libsync/creds/tokencredentials.h    |  2 +-
 14 files changed, 48 insertions(+), 23 deletions(-)

diff --git a/src/gui/accountstate.cpp b/src/gui/accountstate.cpp
index 7631412..70d5d20 100644
--- a/src/gui/accountstate.cpp
+++ b/src/gui/accountstate.cpp
@@ -79,7 +79,7 @@ void AccountState::setState(State state)
             _connectionStatus = ConnectionValidator::Undefined;
             _connectionErrors.clear();
         } else if (oldState == SignedOut && _state == Disconnected) {
-            checkConnectivity();
+            checkConnectivity(AbstractCredentials::Interactive);
         }
     }
 
@@ -131,7 +131,7 @@ bool AccountState::isConnectedOrTemporarilyUnavailable() const
     return isConnected() || _state == ServiceUnavailable;
 }
 
-void AccountState::checkConnectivity()
+void AccountState::checkConnectivity(AbstractCredentials::FetchMode credentialsFetchMode)
 {
     if (isSignedOut() || _waitingForNewCredentials) {
         return;
@@ -141,7 +141,7 @@ void AccountState::checkConnectivity()
         qDebug() << "ConnectionValidator already running, ignoring";
         return;
     }
-    ConnectionValidator * conValidator = new ConnectionValidator(account());
+    ConnectionValidator * conValidator = new ConnectionValidator(account(), credentialsFetchMode);
     _connectionValidator = conValidator;
     connect(conValidator, SIGNAL(connectionResult(ConnectionValidator::Status,QStringList)),
             SLOT(slotConnectionValidatorResult(ConnectionValidator::Status,QStringList)));
@@ -243,7 +243,10 @@ void AccountState::slotCredentialsFetched(AbstractCredentials* credentials)
         delete _connectionValidator;
     }
 
-    checkConnectivity();
+    // If we made it this far, it means that we either fetched credentials
+    // interactively, or that we already aborted for missing/invalid credentials.
+    Q_ASSERT(credentials->ready());
+    checkConnectivity(AbstractCredentials::Interactive);
 }
 
 std::unique_ptr<QSettings> AccountState::settings()
diff --git a/src/gui/accountstate.h b/src/gui/accountstate.h
index f56364e..7280334 100644
--- a/src/gui/accountstate.h
+++ b/src/gui/accountstate.h
@@ -84,7 +84,7 @@ public:
 
     /// Triggers a ping to the server to update state and
     /// connection status and errors.
-    void checkConnectivity();
+    void checkConnectivity(AbstractCredentials::FetchMode credentialsFetchMode);
 
     /** Returns a new settings object for this account, already in the right groups. */
     std::unique_ptr<QSettings> settings();
diff --git a/src/gui/application.cpp b/src/gui/application.cpp
index 7810267..0b2460b 100644
--- a/src/gui/application.cpp
+++ b/src/gui/application.cpp
@@ -223,7 +223,7 @@ void Application::slotCheckConnection()
         // when the error is permanent.
         if (state != AccountState::SignedOut
                 && state != AccountState::ConfigurationError) {
-            accountState->checkConnectivity();
+            accountState->checkConnectivity(AbstractCredentials::NonInteractive);
         }
     }
 
diff --git a/src/gui/creds/shibbolethcredentials.cpp b/src/gui/creds/shibbolethcredentials.cpp
index 9a98111..c65f71b 100644
--- a/src/gui/creds/shibbolethcredentials.cpp
+++ b/src/gui/creds/shibbolethcredentials.cpp
@@ -28,6 +28,7 @@
 
 #include "accessmanager.h"
 #include "account.h"
+#include "logger.h"
 #include "theme.h"
 #include "cookiejar.h"
 #include "syncengine.h"
@@ -94,6 +95,7 @@ ShibbolethCredentials::ShibbolethCredentials(const QNetworkCookie& cookie)
   : _ready(true),
     _stillValid(true),
     _fetchJobInProgress(false),
+    _interactiveFetch(true),
     _browser(0),
     _shibCookie(cookie)
 {
@@ -191,11 +193,12 @@ bool ShibbolethCredentials::ready() const
     return _ready;
 }
 
-void ShibbolethCredentials::fetch()
+void ShibbolethCredentials::fetch(FetchMode mode)
 {
     if(_fetchJobInProgress) {
         return;
     }
+    _interactiveFetch = mode == Interactive;
 
     if (_user.isEmpty()) {
         _user = _account->credentialSetting(QLatin1String(userC)).toString();
@@ -357,8 +360,13 @@ void ShibbolethCredentials::slotReadJobDone(QKeychain::Job *job)
         _stillValid = true;
         _fetchJobInProgress = false;
         Q_EMIT fetched();
-    } else {
+    } else if (_interactiveFetch) {
         showLoginWindow();
+    } else {
+        Logger::instance()->postOptionalGuiLog(tr("Reauthentication required"), tr("You need to re-login to continue using the account %1.").arg(_account->displayName()));
+        _ready = false;
+        _fetchJobInProgress = false;
+        Q_EMIT fetched();
     }
 }
 
diff --git a/src/gui/creds/shibbolethcredentials.h b/src/gui/creds/shibbolethcredentials.h
index a4e2663..4248038 100644
--- a/src/gui/creds/shibbolethcredentials.h
+++ b/src/gui/creds/shibbolethcredentials.h
@@ -55,7 +55,7 @@ public:
     QString user() const Q_DECL_OVERRIDE;
     QNetworkAccessManager* getQNAM() const Q_DECL_OVERRIDE;
     bool ready() const Q_DECL_OVERRIDE;
-    void fetch() Q_DECL_OVERRIDE;
+    void fetch(FetchMode mode = Interactive) Q_DECL_OVERRIDE;
     bool stillValid(QNetworkReply *reply) Q_DECL_OVERRIDE;
     void persist() Q_DECL_OVERRIDE;
     void invalidateToken() Q_DECL_OVERRIDE;
@@ -94,6 +94,7 @@ private:
     bool _ready;
     bool _stillValid;
     bool _fetchJobInProgress;
+    bool _interactiveFetch;
     QPointer<ShibbolethWebView> _browser;
     QNetworkCookie _shibCookie;
     QString _user;
diff --git a/src/libsync/connectionvalidator.cpp b/src/libsync/connectionvalidator.cpp
index 80be8f8..bcc285c 100644
--- a/src/libsync/connectionvalidator.cpp
+++ b/src/libsync/connectionvalidator.cpp
@@ -23,9 +23,10 @@
 
 namespace OCC {
 
-ConnectionValidator::ConnectionValidator(AccountPtr account, QObject *parent)
+ConnectionValidator::ConnectionValidator(AccountPtr account, AbstractCredentials::FetchMode credentialsFetchMode, QObject *parent)
     : QObject(parent),
       _account(account),
+      _credentialsFetchMode(credentialsFetchMode),
       _isCheckingServerAndAuth(false)
 {
 }
@@ -128,7 +129,7 @@ void ConnectionValidator::slotStatusFound(const QUrl&url, const QVariantMap &inf
         // We can't proceed with the auth check because we don't have credentials.
         // Fetch them now! Once fetched, a new connectivity check will be
         // initiated anyway.
-        creds->fetch();
+        creds->fetch(_credentialsFetchMode);
 
         // no result is reported
         deleteLater();
diff --git a/src/libsync/connectionvalidator.h b/src/libsync/connectionvalidator.h
index a80d56f..f723831 100644
--- a/src/libsync/connectionvalidator.h
+++ b/src/libsync/connectionvalidator.h
@@ -20,6 +20,7 @@
 #include <QVariantMap>
 #include <QNetworkReply>
 #include "accountfwd.h"
+#include "creds/abstractcredentials.h"
 
 namespace OCC {
 
@@ -68,7 +69,7 @@ class OWNCLOUDSYNC_EXPORT ConnectionValidator : public QObject
 {
     Q_OBJECT
 public:
-    explicit ConnectionValidator(AccountPtr account, QObject *parent = 0);
+    explicit ConnectionValidator(AccountPtr account, AbstractCredentials::FetchMode credentialsFetchMode, QObject *parent = 0);
 
     enum Status {
         Undefined,
@@ -114,6 +115,7 @@ private:
 
     QStringList _errors;
     AccountPtr   _account;
+    AbstractCredentials::FetchMode _credentialsFetchMode;
     bool _isCheckingServerAndAuth;
 };
 
diff --git a/src/libsync/creds/abstractcredentials.h b/src/libsync/creds/abstractcredentials.h
index 2338132..658f4f4 100644
--- a/src/libsync/creds/abstractcredentials.h
+++ b/src/libsync/creds/abstractcredentials.h
@@ -30,6 +30,7 @@ class OWNCLOUDSYNC_EXPORT AbstractCredentials : public QObject
     Q_OBJECT
 
 public:
+    enum FetchMode { Interactive, NonInteractive };
     AbstractCredentials();
     // No need for virtual destructor - QObject already has one.
 
@@ -48,7 +49,7 @@ public:
     virtual QString user() const = 0;
     virtual QNetworkAccessManager* getQNAM() const = 0;
     virtual bool ready() const = 0;
-    virtual void fetch() = 0;
+    virtual void fetch(FetchMode mode = Interactive) = 0;
     virtual bool stillValid(QNetworkReply *reply) = 0;
     virtual void persist() = 0;
     /** Invalidates auth token, or password for basic auth */
diff --git a/src/libsync/creds/dummycredentials.cpp b/src/libsync/creds/dummycredentials.cpp
index 56257fa..3dbfaa0 100644
--- a/src/libsync/creds/dummycredentials.cpp
+++ b/src/libsync/creds/dummycredentials.cpp
@@ -56,7 +56,7 @@ bool DummyCredentials::stillValid(QNetworkReply *reply)
     return true;
 }
 
-void DummyCredentials::fetch()
+void DummyCredentials::fetch(FetchMode)
 {
     Q_EMIT(fetched());
 }
diff --git a/src/libsync/creds/dummycredentials.h b/src/libsync/creds/dummycredentials.h
index 315e696..8536d20 100644
--- a/src/libsync/creds/dummycredentials.h
+++ b/src/libsync/creds/dummycredentials.h
@@ -35,7 +35,7 @@ public:
     QNetworkAccessManager* getQNAM() const Q_DECL_OVERRIDE;
     bool ready() const Q_DECL_OVERRIDE;
     bool stillValid(QNetworkReply *reply) Q_DECL_OVERRIDE;
-    void fetch() Q_DECL_OVERRIDE;
+    void fetch(FetchMode mode = Interactive) Q_DECL_OVERRIDE;
     void persist() Q_DECL_OVERRIDE;
     void invalidateToken() Q_DECL_OVERRIDE {}
 };
diff --git a/src/libsync/creds/httpcredentials.cpp b/src/libsync/creds/httpcredentials.cpp
index 32c4745..8ce1af2 100644
--- a/src/libsync/creds/httpcredentials.cpp
+++ b/src/libsync/creds/httpcredentials.cpp
@@ -24,6 +24,7 @@
 
 #include "account.h"
 #include "accessmanager.h"
+#include "logger.h"
 #include "utility.h"
 #include "theme.h"
 #include "syncengine.h"
@@ -87,7 +88,8 @@ HttpCredentials::HttpCredentials()
       _certificatePath(),
       _certificatePasswd(),
       _ready(false),
-      _fetchJobInProgress(false)
+      _fetchJobInProgress(false),
+      _interactiveFetch(true)
 {
 }
 
@@ -97,7 +99,8 @@ HttpCredentials::HttpCredentials(const QString& user, const QString& password, c
       _certificatePath(certificatePath),
       _certificatePasswd(certificatePasswd),
       _ready(true),
-      _fetchJobInProgress(false)
+      _fetchJobInProgress(false),
+      _interactiveFetch(true)
 {
 }
 
@@ -199,11 +202,12 @@ QString HttpCredentials::fetchUser()
     return _user;
 }
 
-void HttpCredentials::fetch()
+void HttpCredentials::fetch(FetchMode mode)
 {
     if (_fetchJobInProgress) {
         return;
     }
+    _interactiveFetch = mode == Interactive;
 
     // User must be fetched from config file
     fetchUser();
@@ -274,8 +278,12 @@ void HttpCredentials::slotReadJobDone(QKeychain::Job *job)
                     job->errorString());
         }
 
-        bool ok;
-        QString pwd = queryPassword(&ok, hint);
+        bool ok = false;
+        QString pwd;
+        if (_interactiveFetch)
+            pwd = queryPassword(&ok, hint);
+        else
+            Logger::instance()->postOptionalGuiLog(tr("Reauthentication required"), tr("You need to re-login to continue using the account %1.").arg(_account->displayName()));
         _fetchJobInProgress = false;
         if (ok) {
             _password = pwd;
diff --git a/src/libsync/creds/httpcredentials.h b/src/libsync/creds/httpcredentials.h
index 14674a9..685502d 100644
--- a/src/libsync/creds/httpcredentials.h
+++ b/src/libsync/creds/httpcredentials.h
@@ -44,7 +44,7 @@ public:
     QString authType() const Q_DECL_OVERRIDE;
     QNetworkAccessManager* getQNAM() const Q_DECL_OVERRIDE;
     bool ready() const Q_DECL_OVERRIDE;
-    void fetch() Q_DECL_OVERRIDE;
+    void fetch(FetchMode mode = Interactive) Q_DECL_OVERRIDE;
     bool stillValid(QNetworkReply *reply) Q_DECL_OVERRIDE;
     void persist() Q_DECL_OVERRIDE;
     QString user() const Q_DECL_OVERRIDE;
@@ -74,6 +74,7 @@ private:
     QString _certificatePasswd;
     bool _ready;
     bool _fetchJobInProgress; //True if the keychain job is in progress or the input dialog visible
+    bool _interactiveFetch;
 };
 
 } // namespace OCC
diff --git a/src/libsync/creds/tokencredentials.cpp b/src/libsync/creds/tokencredentials.cpp
index eee692a..5e4896d 100644
--- a/src/libsync/creds/tokencredentials.cpp
+++ b/src/libsync/creds/tokencredentials.cpp
@@ -166,7 +166,7 @@ bool TokenCredentials::ready() const
     return _ready;
 }
 
-void TokenCredentials::fetch()
+void TokenCredentials::fetch(FetchMode)
 {
     Q_EMIT fetched();
 }
diff --git a/src/libsync/creds/tokencredentials.h b/src/libsync/creds/tokencredentials.h
index de3fe0e..3e5d1df 100644
--- a/src/libsync/creds/tokencredentials.h
+++ b/src/libsync/creds/tokencredentials.h
@@ -46,7 +46,7 @@ public:
     QString authType() const Q_DECL_OVERRIDE;
     QNetworkAccessManager* getQNAM() const Q_DECL_OVERRIDE;
     bool ready() const Q_DECL_OVERRIDE;
-    void fetch() Q_DECL_OVERRIDE;
+    void fetch(FetchMode mode = Interactive) Q_DECL_OVERRIDE;
     bool stillValid(QNetworkReply *reply) Q_DECL_OVERRIDE;
     void persist() Q_DECL_OVERRIDE;
     QString user() const Q_DECL_OVERRIDE;

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