Members of the KDE Community are recommended to subscribe to the kde-community mailing list at https://mail.kde.org/mailman/listinfo/kde-community to allow them to participate in important discussions and receive other important announcements

...
 
Commits (3)
......@@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.0)
# KDE Application Version, managed by release script
set (RELEASE_SERVICE_VERSION_MAJOR "20")
set (RELEASE_SERVICE_VERSION_MINOR "07")
set (RELEASE_SERVICE_VERSION_MICRO "70")
set (RELEASE_SERVICE_VERSION_MICRO "80")
set (RELEASE_SERVICE_VERSION "${RELEASE_SERVICE_VERSION_MAJOR}.${RELEASE_SERVICE_VERSION_MINOR}.${RELEASE_SERVICE_VERSION_MICRO}")
project(kio-gdrive VERSION ${RELEASE_SERVICE_VERSION})
......
......@@ -30,7 +30,11 @@ GDriveUrl::GDriveUrl(const QUrl &url)
: m_url(url)
{
const auto path = url.adjusted(QUrl::StripTrailingSlash).path();
#if QT_VERSION < QT_VERSION_CHECK(5, 15, 0)
m_components = path.split(QLatin1Char('/'), QString::SkipEmptyParts);
#else
m_components = path.split(QLatin1Char('/'), Qt::SkipEmptyParts);
#endif
}
QString GDriveUrl::account() const
......@@ -112,3 +116,8 @@ QStringList GDriveUrl::pathComponents() const
{
return m_components;
}
QString GDriveUrl::buildSharedDrivePath(const QString &accountId, const QString &drive)
{
return QStringLiteral("/%1/%2/%3").arg(accountId, SharedDrivesDir, drive);
}
......@@ -43,6 +43,8 @@ public:
QString parentPath() const;
QStringList pathComponents() const;
static QString buildSharedDrivePath(const QString &accountId, const QString &drive);
static const QString Scheme;
static const QString SharedDrivesDir;
static const QString TrashDir;
......
......@@ -409,7 +409,14 @@ void KIOGDrive::statSharedDrive(const QUrl &url)
{
const auto gdriveUrl = GDriveUrl(url);
const QString accountId = gdriveUrl.account();
DrivesFetchJob sharedDriveFetchJob(gdriveUrl.filename(), getAccount(accountId));
const auto sharedDriveId = resolveSharedDriveId(gdriveUrl.filename(), accountId);
if (sharedDriveId.isEmpty()) {
error(KIO::ERR_DOES_NOT_EXIST, url.path());
return;
}
DrivesFetchJob sharedDriveFetchJob(sharedDriveId, getAccount(accountId));
sharedDriveFetchJob.setFields({
Drives::Fields::Kind,
Drives::Fields::Id,
......@@ -426,7 +433,6 @@ void KIOGDrive::statSharedDrive(const QUrl &url)
const DrivesPtr sharedDrive = object.dynamicCast<Drives>();
const auto entry = sharedDriveToUDSEntry(sharedDrive);
statEntry(entry);
finished();
}
KIO::UDSEntry KIOGDrive::fetchSharedDrivesRootEntry(const QString &accountId, FetchEntryFlags flags)
......@@ -526,8 +532,11 @@ QString KIOGDrive::resolveFileIdFromPath(const QString &path, PathFlags flags)
}
if (gdriveUrl.isSharedDrive()) {
qCDebug(GDRIVE) << "Resolved" << path << "to Shared Drive" << gdriveUrl.filename();
return gdriveUrl.filename();
// The gdriveUrl.filename() could be the Shared Drive id or
// the name depending on whether we are navigating from a parent
// or accessing the url directly, use the shared drive specific
// solver to disambiguate
return resolveSharedDriveId(gdriveUrl.filename(), gdriveUrl.account());
}
if (gdriveUrl.isSharedDrivesRoot()) {
......@@ -575,6 +584,83 @@ QString KIOGDrive::resolveFileIdFromPath(const QString &path, PathFlags flags)
return file->id();
}
QString KIOGDrive::resolveSharedDriveId(const QString &idOrName, const QString &accountId)
{
qCDebug(GDRIVE) << "Resolving shared drive id for" << idOrName;
const auto idOrNamePath = GDriveUrl::buildSharedDrivePath(accountId, idOrName);
QString fileId = m_cache.idForPath(idOrNamePath);
if (!fileId.isEmpty()) {
qCDebug(GDRIVE) << "Resolved shared drive id" << idOrName << "to" << fileId << "(from cache)";
return fileId;
}
// We start by trying to fetch a shared drive with the filename as id
DrivesFetchJob searchByIdJob(idOrName, getAccount(accountId));
searchByIdJob.setFields({
Drives::Fields::Kind,
Drives::Fields::Id,
Drives::Fields::Name
});
QEventLoop eventLoop;
QObject::connect(&searchByIdJob, &KGAPI2::Job::finished,
&eventLoop, &QEventLoop::quit);
eventLoop.exec();
if (searchByIdJob.error() == KGAPI2::OK || searchByIdJob.error() == KGAPI2::NoError) {
// A Shared Drive with that id exists so we return it
const auto objects = searchByIdJob.items();
const DrivesPtr sharedDrive = objects.at(0).dynamicCast<Drives>();
fileId = sharedDrive->id();
qCDebug(GDRIVE) << "Resolved shared drive id" << idOrName << "to" << fileId;
const auto idPath = idOrNamePath;
const auto namePath = GDriveUrl::buildSharedDrivePath(accountId, sharedDrive->name());
m_cache.insertPath(idPath, fileId);
m_cache.insertPath(namePath, fileId);
return fileId;
}
// The gdriveUrl's filename is not a shared drive id, we must
// search for a shared drive with the filename name.
// Unfortunately searching by name is only allowed for admin
// accounts (i.e. useDomainAdminAccess=true) so we retrieve all
// shared drives and search by name here
DrivesFetchJob sharedDrivesFetchJob(getAccount(accountId));
sharedDrivesFetchJob.setFields({
Drives::Fields::Kind,
Drives::Fields::Id,
Drives::Fields::Name
});
QObject::connect(&sharedDrivesFetchJob, &KGAPI2::Job::finished,
&eventLoop, &QEventLoop::quit);
eventLoop.exec();
if (sharedDrivesFetchJob.error() == KGAPI2::OK || sharedDrivesFetchJob.error() == KGAPI2::NoError) {
const auto objects = sharedDrivesFetchJob.items();
for (const auto &object : objects) {
const DrivesPtr sharedDrive = object.dynamicCast<Drives>();
// If we have one or more hits we will take the first as good because we
// don't have any other measures for picking the correct drive
if (sharedDrive->name() == idOrName) {
fileId = sharedDrive->id();
qCDebug(GDRIVE) << "Resolved shared drive id" << idOrName << "to" << fileId;
const auto idPath = GDriveUrl::buildSharedDrivePath(accountId, fileId);
const auto namePath = idOrNamePath;
m_cache.insertPath(idPath, fileId);
m_cache.insertPath(namePath, fileId);
return fileId;
}
}
}
// We couldn't find any shared drive with that id or name
qCDebug(GDRIVE) << "Failed resolving shared drive" << idOrName << "(couldn't find drive with that id or name)";
return QString();
}
QString KIOGDrive::rootFolderId(const QString &accountId)
{
auto it = m_rootIds.constFind(accountId);
......@@ -780,6 +866,7 @@ void KIOGDrive::stat(const QUrl &url)
if (gdriveUrl.isSharedDrive()) {
qCDebug(GDRIVE) << "stat()ing Shared Drive" << url;
statSharedDrive(url);
finished();
return;
}
......
......@@ -96,6 +96,7 @@ private:
KIO::UDSEntry fetchSharedDrivesRootEntry(const QString &accountId, FetchEntryFlags flags = FetchEntryFlags::None);
QString resolveFileIdFromPath(const QString &path, PathFlags flags = None);
QString resolveSharedDriveId(const QString &idOrName, const QString &accountId);
Action handleError(const KGAPI2::Job &job, const QUrl &url);
KIO::UDSEntry fileToUDSEntry(const KGAPI2::Drive::FilePtr &file, const QString &path) const;
......