Changeset View
Changeset View
Standalone View
Standalone View
src/drive/permissionfetchjob.cpp
Show All 21 Lines | |||||
22 | 22 | | |||
23 | #include "permissionfetchjob.h" | 23 | #include "permissionfetchjob.h" | ||
24 | #include "driveservice.h" | 24 | #include "driveservice.h" | ||
25 | #include "account.h" | 25 | #include "account.h" | ||
26 | #include "file.h" | 26 | #include "file.h" | ||
27 | #include "permission.h" | 27 | #include "permission.h" | ||
28 | #include "utils.h" | 28 | #include "utils.h" | ||
29 | 29 | | |||
30 | | ||||
31 | #include <QNetworkRequest> | 30 | #include <QNetworkRequest> | ||
32 | #include <QNetworkReply> | 31 | #include <QNetworkReply> | ||
32 | #include <QUrlQuery> | ||||
33 | 33 | | |||
34 | using namespace KGAPI2; | 34 | using namespace KGAPI2; | ||
35 | using namespace KGAPI2::Drive; | 35 | using namespace KGAPI2::Drive; | ||
36 | 36 | | |||
37 | class Q_DECL_HIDDEN PermissionFetchJob::Private | 37 | class Q_DECL_HIDDEN PermissionFetchJob::Private | ||
38 | { | 38 | { | ||
39 | public: | 39 | public: | ||
40 | QString fileId; | 40 | QString fileId; | ||
41 | QString permissionId; | 41 | QString permissionId; | ||
42 | bool supportsAllDrives; | ||||
42 | 43 | | |||
43 | }; | 44 | }; | ||
44 | 45 | | |||
45 | PermissionFetchJob::PermissionFetchJob(const QString &fileId, | 46 | PermissionFetchJob::PermissionFetchJob(const QString &fileId, | ||
46 | const AccountPtr &account, | 47 | const AccountPtr &account, | ||
47 | QObject *parent): | 48 | QObject *parent): | ||
48 | FetchJob(account, parent), | 49 | FetchJob(account, parent), | ||
49 | d(new Private) | 50 | d(new Private) | ||
50 | { | 51 | { | ||
52 | d->supportsAllDrives = true; | ||||
51 | d->fileId = fileId; | 53 | d->fileId = fileId; | ||
52 | } | 54 | } | ||
53 | 55 | | |||
54 | PermissionFetchJob::PermissionFetchJob(const FilePtr &file, | 56 | PermissionFetchJob::PermissionFetchJob(const FilePtr &file, | ||
55 | const AccountPtr &account, | 57 | const AccountPtr &account, | ||
56 | QObject *parent): | 58 | QObject *parent): | ||
57 | FetchJob(account, parent), | 59 | FetchJob(account, parent), | ||
58 | d(new Private) | 60 | d(new Private) | ||
59 | { | 61 | { | ||
62 | d->supportsAllDrives = true; | ||||
60 | d->fileId = file->id(); | 63 | d->fileId = file->id(); | ||
61 | } | 64 | } | ||
62 | 65 | | |||
63 | PermissionFetchJob::PermissionFetchJob(const QString &fileId, | 66 | PermissionFetchJob::PermissionFetchJob(const QString &fileId, | ||
64 | const QString &permissionId, | 67 | const QString &permissionId, | ||
65 | const AccountPtr &account, | 68 | const AccountPtr &account, | ||
66 | QObject *parent): | 69 | QObject *parent): | ||
67 | FetchJob(account, parent), | 70 | FetchJob(account, parent), | ||
68 | d(new Private) | 71 | d(new Private) | ||
69 | { | 72 | { | ||
73 | d->supportsAllDrives = true; | ||||
70 | d->fileId = fileId; | 74 | d->fileId = fileId; | ||
71 | d->permissionId = permissionId; | 75 | d->permissionId = permissionId; | ||
72 | } | 76 | } | ||
73 | 77 | | |||
74 | PermissionFetchJob::PermissionFetchJob(const FilePtr &file, | 78 | PermissionFetchJob::PermissionFetchJob(const FilePtr &file, | ||
75 | const QString &permissionId, | 79 | const QString &permissionId, | ||
76 | const AccountPtr &account, | 80 | const AccountPtr &account, | ||
77 | QObject *parent): | 81 | QObject *parent): | ||
78 | FetchJob(account, parent), | 82 | FetchJob(account, parent), | ||
79 | d(new Private) | 83 | d(new Private) | ||
80 | { | 84 | { | ||
85 | d->supportsAllDrives = true; | ||||
81 | d->fileId = file->id(); | 86 | d->fileId = file->id(); | ||
82 | d->permissionId = permissionId; | 87 | d->permissionId = permissionId; | ||
83 | } | 88 | } | ||
84 | 89 | | |||
85 | PermissionFetchJob::~PermissionFetchJob() | 90 | PermissionFetchJob::~PermissionFetchJob() | ||
86 | { | 91 | { | ||
87 | delete d; | 92 | delete d; | ||
88 | } | 93 | } | ||
89 | 94 | | |||
95 | bool PermissionFetchJob::supportsAllDrives() const | ||||
96 | { | ||||
97 | return d->supportsAllDrives; | ||||
98 | } | ||||
99 | | ||||
100 | void PermissionFetchJob::setSupportsAllDrives(bool supportsAllDrives) | ||||
101 | { | ||||
102 | d->supportsAllDrives = supportsAllDrives; | ||||
103 | } | ||||
104 | | ||||
90 | void PermissionFetchJob::start() | 105 | void PermissionFetchJob::start() | ||
91 | { | 106 | { | ||
92 | QNetworkRequest request; | 107 | QUrl url; | ||
93 | if (d->permissionId.isEmpty()) { | 108 | if (d->permissionId.isEmpty()) { | ||
94 | request.setUrl(DriveService::fetchPermissionsUrl(d->fileId)); | 109 | url = DriveService::fetchPermissionsUrl(d->fileId); | ||
95 | } else { | 110 | } else { | ||
96 | request.setUrl(DriveService::fetchPermissionUrl(d->fileId, d->permissionId)); | 111 | url = DriveService::fetchPermissionUrl(d->fileId, d->permissionId); | ||
97 | } | 112 | } | ||
113 | | ||||
114 | QUrlQuery withDriveSupportQuery(url); | ||||
115 | withDriveSupportQuery.addQueryItem(QStringLiteral("supportsAllDrives"), d->supportsAllDrives ? QStringLiteral("true") : QStringLiteral("false")); | ||||
116 | url.setQuery(withDriveSupportQuery); | ||||
117 | | ||||
118 | QNetworkRequest request; | ||||
119 | request.setUrl(url); | ||||
98 | request.setRawHeader("Authorization", "Bearer " + account()->accessToken().toLatin1()); | 120 | request.setRawHeader("Authorization", "Bearer " + account()->accessToken().toLatin1()); | ||
99 | 121 | | |||
100 | enqueueRequest(request); | 122 | enqueueRequest(request); | ||
101 | } | 123 | } | ||
102 | 124 | | |||
103 | ObjectsList PermissionFetchJob::handleReplyWithItems(const QNetworkReply *reply, | 125 | ObjectsList PermissionFetchJob::handleReplyWithItems(const QNetworkReply *reply, | ||
104 | const QByteArray &rawData) | 126 | const QByteArray &rawData) | ||
105 | { | 127 | { | ||
Show All 20 Lines |