Kgapi

contactgroupdeletejob.cpp
1/*
2 * This file is part of LibKGAPI library
3 *
4 * SPDX-FileCopyrightText: 2023 Claudio Cambra <claudio.cambra@kde.org>
5 * SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
6 *
7 */
8
9#include "contactgroupdeletejob.h"
10#include "peopleservice.h"
11#include "private/queuehelper_p.h"
12
13#include <QNetworkRequest>
14#include <QNetworkReply>
15#include <QUrlQuery>
16#include <QJsonDocument>
17#include <QJsonObject>
18#include <QJsonArray>
19
20namespace KGAPI2::People
21{
22
23class Q_DECL_HIDDEN ContactGroupDeleteJob::Private
24{
25public:
26 explicit Private(ContactGroupDeleteJob *parent);
27 void processNextContactGroup();
28
29 QueueHelper<QString> groupResourceNames;
30 QString lastGroupResourceName;
31
32private:
33 ContactGroupDeleteJob * const q;
34};
35
36ContactGroupDeleteJob::Private::Private(ContactGroupDeleteJob *parent)
37 : q(parent)
38{
39}
40
41void ContactGroupDeleteJob::Private::processNextContactGroup()
42{
43 if (groupResourceNames.atEnd()) {
44 q->emitFinished();
45 return;
46 }
47
48 const auto groupResourceName = groupResourceNames.current();
49 const auto deleteUrl = PeopleService::deleteContactGroupUrl(groupResourceName, false);
50 QNetworkRequest request(deleteUrl);
51 request.setRawHeader("Host", "people.googleapis.com");
52 q->enqueueRequest(request);
53}
54
55
56ContactGroupDeleteJob::ContactGroupDeleteJob(const QStringList &contactGroupResourceNames, const AccountPtr& account, QObject* parent)
57 : DeleteJob(account, parent)
58 , d(std::make_unique<Private>(this))
59{
60 d->groupResourceNames = contactGroupResourceNames;
61}
62
63ContactGroupDeleteJob::ContactGroupDeleteJob(const QString &contactGroupResourceName, const AccountPtr &account, QObject* parent)
64 : DeleteJob(account, parent)
65 , d(std::make_unique<Private>(this))
66{
67 d->groupResourceNames << contactGroupResourceName;
68}
69
70ContactGroupDeleteJob::~ContactGroupDeleteJob() = default;
71
72void ContactGroupDeleteJob::start()
73{
74 d->processNextContactGroup();
75}
76
77void ContactGroupDeleteJob::handleReply(const QNetworkReply *reply, const QByteArray &rawData)
78{
79 Q_UNUSED(reply);
80 Q_UNUSED(rawData);
81
82 d->groupResourceNames.currentProcessed();
83 d->processNextContactGroup();
84}
85
86}
87
88#include "moc_contactgroupdeletejob.cpp"
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 22 2024 12:08:13 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.