Kgapi

eventmovejob.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 "eventmovejob.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 EventMoveJob::Private
21{
22public:
23 QueueHelper<QString> eventsIds;
24 QString source;
25 QString destination;
26};
27
29 const QString &sourceCalendarId,
30 const QString &destinationCalendarId,
31 const AccountPtr &account,
32 QObject *parent)
33 : ModifyJob(account, parent)
34 , d(new Private())
35{
36 d->eventsIds << event->id();
37 d->source = sourceCalendarId;
38 d->destination = destinationCalendarId;
39}
40
42 const QString &sourceCalendarId,
43 const QString &destinationCalendarId,
44 const AccountPtr &account,
45 QObject *parent)
46 : ModifyJob(account, parent)
47 , d(new Private())
48{
49 for (const EventPtr &event : events) {
50 d->eventsIds << event->id();
51 }
52 d->source = sourceCalendarId;
53 d->destination = destinationCalendarId;
54}
55
57 const QString &sourceCalendarId,
58 const QString &destinationCalendarId,
59 const AccountPtr &account,
60 QObject *parent)
61 : ModifyJob(account, parent)
62 , d(new Private())
63{
64 d->eventsIds << eventId;
65 d->source = sourceCalendarId;
66 d->destination = destinationCalendarId;
67}
68
70 const QString &sourceCalendarId,
71 const QString &destinationCalendarId,
72 const AccountPtr &account,
73 QObject *parent)
74 : ModifyJob(account, parent)
75 , d(new Private())
76{
77 d->eventsIds = eventsIds;
78 d->source = sourceCalendarId;
79 d->destination = destinationCalendarId;
80}
81
83
85{
86 if (d->eventsIds.atEnd()) {
88 return;
89 }
90
91 const QString eventId = d->eventsIds.current();
92 const auto request = CalendarService::prepareRequest(CalendarService::moveEventUrl(d->source, d->destination, eventId));
93
94 enqueueRequest(request);
95}
96
97void EventMoveJob::dispatchRequest(QNetworkAccessManager *accessManager, const QNetworkRequest &request, const QByteArray &data, const QString &contentType)
98{
99 Q_UNUSED(data)
100 Q_UNUSED(contentType)
101
102 accessManager->post(request, QByteArray());
103}
104
106{
107 const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString();
108 ContentType ct = Utils::stringToContentType(contentType);
110 if (ct != KGAPI2::JSON) {
112 setErrorString(tr("Invalid response content type"));
113 emitFinished();
114 return items;
115 }
116
118 d->eventsIds.currentProcessed();
119 // Enqueue next item or finish
120 start();
121
122 return items;
123}
A job that moves events between given calendars.
void start() override
KGAPI2::Job::start implementation.
void dispatchRequest(QNetworkAccessManager *accessManager, const QNetworkRequest &request, const QByteArray &data, const QString &contentType) override
KGAPI2::Job::dispatchRequest implementation.
KGAPI2::ObjectsList handleReplyWithItems(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::Job::handleReplyWithItems implementation.
~EventMoveJob() override
Destructor.
EventMoveJob(const EventPtr &event, const QString &sourceCalendarId, const QString &destinationCalendarId, const AccountPtr &account, QObject *parent=nullptr)
Constructs a job that will move given event from a calendar with sourceCalendarId to calendar with de...
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
QUrl moveEventUrl(const QString &sourceCalendar, const QString &destCalendar, const QString &eventID)
Returns URL for moving event between calendars.
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
@ InvalidResponse
LibKGAPI error - Google returned invalid response.
Definition types.h:183
ContentType
Definition types.h:210
QNetworkReply * post(const QNetworkRequest &request, QHttpMultiPart *multiPart)
QVariant header(QNetworkRequest::KnownHeaders header) const const
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 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.