Zrythm v2.0.0-DEV
a highly automated and intuitive digital audio workstation
Loading...
Searching...
No Matches
file_system_model.h
1// SPDX-FileCopyrightText: © 2025 Alexandros Theodotou <alex@zrythm.org>
2/* SPDX-License-Identifier: LicenseRef-ZrythmLicense */
3
4#pragma once
5
6#include <QFileSystemModel>
7#include <QMimeDatabase>
8#include <QMimeType>
9#include <QtQmlIntegration/qqmlintegration.h>
10
11namespace zrythm::gui
12{
13class FileSystemModel : public QFileSystemModel
14{
15 Q_OBJECT
16 Q_PROPERTY (
17 QModelIndex rootIndex READ rootIndex WRITE setRootIndex NOTIFY
18 rootIndexChanged)
19 QML_ELEMENT
20
21public:
22 explicit FileSystemModel (QObject * parent = nullptr);
23
24 enum Roles
25 {
26 FileSizeRole = Qt::UserRole + 1
27 };
28
29 Q_INVOKABLE static bool isDir (const QFileInfo * fileInfo)
30 {
31 return fileInfo->isDir ();
32 }
33
34 Q_INVOKABLE QMimeType getFileMimeType (const QString &filePath) const;
35 Q_INVOKABLE QString getFileInfoAsString (const QString &filePath) const;
36
37 QModelIndex rootIndex () const { return root_index_; }
38 void setRootIndex (const QModelIndex &index);
39 Q_SIGNAL void rootIndexChanged ();
40
41 int columnCount (const QModelIndex &parent) const override;
42 QVariant data (const QModelIndex &index, int role) const override;
43 QHash<int, QByteArray> roleNames () const override;
44
45private:
46 QModelIndex root_index_;
47 const QMimeDatabase mime_db_;
48};
49}