Introduce online/offline state, accessible via GUI

This commit is contained in:
Daniel Molkentin 2013-11-23 00:14:02 +01:00
parent 6165c38289
commit 4e22fff427
12 changed files with 123 additions and 19 deletions

View File

@ -35,6 +35,7 @@ public:
bool fetchFromUser(Account *account);
void fetch(Account*);
void persist(Account*);
void invalidateToken(Account *) {}
};
} // ns Mirall

View File

@ -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);

View File

@ -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*);

View File

@ -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()),

View File

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

View File

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

View File

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

View File

@ -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();

View File

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

View File

@ -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();
}
}

View File

@ -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);
_actionOpenoC->setEnabled(isConfigured);
Account *a = AccountManager::instance()->account();
if( _contextMenu ) {
bool isConfigured = (a != 0);
_actionOpenoC->setEnabled(isConfigured);
bool isOnline = false;
if (isConfigured) {
isOnline = a->isOnline();
}
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->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)));
}

View File

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