From 23bbc69759177b97e37e7ba1cd75de6ca7a8be67 Mon Sep 17 00:00:00 2001 From: Hannah von Reth Date: Fri, 28 Jul 2023 10:47:17 +0200 Subject: [PATCH] Add space id to folder and use it Ideally we would no longer need to store the webdav url for spaces, but while the client is starting up or we are offline when starting the client, we don't have the relevant information available. Fixes: #10936 --- src/gui/folder.cpp | 75 +++++++++++++++++-- src/gui/folder.h | 42 ++++++----- src/gui/folderman.cpp | 18 ++--- src/gui/folderman.h | 2 +- src/gui/folderstatusmodel.cpp | 59 ++++++++------- src/gui/folderwizard/folderwizard.cpp | 17 ++++- src/gui/folderwizard/folderwizard.h | 8 +- src/gui/folderwizard/folderwizard_p.h | 1 + src/gui/folderwizard/spacespage.cpp | 2 +- src/gui/folderwizard/spacespage.h | 4 +- src/gui/owncloudgui.cpp | 10 ++- src/gui/scheduling/etagwatcher.cpp | 2 +- src/gui/spaces/spacesbrowser.cpp | 1 + src/gui/spaces/spacesmodel.cpp | 12 ++- src/gui/spaces/spacesmodel.h | 1 + src/libsync/graphapi/spacesmanager.h | 2 +- .../testspacesmigration.cpp | 2 +- test/testutils/testutils.cpp | 2 +- 18 files changed, 180 insertions(+), 80 deletions(-) diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index e75bc1645a3..d188af7aee8 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -21,6 +21,7 @@ #include "accountstate.h" #include "application.h" #include "common/checksums.h" +#include "common/depreaction.h" #include "common/filesystembase.h" #include "common/syncjournalfilerecord.h" #include "common/version.h" @@ -30,6 +31,7 @@ #include "filesystem.h" #include "folderman.h" #include "folderwatcher.h" +#include "libsync/graphapi/spacesmanager.h" #include "localdiscoverytracker.h" #include "networkjobs.h" #include "scheduling/syncscheduler.h" @@ -69,8 +71,14 @@ auto versionC() auto davUrlC() { - return QLatin1String("davUrl"); + return QStringLiteral("davUrl"); } + +auto spaceIdC() +{ + return QStringLiteral("spaceId"); +} + auto displayNameC() { return QLatin1String("displayString"); @@ -368,6 +376,12 @@ QString Folder::remotePath() const QUrl Folder::webDavUrl() const { + const QString spaceId = _definition.spaceId(); + if (!spaceId.isEmpty()) { + if (auto *space = _accountState->account()->spacesManager()->space(spaceId)) { + return QUrl(space->drive().getRoot().getWebDavUrl()); + } + } return _definition.webDavUrl(); } @@ -774,15 +788,29 @@ void Folder::saveToSettings() const removeFromSettings(); auto settings = _accountState->settings(); - settings->beginGroup(QStringLiteral("Folders")); + + auto definitionToSave = _definition; + + // migration + if (accountState()->supportsSpaces() && _definition.spaceId().isEmpty()) { + OC_DISABLE_DEPRECATED_WARNING + if (auto *space = accountState()->account()->spacesManager()->spaceByUrl(webDavUrl())) { + OC_ENABLE_DEPRECATED_WARNING + definitionToSave.setSpaceId(space->drive().getRoot().getId()); + } + } + // with spaces we rely on the space id + // we save the dav url nevertheless to have it available during startup + definitionToSave.setWebDavUrl(webDavUrl()); + // Note: Each of these groups might have a "version" tag, but that's // currently unused. - settings->beginGroup(QString::fromUtf8(_definition.id())); - FolderDefinition::save(*settings, _definition); + settings->beginGroup(QString::fromUtf8(definitionToSave.id())); + FolderDefinition::save(*settings, definitionToSave); settings->sync(); - qCInfo(lcFolder) << "Saved folder" << _definition.localPath() << "to settings, status" << settings->status(); + qCInfo(lcFolder) << "Saved folder" << definitionToSave.localPath() << "to settings, status" << settings->status(); } void Folder::removeFromSettings() const @@ -1244,8 +1272,9 @@ void Folder::slotAboutToRemoveAllFiles(SyncFileItem::Direction direction) ownCloudGui::raiseDialog(msgBox); } -FolderDefinition::FolderDefinition(const QByteArray &id, const QUrl &davUrl, const QString &displayName) +FolderDefinition::FolderDefinition(const QByteArray &id, const QUrl &davUrl, const QString &spaceId, const QString &displayName) : _webDavUrl(davUrl) + , _spaceId(spaceId) , _id(id) , _displayName(displayName) { @@ -1266,6 +1295,9 @@ void FolderDefinition::save(QSettings &settings, const FolderDefinition &folder) settings.setValue(QStringLiteral("localPath"), folder.localPath()); settings.setValue(QStringLiteral("journalPath"), folder.journalPath); settings.setValue(QStringLiteral("targetPath"), folder.targetPath()); + if (!folder.spaceId().isEmpty()) { + settings.setValue(spaceIdC(), folder.spaceId()); + } settings.setValue(davUrlC(), folder.webDavUrl()); settings.setValue(displayNameC(), folder.displayName()); settings.setValue(QStringLiteral("paused"), folder.paused); @@ -1281,7 +1313,7 @@ void FolderDefinition::save(QSettings &settings, const FolderDefinition &folder) FolderDefinition FolderDefinition::load(QSettings &settings, const QByteArray &id) { - FolderDefinition folder(id, settings.value(davUrlC()).toUrl(), settings.value(displayNameC()).toString()); + FolderDefinition folder{id, settings.value(davUrlC()).toUrl(), settings.value(spaceIdC()).toString(), settings.value(displayNameC()).toString()}; folder.setLocalPath(settings.value(QStringLiteral("localPath")).toString()); folder.journalPath = settings.value(QStringLiteral("journalPath")).toString(); folder.setTargetPath(settings.value(QStringLiteral("targetPath")).toString()); @@ -1363,8 +1395,37 @@ bool Folder::groupInSidebar() const return false; } +QString Folder::spaceId() const +{ + return _definition.spaceId(); +} + bool FolderDefinition::isDeployed() const { return _deployed; } + +QUrl FolderDefinition::webDavUrl() const +{ + Q_ASSERT(_webDavUrl.isValid()); + return _webDavUrl; +} + +QString FolderDefinition::targetPath() const +{ + return _targetPath; +} + +QString FolderDefinition::localPath() const +{ + return _localPath; +} + +QString FolderDefinition::spaceId() const +{ + // we might call the function to check for the id + // anyhow one of the conditions needs to be true + Q_ASSERT(_webDavUrl.isValid() || !_spaceId.isEmpty()); + return _spaceId; +} } // namespace OCC diff --git a/src/gui/folder.h b/src/gui/folder.h index 30ef1e3bc9e..3350985efe9 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -51,9 +51,9 @@ class LocalDiscoveryTracker; class FolderDefinition { public: - static auto createNewFolderDefinition(const QUrl &davUrl, const QString &displayName = {}) + static auto createNewFolderDefinition(const QUrl &davUrl, const QString &spaceId, const QString &displayName = {}) { - return FolderDefinition(QUuid::createUuid().toByteArray(QUuid::WithoutBraces), davUrl, displayName); + return FolderDefinition(QUuid::createUuid().toByteArray(QUuid::WithoutBraces), davUrl, spaceId, displayName); } /// path to the journal, usually relative to localPath @@ -84,19 +84,20 @@ class FolderDefinition /// journalPath relative to localPath. QString absoluteJournalPath() const; - QString localPath() const - { - return _localPath; - } - QString targetPath() const - { - return _targetPath; - } - const QUrl &webDavUrl() const - { - Q_ASSERT(_webDavUrl.isValid()); - return _webDavUrl; - } + QString localPath() const; + + QString targetPath() const; + + QUrl webDavUrl() const; + + // could change in the case of spaces + void setWebDavUrl(const QUrl &url) { _webDavUrl = url; } + + // when using spaces we don't store the dav url but the space id + // this id is then used to look up the dav url + QString spaceId() const; + + void setSpaceId(const QString &spaceId) { _spaceId = spaceId; } const QByteArray &id() const; @@ -108,7 +109,6 @@ class FolderDefinition */ bool isDeployed() const; - /** * Higher values mean more imortant * Used for sorting @@ -118,9 +118,12 @@ class FolderDefinition void setPriority(uint32_t newPriority); private: - FolderDefinition(const QByteArray &id, const QUrl &davUrl, const QString &displayName); + FolderDefinition(const QByteArray &id, const QUrl &davUrl, const QString &spaceId, const QString &displayName); + // oc10 and as cache for ocis QUrl _webDavUrl; + + QString _spaceId; /// For legacy reasons this can be a string, new folder objects will use a uuid QByteArray _id; QString _displayName; @@ -195,6 +198,11 @@ class Folder : public QObject */ QUrl webDavUrl() const; + /** + * The space Id (empty for oc10) + */ + QString spaceId() const; + /** * remote folder path, always with a trailing / */ diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index d2d9a7d6b18..dd2afeb67c5 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -150,6 +150,7 @@ void FolderMan::unloadAndDeleteAllFolders() // clear the list of existing folders. const auto folders = std::move(_folders); for (auto *folder : folders) { + folder->saveToSettings(); _socketApi->slotUnregisterPath(folder); folder->deleteLater(); } @@ -875,16 +876,12 @@ bool FolderMan::checkVfsAvailability(const QString &path, Vfs::Mode mode) const return unsupportedConfiguration(path) && Vfs::checkAvailability(path, mode); } -Folder *FolderMan::addFolderFromWizard(const AccountStatePtr &accountStatePtr, const QString &localFolder, const QString &remotePath, const QUrl &webDavUrl, const QString &displayName, bool useVfs) +Folder *FolderMan::addFolderFromWizard(const AccountStatePtr &accountStatePtr, FolderDefinition &&folderDefinition, bool useVfs) { - if (!FolderMan::prepareFolder(localFolder)) { + if (!FolderMan::prepareFolder(folderDefinition.localPath())) { return {}; } - qCInfo(lcFolderMan) << "Adding folder definition for" << localFolder << remotePath; - auto folderDefinition = FolderDefinition::createNewFolderDefinition(webDavUrl, displayName); - folderDefinition.setLocalPath(localFolder); - folderDefinition.setTargetPath(remotePath); folderDefinition.ignoreHiddenFiles = ignoreHiddenFiles(); if (useVfs) { @@ -896,13 +893,13 @@ Folder *FolderMan::addFolderFromWizard(const AccountStatePtr &accountStatePtr, c if (newFolder) { // With spaces we only handle the main folder if (!newFolder->groupInSidebar()) { - Utility::setupFavLink(localFolder); + Utility::setupFavLink(folderDefinition.localPath()); } if (!ConfigFile().newBigFolderSizeLimit().first) { // The user already accepted the selective sync dialog. everything is in the white list newFolder->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncWhiteList, {QStringLiteral("/")}); } - qCDebug(lcFolderMan) << "Local sync folder" << localFolder << "successfully created!"; + qCDebug(lcFolderMan) << "Local sync folder" << folderDefinition.localPath() << "successfully created!"; newFolder->saveToSettings(); } else { qCWarning(lcFolderMan) << "Failed to create local sync folder!"; @@ -912,7 +909,10 @@ Folder *FolderMan::addFolderFromWizard(const AccountStatePtr &accountStatePtr, c Folder *FolderMan::addFolderFromFolderWizardResult(const AccountStatePtr &accountStatePtr, const FolderWizard::Result &config) { - auto f = addFolderFromWizard(accountStatePtr, config.localPath, config.remotePath, config.davUrl, config.displayName, config.useVirtualFiles); + FolderDefinition definition = FolderDefinition::createNewFolderDefinition(config.davUrl, config.spaceId, config.displayName); + definition.setLocalPath(config.localPath); + definition.setTargetPath(config.remotePath); + auto f = addFolderFromWizard(accountStatePtr, std::move(definition), config.useVirtualFiles); if (f) { f->journalDb()->setSelectiveSyncList(SyncJournalDb::SelectiveSyncBlackList, config.selectiveSyncBlackList); f->setPriority(config.priority); diff --git a/src/gui/folderman.h b/src/gui/folderman.h index 9ebd859283e..7c1ac651a0c 100644 --- a/src/gui/folderman.h +++ b/src/gui/folderman.h @@ -126,7 +126,7 @@ class FolderMan : public QObject * Adds a folder for an account. Used to be part of the wizard code base. Constructs the folder definition from the parameters. * In case Wizard::SyncMode::SelectiveSync is used, nullptr is returned. */ - Folder *addFolderFromWizard(const AccountStatePtr &accountStatePtr, const QString &localFolder, const QString &remotePath, const QUrl &webDavUrl, const QString &displayName, bool useVfs); + Folder *addFolderFromWizard(const AccountStatePtr &accountStatePtr, FolderDefinition &&definition, bool useVfs); Folder *addFolderFromFolderWizardResult(const AccountStatePtr &accountStatePtr, const FolderWizard::Result &config); /** Removes a folder */ diff --git a/src/gui/folderstatusmodel.cpp b/src/gui/folderstatusmodel.cpp index 674102d8154..062bb51646b 100644 --- a/src/gui/folderstatusmodel.cpp +++ b/src/gui/folderstatusmodel.cpp @@ -47,37 +47,38 @@ namespace { const char propertyParentIndexC[] = "oc_parentIndex"; const char propertyPermissionMap[] = "oc_permissionMap"; - int64_t getQuota(const AccountStatePtr &accountState, const QUrl &davUrl, FolderStatusModel::Columns type) + int64_t getQuota(const AccountStatePtr &accountState, const QString &spaceId, FolderStatusModel::Columns type) { - if (accountState->supportsSpaces()) { - if (auto spacesManager = accountState->account()->spacesManager()) { - const auto *space = spacesManager->spaceByUrl(davUrl); - if (space) { - const auto quota = space->drive().getQuota(); - if (quota.isValid()) { - switch (type) { - case FolderStatusModel::Columns::QuotaTotal: - return quota.getTotal(); - case FolderStatusModel::Columns::QuotaUsed: - return quota.getUsed(); - default: - Q_UNREACHABLE(); - } + if (auto spacesManager = accountState->account()->spacesManager()) { + const auto *space = spacesManager->space(spaceId); + if (space) { + const auto quota = space->drive().getQuota(); + if (quota.isValid()) { + switch (type) { + case FolderStatusModel::Columns::QuotaTotal: + return quota.getTotal(); + case FolderStatusModel::Columns::QuotaUsed: + return quota.getUsed(); + default: + Q_UNREACHABLE(); } } } - } else { - switch (type) { - case FolderStatusModel::Columns::QuotaTotal: - return accountState->quotaInfo()->lastQuotaTotalBytes(); - case FolderStatusModel::Columns::QuotaUsed: - return accountState->quotaInfo()->lastQuotaUsedBytes(); - default: - Q_UNREACHABLE(); - } } return {}; } + + int64_t getQuotaOc10(const AccountStatePtr &accountState, const QUrl &davUrl, FolderStatusModel::Columns type) + { + switch (type) { + case FolderStatusModel::Columns::QuotaTotal: + return accountState->quotaInfo()->lastQuotaTotalBytes(); + case FolderStatusModel::Columns::QuotaUsed: + return accountState->quotaInfo()->lastQuotaUsedBytes(); + default: + Q_UNREACHABLE(); + } + } } FolderStatusModel::FolderStatusModel(QObject *parent) @@ -246,7 +247,7 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const const auto getSpace = [&]() -> GraphApi::Space * { if (_accountState->supportsSpaces()) { - return _accountState->account()->spacesManager()->spaceByUrl(f->webDavUrl()); + return _accountState->account()->spacesManager()->space(f->spaceId()); } return nullptr; }; @@ -323,9 +324,13 @@ QVariant FolderStatusModel::data(const QModelIndex &index, int role) const case Columns::Priority: return f->priority(); case Columns::QuotaTotal: - return QVariant::fromValue(getQuota(_accountState, f->webDavUrl(), Columns::QuotaTotal)); + [[fallthrough]]; case Columns::QuotaUsed: - return QVariant::fromValue(getQuota(_accountState, f->webDavUrl(), Columns::QuotaUsed)); + if (_accountState->supportsSpaces()) { + return QVariant::fromValue(getQuota(_accountState, f->spaceId(), column)); + } else { + return QVariant::fromValue(getQuotaOc10(_accountState, f->webDavUrl(), column)); + } case Columns::IsUsingSpaces: // handled before [[fallthrough]]; case Columns::ItemType: // handled before diff --git a/src/gui/folderwizard/folderwizard.cpp b/src/gui/folderwizard/folderwizard.cpp index 0b6323ee162..4f0a1bf1b3c 100644 --- a/src/gui/folderwizard/folderwizard.cpp +++ b/src/gui/folderwizard/folderwizard.cpp @@ -103,7 +103,7 @@ QString FolderWizardPrivate::initialLocalPath() const { if (_account->supportsSpaces()) { return FolderMan::instance()->findGoodPathForNewSyncFolder( - defaultSyncRoot(), _spacesPage->selectedSpace(Spaces::SpacesModel::Columns::Name).toString()); + defaultSyncRoot(), _spacesPage->selectedSpaceData(Spaces::SpacesModel::Columns::Name).toString()); } return defaultSyncRoot(); } @@ -116,7 +116,7 @@ QString FolderWizardPrivate::remotePath() const uint32_t FolderWizardPrivate::priority() const { if (_account->supportsSpaces()) { - return _spacesPage->selectedSpace(Spaces::SpacesModel::Columns::Priority).toInt(); + return _spacesPage->selectedSpaceData(Spaces::SpacesModel::Columns::Priority).toInt(); }; return 0; } @@ -124,7 +124,7 @@ uint32_t FolderWizardPrivate::priority() const QUrl FolderWizardPrivate::davUrl() const { if (_account->supportsSpaces()) { - auto url = _spacesPage->selectedSpace(Spaces::SpacesModel::Columns::WebDavUrl).toUrl(); + auto url = _spacesPage->selectedSpaceData(Spaces::SpacesModel::Columns::WebDavUrl).toUrl(); if (!url.path().endsWith(QLatin1Char('/'))) { url.setPath(url.path() + QLatin1Char('/')); } @@ -133,10 +133,18 @@ QUrl FolderWizardPrivate::davUrl() const return _account->account()->davUrl(); } +QString FolderWizardPrivate::spaceId() const +{ + if (_account->supportsSpaces()) { + return _spacesPage->selectedSpaceData(Spaces::SpacesModel::Columns::SpaceId).toString(); + } + return {}; +} + QString FolderWizardPrivate::displayName() const { if (_account->supportsSpaces()) { - return _spacesPage->selectedSpace(Spaces::SpacesModel::Columns::Name).toString(); + return _spacesPage->selectedSpaceData(Spaces::SpacesModel::Columns::Name).toString(); }; return QString(); } @@ -212,6 +220,7 @@ FolderWizard::Result FolderWizard::result() return { d->davUrl(), // + d->spaceId(), // localPath, // d->remotePath(), // d->displayName(), // diff --git a/src/gui/folderwizard/folderwizard.h b/src/gui/folderwizard/folderwizard.h index 9bddd020e11..78c29a0d88d 100644 --- a/src/gui/folderwizard/folderwizard.h +++ b/src/gui/folderwizard/folderwizard.h @@ -50,9 +50,15 @@ class FolderWizard : public QWizard struct Result { /*** - * The webdav url for the sync connection. +- * The webdav url for the sync connection. */ QUrl davUrl; + + /*** + * The id of the space or empty in case of ownCloud 10. + */ + QString spaceId; + /*** * The local folder used for the sync. */ diff --git a/src/gui/folderwizard/folderwizard_p.h b/src/gui/folderwizard/folderwizard_p.h index 9af12dc2a9a..ccd3f1e8d24 100644 --- a/src/gui/folderwizard/folderwizard_p.h +++ b/src/gui/folderwizard/folderwizard_p.h @@ -43,6 +43,7 @@ class FolderWizardPrivate QString defaultSyncRoot() const; QUrl davUrl() const; + QString spaceId() const; bool useVirtualFiles() const; QString displayName() const; diff --git a/src/gui/folderwizard/spacespage.cpp b/src/gui/folderwizard/spacespage.cpp index e9af3dc39db..3fbc29e3d1c 100644 --- a/src/gui/folderwizard/spacespage.cpp +++ b/src/gui/folderwizard/spacespage.cpp @@ -39,7 +39,7 @@ bool OCC::SpacesPage::isComplete() const return ui->widget->currentSpace().isValid(); } -QVariant OCC::SpacesPage::selectedSpace(Spaces::SpacesModel::Columns column) const +QVariant OCC::SpacesPage::selectedSpaceData(Spaces::SpacesModel::Columns column) const { return ui->widget->currentSpace().siblingAtColumn(static_cast(column)).data(); } diff --git a/src/gui/folderwizard/spacespage.h b/src/gui/folderwizard/spacespage.h index 850c86608f9..1a6080da9a4 100644 --- a/src/gui/folderwizard/spacespage.h +++ b/src/gui/folderwizard/spacespage.h @@ -36,10 +36,10 @@ class SpacesPage : public QWizardPage bool isComplete() const override; - QVariant selectedSpace(Spaces::SpacesModel::Columns column) const; + QVariant selectedSpaceData(Spaces::SpacesModel::Columns column) const; private: Ui::SpacesPage *ui; }; -} \ No newline at end of file +} diff --git a/src/gui/owncloudgui.cpp b/src/gui/owncloudgui.cpp index e3fec643488..dcaa828f6b8 100644 --- a/src/gui/owncloudgui.cpp +++ b/src/gui/owncloudgui.cpp @@ -68,8 +68,12 @@ void setUpInitialSyncFolder(AccountStatePtr accountStatePtr, bool useVfs) auto folderMan = FolderMan::instance(); // saves a bit of duplicate code - auto addFolder = [folderMan, accountStatePtr, useVfs](const QString &localFolder, const QString &remotePath, const QUrl &webDavUrl, const QString &displayName = {}) { - return folderMan->addFolderFromWizard(accountStatePtr, localFolder, remotePath, webDavUrl, displayName, useVfs); + auto addFolder = [folderMan, accountStatePtr, useVfs](const QString &localFolder, const QString &remotePath, const QUrl &davUrl, + const QString &spaceId = {}, const QString &displayName = {}) { + auto def = FolderDefinition::createNewFolderDefinition(davUrl, spaceId, displayName); + def.setLocalPath(localFolder); + def.setTargetPath(remotePath); + return folderMan->addFolderFromWizard(accountStatePtr, std::move(def), useVfs); }; auto finalize = [accountStatePtr] { @@ -96,7 +100,7 @@ void setUpInitialSyncFolder(AccountStatePtr accountStatePtr, bool useVfs) for (const auto *space : spaces) { const QString name = space->displayName(); const QString folderName = FolderMan::instance()->findGoodPathForNewSyncFolder(localDir, name); - auto folder = addFolder(folderName, {}, QUrl(space->drive().getRoot().getWebDavUrl()), name); + auto folder = addFolder(folderName, {}, QUrl(space->drive().getRoot().getWebDavUrl()), space->drive().getRoot().getId(), name); folder->setPriority(space->priority()); // save the new priority folder->saveToSettings(); diff --git a/src/gui/scheduling/etagwatcher.cpp b/src/gui/scheduling/etagwatcher.cpp index df0c16b3d7b..bdca100cf33 100644 --- a/src/gui/scheduling/etagwatcher.cpp +++ b/src/gui/scheduling/etagwatcher.cpp @@ -63,7 +63,7 @@ ETagWatcher::ETagWatcher(FolderMan *folderMan, QObject *parent) if (info.first->accountState()->supportsSpaces()) { // we could also connect to the spaceChanged signal but for now this will keep it closer to oc10 // ensure we already know about the space (startup) - if (auto *space = info.first->accountState()->account()->spacesManager()->spaceByUrl(info.first->webDavUrl())) { + if (auto *space = info.first->accountState()->account()->spacesManager()->space(info.first->spaceId())) { updateEtag(info.first, space->drive().getRoot().getETag()); } } else { diff --git a/src/gui/spaces/spacesbrowser.cpp b/src/gui/spaces/spacesbrowser.cpp index c37ccaadd34..c921fc2605f 100644 --- a/src/gui/spaces/spacesbrowser.cpp +++ b/src/gui/spaces/spacesbrowser.cpp @@ -59,6 +59,7 @@ SpacesBrowser::SpacesBrowser(QWidget *parent) header->hideSection(static_cast(SpacesModel::Columns::Subtitle)); header->hideSection(static_cast(SpacesModel::Columns::Priority)); header->hideSection(static_cast(SpacesModel::Columns::Enabled)); + header->hideSection(static_cast(SpacesModel::Columns::SpaceId)); header->setContextMenuPolicy(Qt::CustomContextMenu); connect(header, &QHeaderView::customContextMenuRequested, header, [header, this] { auto menu = new QMenu(this); diff --git a/src/gui/spaces/spacesmodel.cpp b/src/gui/spaces/spacesmodel.cpp index b849ea2eb67..f8b4fec0030 100644 --- a/src/gui/spaces/spacesmodel.cpp +++ b/src/gui/spaces/spacesmodel.cpp @@ -62,9 +62,10 @@ QVariant SpacesModel::headerData(int section, Qt::Orientation orientation, int r return tr("Priority"); case Columns::Enabled: return tr("Enabled"); - default: + case Columns::SpaceId: + return tr("SpaceId"); + case Columns::ColumnCount: Q_UNREACHABLE(); - break; } } } @@ -112,9 +113,12 @@ QVariant SpacesModel::data(const QModelIndex &index, int role) const return {}; case Columns::Priority: return space->priority(); - default: + case Columns::SpaceId: + return space->drive().getRoot().getId(); + case Columns::Enabled: + return !space->disabled(); + case Columns::ColumnCount: Q_UNREACHABLE(); - break; } break; case Qt::DecorationRole: diff --git a/src/gui/spaces/spacesmodel.h b/src/gui/spaces/spacesmodel.h index 90268d5449b..559df806dbe 100644 --- a/src/gui/spaces/spacesmodel.h +++ b/src/gui/spaces/spacesmodel.h @@ -37,6 +37,7 @@ class SpacesModel : public QAbstractTableModel WebDavUrl, Priority, Enabled, + SpaceId, ColumnCount, }; diff --git a/src/libsync/graphapi/spacesmanager.h b/src/libsync/graphapi/spacesmanager.h index b714964a89c..80a4628a837 100644 --- a/src/libsync/graphapi/spacesmanager.h +++ b/src/libsync/graphapi/spacesmanager.h @@ -42,7 +42,7 @@ namespace GraphApi { QVector spaces() const; // deprecated: we need to migrate to id based spaces - Space *spaceByUrl(const QUrl &url) const; + [[deprecated("Use space(const QString &id)")]] Space *spaceByUrl(const QUrl &url) const; Account *account() const; diff --git a/test/testspacesmigration/testspacesmigration.cpp b/test/testspacesmigration/testspacesmigration.cpp index 1a13ed4e266..798d6a6e920 100644 --- a/test/testspacesmigration/testspacesmigration.cpp +++ b/test/testspacesmigration/testspacesmigration.cpp @@ -24,7 +24,7 @@ class TestSpacesMigration : public QObject auto addFolder(AccountStatePtr accountState, const QString &localPath, const QString &remotePath) { - auto d = OCC::FolderDefinition::createNewFolderDefinition(accountState->account()->davUrl()); + auto d = OCC::FolderDefinition::createNewFolderDefinition(accountState->account()->davUrl(), {}); Q_ASSERT(localPath.startsWith(QLatin1Char('/'))); d.setLocalPath(_tmp.path() + localPath); d.setTargetPath(remotePath); diff --git a/test/testutils/testutils.cpp b/test/testutils/testutils.cpp index 62fbe862334..96edbe56d6f 100644 --- a/test/testutils/testutils.cpp +++ b/test/testutils/testutils.cpp @@ -40,7 +40,7 @@ namespace TestUtils { FolderDefinition createDummyFolderDefinition(const AccountPtr &account, const QString &path) { // TODO: legacy - auto d = OCC::FolderDefinition::createNewFolderDefinition(account->davUrl()); + auto d = OCC::FolderDefinition::createNewFolderDefinition(account->davUrl(), {}); d.setLocalPath(path); d.setTargetPath(path); return d;