File indexing completed on 2024-11-24 04:44:28
0001 /* 0002 This file is part of oxaccess. 0003 0004 SPDX-FileCopyrightText: 2009 Tobias Koenig <tokoe@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.0-or-later 0007 */ 0008 0009 #include "folderdeletejob.h" 0010 0011 #include "davmanager.h" 0012 #include "davutils.h" 0013 #include "oxutils.h" 0014 0015 #include <KIO/DavJob> 0016 using namespace OXA; 0017 0018 FolderDeleteJob::FolderDeleteJob(const Folder &folder, QObject *parent) 0019 : KJob(parent) 0020 , mFolder(folder) 0021 { 0022 } 0023 0024 void FolderDeleteJob::start() 0025 { 0026 QDomDocument document; 0027 QDomElement propertyupdate = DAVUtils::addDavElement(document, document, QStringLiteral("propertyupdate")); 0028 QDomElement set = DAVUtils::addDavElement(document, propertyupdate, QStringLiteral("set")); 0029 QDomElement prop = DAVUtils::addDavElement(document, set, QStringLiteral("prop")); 0030 DAVUtils::addOxElement(document, prop, QStringLiteral("object_id"), OXUtils::writeNumber(mFolder.objectId())); 0031 DAVUtils::addOxElement(document, prop, QStringLiteral("method"), OXUtils::writeString(QStringLiteral("DELETE"))); 0032 DAVUtils::addOxElement(document, prop, QStringLiteral("last_modified"), OXUtils::writeString(mFolder.lastModified())); 0033 0034 const QString path = QStringLiteral("/servlet/webdav.folders"); 0035 0036 KIO::DavJob *job = DavManager::self()->createPatchJob(path, document); 0037 connect(job, &KIO::DavJob::result, this, &FolderDeleteJob::davJobFinished); 0038 } 0039 0040 void FolderDeleteJob::davJobFinished(KJob *job) 0041 { 0042 if (job->error()) { 0043 setError(job->error()); 0044 setErrorText(job->errorText()); 0045 emitResult(); 0046 return; 0047 } 0048 0049 auto davJob = qobject_cast<KIO::DavJob *>(job); 0050 0051 const QByteArray ba = davJob->responseData(); 0052 QDomDocument document; 0053 document.setContent(ba); 0054 QString errorText, errorStatus; 0055 if (DAVUtils::davErrorOccurred(document, errorText, errorStatus)) { 0056 setError(UserDefinedError); 0057 setErrorText(errorText); 0058 emitResult(); 0059 return; 0060 } 0061 0062 emitResult(); 0063 } 0064 0065 #include "moc_folderdeletejob.cpp"