From 853b7b82f00a9e180b0b63a00f73275b332c91d3 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 21 Oct 2024 14:52:14 +0800 Subject: [PATCH 1/5] Mark non-const getters in Folder definition as const Signed-off-by: Claudio Cambra --- src/gui/folder.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/gui/folder.h b/src/gui/folder.h index c79153a86758..f55f9c62bf3f 100644 --- a/src/gui/folder.h +++ b/src/gui/folder.h @@ -223,11 +223,11 @@ class Folder : public QObject void setIgnoreHiddenFiles(bool ignore); // Used by the Socket API - SyncJournalDb *journalDb() { return &_journal; } - SyncEngine &syncEngine() { return *_engine; } - Vfs &vfs() { return *_vfs; } + SyncJournalDb *journalDb() const { return &_journal; } + SyncEngine &syncEngine() const { return *_engine; } + Vfs &vfs() const { return *_vfs; } - RequestEtagJob *etagJob() { return _requestEtagJob; } + RequestEtagJob *etagJob() const { return _requestEtagJob; } std::chrono::milliseconds msecSinceLastSync() const { return std::chrono::milliseconds(_timeSinceLastSyncDone.elapsed()); } std::chrono::milliseconds msecLastSyncDuration() const { return _lastSyncDuration; } int consecutiveFollowUpSyncs() const { return _consecutiveFollowUpSyncs; } From de4460f2af3228e761ed5d31d26e8667361c7ed5 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 21 Oct 2024 14:54:34 +0800 Subject: [PATCH 2/5] Store fetched folder as private member in filedetails Signed-off-by: Claudio Cambra --- src/gui/filedetails/filedetails.cpp | 12 ++++++------ src/gui/filedetails/filedetails.h | 1 + 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/gui/filedetails/filedetails.cpp b/src/gui/filedetails/filedetails.cpp index 67ebb554cec2..e7897aaf5f92 100644 --- a/src/gui/filedetails/filedetails.cpp +++ b/src/gui/filedetails/filedetails.cpp @@ -61,15 +61,15 @@ void FileDetails::setLocalPath(const QString &localPath) _fileWatcher.addPath(localPath); connect(&_fileWatcher, &QFileSystemWatcher::fileChanged, this, &FileDetails::refreshFileDetails); - const auto folder = FolderMan::instance()->folderForPath(_localPath); - if (!folder) { + _folder = FolderMan::instance()->folderForPath(_localPath); + if (!_folder) { qCWarning(lcFileDetails) << "No folder found for path:" << _localPath << "will not load file details."; return; } - const auto file = _localPath.mid(folder->cleanPath().length() + 1); + const auto file = _localPath.mid(_folder->cleanPath().length() + 1); - if (!folder->journalDb()->getFileRecord(file, &_fileRecord)) { + if (!_folder->journalDb()->getFileRecord(file, &_fileRecord)) { qCWarning(lcFileDetails) << "Invalid file record for path:" << _localPath << "will not load file details."; @@ -77,9 +77,9 @@ void FileDetails::setLocalPath(const QString &localPath) _filelockState = _fileRecord._lockstate; updateLockExpireString(); - updateFileTagModel(folder); - _sharingAvailable = folder->accountState()->account()->capabilities().shareAPI(); + const auto account = _folder->accountState()->account(); + _sharingAvailable = account->capabilities().shareAPI(); Q_EMIT fileChanged(); } diff --git a/src/gui/filedetails/filedetails.h b/src/gui/filedetails/filedetails.h index 2834981afb76..a4dc7e5931ce 100644 --- a/src/gui/filedetails/filedetails.h +++ b/src/gui/filedetails/filedetails.h @@ -73,6 +73,7 @@ private slots: QFileInfo _fileInfo; QFileSystemWatcher _fileWatcher; + Folder *_folder = nullptr; SyncJournalFileRecord _fileRecord; SyncJournalFileLockInfo _filelockState; QByteArray _numericFileId; From 65746250eda5e879582d6acf5e5b9078f6bc66d7 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 21 Oct 2024 14:56:14 +0800 Subject: [PATCH 3/5] Simply pass AccountPtr to updateFileTagModel Signed-off-by: Claudio Cambra --- src/gui/filedetails/filedetails.cpp | 5 ++--- src/gui/filedetails/filedetails.h | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/src/gui/filedetails/filedetails.cpp b/src/gui/filedetails/filedetails.cpp index e7897aaf5f92..2b76c70ad296 100644 --- a/src/gui/filedetails/filedetails.cpp +++ b/src/gui/filedetails/filedetails.cpp @@ -80,6 +80,7 @@ void FileDetails::setLocalPath(const QString &localPath) const auto account = _folder->accountState()->account(); _sharingAvailable = account->capabilities().shareAPI(); + updateFileTagModel(account); Q_EMIT fileChanged(); } @@ -167,10 +168,8 @@ FileTagModel *FileDetails::fileTagModel() const return _fileTagModel.get(); } -void FileDetails::updateFileTagModel(const Folder * const folder) +void FileDetails::updateFileTagModel(const AccountPtr &account) { - Q_ASSERT(folder); - const auto account = folder->accountState()->account(); Q_ASSERT(account); const auto serverRelPath = QString(folder->remotePathTrailingSlash() + name()); diff --git a/src/gui/filedetails/filedetails.h b/src/gui/filedetails/filedetails.h index a4dc7e5931ce..fef2b010aeda 100644 --- a/src/gui/filedetails/filedetails.h +++ b/src/gui/filedetails/filedetails.h @@ -66,7 +66,7 @@ public slots: private slots: void refreshFileDetails(); void updateLockExpireString(); - void updateFileTagModel(const OCC::Folder * const folder); + void updateFileTagModel(const OCC::AccountPtr &account); private: QString _localPath; From 9c5d1e281e1cae1c6bf183caa96dfba84f758f98 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Mon, 21 Oct 2024 14:57:22 +0800 Subject: [PATCH 4/5] Ensure we are checking for tags in correct server path regardless of the particular local path Fixes issues with users who are using remote non-root sync folders Signed-off-by: Claudio Cambra --- src/gui/filedetails/filedetails.cpp | 6 +----- src/gui/filetagmodel.cpp | 12 ++++++++++-- src/gui/filetagmodel.h | 7 ++++++- 3 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/gui/filedetails/filedetails.cpp b/src/gui/filedetails/filedetails.cpp index 2b76c70ad296..9ebe8fac2bc1 100644 --- a/src/gui/filedetails/filedetails.cpp +++ b/src/gui/filedetails/filedetails.cpp @@ -170,11 +170,7 @@ FileTagModel *FileDetails::fileTagModel() const void FileDetails::updateFileTagModel(const AccountPtr &account) { - Q_ASSERT(account); - - const auto serverRelPath = QString(folder->remotePathTrailingSlash() + name()); - - _fileTagModel = std::make_unique(serverRelPath, account); + _fileTagModel = std::make_unique(_fileRecord, _folder, account); Q_EMIT fileTagModelChanged(); } diff --git a/src/gui/filetagmodel.cpp b/src/gui/filetagmodel.cpp index 64cab4486a4f..282ff84c1884 100644 --- a/src/gui/filetagmodel.cpp +++ b/src/gui/filetagmodel.cpp @@ -20,13 +20,21 @@ Q_LOGGING_CATEGORY(lcFileTagModel, "nextcloud.gui.filetagmodel", QtInfoMsg) namespace OCC { -FileTagModel::FileTagModel(const QString &serverRelativePath, +FileTagModel::FileTagModel(const SyncJournalFileRecord &fileRecord, + const Folder * const syncFolder, const AccountPtr &account, QObject * const parent) : QAbstractListModel(parent) - , _serverRelativePath(serverRelativePath) , _account(account) { + _serverRelativePath = syncFolder->remotePathTrailingSlash() + fileRecord.path(); + + if (const auto vfsMode = syncFolder->vfs().mode(); fileRecord.isVirtualFile() && vfsMode == Vfs::WithSuffix) { + if (const auto suffix = syncFolder->vfs().fileSuffix(); !suffix.isEmpty() && _serverRelativePath.endsWith(suffix)) { + _serverRelativePath.chop(suffix.length()); + } + } + fetchFileTags(); } diff --git a/src/gui/filetagmodel.h b/src/gui/filetagmodel.h index 618702e8b5b0..77933eccd984 100644 --- a/src/gui/filetagmodel.h +++ b/src/gui/filetagmodel.h @@ -16,6 +16,8 @@ #include +#include "common/syncjournalfilerecord.h" +#include "gui/folder.h" #include "libsync/account.h" namespace OCC { @@ -31,7 +33,10 @@ class FileTagModel : public QAbstractListModel Q_PROPERTY(QString overflowTagsString READ overflowTagsString NOTIFY overflowTagsStringChanged) public: - explicit FileTagModel(const QString &serverRelativePath, const AccountPtr &account, QObject * const parent = nullptr); + explicit FileTagModel(const SyncJournalFileRecord &fileRecord, + const Folder *const syncFolder, + const AccountPtr &account, + QObject *const parent = nullptr); [[nodiscard]] int rowCount(const QModelIndex &parent = QModelIndex()) const override; [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; From eff48c156dc8c3a647fb7d2376d351e7b06fd1d4 Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Wed, 23 Oct 2024 14:53:37 +0800 Subject: [PATCH 5/5] Move setup of server relative path used in FileTagModel into FileDetails This fixes the build breakages in the file tag model tests Signed-off-by: Claudio Cambra --- src/gui/filedetails/filedetails.cpp | 33 +++++++++++++++++++++++++---- src/gui/filedetails/filedetails.h | 2 +- src/gui/filetagmodel.cpp | 12 ++--------- src/gui/filetagmodel.h | 3 +-- 4 files changed, 33 insertions(+), 17 deletions(-) diff --git a/src/gui/filedetails/filedetails.cpp b/src/gui/filedetails/filedetails.cpp index 9ebe8fac2bc1..bc8f2d4895c8 100644 --- a/src/gui/filedetails/filedetails.cpp +++ b/src/gui/filedetails/filedetails.cpp @@ -62,6 +62,7 @@ void FileDetails::setLocalPath(const QString &localPath) connect(&_fileWatcher, &QFileSystemWatcher::fileChanged, this, &FileDetails::refreshFileDetails); _folder = FolderMan::instance()->folderForPath(_localPath); + Q_ASSERT(_folder); if (!_folder) { qCWarning(lcFileDetails) << "No folder found for path:" << _localPath << "will not load file details."; return; @@ -78,9 +79,23 @@ void FileDetails::setLocalPath(const QString &localPath) _filelockState = _fileRecord._lockstate; updateLockExpireString(); - const auto account = _folder->accountState()->account(); + const auto accountState = _folder->accountState(); + Q_ASSERT(accountState); + if (!accountState) { + qCWarning(lcFileDetails) << "No account state found for path:" << _localPath << "will not correctly load file details."; + return; + } + + const auto account = accountState->account(); + Q_ASSERT(account); + if (!account) { + qCWarning(lcFileDetails) << "No account found for path:" << _localPath << "will not correctly load file details."; + return; + } + _sharingAvailable = account->capabilities().shareAPI(); - updateFileTagModel(account); + + updateFileTagModel(); Q_EMIT fileChanged(); } @@ -168,9 +183,19 @@ FileTagModel *FileDetails::fileTagModel() const return _fileTagModel.get(); } -void FileDetails::updateFileTagModel(const AccountPtr &account) +void FileDetails::updateFileTagModel() { - _fileTagModel = std::make_unique(_fileRecord, _folder, account); + const auto localPath = _fileRecord.path(); + const auto relPath = localPath.mid(_folder->cleanPath().length() + 1); + QString serverPath = _folder->remotePathTrailingSlash() + _fileRecord.path(); + + if (const auto vfsMode = _folder->vfs().mode(); _fileRecord.isVirtualFile() && vfsMode == Vfs::WithSuffix) { + if (const auto suffix = _folder->vfs().fileSuffix(); !suffix.isEmpty() && serverPath.endsWith(suffix)) { + serverPath.chop(suffix.length()); + } + } + + _fileTagModel = std::make_unique(relPath, _folder->accountState()->account()); Q_EMIT fileTagModelChanged(); } diff --git a/src/gui/filedetails/filedetails.h b/src/gui/filedetails/filedetails.h index fef2b010aeda..8f0ff7165903 100644 --- a/src/gui/filedetails/filedetails.h +++ b/src/gui/filedetails/filedetails.h @@ -66,7 +66,7 @@ public slots: private slots: void refreshFileDetails(); void updateLockExpireString(); - void updateFileTagModel(const OCC::AccountPtr &account); + void updateFileTagModel(); private: QString _localPath; diff --git a/src/gui/filetagmodel.cpp b/src/gui/filetagmodel.cpp index 282ff84c1884..64cab4486a4f 100644 --- a/src/gui/filetagmodel.cpp +++ b/src/gui/filetagmodel.cpp @@ -20,21 +20,13 @@ Q_LOGGING_CATEGORY(lcFileTagModel, "nextcloud.gui.filetagmodel", QtInfoMsg) namespace OCC { -FileTagModel::FileTagModel(const SyncJournalFileRecord &fileRecord, - const Folder * const syncFolder, +FileTagModel::FileTagModel(const QString &serverRelativePath, const AccountPtr &account, QObject * const parent) : QAbstractListModel(parent) + , _serverRelativePath(serverRelativePath) , _account(account) { - _serverRelativePath = syncFolder->remotePathTrailingSlash() + fileRecord.path(); - - if (const auto vfsMode = syncFolder->vfs().mode(); fileRecord.isVirtualFile() && vfsMode == Vfs::WithSuffix) { - if (const auto suffix = syncFolder->vfs().fileSuffix(); !suffix.isEmpty() && _serverRelativePath.endsWith(suffix)) { - _serverRelativePath.chop(suffix.length()); - } - } - fetchFileTags(); } diff --git a/src/gui/filetagmodel.h b/src/gui/filetagmodel.h index 77933eccd984..9f0a6b6d091d 100644 --- a/src/gui/filetagmodel.h +++ b/src/gui/filetagmodel.h @@ -33,8 +33,7 @@ class FileTagModel : public QAbstractListModel Q_PROPERTY(QString overflowTagsString READ overflowTagsString NOTIFY overflowTagsStringChanged) public: - explicit FileTagModel(const SyncJournalFileRecord &fileRecord, - const Folder *const syncFolder, + explicit FileTagModel(const QString &serverRelativePath, const AccountPtr &account, QObject *const parent = nullptr);