mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-26 15:06:08 +03:00
Add capability for FileTagModel to fetch tags
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:
parent
84c8392491
commit
9cc241bf96
2 changed files with 49 additions and 0 deletions
|
@ -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.";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue