Kgapi

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

KDE's Doxygen guidelines are available online.