From 9cc241bf96f9ce36c10d60b747023ccb2def8f0f Mon Sep 17 00:00:00 2001 From: Claudio Cambra Date: Tue, 11 Apr 2023 23:21:17 +0800 Subject: [PATCH] Add capability for FileTagModel to fetch tags Signed-off-by: Claudio Cambra --- src/gui/filetagmodel.cpp | 43 ++++++++++++++++++++++++++++++++++++++++ src/gui/filetagmodel.h | 6 ++++++ 2 files changed, 49 insertions(+) diff --git a/src/gui/filetagmodel.cpp b/src/gui/filetagmodel.cpp index eaa11f197..c94f1cfef 100644 --- a/src/gui/filetagmodel.cpp +++ b/src/gui/filetagmodel.cpp @@ -16,6 +16,8 @@ #include "libsync/networkjobs.h" +Q_LOGGING_CATEGORY(lcFileTagModel, "nextcloud.gui.filetagmodel", QtInfoMsg) + namespace OCC { FileTagModel::FileTagModel(const QString &serverRelativePath, @@ -25,6 +27,7 @@ FileTagModel::FileTagModel(const QString &serverRelativePath, , _serverRelativePath(serverRelativePath) , _account(account) { + fetchFileTags(); } int FileTagModel::rowCount(const QModelIndex &parent) const @@ -45,4 +48,44 @@ QVariant FileTagModel::data(const QModelIndex &index, int role) const // FIXME: Implement me! return QVariant(); } + +void FileTagModel::fetchFileTags() +{ + if (!_account || _serverRelativePath.isEmpty()) { + qCDebug(lcFileTagModel) << "Cannot fetch filetags as account is null, or server relative path is empty"; + return; + } + + qCDebug(lcFileTagModel) << "Starting fetch of filetags for file at:" << _serverRelativePath; + + const auto propfindJob = new PropfindJob(_account, _serverRelativePath, this); + propfindJob->setProperties({ QByteArrayLiteral("http://nextcloud.org/ns:tags") }); + + connect(propfindJob, &PropfindJob::result, this, &FileTagModel::processFileTagRequestFinished); + connect(propfindJob, &PropfindJob::finishedWithError, this, &FileTagModel::processFileTagRequestFinishedWithError); + + propfindJob->start(); +} + +void FileTagModel::processFileTagRequestFinished(const QVariantMap &result) +{ + if (result.empty()) { + qCDebug(lcFileTagModel) << "File tag fetch request finished successfully, but received empty results..." + << _serverRelativePath; + return; + } + + qCDebug(lcFileTagModel) << "File tag fetch request finished successfully, processing results..." + << _serverRelativePath; + + beginResetModel(); + _tags = result.value(QStringLiteral("tags")).toStringList(); + endResetModel(); +} + +void FileTagModel::processFileTagRequestFinishedWithError() +{ + qCWarning(lcFileTagModel) << "File tag fetch request job ended with error."; +} + } diff --git a/src/gui/filetagmodel.h b/src/gui/filetagmodel.h index a18022eb9..3808ba65d 100644 --- a/src/gui/filetagmodel.h +++ b/src/gui/filetagmodel.h @@ -32,9 +32,15 @@ public: [[nodiscard]] QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; +private slots: + void fetchFileTags(); + void processFileTagRequestFinished(const QVariantMap &result); + void processFileTagRequestFinishedWithError(); + private: QString _serverRelativePath; AccountPtr _account; + QStringList _tags; }; } -- 2.30.2