]> dgit.raspbian.org Git - nextcloud-desktop.git/commitdiff
Move setup of server relative path used in FileTagModel into FileDetails
authorClaudio Cambra <claudio.cambra@nextcloud.com>
Wed, 23 Oct 2024 06:53:37 +0000 (14:53 +0800)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Thu, 21 Nov 2024 08:57:39 +0000 (09:57 +0100)
This fixes the build breakages in the file tag model tests

Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
src/gui/filedetails/filedetails.cpp
src/gui/filedetails/filedetails.h
src/gui/filetagmodel.cpp
src/gui/filetagmodel.h

index 9ebe8fac2bc1a31c9548efa8056401981160c1b8..bc8f2d4895c847b97fc5258978ae5ac2754562ca 100644 (file)
@@ -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<FileTagModel>(_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<FileTagModel>(relPath, _folder->accountState()->account());
     Q_EMIT fileTagModelChanged();
 }
 
index fef2b010aeda0f7b51a16b99f03fccc65af5fbb6..8f0ff7165903c177dbc6b5f27cf83cb26d3c7965 100644 (file)
@@ -66,7 +66,7 @@ signals:
 private slots:
     void refreshFileDetails();
     void updateLockExpireString();
-    void updateFileTagModel(const OCC::AccountPtr &account);
+    void updateFileTagModel();
 
 private:
     QString _localPath;
index 282ff84c1884817539eede4417cab74684d95140..64cab4486a4f98ce6c925910c986e94cfffad401 100644 (file)
@@ -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();
 }
 
index 77933eccd98418cff056c266df7ac554eaade101..9f0a6b6d091dce782a94ac68a9e4b95f3e39f9f1 100644 (file)
@@ -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);