KDAV

davitemdeletejob.cpp
1/*
2 SPDX-FileCopyrightText: 2010 Tobias Koenig <tokoe@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "davitemdeletejob.h"
8#include "davjobbase_p.h"
9
10#include "daverror.h"
11#include "davitemfetchjob.h"
12#include "davmanager_p.h"
13
14#include <KIO/DeleteJob>
15#include <KIO/Job>
16
17using namespace KDAV;
18
19namespace KDAV
20{
21class DavItemDeleteJobPrivate : public DavJobBasePrivate
22{
23public:
24 void davJobFinished(KJob *job);
25 void conflictingItemFetched(KJob *job);
26
27 DavItem mItem;
28 DavItem mFreshItem;
29 int mFreshResponseCode = -1;
30};
31}
32
34 : DavJobBase(new DavItemDeleteJobPrivate, parent)
35{
37 d->mItem = item;
38}
39
41{
43 KIO::DeleteJob *job = KIO::del(d->mItem.url().url(), KIO::HideProgressInfo | KIO::DefaultFlags);
44 job->addMetaData(QStringLiteral("PropagateHttpHeader"), QStringLiteral("true"));
45 job->addMetaData(QStringLiteral("customHTTPHeader"), QStringLiteral("If-Match: ") + d->mItem.etag());
46 job->addMetaData(QStringLiteral("cookies"), QStringLiteral("none"));
47 job->addMetaData(QStringLiteral("no-auth-prompt"), QStringLiteral("true"));
48
49 connect(job, &KIO::DeleteJob::result, this, [d](KJob *job) {
50 d->davJobFinished(job);
51 });
52}
53
55{
56 Q_D(const DavItemDeleteJob);
57 return d->mFreshItem;
58}
59
61{
62 Q_D(const DavItemDeleteJob);
63 return d->mFreshResponseCode;
64}
65
66void DavItemDeleteJobPrivate::davJobFinished(KJob *job)
67{
68 KIO::DeleteJob *deleteJob = qobject_cast<KIO::DeleteJob *>(job);
69
70 if (deleteJob->error() && deleteJob->error() != KIO::ERR_NO_CONTENT) {
71 const int responseCode = deleteJob->queryMetaData(QStringLiteral("responsecode")).isEmpty() //
72 ? 0
73 : deleteJob->queryMetaData(QStringLiteral("responsecode")).toInt();
74
75 if (responseCode != 404 && responseCode != 410) {
76 setLatestResponseCode(responseCode);
77 setError(ERR_ITEMDELETE);
78 setJobErrorText(deleteJob->errorText());
79 setJobError(deleteJob->error());
80 setErrorTextFromDavError();
81 }
82
83 if (q_ptr->hasConflict()) {
84 DavItemFetchJob *fetchJob = new DavItemFetchJob(mItem);
85 QObject::connect(fetchJob, &DavItemFetchJob::result, q_ptr, [this](KJob *job) {
86 conflictingItemFetched(job);
87 });
88 fetchJob->start();
89 return;
90 }
91 }
92
93 emitResult();
94}
95
96void DavItemDeleteJobPrivate::conflictingItemFetched(KJob *job)
97{
98 DavItemFetchJob *fetchJob = qobject_cast<DavItemFetchJob *>(job);
99 mFreshResponseCode = fetchJob->latestResponseCode();
100
101 if (!job->error()) {
102 mFreshItem = fetchJob->item();
103 }
104
105 emitResult();
106}
107
108#include "moc_davitemdeletejob.cpp"
A job to delete a DAV item on the DAV server.
DavItemDeleteJob(const DavItem &item, QObject *parent=nullptr)
Creates a new DAV item delete job.
int freshResponseCode() const
Returns the response code we got when fetching the fresh item.
DavItem freshItem() const
Returns the item that triggered the conflict, if any.
void start() override
Starts the job.
A job that fetches a DAV item from the DAV server.
DavItem item() const
Returns the fetched item including current ETag information.
void start() override
Starts the job.
A helper class to store information about DAV resources.
Definition davitem.h:39
base class for the jobs used by the resource.
Definition davjobbase.h:27
int latestResponseCode() const
Get the latest response code.
void addMetaData(const QMap< QString, QString > &values)
QString queryMetaData(const QString &key)
int error() const
void result(KJob *job)
QString errorText() const
The KDAV namespace.
KIOCORE_EXPORT DeleteJob * del(const QList< QUrl > &src, JobFlags flags=DefaultFlags)
DefaultFlags
HideProgressInfo
ERR_NO_CONTENT
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
bool isEmpty() const const
int toInt(bool *ok, int base) const const
Q_D(Todo)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Tue Mar 26 2024 11:16:34 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.