diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 72eb24d..ed6cdd1 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,81 +1,82 @@ include(ECMAddTests) find_package(Qt5Test CONFIG REQUIRED) set(kgapitest_SRCS fakeaccountstorage.cpp fakeauthwidget.cpp fakenetworkreply.cpp fakenetworkaccessmanager.cpp fakenetworkaccessmanagerfactory.cpp testutils.cpp ) add_library(kgapitest STATIC ${kgapitest_SRCS}) target_link_libraries(kgapitest Qt5::Core Qt5::Network Qt5::Test KPimGAPICore) macro(add_libkgapi2_test _module _testname) set(testSources ${_module}/${_testname}.cpp) string(SUBSTRING ${_module} 0 1 moduleFirst) string(SUBSTRING ${_module} 1 -1 moduleLast) string(TOUPPER ${moduleFirst} moduleFirst) string(CONCAT moduleName ${moduleFirst} ${moduleLast}) set(extraLibs "KPimGAPI${moduleName}") set(utilsFile ${CMAKE_CURRENT_SOURCE_DIR}/${_module}/${_module}testutils.cpp) if (EXISTS ${utilsFile}) list(APPEND testSources ${utilsFile}) endif() ecm_add_test(${testSources} LINK_LIBRARIES kgapitest KPimGAPICore ${extraLibs} TEST_NAME ${_testname} NAME_PREFIX ${_module}- ) endmacro(add_libkgapi2_test) ecm_add_test(fakenamtest.cpp LINK_LIBRARIES kgapitest KPimGAPICore TEST_NAME fakenamtest NAME_PREFIX fake-) add_libkgapi2_test(core accountinfofetchjobtest) add_libkgapi2_test(core accountmanagertest) add_libkgapi2_test(core createjobtest) add_libkgapi2_test(core fetchjobtest) add_libkgapi2_test(contacts contactcreatejobtest) add_libkgapi2_test(contacts contactdeletejobtest) add_libkgapi2_test(contacts contactfetchjobtest) add_libkgapi2_test(contacts contactfetchphotojobtest) add_libkgapi2_test(contacts contactmodifyjobtest) add_libkgapi2_test(contacts contactsgroupcreatejobtest) add_libkgapi2_test(contacts contactsgroupdeletejobtest) add_libkgapi2_test(contacts contactsgroupfetchjobtest) add_libkgapi2_test(contacts contactsgroupmodifyjobtest) add_libkgapi2_test(calendar calendarcreatejobtest) add_libkgapi2_test(calendar calendardeletejobtest) add_libkgapi2_test(calendar calendarfetchjobtest) add_libkgapi2_test(calendar calendarmodifyjobtest) add_libkgapi2_test(calendar eventcreatejobtest) add_libkgapi2_test(calendar eventdeletejobtest) add_libkgapi2_test(calendar eventfetchjobtest) add_libkgapi2_test(calendar eventmodifyjobtest) add_libkgapi2_test(calendar freebusyqueryjobtest) add_libkgapi2_test(tasks taskcreatejobtest) add_libkgapi2_test(tasks taskdeletejobtest) add_libkgapi2_test(tasks taskfetchjobtest) add_libkgapi2_test(tasks taskmodifyjobtest) add_libkgapi2_test(tasks taskmovejobtest) add_libkgapi2_test(tasks tasklistcreatejobtest) add_libkgapi2_test(tasks tasklistdeletejobtest) add_libkgapi2_test(tasks tasklistfetchjobtest) add_libkgapi2_test(tasks tasklistmodifyjobtest) add_libkgapi2_test(drive aboutfetchjobtest) add_libkgapi2_test(drive changefetchjobtest) add_libkgapi2_test(drive filecopyjobtest) add_libkgapi2_test(drive filecreatejobtest) add_libkgapi2_test(drive filesearchquerytest) add_libkgapi2_test(drive teamdrivecreatejobtest) add_libkgapi2_test(drive teamdrivedeletejobtest) +add_libkgapi2_test(drive teamdrivemodifyjobtest) add_libkgapi2_test(drive teamdrivefetchjobtest) add_libkgapi2_test(drive teamdrivesearchquerytest) diff --git a/autotests/drive/data/teamdrive_modify_request.txt b/autotests/drive/data/teamdrive_modify_request.txt new file mode 100644 index 0000000..33dd1c8 --- /dev/null +++ b/autotests/drive/data/teamdrive_modify_request.txt @@ -0,0 +1,7 @@ +POST https://www.googleapis.com/drive/v2/teamdrives/0APqEW6eViiMXUk9PVA + +{ + "kind": "drive#teamDrive", + "id": "0APqEW6eViiMXUk9PVA", + "name": "Renamed Team Drive" +} diff --git a/autotests/drive/data/teamdrive_modify_response.txt b/autotests/drive/data/teamdrive_modify_response.txt new file mode 100644 index 0000000..a0f8607 --- /dev/null +++ b/autotests/drive/data/teamdrive_modify_response.txt @@ -0,0 +1,8 @@ +HTTP/1.1 200 OK +content-type: application/json; charset=UTF-8 + +{ + "kind": "drive#teamDrive", + "id": "0APqEW6eViiMXUk9PVA", + "name": "Renamed Team Drive" +} diff --git a/autotests/drive/teamdrivecreatejobtest.cpp b/autotests/drive/teamdrivecreatejobtest.cpp index 4ce2c7e..f3ac9f8 100644 --- a/autotests/drive/teamdrivecreatejobtest.cpp +++ b/autotests/drive/teamdrivecreatejobtest.cpp @@ -1,92 +1,92 @@ /* - * Createright (C) 2019 David Barchiesi + * Copyright (C) 2019 David Barchiesi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * - * You should have received a create of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include #include #include "fakenetworkaccessmanagerfactory.h" #include "testutils.h" #include "drivetestutils.h" #include "types.h" #include "teamdrivecreatejob.h" #include "teamdrive.h" #include "account.h" using namespace KGAPI2; Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(KGAPI2::Drive::TeamdrivePtr) class TeamdriveCreateJobTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase() { NetworkAccessManagerFactory::setFactory(new FakeNetworkAccessManagerFactory); } void testCreate_data() { QTest::addColumn>("scenarios"); QTest::addColumn("sourceTeamdrive"); QTest::addColumn("requestId"); QTest::addColumn("expectedResult"); QTest::newRow("metadata only") << QList{ scenarioFromFile(QFINDTESTDATA("data/teamdrive_create_request.txt"), QFINDTESTDATA("data/teamdrive_create_response.txt")) } << teamdriveFromFile(QFINDTESTDATA("data/teamdrive.json")) << QStringLiteral("MockRequestId") << teamdriveFromFile(QFINDTESTDATA("data/teamdrive.json")); } void testCreate() { QFETCH(QList, scenarios); QFETCH(Drive::TeamdrivePtr, sourceTeamdrive); QFETCH(QString, requestId); QFETCH(Drive::TeamdrivePtr, expectedResult); FakeNetworkAccessManagerFactory::get()->setScenarios(scenarios); auto account = AccountPtr::create(QStringLiteral("MockAccount"), QStringLiteral("MockToken")); Drive::TeamdriveCreateJob *job = new Drive::TeamdriveCreateJob(requestId, sourceTeamdrive, account); QVERIFY(execJob(job)); const auto items = job->items(); QCOMPARE(items.count(), 1); QVERIFY(*items.cbegin()); QCOMPARE(**items.cbegin(), *expectedResult); QCOMPARE(requestId, job->requestId()); } }; QTEST_GUILESS_MAIN(TeamdriveCreateJobTest) #include "teamdrivecreatejobtest.moc" diff --git a/autotests/drive/teamdrivedeletejobtest.cpp b/autotests/drive/teamdrivedeletejobtest.cpp index 565d406..e0563cd 100644 --- a/autotests/drive/teamdrivedeletejobtest.cpp +++ b/autotests/drive/teamdrivedeletejobtest.cpp @@ -1,80 +1,80 @@ /* - * Deleteright (C) 2019 David Barchiesi + * Copyright (C) 2019 David Barchiesi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * - * You should have received a delete of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include #include #include "fakenetworkaccessmanagerfactory.h" #include "testutils.h" #include "types.h" #include "teamdrivedeletejob.h" #include "teamdrive.h" #include "account.h" using namespace KGAPI2; Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(KGAPI2::Drive::TeamdrivePtr) class TeamdriveDeleteJobTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase() { NetworkAccessManagerFactory::setFactory(new FakeNetworkAccessManagerFactory); } void testDelete_data() { QTest::addColumn>("scenarios"); QTest::addColumn("teamdriveId"); QTest::newRow("metadata only") << QList{ scenarioFromFile(QFINDTESTDATA("data/teamdrive_delete_request.txt"), QFINDTESTDATA("data/generic_no_content_response.txt")) } << QStringLiteral("somelongid"); } void testDelete() { QFETCH(QList, scenarios); QFETCH(QString, teamdriveId); FakeNetworkAccessManagerFactory::get()->setScenarios(scenarios); auto account = AccountPtr::create(QStringLiteral("MockAccount"), QStringLiteral("MockToken")); Drive::TeamdriveDeleteJob *job = new Drive::TeamdriveDeleteJob(teamdriveId, account); QVERIFY(execJob(job)); } }; QTEST_GUILESS_MAIN(TeamdriveDeleteJobTest) #include "teamdrivedeletejobtest.moc" diff --git a/autotests/drive/teamdrivecreatejobtest.cpp b/autotests/drive/teamdrivemodifyjobtest.cpp similarity index 72% copy from autotests/drive/teamdrivecreatejobtest.cpp copy to autotests/drive/teamdrivemodifyjobtest.cpp index 4ce2c7e..1d767eb 100644 --- a/autotests/drive/teamdrivecreatejobtest.cpp +++ b/autotests/drive/teamdrivemodifyjobtest.cpp @@ -1,92 +1,93 @@ /* - * Createright (C) 2019 David Barchiesi + * Copyright (C) 2019 David Barchiesi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * - * You should have received a create of the GNU Lesser General Public + * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #include #include #include "fakenetworkaccessmanagerfactory.h" #include "testutils.h" #include "drivetestutils.h" #include "types.h" -#include "teamdrivecreatejob.h" +#include "teamdrivemodifyjob.h" #include "teamdrive.h" #include "account.h" using namespace KGAPI2; Q_DECLARE_METATYPE(QList) Q_DECLARE_METATYPE(KGAPI2::Drive::TeamdrivePtr) -class TeamdriveCreateJobTest : public QObject +class TeamdriveModifyJobTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase() { NetworkAccessManagerFactory::setFactory(new FakeNetworkAccessManagerFactory); } - void testCreate_data() + void testModify_data() { QTest::addColumn>("scenarios"); QTest::addColumn("sourceTeamdrive"); QTest::addColumn("requestId"); - QTest::addColumn("expectedResult"); QTest::newRow("metadata only") << QList{ - scenarioFromFile(QFINDTESTDATA("data/teamdrive_create_request.txt"), - QFINDTESTDATA("data/teamdrive_create_response.txt")) + scenarioFromFile(QFINDTESTDATA("data/teamdrive_modify_request.txt"), + QFINDTESTDATA("data/teamdrive_modify_response.txt")) } << teamdriveFromFile(QFINDTESTDATA("data/teamdrive.json")) - << QStringLiteral("MockRequestId") - << teamdriveFromFile(QFINDTESTDATA("data/teamdrive.json")); + << QStringLiteral("MockRequestId"); } - void testCreate() + void testModify() { QFETCH(QList, scenarios); QFETCH(Drive::TeamdrivePtr, sourceTeamdrive); QFETCH(QString, requestId); - QFETCH(Drive::TeamdrivePtr, expectedResult); FakeNetworkAccessManagerFactory::get()->setScenarios(scenarios); + sourceTeamdrive->setName(QStringLiteral("Renamed Team Drive")); + auto account = AccountPtr::create(QStringLiteral("MockAccount"), QStringLiteral("MockToken")); - Drive::TeamdriveCreateJob *job = new Drive::TeamdriveCreateJob(requestId, sourceTeamdrive, account); + Drive::TeamdriveModifyJob *job = new Drive::TeamdriveModifyJob(sourceTeamdrive, account); QVERIFY(execJob(job)); + const auto items = job->items(); QCOMPARE(items.count(), 1); - QVERIFY(*items.cbegin()); - QCOMPARE(**items.cbegin(), *expectedResult); - QCOMPARE(requestId, job->requestId()); + + Drive::TeamdrivePtr firstResult = (*items.cbegin()).dynamicCast(); + QVERIFY(firstResult); + QCOMPARE(*firstResult, *sourceTeamdrive); } }; -QTEST_GUILESS_MAIN(TeamdriveCreateJobTest) +QTEST_GUILESS_MAIN(TeamdriveModifyJobTest) -#include "teamdrivecreatejobtest.moc" +#include "teamdrivemodifyjobtest.moc" diff --git a/examples/teamdrive/mainwindow.cpp b/examples/teamdrive/mainwindow.cpp index 989b629..ac4a951 100644 --- a/examples/teamdrive/mainwindow.cpp +++ b/examples/teamdrive/mainwindow.cpp @@ -1,251 +1,295 @@ /* Copyright (C) 2019 David Barchiesi This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "mainwindow.h" #include "ui_main.h" #include #include #include #include +#include #include #include #include #include #include #include #include #include MainWindow::MainWindow(QWidget * parent): QMainWindow(parent), m_ui(new Ui::MainWindow) { /* Initialize GUI */ m_ui->setupUi(this); m_ui->errorLabel->setVisible(false); connect(m_ui->authButton, &QAbstractButton::clicked, this, &MainWindow::authenticate); connect(m_ui->newTeamdriveButton, &QAbstractButton::clicked, this, &MainWindow::createTeamdrive); connect(m_ui->teamdriveListButton, &QAbstractButton::clicked, this, &MainWindow::fetchTeamdriveList); connect(m_ui->teamdriveSelectedDeleteButton, &QAbstractButton::clicked, this, &MainWindow::deleteSelectedTeamdrive); + connect(m_ui->renameTeamdriveButton, &QAbstractButton::clicked, + this, &MainWindow::renameSelectedTeamdrive); connect(m_ui->teamdriveList, &QListWidget::itemSelectionChanged, this, &MainWindow::teamdriveSelected); } MainWindow::~MainWindow() { delete m_ui; } void MainWindow::authenticate() { KGAPI2::AccountPtr account(new KGAPI2::Account); account->setScopes( QList() << KGAPI2::Account::driveScopeUrl() ); /* Create AuthJob to retrieve OAuth tokens for the account */ KGAPI2::AuthJob *authJob = new KGAPI2::AuthJob( account, QStringLiteral("554041944266.apps.googleusercontent.com"), QStringLiteral("mdT1DjzohxN3npUUzkENT0gO")); connect(authJob, &KGAPI2::Job::finished, this, &MainWindow::slotAuthJobFinished); } void MainWindow::slotAuthJobFinished(KGAPI2::Job *job) { KGAPI2::AuthJob *authJob = qobject_cast(job); Q_ASSERT(authJob); /* Always remember to delete the jobs, otherwise your application will * leak memory. */ authJob->deleteLater(); if (authJob->error() != KGAPI2::NoError) { m_ui->errorLabel->setText(QStringLiteral("Error: %1").arg(authJob->errorString())); m_ui->errorLabel->setVisible(true); return; } m_account = authJob->account(); m_ui->authStatusLabel->setText(QStringLiteral("Authenticated")); m_ui->teamdriveListButton->setEnabled(true); + m_ui->newTeamdriveEdit->setEnabled(true); + m_ui->newTeamdriveButton->setEnabled(true); m_ui->authButton->setEnabled(false); } void MainWindow::createTeamdrive() { QString teamdriveName = m_ui->newTeamdriveEdit->text(); if (teamdriveName.isEmpty()) { return; } QString requestId = QUuid::createUuid().toString(); KGAPI2::Drive::TeamdrivePtr teamdrive = KGAPI2::Drive::TeamdrivePtr::create(); teamdrive->setName(teamdriveName); + KGAPI2::Drive::TeamdriveCreateJob *createJob = new KGAPI2::Drive::TeamdriveCreateJob(requestId, teamdrive, m_account, this); connect(createJob, &KGAPI2::Job::finished, this, &MainWindow::slotTeamdriveCreateJobFinished); } void MainWindow::slotTeamdriveCreateJobFinished(KGAPI2::Job *job) { KGAPI2::Drive::TeamdriveCreateJob *createJob = qobject_cast(job); Q_ASSERT(createJob); createJob->deleteLater(); if (createJob->error() != KGAPI2::NoError) { m_ui->errorLabel->setText(QStringLiteral("Error: %1").arg(createJob->errorString())); m_ui->errorLabel->setVisible(true); m_ui->teamdriveListButton->setEnabled(true); return; } m_ui->newTeamdriveEdit->clear(); fetchTeamdriveList(); } +void MainWindow::renameSelectedTeamdrive() +{ + QString teamdriveName = m_ui->renameTeamdriveEdit->text(); + if (teamdriveName.isEmpty()) { + return; + } + QString teamdriveId = m_ui->teamdriveList->selectedItems().at(0)->data(Qt::UserRole).toString(); + + KGAPI2::Drive::TeamdrivePtr teamdrive = KGAPI2::Drive::TeamdrivePtr::create(); + teamdrive->setId(teamdriveId); + teamdrive->setName(teamdriveName); + + KGAPI2::Drive::TeamdriveModifyJob *modifyJob = new KGAPI2::Drive::TeamdriveModifyJob(teamdrive, m_account, this); + connect(modifyJob, &KGAPI2::Job::finished, + this, &MainWindow::slotTeamdriveModifyJobFinished); +} + +void MainWindow::slotTeamdriveModifyJobFinished(KGAPI2::Job *job) +{ + KGAPI2::Drive::TeamdriveModifyJob *modifyJob = qobject_cast(job); + Q_ASSERT(modifyJob); + modifyJob->deleteLater(); + + if (modifyJob->error() != KGAPI2::NoError) { + m_ui->errorLabel->setText(QStringLiteral("Error: %1").arg(modifyJob->errorString())); + m_ui->errorLabel->setVisible(true); + m_ui->teamdriveListButton->setEnabled(true); + return; + } + + fetchTeamdriveList(); +} + void MainWindow::fetchTeamdriveList() { if (m_account.isNull()) { m_ui->errorLabel->setText(QStringLiteral("Error: Please authenticate first")); m_ui->errorLabel->setVisible(true); m_ui->authButton->setVisible(true); return; } KGAPI2::Drive::TeamdriveFetchJob *fetchJob = new KGAPI2::Drive::TeamdriveFetchJob(m_account, this); connect(fetchJob, &KGAPI2::Job::finished, this, &MainWindow::slotFetchJobFinished); m_ui->teamdriveListButton->setEnabled(false); } void MainWindow::slotFetchJobFinished(KGAPI2::Job *job) { KGAPI2::Drive::TeamdriveFetchJob *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); m_ui->teamdriveListButton->setEnabled(true); return; } /* Get all items the job has retrieved */ const KGAPI2::ObjectsList objects = fetchJob->items(); m_ui->teamdriveList->clear(); for (const KGAPI2::ObjectPtr &object : objects) { const KGAPI2::Drive::TeamdrivePtr teamdrive = object.dynamicCast(); /* Convert the teamdrive to QListWidget item */ QListWidgetItem *item = new QListWidgetItem(m_ui->teamdriveList); item->setText(teamdrive->name()); item->setData(Qt::UserRole, teamdrive->id()); m_ui->teamdriveList->addItem(item); } m_ui->teamdriveListButton->setEnabled(true); } void MainWindow::deleteSelectedTeamdrive() { const QString teamdrive_id = m_ui->teamdriveList->selectedItems().at(0)->data(Qt::UserRole).toString(); KGAPI2::Drive::TeamdriveDeleteJob *deleteJob = new KGAPI2::Drive::TeamdriveDeleteJob(teamdrive_id, m_account, this); connect(deleteJob, &KGAPI2::Job::finished, this, &MainWindow::slotTeamdriveDeleteJobFinished); } void MainWindow::slotTeamdriveDeleteJobFinished(KGAPI2::Job *job) { KGAPI2::Drive::TeamdriveDeleteJob *deleteJob = qobject_cast(job); Q_ASSERT(deleteJob); deleteJob->deleteLater(); if (deleteJob->error() != KGAPI2::NoError) { m_ui->errorLabel->setText(QStringLiteral("Error: %1").arg(deleteJob->errorString())); m_ui->errorLabel->setVisible(true); m_ui->teamdriveListButton->setEnabled(true); return; } fetchTeamdriveList(); } void MainWindow::teamdriveSelected() { bool hasSelection = (m_ui->teamdriveList->selectedItems().count() != 0); m_ui->teamdriveSelectedDeleteButton->setEnabled(hasSelection); + m_ui->renameTeamdriveButton->setEnabled(hasSelection); + m_ui->renameTeamdriveEdit->setEnabled(hasSelection); 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 | KGAPI2::Drive::FileFetchJob::LastViewedByMeDate); connect(fileFetchJob, &KGAPI2::Job::finished, this, &MainWindow::slotTeamdriveFetchJobFinished); } void MainWindow::slotTeamdriveFetchJobFinished(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); m_ui->teamdriveListButton->setEnabled(true); return; } /* Get all items we have received from Google (should be just one) */ 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'); } m_ui->teamdrivePreview->setText(text); } diff --git a/examples/teamdrive/mainwindow.h b/examples/teamdrive/mainwindow.h index b7346dc..9ff23f6 100644 --- a/examples/teamdrive/mainwindow.h +++ b/examples/teamdrive/mainwindow.h @@ -1,107 +1,117 @@ /* Copyright (C) 2019 David Barchiesi This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef MAINWINDOW_H #define MAINWINDOW_H #include #include namespace Ui { class MainWindow; } namespace KGAPI2 { class Job; } class MainWindow : public QMainWindow { Q_OBJECT public: explicit MainWindow(QWidget *parent = nullptr); ~MainWindow() override; private Q_SLOTS: /** * Retrieves tokens from Google that we will use to authenticate * fursther requests */ void authenticate(); /** * Authentication has finished */ void slotAuthJobFinished(KGAPI2::Job *job); /** * Creates the Team Drive with name in newTeamdriveEdit */ void createTeamdrive(); /** * Team Drive was created. */ void slotTeamdriveCreateJobFinished(KGAPI2::Job *job); + /** + * Rename the selected Team Drive with name in renameTeamdriveEdit + */ + void renameSelectedTeamdrive(); + + /** + * Team Drive was modified. + */ + void slotTeamdriveModifyJobFinished(KGAPI2::Job *job); + /** * All Team Drives were fetched. */ void slotFetchJobFinished(KGAPI2::Job *job); /** * Team Drive listing was fetched. */ void slotTeamdriveFetchJobFinished(KGAPI2::Job *job); /** * Retrieves list of all teamdrive from user's Google teamdrive * addressbook */ void fetchTeamdriveList(); /** * Deletes the selected Team Drive */ void deleteSelectedTeamdrive(); /** * Team Drive was deleted. */ 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 */ void teamdriveSelected(); private: Ui::MainWindow *m_ui; KGAPI2::AccountPtr m_account; }; #endif // MAINWINDOW_H diff --git a/examples/teamdrive/ui/main.ui b/examples/teamdrive/ui/main.ui index d52e9b0..396ddf3 100644 --- a/examples/teamdrive/ui/main.ui +++ b/examples/teamdrive/ui/main.ui @@ -1,194 +1,222 @@ MainWindow 0 0 640 486 MainWindow Authenticate Not authenticated Qt::Horizontal - + + + false + + + + false + Create + + + + + + false + + + + + + + false + + + Rename + + + + + false Get Team Drive list false Delete selected Team Drive 12 75 true Qt::RightToLeft Team Drive list Qt::AlignCenter 12 75 true Qt::RightToLeft Team Drive folder preview Qt::AlignCenter true 0 0 640 30 File Quit actionQuit activated() MainWindow close() -1 -1 319 206 diff --git a/src/drive/CMakeLists.txt b/src/drive/CMakeLists.txt index 0b0af28..dc88f77 100644 --- a/src/drive/CMakeLists.txt +++ b/src/drive/CMakeLists.txt @@ -1,152 +1,154 @@ set(kgapidrive_SRCS about.cpp aboutfetchjob.cpp app.cpp appfetchjob.cpp change.cpp changefetchjob.cpp childreference.cpp childreferencecreatejob.cpp childreferencedeletejob.cpp childreferencefetchjob.cpp driveservice.cpp searchquery.cpp file.cpp fileabstractdatajob.cpp fileabstractmodifyjob.cpp fileabstractuploadjob.cpp filecopyjob.cpp filecreatejob.cpp filedeletejob.cpp filefetchcontentjob.cpp filefetchjob.cpp filemodifyjob.cpp filesearchquery.cpp filetouchjob.cpp filetrashjob.cpp fileuntrashjob.cpp parentreference.cpp parentreferencecreatejob.cpp parentreferencedeletejob.cpp parentreferencefetchjob.cpp permission.cpp permissioncreatejob.cpp permissiondeletejob.cpp permissionfetchjob.cpp permissionmodifyjob.cpp revision.cpp revisiondeletejob.cpp revisionfetchjob.cpp revisionmodifyjob.cpp teamdrive.cpp teamdrivecreatejob.cpp teamdrivedeletejob.cpp teamdrivefetchjob.cpp + teamdrivemodifyjob.cpp teamdrivesearchquery.cpp user.cpp ../debug.cpp ) ecm_generate_headers(kgapidrive_CamelCase_HEADERS HEADER_NAMES About AboutFetchJob App AppFetchJob Change ChangeFetchJob ChildReference ChildReferenceCreateJob ChildReferenceDeleteJob ChildReferenceFetchJob SearchQuery File FileAbstractDataJob FileAbstractModifyJob FileAbstractUploadJob FileCopyJob FileCreateJob FileDeleteJob FileFetchContentJob FileFetchJob FileModifyJob FileSearchQuery FileTouchJob FileTrashJob FileUntrashJob ParentReference ParentReferenceCreateJob ParentReferenceDeleteJob ParentReferenceFetchJob Permission PermissionCreateJob PermissionDeleteJob PermissionFetchJob PermissionModifyJob Revision RevisionDeleteJob RevisionFetchJob RevisionModifyJob Teamdrive TeamdriveCreateJob TeamdriveDeleteJob TeamdriveFetchJob + TeamdriveModifyJob TeamdriveSearchQuery User PREFIX KGAPI/Drive REQUIRED_HEADERS kgapidrive_HEADERS ) add_library(KPimGAPIDrive ${kgapidrive_SRCS} ) generate_export_header(KPimGAPIDrive BASE_NAME kgapidrive) add_library(KPim::GAPIDrive ALIAS KPimGAPIDrive) # TODO: Backwards compatibility, remove in next major release add_library(KF5::GAPIDrive ALIAS KPimGAPIDrive) target_include_directories(KPimGAPIDrive INTERFACE "$") target_link_libraries(KPimGAPIDrive PUBLIC KPim::GAPICore PRIVATE Qt5::Network ) set_target_properties(KPimGAPIDrive PROPERTIES VERSION ${KGAPI_VERSION_STRING} SOVERSION ${KGAPI_SOVERSION} EXPORT_NAME GAPIDrive ) install(TARGETS KPimGAPIDrive EXPORT KPimGAPITargets ${KDE_INSTALL_TARGETS_DEFAULT_ARGS} ) install(FILES ${kgapidrive_CamelCase_HEADERS} DESTINATION "${KDE_INSTALL_INCLUDEDIR}/KPim/KGAPI/KGAPI/Drive" COMPONENT Devel ) install(FILES ${kgapidrive_HEADERS} "${CMAKE_CURRENT_BINARY_DIR}/kgapidrive_export.h" DESTINATION "${KDE_INSTALL_INCLUDEDIR}/KPim/KGAPI/kgapi/drive" COMPONENT Devel ) ecm_generate_pri_file(BASE_NAME KGAPIDrive LIB_NAME KPimGAPIDrive DEPS "GAPICore" FILENAME_VAR PRI_FILENAME INCLUDE_INSTALL_DIR "${KDE_INSTALL_INCLUDEDIR}/KPim/KGAPI" ) install(FILES "${PRI_FILENAME}" DESTINATION "${ECM_MKSPECS_INSTALL_DIR}" ) diff --git a/src/drive/teamdrive.cpp b/src/drive/teamdrive.cpp index 7a63f6f..75bbe12 100644 --- a/src/drive/teamdrive.cpp +++ b/src/drive/teamdrive.cpp @@ -1,627 +1,692 @@ /* Copyright (C) 2019 David Barchiesi This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "driveservice.h" #include "teamdrive.h" #include "utils_p.h" #include #include #include namespace { static const QString ApiKind = QStringLiteral("drive#teamDrive"); static const QString ApiKindList = QStringLiteral("drive#teamDriveList"); static const QString AdminManagedRestrictionsAttr = QStringLiteral("adminManagedRestrictions"); static const QString BackgroundImageFileAttr = QStringLiteral("backgroundImageFile"); static const QString BackgroundImageLinkAttr = QStringLiteral("backgroundImageLink"); static const QString CanAddChildrenAttr = QStringLiteral("canAddChildren"); static const QString CanChangeCopyRequiresWriterPermissionRestrictionAttr = QStringLiteral("canChangeCopyRequiresWriterPermissionRestriction"); static const QString CanChangeDomainUsersOnlyRestrictionAttr = QStringLiteral("canChangeDomainUsersOnlyRestriction"); static const QString CanChangeTeamDriveBackgroundAttr = QStringLiteral("canChangeTeamDriveBackground"); static const QString CanChangeTeamMembersOnlyRestrictionAttr = QStringLiteral("canChangeTeamMembersOnlyRestriction"); static const QString CanCommentAttr = QStringLiteral("canComment"); static const QString CanCopyAttr = QStringLiteral("canCopy"); static const QString CanDeleteChildrenAttr = QStringLiteral("canDeleteChildren"); static const QString CanDeleteTeamDriveAttr = QStringLiteral("canDeleteTeamDrive"); static const QString CanDownloadAttr = QStringLiteral("canDownload"); static const QString CanEditAttr = QStringLiteral("canEdit"); static const QString CanListChildrenAttr = QStringLiteral("canListChildren"); static const QString CanManageMembersAttr = QStringLiteral("canManageMembers"); static const QString CanReadRevisionsAttr = QStringLiteral("canReadRevisions"); static const QString CanRenameAttr = QStringLiteral("canRename"); static const QString CanRenameTeamDriveAttr = QStringLiteral("canRenameTeamDrive"); static const QString CanShareAttr = QStringLiteral("canShare"); static const QString CanTrashChildrenAttr = QStringLiteral("canTrashChildren"); static const QString CapabilitiesAttr = QStringLiteral("capabilities"); static const QString ColorRgbAttr = QStringLiteral("colorRgb"); static const QString CopyRequiresWriterPermissionAttr = QStringLiteral("copyRequiresWriterPermission"); static const QString CreatedDateAttr = QStringLiteral("createdDate"); static const QString DomainUsersOnlyAttr = QStringLiteral("domainUsersOnly"); static const QString IdAttr = QStringLiteral("id"); static const QString ItemsAttr = QStringLiteral("items"); static const QString KindAttr = QStringLiteral("kind"); static const QString KindDriveAttr = QStringLiteral("kind"); static const QString NameAttr = QStringLiteral("name"); static const QString PageTokenAttr = QStringLiteral("pageToken"); static const QString NextPageTokenAttr = QStringLiteral("nextPageToken"); static const QString RestrictionsAttr = QStringLiteral("restrictions"); static const QString TeamMembersOnlyAttr = QStringLiteral("teamMembersOnly"); static const QString ThemeIdAttr = QStringLiteral("themeId"); static const QString WidthAttr = QStringLiteral("width"); static const QString XCoordinateAttr = QStringLiteral("xCoordinate"); static const QString YCoordinateAttr = QStringLiteral("yCoordinate"); } using namespace KGAPI2; using namespace KGAPI2::Drive; ///// DriveTeamdrive::Restrictions class Q_DECL_HIDDEN Teamdrive::Restrictions::Private { public: Private() = default; Private(const Private &other) = default; bool adminManagedRestrictions = false; bool copyRequiresWriterPermission = false; bool domainUsersOnly = false; bool teamMembersOnly = false; }; Teamdrive::Restrictions::Restrictions(): d(new Private) { } Teamdrive::Restrictions::Restrictions(const Teamdrive::Restrictions &other): d(new Private(*(other.d))) { } Teamdrive::Restrictions::~Restrictions() = default; bool Teamdrive::Restrictions::operator==(const Teamdrive::Restrictions &other) const { GAPI_COMPARE(adminManagedRestrictions); GAPI_COMPARE(copyRequiresWriterPermission); GAPI_COMPARE(domainUsersOnly); GAPI_COMPARE(teamMembersOnly); return true; } bool Teamdrive::Restrictions::adminManagedRestrictions() const { return d->adminManagedRestrictions; } +void Teamdrive::Restrictions::setAdminManagedRestrictions(bool adminManagedRestrictions) const +{ + d->adminManagedRestrictions = adminManagedRestrictions; +} + bool Teamdrive::Restrictions::copyRequiresWriterPermission() const { return d->copyRequiresWriterPermission; } +void Teamdrive::Restrictions::setCopyRequiresWriterPermission(bool copyRequiresWriterPermission) const +{ + d->copyRequiresWriterPermission = copyRequiresWriterPermission; +} + bool Teamdrive::Restrictions::domainUsersOnly() const { return d->domainUsersOnly; } +void Teamdrive::Restrictions::setDomainUsersOnly(bool domainUsersOnly) const +{ + d->domainUsersOnly = domainUsersOnly; +} + bool Teamdrive::Restrictions::teamMembersOnly() const { return d->teamMembersOnly; } +void Teamdrive::Restrictions::setTeamMembersOnly(bool teamMembersOnly) const +{ + d->teamMembersOnly = teamMembersOnly; +} + ///// DriveTeamdrive::Capabilities class Q_DECL_HIDDEN Teamdrive::Capabilities::Private { public: Private() = default; Private(const Private &other) = default; bool canAddChildren = false; bool canChangeCopyRequiresWriterPermissionRestriction = false; bool canChangeDomainUsersOnlyRestriction = false; bool canChangeTeamDriveBackground = false; bool canChangeTeamMembersOnlyRestriction = false; bool canComment = false; bool canCopy = false; bool canDeleteChildren = false; bool canDeleteTeamDrive = false; bool canDownload = false; bool canEdit = false; bool canListChildren = false; bool canManageMembers = false; bool canReadRevisions = false; bool canRename = false; bool canRenameTeamDrive = false; bool canShare = false; bool canTrashChildren = false; }; Teamdrive::Capabilities::Capabilities(): d(new Private) { } Teamdrive::Capabilities::Capabilities(const Teamdrive::Capabilities &other): d(new Private(*(other.d))) { } Teamdrive::Capabilities::~Capabilities() = default; bool Teamdrive::Capabilities::operator==(const Teamdrive::Capabilities &other) const { GAPI_COMPARE(canAddChildren); GAPI_COMPARE(canChangeCopyRequiresWriterPermissionRestriction); GAPI_COMPARE(canChangeDomainUsersOnlyRestriction); GAPI_COMPARE(canChangeTeamDriveBackground); GAPI_COMPARE(canChangeTeamMembersOnlyRestriction); GAPI_COMPARE(canComment); GAPI_COMPARE(canCopy); GAPI_COMPARE(canDeleteChildren); GAPI_COMPARE(canDeleteTeamDrive); GAPI_COMPARE(canDownload); GAPI_COMPARE(canEdit); GAPI_COMPARE(canListChildren); GAPI_COMPARE(canManageMembers); GAPI_COMPARE(canReadRevisions); GAPI_COMPARE(canRename); GAPI_COMPARE(canRenameTeamDrive); GAPI_COMPARE(canShare); GAPI_COMPARE(canTrashChildren); return true; } bool Teamdrive::Capabilities::canAddChildren() const { return d->canAddChildren; } bool Teamdrive::Capabilities::canChangeCopyRequiresWriterPermissionRestriction() const { return d->canChangeCopyRequiresWriterPermissionRestriction; } bool Teamdrive::Capabilities::canChangeDomainUsersOnlyRestriction() const { return d->canChangeDomainUsersOnlyRestriction; } bool Teamdrive::Capabilities::canChangeTeamDriveBackground() const { return d->canChangeTeamDriveBackground; } bool Teamdrive::Capabilities::canChangeTeamMembersOnlyRestriction() const { return d->canChangeTeamMembersOnlyRestriction; } bool Teamdrive::Capabilities::canComment() const { return d->canComment; } bool Teamdrive::Capabilities::canCopy() const { return d->canCopy; } bool Teamdrive::Capabilities::canDeleteChildren() const { return d->canDeleteChildren; } bool Teamdrive::Capabilities::canDeleteTeamDrive() const { return d->canDeleteTeamDrive; } bool Teamdrive::Capabilities::canDownload() const { return d->canDownload; } bool Teamdrive::Capabilities::canEdit() const { return d->canEdit; } bool Teamdrive::Capabilities::canListChildren() const { return d->canListChildren; } bool Teamdrive::Capabilities::canManageMembers() const { return d->canManageMembers; } bool Teamdrive::Capabilities::canReadRevisions() const { return d->canReadRevisions; } bool Teamdrive::Capabilities::canRename() const { return d->canRename; } bool Teamdrive::Capabilities::canRenameTeamDrive() const { return d->canRenameTeamDrive; } bool Teamdrive::Capabilities::canShare() const { return d->canShare; } bool Teamdrive::Capabilities::canTrashChildren() const { return d->canTrashChildren; } ///// DriveTeamdrive::BackgroundImageFile class Q_DECL_HIDDEN Teamdrive::BackgroundImageFile::Private { public: Private() = default; Private(const Private &other) = default; QString id; float xCoordinate = 0.0f; float yCoordinate = 0.0f; float width = 0.0f; }; Teamdrive::BackgroundImageFile::BackgroundImageFile(): d(new Private) { } Teamdrive::BackgroundImageFile::BackgroundImageFile(const Teamdrive::BackgroundImageFile &other): d(new Private(*(other.d))) { } Teamdrive::BackgroundImageFile::~BackgroundImageFile() = default; bool Teamdrive::BackgroundImageFile::operator==(const Teamdrive::BackgroundImageFile &other) const { GAPI_COMPARE(id); GAPI_COMPARE(xCoordinate); GAPI_COMPARE(yCoordinate); GAPI_COMPARE(width); return true; } QString Teamdrive::BackgroundImageFile::id() const { return d->id; } +void Teamdrive::BackgroundImageFile::setId(const QString &id) const +{ + d->id = id; +} + float Teamdrive::BackgroundImageFile::xCoordinate() const { return d->xCoordinate; } +void Teamdrive::BackgroundImageFile::setXCoordinate(const float xCoordinate) const +{ + d->xCoordinate = xCoordinate; +} + float Teamdrive::BackgroundImageFile::yCoordinate() const { return d->yCoordinate; } +void Teamdrive::BackgroundImageFile::setYCoordinate(const float yCoordinate) const +{ + d->yCoordinate = yCoordinate; +} + float Teamdrive::BackgroundImageFile::width() const { return d->width; } +void Teamdrive::BackgroundImageFile::setWidth(const float width) const +{ + d->width = width; +} + ///// DriveTeamdrive class Q_DECL_HIDDEN Teamdrive::Private { public: Private() = default; Private(const Private& other) = default; QString id; QString name; QString themeId; QString colorRgb; BackgroundImageFilePtr backgroundImageFile; QString backgroundImageLink; CapabilitiesPtr capabilities; QDateTime createdDate; RestrictionsPtr restrictions; static TeamdrivePtr fromJSON(const QVariantMap &map); }; TeamdrivePtr Teamdrive::Private::fromJSON(const QVariantMap &map) { if (!map.contains(KindAttr) || map[KindAttr].toString() != ApiKind) { return TeamdrivePtr(); } auto teamdrive = TeamdrivePtr::create(); if (map.contains(IdAttr)) { teamdrive->d->id = map[IdAttr].toString(); } if (map.contains(NameAttr)) { teamdrive->d->name = map[NameAttr].toString(); } if (map.contains(ThemeIdAttr)) { teamdrive->d->themeId = map[ThemeIdAttr].toString(); } if (map.contains(ColorRgbAttr)) { teamdrive->d->colorRgb = map[ColorRgbAttr].toString(); } if (map.contains(BackgroundImageLinkAttr)) { teamdrive->d->backgroundImageLink = map[BackgroundImageLinkAttr].toString(); } if (map.contains(CreatedDateAttr)) { teamdrive->d->createdDate = QDateTime::fromString(map[CreatedDateAttr].toString(), Qt::ISODate); } if (map.contains(BackgroundImageFileAttr)) { const QVariantMap backgroundImageFileMap = map[BackgroundImageFileAttr].toMap(); auto backgroundImageFile = BackgroundImageFilePtr::create(); backgroundImageFile->d->id = backgroundImageFileMap[IdAttr].toString(); backgroundImageFile->d->xCoordinate = backgroundImageFileMap[XCoordinateAttr].toReal(); backgroundImageFile->d->yCoordinate = backgroundImageFileMap[YCoordinateAttr].toReal(); backgroundImageFile->d->width = backgroundImageFileMap[WidthAttr].toReal(); teamdrive->d->backgroundImageFile = backgroundImageFile; } if (map.contains(CapabilitiesAttr)) { const QVariantMap capabilitiesMap = map[CapabilitiesAttr].toMap(); auto capabilities = CapabilitiesPtr::create(); capabilities->d->canAddChildren = capabilitiesMap[CanAddChildrenAttr].toBool(); capabilities->d->canChangeCopyRequiresWriterPermissionRestriction = capabilitiesMap[CanChangeCopyRequiresWriterPermissionRestrictionAttr].toBool(); capabilities->d->canChangeDomainUsersOnlyRestriction = capabilitiesMap[CanChangeDomainUsersOnlyRestrictionAttr].toBool(); capabilities->d->canChangeTeamDriveBackground = capabilitiesMap[CanChangeTeamDriveBackgroundAttr].toBool(); capabilities->d->canChangeTeamMembersOnlyRestriction = capabilitiesMap[CanChangeTeamMembersOnlyRestrictionAttr].toBool(); capabilities->d->canComment = capabilitiesMap[CanCommentAttr].toBool(); capabilities->d->canCopy = capabilitiesMap[CanCopyAttr].toBool(); capabilities->d->canDeleteChildren = capabilitiesMap[CanDeleteChildrenAttr].toBool(); capabilities->d->canDeleteTeamDrive = capabilitiesMap[CanDeleteTeamDriveAttr].toBool(); capabilities->d->canDownload = capabilitiesMap[CanDownloadAttr].toBool(); capabilities->d->canEdit = capabilitiesMap[CanEditAttr].toBool(); capabilities->d->canListChildren = capabilitiesMap[CanListChildrenAttr].toBool(); capabilities->d->canManageMembers = capabilitiesMap[CanManageMembersAttr].toBool(); capabilities->d->canReadRevisions = capabilitiesMap[CanReadRevisionsAttr].toBool(); capabilities->d->canRename = capabilitiesMap[CanRenameAttr].toBool(); capabilities->d->canRenameTeamDrive = capabilitiesMap[CanRenameTeamDriveAttr].toBool(); capabilities->d->canShare = capabilitiesMap[CanShareAttr].toBool(); capabilities->d->canTrashChildren = capabilitiesMap[CanTrashChildrenAttr].toBool(); teamdrive->d->capabilities = capabilities; } if (map.contains(RestrictionsAttr)) { const QVariantMap restrictionsMap = map[RestrictionsAttr].toMap(); auto restrictions = RestrictionsPtr::create(); restrictions->d->adminManagedRestrictions = restrictionsMap[AdminManagedRestrictionsAttr].toBool(); restrictions->d->copyRequiresWriterPermission = restrictionsMap[CopyRequiresWriterPermissionAttr].toBool(); restrictions->d->domainUsersOnly = restrictionsMap[DomainUsersOnlyAttr].toBool(); restrictions->d->teamMembersOnly = restrictionsMap[TeamMembersOnlyAttr].toBool(); teamdrive->d->restrictions = restrictions; } return teamdrive; } Teamdrive::Teamdrive(): KGAPI2::Object(), d(new Private) { } Teamdrive::Teamdrive(const Teamdrive& other): KGAPI2::Object(other), d(new Private(*(other.d))) { } Teamdrive::~Teamdrive() = default; bool Teamdrive::operator==(const Teamdrive &other) const { if (!Object::operator==(other)) { return false; } GAPI_COMPARE(id); GAPI_COMPARE(name); GAPI_COMPARE(themeId); GAPI_COMPARE(colorRgb); GAPI_COMPARE_SHAREDPTRS(backgroundImageFile); GAPI_COMPARE(backgroundImageLink); GAPI_COMPARE_SHAREDPTRS(capabilities); GAPI_COMPARE(createdDate); GAPI_COMPARE_SHAREDPTRS(restrictions); return true; } QString Teamdrive::id() const { return d->id; } +void Teamdrive::setId(const QString &id) const +{ + d->id = id; +} + QString Teamdrive::name() const { return d->name; } void Teamdrive::setName(const QString &name) const { d->name = name; } QString Teamdrive::themeId() const { return d->themeId; } +void Teamdrive::setThemeId(const QString &themeId) const +{ + d->themeId = themeId; +} + QString Teamdrive::colorRgb() const { return d->colorRgb; } +void Teamdrive::setColorRgb(const QString &colorRgb) const +{ + d->colorRgb = colorRgb; +} + Teamdrive::BackgroundImageFilePtr Teamdrive::backgroundImageFile() const { return d->backgroundImageFile; } +void Teamdrive::setBackgroundImageFile(const Teamdrive::BackgroundImageFilePtr &backgroundImageFile) const +{ + d->backgroundImageFile = backgroundImageFile; +} + QString Teamdrive::backgroundImageLink() const { return d->backgroundImageLink; } Teamdrive::CapabilitiesPtr Teamdrive::capabilities() const { return d->capabilities; } QDateTime Teamdrive::createdDate() const { return d->createdDate; } +void Teamdrive::setRestrictions(const Teamdrive::RestrictionsPtr &restrictions) const +{ + d->restrictions = restrictions; +} + Teamdrive::RestrictionsPtr Teamdrive::restrictions() const { return d->restrictions; } TeamdrivePtr Teamdrive::fromJSON(const QByteArray &jsonData) { QJsonDocument document = QJsonDocument::fromJson(jsonData); if (document.isNull()) { return TeamdrivePtr(); } const QVariant data = document.toVariant(); return Private::fromJSON(data.toMap()); } TeamdrivesList Teamdrive::fromJSONFeed(const QByteArray &jsonData, FeedData &feedData) { QJsonDocument document = QJsonDocument::fromJson(jsonData); if (document.isNull()) { return TeamdrivesList(); } const QVariant data = document.toVariant(); const QVariantMap map = data.toMap(); if (!map.contains(KindAttr) || map[KindAttr].toString() != ApiKindList) { return TeamdrivesList(); } if (map.contains(NextPageTokenAttr)) { feedData.nextPageUrl = DriveService::fetchTeamdrivesUrl(); QUrlQuery query(feedData.nextPageUrl); query.addQueryItem(PageTokenAttr, map.value(NextPageTokenAttr).toString()); feedData.nextPageUrl.setQuery(query); } TeamdrivesList list; const QVariantList items = map[ItemsAttr].toList(); for (const QVariant & item : items) { const TeamdrivePtr teamdrive = Private::fromJSON(item.toMap()); if (!teamdrive.isNull()) { list << teamdrive; } } return list; } QByteArray Teamdrive::toJSON(const TeamdrivePtr &teamdrive) { QVariantMap teamDriveMap; teamDriveMap[KindAttr] = ApiKind; if (!teamdrive->id().isEmpty()) { teamDriveMap[IdAttr] = teamdrive->id(); } if (!teamdrive->name().isEmpty()) { teamDriveMap[NameAttr] = teamdrive->name(); } if (!teamdrive->themeId().isEmpty()) { teamDriveMap[ThemeIdAttr] = teamdrive->themeId(); } if (!teamdrive->colorRgb().isEmpty()) { teamDriveMap[ColorRgbAttr] = teamdrive->colorRgb(); } if (!teamdrive->backgroundImageLink().isEmpty()) { teamDriveMap[BackgroundImageLinkAttr] = teamdrive->backgroundImageLink(); } if (teamdrive->createdDate().isValid()) { teamDriveMap[CreatedDateAttr] = teamdrive->createdDate(); } if (teamdrive->restrictions()) { QVariantMap restrictionsMap; restrictionsMap[AdminManagedRestrictionsAttr] = teamdrive->restrictions()->adminManagedRestrictions(); restrictionsMap[CopyRequiresWriterPermissionAttr] = teamdrive->restrictions()->copyRequiresWriterPermission(); restrictionsMap[DomainUsersOnlyAttr] = teamdrive->restrictions()->domainUsersOnly(); restrictionsMap[TeamMembersOnlyAttr] = teamdrive->restrictions()->teamMembersOnly(); teamDriveMap[RestrictionsAttr] = restrictionsMap; } if (teamdrive->backgroundImageFile()) { QVariantMap backgroundImageFileMap; backgroundImageFileMap[IdAttr] = teamdrive->backgroundImageFile()->id(); backgroundImageFileMap[XCoordinateAttr] = teamdrive->backgroundImageFile()->xCoordinate(); backgroundImageFileMap[YCoordinateAttr] = teamdrive->backgroundImageFile()->yCoordinate(); backgroundImageFileMap[WidthAttr] = teamdrive->backgroundImageFile()->width(); teamDriveMap[BackgroundImageFileAttr] = backgroundImageFileMap; } if (teamdrive->capabilities()) { QVariantMap capabilitiesMap; capabilitiesMap[CanAddChildrenAttr] = teamdrive->capabilities()->canAddChildren(); capabilitiesMap[CanChangeCopyRequiresWriterPermissionRestrictionAttr] = teamdrive->capabilities()->canChangeCopyRequiresWriterPermissionRestriction(); capabilitiesMap[CanChangeDomainUsersOnlyRestrictionAttr] = teamdrive->capabilities()->canChangeDomainUsersOnlyRestriction(); capabilitiesMap[CanChangeTeamDriveBackgroundAttr] = teamdrive->capabilities()->canChangeTeamDriveBackground(); capabilitiesMap[CanChangeTeamMembersOnlyRestrictionAttr] = teamdrive->capabilities()->canChangeTeamMembersOnlyRestriction(); capabilitiesMap[CanCommentAttr] = teamdrive->capabilities()->canComment(); capabilitiesMap[CanCopyAttr] = teamdrive->capabilities()->canCopy(); capabilitiesMap[CanDeleteChildrenAttr] = teamdrive->capabilities()->canDeleteChildren(); capabilitiesMap[CanDeleteTeamDriveAttr] = teamdrive->capabilities()->canDeleteTeamDrive(); capabilitiesMap[CanDownloadAttr] = teamdrive->capabilities()->canDownload(); capabilitiesMap[CanEditAttr] = teamdrive->capabilities()->canEdit(); capabilitiesMap[CanListChildrenAttr] = teamdrive->capabilities()->canListChildren(); capabilitiesMap[CanManageMembersAttr] = teamdrive->capabilities()->canManageMembers(); capabilitiesMap[CanReadRevisionsAttr] = teamdrive->capabilities()->canReadRevisions(); capabilitiesMap[CanRenameAttr] = teamdrive->capabilities()->canRename(); capabilitiesMap[CanRenameTeamDriveAttr] = teamdrive->capabilities()->canRenameTeamDrive(); capabilitiesMap[CanShareAttr] = teamdrive->capabilities()->canShare(); capabilitiesMap[CanTrashChildrenAttr] = teamdrive->capabilities()->canTrashChildren(); teamDriveMap[CapabilitiesAttr] = capabilitiesMap; } QJsonDocument document = QJsonDocument::fromVariant(teamDriveMap); return document.toJson(QJsonDocument::Compact); } diff --git a/src/drive/teamdrive.h b/src/drive/teamdrive.h index 9e736aa..26a265a 100644 --- a/src/drive/teamdrive.h +++ b/src/drive/teamdrive.h @@ -1,349 +1,448 @@ /* Copyright (C) 2019 David Barchiesi This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef LIBKGAPI2_DRIVETEAMDRIVE_H #define LIBKGAPI2_DRIVETEAMDRIVE_H #include "types.h" #include "object.h" #include "kgapidrive_export.h" #include #include namespace KGAPI2 { namespace Drive { /** * @brief Teamdrive contains a representation of a Team Drive. * * Getters and setters' documentation is based on Google Drive's API v2 reference * @see Teamdrives * * @since x.0 * @author David Barchiesi */ class KGAPIDRIVE_EXPORT Teamdrive: public KGAPI2::Object { public: /** * @brief DriveTeamdrive::Restrictions holds the structure used for * restrictions property. */ class Restrictions { public: Restrictions(); Restrictions(const Restrictions &other); ~Restrictions(); bool operator==(const Restrictions &other) const; bool operator!=(const Restrictions &other) const { return !operator==(other); } /** * @brief Returns whether administrative privileges on this Team Drive * are required to modify restrictions. */ bool adminManagedRestrictions() const; + /** + * @brief Sets whether administrative privileges on this Team Drive + * are required to modify restrictions. + * + * @param adminManagedRestrictions + */ + void setAdminManagedRestrictions(bool adminManagedRestrictions) const; + /** * @brief Returns whether the options to copy, print, or download files * inside this Team Drive, should be disabled for readers and commenters. * When this restriction is set to true, it will override the similarly * named field to true for any file inside this Team Drive. */ bool copyRequiresWriterPermission() const; + /** + * @brief Sets whether the options to copy, print, or download files + * inside this Team Drive, should be disabled for readers and commenters. + * When this restriction is set to true, it will override the similarly + * named field to true for any file inside this Team Drive. + * + * @param copyRequiresWriterPermission + */ + void setCopyRequiresWriterPermission(bool copyRequiresWriterPermission) const; + /** * @brief Returns whether access to this Team Drive and items inside this * Team Drive is restricted to users of the domain to which this Team * Drive belongs. This restriction may be overridden by other sharing * policies controlled outside of this Team Drive. */ bool domainUsersOnly() const; + /** + * @brief Sets whether access to this Team Drive and items inside this + * Team Drive is restricted to users of the domain to which this Team + * Drive belongs. This restriction may be overridden by other sharing + * policies controlled outside of this Team Drive. + * + * @param domainUsersOnly + */ + void setDomainUsersOnly(bool domainUsersOnly) const; + /** * @brief Returns whether access to items inside this Team Drive is * restricted to members of this Team Drive. */ bool teamMembersOnly() const; + /** + * @brief Sets whether access to items inside this Team Drive is + * restricted to members of this Team Drive. + * + * @param teamMembersOnly + */ + void setTeamMembersOnly(bool teamMembersOnly) const; + private: class Private; QScopedPointer const d; friend class Private; friend class Teamdrive; }; typedef QSharedPointer RestrictionsPtr; /** * @brief DriveTeamdrive::Capabilities holds the structure used for capabilities property. */ class Capabilities { public: Capabilities(); Capabilities(const Capabilities &other); ~Capabilities(); bool operator==(const Capabilities &other) const; bool operator!=(const Capabilities &other) const { return !operator==(other); } /** * @brief Returns whether the current user can add children to folders * in this Team Drive. */ bool canAddChildren() const; /** * @brief Returns whether the current user can change the * copyRequiresWriterPermission restriction of this Team Drive. */ bool canChangeCopyRequiresWriterPermissionRestriction() const; /** * @brief Returns whether the current user can change the domainUsersOnly * restriction of this Team Drive. */ bool canChangeDomainUsersOnlyRestriction() const; /** * @brief Returns whether the current user can change the background of * this Team Drive. */ bool canChangeTeamDriveBackground() const; /** * @brief Returns whether the current user can change the teamMembersOnly * restriction of this Team Drive. */ bool canChangeTeamMembersOnlyRestriction() const; /** * @brief Returns Whether the current user can comment on files in * this Team Drive. */ bool canComment() const; /** * @brief Returns Whether the current user can copy files in this Team Drive. */ bool canCopy() const; /** * @brief Returns Whether the current user can delete children from * folders in this Team Drive. */ bool canDeleteChildren() const; /** * @brief Returns Whether the current user can delete this Team Drive. * * Attempting to delete the Team Drive may still fail if there are * untrashed items inside the Team Drive. */ bool canDeleteTeamDrive() const; /** * @brief Returns Whether the current user can download files in this * Team Drive. */ bool canDownload() const; /** * @brief Returns Whether the current user can edit files in this * Team Drive */ bool canEdit() const; /** * @brief Returns Whether the current user can list the children of * folders in this Team Drive. */ bool canListChildren() const; /** * @brief Returns Whether the current user can add members to this Team Drive * or remove them or change their role. */ bool canManageMembers() const; /** * @brief Returns Whether the current user can read the revisions * resource of files in this Team Drive. */ bool canReadRevisions() const; /** * @brief Returns Whether the current user can rename files or folders * in this Team Drive. */ bool canRename() const; /** * @brief Returns Whether the current user can rename this Team Drive. */ bool canRenameTeamDrive() const; /** * @brief Returns Whether the current user can share files or folders * in this Team Drive. */ bool canShare() const; /** * @brief Returns Whether the current user can trash children from * folders in this Team Drive. */ bool canTrashChildren() const; private: class Private; QScopedPointer const d; friend class Private; friend class Teamdrive; }; typedef QSharedPointer CapabilitiesPtr; /** * @brief DriveTeamdrive::BackgroundImageFile holds the structure used * for backgroundImageFile property. */ class BackgroundImageFile { public: BackgroundImageFile(); BackgroundImageFile(const BackgroundImageFile &other); ~BackgroundImageFile(); bool operator==(const BackgroundImageFile &other) const; bool operator!=(const BackgroundImageFile &other) const { return !operator==(other); } /** * @brief Returns the id of the background image file. */ QString id() const; + /** + * @brief Sets the id of the background image file. + * + * @param id + */ + void setId(const QString &id) const; + /** * @brief Returns the x coordinate for this background image file. */ float xCoordinate() const; + /** + * @brief Sets the x coordinate for this background image file. + * + * @param xCoordinate + */ + void setXCoordinate(float xCoordinate) const; + /** * @brief Returns the y coordinate for this background image file. */ float yCoordinate() const; + /** + * @brief Sets the y coordinate for this background image file. + * + * @param yCoordinate + */ + void setYCoordinate(float yCoordinate) const; + /** * @brief Returns the width for this background image file. */ float width() const; + /** + * @brief Sets the width for this background image file. + * + * @param width + */ + void setWidth(float width) const; + private: class Private; QScopedPointer const d; friend class Private; friend class Teamdrive; }; typedef QSharedPointer BackgroundImageFilePtr; Teamdrive(); Teamdrive(const Teamdrive &other); ~Teamdrive() override; bool operator==(const Teamdrive &other) const; bool operator!=(const Teamdrive &other) const { return !operator==(other); } /** * @brief Returns the id of the teamdrive. */ QString id() const; + /** + * @brief Sets the id of the teamdrive. + * + * @param id + */ + void setId(const QString &id) const; + /** * @brief Returns the name of the teamdrive. */ QString name() const; /** * @brief Sets the name of the teamdrive. * * @param name */ void setName(const QString &name) const; /** * @brief Returns the themeId of the teamdrive. */ QString themeId() const; + /** + * @brief Sets the themeId of the teamdrive. + * + * @param themeId + */ + void setThemeId(const QString &themeId) const; + /** * @brief Returns the colorRgb of the teamdrive. */ QString colorRgb() const; + /** + * @brief Sets the colorRgb of the teamdrive. + * + * @param colorRgb + */ + void setColorRgb(const QString &colorRgb) const; + /** * @brief Returns the image file and cropping parameters from which a background image for this Team Drive is set. */ BackgroundImageFilePtr backgroundImageFile() const; + /** + * @brief Sets the backgroundImageFile of the teamdrive. + * + * @param backgroundImageFile + */ + void setBackgroundImageFile(const BackgroundImageFilePtr &backgroundImageFile) const; + /** * @brief Returns the backgroundImageLink of the teamdrive. */ QString backgroundImageLink() const; /** * @brief Returns the capabilities the current user has on this Team Drive. */ CapabilitiesPtr capabilities() const; /** * @brief Returns the time at which the Team Drive was created. */ QDateTime createdDate() const; /** * @brief Returns the set of restrictions that apply to this Team Drive or * items inside this Team Drive. */ RestrictionsPtr restrictions() const; + /** + * @brief Sets the restrictions of the teamdrive. + * + * @param restrictions + */ + void setRestrictions(const RestrictionsPtr &restrictions) const; + static TeamdrivePtr fromJSON(const QByteArray &jsonData); static TeamdrivesList fromJSONFeed(const QByteArray &jsonData, FeedData &feedData); static QByteArray toJSON(const TeamdrivePtr &teamdrive); private: class Private; QScopedPointer const d; friend class Private; }; } /* namespace Drive */ } /* namespace KGAPI2 */ #endif // LIBKGAPI2_DRIVETEAMDRIVE_H diff --git a/src/drive/teamdrivecreatejob.h b/src/drive/teamdrivecreatejob.h index 43ab091..d6f0896 100644 --- a/src/drive/teamdrivecreatejob.h +++ b/src/drive/teamdrivecreatejob.h @@ -1,68 +1,68 @@ /* * This file is part of LibKGAPI library * * Copyright (C) 2019 David Barchiesi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ #ifndef KGAPI2_DRIVETEAMDRIVECREATEJOB_H #define KGAPI2_DRIVETEAMDRIVECREATEJOB_H #include "createjob.h" #include "kgapidrive_export.h" namespace KGAPI2 { namespace Drive { class KGAPIDRIVE_EXPORT TeamdriveCreateJob : public KGAPI2::CreateJob { Q_OBJECT public: TeamdriveCreateJob(const QString &requestId, const TeamdrivePtr &teamdrive, const AccountPtr &account, QObject *parent = nullptr); TeamdriveCreateJob(const QString &requestId, const TeamdrivesList &teamdrives, const AccountPtr &account, QObject *parent = nullptr); ~TeamdriveCreateJob() override; /** * @brief Returns the requestId used in this create request. */ QString requestId() const; protected: void start() override; KGAPI2::ObjectsList handleReplyWithItems(const QNetworkReply *reply, - const QByteArray &rawData) override; + const QByteArray &rawData) override; private: class Private; QScopedPointer d; friend class Private; }; } // namespace Drive } // namespace KGAPI2 #endif // KGAPI2_DRIVETEAMDRIVECREATEJOB_H diff --git a/src/drive/teamdrivemodifyjob.cpp b/src/drive/teamdrivemodifyjob.cpp new file mode 100644 index 0000000..f99f601 --- /dev/null +++ b/src/drive/teamdrivemodifyjob.cpp @@ -0,0 +1,117 @@ +/* + * This file is part of LibKGAPI library + * + * Copyright (C) 2019 David Barchiesi + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) version 3, or any + * later version accepted by the membership of KDE e.V. (or its + * successor approved by the membership of KDE e.V.), which shall + * act as a proxy defined in Section 6 of version 3 of the license. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + */ + + +#include "teamdrivemodifyjob.h" +#include "account.h" +#include "driveservice.h" +#include "teamdrive.h" +#include "utils.h" + +#include +#include + + +using namespace KGAPI2; +using namespace KGAPI2::Drive; + +class Q_DECL_HIDDEN TeamdriveModifyJob::Private +{ + public: + Private(TeamdriveModifyJob *parent); + void processNext(); + + TeamdrivesList teamdrives; + + private: + TeamdriveModifyJob *const q; +}; + +TeamdriveModifyJob::Private::Private(TeamdriveModifyJob *parent): + q(parent) +{ +} + +void TeamdriveModifyJob::Private::processNext() +{ + if (teamdrives.isEmpty()) { + q->emitFinished(); + return; + } + + const TeamdrivePtr teamdrive = teamdrives.takeFirst(); + const QUrl url = DriveService::fetchTeamdriveUrl(teamdrive->id()); + + QNetworkRequest request(url); + request.setRawHeader("Authorization", "Bearer " + q->account()->accessToken().toLatin1()); + + const QByteArray rawData = Teamdrive::toJSON(teamdrive); + q->enqueueRequest(request, rawData, QStringLiteral("application/json")); +} + +TeamdriveModifyJob::TeamdriveModifyJob(const TeamdrivePtr &teamdrive, + const AccountPtr &account, + QObject *parent): + ModifyJob(account, parent), + d(new Private(this)) +{ + d->teamdrives << teamdrive; +} + +TeamdriveModifyJob::TeamdriveModifyJob(const TeamdrivesList &teamdrives, + const AccountPtr &account, + QObject *parent): + ModifyJob(account, parent), + d(new Private(this)) +{ + d->teamdrives << teamdrives; +} + +TeamdriveModifyJob::~TeamdriveModifyJob() = default; + +void TeamdriveModifyJob::start() +{ + d->processNext(); +} + +ObjectsList TeamdriveModifyJob::handleReplyWithItems(const QNetworkReply *reply, + const QByteArray &rawData) +{ + const QString contentType = reply->header(QNetworkRequest::ContentTypeHeader).toString(); + ContentType ct = Utils::stringToContentType(contentType); + ObjectsList items; + if (ct == KGAPI2::JSON) { + items << Teamdrive::fromJSON(rawData); + } else { + setError(KGAPI2::InvalidResponse); + setErrorString(tr("Invalid response content type")); + emitFinished(); + return items; + } + + // Enqueue next item or finish + d->processNext(); + + return items; +} + + diff --git a/src/drive/teamdrivecreatejob.h b/src/drive/teamdrivemodifyjob.h similarity index 61% copy from src/drive/teamdrivecreatejob.h copy to src/drive/teamdrivemodifyjob.h index 43ab091..194626e 100644 --- a/src/drive/teamdrivecreatejob.h +++ b/src/drive/teamdrivemodifyjob.h @@ -1,68 +1,62 @@ /* * This file is part of LibKGAPI library * * Copyright (C) 2019 David Barchiesi * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) version 3, or any * later version accepted by the membership of KDE e.V. (or its * successor approved by the membership of KDE e.V.), which shall * act as a proxy defined in Section 6 of version 3 of the license. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library. If not, see . */ -#ifndef KGAPI2_DRIVETEAMDRIVECREATEJOB_H -#define KGAPI2_DRIVETEAMDRIVECREATEJOB_H -#include "createjob.h" +#ifndef KGAPI2_DRIVETEAMDRIVEMODIFYJOB_H +#define KGAPI2_DRIVETEAMDRIVEMODIFYJOB_H + +#include "modifyjob.h" #include "kgapidrive_export.h" namespace KGAPI2 { namespace Drive { -class KGAPIDRIVE_EXPORT TeamdriveCreateJob : public KGAPI2::CreateJob +class KGAPIDRIVE_EXPORT TeamdriveModifyJob : public KGAPI2::ModifyJob { Q_OBJECT public: - TeamdriveCreateJob(const QString &requestId, - const TeamdrivePtr &teamdrive, - const AccountPtr &account, QObject *parent = nullptr); - TeamdriveCreateJob(const QString &requestId, - const TeamdrivesList &teamdrives, - const AccountPtr &account, QObject *parent = nullptr); - ~TeamdriveCreateJob() override; - - /** - * @brief Returns the requestId used in this create request. - */ - QString requestId() const; + explicit TeamdriveModifyJob(const TeamdrivePtr &teamdrive, + const AccountPtr &account, QObject *parent = nullptr); + explicit TeamdriveModifyJob(const TeamdrivesList &teamdrives, + const AccountPtr &account, QObject *parent = nullptr); + ~TeamdriveModifyJob() override; protected: void start() override; KGAPI2::ObjectsList handleReplyWithItems(const QNetworkReply *reply, - const QByteArray &rawData) override; + const QByteArray &rawData) override; private: class Private; QScopedPointer d; friend class Private; }; } // namespace Drive } // namespace KGAPI2 -#endif // KGAPI2_DRIVETEAMDRIVECREATEJOB_H +#endif // KGAPI2_DRIVETEAMDRIVEMODIFYJOB_H