Kgapi

taskdeletejob.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 
10 #include "taskdeletejob.h"
11 #include "tasksservice.h"
12 #include "account.h"
13 #include "../debug.h"
14 #include "task.h"
15 #include "utils.h"
16 #include "private/queuehelper_p.h"
17 
18 #include <QNetworkRequest>
19 
20 using namespace KGAPI2;
21 
22 class Q_DECL_HIDDEN TaskDeleteJob::Private
23 {
24  public:
25  QueueHelper<QString> tasksIds;
26  QString taskListId;
27 };
28 
29 TaskDeleteJob::TaskDeleteJob(const TaskPtr& task, const QString& taskListId,
30  const AccountPtr& account, QObject* parent):
31  DeleteJob(account, parent),
32  d(new Private())
33 {
34  d->tasksIds << task->uid();
35  d->taskListId = taskListId;
36 }
37 
38 TaskDeleteJob::TaskDeleteJob(const TasksList& tasks, const QString& tasklistId,
39  const AccountPtr& account, QObject* parent):
40  DeleteJob(account, parent),
41  d(new Private())
42 {
43  d->tasksIds.reserve(tasks.size());
44  for (const TaskPtr &task : qAsConst(tasks)) {
45  d->tasksIds << task->uid();
46  }
47  d->taskListId = tasklistId;
48 }
49 
50 TaskDeleteJob::TaskDeleteJob(const QString &taskId, const QString &taskListId,
51  const AccountPtr &account, QObject *parent):
52  DeleteJob(account, parent),
53  d(new Private())
54 {
55  d->tasksIds << taskId;
56  d->taskListId = taskListId;
57 }
58 
59 TaskDeleteJob::TaskDeleteJob(const QStringList &tasksIds, const QString &taskListId,
60  const AccountPtr &account, QObject *parent):
61  DeleteJob(account, parent),
62  d(new Private())
63 {
64  d->tasksIds = tasksIds;
65  d->taskListId = taskListId;
66 }
67 
69 
71 {
72  if (d->tasksIds.atEnd()) {
73  emitFinished();
74  return;
75  }
76 
77  const QString taskId = d->tasksIds.current();
78  const QUrl url = TasksService::removeTaskUrl(d->taskListId, taskId);
79  QNetworkRequest request(url);
80 
81  enqueueRequest(request);
82 }
83 
84 void TaskDeleteJob::handleReply(const QNetworkReply* reply, const QByteArray& rawData)
85 {
86  d->tasksIds.currentProcessed();
87 
88  KGAPI2::DeleteJob::handleReply(reply, rawData);
89 }
90 
91 
AccountPtr account() const
Returns account used to authenticate requests.
Definition: job.cpp:423
~TaskDeleteJob() override
Destructor.
void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::Job::handleReply implementation.
Definition: deletejob.cpp:59
void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::Job::handleReply implementation.
int size() const const
QUrl removeTaskUrl(const QString &tasklistID, const QString &taskID)
Returns URL for removing a task.
virtual void enqueueRequest(const QNetworkRequest &request, const QByteArray &data=QByteArray(), const QString &contentType=QString())
Enqueues request in dispatcher queue.
Definition: job.cpp:495
A job to fetch a single map tile described by a StaticMapUrl.
Definition: blog.h:16
Abstract superclass for all jobs that delete resources from Google.
Definition: deletejob.h:24
virtual void emitFinished()
Emits Job::finished() signal.
Definition: job.cpp:477
A job to delete one or more tasks from tasklist in user&#39;s Google Tasks account.
Definition: taskdeletejob.h:29
void start() override
KGAPI2::Job::start implementation.
QObject * parent() const const
TaskDeleteJob(const TaskPtr &task, const QString &taskListId, const AccountPtr &account, QObject *parent=nullptr)
Constructs a new job that will delete given task from a tasklist with given taskListId.
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jul 10 2020 23:08:03 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.