[Pkg-owncloud-commits] [owncloud-client] 388/484: Add an experimental ProppatchJob #3235
Sandro Knauß
hefee-guest at moszumanska.debian.org
Wed Dec 16 00:38:10 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 bdf830f691c899e39242202f3abb556cc2f9a54f
Author: Christian Kamm <mail at ckamm.de>
Date: Thu Nov 12 11:20:45 2015 +0100
Add an experimental ProppatchJob #3235
---
src/libsync/networkjobs.cpp | 75 +++++++++++++++++++++++++++++++++++++++++++++
src/libsync/networkjobs.h | 37 ++++++++++++++++++++++
2 files changed, 112 insertions(+)
diff --git a/src/libsync/networkjobs.cpp b/src/libsync/networkjobs.cpp
index aca38bd..5a51a4e 100644
--- a/src/libsync/networkjobs.cpp
+++ b/src/libsync/networkjobs.cpp
@@ -565,6 +565,81 @@ bool PropfindJob::finished()
/*********************************************************************************************/
+ProppatchJob::ProppatchJob(AccountPtr account, const QString &path, QObject *parent)
+ : AbstractNetworkJob(account, path, parent)
+{
+
+}
+
+void ProppatchJob::start()
+{
+ if (_properties.isEmpty()) {
+ qWarning() << "Proppatch with no properties!";
+ }
+ QNetworkRequest req;
+
+ QByteArray propStr;
+ QMapIterator<QByteArray, QByteArray> it(_properties);
+ while (it.hasNext()) {
+ it.next();
+ QByteArray keyName = it.key();
+ QByteArray keyNs;
+ if (keyName.contains(':')) {
+ int colIdx = keyName.lastIndexOf(":");
+ keyNs = keyName.left(colIdx);
+ keyName = keyName.mid(colIdx+1);
+ }
+
+ propStr += " <" + keyName;
+ if (!keyNs.isEmpty()) {
+ propStr += " xmlns=\"" + keyNs + "\" ";
+ }
+ propStr += ">";
+ propStr += it.value();
+ propStr += "</" + keyName + ">\n";
+ }
+ QByteArray xml = "<?xml version=\"1.0\" ?>\n"
+ "<d:propertyupdate xmlns:d=\"DAV:\">\n"
+ " <d:set><d:prop>\n"
+ + propStr +
+ " </d:prop></d:set>\n"
+ "</d:propertyupdate>\n";
+
+ QBuffer *buf = new QBuffer(this);
+ buf->setData(xml);
+ buf->open(QIODevice::ReadOnly);
+ setReply(davRequest("PROPPATCH", path(), req, buf));
+ buf->setParent(reply());
+ setupConnections(reply());
+ AbstractNetworkJob::start();
+}
+
+void ProppatchJob::setProperties(QMap<QByteArray, QByteArray> properties)
+{
+ _properties = properties;
+}
+
+QMap<QByteArray, QByteArray> ProppatchJob::properties() const
+{
+ return _properties;
+}
+
+bool ProppatchJob::finished()
+{
+ int http_result_code = reply()->attribute(QNetworkRequest::HttpStatusCodeAttribute).toInt();
+
+ if (http_result_code == 207) {
+ emit success();
+ } else {
+ qDebug() << "PROPPATCH request *not* successful, http result code is" << http_result_code
+ << (http_result_code == 302 ? reply()->header(QNetworkRequest::LocationHeader).toString() : QLatin1String(""));
+ emit finishedWithError();
+ }
+ return true;
+}
+
+/*********************************************************************************************/
+
EntityExistsJob::EntityExistsJob(AccountPtr account, const QString &path, QObject *parent)
: AbstractNetworkJob(account, path, parent)
{
diff --git a/src/libsync/networkjobs.h b/src/libsync/networkjobs.h
index 69c8f8e..62048d8 100644
--- a/src/libsync/networkjobs.h
+++ b/src/libsync/networkjobs.h
@@ -128,6 +128,43 @@ private:
};
/**
+ * @brief Send a Proppatch request
+ *
+ * Setting the desired properties with setProperties() is mandatory.
+ *
+ * WARNING: Untested!
+ *
+ * @ingroup libsync
+ */
+class OWNCLOUDSYNC_EXPORT ProppatchJob : public AbstractNetworkJob {
+ Q_OBJECT
+public:
+ explicit ProppatchJob(AccountPtr account, const QString &path, QObject *parent = 0);
+ void start() Q_DECL_OVERRIDE;
+
+ /**
+ * Used to specify which properties shall be set.
+ *
+ * The property keys can
+ * - contain no colon: they refer to a property in the DAV: namespace
+ * - contain a colon: and thus specify an explicit namespace,
+ * e.g. "ns:with:colons:bar", which is "bar" in the "ns:with:colons" namespace
+ */
+ void setProperties(QMap<QByteArray, QByteArray> properties);
+ QMap<QByteArray, QByteArray> properties() const;
+
+signals:
+ void success();
+ void finishedWithError();
+
+private slots:
+ virtual bool finished() Q_DECL_OVERRIDE;
+
+private:
+ QMap<QByteArray, QByteArray> _properties;
+};
+
+/**
* @brief The MkColJob class
* @ingroup libsync
*/
--
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