diff --git a/src/gui/filedetails/filedetails.cpp b/src/gui/filedetails/filedetails.cpp index 67ebb554cec2..bc8f2d4895c8 100644 --- a/src/gui/filedetails/filedetails.cpp +++ b/src/gui/filedetails/filedetails.cpp @@ -61,15 +61,16 @@ 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); + Q_ASSERT(_folder); + 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 +78,24 @@ void FileDetails::setLocalPath(const QString &localPath) _filelockState = _fileRecord._lockstate; updateLockExpireString(); - updateFileTagModel(folder); - _sharingAvailable = folder->accountState()->account()->capabilities().shareAPI(); + 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(); Q_EMIT fileChanged(); } @@ -167,15 +183,19 @@ FileTagModel *FileDetails::fileTagModel() const return _fileTagModel.get(); } -void FileDetails::updateFileTagModel(const Folder * const folder) +void FileDetails::updateFileTagModel() { - Q_ASSERT(folder); - const auto account = folder->accountState()->account(); - Q_ASSERT(account); - - const auto serverRelPath = QString(folder->remotePathTrailingSlash() + name()); + 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(serverRelPath, account); + _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 2834981afb76..8f0ff7165903 100644 --- a/src/gui/filedetails/filedetails.h +++ b/src/gui/filedetails/filedetails.h @@ -66,13 +66,14 @@ public slots: private slots: void refreshFileDetails(); void updateLockExpireString(); - void updateFileTagModel(const OCC::Folder * const folder); + void updateFileTagModel(); private: QString _localPath; QFileInfo _fileInfo; QFileSystemWatcher _fileWatcher; + Folder *_folder = nullptr; SyncJournalFileRecord _fileRecord; SyncJournalFileLockInfo _filelockState; QByteArray _numericFileId; diff --git a/src/gui/filetagmodel.h b/src/gui/filetagmodel.h index 618702e8b5b0..9f0a6b6d091d 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,9 @@ 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 QString &serverRelativePath, + 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; 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; }