diff --git a/src/gui/filedetails/filedetails.cpp b/src/gui/filedetails/filedetails.cpp index 9ebe8fac2bc1a..bc8f2d4895c84 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 fef2b010aeda0..8f0ff7165903c 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 282ff84c18848..64cab4486a4f9 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 77933eccd9841..9f0a6b6d091dc 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);