Kgapi

filefetchcontentjob.cpp
1/*
2 * This file is part of LibKGAPI library
3 *
4 * SPDX-FileCopyrightText: 2013 Daniel Vrátil <dvratil@redhat.com>
5 *
6 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7 */
8
9#include "filefetchcontentjob.h"
10#include "file.h"
11
12#include <QNetworkReply>
13#include <QNetworkRequest>
14
15using namespace KGAPI2;
16using namespace KGAPI2::Drive;
17
18class Q_DECL_HIDDEN FileFetchContentJob::Private
19{
20public:
21 Private(FileFetchContentJob *parent);
22
23 void _k_downloadProgress(qint64 downloaded, qint64 total);
24
25 QUrl url;
26 QByteArray fileData;
27
28private:
29 FileFetchContentJob *const q;
30};
31
32FileFetchContentJob::Private::Private(FileFetchContentJob *parent)
33 : q(parent)
34{
35}
36
37void FileFetchContentJob::Private::_k_downloadProgress(qint64 downloaded, qint64 total)
38{
39 q->emitProgress(downloaded, total);
40}
41
42FileFetchContentJob::FileFetchContentJob(const FilePtr &file, const AccountPtr &account, QObject *parent)
44 , d(new Private(this))
45{
46 d->url = file->downloadUrl();
47}
48
49FileFetchContentJob::FileFetchContentJob(const QUrl &url, const AccountPtr &account, QObject *parent)
50 : FetchJob(account, parent)
51 , d(new Private(this))
52{
53 d->url = url;
54}
55
56FileFetchContentJob::~FileFetchContentJob()
57{
58 delete d;
59}
60
61QByteArray FileFetchContentJob::data() const
62{
63 return d->fileData;
64}
65
66void FileFetchContentJob::start()
67{
68 QNetworkRequest request(d->url);
69 enqueueRequest(request);
70}
71
72void FileFetchContentJob::dispatchRequest(QNetworkAccessManager *accessManager,
73 const QNetworkRequest &request,
74 const QByteArray &data,
75 const QString &contentType)
76{
77 Q_UNUSED(data)
78 Q_UNUSED(contentType)
79
80 QNetworkReply *reply = accessManager->get(request);
81 connect(reply, &QNetworkReply::downloadProgress, this, [this](qint64 downloaded, qint64 total) {
82 d->_k_downloadProgress(downloaded, total);
83 });
84}
85
86void FileFetchContentJob::handleReply(const QNetworkReply *reply, const QByteArray &rawData)
87{
88 Q_UNUSED(reply)
89
90 d->fileData = rawData;
91}
92
93ObjectsList FileFetchContentJob::handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData)
94{
95 Q_UNUSED(reply)
96 Q_UNUSED(rawData)
97
98 return ObjectsList();
99}
100
101#include "moc_filefetchcontentjob.cpp"
Abstract superclass for all jobs that fetch resources from Google.
Definition fetchjob.h:25
virtual void emitProgress(int processed, int total)
Emit progress() signal.
Definition job.cpp:508
AccountPtr account() const
Returns account used to authenticate requests.
Definition job.cpp:436
virtual void enqueueRequest(const QNetworkRequest &request, const QByteArray &data=QByteArray(), const QString &contentType=QString())
Enqueues request in dispatcher queue.
Definition job.cpp:513
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
QNetworkReply * get(const QNetworkRequest &request)
void downloadProgress(qint64 bytesReceived, qint64 bytesTotal)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:11:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.