mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 23:28:14 +03:00
Readd "online" notion as a state in account.
This gets updated by the ConnectionValidator. Not sure if that's the best choice, but it mimmicks the old behavior the closest.
This commit is contained in:
parent
478ba9c5ef
commit
aa4b6bd4ea
4 changed files with 37 additions and 12 deletions
|
@ -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<QSslError> errors)
|
||||
{
|
||||
qDebug() << "SSL-Warnings happened for url " << reply->url().toString();
|
||||
|
|
|
@ -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<QSslError>);
|
||||
|
||||
private:
|
||||
QMap<QString, QVariant> _settingsMap;
|
||||
QNetworkAccessManager *_am;
|
||||
QUrl _url;
|
||||
AbstractCredentials* _credentials;
|
||||
QList<QSslCertificate> _approvedCerts;
|
||||
QList<QSslCertificate> _certificateChain;
|
||||
bool _treatSslErrorsAsFailure;
|
||||
QScopedPointer<AbstractSslErrorHandler> _sslErrorHandler;
|
||||
QNetworkAccessManager *_am;
|
||||
AbstractCredentials* _credentials;
|
||||
bool _treatSslErrorsAsFailure;
|
||||
bool _isOnline;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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 <a href=\"%1\">%2</a>.").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 <a href=\"%1\">%2</a>.")
|
||||
.arg(Theme::instance()->appNameGUI(),
|
||||
_account->url().toString(),
|
||||
safeUrl.toString()) );
|
||||
}
|
||||
} else {
|
||||
// ownCloud is not yet configured.
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue