Changeset View
Changeset View
Standalone View
Standalone View
examples/teamdrive/mainwindow.cpp
Show First 20 Lines • Show All 50 Lines • ▼ Show 20 Line(s) | 43 | { | |||
---|---|---|---|---|---|
51 | connect(m_ui->teamdriveListButton, &QAbstractButton::clicked, | 51 | connect(m_ui->teamdriveListButton, &QAbstractButton::clicked, | ||
52 | this, &MainWindow::fetchTeamdriveList); | 52 | this, &MainWindow::fetchTeamdriveList); | ||
53 | connect(m_ui->teamdriveSelectedDeleteButton, &QAbstractButton::clicked, | 53 | connect(m_ui->teamdriveSelectedDeleteButton, &QAbstractButton::clicked, | ||
54 | this, &MainWindow::deleteSelectedTeamdrive); | 54 | this, &MainWindow::deleteSelectedTeamdrive); | ||
55 | connect(m_ui->renameTeamdriveButton, &QAbstractButton::clicked, | 55 | connect(m_ui->renameTeamdriveButton, &QAbstractButton::clicked, | ||
56 | this, &MainWindow::renameSelectedTeamdrive); | 56 | this, &MainWindow::renameSelectedTeamdrive); | ||
57 | connect(m_ui->teamdriveList, &QListWidget::itemSelectionChanged, | 57 | connect(m_ui->teamdriveList, &QListWidget::itemSelectionChanged, | ||
58 | this, &MainWindow::teamdriveSelected); | 58 | this, &MainWindow::teamdriveSelected); | ||
59 | connect(m_ui->teamdrivePreviewList, &QListWidget::itemSelectionChanged, | ||||
60 | this, &MainWindow::teamdriveItemSelected); | ||||
59 | } | 61 | } | ||
60 | 62 | | |||
61 | MainWindow::~MainWindow() | 63 | MainWindow::~MainWindow() | ||
62 | { | 64 | { | ||
63 | delete m_ui; | 65 | delete m_ui; | ||
64 | } | 66 | } | ||
65 | 67 | | |||
66 | void MainWindow::authenticate() | 68 | void MainWindow::authenticate() | ||
▲ Show 20 Lines • Show All 172 Lines • ▼ Show 20 Line(s) | |||||
239 | void MainWindow::teamdriveSelected() | 241 | void MainWindow::teamdriveSelected() | ||
240 | { | 242 | { | ||
241 | bool hasSelection = (m_ui->teamdriveList->selectedItems().count() != 0); | 243 | bool hasSelection = (m_ui->teamdriveList->selectedItems().count() != 0); | ||
242 | 244 | | |||
243 | m_ui->teamdriveSelectedDeleteButton->setEnabled(hasSelection); | 245 | m_ui->teamdriveSelectedDeleteButton->setEnabled(hasSelection); | ||
244 | m_ui->renameTeamdriveButton->setEnabled(hasSelection); | 246 | m_ui->renameTeamdriveButton->setEnabled(hasSelection); | ||
245 | m_ui->renameTeamdriveEdit->setEnabled(hasSelection); | 247 | m_ui->renameTeamdriveEdit->setEnabled(hasSelection); | ||
246 | 248 | | |||
249 | m_ui->teamdrivePreviewList->clear(); | ||||
250 | | ||||
247 | if (!hasSelection) { | 251 | if (!hasSelection) { | ||
248 | m_ui->teamdrivePreview->clear(); | | |||
249 | m_ui->renameTeamdriveEdit->clear(); | 252 | m_ui->renameTeamdriveEdit->clear(); | ||
250 | return; | 253 | return; | ||
251 | } | 254 | } | ||
252 | 255 | | |||
253 | const QString id = m_ui->teamdriveList->selectedItems().at(0)->data(Qt::UserRole).toString(); | 256 | const QString id = m_ui->teamdriveList->selectedItems().at(0)->data(Qt::UserRole).toString(); | ||
254 | const QString name = m_ui->teamdriveList->selectedItems().at(0)->data(Qt::DisplayRole).toString(); | 257 | const QString name = m_ui->teamdriveList->selectedItems().at(0)->data(Qt::DisplayRole).toString(); | ||
258 | | ||||
255 | m_ui->renameTeamdriveEdit->setText(name); | 259 | m_ui->renameTeamdriveEdit->setText(name); | ||
256 | 260 | | |||
257 | KGAPI2::Drive::FileSearchQuery query; | 261 | KGAPI2::Drive::FileSearchQuery query; | ||
258 | query.addQuery(KGAPI2::Drive::FileSearchQuery::Trashed, KGAPI2::Drive::FileSearchQuery::Equals, false); | 262 | query.addQuery(KGAPI2::Drive::FileSearchQuery::Trashed, KGAPI2::Drive::FileSearchQuery::Equals, false); | ||
259 | query.addQuery(KGAPI2::Drive::FileSearchQuery::Parents, KGAPI2::Drive::FileSearchQuery::In, id); | 263 | query.addQuery(KGAPI2::Drive::FileSearchQuery::Parents, KGAPI2::Drive::FileSearchQuery::In, id); | ||
260 | 264 | | |||
261 | KGAPI2::Drive::FileFetchJob *fileFetchJob = new KGAPI2::Drive::FileFetchJob(query, m_account, nullptr); | 265 | KGAPI2::Drive::FileFetchJob *fileFetchJob = new KGAPI2::Drive::FileFetchJob(query, m_account, nullptr); | ||
262 | fileFetchJob->setIncludeTeamDriveItems(true); | | |||
263 | fileFetchJob->setFields((KGAPI2::Drive::FileFetchJob::BasicFields & ~KGAPI2::Drive::FileFetchJob::Permissions) | 266 | fileFetchJob->setFields((KGAPI2::Drive::FileFetchJob::BasicFields & ~KGAPI2::Drive::FileFetchJob::Permissions) | ||
264 | | KGAPI2::Drive::FileFetchJob::Labels | 267 | | KGAPI2::Drive::FileFetchJob::Labels | ||
265 | | KGAPI2::Drive::FileFetchJob::ExportLinks | 268 | | KGAPI2::Drive::FileFetchJob::ExportLinks | ||
266 | | KGAPI2::Drive::FileFetchJob::LastViewedByMeDate); | 269 | | KGAPI2::Drive::FileFetchJob::LastViewedByMeDate); | ||
267 | connect(fileFetchJob, &KGAPI2::Job::finished, | 270 | connect(fileFetchJob, &KGAPI2::Job::finished, | ||
268 | this, &MainWindow::slotTeamdriveFetchJobFinished); | 271 | this, &MainWindow::slotTeamdriveFetchJobFinished); | ||
269 | } | 272 | } | ||
270 | 273 | | |||
271 | void MainWindow::slotTeamdriveFetchJobFinished(KGAPI2::Job *job) | 274 | void MainWindow::slotTeamdriveFetchJobFinished(KGAPI2::Job *job) | ||
272 | { | 275 | { | ||
273 | KGAPI2::Drive::FileFetchJob *fetchJob = qobject_cast<KGAPI2::Drive::FileFetchJob*>(job); | 276 | KGAPI2::Drive::FileFetchJob *fetchJob = qobject_cast<KGAPI2::Drive::FileFetchJob*>(job); | ||
274 | Q_ASSERT(fetchJob); | 277 | Q_ASSERT(fetchJob); | ||
275 | fetchJob->deleteLater(); | 278 | fetchJob->deleteLater(); | ||
276 | 279 | | |||
277 | if (fetchJob->error() != KGAPI2::NoError) { | 280 | if (fetchJob->error() != KGAPI2::NoError) { | ||
278 | m_ui->errorLabel->setText(QStringLiteral("Error: %1").arg(fetchJob->errorString())); | 281 | m_ui->errorLabel->setText(QStringLiteral("Error: %1").arg(fetchJob->errorString())); | ||
279 | m_ui->errorLabel->setVisible(true); | 282 | m_ui->errorLabel->setVisible(true); | ||
280 | m_ui->teamdriveListButton->setEnabled(true); | 283 | m_ui->teamdriveListButton->setEnabled(true); | ||
281 | return; | 284 | return; | ||
282 | } | 285 | } | ||
283 | 286 | | |||
284 | /* Get all items we have received from Google (should be just one) */ | 287 | /* Get all items we have received from Google */ | ||
285 | KGAPI2::ObjectsList objects = fetchJob->items(); | 288 | KGAPI2::ObjectsList objects = fetchJob->items(); | ||
286 | 289 | | |||
287 | QString text; | | |||
288 | Q_FOREACH (const KGAPI2::ObjectPtr &object, objects) { | 290 | Q_FOREACH (const KGAPI2::ObjectPtr &object, objects) { | ||
289 | const KGAPI2::Drive::FilePtr file = object.dynamicCast<KGAPI2::Drive::File>(); | 291 | const KGAPI2::Drive::FilePtr file = object.dynamicCast<KGAPI2::Drive::File>(); | ||
290 | text += QStringLiteral("%1").arg(file->title()); | 292 | | ||
291 | text += QLatin1Char('\n'); | 293 | /* Convert the teamdrive to QListWidget item */ | ||
294 | QListWidgetItem *item = new QListWidgetItem(m_ui->teamdrivePreviewList); | ||||
295 | item->setText(file->title()); | ||||
296 | item->setData(Qt::UserRole, file->id()); | ||||
297 | | ||||
298 | m_ui->teamdrivePreviewList->addItem(item); | ||||
299 | } | ||||
300 | } | ||||
301 | | ||||
302 | void MainWindow::teamdriveItemSelected() | ||||
303 | { | ||||
304 | bool hasSelection = (m_ui->teamdrivePreviewList->selectedItems().count() != 0); | ||||
305 | if (!hasSelection) { | ||||
306 | return; | ||||
292 | } | 307 | } | ||
293 | 308 | | |||
294 | m_ui->teamdrivePreview->setText(text); | 309 | const QString id = m_ui->teamdrivePreviewList->selectedItems().at(0)->data(Qt::UserRole).toString(); | ||
310 | | ||||
311 | KGAPI2::Drive::FileFetchJob *fileFetchJob = new KGAPI2::Drive::FileFetchJob(id, m_account, nullptr); | ||||
312 | fileFetchJob->setFields((KGAPI2::Drive::FileFetchJob::BasicFields & ~KGAPI2::Drive::FileFetchJob::Permissions) | ||||
313 | | KGAPI2::Drive::FileFetchJob::Labels | ||||
314 | | KGAPI2::Drive::FileFetchJob::ExportLinks | ||||
315 | | KGAPI2::Drive::FileFetchJob::LastViewedByMeDate); | ||||
316 | connect(fileFetchJob, &KGAPI2::Job::finished, | ||||
317 | this, &MainWindow::slotTeamdriveItemFetchJobFinished); | ||||
318 | } | ||||
319 | | ||||
320 | void MainWindow::slotTeamdriveItemFetchJobFinished(KGAPI2::Job *job) | ||||
321 | { | ||||
322 | KGAPI2::Drive::FileFetchJob *fetchJob = qobject_cast<KGAPI2::Drive::FileFetchJob*>(job); | ||||
323 | Q_ASSERT(fetchJob); | ||||
324 | fetchJob->deleteLater(); | ||||
325 | | ||||
326 | if (fetchJob->error() != KGAPI2::NoError) { | ||||
327 | m_ui->errorLabel->setText(QStringLiteral("Error: %1").arg(fetchJob->errorString())); | ||||
328 | m_ui->errorLabel->setVisible(true); | ||||
329 | return; | ||||
330 | } | ||||
331 | | ||||
332 | KGAPI2::ObjectsList objects = fetchJob->items(); | ||||
333 | if (objects.size() != 1) { | ||||
334 | return; | ||||
335 | } | ||||
336 | | ||||
337 | KGAPI2::ObjectPtr object = objects.at(0); | ||||
338 | const KGAPI2::Drive::FilePtr file = object.dynamicCast<KGAPI2::Drive::File>(); | ||||
339 | QStringList msgBuilder; | ||||
340 | msgBuilder << file->title(); | ||||
341 | msgBuilder << QString::number(file->fileSize()) + QStringLiteral(" bytes"); | ||||
342 | QString msg = msgBuilder.join(QStringLiteral(", ")); | ||||
343 | m_ui->statusbar->showMessage(msg); | ||||
295 | } | 344 | } |