Kgapi

calendarcreatejob.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 "calendarcreatejob.h"
10#include "account.h"
11#include "calendar.h"
12#include "calendarservice.h"
13#include "debug.h"
14#include "object.h"
15#include "private/queuehelper_p.h"
16#include "utils.h"
17
18#include <QNetworkReply>
19#include <QNetworkRequest>
20
21using namespace KGAPI2;
22
23class Q_DECL_HIDDEN CalendarCreateJob::Private
24{
25public:
26 QueueHelper<CalendarPtr> calendars;
27};
28
29CalendarCreateJob::CalendarCreateJob(const CalendarPtr &calendar, const AccountPtr &account, QObject *parent)
30 : CreateJob(account, parent)
31 , d(new Private)
32{
33 d->calendars << calendar;
34}
35
36CalendarCreateJob::CalendarCreateJob(const CalendarsList &calendars, const AccountPtr &account, QObject *parent)
37 : CreateJob(account, parent)
38 , d(new Private)
39{
40 d->calendars = calendars;
41}
42
44
46{
47 if (d->calendars.atEnd()) {
49 return;
50 }
51
52 const CalendarPtr calendar = d->calendars.current();
54 const QByteArray rawData = CalendarService::calendarToJSON(calendar);
55
56 enqueueRequest(request, rawData, QStringLiteral("application/json"));
57}
58
60{
61 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
62 ContentType ct = Utils::stringToContentType(contentType);
64 if (ct != KGAPI2::JSON) {
66 setErrorString(tr("Invalid response content type"));
68 return items;
69 }
70
72 d->calendars.currentProcessed();
73 start();
74
75 return items;
76}
A job to create one or more new calendars in user's Google Calendar account.
CalendarCreateJob(const CalendarPtr &calendar, const AccountPtr &account, QObject *parent=nullptr)
Constructs a job that will create given calendar in user's Google Calendar account.
~CalendarCreateJob() override
Destructor.
void start() override
KGAPI2::Job::start implementation.
ObjectsList handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::CreateJob::handleReplyWithItems implementation.
Abstract superclass for all jobs that create new objects on the server.
Definition createjob.h:26
virtual ObjectsList items() const
Definition createjob.cpp:40
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
Base class for all objects.
Definition object.h:31
QUrl createCalendarUrl()
Returns URL for creating a new calendar.
QByteArray calendarToJSON(const CalendarPtr &calendar)
Serializes calendar into JSON.
CalendarPtr JSONToCalendar(const QByteArray &jsonData)
Parses calendar JSON data into Calendar object.
QNetworkRequest prepareRequest(const QUrl &url)
Preparse a QNetworkRequest for given URL.
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
QString tr(const char *sourceText, const char *disambiguation, int n)
QSharedPointer< X > dynamicCast() const const
QString toString() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:08:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.