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 "foldersrequestjob.h" 0010 0011 #include "davmanager.h" 0012 #include "davutils.h" 0013 #include "folderutils.h" 0014 #include "oxutils.h" 0015 #include <KIO/DavJob> 0016 0017 using namespace OXA; 0018 0019 FoldersRequestJob::FoldersRequestJob(qulonglong lastSync, Mode mode, QObject *parent) 0020 : KJob(parent) 0021 , mLastSync(lastSync) 0022 , mMode(mode) 0023 { 0024 } 0025 0026 void FoldersRequestJob::start() 0027 { 0028 QDomDocument document; 0029 QDomElement multistatus = DAVUtils::addDavElement(document, document, QStringLiteral("multistatus")); 0030 QDomElement prop = DAVUtils::addDavElement(document, multistatus, QStringLiteral("prop")); 0031 DAVUtils::addOxElement(document, prop, QStringLiteral("lastsync"), OXUtils::writeNumber(mLastSync)); 0032 if (mMode == Modified) { 0033 DAVUtils::addOxElement(document, prop, QStringLiteral("objectmode"), QStringLiteral("MODIFIED")); 0034 } else { 0035 DAVUtils::addOxElement(document, prop, QStringLiteral("objectmode"), QStringLiteral("DELETED")); 0036 } 0037 0038 const QString path = QStringLiteral("/servlet/webdav.folders"); 0039 0040 KIO::DavJob *job = DavManager::self()->createFindJob(path, document); 0041 connect(job, &KIO::DavJob::result, this, &FoldersRequestJob::davJobFinished); 0042 } 0043 0044 Folder::List FoldersRequestJob::folders() const 0045 { 0046 return mFolders; 0047 } 0048 0049 void FoldersRequestJob::davJobFinished(KJob *job) 0050 { 0051 if (job->error()) { 0052 setError(job->error()); 0053 setErrorText(job->errorText()); 0054 emitResult(); 0055 return; 0056 } 0057 0058 auto davJob = qobject_cast<KIO::DavJob *>(job); 0059 0060 const QByteArray ba = davJob->responseData(); 0061 QDomDocument document; 0062 document.setContent(ba); 0063 0064 QString errorText, errorStatus; 0065 if (DAVUtils::davErrorOccurred(document, errorText, errorStatus)) { 0066 setError(UserDefinedError); 0067 setErrorText(errorText); 0068 emitResult(); 0069 return; 0070 } 0071 0072 QDomElement multistatus = document.documentElement(); 0073 QDomElement response = multistatus.firstChildElement(QStringLiteral("response")); 0074 while (!response.isNull()) { 0075 const QDomNodeList props = response.elementsByTagName(QStringLiteral("prop")); 0076 const QDomElement prop = props.at(0).toElement(); 0077 mFolders.append(FolderUtils::parseFolder(prop)); 0078 response = response.nextSiblingElement(); 0079 } 0080 0081 emitResult(); 0082 } 0083 0084 #include "moc_foldersrequestjob.cpp"