Kgapi

calendarfetchjob.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 "calendarfetchjob.h"
10#include "account.h"
11#include "calendar.h"
12#include "calendarservice.h"
13#include "debug.h"
14#include "utils.h"
15
16#include <QNetworkReply>
17#include <QNetworkRequest>
18
19using namespace KGAPI2;
20
21class Q_DECL_HIDDEN CalendarFetchJob::Private
22{
23public:
24 QString calendarId;
25};
26
28 : FetchJob(account, parent)
29 , d(new Private())
30{
31}
32
33CalendarFetchJob::CalendarFetchJob(const QString &calendarId, const AccountPtr &account, QObject *parent)
34 : FetchJob(account, parent)
35 , d(new Private())
36{
37 d->calendarId = calendarId;
38}
39
41
43{
44 QUrl url;
45 if (d->calendarId.isEmpty()) {
47 } else {
48 url = CalendarService::fetchCalendarUrl(d->calendarId);
49 }
50 const auto request = CalendarService::prepareRequest(url);
51 enqueueRequest(request);
52}
53
55{
56 FeedData feedData;
57 feedData.requestUrl = reply->request().url();
58
60 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
61 ContentType ct = Utils::stringToContentType(contentType);
62 if (ct == KGAPI2::JSON) {
63 if (d->calendarId.isEmpty()) {
65 } else {
67 }
68 } else {
70 setErrorString(tr("Invalid response content type"));
72 return items;
73 }
74
75 if (feedData.nextPageUrl.isValid()) {
76 const auto request = CalendarService::prepareRequest(feedData.nextPageUrl);
77 enqueueRequest(request);
78 }
79
80 return items;
81}
A job to fetch calendars from user's Google Calendar account.
CalendarFetchJob(const AccountPtr &account, QObject *parent=nullptr)
Constructs a job that will fetch all calendars from user's Google Calendar account.
~CalendarFetchJob() override
Destructor.
ObjectsList handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::FetchJob::handleReplyWithItems implementation.
void start() override
KGAPI2::Job::start implementation.
Structure to store additional information about a feed.
Definition types.h:24
QUrl requestUrl
Original URL of the request.
Definition types.h:39
QUrl nextPageUrl
Link to next page of feed.
Definition types.h:38
Abstract superclass for all jobs that fetch resources from Google.
Definition fetchjob.h:25
virtual ObjectsList items() const
Returns all items fetched by this job.
Definition fetchjob.cpp:41
void setErrorString(const QString &errorString)
Set job error description to errorString.
Definition job.cpp:401
virtual void emitFinished()
Emits Job::finished() signal.
Definition job.cpp:493
void setError(KGAPI2::Error error)
Set job error to error.
Definition job.cpp:386
virtual void enqueueRequest(const QNetworkRequest &request, const QByteArray &data=QByteArray(), const QString &contentType=QString())
Enqueues request in dispatcher queue.
Definition job.cpp:513
QUrl fetchCalendarsUrl()
Returns URL for fetching calendars list.
QUrl fetchCalendarUrl(const QString &calendarID)
Returns URL for fetching single calendar.
CalendarPtr JSONToCalendar(const QByteArray &jsonData)
Parses calendar JSON data into Calendar object.
QNetworkRequest prepareRequest(const QUrl &url)
Preparse a QNetworkRequest for given URL.
ObjectsList parseCalendarJSONFeed(const QByteArray &jsonFeed, FeedData &feedData)
Parses JSON feed into list of Calendars.
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
@ InvalidResponse
LibKGAPI error - Google returned invalid response.
Definition types.h:183
ContentType
Definition types.h:210
QVariant header(QNetworkRequest::KnownHeaders header) const const
QNetworkRequest request() const const
QUrl url() const const
QString tr(const char *sourceText, const char *disambiguation, int n)
bool isValid() const const
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Jul 19 2024 11:58:17 by doxygen 1.11.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.