diff --git a/src/gdriveurl.h b/src/gdriveurl.h --- a/src/gdriveurl.h +++ b/src/gdriveurl.h @@ -33,6 +33,7 @@ QString filename() const; bool isRoot() const; bool isAccountRoot() const; + bool isNewAccountPath() const; bool isTopLevel() const; bool isSharedDrivesRoot() const; bool isSharedDrive() const; @@ -45,6 +46,8 @@ static const QString Scheme; static const QString SharedDrivesDir; static const QString TrashDir; + static const QString NewAccountPath; + private: QUrl m_url; QStringList m_components; diff --git a/src/gdriveurl.cpp b/src/gdriveurl.cpp --- a/src/gdriveurl.cpp +++ b/src/gdriveurl.cpp @@ -24,6 +24,7 @@ const QString GDriveUrl::Scheme = QLatin1String("gdrive"); const QString GDriveUrl::SharedDrivesDir = QLatin1String("Shared Drives"); const QString GDriveUrl::TrashDir = QLatin1String("trash"); +const QString GDriveUrl::NewAccountPath = QLatin1String("new-account"); GDriveUrl::GDriveUrl(const QUrl &url) : m_url(url) @@ -57,7 +58,12 @@ bool GDriveUrl::isAccountRoot() const { - return m_components.length() == 1; + return m_components.length() == 1 && !isNewAccountPath(); +} + +bool GDriveUrl::isNewAccountPath() const +{ + return m_components.length() == 1 && m_components.at(0) == NewAccountPath; } bool GDriveUrl::isTopLevel() const diff --git a/src/kio_gdrive.h b/src/kio_gdrive.h --- a/src/kio_gdrive.h +++ b/src/kio_gdrive.h @@ -82,6 +82,7 @@ CurrentDir = 1 }; + static KIO::UDSEntry newAccountUDSEntry(); static KIO::UDSEntry accountToUDSEntry(const QString &accountName); static KIO::UDSEntry sharedDriveToUDSEntry(const KGAPI2::Drive::DrivesPtr &sharedDrive); diff --git a/src/kio_gdrive.cpp b/src/kio_gdrive.cpp --- a/src/kio_gdrive.cpp +++ b/src/kio_gdrive.cpp @@ -145,19 +145,19 @@ void KIOGDrive::fileSystemFreeSpace(const QUrl &url) { const auto gdriveUrl = GDriveUrl(url); - const QString accountId = gdriveUrl.account(); - if (accountId == QLatin1String("new-account")) { + if (gdriveUrl.isNewAccountPath()) { qCDebug(GDRIVE) << "fileSystemFreeSpace is not supported for new-account url"; finished(); return; } if (gdriveUrl.isRoot()) { - qCDebug(GDRIVE) << "fileSystemFreeSpace is not supported for gdrive root urls"; + qCDebug(GDRIVE) << "fileSystemFreeSpace is not supported for gdrive root url"; error(KIO::ERR_CANNOT_STAT, url.toDisplayString()); return; } qCDebug(GDRIVE) << "Getting fileSystemFreeSpace for" << url; + const QString accountId = gdriveUrl.account(); AboutFetchJob aboutFetch(getAccount(accountId)); aboutFetch.setFields({ About::Fields::Kind, @@ -259,6 +259,19 @@ qCDebug(GDRIVE) << "Ready to talk to GDrive"; } +KIO::UDSEntry KIOGDrive::newAccountUDSEntry() +{ + KIO::UDSEntry entry; + + entry.fastInsert(KIO::UDSEntry::UDS_NAME, GDriveUrl::NewAccountPath); + entry.fastInsert(KIO::UDSEntry::UDS_DISPLAY_NAME, i18nc("login in a new google account", "New account")); + entry.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR); + entry.fastInsert(KIO::UDSEntry::UDS_ICON_NAME, QStringLiteral("list-add-user")); + entry.fastInsert(KIO::UDSEntry::UDS_ACCESS, S_IRUSR); + + return entry; +} + KIO::UDSEntry KIOGDrive::accountToUDSEntry(const QString &accountNAme) { KIO::UDSEntry entry; @@ -326,11 +339,8 @@ const KIO::UDSEntry entry = accountToUDSEntry(account); listEntry(entry); } - KIO::UDSEntry newAccountEntry; - newAccountEntry.fastInsert(KIO::UDSEntry::UDS_NAME, QStringLiteral("new-account")); - newAccountEntry.fastInsert(KIO::UDSEntry::UDS_DISPLAY_NAME, i18nc("login in a new google account", "New account")); - newAccountEntry.fastInsert(KIO::UDSEntry::UDS_FILE_TYPE, S_IFDIR); - newAccountEntry.fastInsert(KIO::UDSEntry::UDS_ICON_NAME, QStringLiteral("list-add-user")); + + KIO::UDSEntry newAccountEntry = newAccountUDSEntry(); listEntry(newAccountEntry); // Create also non-writable UDSentry for "." @@ -595,12 +605,12 @@ qCDebug(GDRIVE) << "Going to list" << url; const auto gdriveUrl = GDriveUrl(url); - const QString accountId = gdriveUrl.account(); - if (accountId == QLatin1String("new-account")) { + if (gdriveUrl.isNewAccountPath()) { createAccount(); return; } + const QString accountId = gdriveUrl.account(); QString folderId; if (gdriveUrl.isRoot()) { listAccounts(); @@ -724,11 +734,19 @@ return; } if (gdriveUrl.isAccountRoot()) { + qCDebug(GDRIVE) << "stat()ing account root"; const KIO::UDSEntry entry = accountToUDSEntry(accountId); statEntry(entry); finished(); return; } + if (gdriveUrl.isNewAccountPath()) { + qCDebug(GDRIVE) << "stat()ing new-account path"; + const KIO::UDSEntry entry = newAccountUDSEntry(); + statEntry(entry); + finished(); + return; + } if (gdriveUrl.isSharedDrivesRoot()) { qCDebug(GDRIVE) << "stat()ing Shared Drives root"; const auto entry = fetchSharedDrivesRootEntry(accountId);