File indexing completed on 2024-11-17 04:44:01
0001 /* 0002 Copyright (c) 2010 Tobias Koenig <tokoe@kde.org> 0003 0004 This program is free software; you can redistribute it and/or modify 0005 it under the terms of the GNU General Public License as published by 0006 the Free Software Foundation; either version 2 of the License, or 0007 (at your option) any later version. 0008 0009 This program is distributed in the hope that it will be useful, 0010 but WITHOUT ANY WARRANTY; without even the implied warranty of 0011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0012 GNU General Public License for more details. 0013 0014 You should have received a copy of the GNU General Public License 0015 along with this program; if not, write to the Free Software 0016 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 0017 */ 0018 0019 #include "davitemdeletejob.h" 0020 0021 #include "davitemfetchjob.h" 0022 #include "davmanager.h" 0023 #include "daverror.h" 0024 #include "davjob.h" 0025 0026 using namespace KDAV2; 0027 0028 DavItemDeleteJob::DavItemDeleteJob(const DavItem &item, QObject *parent) 0029 : DavJobBase(parent), mItem(item), mFreshResponseCode(-1) 0030 { 0031 } 0032 0033 void DavItemDeleteJob::start() 0034 { 0035 DavJob *job = DavManager::self()->createDeleteJob(mItem.url().url()); 0036 connect(job, &DavJob::result, this, &DavItemDeleteJob::davJobFinished); 0037 } 0038 0039 DavItem DavItemDeleteJob::freshItem() const 0040 { 0041 return mFreshItem; 0042 } 0043 0044 int DavItemDeleteJob::freshResponseCode() const 0045 { 0046 return mFreshResponseCode; 0047 } 0048 0049 void DavItemDeleteJob::davJobFinished(KJob *job) 0050 { 0051 auto deleteJob = static_cast<DavJob *>(job); 0052 0053 if (deleteJob->error()) { 0054 const int responseCode = deleteJob->httpStatusCode(); 0055 if (responseCode != 404 && responseCode != 410) { 0056 setErrorFromJob(deleteJob, ERR_ITEMDELETE); 0057 } 0058 0059 if (hasConflict()) { 0060 DavItemFetchJob *fetchJob = new DavItemFetchJob(mItem); 0061 connect(fetchJob, &DavItemFetchJob::result, this, &DavItemDeleteJob::conflictingItemFetched); 0062 fetchJob->start(); 0063 return; 0064 } 0065 } 0066 0067 emitResult(); 0068 } 0069 0070 void DavItemDeleteJob::conflictingItemFetched(KJob *job) 0071 { 0072 DavItemFetchJob *fetchJob = qobject_cast<DavItemFetchJob *>(job); 0073 mFreshResponseCode = fetchJob->latestHttpStatusCode(); 0074 0075 if (!job->error()) { 0076 mFreshItem = fetchJob->item(); 0077 } 0078 0079 emitResult(); 0080 } 0081