diff --git a/src/mirall/account.cpp b/src/mirall/account.cpp index 60e920054..651d2df4d 100644 --- a/src/mirall/account.cpp +++ b/src/mirall/account.cpp @@ -58,10 +58,11 @@ void AccountManager::setAccount(Account *account) Account::Account(AbstractSslErrorHandler *sslErrorHandler, QObject *parent) : QObject(parent) + , _sslErrorHandler(sslErrorHandler) , _am(0) , _credentials(0) , _treatSslErrorsAsFailure(false) - , _sslErrorHandler(sslErrorHandler) + , _isOnline(false) { } @@ -263,6 +264,19 @@ void Account::setCredentialSetting(const QString &key, const QVariant &value) } } +bool Account::isOnline() const +{ + return _isOnline; +} + +void Account::setOnline(bool online) +{ + if (_isOnline != online) { + emit onlineStateChanged(online); + } + _isOnline = online; +} + void Account::slotHandleErrors(QNetworkReply *reply , QList errors) { qDebug() << "SSL-Warnings happened for url " << reply->url().toString(); diff --git a/src/mirall/account.h b/src/mirall/account.h index 1de4fd4bc..f462c1461 100644 --- a/src/mirall/account.h +++ b/src/mirall/account.h @@ -133,18 +133,24 @@ public: QVariant credentialSetting(const QString& key) const; void setCredentialSetting(const QString& key, const QVariant &value); + bool isOnline() const; + void setOnline(bool online); +signals: + void onlineStateChanged(bool online); + protected Q_SLOTS: void slotHandleErrors(QNetworkReply*,QList); private: QMap _settingsMap; - QNetworkAccessManager *_am; QUrl _url; - AbstractCredentials* _credentials; QList _approvedCerts; QList _certificateChain; - bool _treatSslErrorsAsFailure; QScopedPointer _sslErrorHandler; + QNetworkAccessManager *_am; + AbstractCredentials* _credentials; + bool _treatSslErrorsAsFailure; + bool _isOnline; }; } diff --git a/src/mirall/accountsettings.cpp b/src/mirall/accountsettings.cpp index e07e67c0e..038e5e613 100644 --- a/src/mirall/accountsettings.cpp +++ b/src/mirall/accountsettings.cpp @@ -100,8 +100,8 @@ AccountSettings::AccountSettings(QWidget *parent) : ui->connectLabel->setWordWrap( true ); ui->quotaLabel->setWordWrap( true ); - // ### TODO: - slotOnlineStateChanged(); + connect(_account, SIGNAL(onlineStateChanged(bool)), SLOT(slotOnlineStateChanged(bool))); + slotOnlineStateChanged(_account->isOnline()); setFolderList(FolderMan::instance()->map()); } @@ -776,16 +776,17 @@ void AccountSettings::slotIgnoreFilesEditor() void AccountSettings::slotOnlineStateChanged(bool online) { if (_account) { -// connect(_account, SIGNAL(quotaUpdated(qint64,qint64)), SLOT(slotUpdateQuota(qint64,qint64)), Qt::UniqueConnection); -// slotUpdateQuota(_account->lastQuotaTotalBytes(), _account->lastQuotaUsedBytes()); + QUrl safeUrl(_account->url()); + safeUrl.setPassword(QString()); // Remove the password from the URL to avoid showing it in the UI + ui->_buttonAdd->setEnabled(online); if (online) { - QUrl safeUrl(_account->url()); - safeUrl.setPassword(QString()); // Remove the password from the URL to avoid showing it in the UI showConnectionLabel( tr("Connected to %2.").arg(_account->url().toString(), safeUrl.toString()) /*, tr("Version: %1 (%2)").arg(versionStr).arg(version) */ ); - ui->_buttonAdd->setEnabled(true); } else { - showConnectionLabel( tr("Checking %1 connection...").arg(Theme::instance()->appNameGUI())); + showConnectionLabel( tr("No connection to %1 at %2.") + .arg(Theme::instance()->appNameGUI(), + _account->url().toString(), + safeUrl.toString()) ); } } else { // ownCloud is not yet configured. diff --git a/src/mirall/connectionvalidator.cpp b/src/mirall/connectionvalidator.cpp index 1cf28a988..5e6c1ab14 100644 --- a/src/mirall/connectionvalidator.cpp +++ b/src/mirall/connectionvalidator.cpp @@ -112,6 +112,8 @@ void ConnectionValidator::slotStatusFound(const QUrl&url, const QVariantMap &inf // status.php could not be loaded. void ConnectionValidator::slotNoStatusFound(QNetworkReply *reply) { + _account->setOnline(false); + // ### TODO _errors.append(tr("Unable to connect to %1").arg(_account->url().toString())); _errors.append( reply->errorString() ); @@ -139,6 +141,7 @@ void ConnectionValidator::slotAuthFailed(QNetworkReply *reply) qDebug() << "******** Password is wrong!"; _errors << tr("The provided credentials are not correct"); stat = CredentialsWrong; + _account->setOnline(false); } else if( reply->error() != QNetworkReply::NoError ) { _errors << reply->errorString(); } @@ -148,6 +151,7 @@ void ConnectionValidator::slotAuthFailed(QNetworkReply *reply) void ConnectionValidator::slotAuthSuccess() { + _account->setOnline(true); emit connectionResult(Connected); }