1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the examples of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #ifndef QQUICKFOLDERLISTMODEL_H
43 #define QQUICKFOLDERLISTMODEL_H
46 #include <QStringList>
48 #include <QAbstractListModel>
58 class QQuickFolderListModelPrivate;
61 class QQuickFolderListModel : public QAbstractListModel, public QQmlParserStatus
64 Q_INTERFACES(QQmlParserStatus)
68 Q_PROPERTY(QUrl folder READ folder WRITE setFolder NOTIFY folderChanged)
69 Q_PROPERTY(QUrl rootFolder READ rootFolder WRITE setRootFolder)
70 Q_PROPERTY(QUrl parentFolder READ parentFolder NOTIFY folderChanged)
71 Q_PROPERTY(QStringList nameFilters READ nameFilters WRITE setNameFilters)
72 Q_PROPERTY(SortField sortField READ sortField WRITE setSortField)
73 Q_PROPERTY(bool sortReversed READ sortReversed WRITE setSortReversed)
74 Q_PROPERTY(bool showDirs READ showDirs WRITE setShowDirs)
75 Q_PROPERTY(bool showDirsFirst READ showDirsFirst WRITE setShowDirsFirst)
76 Q_PROPERTY(bool showDotAndDotDot READ showDotAndDotDot WRITE setShowDotAndDotDot)
77 Q_PROPERTY(bool showOnlyReadable READ showOnlyReadable WRITE setShowOnlyReadable)
78 Q_PROPERTY(int count READ count NOTIFY rowCountChanged)
83 QQuickFolderListModel(QObject *parent = 0);
84 ~QQuickFolderListModel();
87 FileNameRole = Qt::UserRole + 1,
88 FilePathRole = Qt::UserRole + 2,
89 FileBaseNameRole = Qt::UserRole + 3,
90 FileSuffixRole = Qt::UserRole + 4,
91 FileSizeRole = Qt::UserRole + 5,
92 FileLastModifiedRole = Qt::UserRole + 6,
93 FileLastReadRole = Qt::UserRole +7,
94 FileIsDirRole = Qt::UserRole + 8
97 virtual int rowCount(const QModelIndex &parent = QModelIndex()) const;
98 virtual QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const;
99 virtual QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
100 virtual QHash<int, QByteArray> roleNames() const;
104 int count() const { return rowCount(QModelIndex()); }
109 void setFolder(const QUrl &folder);
110 QUrl rootFolder() const;
111 void setRootFolder(const QUrl &path);
113 QUrl parentFolder() const;
115 QStringList nameFilters() const;
116 void setNameFilters(const QStringList &filters);
118 enum SortField { Unsorted, Name, Time, Size, Type };
119 SortField sortField() const;
120 void setSortField(SortField field);
123 bool sortReversed() const;
124 void setSortReversed(bool rev);
126 bool showDirs() const;
127 void setShowDirs(bool showDirs);
128 bool showDirsFirst() const;
129 void setShowDirsFirst(bool showDirsFirst);
130 bool showDotAndDotDot() const;
131 void setShowDotAndDotDot(bool on);
132 bool showOnlyReadable() const;
133 void setShowOnlyReadable(bool on);
136 Q_INVOKABLE bool isFolder(int index) const;
137 Q_INVOKABLE QVariant get(int idx, const QString &property) const;
140 virtual void classBegin();
141 virtual void componentComplete();
144 int roleFromString(const QString &roleName) const;
148 void folderChanged();
149 void rowCountChanged() const;
156 Q_DISABLE_COPY(QQuickFolderListModel)
157 Q_DECLARE_PRIVATE(QQuickFolderListModel)
158 QScopedPointer<QQuickFolderListModelPrivate> d_ptr;
160 Q_PRIVATE_SLOT(d_func(), void _q_directoryChanged(const QString &directory, const QList<FileProperty> &list))
161 Q_PRIVATE_SLOT(d_func(), void _q_directoryUpdated(const QString &directory, const QList<FileProperty> &list, int fromIndex, int toIndex))
162 Q_PRIVATE_SLOT(d_func(), void _q_sortFinished(const QList<FileProperty> &list))
170 #endif // QQUICKFOLDERLISTMODEL_H