Libkdav2

davitemfetchjob.cpp
1/*
2 Copyright (c) 2010 Tobias Koenig <tokoe@kde.org>
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 "davitemfetchjob.h"
20
21#include "davmanager.h"
22#include "daverror.h"
23#include "davjob.h"
24
25using namespace KDAV2;
26
28 : DavJobBase(parent), mItem(item)
29{
30}
31
33{
34 auto job = DavManager::self()->createGetJob(mItem.url().url());
35 connect(job, &DavJob::result, this, &DavItemFetchJob::davJobFinished);
36}
37
39{
40 return mItem;
41}
42
43void DavItemFetchJob::davJobFinished(KJob *job)
44{
45 auto *storedJob = static_cast<DavJob*>(job);
46 if (storedJob->error()) {
47 setErrorFromJob(storedJob);
48 } else {
49 mItem.setData(storedJob->data());
50 mItem.setContentType(storedJob->getContentTypeHeader());
51 mItem.setEtag(storedJob->getETagHeader());
52 }
53
54 emitResult();
55}
56
DavItem item() const
Returns the fetched item including current etag information.
DavItemFetchJob(const DavItem &item, QObject *parent=nullptr)
Creates a new dav item fetch job.
void start() override
Starts the job.
A helper class to store information about DAV resources.
Definition davitem.h:52
DavUrl url() const
Returns the url that identifies the item.
Definition davitem.cpp:84
void setEtag(const QString &etag)
Sets the etag of the item.
Definition davitem.cpp:109
void setData(const QByteArray &data)
Sets the raw content data of the item.
Definition davitem.cpp:99
void setContentType(const QString &type)
Sets the content type of the item.
Definition davitem.cpp:89
base class for the jobs used by the resource.
Definition davjobbase.h:38
void setErrorFromJob(DavJob *, ErrorNumber jobErrorCode=ERR_PROBLEM_WITH_REQUEST)
Set the error of this job from a failed DavJob (executed by this job).
DavJob * createGetJob(const QUrl &url)
Returns a preconfigured DAV GET job.
static DavManager * self()
Returns the global instance of the DAV manager.
QUrl url() const
Returns the url that identifies the DAV object.
Definition davurl.cpp:41
void emitResult()
void result(KJob *job)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:00:37 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.