diff --git a/examples/teamdrive/mainwindow.h b/examples/teamdrive/mainwindow.h --- a/examples/teamdrive/mainwindow.h +++ b/examples/teamdrive/mainwindow.h @@ -102,11 +102,22 @@ void slotTeamdriveDeleteJobFinished(KGAPI2::Job *job); /** - * A specific contact in contact list has been selected. Sends a request - * to Google to retrieve full details about the specific contact + * A specific team drive in teamdrive list has been selected. Sends a request + * to Google to retrieve teh team drive file list. */ void teamdriveSelected(); + /** + * A specific item in the teamdrive list has been selected. Sends a request + * to Google to retrieve full details about the specific file + */ + void teamdriveItemSelected(); + + /** + * Team Drive item detail was fetched. + */ + void slotTeamdriveItemFetchJobFinished(KGAPI2::Job *job); + private: Ui::MainWindow *m_ui; diff --git a/examples/teamdrive/mainwindow.cpp b/examples/teamdrive/mainwindow.cpp --- a/examples/teamdrive/mainwindow.cpp +++ b/examples/teamdrive/mainwindow.cpp @@ -56,6 +56,8 @@ this, &MainWindow::renameSelectedTeamdrive); connect(m_ui->teamdriveList, &QListWidget::itemSelectionChanged, this, &MainWindow::teamdriveSelected); + connect(m_ui->teamdrivePreviewList, &QListWidget::itemSelectionChanged, + this, &MainWindow::teamdriveItemSelected); } MainWindow::~MainWindow() @@ -244,14 +246,16 @@ 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; @@ -259,7 +263,6 @@ 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/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; }