diff --git a/src/libsync/networkjobs.cpp b/src/libsync/networkjobs.cpp index aca38bd9676..5a51a4e4499 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 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 += "\n"; + } + QByteArray xml = "\n" + "\n" + " \n" + + propStr + + " \n" + "\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 properties) +{ + _properties = properties; +} + +QMap 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 69c8f8efae5..62048d80a6e 100644 --- a/src/libsync/networkjobs.h +++ b/src/libsync/networkjobs.h @@ -127,6 +127,43 @@ private slots: QList _properties; }; +/** + * @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 properties); + QMap properties() const; + +signals: + void success(); + void finishedWithError(); + +private slots: + virtual bool finished() Q_DECL_OVERRIDE; + +private: + QMap _properties; +}; + /** * @brief The MkColJob class * @ingroup libsync