Kgapi

taskmovejob.cpp
1 /*
2  * This file is part of LibKGAPI library
3  *
4  * Copyright (C) 2013 Daniel Vrátil <[email protected]>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) version 3, or any
10  * later version accepted by the membership of KDE e.V. (or its
11  * successor approved by the membership of KDE e.V.), which shall
12  * act as a proxy defined in Section 6 of version 3 of the license.
13  *
14  * This library is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library. If not, see <https://www.gnu.org/licenses/>.
21  */
22 
23 #include "taskmovejob.h"
24 #include "tasksservice.h"
25 #include "account.h"
26 #include "../debug.h"
27 #include "task.h"
28 #include "utils.h"
29 #include "private/queuehelper_p.h"
30 
31 #include <QNetworkRequest>
32 #include <QNetworkReply>
33 
34 using namespace KGAPI2;
35 
36 class Q_DECL_HIDDEN TaskMoveJob::Private
37 {
38  public:
39  Private(TaskMoveJob *parent);
40  void processNextTask();
41 
42  QueueHelper<QString> tasksIds;
43  QString taskListId;
44  QString newParentId;
45 
46  private:
47  TaskMoveJob * const q;
48 };
49 
50 TaskMoveJob::Private::Private(TaskMoveJob *parent):
51  q(parent)
52 {
53 }
54 
55 void TaskMoveJob::Private::processNextTask()
56 {
57  if (tasksIds.atEnd()) {
58  q->emitFinished();
59  return;
60  }
61 
62  const QString taskId = tasksIds.current();
63  const QUrl url = TasksService::moveTaskUrl(taskListId, taskId, newParentId);
64  QNetworkRequest request(url);
65 
66  QStringList headers;
67  const auto rawHeaderList = request.rawHeaderList();
68  headers.reserve(rawHeaderList.size());
69  for (const QByteArray &str : qAsConst(rawHeaderList)) {
70  headers << QLatin1String(str) + QLatin1String(": ") + QLatin1String(request.rawHeader(str));
71  }
72 
73  q->enqueueRequest(request);
74 }
75 
76 TaskMoveJob::TaskMoveJob(const TaskPtr& task, const QString& taskListId,
77  const QString& newParentId, const AccountPtr& account,
78  QObject* parent):
79  ModifyJob(account, parent),
80  d(new Private(this))
81 {
82  d->tasksIds << task->uid();
83  d->taskListId = taskListId;
84  d->newParentId = newParentId;
85 }
86 
87 TaskMoveJob::TaskMoveJob(const TasksList& tasks, const QString& taskListId,
88  const QString& newParentId, const AccountPtr& account,
89  QObject* parent):
90  ModifyJob(account, parent),
91  d(new Private(this))
92 {
93  d->tasksIds.reserve(tasks.size());
94  for (const TaskPtr &task : tasks) {
95  d->tasksIds << task->uid();
96  }
97  d->taskListId = taskListId;
98  d->newParentId = newParentId;
99 }
100 
101 TaskMoveJob::TaskMoveJob(const QString &taskId, const QString &taskListId,
102  const QString &newParentId, const AccountPtr &account,
103  QObject *parent):
104  ModifyJob(account, parent),
105  d(new Private(this))
106 {
107  d->tasksIds << taskId;
108  d->taskListId = taskListId;
109  d->newParentId = newParentId;
110 }
111 
112 TaskMoveJob::TaskMoveJob(const QStringList &tasksIds, const QString &taskListId,
113  const QString &newParentId, const AccountPtr &account,
114  QObject *parent):
115  ModifyJob(account, parent),
116  d(new Private(this))
117 {
118  d->tasksIds = tasksIds;
119  d->taskListId = taskListId;
120  d->newParentId = newParentId;
121 }
122 
124 {
125  delete d;
126 }
127 
129 {
130  d->processNextTask();
131 }
132 
133 void TaskMoveJob::dispatchRequest(QNetworkAccessManager *accessManager, const QNetworkRequest &request, const QByteArray &data, const QString &contentType)
134 {
135  Q_UNUSED(data)
136  Q_UNUSED(contentType)
137 
138  accessManager->post(request, QByteArray());
139 }
140 
141 void TaskMoveJob::handleReply(const QNetworkReply *reply, const QByteArray& rawData)
142 {
143  Q_UNUSED(reply)
144  Q_UNUSED(rawData)
145 
146  d->tasksIds.currentProcessed();
147  d->processNextTask();
148 }
149 
150 
AccountPtr account() const
Returns account used to authenticate requests.
Definition: job.cpp:437
A job that can reparent tasks to become subtasks of another task.
Definition: taskmovejob.h:38
void start() override
KGAPI2::Job::start implementation.
void reserve(int alloc)
~TaskMoveJob() override
Destructor.
void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::Job::handleReply implementation.
int size() const const
QNetworkReply * post(const QNetworkRequest &request, QIODevice *data)
A job to fetch a single map tile described by a StaticMapUrl.
Definition: blog.h:30
void dispatchRequest(QNetworkAccessManager *accessManager, const QNetworkRequest &request, const QByteArray &data, const QString &contentType) override
KGAPI2::Job::dispatchRequest implementation.
QUrl moveTaskUrl(const QString &tasklistID, const QString &taskID, const QString &newParent)
Returns URL to reparent task.
Abstract superclass for all jobs that somehow modify resources on Google.
Definition: modifyjob.h:38
QObject * parent() const const
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...
Definition: taskmovejob.cpp:76
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Tue May 26 2020 22:38:58 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.