src/gui/dialogs/qfilesystemmodel.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    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     friend class QFileDialogPrivate;
       
   163 };
       
   164 
       
   165 inline bool QFileSystemModel::rmdir(const QModelIndex &aindex) const
       
   166 { QDir dir; return dir.rmdir(filePath(aindex)); }
       
   167 inline QString QFileSystemModel::fileName(const QModelIndex &aindex) const
       
   168 { return aindex.data(Qt::DisplayRole).toString(); }
       
   169 inline QIcon QFileSystemModel::fileIcon(const QModelIndex &aindex) const
       
   170 { return qvariant_cast<QIcon>(aindex.data(Qt::DecorationRole)); }
       
   171 inline QFileInfo QFileSystemModel::fileInfo(const QModelIndex &aindex) const
       
   172 { return QFileInfo(filePath(aindex)); }
       
   173 
       
   174 #endif // QT_NO_FILESYSTEMMODEL
       
   175 
       
   176 QT_END_NAMESPACE
       
   177 
       
   178 QT_END_HEADER
       
   179 
       
   180 #endif // QFILESYSTEMMODEL_H
       
   181