[Pkg-owncloud-commits] [owncloud-client] 197/498: QuotaJob: remove and use a PropfindJob instead
Sandro Knauß
hefee-guest at moszumanska.debian.org
Tue Aug 11 14:48:49 UTC 2015
This is an automated email from the git hooks/post-receive script.
hefee-guest pushed a commit to branch master
in repository owncloud-client.
commit db87d2a18e901569ce1cc30b9423164e0364acc2
Author: Olivier Goffart <ogoffart at woboq.com>
Date: Thu Jun 25 14:28:15 2015 +0200
QuotaJob: remove and use a PropfindJob instead
This remove code duplication because the QuotaJob was just a duplication
of the propfind jobs with the properties hardcoded.
---
src/gui/quotainfo.cpp | 16 +++++----
src/gui/quotainfo.h | 3 +-
src/gui/wizard/owncloudadvancedsetuppage.cpp | 10 +++---
src/gui/wizard/owncloudadvancedsetuppage.h | 2 +-
src/libsync/networkjobs.cpp | 54 ----------------------------
src/libsync/networkjobs.h | 17 ---------
6 files changed, 19 insertions(+), 83 deletions(-)
diff --git a/src/gui/quotainfo.cpp b/src/gui/quotainfo.cpp
index 2539b79..5474632 100644
--- a/src/gui/quotainfo.cpp
+++ b/src/gui/quotainfo.cpp
@@ -78,17 +78,21 @@ void QuotaInfo::slotCheckQuota()
}
AccountPtr account = _accountState->account();
- CheckQuotaJob *job = new CheckQuotaJob(account, "/", this);
- connect(job, SIGNAL(quotaRetrieved(qint64,qint64)), SLOT(slotUpdateLastQuota(qint64,qint64)));
+ PropfindJob *job = new PropfindJob(account, "/", this);
+ job->setProperties(QList<QByteArray>() << "quota-available-bytes" << "quota-used-bytes");
+ connect(job, SIGNAL(result(QVariantMap)), SLOT(slotUpdateLastQuota(QVariantMap)));
connect(job, SIGNAL(networkError(QNetworkReply*)), SLOT(slotRequestFailed()));
job->start();
}
-void QuotaInfo::slotUpdateLastQuota(qint64 total, qint64 used)
+void QuotaInfo::slotUpdateLastQuota(const QVariantMap &result)
{
- _lastQuotaTotalBytes = total;
- _lastQuotaUsedBytes = used;
- emit quotaUpdated(total, used);
+ // The server can return frational bytes (#1374)
+ // <d:quota-available-bytes>1374532061.2</d:quota-available-bytes>
+ quint64 avail = result["quota-available-bytes"].toDouble();
+ _lastQuotaUsedBytes = result["quota-used-bytes"].toDouble();
+ _lastQuotaTotalBytes = _lastQuotaUsedBytes + avail;
+ emit quotaUpdated(_lastQuotaTotalBytes, _lastQuotaUsedBytes);
_jobRestartTimer->start(defaultIntervalT);
}
diff --git a/src/gui/quotainfo.h b/src/gui/quotainfo.h
index db69ac8..385da01 100644
--- a/src/gui/quotainfo.h
+++ b/src/gui/quotainfo.h
@@ -16,6 +16,7 @@
#include <QObject>
#include <QPointer>
+#include <QVariant>
class QTimer;
@@ -32,10 +33,10 @@ public:
qint64 lastQuotaUsedBytes() const { return _lastQuotaUsedBytes; }
public Q_SLOTS:
- void slotUpdateLastQuota(qint64 total, qint64 used);
void slotCheckQuota();
private Q_SLOTS:
+ void slotUpdateLastQuota(const QVariantMap &);
void slotAccountStateChanged(int state);
void slotRequestFailed();
diff --git a/src/gui/wizard/owncloudadvancedsetuppage.cpp b/src/gui/wizard/owncloudadvancedsetuppage.cpp
index e2821b8..82dd46a 100644
--- a/src/gui/wizard/owncloudadvancedsetuppage.cpp
+++ b/src/gui/wizard/owncloudadvancedsetuppage.cpp
@@ -108,8 +108,10 @@ void OwncloudAdvancedSetupPage::initializePage()
QTimer::singleShot(0, wizard()->button(QWizard::NextButton), SLOT(setFocus()));
auto acc = static_cast<OwncloudWizard *>(wizard())->account();
- auto quotaJob = new CheckQuotaJob(acc, _remoteFolder, this);
- connect(quotaJob, SIGNAL(quotaRetrieved(qint64,qint64)), SLOT(slotQuotaRetrieved(qint64,qint64)));
+ auto quotaJob = new PropfindJob(acc, _remoteFolder, this);
+ quotaJob->setProperties(QList<QByteArray>() << "quota-used-bytes");
+
+ connect(quotaJob, SIGNAL(result(QVariantMap)), SLOT(slotQuotaRetrieved(QVariantMap)));
quotaJob->start();
@@ -299,9 +301,9 @@ void OwncloudAdvancedSetupPage::slotSyncEverythingClicked()
_selectiveSyncBlacklist.clear();
}
-void OwncloudAdvancedSetupPage::slotQuotaRetrieved(qint64, qint64 usedQuota)
+void OwncloudAdvancedSetupPage::slotQuotaRetrieved(const QVariantMap &result)
{
- _ui.lSyncEverythingSizeLabel->setText(tr("(%1)").arg(Utility::octetsToString(usedQuota)));
+ _ui.lSyncEverythingSizeLabel->setText(tr("(%1)").arg(Utility::octetsToString(result["quota-used-bytes"].toDouble())));
}
diff --git a/src/gui/wizard/owncloudadvancedsetuppage.h b/src/gui/wizard/owncloudadvancedsetuppage.h
index 1245abc..d5190ab 100644
--- a/src/gui/wizard/owncloudadvancedsetuppage.h
+++ b/src/gui/wizard/owncloudadvancedsetuppage.h
@@ -52,7 +52,7 @@ private slots:
void slotSelectFolder();
void slotSyncEverythingClicked();
void slotSelectiveSyncClicked();
- void slotQuotaRetrieved(qint64,qint64);
+ void slotQuotaRetrieved(const QVariantMap& result);
private:
void setupCustomization();
diff --git a/src/libsync/networkjobs.cpp b/src/libsync/networkjobs.cpp
index 4a670de..20e15de 100644
--- a/src/libsync/networkjobs.cpp
+++ b/src/libsync/networkjobs.cpp
@@ -549,60 +549,6 @@ bool EntityExistsJob::finished()
/*********************************************************************************************/
-CheckQuotaJob::CheckQuotaJob(AccountPtr account, const QString &path, QObject *parent)
- : AbstractNetworkJob(account, path, parent)
-{
-}
-
-void CheckQuotaJob::start()
-{
- QNetworkRequest req;
- req.setRawHeader("Depth", "0");
- QByteArray xml("<?xml version=\"1.0\" ?>\n"
- "<d:propfind xmlns:d=\"DAV:\">\n"
- " <d:prop>\n"
- " <d:quota-available-bytes/>\n"
- " <d:quota-used-bytes/>\n"
- " </d:prop>\n"
- "</d:propfind>\n");
- QBuffer *buf = new QBuffer(this);
- buf->setData(xml);
- buf->open(QIODevice::ReadOnly);
- // assumes ownership
- setReply(davRequest("PROPFIND", path(), req, buf));
- buf->setParent(reply());
- setupConnections(reply());
- AbstractNetworkJob::start();
-}
-
-bool CheckQuotaJob::finished()
-{
- if (reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute) == 207) {
- // Parse DAV response
- QXmlStreamReader reader(reply());
- reader.addExtraNamespaceDeclaration(QXmlStreamNamespaceDeclaration("d", "DAV:"));
- qint64 quotaAvailableBytes = 0;
- qint64 quotaUsedBytes = 0;
- while (!reader.atEnd()) {
- QXmlStreamReader::TokenType type = reader.readNext();
- if (type == QXmlStreamReader::StartElement &&
- reader.namespaceUri() == QLatin1String("DAV:")) {
- QString name = reader.name().toString();
- if (name == QLatin1String("quota-available-bytes")) {
- // I have seen the server returning frational bytes:
- // <d:quota-available-bytes>1374532061.2</d:quota-available-bytes>
- quotaAvailableBytes = reader.readElementText().toDouble();
- } else if (name == QLatin1String("quota-used-bytes")) {
- quotaUsedBytes = reader.readElementText().toDouble();
- }
- }
- }
- qint64 total = quotaUsedBytes + quotaAvailableBytes;
- emit quotaRetrieved(total, quotaUsedBytes);
- }
- return true;
-}
-
JsonApiJob::JsonApiJob(const AccountPtr &account, const QString& path, QObject* parent): AbstractNetworkJob(account, path, parent)
{ }
diff --git a/src/libsync/networkjobs.h b/src/libsync/networkjobs.h
index c0c8ca7..1062e89 100644
--- a/src/libsync/networkjobs.h
+++ b/src/libsync/networkjobs.h
@@ -183,23 +183,6 @@ private slots:
};
/**
- * @brief The CheckQuota class
- */
-class OWNCLOUDSYNC_EXPORT CheckQuotaJob : public AbstractNetworkJob {
- Q_OBJECT
-public:
- explicit CheckQuotaJob(AccountPtr account, const QString &path, QObject *parent = 0);
- void start() Q_DECL_OVERRIDE;
-
-signals:
- void quotaRetrieved(qint64 totalBytes, qint64 availableBytes);
-
-private slots:
- /** Return true if you want the job to be deleted after this slot has finished running. */
- virtual bool finished() Q_DECL_OVERRIDE;
-};
-
-/**
* @brief Job to check an API that return JSON
*
* Note! you need to be in the connected state before calling this because of a server bug:
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git
More information about the Pkg-owncloud-commits
mailing list