Changeset View
Changeset View
Standalone View
Standalone View
src/drive/teamdrivedeletejob.cpp
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | * This file is part of LibKGAPI library | ||||
3 | * | ||||
4 | * Copyright (C) 2019 David Barchiesi <david@barchie.si> | ||||
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 | | ||||
24 | #include "teamdrivedeletejob.h" | ||||
25 | #include "teamdrive.h" | ||||
26 | #include "account.h" | ||||
27 | #include "driveservice.h" | ||||
28 | | ||||
29 | #include <QNetworkRequest> | ||||
30 | | ||||
31 | using namespace KGAPI2; | ||||
32 | using namespace KGAPI2::Drive; | ||||
33 | | ||||
34 | class Q_DECL_HIDDEN TeamdriveDeleteJob::Private | ||||
35 | { | ||||
36 | public: | ||||
37 | QStringList teamdrivesIds; | ||||
38 | }; | ||||
39 | | ||||
40 | TeamdriveDeleteJob::TeamdriveDeleteJob(const QString &teamdriveId, | ||||
41 | const AccountPtr &account, QObject *parent): | ||||
42 | DeleteJob(account, parent), | ||||
43 | d(new Private) | ||||
44 | { | ||||
45 | d->teamdrivesIds << teamdriveId; | ||||
46 | } | ||||
47 | | ||||
48 | TeamdriveDeleteJob::TeamdriveDeleteJob(const QStringList &teamdrivesIds, | ||||
49 | const AccountPtr &account, QObject *parent): | ||||
50 | DeleteJob(account, parent), | ||||
51 | d(new Private) | ||||
52 | { | ||||
53 | d->teamdrivesIds << teamdrivesIds; | ||||
54 | } | ||||
55 | | ||||
56 | TeamdriveDeleteJob::TeamdriveDeleteJob(const TeamdrivePtr &teamdrive, | ||||
57 | const AccountPtr &account, QObject *parent): | ||||
58 | DeleteJob(account, parent), | ||||
59 | d(new Private) | ||||
60 | { | ||||
61 | d->teamdrivesIds << teamdrive->id(); | ||||
62 | } | ||||
63 | | ||||
64 | TeamdriveDeleteJob::TeamdriveDeleteJob(const TeamdrivesList &teamdrives, | ||||
65 | const AccountPtr &account, QObject *parent): | ||||
66 | DeleteJob(account, parent), | ||||
67 | d(new Private) | ||||
68 | { | ||||
69 | for (const TeamdrivePtr & teamdrive : qAsConst(teamdrives)) { | ||||
70 | d->teamdrivesIds << teamdrive->id(); | ||||
71 | } | ||||
72 | } | ||||
73 | | ||||
74 | TeamdriveDeleteJob::~TeamdriveDeleteJob() = default; | ||||
75 | | ||||
76 | void TeamdriveDeleteJob::start() | ||||
77 | { | ||||
78 | if (d->teamdrivesIds.isEmpty()) { | ||||
79 | emitFinished(); | ||||
80 | return; | ||||
81 | } | ||||
82 | | ||||
83 | const QString teamdriveId = d->teamdrivesIds.takeFirst(); | ||||
84 | const QUrl url = DriveService::fetchTeamdriveUrl(teamdriveId); | ||||
85 | QNetworkRequest request(url); | ||||
86 | request.setRawHeader("Authorization", "Bearer " + account()->accessToken().toLatin1()); | ||||
87 | | ||||
88 | enqueueRequest(request); | ||||
89 | } | ||||
90 | | ||||
91 | |