Kgapi

eventdeletejob.cpp
1 /*
2  * This file is part of LibKGAPI library
3  *
4  * SPDX-FileCopyrightText: 2013 Daniel Vrátil <[email protected]>
5  *
6  * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
7  */
8 
9 #include "eventdeletejob.h"
10 #include "calendarservice.h"
11 #include "account.h"
12 #include "../debug.h"
13 #include "event.h"
14 #include "private/queuehelper_p.h"
15 
16 #include <QNetworkRequest>
17 
18 using namespace KGAPI2;
19 
20 class Q_DECL_HIDDEN EventDeleteJob::Private
21 {
22  public:
23  QueueHelper<QString> eventsIds;
24  QString calendarId;
25 };
26 
27 EventDeleteJob::EventDeleteJob(const EventPtr& event, const QString &calendarId, const AccountPtr& account, QObject* parent):
28  DeleteJob(account, parent),
29  d(new Private)
30 {
31  d->eventsIds << event->id();
32  d->calendarId = calendarId;
33 }
34 
36  DeleteJob(account, parent),
37  d(new Private)
38 {
39  for (const EventPtr &event : events) {
40  d->eventsIds << event->id();
41  }
42  d->calendarId = calendarId;
43 }
44 
45 EventDeleteJob::EventDeleteJob(const QString &eventId, const QString &calendarId, const AccountPtr &account, QObject *parent):
46  DeleteJob(account, parent),
47  d(new Private)
48 {
49  d->eventsIds << eventId;
50  d->calendarId = calendarId;
51 }
52 
53 EventDeleteJob::EventDeleteJob(const QStringList &eventIds, const QString &calendarId, const AccountPtr &account, QObject *parent):
54  DeleteJob(account, parent),
55  d(new Private)
56 {
57  d->eventsIds = eventIds;
58  d->calendarId = calendarId;
59 }
60 
61 
63 
65 {
66  if (d->eventsIds.atEnd()) {
67  emitFinished();
68  return;
69  }
70 
71  const QString eventId = d->eventsIds.current();
72  const auto request = CalendarService::prepareRequest(CalendarService::removeEventUrl(d->calendarId, eventId));
73 
74  enqueueRequest(request);
75 }
76 
77 void EventDeleteJob::handleReply(const QNetworkReply* reply, const QByteArray& rawData)
78 {
79  d->eventsIds.currentProcessed();
80 
81  KGAPI2::DeleteJob::handleReply(reply, rawData);
82 }
83 
84 
85 
QUrl removeEventUrl(const QString &calendarID, const QString &eventID)
Returns URL for removing events.
QNetworkRequest prepareRequest(const QUrl &url)
Preparse a QNetworkRequest for given URL.
AccountPtr account() const
Returns account used to authenticate requests.
Definition: job.cpp:425
void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::Job::handleReply implementation.
void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::Job::handleReply implementation.
Definition: deletejob.cpp:59
virtual bool event(QEvent *e)
virtual void enqueueRequest(const QNetworkRequest &request, const QByteArray &data=QByteArray(), const QString &contentType=QString())
Enqueues request in dispatcher queue.
Definition: job.cpp:497
A job to fetch a single map tile described by a StaticMapUrl.
Definition: blog.h:15
Abstract superclass for all jobs that delete resources from Google.
Definition: deletejob.h:23
A job to delete one or more events from calendar in user&#39;s Google Calendar account.
virtual void emitFinished()
Emits Job::finished() signal.
Definition: job.cpp:479
~EventDeleteJob() override
Destructor.
void start() override
KGAPI2::Job::start implementation.
EventDeleteJob(const EventPtr &event, const QString &calendarId, const AccountPtr &account, QObject *parent)
Constructs a new job that will delete given event from a calendar with given calendarId.
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2021 The KDE developers.
Generated on Fri Jun 18 2021 23:10:47 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.