Kgapi

taskmovejob.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 "taskmovejob.h"
10#include "private/queuehelper_p.h"
11#include "task.h"
12#include "tasksservice.h"
13
14#include <QNetworkReply>
15#include <QNetworkRequest>
16
17using namespace KGAPI2;
18
19class Q_DECL_HIDDEN TaskMoveJob::Private
20{
21public:
22 Private(TaskMoveJob *parent);
23 void processNextTask();
24
25 QueueHelper<QString> tasksIds;
26 QString taskListId;
27 QString newParentId;
28
29private:
30 TaskMoveJob *const q;
31};
32
33TaskMoveJob::Private::Private(TaskMoveJob *parent)
34 : q(parent)
35{
36}
37
38void TaskMoveJob::Private::processNextTask()
39{
40 if (tasksIds.atEnd()) {
41 q->emitFinished();
42 return;
43 }
44
45 const QString taskId = tasksIds.current();
46 const QUrl url = TasksService::moveTaskUrl(taskListId, taskId, newParentId);
47 QNetworkRequest request(url);
48
49 QStringList headers;
50 const auto rawHeaderList = request.rawHeaderList();
51 headers.reserve(rawHeaderList.size());
52 for (const QByteArray &str : std::as_const(rawHeaderList)) {
53 headers << QLatin1StringView(str) + QLatin1StringView(": ") + QLatin1StringView(request.rawHeader(str));
54 }
55
56 q->enqueueRequest(request);
57}
58
59TaskMoveJob::TaskMoveJob(const TaskPtr &task, const QString &taskListId, const QString &newParentId, const AccountPtr &account, QObject *parent)
61 , d(new Private(this))
62{
63 d->tasksIds << task->uid();
64 d->taskListId = taskListId;
65 d->newParentId = newParentId;
66}
67
68TaskMoveJob::TaskMoveJob(const TasksList &tasks, const QString &taskListId, const QString &newParentId, const AccountPtr &account, QObject *parent)
69 : ModifyJob(account, parent)
70 , d(new Private(this))
71{
72 d->tasksIds.reserve(tasks.size());
73 for (const TaskPtr &task : tasks) {
74 d->tasksIds << task->uid();
75 }
76 d->taskListId = taskListId;
77 d->newParentId = newParentId;
78}
79
80TaskMoveJob::TaskMoveJob(const QString &taskId, const QString &taskListId, const QString &newParentId, const AccountPtr &account, QObject *parent)
81 : ModifyJob(account, parent)
82 , d(new Private(this))
83{
84 d->tasksIds << taskId;
85 d->taskListId = taskListId;
86 d->newParentId = newParentId;
87}
88
89TaskMoveJob::TaskMoveJob(const QStringList &tasksIds, const QString &taskListId, const QString &newParentId, const AccountPtr &account, QObject *parent)
90 : ModifyJob(account, parent)
91 , d(new Private(this))
92{
93 d->tasksIds = tasksIds;
94 d->taskListId = taskListId;
95 d->newParentId = newParentId;
96}
97
99
101{
102 d->processNextTask();
103}
104
105void TaskMoveJob::dispatchRequest(QNetworkAccessManager *accessManager, const QNetworkRequest &request, const QByteArray &data, const QString &contentType)
106{
107 Q_UNUSED(data)
108 Q_UNUSED(contentType)
109
110 accessManager->post(request, QByteArray());
111}
112
113void TaskMoveJob::handleReply(const QNetworkReply *reply, const QByteArray &rawData)
114{
115 Q_UNUSED(reply)
116 Q_UNUSED(rawData)
117
118 d->tasksIds.currentProcessed();
119 d->processNextTask();
120}
121
122#include "moc_taskmovejob.cpp"
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
Abstract superclass for all jobs that somehow modify resources on Google.
Definition modifyjob.h:25
A job that can reparent tasks to become subtasks of another task.
Definition taskmovejob.h:26
TaskMoveJob(const TaskPtr &task, const QString &taskListId, const QString &newParentId, const AccountPtr &account, QObject *parent=nullptr)
Constructs a job that will move given task in a tasklist with given taskListId to be a subtask of ano...
void dispatchRequest(QNetworkAccessManager *accessManager, const QNetworkRequest &request, const QByteArray &data, const QString &contentType) override
KGAPI2::Job::dispatchRequest implementation.
void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::Job::handleReply implementation.
void start() override
KGAPI2::Job::start implementation.
~TaskMoveJob() override
Destructor.
QUrl moveTaskUrl(const QString &tasklistID, const QString &taskID, const QString &newParent)
Returns URL to reparent task.
A job to fetch a single map tile described by a StaticMapUrl.
Definition blog.h:16
void reserve(qsizetype size)
qsizetype size() const const
QNetworkReply * post(const QNetworkRequest &request, QHttpMultiPart *multiPart)
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sat Dec 21 2024 17:00:12 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.