Kgapi

eventmodifyjob.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 "eventmodifyjob.h"
10#include "calendarservice.h"
11#include "event.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 EventModifyJob::Private
21{
22public:
23 QueueHelper<EventPtr> events;
24 QString calendarId;
25 SendUpdatesPolicy updatesPolicy = SendUpdatesPolicy::All;
26};
27
28EventModifyJob::EventModifyJob(const EventPtr &event, const QString &calendarId, const AccountPtr &account, QObject *parent)
29 : ModifyJob(account, parent)
30 , d(new Private)
31{
32 d->events << event;
33 d->calendarId = calendarId;
34}
35
36EventModifyJob::EventModifyJob(const EventsList &events, const QString &calendarId, const AccountPtr &account, QObject *parent)
37 : ModifyJob(account, parent)
38 , d(new Private)
39{
40 d->events = events;
41 d->calendarId = calendarId;
42}
43
45
46void EventModifyJob::setSendUpdates(KGAPI2::SendUpdatesPolicy updatesPolicy)
47{
48 if (d->updatesPolicy != updatesPolicy) {
49 d->updatesPolicy = updatesPolicy;
50 Q_EMIT sendUpdatesChanged(d->updatesPolicy);
51 }
52}
53
54SendUpdatesPolicy EventModifyJob::sendUpdates() const
55{
56 return d->updatesPolicy;
57}
58
60{
61 if (d->events.atEnd()) {
63 return;
64 }
65
66 const EventPtr event = d->events.current();
67 const auto request = CalendarService::prepareRequest(CalendarService::updateEventUrl(d->calendarId, event->id(), d->updatesPolicy));
69
70 enqueueRequest(request, rawData, QStringLiteral("application/json"));
71}
72
74{
75 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
76 ContentType ct = Utils::stringToContentType(contentType);
78 if (ct != KGAPI2::JSON) {
80 setErrorString(tr("Invalid response content type"));
82 return items;
83 }
84
86 d->events.currentProcessed();
87 // Enqueue next item or finish
88 start();
89
90 return items;
91}
A job to modify events in a calendar on user's Google Calendar account.
~EventModifyJob() override
Destructor.
EventModifyJob(const EventPtr &event, const QString &calendarId, const AccountPtr &account, QObject *parent=nullptr)
Constructs a job that will write changes in given event to corresponding event in calendar with given...
ObjectsList handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::ModifyJob::handleReplyWithItems implementation.
void start() override
KGAPI2::Job::start implementation.
Represents a single event from Google Calendar.
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
QByteArray eventToJSON(const EventPtr &event, EventSerializeFlags flags)
Serializes Event into JSON.
QUrl updateEventUrl(const QString &calendarID, const QString &eventID, SendUpdatesPolicy updatePolicy)
Returns URL for updating a single event.
QNetworkRequest prepareRequest(const QUrl &url)
Preparse a QNetworkRequest for given URL.
EventPtr JSONToEvent(const QByteArray &jsonData)
Parses event JSON into Event object.
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
SendUpdatesPolicy
Determines whether Google Calendar should send updates to participants.
Definition enums.h:22
@ InvalidResponse
LibKGAPI error - Google returned invalid response.
Definition types.h:183
ContentType
Definition types.h:210
QVariant header(QNetworkRequest::KnownHeaders header) const const
Q_EMITQ_EMIT
virtual bool event(QEvent *e)
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 6 2024 12:11:00 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.