Changeset View
Changeset View
Standalone View
Standalone View
examples/teamdrive/mainwindow.cpp
Context not available. | |||||
23 | #include "ui_main.h" | 23 | #include "ui_main.h" | ||
---|---|---|---|---|---|
24 | 24 | | |||
25 | #include <drive/teamdrive.h> | 25 | #include <drive/teamdrive.h> | ||
26 | #include <drive/teamdrivecreatejob.h> | ||||
26 | #include <drive/teamdrivefetchjob.h> | 27 | #include <drive/teamdrivefetchjob.h> | ||
27 | #include <drive/teamdrivesearchquery.h> | 28 | #include <drive/teamdrivesearchquery.h> | ||
28 | #include <drive/file.h> | 29 | #include <drive/file.h> | ||
Context not available. | |||||
32 | #include <account.h> | 33 | #include <account.h> | ||
33 | 34 | | |||
34 | #include <QListWidgetItem> | 35 | #include <QListWidgetItem> | ||
36 | #include <QUuid> | ||||
35 | 37 | | |||
36 | MainWindow::MainWindow(QWidget * parent): | 38 | MainWindow::MainWindow(QWidget * parent): | ||
37 | QMainWindow(parent), | 39 | QMainWindow(parent), | ||
Context not available. | |||||
42 | m_ui->errorLabel->setVisible(false); | 44 | m_ui->errorLabel->setVisible(false); | ||
43 | connect(m_ui->authButton, &QAbstractButton::clicked, | 45 | connect(m_ui->authButton, &QAbstractButton::clicked, | ||
44 | this, &MainWindow::authenticate); | 46 | this, &MainWindow::authenticate); | ||
47 | connect(m_ui->newTeamdriveButton, &QAbstractButton::clicked, | ||||
48 | this, &MainWindow::createTeamdrive); | ||||
45 | connect(m_ui->teamdriveListButton, &QAbstractButton::clicked, | 49 | connect(m_ui->teamdriveListButton, &QAbstractButton::clicked, | ||
46 | this, &MainWindow::fetchTeamdriveList); | 50 | this, &MainWindow::fetchTeamdriveList); | ||
47 | connect(m_ui->teamdriveList, &QListWidget::itemSelectionChanged, | 51 | connect(m_ui->teamdriveList, &QListWidget::itemSelectionChanged, | ||
Context not available. | |||||
88 | m_ui->authButton->setEnabled(false); | 92 | m_ui->authButton->setEnabled(false); | ||
89 | } | 93 | } | ||
90 | 94 | | |||
95 | void MainWindow::createTeamdrive() | ||||
96 | { | ||||
97 | QString teamdriveName = m_ui->newTeamdriveEdit->text(); | ||||
98 | if (teamdriveName.isEmpty()) { | ||||
99 | return; | ||||
100 | } | ||||
101 | QString requestId = QUuid::createUuid().toString(); | ||||
102 | | ||||
103 | KGAPI2::Drive::TeamdrivePtr teamdrive = KGAPI2::Drive::TeamdrivePtr::create(); | ||||
104 | teamdrive->setName(teamdriveName); | ||||
105 | KGAPI2::Drive::TeamdriveCreateJob *createJob = new KGAPI2::Drive::TeamdriveCreateJob(requestId, teamdrive, m_account, this); | ||||
106 | connect(createJob, &KGAPI2::Job::finished, | ||||
107 | this, &MainWindow::slotTeamdriveCreateJobFinished); | ||||
108 | } | ||||
109 | | ||||
110 | void MainWindow::slotTeamdriveCreateJobFinished(KGAPI2::Job *job) | ||||
111 | { | ||||
112 | KGAPI2::Drive::TeamdriveCreateJob *createJob = qobject_cast<KGAPI2::Drive::TeamdriveCreateJob*>(job); | ||||
113 | Q_ASSERT(createJob); | ||||
114 | createJob->deleteLater(); | ||||
115 | | ||||
116 | if (createJob->error() != KGAPI2::NoError) { | ||||
117 | m_ui->errorLabel->setText(QStringLiteral("Error: %1").arg(createJob->errorString())); | ||||
118 | m_ui->errorLabel->setVisible(true); | ||||
119 | m_ui->teamdriveListButton->setEnabled(true); | ||||
120 | return; | ||||
121 | } | ||||
122 | | ||||
123 | m_ui->newTeamdriveEdit->clear(); | ||||
124 | fetchTeamdriveList(); | ||||
125 | } | ||||
126 | | ||||
91 | void MainWindow::fetchTeamdriveList() | 127 | void MainWindow::fetchTeamdriveList() | ||
92 | { | 128 | { | ||
93 | if (m_account.isNull()) { | 129 | if (m_account.isNull()) { | ||
Context not available. | |||||
97 | return; | 133 | return; | ||
98 | } | 134 | } | ||
99 | 135 | | |||
100 | KGAPI2::Drive::TeamdriveSearchQuery query; | 136 | KGAPI2::Drive::TeamdriveFetchJob *fetchJob = new KGAPI2::Drive::TeamdriveFetchJob(m_account, this); | ||
101 | query.addQuery(KGAPI2::Drive::TeamdriveSearchQuery::MemberCount, KGAPI2::Drive::TeamdriveSearchQuery::Less, 10); | | |||
102 | | ||||
103 | KGAPI2::Drive::TeamdriveFetchJob *fetchJob = new KGAPI2::Drive::TeamdriveFetchJob(query, m_account, this); | | |||
104 | connect(fetchJob, &KGAPI2::Job::finished, | 137 | connect(fetchJob, &KGAPI2::Job::finished, | ||
105 | this, &MainWindow::slotFetchJobFinished); | 138 | this, &MainWindow::slotFetchJobFinished); | ||
106 | 139 | | |||
Context not available. | |||||
122 | 155 | | |||
123 | /* Get all items the job has retrieved */ | 156 | /* Get all items the job has retrieved */ | ||
124 | const KGAPI2::ObjectsList objects = fetchJob->items(); | 157 | const KGAPI2::ObjectsList objects = fetchJob->items(); | ||
125 | 158 | m_ui->teamdriveList->clear(); | |||
126 | for (const KGAPI2::ObjectPtr &object : objects) { | 159 | for (const KGAPI2::ObjectPtr &object : objects) { | ||
127 | const KGAPI2::Drive::TeamdrivePtr teamdrive = object.dynamicCast<KGAPI2::Drive::Teamdrive>(); | 160 | const KGAPI2::Drive::TeamdrivePtr teamdrive = object.dynamicCast<KGAPI2::Drive::Teamdrive>(); | ||
128 | 161 | | |||
Context not available. |