Libkdav2

davitemdeletejob.cpp
1 /*
2  Copyright (c) 2010 Tobias Koenig <[email protected]>
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  GNU General Public License for more details.
13 
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
16  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 #include "davitemdeletejob.h"
20 
21 #include "davitemfetchjob.h"
22 #include "davmanager.h"
23 #include "daverror.h"
24 #include "davjob.h"
25 
26 using namespace KDAV2;
27 
29  : DavJobBase(parent), mItem(item), mFreshResponseCode(-1)
30 {
31 }
32 
34 {
35  DavJob *job = DavManager::self()->createDeleteJob(mItem.url().url());
36  connect(job, &DavJob::result, this, &DavItemDeleteJob::davJobFinished);
37 }
38 
40 {
41  return mFreshItem;
42 }
43 
45 {
46  return mFreshResponseCode;
47 }
48 
49 void DavItemDeleteJob::davJobFinished(KJob *job)
50 {
51  auto deleteJob = static_cast<DavJob *>(job);
52 
53  if (deleteJob->error()) {
54  const int responseCode = deleteJob->httpStatusCode();
55  if (responseCode != 404 && responseCode != 410) {
56  setErrorFromJob(deleteJob, ERR_ITEMDELETE);
57  }
58 
59  if (hasConflict()) {
60  DavItemFetchJob *fetchJob = new DavItemFetchJob(mItem);
61  connect(fetchJob, &DavItemFetchJob::result, this, &DavItemDeleteJob::conflictingItemFetched);
62  fetchJob->start();
63  return;
64  }
65  }
66 
67  emitResult();
68 }
69 
70 void DavItemDeleteJob::conflictingItemFetched(KJob *job)
71 {
72  DavItemFetchJob *fetchJob = qobject_cast<DavItemFetchJob *>(job);
73  mFreshResponseCode = fetchJob->latestHttpStatusCode();
74 
75  if (!job->error()) {
76  mFreshItem = fetchJob->item();
77  }
78 
79  emitResult();
80 }
81 
void result(KJob *job)
static DavManager * self()
Returns the global instance of the DAV manager.
Definition: davmanager.cpp:52
void start() override
Starts the job.
base class for the jobs used by the resource.
Definition: davjobbase.h:37
int freshResponseCode() const
Returns the http response code we got when fetching the fresh item.
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
DavItemDeleteJob(const DavItem &item, QObject *parent=nullptr)
Creates a new dav item delete job.
DavJob * createDeleteJob(const QUrl &url)
Returns a preconfigured DAV DELETE job.
Definition: davmanager.cpp:80
DavItem item() const
Returns the fetched item including current etag information.
unsigned int latestHttpStatusCode() const
Get the latest http status code.
Definition: davjobbase.cpp:39
DavUrl url() const
Returns the url that identifies the item.
Definition: davitem.cpp:84
bool hasConflict() const
Check if the job failed because of a conflict.
Definition: davjobbase.cpp:77
void start() override
Starts the job.
A helper class to store information about DAV resources.
Definition: davitem.h:51
void setErrorFromJob(DavJob *, ErrorNumber jobErrorCode=ERR_PROBLEM_WITH_REQUEST)
Set the error of this job from a failed DavJob (executed by this job).
Definition: davjobbase.cpp:99
A job that fetches a DAV item from the DAV server.
void emitResult()
int error() const
QUrl url() const
Returns the url that identifies the DAV object.
Definition: davurl.cpp:41
DavItem freshItem() const
Returns the item that triggered the conflict, if any.
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Mon Aug 15 2022 04:07:29 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.