1 | /* |
---|---|
2 | SPDX-FileCopyrightText: 2010 Grégory Oestreicher <greg@kamago.net> |
3 | |
4 | SPDX-License-Identifier: LGPL-2.0-or-later |
5 | */ |
6 | |
7 | #include "davcollectiondeletejob.h" |
8 | #include "davjobbase_p.h" |
9 | |
10 | #include "daverror.h" |
11 | |
12 | #include <KIO/DeleteJob> |
13 | #include <KIO/Job> |
14 | |
15 | using namespace KDAV; |
16 | |
17 | namespace KDAV |
18 | { |
19 | class DavCollectionDeleteJobPrivate : public DavJobBasePrivate |
20 | { |
21 | public: |
22 | void davJobFinished(KJob *job); |
23 | |
24 | DavUrl mUrl; |
25 | }; |
26 | } |
27 | |
28 | DavCollectionDeleteJob::DavCollectionDeleteJob(const DavUrl &url, QObject *parent) |
29 | : DavJobBase(new DavCollectionDeleteJobPrivate, parent) |
30 | { |
31 | Q_D(DavCollectionDeleteJob); |
32 | d->mUrl = url; |
33 | } |
34 | |
35 | void DavCollectionDeleteJob::start() |
36 | { |
37 | Q_D(DavCollectionDeleteJob); |
38 | KIO::DeleteJob *job = KIO::del(src: d->mUrl.url(), flags: KIO::HideProgressInfo | KIO::DefaultFlags); |
39 | job->addMetaData(QStringLiteral("PropagateHttpHeader"), QStringLiteral( "true")); |
40 | job->addMetaData(QStringLiteral("cookies"), QStringLiteral( "none")); |
41 | job->addMetaData(QStringLiteral("no-auth-prompt"), QStringLiteral( "true")); |
42 | |
43 | connect(sender: job, signal: &KIO::DeleteJob::result, context: this, slot: [d](KJob *job) { |
44 | d->davJobFinished(job); |
45 | }); |
46 | } |
47 | |
48 | void DavCollectionDeleteJobPrivate::davJobFinished(KJob *job) |
49 | { |
50 | KIO::DeleteJob *deleteJob = qobject_cast<KIO::DeleteJob *>(object: job); |
51 | |
52 | if (deleteJob->error() && deleteJob->error() != KIO::ERR_NO_CONTENT) { |
53 | const int responseCode = deleteJob->queryMetaData(QStringLiteral("responsecode")).isEmpty() // |
54 | ? 0 |
55 | : deleteJob->queryMetaData(QStringLiteral("responsecode")).toInt(); |
56 | |
57 | setLatestResponseCode(responseCode); |
58 | setError(ERR_COLLECTIONDELETE); |
59 | setJobErrorText(deleteJob->errorText()); |
60 | setJobError(deleteJob->error()); |
61 | setErrorTextFromDavError(); |
62 | } |
63 | |
64 | emitResult(); |
65 | } |
66 | |
67 | #include "moc_davcollectiondeletejob.cpp" |
68 |