Update to 5.0.0-beta1
[profile/ivi/qtdeclarative.git] / src / imports / folderlistmodel / qquickfolderlistmodel.h
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the examples of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #ifndef QQUICKFOLDERLISTMODEL_H
43 #define QQUICKFOLDERLISTMODEL_H
44
45 #include <qqml.h>
46 #include <QStringList>
47 #include <QUrl>
48 #include <QAbstractListModel>
49
50 QT_BEGIN_HEADER
51
52 QT_BEGIN_NAMESPACE
53
54
55 class QQmlContext;
56 class QModelIndex;
57
58 class QQuickFolderListModelPrivate;
59
60 //![class begin]
61 class QQuickFolderListModel : public QAbstractListModel, public QQmlParserStatus
62 {
63     Q_OBJECT
64     Q_INTERFACES(QQmlParserStatus)
65 //![class begin]
66
67 //![class props]
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)
79 //![class props]
80
81 //![abslistmodel]
82 public:
83     QQuickFolderListModel(QObject *parent = 0);
84     ~QQuickFolderListModel();
85
86     enum Roles {
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
95     };
96
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;
101 //![abslistmodel]
102
103 //![count]
104     int count() const { return rowCount(QModelIndex()); }
105 //![count]
106
107 //![prop funcs]
108     QUrl folder() const;
109     void setFolder(const QUrl &folder);
110     QUrl rootFolder() const;
111     void setRootFolder(const QUrl &path);
112
113     QUrl parentFolder() const;
114
115     QStringList nameFilters() const;
116     void setNameFilters(const QStringList &filters);
117
118     enum SortField { Unsorted, Name, Time, Size, Type };
119     SortField sortField() const;
120     void setSortField(SortField field);
121     Q_ENUMS(SortField)
122
123     bool sortReversed() const;
124     void setSortReversed(bool rev);
125
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);
134 //![prop funcs]
135
136     Q_INVOKABLE bool isFolder(int index) const;
137     Q_INVOKABLE QVariant get(int idx, const QString &property) const;
138
139 //![parserstatus]
140     virtual void classBegin();
141     virtual void componentComplete();
142 //![parserstatus]
143
144     int roleFromString(const QString &roleName) const;
145
146 //![notifier]
147 Q_SIGNALS:
148     void folderChanged();
149     void rowCountChanged() const;
150 //![notifier]
151
152 //![class end]
153
154
155 private:
156     Q_DISABLE_COPY(QQuickFolderListModel)
157     Q_DECLARE_PRIVATE(QQuickFolderListModel)
158     QScopedPointer<QQuickFolderListModelPrivate> d_ptr;
159
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))
163 };
164 //![class end]
165
166 QT_END_NAMESPACE
167
168 QT_END_HEADER
169
170 #endif // QQUICKFOLDERLISTMODEL_H