1 /****************************************************************************
2 **
3 ** DQt - D bindings for the Qt Toolkit
4 **
5 ** GNU Lesser General Public License Usage
6 ** This file may be used under the terms of the GNU Lesser
7 ** General Public License version 3 as published by the Free Software
8 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
9 ** packaging of this file. Please review the following information to
10 ** ensure the GNU Lesser General Public License version 3 requirements
11 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
12 **
13 ****************************************************************************/
14 module qt.widgets.filesystemmodel;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.abstractitemmodel;
19 import qt.core.coreevent;
20 import qt.core.datetime;
21 import qt.core.dir;
22 import qt.core.file;
23 import qt.core.fileinfo;
24 import qt.core.flags;
25 import qt.core.global;
26 import qt.core.mimedata;
27 import qt.core.namespace;
28 import qt.core.object;
29 import qt.core.string;
30 import qt.core.stringlist;
31 import qt.core.variant;
32 import qt.gui.icon;
33 import qt.helpers;
34 import qt.widgets.fileiconprovider;
35 
36 /+ QT_REQUIRE_CONFIG(filesystemmodel); +/
37 
38 
39 extern(C++, class) struct ExtendedInformation;
40 extern(C++, class) struct QFileSystemModelPrivate;
41 /+ class QFileIconProvider; +/
42 
43 class /+ Q_WIDGETS_EXPORT +/ QFileSystemModel : QAbstractItemModel
44 {
45     mixin(Q_OBJECT);
46     /+ Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks)
47     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly)
48     Q_PROPERTY(bool nameFilterDisables READ nameFilterDisables WRITE setNameFilterDisables)
49     Q_PROPERTY(Options options READ options WRITE setOptions) +/
50 
51 /+ Q_SIGNALS +/public:
52     @QSignal final void rootPathChanged(ref const(QString) newPath);
53     @QSignal final void fileRenamed(ref const(QString) path, ref const(QString) oldName, ref const(QString) newName);
54     @QSignal final void directoryLoaded(ref const(QString) path);
55 
56 public:
57 /*    enum Roles {
58         FileIconRole = /+ Qt:: +/qt.core.namespace.ItemDataRole.DecorationRole,
59         FilePathRole = /+ Qt:: +/qt.core.namespace.ItemDataRole.UserRole + 1,
60         FileNameRole = /+ Qt:: +/qt.core.namespace.ItemDataRole.UserRole + 2,
61         FilePermissions = /+ Qt:: +/qt.core.namespace.ItemDataRole.UserRole + 3
62     }*/
63 
64     enum Option
65     {
66         DontWatchForChanges         = 0x00000001,
67         DontResolveSymlinks         = 0x00000002,
68         DontUseCustomDirectoryIcons = 0x00000004
69     }
70     /+ Q_ENUM(Option) +/
71     /+ Q_DECLARE_FLAGS(Options, Option) +/
72 alias Options = QFlags!(Option);
73     /+ explicit +/this(QObject parent = null);
74     ~this();
75 
76     override QModelIndex index(int row, int column, ref const(QModelIndex) parent = globalInitVar!QModelIndex) const;
77     final QModelIndex index(ref const(QString) path, int column = 0) const;
78     override QModelIndex parent(ref const(QModelIndex) child) const;
79     /+ using QObject::parent; +/
80     override QModelIndex sibling(int row, int column, ref const(QModelIndex) idx) const;
81     override bool hasChildren(ref const(QModelIndex) parent = globalInitVar!QModelIndex) const;
82     override bool canFetchMore(ref const(QModelIndex) parent) const;
83     override void fetchMore(ref const(QModelIndex) parent);
84 
85     override int rowCount(ref const(QModelIndex) parent = globalInitVar!QModelIndex) const;
86     override int columnCount(ref const(QModelIndex) parent = globalInitVar!QModelIndex) const;
87 
88     final QVariant myComputer(int role = /+ Qt:: +/qt.core.namespace.ItemDataRole.DisplayRole) const;
89     override QVariant data(ref const(QModelIndex) index, int role = /+ Qt:: +/qt.core.namespace.ItemDataRole.DisplayRole) const;
90     override bool setData(ref const(QModelIndex) index, ref const(QVariant) value, int role = /+ Qt:: +/qt.core.namespace.ItemDataRole.EditRole);
91 
92     override QVariant headerData(int section, /+ Qt:: +/qt.core.namespace.Orientation orientation, int role = /+ Qt:: +/qt.core.namespace.ItemDataRole.DisplayRole) const;
93 
94     override /+ Qt:: +/qt.core.namespace.ItemFlags flags(ref const(QModelIndex) index) const;
95 
96     override void sort(int column, /+ Qt:: +/qt.core.namespace.SortOrder order = /+ Qt:: +/qt.core.namespace.SortOrder.AscendingOrder);
97 
98     override QStringList mimeTypes() const;
99     override QMimeData mimeData(ref const(QModelIndexList) indexes) const;
100     override bool dropMimeData(const(QMimeData) data, /+ Qt:: +/qt.core.namespace.DropAction action,
101                           int row, int column, ref const(QModelIndex) parent);
102     override /+ Qt:: +/qt.core.namespace.DropActions supportedDropActions() const;
103 
104     // QFileSystemModel specific API
105     final QModelIndex setRootPath(ref const(QString) path);
106     final QString rootPath() const;
107     final QDir rootDirectory() const;
108 
109     final void setIconProvider(QFileIconProvider provider);
110     final QFileIconProvider iconProvider() const;
111 
112     final void setFilter(QDir.Filters filters);
113     final QDir.Filters filter() const;
114 
115     final void setResolveSymlinks(bool enable);
116     final bool resolveSymlinks() const;
117 
118     final void setReadOnly(bool enable);
119     final bool isReadOnly() const;
120 
121     final void setNameFilterDisables(bool enable);
122     final bool nameFilterDisables() const;
123 
124     final void setNameFilters(ref const(QStringList) filters);
125     final QStringList nameFilters() const;
126 
127     final void setOption(Option option, bool on = true);
128     final bool testOption(Option option) const;
129     final void setOptions(Options options);
130     final Options options() const;
131 
132     final QString filePath(ref const(QModelIndex) index) const;
133     final bool isDir(ref const(QModelIndex) index) const;
134     final qint64 size(ref const(QModelIndex) index) const;
135     final QString type(ref const(QModelIndex) index) const;
136     final QDateTime lastModified(ref const(QModelIndex) index) const;
137 
138     final QModelIndex mkdir(ref const(QModelIndex) parent, ref const(QString) name);
139     final bool rmdir(ref const(QModelIndex) index);
140     pragma(inline, true) final QString fileName(ref const(QModelIndex) aindex) const
141     { return aindex.data(/+ Qt:: +/qt.core.namespace.ItemDataRole.DisplayRole).toString(); }
142 /+    pragma(inline, true) final QIcon fileIcon(ref const(QModelIndex) aindex) const
143     { return qvariant_cast!(QIcon)(aindex.data(/+ Qt:: +/qt.core.namespace.ItemDataRole.DecorationRole)); }+/
144     final QFile.Permissions permissions(ref const(QModelIndex) index) const;
145     final QFileInfo fileInfo(ref const(QModelIndex) index) const;
146     final bool remove(ref const(QModelIndex) index);
147 
148 protected:
149     this(ref QFileSystemModelPrivate , QObject parent = null);
150     override void timerEvent(QTimerEvent event);
151     override 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 QVector<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 /+pragma(inline, true) QFlags!(QFileSystemModel.Options.enum_type) operator |(QFileSystemModel.Options.enum_type f1, QFileSystemModel.Options.enum_type f2)/+noexcept+/{return QFlags!(QFileSystemModel.Options.enum_type)(f1)|f2;}+/
165 /+pragma(inline, true) QFlags!(QFileSystemModel.Options.enum_type) operator |(QFileSystemModel.Options.enum_type f1, QFlags!(QFileSystemModel.Options.enum_type) f2)/+noexcept+/{return f2|f1;}+/
166 /+pragma(inline, true) QIncompatibleFlag operator |(QFileSystemModel.Options.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/
167 
168 /+ Q_DECLARE_OPERATORS_FOR_FLAGS(QFileSystemModel::Options) +/