Kgapi

contactsgroupdeletejob.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 "contactsgroupdeletejob.h"
10 #include "contactsgroup.h"
11 #include "contactsservice.h"
12 #include "../debug.h"
13 #include "utils.h"
14 #include "account.h"
15 #include "private/queuehelper_p.h"
16 
17 #include <QNetworkRequest>
18 
19 using namespace KGAPI2;
20 
21 class Q_DECL_HIDDEN ContactsGroupDeleteJob::Private
22 {
23  public:
24  Private(ContactsGroupDeleteJob *parent);
25  QNetworkRequest createRequest(const QUrl &url) const;
26 
27  QueueHelper<QString> groupsIds;
28 
29  private:
30  ContactsGroupDeleteJob * const q;
31 };
32 
33 ContactsGroupDeleteJob::Private::Private(ContactsGroupDeleteJob* parent):
34  q(parent)
35 {
36 }
37 
38 QNetworkRequest ContactsGroupDeleteJob::Private::createRequest(const QUrl& url) const
39 {
40  QNetworkRequest request(url);
41  request.setRawHeader("GData-Version", ContactsService::APIVersion().toLatin1());
42 
43  QStringList headers;
44  auto rawHeaderList = request.rawHeaderList();
45  headers.reserve(rawHeaderList.size());
46  for (const QByteArray &str : qAsConst(rawHeaderList)) {
47  headers << QLatin1String(str) + QLatin1String(": ") + QLatin1String(request.rawHeader(str));
48  }
49 
50  return request;
51 }
52 
53 
55  DeleteJob(account, parent),
56  d(new Private(this))
57 {
58  d->groupsIds.reserve(groups.size());
59  for(const ContactsGroupPtr &group : groups) {
60  d->groupsIds << group->id();
61  }
62 }
63 
65  DeleteJob(account, parent),
66  d(new Private(this))
67 {
68  d->groupsIds << group->id();
69 }
70 
72  DeleteJob(account, parent),
73  d(new Private(this))
74 {
75  d->groupsIds = groupsIds;
76 }
77 
79  DeleteJob(account, parent),
80  d(new Private(this))
81 {
82  d->groupsIds << groupId;
83 }
84 
86 {
87  delete d;
88 }
89 
91 {
92  if (d->groupsIds.atEnd()) {
93  emitFinished();
94  return;
95  }
96 
97  const QString groupId = d->groupsIds.current();
98  const QUrl url = ContactsService::removeGroupUrl(account()->accountName(), groupId);
99  const QNetworkRequest request = d->createRequest(url);
100 
101  enqueueRequest(request);
102 }
103 
105 {
106  d->groupsIds.currentProcessed();
107 
108  KGAPI2::DeleteJob::handleReply(reply, rawData);
109 }
110 
111 
112 
AccountPtr account() const
Returns account used to authenticate requests.
Definition: job.cpp:423
void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::Job::handleReply implementation.
Definition: deletejob.cpp:59
void reserve(int alloc)
QString APIVersion()
Supported API version.
~ContactsGroupDeleteJob() override
Destructor.
int size() const const
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 delete one or more contact groups from addressbook in user&#39;s Google Contacts account...
A job to fetch a single map tile described by a StaticMapUrl.
Definition: blog.h:16
ContactsGroupDeleteJob(const ContactsGroupsList &groups, const AccountPtr &account, QObject *parent)
Constructs a new job that will delete given groups from user&#39;s addressbook.
void start() override
KGAPI2::Job::start implementation.
Abstract superclass for all jobs that delete resources from Google.
Definition: deletejob.h:24
void handleReply(const QNetworkReply *reply, const QByteArray &rawData) override
KGAPI2::Job::handleReply implementation.
virtual void emitFinished()
Emits Job::finished() signal.
Definition: job.cpp:477
QUrl removeGroupUrl(const QString &user, const QString &groupId)
Returns URL for removing a single contacts group.
QObject * parent() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Jul 3 2020 23:09:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.