Changeset View
Changeset View
Standalone View
Standalone View
src/kio_gdrive.cpp
Show First 20 Lines • Show All 140 Lines • ▼ Show 20 Line(s) | 140 | { | |||
---|---|---|---|---|---|
141 | const auto gdriveUrl = GDriveUrl(url); | 141 | const auto gdriveUrl = GDriveUrl(url); | ||
142 | const QString accountId = gdriveUrl.account(); | 142 | const QString accountId = gdriveUrl.account(); | ||
143 | if (accountId == QLatin1String("new-account")) { | 143 | if (accountId == QLatin1String("new-account")) { | ||
144 | finished(); | 144 | finished(); | ||
145 | return; | 145 | return; | ||
146 | } | 146 | } | ||
147 | if (!gdriveUrl.isRoot()) { | 147 | if (!gdriveUrl.isRoot()) { | ||
148 | AboutFetchJob aboutFetch(getAccount(accountId)); | 148 | AboutFetchJob aboutFetch(getAccount(accountId)); | ||
149 | aboutFetch.setFields({ | ||||
150 | About::Fields::Kind, | ||||
151 | About::Fields::QuotaBytesTotal, | ||||
152 | About::Fields::QuotaBytesUsedAggregate, | ||||
153 | About::Fields::CanCreateTeamDrives, | ||||
154 | }); | ||||
149 | if (runJob(aboutFetch, url, accountId)) { | 155 | if (runJob(aboutFetch, url, accountId)) { | ||
150 | const AboutPtr about = aboutFetch.aboutData(); | 156 | const AboutPtr about = aboutFetch.aboutData(); | ||
151 | if (about) { | 157 | if (about) { | ||
152 | setMetaData(QStringLiteral("total"), QString::number(about->quotaBytesTotal())); | 158 | setMetaData(QStringLiteral("total"), QString::number(about->quotaBytesTotal())); | ||
153 | setMetaData(QStringLiteral("available"), QString::number(about->quotaBytesTotal() - about->quotaBytesUsedAggregate())); | 159 | setMetaData(QStringLiteral("available"), QString::number(about->quotaBytesTotal() - about->quotaBytesUsedAggregate())); | ||
154 | finished(); | 160 | finished(); | ||
155 | return; | 161 | return; | ||
156 | } | 162 | } | ||
▲ Show 20 Lines • Show All 217 Lines • ▼ Show 20 Line(s) | 378 | query.addQuery(FileSearchQuery::MimeType, | |||
374 | GDriveHelper::folderMimeType()); | 380 | GDriveHelper::folderMimeType()); | ||
375 | } | 381 | } | ||
376 | query.addQuery(FileSearchQuery::Title, FileSearchQuery::Equals, components.last()); | 382 | query.addQuery(FileSearchQuery::Title, FileSearchQuery::Equals, components.last()); | ||
377 | query.addQuery(FileSearchQuery::Parents, FileSearchQuery::In, parentId); | 383 | query.addQuery(FileSearchQuery::Parents, FileSearchQuery::In, parentId); | ||
378 | query.addQuery(FileSearchQuery::Trashed, FileSearchQuery::Equals, components[1] == QLatin1String("trash")); | 384 | query.addQuery(FileSearchQuery::Trashed, FileSearchQuery::Equals, components[1] == QLatin1String("trash")); | ||
379 | 385 | | |||
380 | const QString accountId = gdriveUrl.account(); | 386 | const QString accountId = gdriveUrl.account(); | ||
381 | FileFetchJob fetchJob(query, getAccount(accountId)); | 387 | FileFetchJob fetchJob(query, getAccount(accountId)); | ||
382 | fetchJob.setFields(FileFetchJob::Id | FileFetchJob::Title | FileFetchJob::Labels); | 388 | fetchJob.setFields({File::Fields::Id, File::Fields::Title, File::Fields::Labels}); | ||
383 | if (!runJob(fetchJob, url, accountId)) { | 389 | if (!runJob(fetchJob, url, accountId)) { | ||
384 | return QString(); | 390 | return QString(); | ||
385 | } | 391 | } | ||
386 | 392 | | |||
387 | const ObjectsList objects = fetchJob.items(); | 393 | const ObjectsList objects = fetchJob.items(); | ||
388 | qCDebug(GDRIVE) << objects; | 394 | qCDebug(GDRIVE) << objects; | ||
389 | if (objects.count() == 0) { | 395 | if (objects.count() == 0) { | ||
390 | qCWarning(GDRIVE) << "Failed to resolve" << path; | 396 | qCWarning(GDRIVE) << "Failed to resolve" << path; | ||
391 | return QString(); | 397 | return QString(); | ||
392 | } | 398 | } | ||
393 | 399 | | |||
394 | const FilePtr file = objects[0].dynamicCast<File>(); | 400 | const FilePtr file = objects[0].dynamicCast<File>(); | ||
395 | 401 | | |||
396 | m_cache.insertPath(path, file->id()); | 402 | m_cache.insertPath(path, file->id()); | ||
397 | 403 | | |||
398 | qCDebug(GDRIVE) << "Resolved" << path << "to" << file->id() << "(from network)"; | 404 | qCDebug(GDRIVE) << "Resolved" << path << "to" << file->id() << "(from network)"; | ||
399 | return file->id(); | 405 | return file->id(); | ||
400 | } | 406 | } | ||
401 | 407 | | |||
402 | QString KIOGDrive::rootFolderId(const QString &accountId) | 408 | QString KIOGDrive::rootFolderId(const QString &accountId) | ||
403 | { | 409 | { | ||
404 | auto it = m_rootIds.constFind(accountId); | 410 | auto it = m_rootIds.constFind(accountId); | ||
405 | if (it == m_rootIds.cend()) { | 411 | if (it == m_rootIds.cend()) { | ||
406 | AboutFetchJob aboutFetch(getAccount(accountId)); | 412 | AboutFetchJob aboutFetch(getAccount(accountId)); | ||
413 | aboutFetch.setFields({About::Fields::Kind, About::Fields::RootFolderId}); | ||||
407 | QUrl url; | 414 | QUrl url; | ||
408 | if (!runJob(aboutFetch, url, accountId)) { | 415 | if (!runJob(aboutFetch, url, accountId)) { | ||
409 | return QString(); | 416 | return QString(); | ||
410 | } | 417 | } | ||
411 | 418 | | |||
412 | const AboutPtr about = aboutFetch.aboutData(); | 419 | const AboutPtr about = aboutFetch.aboutData(); | ||
413 | if (!about || about->rootFolderId().isEmpty()) { | 420 | if (!about || about->rootFolderId().isEmpty()) { | ||
414 | qCWarning(GDRIVE) << "Failed to obtain root ID"; | 421 | qCWarning(GDRIVE) << "Failed to obtain root ID"; | ||
Show All 35 Lines | 455 | if (folderId.isEmpty()) { | |||
450 | return; | 457 | return; | ||
451 | } | 458 | } | ||
452 | } | 459 | } | ||
453 | 460 | | |||
454 | FileSearchQuery query; | 461 | FileSearchQuery query; | ||
455 | query.addQuery(FileSearchQuery::Trashed, FileSearchQuery::Equals, false); | 462 | query.addQuery(FileSearchQuery::Trashed, FileSearchQuery::Equals, false); | ||
456 | query.addQuery(FileSearchQuery::Parents, FileSearchQuery::In, folderId); | 463 | query.addQuery(FileSearchQuery::Parents, FileSearchQuery::In, folderId); | ||
457 | FileFetchJob fileFetchJob(query, getAccount(accountId)); | 464 | FileFetchJob fileFetchJob(query, getAccount(accountId)); | ||
458 | fileFetchJob.setFields((FileFetchJob::BasicFields & ~FileFetchJob::Permissions) | 465 | const auto extraFields = | ||
459 | | FileFetchJob::Labels | 466 | KGAPI2::Drive::FileFetchJob::FieldShorthands::BasicFields + | ||
460 | | FileFetchJob::ExportLinks | 467 | QStringList({ KGAPI2::Drive::File::Fields::Labels, | ||
461 | | FileFetchJob::LastViewedByMeDate); | 468 | KGAPI2::Drive::File::Fields::ExportLinks, | ||
469 | KGAPI2::Drive::File::Fields::LastViewedByMeDate, | ||||
470 | }); | ||||
elvisangelaccio: Is it possible to merge these 2 lines in a single one and make it a `const` variable? | |||||
dvratil: Plus can be turned into an initializer list, I'll fix that before merge. | |||||
471 | fileFetchJob.setFields(KGAPI2::Drive::FileFetchJob::FieldShorthands::BasicFields + extraFields); | ||||
462 | runJob(fileFetchJob, url, accountId); | 472 | runJob(fileFetchJob, url, accountId); | ||
463 | 473 | | |||
464 | ObjectsList objects = fileFetchJob.items(); | 474 | ObjectsList objects = fileFetchJob.items(); | ||
465 | Q_FOREACH (const ObjectPtr &object, objects) { | 475 | Q_FOREACH (const ObjectPtr &object, objects) { | ||
466 | const FilePtr file = object.dynamicCast<File>(); | 476 | const FilePtr file = object.dynamicCast<File>(); | ||
467 | 477 | | |||
468 | const KIO::UDSEntry entry = fileToUDSEntry(file, url.adjusted(QUrl::StripTrailingSlash).path()); | 478 | const KIO::UDSEntry entry = fileToUDSEntry(file, url.adjusted(QUrl::StripTrailingSlash).path()); | ||
469 | listEntry(entry); | 479 | listEntry(entry); | ||
▲ Show 20 Lines • Show All 132 Lines • ▼ Show 20 Line(s) | 610 | urlQuery.hasQueryItem(QStringLiteral("id")) | |||
602 | : resolveFileIdFromPath(url.adjusted(QUrl::StripTrailingSlash).path(), | 612 | : resolveFileIdFromPath(url.adjusted(QUrl::StripTrailingSlash).path(), | ||
603 | KIOGDrive::PathIsFile); | 613 | KIOGDrive::PathIsFile); | ||
604 | if (fileId.isEmpty()) { | 614 | if (fileId.isEmpty()) { | ||
605 | error(KIO::ERR_DOES_NOT_EXIST, url.path()); | 615 | error(KIO::ERR_DOES_NOT_EXIST, url.path()); | ||
606 | return; | 616 | return; | ||
607 | } | 617 | } | ||
608 | 618 | | |||
609 | FileFetchJob fileFetchJob(fileId, getAccount(accountId)); | 619 | FileFetchJob fileFetchJob(fileId, getAccount(accountId)); | ||
610 | fileFetchJob.setFields(FileFetchJob::Id | 620 | fileFetchJob.setFields({File::Fields::Id, File::Fields::MimeType, File::Fields::ExportLinks, File::Fields::DownloadUrl}); | ||
611 | | FileFetchJob::MimeType | | |||
612 | | FileFetchJob::ExportLinks | | |||
613 | | FileFetchJob::DownloadUrl); | | |||
614 | runJob(fileFetchJob, url, accountId); | 621 | runJob(fileFetchJob, url, accountId); | ||
615 | 622 | | |||
616 | const ObjectsList objects = fileFetchJob.items(); | 623 | const ObjectsList objects = fileFetchJob.items(); | ||
617 | if (objects.count() != 1) { | 624 | if (objects.count() != 1) { | ||
618 | error(KIO::ERR_DOES_NOT_EXIST, url.fileName()); | 625 | error(KIO::ERR_DOES_NOT_EXIST, url.fileName()); | ||
619 | return; | 626 | return; | ||
620 | } | 627 | } | ||
621 | 628 | | |||
▲ Show 20 Lines • Show All 239 Lines • ▼ Show 20 Line(s) | 867 | const QString sourceFileId | |||
861 | = urlQuery.hasQueryItem(QStringLiteral("id")) | 868 | = urlQuery.hasQueryItem(QStringLiteral("id")) | ||
862 | ? urlQuery.queryItemValue(QStringLiteral("id")) | 869 | ? urlQuery.queryItemValue(QStringLiteral("id")) | ||
863 | : resolveFileIdFromPath(src.adjusted(QUrl::StripTrailingSlash).path()); | 870 | : resolveFileIdFromPath(src.adjusted(QUrl::StripTrailingSlash).path()); | ||
864 | if (sourceFileId.isEmpty()) { | 871 | if (sourceFileId.isEmpty()) { | ||
865 | error(KIO::ERR_DOES_NOT_EXIST, src.path()); | 872 | error(KIO::ERR_DOES_NOT_EXIST, src.path()); | ||
866 | return; | 873 | return; | ||
867 | } | 874 | } | ||
868 | FileFetchJob sourceFileFetchJob(sourceFileId, getAccount(sourceAccountId)); | 875 | FileFetchJob sourceFileFetchJob(sourceFileId, getAccount(sourceAccountId)); | ||
869 | sourceFileFetchJob.setFields(FileFetchJob::Id | FileFetchJob::ModifiedDate | | 876 | sourceFileFetchJob.setFields({File::Fields::Id, File::Fields::ModifiedDate, File::Fields::LastViewedByMeDate, File::Fields::Description}); | ||
870 | FileFetchJob::LastViewedByMeDate | FileFetchJob::Description); | | |||
871 | runJob(sourceFileFetchJob, src, sourceAccountId); | 877 | runJob(sourceFileFetchJob, src, sourceAccountId); | ||
872 | 878 | | |||
873 | const ObjectsList objects = sourceFileFetchJob.items(); | 879 | const ObjectsList objects = sourceFileFetchJob.items(); | ||
874 | if (objects.count() != 1) { | 880 | if (objects.count() != 1) { | ||
875 | error(KIO::ERR_DOES_NOT_EXIST, src.path()); | 881 | error(KIO::ERR_DOES_NOT_EXIST, src.path()); | ||
876 | return; | 882 | return; | ||
877 | } | 883 | } | ||
878 | 884 | | |||
▲ Show 20 Lines • Show All 202 Lines • ▼ Show 20 Line(s) | 1085 | = urlQuery.hasQueryItem(QStringLiteral("id")) | |||
1081 | : resolveFileIdFromPath(url.adjusted(QUrl::StripTrailingSlash).path()); | 1087 | : resolveFileIdFromPath(url.adjusted(QUrl::StripTrailingSlash).path()); | ||
1082 | if (fileId.isEmpty()) { | 1088 | if (fileId.isEmpty()) { | ||
1083 | error(KIO::ERR_DOES_NOT_EXIST, url.path()); | 1089 | error(KIO::ERR_DOES_NOT_EXIST, url.path()); | ||
1084 | return; | 1090 | return; | ||
1085 | } | 1091 | } | ||
1086 | const QString accountId = GDriveUrl(url).account(); | 1092 | const QString accountId = GDriveUrl(url).account(); | ||
1087 | 1093 | | |||
1088 | FileFetchJob fileFetchJob(fileId, getAccount(accountId)); | 1094 | FileFetchJob fileFetchJob(fileId, getAccount(accountId)); | ||
1089 | fileFetchJob.setFields(FileFetchJob::Id | FileFetchJob::MimeType); | 1095 | fileFetchJob.setFields({File::Fields::Id, File::Fields::MimeType}); | ||
1090 | runJob(fileFetchJob, url, accountId); | 1096 | runJob(fileFetchJob, url, accountId); | ||
1091 | 1097 | | |||
1092 | const ObjectsList objects = fileFetchJob.items(); | 1098 | const ObjectsList objects = fileFetchJob.items(); | ||
1093 | if (objects.count() != 1) { | 1099 | if (objects.count() != 1) { | ||
1094 | error(KIO::ERR_DOES_NOT_EXIST, url.path()); | 1100 | error(KIO::ERR_DOES_NOT_EXIST, url.path()); | ||
1095 | return; | 1101 | return; | ||
1096 | } | 1102 | } | ||
1097 | 1103 | | |||
1098 | const FilePtr file = objects.first().dynamicCast<File>(); | 1104 | const FilePtr file = objects.first().dynamicCast<File>(); | ||
1099 | mimeType(file->mimeType()); | 1105 | mimeType(file->mimeType()); | ||
1100 | finished(); | 1106 | finished(); | ||
1101 | } | 1107 | } | ||
1102 | 1108 | | |||
1103 | #include "kio_gdrive.moc" | 1109 | #include "kio_gdrive.moc" |
Is it possible to merge these 2 lines in a single one and make it a const variable?