From e70cb285acf53516b20c02ba167a801157576395 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Tue, 2 Sep 2025 18:40:31 +1000 Subject: internal: use FileSystemModel for FileDialog --- plugin/src/Caelestia/filesystemmodel.hpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'plugin') diff --git a/plugin/src/Caelestia/filesystemmodel.hpp b/plugin/src/Caelestia/filesystemmodel.hpp index f30850d..fdcd6c1 100644 --- a/plugin/src/Caelestia/filesystemmodel.hpp +++ b/plugin/src/Caelestia/filesystemmodel.hpp @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -18,22 +19,27 @@ class FileSystemEntry : public QObject { Q_PROPERTY(QString relativePath READ relativePath CONSTANT) Q_PROPERTY(QString name READ name CONSTANT) Q_PROPERTY(QString parentDir READ parentDir CONSTANT) + Q_PROPERTY(QString suffix READ suffix CONSTANT) Q_PROPERTY(qint64 size READ size CONSTANT) Q_PROPERTY(bool isDir READ isDir CONSTANT) Q_PROPERTY(bool isImage READ isImage CONSTANT) + Q_PROPERTY(QString mimeType READ mimeType CONSTANT) public: explicit FileSystemEntry(const QString& path, const QString& relativePath, QObject* parent = nullptr) : QObject(parent) , m_fileInfo(QFileInfo(path)) , m_path(path) - , m_relativePath(relativePath) {} + , m_relativePath(relativePath) + , m_isImageInitialised(false) + , m_mimeTypeInitialised(false) {} QString path() const { return m_path; }; QString relativePath() const { return m_relativePath; }; QString name() const { return m_fileInfo.fileName(); }; QString parentDir() const { return m_fileInfo.absolutePath(); }; + QString suffix() const { return m_fileInfo.completeSuffix(); }; qint64 size() const { return m_fileInfo.size(); }; bool isDir() const { return m_fileInfo.isDir(); }; @@ -46,6 +52,15 @@ public: return m_isImage; } + QString mimeType() { + if (!m_mimeTypeInitialised) { + const QMimeDatabase db; + m_mimeType = db.mimeTypeForFile(m_path).name(); + m_mimeTypeInitialised = true; + } + return m_mimeType; + } + private: const QFileInfo m_fileInfo; @@ -54,6 +69,9 @@ private: bool m_isImage; bool m_isImageInitialised; + + QString m_mimeType; + bool m_mimeTypeInitialised; }; class FileSystemModel : public QAbstractListModel { @@ -79,7 +97,7 @@ public: explicit FileSystemModel(QObject* parent = nullptr) : QAbstractListModel(parent) - , m_recursive(true) + , m_recursive(false) , m_watchChanges(true) , m_showHidden(false) , m_filter(NoFilter) { -- cgit v1.2.3-freya