Skip to content

Commit

Permalink
Move setup of server relative path used in FileTagModel into FileDetails
Browse files Browse the repository at this point in the history
This fixes the build breakages in the file tag model tests

Signed-off-by: Claudio Cambra <[email protected]>
  • Loading branch information
claucambra committed Oct 23, 2024
1 parent 9c5d1e2 commit eff48c1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 17 deletions.
33 changes: 29 additions & 4 deletions src/gui/filedetails/filedetails.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

Check warning on line 66 in src/gui/filedetails/filedetails.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/filedetails/filedetails.cpp:66:10 [readability-implicit-bool-conversion]

implicit conversion 'OCC::Folder *' -> bool
qCWarning(lcFileDetails) << "No folder found for path:" << _localPath << "will not load file details.";
return;
Expand All @@ -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();
}
Expand Down Expand Up @@ -168,9 +183,19 @@ FileTagModel *FileDetails::fileTagModel() const
return _fileTagModel.get();
}

void FileDetails::updateFileTagModel(const AccountPtr &account)
void FileDetails::updateFileTagModel()
{
_fileTagModel = std::make_unique<FileTagModel>(_fileRecord, _folder, account);
const auto localPath = _fileRecord.path();
const auto relPath = localPath.mid(_folder->cleanPath().length() + 1);
QString serverPath = _folder->remotePathTrailingSlash() + _fileRecord.path();

Check warning on line 190 in src/gui/filedetails/filedetails.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/filedetails/filedetails.cpp:190:13 [cppcoreguidelines-init-variables]

variable 'serverPath' is not initialized

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<FileTagModel>(relPath, _folder->accountState()->account());
Q_EMIT fileTagModelChanged();

Check warning on line 199 in src/gui/filedetails/filedetails.cpp

View workflow job for this annotation

GitHub Actions / build

src/gui/filedetails/filedetails.cpp:199:12 [modernize-use-trailing-return-type]

use a trailing return type for this function
}

Expand Down
2 changes: 1 addition & 1 deletion src/gui/filedetails/filedetails.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public slots:
private slots:
void refreshFileDetails();
void updateLockExpireString();
void updateFileTagModel(const OCC::AccountPtr &account);
void updateFileTagModel();

private:
QString _localPath;
Expand Down
12 changes: 2 additions & 10 deletions src/gui/filetagmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
3 changes: 1 addition & 2 deletions src/gui/filetagmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit eff48c1

Please sign in to comment.