From ff4cdc3161ddbb74a0fe10f969043ff898fbb93a Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 17 Mar 2016 15:33:37 +0100 Subject: [PATCH] Quota: Change quota path if single folder #4460 Since the quota is a per-folder value, this will make the displayed data more useful when a single sync folder is configured. Of course each subfolder could have a different quota again. --- src/gui/quotainfo.cpp | 21 ++++++++++++++++++++- src/gui/quotainfo.h | 3 +++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/gui/quotainfo.cpp b/src/gui/quotainfo.cpp index 02d5dfdc4b..ba124debe4 100644 --- a/src/gui/quotainfo.cpp +++ b/src/gui/quotainfo.cpp @@ -15,6 +15,7 @@ #include "account.h" #include "accountstate.h" #include "networkjobs.h" +#include "folderman.h" #include "creds/abstractcredentials.h" #include @@ -79,6 +80,24 @@ bool QuotaInfo::canGetQuota() const && account->credentials()->ready(); } +QString QuotaInfo::quotaBaseFolder() const +{ + // If there's exactly one folder, use its remote path. + // Otherwise use / + bool foundOne = false; + QString path = "/"; + for (const auto & folder : FolderMan::instance()->map()) { + if (folder->accountState() == _accountState) { + if (foundOne) + return "/"; + foundOne = true; + path = folder->remotePath(); + } + } + + return path; +} + void QuotaInfo::slotCheckQuota() { if (! canGetQuota()) { @@ -91,7 +110,7 @@ void QuotaInfo::slotCheckQuota() } AccountPtr account = _accountState->account(); - _job = new PropfindJob(account, "/", this); + _job = new PropfindJob(account, quotaBaseFolder(), this); _job->setProperties(QList() << "quota-available-bytes" << "quota-used-bytes"); connect(_job, SIGNAL(result(QVariantMap)), SLOT(slotUpdateLastQuota(QVariantMap))); connect(_job, SIGNAL(networkError(QNetworkReply*)), SLOT(slotRequestFailed())); diff --git a/src/gui/quotainfo.h b/src/gui/quotainfo.h index b9ada1a2cb..480fe78415 100644 --- a/src/gui/quotainfo.h +++ b/src/gui/quotainfo.h @@ -71,6 +71,9 @@ Q_SIGNALS: private: bool canGetQuota() const; + /// Returns the folder that quota shall be retrieved for + QString quotaBaseFolder() const; + QPointer _accountState; qint64 _lastQuotaTotalBytes; qint64 _lastQuotaUsedBytes;