File indexing completed on 2024-06-16 04:52:27

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 "davitemfetchjob.h"
0020 
0021 #include "davmanager.h"
0022 #include "daverror.h"
0023 #include "davjob.h"
0024 
0025 using namespace KDAV2;
0026 
0027 DavItemFetchJob::DavItemFetchJob(const DavItem &item, QObject *parent)
0028     : DavJobBase(parent), mItem(item)
0029 {
0030 }
0031 
0032 void DavItemFetchJob::start()
0033 {
0034     auto job = DavManager::self()->createGetJob(mItem.url().url());
0035     connect(job, &DavJob::result, this, &DavItemFetchJob::davJobFinished);
0036 }
0037 
0038 DavItem DavItemFetchJob::item() const
0039 {
0040     return mItem;
0041 }
0042 
0043 void DavItemFetchJob::davJobFinished(KJob *job)
0044 {
0045     auto *storedJob = static_cast<DavJob*>(job);
0046     if (storedJob->error()) {
0047         setErrorFromJob(storedJob);
0048     } else {
0049         mItem.setData(storedJob->data());
0050         mItem.setContentType(storedJob->getContentTypeHeader());
0051         mItem.setEtag(storedJob->getETagHeader());
0052     }
0053 
0054     emitResult();
0055 }
0056