| 1 | /**************************************************************************** | 
|---|
| 2 | ** | 
|---|
| 3 | ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). | 
|---|
| 4 | ** Contact: Qt Software Information (qt-info@nokia.com) | 
|---|
| 5 | ** | 
|---|
| 6 | ** This file is part of the QtGui module of the Qt Toolkit. | 
|---|
| 7 | ** | 
|---|
| 8 | ** $QT_BEGIN_LICENSE:LGPL$ | 
|---|
| 9 | ** Commercial Usage | 
|---|
| 10 | ** Licensees holding valid Qt Commercial licenses may use this file in | 
|---|
| 11 | ** accordance with the Qt Commercial License Agreement provided with the | 
|---|
| 12 | ** Software or, alternatively, in accordance with the terms contained in | 
|---|
| 13 | ** a written agreement between you and Nokia. | 
|---|
| 14 | ** | 
|---|
| 15 | ** GNU Lesser General Public License Usage | 
|---|
| 16 | ** Alternatively, this file may be used under the terms of the GNU Lesser | 
|---|
| 17 | ** General Public License version 2.1 as published by the Free Software | 
|---|
| 18 | ** Foundation and appearing in the file LICENSE.LGPL included in the | 
|---|
| 19 | ** packaging of this file.  Please review the following information to | 
|---|
| 20 | ** ensure the GNU Lesser General Public License version 2.1 requirements | 
|---|
| 21 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. | 
|---|
| 22 | ** | 
|---|
| 23 | ** In addition, as a special exception, Nokia gives you certain | 
|---|
| 24 | ** additional rights. These rights are described in the Nokia Qt LGPL | 
|---|
| 25 | ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this | 
|---|
| 26 | ** package. | 
|---|
| 27 | ** | 
|---|
| 28 | ** GNU General Public License Usage | 
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU | 
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software | 
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the | 
|---|
| 32 | ** packaging of this file.  Please review the following information to | 
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be | 
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html. | 
|---|
| 35 | ** | 
|---|
| 36 | ** If you are unsure which license is appropriate for your use, please | 
|---|
| 37 | ** contact the sales department at qt-sales@nokia.com. | 
|---|
| 38 | ** $QT_END_LICENSE$ | 
|---|
| 39 | ** | 
|---|
| 40 | ****************************************************************************/ | 
|---|
| 41 |  | 
|---|
| 42 | #ifndef QFILESYSTEMMODEL_H | 
|---|
| 43 | #define QFILESYSTEMMODEL_H | 
|---|
| 44 |  | 
|---|
| 45 | #include <QtCore/qabstractitemmodel.h> | 
|---|
| 46 | #include <QtCore/qpair.h> | 
|---|
| 47 | #include <QtCore/qdir.h> | 
|---|
| 48 | #include <QtGui/qicon.h> | 
|---|
| 49 | #include <QtCore/qdiriterator.h> | 
|---|
| 50 |  | 
|---|
| 51 | QT_BEGIN_HEADER | 
|---|
| 52 |  | 
|---|
| 53 | QT_BEGIN_NAMESPACE | 
|---|
| 54 |  | 
|---|
| 55 | QT_MODULE(Gui) | 
|---|
| 56 |  | 
|---|
| 57 | #ifndef QT_NO_FILESYSTEMMODEL | 
|---|
| 58 |  | 
|---|
| 59 | class ExtendedInformation; | 
|---|
| 60 | class QFileSystemModelPrivate; | 
|---|
| 61 | class QFileIconProvider; | 
|---|
| 62 |  | 
|---|
| 63 | class Q_GUI_EXPORT QFileSystemModel : public QAbstractItemModel | 
|---|
| 64 | { | 
|---|
| 65 | Q_OBJECT | 
|---|
| 66 | Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks) | 
|---|
| 67 | Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly) | 
|---|
| 68 | Q_PROPERTY(bool nameFilterDisables READ nameFilterDisables WRITE setNameFilterDisables) | 
|---|
| 69 |  | 
|---|
| 70 | Q_SIGNALS: | 
|---|
| 71 | void rootPathChanged(const QString &newPath); | 
|---|
| 72 | void fileRenamed(const QString &path, const QString &oldName, const QString &newName); | 
|---|
| 73 |  | 
|---|
| 74 | public: | 
|---|
| 75 | enum Roles { | 
|---|
| 76 | FileIconRole = Qt::DecorationRole, | 
|---|
| 77 | FilePathRole = Qt::UserRole + 1, | 
|---|
| 78 | FileNameRole = Qt::UserRole + 2, | 
|---|
| 79 | FilePermissions = Qt::UserRole + 3 | 
|---|
| 80 | }; | 
|---|
| 81 |  | 
|---|
| 82 | explicit QFileSystemModel(QObject *parent = 0); | 
|---|
| 83 | ~QFileSystemModel(); | 
|---|
| 84 |  | 
|---|
| 85 | QModelIndex index(int row, int column, const QModelIndex &parent = QModelIndex()) const; | 
|---|
| 86 | QModelIndex index(const QString &path, int column = 0) const; | 
|---|
| 87 | QModelIndex parent(const QModelIndex &child) const; | 
|---|
| 88 | bool hasChildren(const QModelIndex &parent = QModelIndex()) const; | 
|---|
| 89 | bool canFetchMore(const QModelIndex &parent) const; | 
|---|
| 90 | void fetchMore(const QModelIndex &parent); | 
|---|
| 91 |  | 
|---|
| 92 | int rowCount(const QModelIndex &parent = QModelIndex()) const; | 
|---|
| 93 | int columnCount(const QModelIndex &parent = QModelIndex()) const; | 
|---|
| 94 |  | 
|---|
| 95 | QVariant myComputer(int role = Qt::DisplayRole) const; | 
|---|
| 96 | QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const; | 
|---|
| 97 | bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole); | 
|---|
| 98 |  | 
|---|
| 99 | QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const; | 
|---|
| 100 |  | 
|---|
| 101 | Qt::ItemFlags flags(const QModelIndex &index) const; | 
|---|
| 102 |  | 
|---|
| 103 | void sort(int column, Qt::SortOrder order = Qt::AscendingOrder); | 
|---|
| 104 |  | 
|---|
| 105 | QStringList mimeTypes() const; | 
|---|
| 106 | QMimeData *mimeData(const QModelIndexList &indexes) const; | 
|---|
| 107 | bool dropMimeData(const QMimeData *data, Qt::DropAction action, | 
|---|
| 108 | int row, int column, const QModelIndex &parent); | 
|---|
| 109 | Qt::DropActions supportedDropActions() const; | 
|---|
| 110 |  | 
|---|
| 111 | // QFileSystemModel specific API | 
|---|
| 112 | QModelIndex setRootPath(const QString &path); | 
|---|
| 113 | QString rootPath() const; | 
|---|
| 114 | QDir rootDirectory() const; | 
|---|
| 115 |  | 
|---|
| 116 | void setIconProvider(QFileIconProvider *provider); | 
|---|
| 117 | QFileIconProvider *iconProvider() const; | 
|---|
| 118 |  | 
|---|
| 119 | void setFilter(QDir::Filters filters); | 
|---|
| 120 | QDir::Filters filter() const; | 
|---|
| 121 |  | 
|---|
| 122 | void setResolveSymlinks(bool enable); | 
|---|
| 123 | bool resolveSymlinks() const; | 
|---|
| 124 |  | 
|---|
| 125 | void setReadOnly(bool enable); | 
|---|
| 126 | bool isReadOnly() const; | 
|---|
| 127 |  | 
|---|
| 128 | void setNameFilterDisables(bool enable); | 
|---|
| 129 | bool nameFilterDisables() const; | 
|---|
| 130 |  | 
|---|
| 131 | void setNameFilters(const QStringList &filters); | 
|---|
| 132 | QStringList nameFilters() const; | 
|---|
| 133 |  | 
|---|
| 134 | QString filePath(const QModelIndex &index) const; | 
|---|
| 135 | bool isDir(const QModelIndex &index) const; | 
|---|
| 136 | qint64 size(const QModelIndex &index) const; | 
|---|
| 137 | QString type(const QModelIndex &index) const; | 
|---|
| 138 | QDateTime lastModified(const QModelIndex &index) const; | 
|---|
| 139 |  | 
|---|
| 140 | QModelIndex mkdir(const QModelIndex &parent, const QString &name); | 
|---|
| 141 | inline bool rmdir(const QModelIndex &index) const; | 
|---|
| 142 | inline QString fileName(const QModelIndex &index) const; | 
|---|
| 143 | inline QIcon fileIcon(const QModelIndex &index) const; | 
|---|
| 144 | QFile::Permissions permissions(const QModelIndex &index) const; | 
|---|
| 145 | inline QFileInfo fileInfo(const QModelIndex &index) const; | 
|---|
| 146 | bool remove(const QModelIndex &index) const; | 
|---|
| 147 |  | 
|---|
| 148 | protected: | 
|---|
| 149 | QFileSystemModel(QFileSystemModelPrivate &, QObject *parent = 0); | 
|---|
| 150 | void timerEvent(QTimerEvent *event); | 
|---|
| 151 | bool event(QEvent *event); | 
|---|
| 152 |  | 
|---|
| 153 | private: | 
|---|
| 154 | Q_DECLARE_PRIVATE(QFileSystemModel) | 
|---|
| 155 | Q_DISABLE_COPY(QFileSystemModel) | 
|---|
| 156 |  | 
|---|
| 157 | Q_PRIVATE_SLOT(d_func(), void _q_directoryChanged(const QString &directory, const QStringList &list)) | 
|---|
| 158 | Q_PRIVATE_SLOT(d_func(), void _q_performDelayedSort()) | 
|---|
| 159 | Q_PRIVATE_SLOT(d_func(), void _q_fileSystemChanged(const QString &path, const QList<QPair<QString, QFileInfo> > &)) | 
|---|
| 160 | Q_PRIVATE_SLOT(d_func(), void _q_resolvedName(const QString &fileName, const QString &resolvedName)) | 
|---|
| 161 | }; | 
|---|
| 162 |  | 
|---|
| 163 | inline bool QFileSystemModel::rmdir(const QModelIndex &aindex) const | 
|---|
| 164 | { QDir dir; return dir.rmdir(filePath(aindex)); } | 
|---|
| 165 | inline QString QFileSystemModel::fileName(const QModelIndex &aindex) const | 
|---|
| 166 | { return aindex.data(Qt::DisplayRole).toString(); } | 
|---|
| 167 | inline QIcon QFileSystemModel::fileIcon(const QModelIndex &aindex) const | 
|---|
| 168 | { return qvariant_cast<QIcon>(aindex.data(Qt::DecorationRole)); } | 
|---|
| 169 | inline QFileInfo QFileSystemModel::fileInfo(const QModelIndex &aindex) const | 
|---|
| 170 | { return QFileInfo(filePath(aindex)); } | 
|---|
| 171 |  | 
|---|
| 172 | #endif // QT_NO_FILESYSTEMMODEL | 
|---|
| 173 |  | 
|---|
| 174 | QT_END_NAMESPACE | 
|---|
| 175 |  | 
|---|
| 176 | QT_END_HEADER | 
|---|
| 177 |  | 
|---|
| 178 | #endif // QFILESYSTEMMODEL_H | 
|---|
| 179 |  | 
|---|