Kgapi

tasklistdeletejob.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 "tasklistdeletejob.h"
10#include "private/queuehelper_p.h"
11#include "tasklist.h"
12#include "tasksservice.h"
13
14#include <QNetworkRequest>
15
16using namespace KGAPI2;
17
18class Q_DECL_HIDDEN TaskListDeleteJob::Private
19{
20public:
21 Private(TaskListDeleteJob *parent);
22 void processNextTaskList();
23
24 QueueHelper<QString> taskListsIds;
25
26private:
27 TaskListDeleteJob *const q;
28};
29
30TaskListDeleteJob::Private::Private(TaskListDeleteJob *parent)
31 : q(parent)
32{
33}
34
35void TaskListDeleteJob::Private::processNextTaskList()
36{
37 if (taskListsIds.atEnd()) {
38 q->emitFinished();
39 return;
40 }
41
42 const QString taskListId = taskListsIds.current();
43 const QUrl url = TasksService::removeTaskListUrl(taskListId);
44 QNetworkRequest request(url);
45
46 QStringList headers;
47 const auto rawHeaderList = request.rawHeaderList();
48 headers.reserve(rawHeaderList.size());
49 for (const QByteArray &str : std::as_const(rawHeaderList)) {
50 headers << QLatin1StringView(str) + QLatin1StringView(": ") + QLatin1StringView(request.rawHeader(str));
51 }
52
53 q->enqueueRequest(request);
54}
55
58 , d(new Private(this))
59{
60 d->taskListsIds << taskList->uid();
61}
62
63TaskListDeleteJob::TaskListDeleteJob(const TaskListsList &taskLists, const AccountPtr &account, QObject *parent)
64 : DeleteJob(account, parent)
65 , d(new Private(this))
66{
67 d->taskListsIds.reserve(taskLists.size());
68 for (const TaskListPtr &taskList : taskLists) {
69 d->taskListsIds << taskList->uid();
70 }
71}
72
73TaskListDeleteJob::TaskListDeleteJob(const QStringList &taskListsIds, const AccountPtr &account, QObject *parent)
74 : DeleteJob(account, parent)
75 , d(new Private(this))
76{
77 d->taskListsIds = taskListsIds;
78}
79
80TaskListDeleteJob::TaskListDeleteJob(const QString &taskListsId, const AccountPtr &account, QObject *parent)
81 : DeleteJob(account, parent)
82 , d(new Private(this))
83{
84 d->taskListsIds << taskListsId;
85}
86
88
90{
91 d->processNextTaskList();
92}
93
95{
96 d->taskListsIds.currentProcessed();
97
98 KGAPI2::DeleteJob::handleReply(reply, rawData);
99}
100
101#include "moc_tasklistdeletejob.cpp"
Abstract superclass for all jobs that delete resources from Google.
Definition deletejob.h:25
void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::Job::handleReply implementation.
Definition deletejob.cpp:58
AccountPtr account() const
Returns account used to authenticate requests.
Definition job.cpp:436
virtual void emitFinished()
Emits Job::finished() signal.
Definition job.cpp:493
virtual void enqueueRequest(const QNetworkRequest &request, const QByteArray &data=QByteArray(), const QString &contentType=QString())
Enqueues request in dispatcher queue.
Definition job.cpp:513
A job to delete one or more tasklists from user's Google Calendar account.
TaskListDeleteJob(const TaskListPtr &taskList, const AccountPtr &account, QObject *parent)
Constructs a new job that will delete given taskList from user's Google Tasks account.
void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::Job::handleReply.
~TaskListDeleteJob() override
Destructor.
void start() override
KGAPI2::Job::start.
QUrl removeTaskListUrl(const QString &tasklistID)
Returns URL for deleting a tasklist.
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
void reserve(qsizetype size)
qsizetype size() const const
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:17:41 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.