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

github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Schuster <michael@schuster.ms>2020-02-14 04:10:01 +0300
committerMichael Schuster <michael@schuster.ms>2020-02-14 04:10:01 +0300
commitabfebcf2917e971a4e8c279d3f2871c79e64583a (patch)
tree871350d0f6759b440e57e80ae2d96f068d0f1317 /src/gui/connectionvalidator.cpp
parentbbb310a853b930692dd69dd1f9b6038dece0479a (diff)
Add UserInfo class and fetch quota via API instead of PropfindJob
The PropfindJob quota includes the size of shares and thus leads to confusion in regard of the real space available, as shown in the UI. This commit aims to streamline the behaviour with the Android and iOS apps, which also utilize the API. Details: - Refactor the QuotaInfo class into UserInfo - Use JsonApiJob (ocs/v1.php/cloud/user) instead of PropfindJob - Let ConnectionValidator use the new UserInfo class to fetch the user and the avatar image (to avoid code duplication) - Allow updating the avatar image upon AccountSettings visibility, using UserInfo's quota fetching Signed-off-by: Michael Schuster <michael@schuster.ms>
Diffstat (limited to 'src/gui/connectionvalidator.cpp')
-rw-r--r--src/gui/connectionvalidator.cpp40
1 files changed, 15 insertions, 25 deletions
diff --git a/src/gui/connectionvalidator.cpp b/src/gui/connectionvalidator.cpp
index 97bdf7573..3b9f8f4ca 100644
--- a/src/gui/connectionvalidator.cpp
+++ b/src/gui/connectionvalidator.cpp
@@ -22,6 +22,8 @@
#include "connectionvalidator.h"
#include "account.h"
+#include "accountstate.h"
+#include "userinfo.h"
#include "networkjobs.h"
#include "clientproxy.h"
#include <creds/abstractcredentials.h>
@@ -34,9 +36,10 @@ Q_LOGGING_CATEGORY(lcConnectionValidator, "nextcloud.sync.connectionvalidator",
// This makes sure we get tried often enough without "ConnectionValidator already running"
static qint64 timeoutToUseMsec = qMax(1000, ConnectionValidator::DefaultCallingIntervalMsec - 5 * 1000);
-ConnectionValidator::ConnectionValidator(AccountPtr account, QObject *parent)
+ConnectionValidator::ConnectionValidator(AccountStatePtr accountState, QObject *parent)
: QObject(parent)
- , _account(account)
+ , _accountState(accountState)
+ , _account(accountState->account())
, _isCheckingServerAndAuth(false)
{
}
@@ -270,10 +273,9 @@ void ConnectionValidator::ocsConfigReceived(const QJsonDocument &json, AccountPt
void ConnectionValidator::fetchUser()
{
- JsonApiJob *job = new JsonApiJob(_account, QLatin1String("ocs/v1.php/cloud/user"), this);
- job->setTimeout(timeoutToUseMsec);
- QObject::connect(job, &JsonApiJob::jsonReceived, this, &ConnectionValidator::slotUserFetched);
- job->start();
+ UserInfo *userInfo = new UserInfo(_accountState.data(), true, true, this);
+ QObject::connect(userInfo, &UserInfo::fetchedLastInfo, this, &ConnectionValidator::slotUserFetched);
+ userInfo->setActive(true);
}
bool ConnectionValidator::setAndCheckServerVersion(const QString &version)
@@ -305,34 +307,22 @@ bool ConnectionValidator::setAndCheckServerVersion(const QString &version)
return true;
}
-void ConnectionValidator::slotUserFetched(const QJsonDocument &json)
+void ConnectionValidator::slotUserFetched(UserInfo *userInfo)
{
- QString user = json.object().value("ocs").toObject().value("data").toObject().value("id").toString();
- if (!user.isEmpty()) {
- _account->setDavUser(user);
- }
- QString displayName = json.object().value("ocs").toObject().value("data").toObject().value("display-name").toString();
- if (!displayName.isEmpty()) {
- _account->setDavDisplayName(displayName);
+ if(userInfo) {
+ userInfo->setActive(false);
+ userInfo->deleteLater();
}
+
#ifndef TOKEN_AUTH_ONLY
- AvatarJob *job = new AvatarJob(_account, _account->davUser(), 128, this);
- job->setTimeout(20 * 1000);
- QObject::connect(job, &AvatarJob::avatarPixmap, this, &ConnectionValidator::slotAvatarImage);
- job->start();
+ connect(_account->e2e(), &ClientSideEncryption::initializationFinished, this, &ConnectionValidator::reportConnected);
+ _account->e2e()->initialize();
#else
reportResult(Connected);
#endif
}
#ifndef TOKEN_AUTH_ONLY
-void ConnectionValidator::slotAvatarImage(const QImage &img)
-{
- _account->setAvatar(img);
- connect(_account->e2e(), &ClientSideEncryption::initializationFinished, this, &ConnectionValidator::reportConnected);
- _account->e2e()->initialize();
-}
-
void ConnectionValidator::reportConnected() {
reportResult(Connected);
}