Changeset View
Changeset View
Standalone View
Standalone View
src/common/davitemdeletejob.cpp
Show All 11 Lines | 1 | /* | |||
---|---|---|---|---|---|
12 | GNU General Public License for more details. | 12 | GNU General Public License for more details. | ||
13 | 13 | | |||
14 | You should have received a copy of the GNU General Public License | 14 | You should have received a copy of the GNU General Public License | ||
15 | along with this program; if not, write to the Free Software | 15 | along with this program; if not, write to the Free Software | ||
16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | 16 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | ||
17 | */ | 17 | */ | ||
18 | 18 | | |||
19 | #include "davitemdeletejob.h" | 19 | #include "davitemdeletejob.h" | ||
20 | #include "davjobbase_p.h" | ||||
20 | 21 | | |||
21 | #include "davitemfetchjob.h" | 22 | #include "davitemfetchjob.h" | ||
22 | #include "davmanager.h" | 23 | #include "davmanager.h" | ||
23 | #include "daverror.h" | 24 | #include "daverror.h" | ||
24 | 25 | | |||
25 | #include <KIO/DeleteJob> | 26 | #include <KIO/DeleteJob> | ||
26 | #include <KIO/Job> | 27 | #include <KIO/Job> | ||
27 | 28 | | |||
28 | using namespace KDAV; | 29 | using namespace KDAV; | ||
29 | 30 | | |||
31 | namespace KDAV { | ||||
32 | class DavItemDeleteJobPrivate : public DavJobBasePrivate | ||||
33 | { | ||||
34 | public: | ||||
35 | DavItem mItem; | ||||
36 | DavItem mFreshItem; | ||||
37 | int mFreshResponseCode = -1; | ||||
38 | }; | ||||
39 | } | ||||
40 | | ||||
30 | DavItemDeleteJob::DavItemDeleteJob(const DavItem &item, QObject *parent) | 41 | DavItemDeleteJob::DavItemDeleteJob(const DavItem &item, QObject *parent) | ||
31 | : DavJobBase(parent) | 42 | : DavJobBase(new DavItemDeleteJobPrivate, parent) | ||
32 | , mItem(item) | | |||
33 | , mFreshResponseCode(-1) | | |||
34 | { | 43 | { | ||
44 | Q_D(DavItemDeleteJob); | ||||
45 | d->mItem = item; | ||||
35 | } | 46 | } | ||
36 | 47 | | |||
37 | void DavItemDeleteJob::start() | 48 | void DavItemDeleteJob::start() | ||
38 | { | 49 | { | ||
39 | KIO::DeleteJob *job = KIO::del(mItem.url().url(), KIO::HideProgressInfo | KIO::DefaultFlags); | 50 | Q_D(DavItemDeleteJob); | ||
51 | KIO::DeleteJob *job = KIO::del(d->mItem.url().url(), KIO::HideProgressInfo | KIO::DefaultFlags); | ||||
40 | job->addMetaData(QStringLiteral("PropagateHttpHeader"), QStringLiteral("true")); | 52 | job->addMetaData(QStringLiteral("PropagateHttpHeader"), QStringLiteral("true")); | ||
41 | job->addMetaData(QStringLiteral("customHTTPHeader"), QStringLiteral("If-Match: ") + mItem.etag()); | 53 | job->addMetaData(QStringLiteral("customHTTPHeader"), QStringLiteral("If-Match: ") + d->mItem.etag()); | ||
42 | job->addMetaData(QStringLiteral("cookies"), QStringLiteral("none")); | 54 | job->addMetaData(QStringLiteral("cookies"), QStringLiteral("none")); | ||
43 | job->addMetaData(QStringLiteral("no-auth-prompt"), QStringLiteral("true")); | 55 | job->addMetaData(QStringLiteral("no-auth-prompt"), QStringLiteral("true")); | ||
44 | 56 | | |||
45 | connect(job, &KIO::DeleteJob::result, this, &DavItemDeleteJob::davJobFinished); | 57 | connect(job, &KIO::DeleteJob::result, this, &DavItemDeleteJob::davJobFinished); | ||
46 | } | 58 | } | ||
47 | 59 | | |||
48 | DavItem DavItemDeleteJob::freshItem() const | 60 | DavItem DavItemDeleteJob::freshItem() const | ||
49 | { | 61 | { | ||
50 | return mFreshItem; | 62 | Q_D(const DavItemDeleteJob); | ||
63 | return d->mFreshItem; | ||||
51 | } | 64 | } | ||
52 | 65 | | |||
53 | int DavItemDeleteJob::freshResponseCode() const | 66 | int DavItemDeleteJob::freshResponseCode() const | ||
54 | { | 67 | { | ||
55 | return mFreshResponseCode; | 68 | Q_D(const DavItemDeleteJob); | ||
69 | return d->mFreshResponseCode; | ||||
56 | } | 70 | } | ||
57 | 71 | | |||
58 | void DavItemDeleteJob::davJobFinished(KJob *job) | 72 | void DavItemDeleteJob::davJobFinished(KJob *job) | ||
59 | { | 73 | { | ||
74 | Q_D(DavItemDeleteJob); | ||||
60 | KIO::DeleteJob *deleteJob = qobject_cast<KIO::DeleteJob *>(job); | 75 | KIO::DeleteJob *deleteJob = qobject_cast<KIO::DeleteJob *>(job); | ||
61 | 76 | | |||
62 | if (deleteJob->error() && deleteJob->error() != KIO::ERR_NO_CONTENT) { | 77 | if (deleteJob->error() && deleteJob->error() != KIO::ERR_NO_CONTENT) { | ||
63 | const int responseCode = deleteJob->queryMetaData(QStringLiteral("responsecode")).isEmpty() | 78 | const int responseCode = deleteJob->queryMetaData(QStringLiteral("responsecode")).isEmpty() | ||
64 | ? 0 | 79 | ? 0 | ||
65 | : deleteJob->queryMetaData(QStringLiteral("responsecode")).toInt(); | 80 | : deleteJob->queryMetaData(QStringLiteral("responsecode")).toInt(); | ||
66 | 81 | | |||
67 | if (responseCode != 404 && responseCode != 410) { | 82 | if (responseCode != 404 && responseCode != 410) { | ||
68 | setLatestResponseCode(responseCode); | 83 | setLatestResponseCode(responseCode); | ||
69 | setError(ERR_ITEMDELETE); | 84 | setError(ERR_ITEMDELETE); | ||
70 | setJobErrorText(deleteJob->errorText()); | 85 | setJobErrorText(deleteJob->errorText()); | ||
71 | setJobError(deleteJob->error()); | 86 | setJobError(deleteJob->error()); | ||
72 | setErrorTextFromDavError(); | 87 | setErrorTextFromDavError(); | ||
73 | } | 88 | } | ||
74 | 89 | | |||
75 | if (hasConflict()) { | 90 | if (hasConflict()) { | ||
76 | DavItemFetchJob *fetchJob = new DavItemFetchJob(mItem); | 91 | DavItemFetchJob *fetchJob = new DavItemFetchJob(d->mItem); | ||
77 | connect(fetchJob, &DavItemFetchJob::result, this, &DavItemDeleteJob::conflictingItemFetched); | 92 | connect(fetchJob, &DavItemFetchJob::result, this, &DavItemDeleteJob::conflictingItemFetched); | ||
78 | fetchJob->start(); | 93 | fetchJob->start(); | ||
79 | return; | 94 | return; | ||
80 | } | 95 | } | ||
81 | } | 96 | } | ||
82 | 97 | | |||
83 | emitResult(); | 98 | emitResult(); | ||
84 | } | 99 | } | ||
85 | 100 | | |||
86 | void DavItemDeleteJob::conflictingItemFetched(KJob *job) | 101 | void DavItemDeleteJob::conflictingItemFetched(KJob *job) | ||
87 | { | 102 | { | ||
103 | Q_D(DavItemDeleteJob); | ||||
88 | DavItemFetchJob *fetchJob = qobject_cast<DavItemFetchJob *>(job); | 104 | DavItemFetchJob *fetchJob = qobject_cast<DavItemFetchJob *>(job); | ||
89 | mFreshResponseCode = fetchJob->latestResponseCode(); | 105 | d->mFreshResponseCode = fetchJob->latestResponseCode(); | ||
90 | 106 | | |||
91 | if (!job->error()) { | 107 | if (!job->error()) { | ||
92 | mFreshItem = fetchJob->item(); | 108 | d->mFreshItem = fetchJob->item(); | ||
93 | } | 109 | } | ||
94 | 110 | | |||
95 | emitResult(); | 111 | emitResult(); | ||
96 | } | 112 | } |