Libkdav2

davitemfetchjob.cpp
1 /*
2  Copyright (c) 2010 Tobias Koenig <[email protected]>
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 
25 using 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 
43 void 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 
QUrl url() const
Returns the url that identifies the DAV object.
Definition: davurl.cpp:41
void setData(const QByteArray &data)
Sets the raw content data of the item.
Definition: davitem.cpp:99
void emitResult()
static DavManager * self()
Returns the global instance of the DAV manager.
Definition: davmanager.cpp:52
base class for the jobs used by the resource.
Definition: davjobbase.h:37
void setEtag(const QString &etag)
Sets the etag of the item.
Definition: davitem.cpp:109
void setContentType(const QString &type)
Sets the content type of the item.
Definition: davitem.cpp:89
void start() override
Starts the job.
DavUrl url() const
Returns the url that identifies the item.
Definition: davitem.cpp:84
DavItemFetchJob(const DavItem &item, QObject *parent=nullptr)
Creates a new dav item fetch job.
A helper class to store information about DAV resources.
Definition: davitem.h:51
DavItem item() const
Returns the fetched item including current etag information.
DavJob * createGetJob(const QUrl &url)
Returns a preconfigured DAV GET job.
Definition: davmanager.cpp:88
QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Sep 25 2020 23:20:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.