diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt index 2d2831f..72eb24d 100644 --- a/autotests/CMakeLists.txt +++ b/autotests/CMakeLists.txt @@ -1,80 +1,81 @@ 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 teamdrivefetchjobtest) add_libkgapi2_test(drive teamdrivesearchquerytest) diff --git a/autotests/drive/data/generic_no_content_response.txt b/autotests/drive/data/generic_no_content_response.txt new file mode 100644 index 0000000..0074ded --- /dev/null +++ b/autotests/drive/data/generic_no_content_response.txt @@ -0,0 +1,2 @@ +HTTP/1.1 204 No Content + diff --git a/autotests/drive/data/teamdrive_delete_request.txt b/autotests/drive/data/teamdrive_delete_request.txt new file mode 100644 index 0000000..daf15d7 --- /dev/null +++ b/autotests/drive/data/teamdrive_delete_request.txt @@ -0,0 +1 @@ +DELETE https://www.googleapis.com/drive/v2/teamdrives/somelongid diff --git a/autotests/drive/teamdrivedeletejobtest.cpp b/autotests/drive/teamdrivedeletejobtest.cpp new file mode 100644 index 0000000..565d406 --- /dev/null +++ b/autotests/drive/teamdrivedeletejobtest.cpp @@ -0,0 +1,80 @@ +/* + * Deleteright (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 + * 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/examples/teamdrive/mainwindow.cpp b/examples/teamdrive/mainwindow.cpp index ff1a907..989b629 100644 --- a/examples/teamdrive/mainwindow.cpp +++ b/examples/teamdrive/mainwindow.cpp @@ -1,220 +1,251 @@ /* 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 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->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->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::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() { - if (m_ui->teamdriveList->selectedItems().count() == 0) { + bool hasSelection = (m_ui->teamdriveList->selectedItems().count() != 0); + + m_ui->teamdriveSelectedDeleteButton->setEnabled(hasSelection); + + if (!hasSelection) { m_ui->teamdrivePreview->clear(); return; } const QString id = m_ui->teamdriveList->selectedItems().at(0)->data(Qt::UserRole).toString(); 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 ac3c49d..b7346dc 100644 --- a/examples/teamdrive/mainwindow.h +++ b/examples/teamdrive/mainwindow.h @@ -1,97 +1,107 @@ /* 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); /** * 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 3f21528..d52e9b0 100644 --- a/examples/teamdrive/ui/main.ui +++ b/examples/teamdrive/ui/main.ui @@ -1,180 +1,194 @@ MainWindow 0 0 640 486 MainWindow Authenticate Not authenticated Qt::Horizontal Create - - - false - - - Get Team Drive list - - + + + + + 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 407ded6..0b0af28 100644 --- a/src/drive/CMakeLists.txt +++ b/src/drive/CMakeLists.txt @@ -1,150 +1,152 @@ 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 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 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/teamdrivedeletejob.cpp b/src/drive/teamdrivedeletejob.cpp new file mode 100644 index 0000000..fc8cd59 --- /dev/null +++ b/src/drive/teamdrivedeletejob.cpp @@ -0,0 +1,91 @@ +/* + * 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 "teamdrivedeletejob.h" +#include "teamdrive.h" +#include "account.h" +#include "driveservice.h" + +#include + +using namespace KGAPI2; +using namespace KGAPI2::Drive; + +class Q_DECL_HIDDEN TeamdriveDeleteJob::Private +{ + public: + QStringList teamdrivesIds; +}; + +TeamdriveDeleteJob::TeamdriveDeleteJob(const QString &teamdriveId, + const AccountPtr &account, QObject *parent): + DeleteJob(account, parent), + d(new Private) +{ + d->teamdrivesIds << teamdriveId; +} + +TeamdriveDeleteJob::TeamdriveDeleteJob(const QStringList &teamdrivesIds, + const AccountPtr &account, QObject *parent): + DeleteJob(account, parent), + d(new Private) +{ + d->teamdrivesIds << teamdrivesIds; +} + +TeamdriveDeleteJob::TeamdriveDeleteJob(const TeamdrivePtr &teamdrive, + const AccountPtr &account, QObject *parent): + DeleteJob(account, parent), + d(new Private) +{ + d->teamdrivesIds << teamdrive->id(); +} + +TeamdriveDeleteJob::TeamdriveDeleteJob(const TeamdrivesList &teamdrives, + const AccountPtr &account, QObject *parent): + DeleteJob(account, parent), + d(new Private) +{ + for (const TeamdrivePtr & teamdrive : qAsConst(teamdrives)) { + d->teamdrivesIds << teamdrive->id(); + } +} + +TeamdriveDeleteJob::~TeamdriveDeleteJob() = default; + +void TeamdriveDeleteJob::start() +{ + if (d->teamdrivesIds.isEmpty()) { + emitFinished(); + return; + } + + const QString teamdriveId = d->teamdrivesIds.takeFirst(); + const QUrl url = DriveService::fetchTeamdriveUrl(teamdriveId); + QNetworkRequest request(url); + request.setRawHeader("Authorization", "Bearer " + account()->accessToken().toLatin1()); + + enqueueRequest(request); +} + + diff --git a/src/drive/teamdrivedeletejob.h b/src/drive/teamdrivedeletejob.h new file mode 100644 index 0000000..13703b4 --- /dev/null +++ b/src/drive/teamdrivedeletejob.h @@ -0,0 +1,64 @@ +/* + * 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_DRIVETEAMDRIVEDELETEJOB_H +#define KGAPI2_DRIVETEAMDRIVEDELETEJOB_H + +#include "deletejob.h" +#include "kgapidrive_export.h" + +namespace KGAPI2 +{ + +namespace Drive +{ + +class KGAPIDRIVE_EXPORT TeamdriveDeleteJob : public KGAPI2::DeleteJob +{ + Q_OBJECT + + public: + TeamdriveDeleteJob(const QString &teamdriveId, + const AccountPtr &account, QObject *parent = nullptr); + TeamdriveDeleteJob(const QStringList &teamdrivesIds, + const AccountPtr &account, QObject *parent = nullptr); + TeamdriveDeleteJob(const TeamdrivePtr &teamdrive, + const AccountPtr &account, QObject *parent = nullptr); + TeamdriveDeleteJob(const TeamdrivesList &teamdrives, + const AccountPtr &account, QObject *parent = nullptr); + ~TeamdriveDeleteJob() override; + + protected: + void start() override; + + private: + class Private; + QScopedPointer d; + friend class Private; +}; + +} // namespace Drive + +} // namespace KGAPI2 + +#endif // KGAPI2_DRIVETEAMDRIVEDELETEJOB_H