Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/owncloud/client.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Molkentin <danimo@owncloud.com>2013-11-23 03:14:02 +0400
committerDaniel Molkentin <danimo@owncloud.com>2013-11-25 18:34:16 +0400
commit4e22fff42709bfdf3b1dfd2b749acb79d3f757af (patch)
tree25bf54046ce6887df0001043c95c685b5f8bd1f3
parent6165c38289482bfd331018f2478bf7d03f0350d3 (diff)
Introduce online/offline state, accessible via GUI
-rw-r--r--src/creds/dummycredentials.h1
-rw-r--r--src/creds/httpcredentials.cpp18
-rw-r--r--src/creds/httpcredentials.h1
-rw-r--r--src/creds/shibbolethcredentials.cpp8
-rw-r--r--src/creds/shibbolethcredentials.h1
-rw-r--r--src/mirall/account.cpp2
-rw-r--r--src/mirall/application.cpp40
-rw-r--r--src/mirall/application.h4
-rw-r--r--src/mirall/connectionvalidator.cpp3
-rw-r--r--src/mirall/networkjobs.cpp6
-rw-r--r--src/mirall/owncloudgui.cpp52
-rw-r--r--src/mirall/owncloudgui.h4
12 files changed, 122 insertions, 18 deletions
diff --git a/src/creds/dummycredentials.h b/src/creds/dummycredentials.h
index 053996eb6..7c883ced4 100644
--- a/src/creds/dummycredentials.h
+++ b/src/creds/dummycredentials.h
@@ -35,6 +35,7 @@ public:
bool fetchFromUser(Account *account);
void fetch(Account*);
void persist(Account*);
+ void invalidateToken(Account *) {}
};
} // ns Mirall
diff --git a/src/creds/httpcredentials.cpp b/src/creds/httpcredentials.cpp
index 12208bbb7..8fc9cf11b 100644
--- a/src/creds/httpcredentials.cpp
+++ b/src/creds/httpcredentials.cpp
@@ -187,7 +187,9 @@ void HttpCredentials::fetch(Account *account)
}
bool HttpCredentials::stillValid(QNetworkReply *reply)
{
- return (reply->error() != QNetworkReply::AuthenticationRequiredError);
+ return ((reply->error() != QNetworkReply::AuthenticationRequiredError)
+ // returned if user or password is incorrect
+ && (reply->error() != QNetworkReply::OperationCanceledError));
}
bool HttpCredentials::fetchFromUser(Account *account)
@@ -230,16 +232,28 @@ void HttpCredentials::slotReadJobDone(QKeychain::Job *job)
QString HttpCredentials::queryPassword(bool *ok)
{
+ qDebug() << AccountManager::instance()->account()->isOnline();
if (ok) {
- return QInputDialog::getText(0, tr("Enter Password"),
+ QString str = QInputDialog::getText(0, tr("Enter Password"),
tr("Please enter %1 password for user '%2':")
.arg(Theme::instance()->appNameGUI(), _user),
QLineEdit::Password, QString(), ok);
+ qDebug() << AccountManager::instance()->account()->isOnline();
+ return str;
} else {
return QString();
}
}
+void HttpCredentials::invalidateToken(Account *account)
+{
+ _password = QString();
+ DeletePasswordJob *job = new DeletePasswordJob(Theme::instance()->appName());
+ job->setKey(keychainKey(account->url().toString(), _user));
+ job->start();
+ _ready = false;
+}
+
void HttpCredentials::persist(Account *account)
{
account->setCredentialSetting(QLatin1String(userC), _user);
diff --git a/src/creds/httpcredentials.h b/src/creds/httpcredentials.h
index 4f6fa25ad..3c8b53103 100644
--- a/src/creds/httpcredentials.h
+++ b/src/creds/httpcredentials.h
@@ -51,6 +51,7 @@ public:
QString user() const;
QString password() const;
QString queryPassword(bool *ok);
+ void invalidateToken(Account *account);
private Q_SLOTS:
void slotAuthentication(QNetworkReply*, QAuthenticator*);
diff --git a/src/creds/shibbolethcredentials.cpp b/src/creds/shibbolethcredentials.cpp
index 975d1489b..051361e00 100644
--- a/src/creds/shibbolethcredentials.cpp
+++ b/src/creds/shibbolethcredentials.cpp
@@ -211,6 +211,14 @@ void ShibbolethCredentials::persist(Account* /*account*/)
cfg.storeCookies(_otherCookies);
}
+void ShibbolethCredentials::invalidateToken(Account *account)
+{
+ Q_UNUSED(account)
+ _shibCookie.setValue("");
+ // ### access to ctx missing, but might not be required at all
+ //csync_set_module_property(ctx, "session_key", "");
+}
+
void ShibbolethCredentials::disposeBrowser()
{
disconnect(_browser, SIGNAL(viewHidden()),
diff --git a/src/creds/shibbolethcredentials.h b/src/creds/shibbolethcredentials.h
index e7f9a4033..6f53925e5 100644
--- a/src/creds/shibbolethcredentials.h
+++ b/src/creds/shibbolethcredentials.h
@@ -45,6 +45,7 @@ public:
bool stillValid(QNetworkReply *reply);
virtual bool fetchFromUser(Account *account);
void persist(Account *account);
+ void invalidateToken(Account *account);
QNetworkCookie cookie() const;
diff --git a/src/mirall/account.cpp b/src/mirall/account.cpp
index fb6acf8d0..a469b2d0d 100644
--- a/src/mirall/account.cpp
+++ b/src/mirall/account.cpp
@@ -293,9 +293,9 @@ bool Account::isOnline() const
void Account::setOnline(bool online)
{
if (_isOnline != online) {
+ _isOnline = online;
emit onlineStateChanged(online);
}
- _isOnline = online;
}
void Account::slotHandleErrors(QNetworkReply *reply , QList<QSslError> errors)
diff --git a/src/mirall/application.cpp b/src/mirall/application.cpp
index e5efde42b..5cccc1439 100644
--- a/src/mirall/application.cpp
+++ b/src/mirall/application.cpp
@@ -124,6 +124,11 @@ Application::Application(int &argc, char **argv) :
_gui->slotToggleLogBrowser(); // _showLogWindow is set in parseOptions.
}
connect( _gui, SIGNAL(setupProxy()), SLOT(slotSetupProxy()));
+ if (account) {
+ connect(account, SIGNAL(onlineStateChanged(bool)), _gui, SLOT(slotOnlineStateChanged()));
+ }
+ connect(AccountManager::instance(), SIGNAL(accountChanged(Account*,Account*)),
+ this, SLOT(slotAccountChanged(Account*,Account*)));
// startup procedure.
QTimer::singleShot( 0, this, SLOT( slotCheckConnection() ));
@@ -135,6 +140,7 @@ Application::Application(int &argc, char **argv) :
connect (this, SIGNAL(aboutToQuit()), SLOT(slotCleanup()));
_socketApi = new SocketApi(this, cfg.configPathWithAppName().append(QLatin1String("socket")));
+
}
Application::~Application()
@@ -142,6 +148,40 @@ Application::~Application()
// qDebug() << "* Mirall shutdown";
}
+void Application::slotLogin()
+{
+ Account *a = AccountManager::instance()->account();
+ if (a) {
+ FolderMan::instance()->setupFolders();
+ slotCheckConnection();
+ }
+}
+
+void Application::slotLogout()
+{
+ Account *a = AccountManager::instance()->account();
+ if (a) {
+ // invalidate & forget token/password
+ a->credentials()->invalidateToken(a);
+ // terminate all syncs and unload folders
+ FolderMan *folderMan = FolderMan::instance();
+ folderMan->setSyncEnabled(false);
+ folderMan->terminateSyncProcess();
+ folderMan->unloadAllFolders();
+ // go offline
+ a->setOnline(false);
+ // show result
+ _gui->slotComputeOverallSyncStatus();
+ }
+}
+
+void Application::slotAccountChanged(Account *newAccount, Account *oldAccount)
+{
+ disconnect(oldAccount, SIGNAL(onlineStateChanged(bool)), _gui, SLOT(slotOnlineStateChanged()));
+ connect(newAccount, SIGNAL(onlineStateChanged(bool)), _gui, SLOT(slotOnlineStateChanged()));
+}
+
+
void Application::slotCleanup()
{
// explicitly close windows. This is somewhat of a hack to ensure
diff --git a/src/mirall/application.h b/src/mirall/application.h
index a5a712a18..f64194c44 100644
--- a/src/mirall/application.h
+++ b/src/mirall/application.h
@@ -73,7 +73,11 @@ protected slots:
void slotSetupProxy();
void slotUseMonoIconsChanged( bool );
void slotCredentialsFetched();
+ void slotLogin();
+ void slotLogout();
void slotCleanup();
+ void slotAccountChanged(Account *newAccount, Account *oldAccount);
+
private:
void setHelp();
void runValidator();
diff --git a/src/mirall/connectionvalidator.cpp b/src/mirall/connectionvalidator.cpp
index 6d6533d4a..5d02b6de5 100644
--- a/src/mirall/connectionvalidator.cpp
+++ b/src/mirall/connectionvalidator.cpp
@@ -142,7 +142,8 @@ void ConnectionValidator::slotAuthFailed(QNetworkReply *reply)
Status stat = StatusNotFound;
if( reply->error() == QNetworkReply::AuthenticationRequiredError ||
- reply->error() == QNetworkReply::OperationCanceledError ) { // returned if the user is wrong.
+ reply->error() == QNetworkReply::OperationCanceledError ) { // returned if the user/pwd is wrong.
+ qDebug() << reply->error() << reply->errorString();
qDebug() << "******** Password is wrong!";
_errors << tr("The provided credentials are not correct");
stat = CredentialsWrong;
diff --git a/src/mirall/networkjobs.cpp b/src/mirall/networkjobs.cpp
index 2a29dfcbf..f42dde9ad 100644
--- a/src/mirall/networkjobs.cpp
+++ b/src/mirall/networkjobs.cpp
@@ -135,7 +135,6 @@ void AbstractNetworkJob::slotFinished()
{
static QMutex mutex;
AbstractCredentials *creds = _account->credentials();
- qDebug() << creds->stillValid(_reply) << _ignoreCredentialFailure << _reply->errorString();
if (creds->stillValid(_reply) || _ignoreCredentialFailure) {
finished();
} else {
@@ -145,8 +144,9 @@ void AbstractNetworkJob::slotFinished()
// query the user
if (mutex.tryLock()) {
Account *a = account();
- a->setOnline(false);
- a->setOnline(creds->fetchFromUser(a));
+ //a->setOnline(false);
+ bool fetched = creds->fetchFromUser(a);
+ a->setOnline(fetched);
mutex.unlock();
}
}
diff --git a/src/mirall/owncloudgui.cpp b/src/mirall/owncloudgui.cpp
index dfdb28ffb..9df2cd9e6 100644
--- a/src/mirall/owncloudgui.cpp
+++ b/src/mirall/owncloudgui.cpp
@@ -23,6 +23,7 @@
#include "mirall/logger.h"
#include "mirall/logbrowser.h"
#include "mirall/account.h"
+#include "creds/abstractcredentials.h"
#include <QDesktopServices>
#include <QMessageBox>
@@ -140,6 +141,11 @@ void ownCloudGui::slotOpenPath(const QString &path)
Utility::showInFileManager(path);
}
+void ownCloudGui::slotOnlineStateChanged()
+{
+ setupContextMenu();
+}
+
void ownCloudGui::startupConnected( bool connected, const QStringList& fails )
{
FolderMan *folderMan = FolderMan::instance();
@@ -161,6 +167,13 @@ void ownCloudGui::startupConnected( bool connected, const QStringList& fails )
void ownCloudGui::slotComputeOverallSyncStatus()
{
+ if (Account *a = AccountManager::instance()->account()) {
+ if (!a->isOnline()) {
+ _tray->setIcon(Theme::instance()->syncStateIcon( SyncResult::Unavailable, true));
+ _tray->setToolTip(tr("Please sign in"));
+ return;
+ }
+ }
// display the info of the least successful sync (eg. not just display the result of the latest sync
QString trayMessage;
FolderMan *folderMan = FolderMan::instance();
@@ -208,17 +221,23 @@ void ownCloudGui::setupContextMenu()
{
FolderMan *folderMan = FolderMan::instance();
- bool isConfigured = (AccountManager::instance()->account() != 0);
+ Account *a = AccountManager::instance()->account();
+
+ bool isConfigured = (a != 0);
_actionOpenoC->setEnabled(isConfigured);
+ bool isOnline = false;
+ if (isConfigured) {
+ isOnline = a->isOnline();
+ }
- if( _contextMenu ) {
+ if ( _contextMenu ) {
_contextMenu->clear();
_recentActionsMenu->clear();
_recentActionsMenu->addAction(tr("None."));
_recentActionsMenu->addAction(_actionRecent);
} else {
- _contextMenu = new QMenu();
- _recentActionsMenu = _contextMenu->addMenu(tr("Recent Changes"));
+ _contextMenu = new QMenu(_contextMenu);
+ _recentActionsMenu = new QMenu(tr("Recent Changes"));
// this must be called only once after creating the context menu, or
// it will trigger a bug in Ubuntu's SNI bridge patch (11.10, 12.04).
_tray->setContextMenu(_contextMenu);
@@ -255,19 +274,25 @@ void ownCloudGui::setupContextMenu()
_contextMenu->addAction(action);
}
}
-
- _contextMenu->addSeparator();
- _contextMenu->addAction(_actionQuota);
- _contextMenu->addSeparator();
- _contextMenu->addAction(_actionStatus);
- _contextMenu->addMenu(_recentActionsMenu);
_contextMenu->addSeparator();
+
+ if (isConfigured && isOnline) {
+ _contextMenu->addAction(_actionQuota);
+ _contextMenu->addSeparator();
+ _contextMenu->addAction(_actionStatus);
+ _contextMenu->addMenu(_recentActionsMenu);
+ _contextMenu->addSeparator();
+ }
_contextMenu->addAction(_actionSettings);
if (!Theme::instance()->helpUrl().isEmpty()) {
_contextMenu->addAction(_actionHelp);
}
_contextMenu->addSeparator();
-
+ if (isConfigured && isOnline) {
+ _contextMenu->addAction(_actionLogout);
+ } else {
+ _contextMenu->addAction(_actionLogin);
+ }
_contextMenu->addAction(_actionQuit);
// Populate once at start
@@ -334,6 +359,11 @@ void ownCloudGui::setupActions()
_actionQuit = new QAction(tr("Quit %1").arg(Theme::instance()->appNameGUI()), this);
QObject::connect(_actionQuit, SIGNAL(triggered(bool)), _app, SLOT(quit()));
+ _actionLogin = new QAction(tr("Sign in..."), this);
+ connect(_actionLogin, SIGNAL(triggered()), _app, SLOT(slotLogin()));
+ _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)));
}
diff --git a/src/mirall/owncloudgui.h b/src/mirall/owncloudgui.h
index 001707076..f78853e7d 100644
--- a/src/mirall/owncloudgui.h
+++ b/src/mirall/owncloudgui.h
@@ -67,6 +67,7 @@ public slots:
void slotOpenOwnCloud();
void slotHelp();
void slotOpenPath(const QString& path);
+ void slotOnlineStateChanged();
private slots:
void slotDisplayIdle();
@@ -81,6 +82,9 @@ private:
QMenu *_contextMenu;
QMenu *_recentActionsMenu;
+ QAction *_actionLogin;
+ QAction *_actionLogout;
+
QAction *_actionOpenoC;
QAction *_actionSettings;
QAction *_actionQuota;