mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-27 09:30:13 +03:00
Add an experimental ProppatchJob #3235
This commit is contained in:
parent
bd72642a58
commit
bdf830f691
2 changed files with 112 additions and 0 deletions
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -127,6 +127,43 @@ private:
|
|||
QList<QByteArray> _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<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
|
||||
|
|
Loading…
Reference in a new issue