Kgapi

calendarmodifyjob.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 "calendarmodifyjob.h"
10#include "calendar.h"
11#include "calendarservice.h"
12#include "private/queuehelper_p.h"
13#include "utils.h"
14
15#include <QNetworkReply>
16#include <QNetworkRequest>
17
18using namespace KGAPI2;
19
20class Q_DECL_HIDDEN CalendarModifyJob::Private
21{
22public:
23 QueueHelper<CalendarPtr> calendars;
24};
25
26CalendarModifyJob::CalendarModifyJob(const CalendarPtr &calendar, const AccountPtr &account, QObject *parent)
27 : ModifyJob(account, parent)
28 , d(new Private)
29{
30 d->calendars << calendar;
31}
32
33CalendarModifyJob::CalendarModifyJob(const CalendarsList &calendars, const AccountPtr &account, QObject *parent)
34 : ModifyJob(account, parent)
35 , d(new Private)
36{
37 d->calendars = calendars;
38}
39
41
43{
44 if (d->calendars.atEnd()) {
46 return;
47 }
48
49 const CalendarPtr calendar = d->calendars.current();
50 const auto request = CalendarService::prepareRequest(CalendarService::updateCalendarUrl(calendar->uid()));
51 const QByteArray rawData = CalendarService::calendarToJSON(calendar);
52
53 enqueueRequest(request, rawData, QStringLiteral("application/json"));
54}
55
57{
58 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
59 ContentType ct = Utils::stringToContentType(contentType);
61 if (ct != KGAPI2::JSON) {
63 setErrorString(tr("Invalid response content type"));
65 return items;
66 }
67
69 d->calendars.currentProcessed();
70 // Enqueue next item or finish
71 start();
72
73 return items;
74}
A job to modify calendars on user's Google Calendar account.
~CalendarModifyJob() override
Destructor.
void start() override
KGAPI2::Job::start implementation.
ObjectsList handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::ModifyJob::handleReplyWithItems implementation.
CalendarModifyJob(const CalendarPtr &calendar, const AccountPtr &account, QObject *parent=nullptr)
Constructs a job that will write changes in given calendar to corresponding calendar on user's Google...
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
Abstract superclass for all jobs that somehow modify resources on Google.
Definition modifyjob.h:25
ObjectsList items() const
Definition modifyjob.cpp:43
Base class for all objects.
Definition object.h:31
QUrl updateCalendarUrl(const QString &calendarID)
Returns URL for updating existing 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 Dec 20 2024 11:59:22 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.