| 1 | // Copyright (C) 2016 The Qt Company Ltd. |
| 2 | // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only |
| 3 | |
| 4 | #ifndef QQUICKFOLDERLISTMODEL_P_H |
| 5 | #define QQUICKFOLDERLISTMODEL_P_H |
| 6 | |
| 7 | // |
| 8 | // W A R N I N G |
| 9 | // ------------- |
| 10 | // |
| 11 | // This file is not part of the Qt API. It exists purely as an |
| 12 | // implementation detail. This header file may change from version to |
| 13 | // version without notice, or even be removed. |
| 14 | // |
| 15 | // We mean it. |
| 16 | // |
| 17 | |
| 18 | #include "qquickfolderlistmodelglobal_p.h" |
| 19 | |
| 20 | #include <QtQml/qqml.h> |
| 21 | #include <QStringList> |
| 22 | #include <QUrl> |
| 23 | #include <QAbstractListModel> |
| 24 | |
| 25 | QT_BEGIN_NAMESPACE |
| 26 | |
| 27 | |
| 28 | class QQmlContext; |
| 29 | class QModelIndex; |
| 30 | |
| 31 | class QQuickFolderListModelPrivate; |
| 32 | |
| 33 | //![class begin] |
| 34 | class Q_LABSFOLDERLISTMODEL_EXPORT QQuickFolderListModel : public QAbstractListModel, public QQmlParserStatus |
| 35 | { |
| 36 | Q_OBJECT |
| 37 | Q_INTERFACES(QQmlParserStatus) |
| 38 | //![class begin] |
| 39 | |
| 40 | //![class props] |
| 41 | Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged FINAL) |
| 42 | Q_PROPERTY(QUrl rootFolder READ rootFolder WRITE setRootFolder FINAL) |
| 43 | Q_PROPERTY(QUrl parentFolder READ parentFolder NOTIFY folderChanged FINAL) |
| 44 | Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters FINAL) |
| 45 | Q_PROPERTY(SortField sortField READ sortField WRITE setSortField FINAL) |
| 46 | Q_PROPERTY(bool sortReversed READ sortReversed WRITE setSortReversed FINAL) |
| 47 | Q_PROPERTY(bool showFiles READ showFiles WRITE setShowFiles REVISION(2, 1) FINAL) |
| 48 | Q_PROPERTY(bool showDirs READ showDirs WRITE setShowDirs FINAL) |
| 49 | Q_PROPERTY(bool showDirsFirst READ showDirsFirst WRITE setShowDirsFirst FINAL) |
| 50 | Q_PROPERTY(bool showDotAndDotDot READ showDotAndDotDot WRITE setShowDotAndDotDot FINAL) |
| 51 | Q_PROPERTY(bool showHidden READ showHidden WRITE setShowHidden REVISION(2, 1) FINAL) |
| 52 | Q_PROPERTY(bool showOnlyReadable READ showOnlyReadable WRITE setShowOnlyReadable FINAL) |
| 53 | Q_PROPERTY(bool caseSensitive READ caseSensitive WRITE setCaseSensitive REVISION(2, 2) FINAL) |
| 54 | Q_PROPERTY(int count READ count NOTIFY countChanged FINAL) |
| 55 | Q_PROPERTY(Status status READ status NOTIFY statusChanged REVISION(2, 11) FINAL) |
| 56 | Q_PROPERTY(bool sortCaseSensitive READ sortCaseSensitive WRITE setSortCaseSensitive REVISION(2, 12) FINAL) |
| 57 | //![class props] |
| 58 | |
| 59 | QML_NAMED_ELEMENT(FolderListModel) |
| 60 | QML_ADDED_IN_VERSION(1, 0) |
| 61 | //![abslistmodel] |
| 62 | public: |
| 63 | QQuickFolderListModel(QObject *parent = nullptr); |
| 64 | ~QQuickFolderListModel(); |
| 65 | |
| 66 | enum Roles { |
| 67 | FileNameRole = Qt::UserRole + 1, |
| 68 | FilePathRole = Qt::UserRole + 2, |
| 69 | FileBaseNameRole = Qt::UserRole + 3, |
| 70 | FileSuffixRole = Qt::UserRole + 4, |
| 71 | FileSizeRole = Qt::UserRole + 5, |
| 72 | FileLastModifiedRole = Qt::UserRole + 6, |
| 73 | FileLastReadRole = Qt::UserRole +7, |
| 74 | FileIsDirRole = Qt::UserRole + 8, |
| 75 | FileUrlRole = Qt::UserRole + 9, |
| 76 | FileURLRole = Qt::UserRole + 10 |
| 77 | }; |
| 78 | |
| 79 | int rowCount(const QModelIndex &parent = QModelIndex()) const override; |
| 80 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const override; |
| 81 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const override; |
| 82 | QHash<int, QByteArray> roleNames() const override; |
| 83 | //![abslistmodel] |
| 84 | |
| 85 | //![count] |
| 86 | int count() const { return rowCount(parent: QModelIndex()); } |
| 87 | //![count] |
| 88 | |
| 89 | //![prop funcs] |
| 90 | QUrl folder() const; |
| 91 | void setFolder(const QUrl &folder); |
| 92 | QUrl rootFolder() const; |
| 93 | void setRootFolder(const QUrl &path); |
| 94 | |
| 95 | QUrl parentFolder() const; |
| 96 | |
| 97 | QStringList nameFilters() const; |
| 98 | void setNameFilters(const QStringList &filters); |
| 99 | |
| 100 | enum SortField { Unsorted, Name, Time, Size, Type }; |
| 101 | Q_ENUM(SortField) |
| 102 | SortField sortField() const; |
| 103 | void setSortField(SortField field); |
| 104 | |
| 105 | bool sortReversed() const; |
| 106 | void setSortReversed(bool rev); |
| 107 | |
| 108 | bool showFiles() const; |
| 109 | void setShowFiles(bool showFiles); |
| 110 | bool showDirs() const; |
| 111 | void setShowDirs(bool showDirs); |
| 112 | bool showDirsFirst() const; |
| 113 | void setShowDirsFirst(bool showDirsFirst); |
| 114 | bool showDotAndDotDot() const; |
| 115 | void setShowDotAndDotDot(bool on); |
| 116 | bool showHidden() const; |
| 117 | void setShowHidden(bool on); |
| 118 | bool showOnlyReadable() const; |
| 119 | void setShowOnlyReadable(bool on); |
| 120 | bool caseSensitive() const; |
| 121 | void setCaseSensitive(bool on); |
| 122 | |
| 123 | enum Status { Null, Ready, Loading }; |
| 124 | Q_ENUM(Status) |
| 125 | Status status() const; |
| 126 | bool sortCaseSensitive() const; |
| 127 | void setSortCaseSensitive(bool on); |
| 128 | //![prop funcs] |
| 129 | |
| 130 | Q_INVOKABLE bool isFolder(int index) const; |
| 131 | Q_INVOKABLE QVariant get(int idx, const QString &property) const; |
| 132 | Q_INVOKABLE int indexOf(const QUrl &file) const; |
| 133 | |
| 134 | //![parserstatus] |
| 135 | void classBegin() override; |
| 136 | void componentComplete() override; |
| 137 | //![parserstatus] |
| 138 | |
| 139 | int roleFromString(const QString &roleName) const; |
| 140 | |
| 141 | //![notifier] |
| 142 | Q_SIGNALS: |
| 143 | void folderChanged(); |
| 144 | void rowCountChanged() const; |
| 145 | Q_REVISION(2, 1) void countChanged() const; |
| 146 | Q_REVISION(2, 11) void statusChanged(); |
| 147 | //![notifier] |
| 148 | |
| 149 | //![class end] |
| 150 | |
| 151 | |
| 152 | private: |
| 153 | Q_DISABLE_COPY(QQuickFolderListModel) |
| 154 | Q_DECLARE_PRIVATE(QQuickFolderListModel) |
| 155 | QScopedPointer<QQuickFolderListModelPrivate> d_ptr; |
| 156 | |
| 157 | Q_PRIVATE_SLOT(d_func(), void _q_directoryChanged(const QString &directory, const QList<FileProperty> &list)) |
| 158 | Q_PRIVATE_SLOT(d_func(), void _q_directoryUpdated(const QString &directory, const QList<FileProperty> &list, int fromIndex, int toIndex)) |
| 159 | Q_PRIVATE_SLOT(d_func(), void _q_sortFinished(const QList<FileProperty> &list)) |
| 160 | Q_PRIVATE_SLOT(d_func(), void _q_statusChanged(QQuickFolderListModel::Status s)) |
| 161 | }; |
| 162 | //![class end] |
| 163 | |
| 164 | QT_END_NAMESPACE |
| 165 | |
| 166 | #endif // QQUICKFOLDERLISTMODEL_P_H |
| 167 | |