diff --git a/autotests/drive/data/change1_fetch_request.txt b/autotests/drive/data/change1_fetch_request.txt --- a/autotests/drive/data/change1_fetch_request.txt +++ b/autotests/drive/data/change1_fetch_request.txt @@ -1 +1 @@ -GET https://www.googleapis.com/drive/v2/changes/194 +GET https://www.googleapis.com/drive/v2/changes/194?supportsAllDrives=true diff --git a/autotests/drive/data/changes_fetch_page1_request.txt b/autotests/drive/data/changes_fetch_page1_request.txt --- a/autotests/drive/data/changes_fetch_page1_request.txt +++ b/autotests/drive/data/changes_fetch_page1_request.txt @@ -1 +1 @@ -GET https://www.googleapis.com/drive/v2/changes?includeDeleted=true&includeSubscribed=true +GET https://www.googleapis.com/drive/v2/changes?includeDeleted=true&includeSubscribed=true&includeItemsFromAllDrives=true&supportsAllDrives=true diff --git a/autotests/drive/data/file1_create_request.txt b/autotests/drive/data/file1_create_request.txt --- a/autotests/drive/data/file1_create_request.txt +++ b/autotests/drive/data/file1_create_request.txt @@ -1,40 +1,40 @@ -POST https://www.googleapis.com/drive/v2/files?convert=false&ocr=false&pinned=false&useContentAsIndexableText=false +POST https://www.googleapis.com/drive/v2/files?convert=false&ocr=false&pinned=false&useContentAsIndexableText=false&supportsAllDrives=true Content-Type: application/json { - "mimeType": "application/vnd.google-apps.spreadsheet", - "thumbnailLink": "https://docs.google.com/feeds/vt?gd=true&id=someid&v=480&s=otherid&sz=s220", + "mimeType": "application/vnd.google-apps.spreadsheet", + "thumbnailLink": "https://docs.google.com/feeds/vt?gd=true&id=someid&v=480&s=otherid&sz=s220", "labels": { - "restricted": false, - "starred": false, - "viewed": false, - "hidden": false, + "restricted": false, + "starred": false, + "viewed": false, + "hidden": false, "trashed": false - }, - "etag": "\"bX7M5zOlGcEthti1qPHKQWp6SJA/MTUyMzM1MTc5MDUyNA\"", - "lastModifyingUserName": "John Doe", - "writersCanShare": true, - "sharedWithMeDate": "2018-03-14T13:35:25Z", - "title": "Super mega secret KDE PIM plans for world domination", + }, + "etag": "\"bX7M5zOlGcEthti1qPHKQWp6SJA/MTUyMzM1MTc5MDUyNA\"", + "lastModifyingUserName": "John Doe", + "writersCanShare": true, + "sharedWithMeDate": "2018-03-14T13:35:25Z", + "title": "Super mega secret KDE PIM plans for world domination", "ownerNames": [ "Konqui Dev" - ], - "id": "abcdefghijklmnopqrstuvwxyz", + ], + "id": "abcdefghijklmnopqrstuvwxyz", "parents": [ { - "id": "zyxwvutsrqponmlkjihgfedcba", - "selfLink": "https://www.googleapis.com/drive/v2/files/abcdefghijklmnopqrstuvwxyz/parents/zyxwvutsrqponmlkjihgfedcba", + "id": "zyxwvutsrqponmlkjihgfedcba", + "selfLink": "https://www.googleapis.com/drive/v2/files/abcdefghijklmnopqrstuvwxyz/parents/zyxwvutsrqponmlkjihgfedcba", "parentLink": "https://www.googleapis.com/drive/v2/files/zyxwvutsrqponmlkjihgfedcba" } - ], - "shared": true, - "editable": false, - "kind": "drive#file", - "modifiedDate": "2018-04-10T09:16:30Z", - "createdDate": "2018-01-05T11:35:58Z", - "iconLink": "https://drive-thirdparty.googleusercontent.com/16/type/application/vnd.google-apps.spreadsheet", - "embedLink": "https://docs.google.com/spreadsheets/d/abcdefghijklmnopqrstuvwxyz/htmlembed?ouid=116901758143213967333", - "alternateLink": "https://docs.google.com/spreadsheets/d/abcdefghijklmnopqrstuvwxyz/edit?usp=drivesdk", + ], + "shared": true, + "editable": false, + "kind": "drive#file", + "modifiedDate": "2018-04-10T09:16:30Z", + "createdDate": "2018-01-05T11:35:58Z", + "iconLink": "https://drive-thirdparty.googleusercontent.com/16/type/application/vnd.google-apps.spreadsheet", + "embedLink": "https://docs.google.com/spreadsheets/d/abcdefghijklmnopqrstuvwxyz/htmlembed?ouid=116901758143213967333", + "alternateLink": "https://docs.google.com/spreadsheets/d/abcdefghijklmnopqrstuvwxyz/edit?usp=drivesdk", "selfLink": "https://www.googleapis.com/drive/v2/files/abcdefghijklmnopqrstuvwxyz" } diff --git a/autotests/drive/data/file2_create_request.txt b/autotests/drive/data/file2_create_request.txt index 0000000000000000000000000000000000000000..0000000000000000000000000000000000000000 GIT binary patch literal 0 Hc$@teamdriveList, &QListWidget::itemSelectionChanged, this, &MainWindow::teamdriveSelected); + connect(m_ui->teamdrivePreviewList, &QListWidget::itemSelectionChanged, + this, &MainWindow::teamdriveItemSelected); } MainWindow::~MainWindow() @@ -244,22 +246,23 @@ m_ui->renameTeamdriveButton->setEnabled(hasSelection); m_ui->renameTeamdriveEdit->setEnabled(hasSelection); + m_ui->teamdrivePreviewList->clear(); + if (!hasSelection) { - m_ui->teamdrivePreview->clear(); m_ui->renameTeamdriveEdit->clear(); return; } const QString id = m_ui->teamdriveList->selectedItems().at(0)->data(Qt::UserRole).toString(); const QString name = m_ui->teamdriveList->selectedItems().at(0)->data(Qt::DisplayRole).toString(); + m_ui->renameTeamdriveEdit->setText(name); KGAPI2::Drive::FileSearchQuery query; query.addQuery(KGAPI2::Drive::FileSearchQuery::Trashed, KGAPI2::Drive::FileSearchQuery::Equals, false); query.addQuery(KGAPI2::Drive::FileSearchQuery::Parents, KGAPI2::Drive::FileSearchQuery::In, id); KGAPI2::Drive::FileFetchJob *fileFetchJob = new KGAPI2::Drive::FileFetchJob(query, m_account, nullptr); - fileFetchJob->setIncludeTeamDriveItems(true); fileFetchJob->setFields((KGAPI2::Drive::FileFetchJob::BasicFields & ~KGAPI2::Drive::FileFetchJob::Permissions) | KGAPI2::Drive::FileFetchJob::Labels | KGAPI2::Drive::FileFetchJob::ExportLinks @@ -281,15 +284,61 @@ return; } - /* Get all items we have received from Google (should be just one) */ + /* Get all items we have received from Google */ KGAPI2::ObjectsList objects = fetchJob->items(); - QString text; Q_FOREACH (const KGAPI2::ObjectPtr &object, objects) { const KGAPI2::Drive::FilePtr file = object.dynamicCast(); - text += QStringLiteral("%1").arg(file->title()); - text += QLatin1Char('\n'); + + /* Convert the teamdrive to QListWidget item */ + QListWidgetItem *item = new QListWidgetItem(m_ui->teamdrivePreviewList); + item->setText(file->title()); + item->setData(Qt::UserRole, file->id()); + + m_ui->teamdrivePreviewList->addItem(item); + } +} + +void MainWindow::teamdriveItemSelected() +{ + bool hasSelection = (m_ui->teamdrivePreviewList->selectedItems().count() != 0); + if (!hasSelection) { + return; + } + + const QString id = m_ui->teamdrivePreviewList->selectedItems().at(0)->data(Qt::UserRole).toString(); + + KGAPI2::Drive::FileFetchJob *fileFetchJob = new KGAPI2::Drive::FileFetchJob(id, m_account, nullptr); + fileFetchJob->setFields((KGAPI2::Drive::FileFetchJob::BasicFields & ~KGAPI2::Drive::FileFetchJob::Permissions) + | KGAPI2::Drive::FileFetchJob::Labels + | KGAPI2::Drive::FileFetchJob::ExportLinks + | KGAPI2::Drive::FileFetchJob::LastViewedByMeDate); + connect(fileFetchJob, &KGAPI2::Job::finished, + this, &MainWindow::slotTeamdriveItemFetchJobFinished); +} + +void MainWindow::slotTeamdriveItemFetchJobFinished(KGAPI2::Job *job) +{ + KGAPI2::Drive::FileFetchJob *fetchJob = qobject_cast(job); + Q_ASSERT(fetchJob); + fetchJob->deleteLater(); + + if (fetchJob->error() != KGAPI2::NoError) { + m_ui->errorLabel->setText(QStringLiteral("Error: %1").arg(fetchJob->errorString())); + m_ui->errorLabel->setVisible(true); + return; + } + + KGAPI2::ObjectsList objects = fetchJob->items(); + if (objects.size() != 1) { + return; } - m_ui->teamdrivePreview->setText(text); + KGAPI2::ObjectPtr object = objects.at(0); + const KGAPI2::Drive::FilePtr file = object.dynamicCast(); + QStringList msgBuilder; + msgBuilder << file->title(); + msgBuilder << QString::number(file->fileSize()) + QStringLiteral(" bytes"); + QString msg = msgBuilder.join(QStringLiteral(", ")); + m_ui->statusbar->showMessage(msg); } diff --git a/examples/teamdrive/ui/main.ui b/examples/teamdrive/ui/main.ui --- a/examples/teamdrive/ui/main.ui +++ b/examples/teamdrive/ui/main.ui @@ -158,7 +158,7 @@ - + diff --git a/src/drive/changefetchjob.h b/src/drive/changefetchjob.h --- a/src/drive/changefetchjob.h +++ b/src/drive/changefetchjob.h @@ -104,6 +104,42 @@ qlonglong startChangeId() const; void setStartChangeId(qlonglong startChangeId); + /** + * @brief Whether both My Drive and shared drive items should be included in results. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards shared drive items will be included in the results. + */ + KGAPIDRIVE_DEPRECATED bool includeItemsFromAllDrives() const; + + /** + * @brief Sets whether both My Drive and shared drive items should be included in results. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards shared drive items will be included in the results. + */ + KGAPIDRIVE_DEPRECATED void setIncludeItemsFromAllDrives(bool includeItemsFromAllDrives); + + /** + * @brief Whether the request supports both My Drives and shared drives. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications + * are assumed to support shared drives. + */ + KGAPIDRIVE_DEPRECATED bool supportsAllDrives() const; + + /** + * @brief Sets whether the request supports both My Drives and shared drives. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications + * are assumed to support shared drives. + */ + KGAPIDRIVE_DEPRECATED void setSupportsAllDrives(bool supportsAllDrives); + protected: void start() override; KGAPI2::ObjectsList handleReplyWithItems(const QNetworkReply *reply, diff --git a/src/drive/changefetchjob.cpp b/src/drive/changefetchjob.cpp --- a/src/drive/changefetchjob.cpp +++ b/src/drive/changefetchjob.cpp @@ -46,6 +46,8 @@ bool includeSubscribed; int maxResults; qlonglong startChangeId; + bool includeItemsFromAllDrives; + bool supportsAllDrives; private: ChangeFetchJob *q; @@ -56,6 +58,8 @@ includeSubscribed(true), maxResults(0), startChangeId(0), + includeItemsFromAllDrives(true), + supportsAllDrives(true), q(parent) { } @@ -149,6 +153,26 @@ return d->startChangeId; } +bool ChangeFetchJob::includeItemsFromAllDrives() const +{ + return d->includeItemsFromAllDrives; +} + +void ChangeFetchJob::setIncludeItemsFromAllDrives(bool includeItemsFromAllDrives) +{ + d->includeItemsFromAllDrives = includeItemsFromAllDrives; +} + +bool ChangeFetchJob::supportsAllDrives() const +{ + return d->supportsAllDrives; +} + +void ChangeFetchJob::setSupportsAllDrives(bool supportsAllDrives) +{ + d->supportsAllDrives = supportsAllDrives; +} + void ChangeFetchJob::start() { QUrl url; @@ -163,11 +187,16 @@ if (d->startChangeId > 0) { query.addQueryItem(QStringLiteral("startChangeId"), QString::number(d->startChangeId)); } + query.addQueryItem(QStringLiteral("includeItemsFromAllDrives"), d->includeItemsFromAllDrives ? QStringLiteral("true") : QStringLiteral("false")); url.setQuery(query); } else { url = DriveService::fetchChangeUrl(d->changeId); } + QUrlQuery query(url); + query.addQueryItem(QStringLiteral("supportsAllDrives"), d->supportsAllDrives ? QStringLiteral("true") : QStringLiteral("false")); + url.setQuery(query); + const QNetworkRequest request = d->createRequest(url); enqueueRequest(request); } diff --git a/src/drive/childreferencecreatejob.h b/src/drive/childreferencecreatejob.h --- a/src/drive/childreferencecreatejob.h +++ b/src/drive/childreferencecreatejob.h @@ -57,6 +57,26 @@ QObject *parent = nullptr); ~ChildReferenceCreateJob() override; + /** + * @brief Whether the request supports both My Drives and shared drives. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications + * are assumed to support shared drives. + */ + KGAPIDRIVE_DEPRECATED bool supportsAllDrives() const; + + /** + * @brief Sets whether the request supports both My Drives and shared drives. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications + * are assumed to support shared drives. + */ + KGAPIDRIVE_DEPRECATED void setSupportsAllDrives(bool supportsAllDrives); + protected: void start() override; ObjectsList handleReplyWithItems(const QNetworkReply *reply, diff --git a/src/drive/childreferencecreatejob.cpp b/src/drive/childreferencecreatejob.cpp --- a/src/drive/childreferencecreatejob.cpp +++ b/src/drive/childreferencecreatejob.cpp @@ -28,6 +28,7 @@ #include #include +#include using namespace KGAPI2; @@ -41,12 +42,14 @@ QString folderId; ChildReferencesList references; + bool supportsAllDrives; private: ChildReferenceCreateJob *q; }; ChildReferenceCreateJob::Private::Private(ChildReferenceCreateJob *parent): + supportsAllDrives(true), q(parent) { } @@ -59,7 +62,11 @@ } const ChildReferencePtr reference = references.takeFirst(); - const QUrl url = DriveService::createChildReference(folderId); + QUrl url = DriveService::createChildReference(folderId); + + QUrlQuery withDriveSupportQuery(url); + withDriveSupportQuery.addQueryItem(QStringLiteral("supportsAllDrives"), supportsAllDrives ? QStringLiteral("true") : QStringLiteral("false")); + url.setQuery(withDriveSupportQuery); QNetworkRequest request; request.setRawHeader("Authorization", "Bearer " + q->account()->accessToken().toLatin1()); @@ -120,6 +127,16 @@ delete d; } +bool ChildReferenceCreateJob::supportsAllDrives() const +{ + return d->supportsAllDrives; +} + +void ChildReferenceCreateJob::setSupportsAllDrives(bool supportsAllDrives) +{ + d->supportsAllDrives = supportsAllDrives; +} + void ChildReferenceCreateJob::start() { d->processNext(); diff --git a/src/drive/fileabstractuploadjob.h b/src/drive/fileabstractuploadjob.h --- a/src/drive/fileabstractuploadjob.h +++ b/src/drive/fileabstractuploadjob.h @@ -76,6 +76,26 @@ bool useContentAsIndexableText() const; void setUseContentAsIndexableText(bool useContentAsIndexableText); + /** + * @brief Whether the request supports both My Drives and shared drives. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications + * are assumed to support shared drives. + */ + KGAPIDRIVE_DEPRECATED bool supportsAllDrives() const; + + /** + * @brief Sets whether the request supports both My Drives and shared drives. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications + * are assumed to support shared drives. + */ + KGAPIDRIVE_DEPRECATED void setSupportsAllDrives(bool supportsAllDrives); + QMap < QString /* file path */, FilePtr /* metadata */ > files() const; protected: diff --git a/src/drive/fileabstractuploadjob.cpp b/src/drive/fileabstractuploadjob.cpp --- a/src/drive/fileabstractuploadjob.cpp +++ b/src/drive/fileabstractuploadjob.cpp @@ -58,6 +58,7 @@ QMap uploadedFiles; + bool supportsAllDrives; bool useContentAsIndexableText; File::SerializationOptions serializationOptions = File::NoOptions; @@ -68,6 +69,7 @@ FileAbstractUploadJob::Private::Private(FileAbstractUploadJob *parent): originalFilesCount(0), + supportsAllDrives(true), useContentAsIndexableText(false), q(parent) { @@ -185,6 +187,8 @@ rawData = File::toJSON(metaData, q->serializationOptions()); contentType = QStringLiteral("application/json"); } + + query.addQueryItem(QStringLiteral("supportsAllDrives"), supportsAllDrives ? QStringLiteral("true") : QStringLiteral("false")); url.setQuery(query); request.setUrl(url); @@ -305,6 +309,16 @@ return d->uploadedFiles; } +bool FileAbstractUploadJob::supportsAllDrives() const +{ + return d->supportsAllDrives; +} + +void FileAbstractUploadJob::setSupportsAllDrives(bool supportsAllDrives) +{ + d->supportsAllDrives = supportsAllDrives; +} + void FileAbstractUploadJob::dispatchRequest(QNetworkAccessManager *accessManager, const QNetworkRequest &request, const QByteArray &data, diff --git a/src/drive/filefetchjob.h b/src/drive/filefetchjob.h --- a/src/drive/filefetchjob.h +++ b/src/drive/filefetchjob.h @@ -120,8 +120,41 @@ void setFields(qulonglong fields); qulonglong fields() const; - bool includeTeamDriveItems() const; - void setIncludeTeamDriveItems(bool includeTeamDriveItems); + /** + * @brief Whether both My Drive and shared drive items should be included in results. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards shared drive items will be included in the results. + */ + KGAPIDRIVE_DEPRECATED bool includeItemsFromAllDrives() const; + + /** + * @brief Sets whether both My Drive and shared drive items should be included in results. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards shared drive items will be included in the results. + */ + KGAPIDRIVE_DEPRECATED void setIncludeItemsFromAllDrives(bool includeItemsFromAllDrives); + + /** + * @brief Whether the request supports both My Drives and shared drives. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications + * are assumed to support shared drives. + */ + KGAPIDRIVE_DEPRECATED bool supportsAllDrives() const; + + /** + * @brief Sets whether the request supports both My Drives and shared drives. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications + * are assumed to support shared drives. + */ + KGAPIDRIVE_DEPRECATED void setSupportsAllDrives(bool supportsAllDrives); protected: void start() override; diff --git a/src/drive/filefetchjob.cpp b/src/drive/filefetchjob.cpp --- a/src/drive/filefetchjob.cpp +++ b/src/drive/filefetchjob.cpp @@ -46,7 +46,8 @@ FileSearchQuery searchQuery; QStringList filesIDs; bool isFeed; - bool includeTeamDriveItems; + bool includeItemsFromAllDrives; + bool supportsAllDrives; bool updateViewedDate; @@ -58,6 +59,8 @@ FileFetchJob::Private::Private(FileFetchJob *parent): isFeed(false), + includeItemsFromAllDrives(true), + supportsAllDrives(true), updateViewedDate(false), fields(FileFetchJob::AllFields), q(parent) @@ -240,10 +243,7 @@ QStringLiteral("etag,kind,nextLink,nextPageToken,selfLink,items(%1)").arg(fieldsStrings.join(QStringLiteral(",")))); } - if (includeTeamDriveItems) { - query.addQueryItem(QStringLiteral("includeTeamDriveItems"), QStringLiteral("true")); - query.addQueryItem(QStringLiteral("supportsTeamDrives"), QStringLiteral("true")); - } + query.addQueryItem(QStringLiteral("includeItemsFromAllDrives"), includeItemsFromAllDrives ? QStringLiteral("true") : QStringLiteral("false")); url.setQuery(query); } else { @@ -262,6 +262,10 @@ } } + QUrlQuery withDriveSupportQuery(url); + withDriveSupportQuery.addQueryItem(QStringLiteral("supportsAllDrives"), supportsAllDrives ? QStringLiteral("true") : QStringLiteral("false")); + url.setQuery(withDriveSupportQuery); + q->enqueueRequest(createRequest(url)); } @@ -333,14 +337,24 @@ return d->fields; } -bool FileFetchJob::includeTeamDriveItems() const +bool FileFetchJob::includeItemsFromAllDrives() const +{ + return d->includeItemsFromAllDrives; +} + +void FileFetchJob::setIncludeItemsFromAllDrives(bool includeItemsFromAllDrives) +{ + d->includeItemsFromAllDrives = includeItemsFromAllDrives; +} + +bool FileFetchJob::supportsAllDrives() const { - return d->includeTeamDriveItems; + return d->supportsAllDrives; } -void FileFetchJob::setIncludeTeamDriveItems(bool includeTeamDriveItems) +void FileFetchJob::setSupportsAllDrives(bool supportsAllDrives) { - d->includeTeamDriveItems = includeTeamDriveItems; + d->supportsAllDrives = supportsAllDrives; } diff --git a/src/drive/parentreferencecreatejob.h b/src/drive/parentreferencecreatejob.h --- a/src/drive/parentreferencecreatejob.h +++ b/src/drive/parentreferencecreatejob.h @@ -57,6 +57,26 @@ QObject *parent = nullptr); ~ParentReferenceCreateJob() override; + /** + * @brief Whether the request supports both My Drives and shared drives. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications + * are assumed to support shared drives. + */ + KGAPIDRIVE_DEPRECATED bool supportsAllDrives() const; + + /** + * @brief Sets whether the request supports both My Drives and shared drives. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications + * are assumed to support shared drives. + */ + KGAPIDRIVE_DEPRECATED void setSupportsAllDrives(bool supportsAllDrives); + protected: void start() override; KGAPI2::ObjectsList handleReplyWithItems(const QNetworkReply *reply, diff --git a/src/drive/parentreferencecreatejob.cpp b/src/drive/parentreferencecreatejob.cpp --- a/src/drive/parentreferencecreatejob.cpp +++ b/src/drive/parentreferencecreatejob.cpp @@ -28,6 +28,7 @@ #include #include +#include using namespace KGAPI2; @@ -38,6 +39,7 @@ public: Private(ParentReferenceCreateJob *parent); void processNext(); + bool supportsAllDrives; QString fileId; ParentReferencesList references; @@ -47,6 +49,7 @@ }; ParentReferenceCreateJob::Private::Private(ParentReferenceCreateJob *parent): + supportsAllDrives(true), q(parent) { } @@ -59,7 +62,11 @@ } const ParentReferencePtr reference = references.takeFirst(); - const QUrl url = DriveService::createParentReferenceUrl(fileId); + QUrl url = DriveService::createParentReferenceUrl(fileId); + + QUrlQuery withDriveSupportQuery(url); + withDriveSupportQuery.addQueryItem(QStringLiteral("supportsAllDrives"), supportsAllDrives ? QStringLiteral("true") : QStringLiteral("false")); + url.setQuery(withDriveSupportQuery); QNetworkRequest request; request.setRawHeader("Authorization", "Bearer " + q->account()->accessToken().toLatin1()); @@ -120,6 +127,16 @@ delete d; } +bool ParentReferenceCreateJob::supportsAllDrives() const +{ + return d->supportsAllDrives; +} + +void ParentReferenceCreateJob::setSupportsAllDrives(bool supportsAllDrives) +{ + d->supportsAllDrives = supportsAllDrives; +} + void ParentReferenceCreateJob::start() { d->processNext(); diff --git a/src/drive/permissioncreatejob.h b/src/drive/permissioncreatejob.h --- a/src/drive/permissioncreatejob.h +++ b/src/drive/permissioncreatejob.h @@ -45,6 +45,26 @@ const AccountPtr &account, QObject *parent = nullptr); ~PermissionCreateJob() override; + /** + * @brief Whether the request supports both My Drives and shared drives. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications + * are assumed to support shared drives. + */ + KGAPIDRIVE_DEPRECATED bool supportsAllDrives() const; + + /** + * @brief Sets whether the request supports both My Drives and shared drives. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications + * are assumed to support shared drives. + */ + KGAPIDRIVE_DEPRECATED void setSupportsAllDrives(bool supportsAllDrives); + protected: void start() override; KGAPI2::ObjectsList handleReplyWithItems(const QNetworkReply *reply, diff --git a/src/drive/permissioncreatejob.cpp b/src/drive/permissioncreatejob.cpp --- a/src/drive/permissioncreatejob.cpp +++ b/src/drive/permissioncreatejob.cpp @@ -28,6 +28,7 @@ #include #include +#include using namespace KGAPI2; @@ -41,12 +42,14 @@ PermissionsList permissions; QString fileId; + bool supportsAllDrives; private: PermissionCreateJob *const q; }; PermissionCreateJob::Private::Private(PermissionCreateJob *parent): + supportsAllDrives(true), q(parent) { } @@ -60,7 +63,11 @@ const PermissionPtr permission = permissions.takeFirst(); - const QUrl url = DriveService::createPermissionUrl(fileId); + QUrl url = DriveService::createPermissionUrl(fileId); + + QUrlQuery withDriveSupportQuery(url); + withDriveSupportQuery.addQueryItem(QStringLiteral("supportsAllDrives"), supportsAllDrives ? QStringLiteral("true") : QStringLiteral("false")); + url.setQuery(withDriveSupportQuery); QNetworkRequest request; request.setRawHeader("Authorization", "Bearer " + q->account()->accessToken().toLatin1()); @@ -97,6 +104,16 @@ delete d; } +bool PermissionCreateJob::supportsAllDrives() const +{ + return d->supportsAllDrives; +} + +void PermissionCreateJob::setSupportsAllDrives(bool supportsAllDrives) +{ + d->supportsAllDrives = supportsAllDrives; +} + void PermissionCreateJob::start() { d->processNext(); diff --git a/src/drive/permissiondeletejob.h b/src/drive/permissiondeletejob.h --- a/src/drive/permissiondeletejob.h +++ b/src/drive/permissiondeletejob.h @@ -54,6 +54,26 @@ const AccountPtr &account, QObject *parent = nullptr); ~PermissionDeleteJob() override; + /** + * @brief Whether the request supports both My Drives and shared drives. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications + * are assumed to support shared drives. + */ + KGAPIDRIVE_DEPRECATED bool supportsAllDrives() const; + + /** + * @brief Sets whether the request supports both My Drives and shared drives. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications + * are assumed to support shared drives. + */ + KGAPIDRIVE_DEPRECATED void setSupportsAllDrives(bool supportsAllDrives); + protected: void start() override; diff --git a/src/drive/permissiondeletejob.cpp b/src/drive/permissiondeletejob.cpp --- a/src/drive/permissiondeletejob.cpp +++ b/src/drive/permissiondeletejob.cpp @@ -27,6 +27,7 @@ #include "driveservice.h" #include +#include using namespace KGAPI2; using namespace KGAPI2::Drive; @@ -36,6 +37,7 @@ public: QString fileId; QStringList permissionsIds; + bool supportsAllDrives; }; PermissionDeleteJob::PermissionDeleteJob(const QString &fileId, @@ -45,6 +47,7 @@ DeleteJob(account, parent), d(new Private) { + d->supportsAllDrives = true; d->fileId = fileId; d->permissionsIds << permission->id(); } @@ -56,6 +59,7 @@ DeleteJob(account, parent), d(new Private) { + d->supportsAllDrives = true; d->fileId = fileId; d->permissionsIds << permissionId; } @@ -67,6 +71,7 @@ DeleteJob(account, parent), d(new Private) { + d->supportsAllDrives = true; d->fileId = fileId; for (const PermissionPtr & permission : qAsConst(permissions)) { d->permissionsIds << permission->id(); @@ -80,6 +85,7 @@ DeleteJob(account, parent), d(new Private) { + d->supportsAllDrives = true; d->fileId = fileId; d->permissionsIds << permissionsIds; } @@ -89,15 +95,28 @@ delete d; } +bool PermissionDeleteJob::supportsAllDrives() const +{ + return d->supportsAllDrives; +} + +void PermissionDeleteJob::setSupportsAllDrives(bool supportsAllDrives) +{ + d->supportsAllDrives = supportsAllDrives; +} + void PermissionDeleteJob::start() { if (d->permissionsIds.isEmpty()) { emitFinished(); return; } const QString permissionId = d->permissionsIds.takeFirst(); - const QUrl url = DriveService::deletePermissionUrl(d->fileId, permissionId); + QUrl url = DriveService::deletePermissionUrl(d->fileId, permissionId); + QUrlQuery withDriveSupportQuery(url); + withDriveSupportQuery.addQueryItem(QStringLiteral("supportsAllDrives"), d->supportsAllDrives ? QStringLiteral("true") : QStringLiteral("false")); + url.setQuery(withDriveSupportQuery); QNetworkRequest request(url); request.setRawHeader("Authorization", "Bearer " + account()->accessToken().toLatin1()); diff --git a/src/drive/permissionfetchjob.h b/src/drive/permissionfetchjob.h --- a/src/drive/permissionfetchjob.h +++ b/src/drive/permissionfetchjob.h @@ -48,6 +48,26 @@ const AccountPtr &account, QObject *parent = nullptr); ~PermissionFetchJob() override; + /** + * @brief Whether the request supports both My Drives and shared drives. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications + * are assumed to support shared drives. + */ + KGAPIDRIVE_DEPRECATED bool supportsAllDrives() const; + + /** + * @brief Sets whether the request supports both My Drives and shared drives. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications + * are assumed to support shared drives. + */ + KGAPIDRIVE_DEPRECATED void setSupportsAllDrives(bool supportsAllDrives); + protected: void start() override; KGAPI2::ObjectsList handleReplyWithItems(const QNetworkReply *reply, diff --git a/src/drive/permissionfetchjob.cpp b/src/drive/permissionfetchjob.cpp --- a/src/drive/permissionfetchjob.cpp +++ b/src/drive/permissionfetchjob.cpp @@ -27,9 +27,9 @@ #include "permission.h" #include "utils.h" - #include #include +#include using namespace KGAPI2; using namespace KGAPI2::Drive; @@ -39,6 +39,7 @@ public: QString fileId; QString permissionId; + bool supportsAllDrives; }; @@ -48,6 +49,7 @@ FetchJob(account, parent), d(new Private) { + d->supportsAllDrives = true; d->fileId = fileId; } @@ -57,6 +59,7 @@ FetchJob(account, parent), d(new Private) { + d->supportsAllDrives = true; d->fileId = file->id(); } @@ -67,6 +70,7 @@ FetchJob(account, parent), d(new Private) { + d->supportsAllDrives = true; d->fileId = fileId; d->permissionId = permissionId; } @@ -78,6 +82,7 @@ FetchJob(account, parent), d(new Private) { + d->supportsAllDrives = true; d->fileId = file->id(); d->permissionId = permissionId; } @@ -87,14 +92,31 @@ delete d; } +bool PermissionFetchJob::supportsAllDrives() const +{ + return d->supportsAllDrives; +} + +void PermissionFetchJob::setSupportsAllDrives(bool supportsAllDrives) +{ + d->supportsAllDrives = supportsAllDrives; +} + void PermissionFetchJob::start() { - QNetworkRequest request; + QUrl url; if (d->permissionId.isEmpty()) { - request.setUrl(DriveService::fetchPermissionsUrl(d->fileId)); + url = DriveService::fetchPermissionsUrl(d->fileId); } else { - request.setUrl(DriveService::fetchPermissionUrl(d->fileId, d->permissionId)); + url = DriveService::fetchPermissionUrl(d->fileId, d->permissionId); } + + QUrlQuery withDriveSupportQuery(url); + withDriveSupportQuery.addQueryItem(QStringLiteral("supportsAllDrives"), d->supportsAllDrives ? QStringLiteral("true") : QStringLiteral("false")); + url.setQuery(withDriveSupportQuery); + + QNetworkRequest request; + request.setUrl(url); request.setRawHeader("Authorization", "Bearer " + account()->accessToken().toLatin1()); enqueueRequest(request); diff --git a/src/drive/permissionmodifyjob.h b/src/drive/permissionmodifyjob.h --- a/src/drive/permissionmodifyjob.h +++ b/src/drive/permissionmodifyjob.h @@ -46,6 +46,26 @@ const AccountPtr &account, QObject *parent = nullptr); ~PermissionModifyJob() override; + /** + * @brief Whether the request supports both My Drives and shared drives. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications + * are assumed to support shared drives. + */ + KGAPIDRIVE_DEPRECATED bool supportsAllDrives() const; + + /** + * @brief Sets whether the request supports both My Drives and shared drives. + * + * Set to true by default as LibKGAPI supports Team Drives. + * + * @deprecated This parameter will only be effective until June 1, 2020. Afterwards all applications + * are assumed to support shared drives. + */ + KGAPIDRIVE_DEPRECATED void setSupportsAllDrives(bool supportsAllDrives); + protected: void start() override; KGAPI2::ObjectsList handleReplyWithItems(const QNetworkReply *reply, diff --git a/src/drive/permissionmodifyjob.cpp b/src/drive/permissionmodifyjob.cpp --- a/src/drive/permissionmodifyjob.cpp +++ b/src/drive/permissionmodifyjob.cpp @@ -29,6 +29,7 @@ #include #include +#include using namespace KGAPI2; @@ -42,12 +43,14 @@ QString fileId; PermissionsList permissions; + bool supportsAllDrives; private: PermissionModifyJob *q; }; PermissionModifyJob::Private::Private(PermissionModifyJob *parent): + supportsAllDrives(true), q(parent) { } @@ -60,7 +63,11 @@ } const PermissionPtr permission = permissions.takeFirst(); - const QUrl url = DriveService::modifyPermissionUrl(fileId, permission->id()); + QUrl url = DriveService::modifyPermissionUrl(fileId, permission->id()); + + QUrlQuery withDriveSupportQuery(url); + withDriveSupportQuery.addQueryItem(QStringLiteral("supportsAllDrives"), supportsAllDrives ? QStringLiteral("true") : QStringLiteral("false")); + url.setQuery(withDriveSupportQuery); QNetworkRequest request(url); request.setRawHeader("Authorization", "Bearer " + q->account()->accessToken().toLatin1()); @@ -96,6 +103,16 @@ delete d; } +bool PermissionModifyJob::supportsAllDrives() const +{ + return d->supportsAllDrives; +} + +void PermissionModifyJob::setSupportsAllDrives(bool supportsAllDrives) +{ + d->supportsAllDrives = supportsAllDrives; +} + void PermissionModifyJob::start() { d->processNext();