1#include <QAuthenticator>
4#include <QHttpMultiPart>
7#include <QNetworkAccessManager>
8#include <QNetworkReply>
9#include <QRegularExpression>
13#include "WebDAVClient.hpp"
14#include "utils/NetworkHelper.hpp"
15#include "utils/WebDAVReply.hpp"
19 this->networkHelper =
new NetworkHelper(host, username, password);
20 this->xmlHelper =
new XMLHelper();
27 return this->listDir(path, ListDepthEnum::Infinity);
32 WebDAVReply *reply =
new WebDAVReply();
34 QMap<QString, QString> headers;
35 QNetworkReply *listDirReply;
38 case ListDepthEnum::Zero:
39 depthVal = QStringLiteral(
"0");
42 case ListDepthEnum::One:
43 depthVal = QStringLiteral(
"1");
46 case ListDepthEnum::Two:
47 depthVal = QStringLiteral(
"2");
50 case ListDepthEnum::Infinity:
51 depthVal = QStringLiteral(
"infinity");
58 headers.
insert(QStringLiteral(
"Depth"), depthVal);
60 listDirReply = this->networkHelper->makeRequest(QStringLiteral(
"PROPFIND"), path, headers);
63 reply->sendListDirResponseSignal(listDirReply, this->xmlHelper->parseListDirResponse(
this, listDirReply->
readAll()));
66 this->errorReplyHandler(reply, err);
74 return this->downloadFrom(path, 0, -1);
79 WebDAVReply *reply =
new WebDAVReply();
81 QTextStream stream(&rangeVal);
82 QMap<QString, QString> headers;
83 QNetworkReply *downloadReply;
85 stream <<
"bytes=" << startByte <<
"-" << endByte;
87 headers.
insert(QStringLiteral(
"Range"), rangeVal);
89 downloadReply = this->networkHelper->makeRequest(QStringLiteral(
"GET"), path, headers);
92 reply->sendDownloadResponseSignal(downloadReply);
96 if (bytesTotal == -1) {
98 QRegularExpression re(QStringLiteral(
"bytes (\\d*)-(\\d*)/(\\d*)"));
99 QRegularExpressionMatch
match = re.match(contentRange);
100 qint64 contentSize =
match.captured(2).toInt() -
match.captured(1).toInt();
102 reply->sendDownloadProgressResponseSignal(bytesReceived, contentSize);
104 reply->sendDownloadProgressResponseSignal(bytesReceived, bytesTotal);
108 this->errorReplyHandler(reply, err);
116 WebDAVReply *reply =
new WebDAVReply();
117 QMap<QString, QString> headers;
118 QNetworkReply *uploadReply;
120 uploadReply = this->networkHelper->makePutRequest(path + QStringLiteral(
"/") + filename, headers, file);
123 reply->sendUploadFinishedResponseSignal(uploadReply);
127 this->errorReplyHandler(reply, err);
135 WebDAVReply *reply =
new WebDAVReply();
136 QMap<QString, QString> headers;
137 QNetworkReply *createDirReply;
139 createDirReply = this->networkHelper->makeRequest(QStringLiteral(
"MKCOL"), path + QStringLiteral(
"/") + dirName, headers);
142 reply->sendDirCreatedResponseSignal(createDirReply);
146 this->errorReplyHandler(reply, err);
154 WebDAVReply *reply =
new WebDAVReply();
155 QMap<QString, QString> headers;
156 QNetworkReply *copyReply;
158 headers.
insert(QStringLiteral(
"Destination"), destination);
160 copyReply = this->networkHelper->makeRequest(QStringLiteral(
"COPY"), source, headers);
163 reply->sendCopyResponseSignal(copyReply);
167 this->errorReplyHandler(reply, err);
175 WebDAVReply *reply =
new WebDAVReply();
176 QMap<QString, QString> headers;
177 QNetworkReply *moveReply;
178 QString overwriteVal =
overwrite ? QStringLiteral(
"T") : QStringLiteral(
"F");
180 headers.
insert(QStringLiteral(
"Destination"), destination);
181 headers.
insert(QStringLiteral(
"Overwrite"), overwriteVal);
183 moveReply = this->networkHelper->makeRequest(QStringLiteral(
"MOVE"), source, headers);
186 reply->sendMoveResponseSignal(moveReply);
190 this->errorReplyHandler(reply, err);
198 WebDAVReply *reply =
new WebDAVReply();
199 QMap<QString, QString> headers;
200 QNetworkReply *removeReply;
202 removeReply = this->networkHelper->makeRequest(QStringLiteral(
"DELETE"), path, headers);
205 reply->sendRemoveResponseSignal(removeReply);
209 this->errorReplyHandler(reply, err);
217 reply->sendError(err);
220WebDAVClient::~WebDAVClient()
222 this->networkHelper->deleteLater();
223 delete this->xmlHelper;
Wraps the available actions for a remote item.
KCOREADDONS_EXPORT Result match(QStringView pattern, QStringView str)
std::string toStdString() const const
iterator insert(const Key &key, const T &value)
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
void errorOccurred(QNetworkReply::NetworkError code)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QString fromStdString(const std::string &str)