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.filedialog;
15 extern(C++):
16 
17 import qt.config;
18 import qt.core.abstractproxymodel;
19 import qt.core.bytearray;
20 import qt.core.coreevent;
21 import qt.core.dir;
22 import qt.core.flags;
23 import qt.core.list;
24 import qt.core.namespace;
25 import qt.core.object;
26 import qt.core.string;
27 import qt.core.stringlist;
28 import qt.core.url;
29 import qt.helpers;
30 import qt.widgets.abstractitemdelegate;
31 import qt.widgets.dialog;
32 import qt.widgets.fileiconprovider;
33 import qt.widgets.widget;
34 
35 /+ QT_REQUIRE_CONFIG(filedialog);
36 
37 
38 class QModelIndex;
39 class QItemSelection; +/
40 struct QFileDialogArgs;
41 /+ class QFileIconProvider; +/
42 extern(C++, class) struct QFileDialogPrivate;
43 /+ class QAbstractItemDelegate;
44 class QAbstractProxyModel; +/
45 
46 class /+ Q_WIDGETS_EXPORT +/ QFileDialog : QDialog
47 {
48     mixin(Q_OBJECT);
49     /+ Q_PROPERTY(ViewMode viewMode READ viewMode WRITE setViewMode)
50     Q_PROPERTY(FileMode fileMode READ fileMode WRITE setFileMode)
51     Q_PROPERTY(AcceptMode acceptMode READ acceptMode WRITE setAcceptMode)
52     Q_PROPERTY(QString defaultSuffix READ defaultSuffix WRITE setDefaultSuffix)
53 #if QT_DEPRECATED_SINCE(5, 13)
54     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly DESIGNABLE false)
55     Q_PROPERTY(bool confirmOverwrite READ confirmOverwrite WRITE setConfirmOverwrite DESIGNABLE false)
56     Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks DESIGNABLE false)
57     Q_PROPERTY(bool nameFilterDetailsVisible READ isNameFilterDetailsVisible
58                WRITE setNameFilterDetailsVisible DESIGNABLE false)
59 #endif
60     Q_PROPERTY(Options options READ options WRITE setOptions)
61     Q_PROPERTY(QStringList supportedSchemes READ supportedSchemes WRITE setSupportedSchemes) +/
62 
63 public:
64     enum ViewMode { Detail, List }
65     /+ Q_ENUM(ViewMode) +/
66     enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles,
67                     DirectoryOnly /+ Q_DECL_ENUMERATOR_DEPRECATED_X("Use setOption(ShowDirsOnly, true) instead") +/}
68     /+ Q_ENUM(FileMode) +/
69     enum AcceptMode { AcceptOpen, AcceptSave }
70     /+ Q_ENUM(AcceptMode) +/
71     enum DialogLabel { LookIn, FileName, FileType, Accept, Reject }
72 
73     enum Option
74     {
75         ShowDirsOnly                = 0x00000001,
76         DontResolveSymlinks         = 0x00000002,
77         DontConfirmOverwrite        = 0x00000004,
78 /+ #if QT_DEPRECATED_SINCE(5, 14) +/
79         DontUseSheet /+ Q_DECL_ENUMERATOR_DEPRECATED +/ = 0x00000008,
80 /+ #endif +/
81         DontUseNativeDialog         = 0x00000010,
82         ReadOnly                    = 0x00000020,
83         HideNameFilterDetails       = 0x00000040,
84         DontUseCustomDirectoryIcons = 0x00000080
85     }
86     /+ Q_ENUM(Option) +/
87     /+ Q_DECLARE_FLAGS(Options, Option) +/
88 alias Options = QFlags!(Option);    /+ Q_FLAG(Options) +/
89 
90     this(QWidget parent, /+ Qt:: +/qt.core.namespace.WindowFlags f);
91     /+ explicit +/this(QWidget parent = null,
92                              ref const(QString) caption = globalInitVar!QString,
93                              ref const(QString) directory = globalInitVar!QString,
94                              ref const(QString) filter = globalInitVar!QString);
95     ~this();
96 
97     final void setDirectory(ref const(QString) directory);
98     pragma(inline, true) final void setDirectory(ref const(QDir) adirectory)
99     { auto tmp = adirectory.absolutePath(); setDirectory(tmp); }
100     final QDir directory() const;
101 
102     final void setDirectoryUrl(ref const(QUrl) directory);
103     final QUrl directoryUrl() const;
104 
105     final void selectFile(ref const(QString) filename);
106     final QStringList selectedFiles() const;
107 
108     final void selectUrl(ref const(QUrl) url);
109     final QList!(QUrl) selectedUrls() const;
110 
111 /+ #if QT_DEPRECATED_SINCE(5, 13) +/
112     /+ QT_DEPRECATED_X("Use setOption(HideNameFilterDetails, !enabled) instead") +/
113         final void setNameFilterDetailsVisible(bool enabled);
114     /+ QT_DEPRECATED_X("Use !testOption(HideNameFilterDetails) instead") +/
115         final bool isNameFilterDetailsVisible() const;
116 /+ #endif +/
117 
118     final void setNameFilter(ref const(QString) filter);
119     final void setNameFilters(ref const(QStringList) filters);
120     final QStringList nameFilters() const;
121     final void selectNameFilter(ref const(QString) filter);
122     final QString selectedMimeTypeFilter() const;
123     final QString selectedNameFilter() const;
124 
125 /+ #if QT_CONFIG(mimetype) +/
126     final void setMimeTypeFilters(ref const(QStringList) filters);
127     final QStringList mimeTypeFilters() const;
128     final void selectMimeTypeFilter(ref const(QString) filter);
129 /+ #endif +/
130 
131     final QDir.Filters filter() const;
132     final void setFilter(QDir.Filters filters);
133 
134     final void setViewMode(ViewMode mode);
135     final ViewMode viewMode() const;
136 
137     final void setFileMode(FileMode mode);
138     final FileMode fileMode() const;
139 
140     final void setAcceptMode(AcceptMode mode);
141     final AcceptMode acceptMode() const;
142 
143 /+ #if QT_DEPRECATED_SINCE(5, 13) +/
144     final void setReadOnly(bool enabled);
145     final bool isReadOnly() const;
146 
147     /+ QT_DEPRECATED_X("Use setOption(DontResolveSymlinks, !enabled) instead") +/
148         final void setResolveSymlinks(bool enabled);
149     /+ QT_DEPRECATED_X("Use !testOption(DontResolveSymlinks) instead") +/
150         final bool resolveSymlinks() const;
151 /+ #endif +/
152 
153     final void setSidebarUrls(ref const(QList!(QUrl)) urls);
154     final QList!(QUrl) sidebarUrls() const;
155 
156     final QByteArray saveState() const;
157     final bool restoreState(ref const(QByteArray) state);
158 
159 /+ #if QT_DEPRECATED_SINCE(5, 13) +/
160     /+ QT_DEPRECATED_X("Use setOption(DontConfirmOverwrite, !enabled) instead") +/
161         final void setConfirmOverwrite(bool enabled);
162     /+ QT_DEPRECATED_X("Use !testOption(DontConfirmOverwrite) instead") +/
163         final bool confirmOverwrite() const;
164 /+ #endif +/
165 
166     final void setDefaultSuffix(ref const(QString) suffix);
167     final QString defaultSuffix() const;
168 
169     final void setHistory(ref const(QStringList) paths);
170     final QStringList history() const;
171 
172     final void setItemDelegate(QAbstractItemDelegate delegate_);
173     final QAbstractItemDelegate itemDelegate() const;
174 
175     final void setIconProvider(QFileIconProvider provider);
176     final QFileIconProvider iconProvider() const;
177 
178     final void setLabelText(DialogLabel label, ref const(QString) text);
179     final QString labelText(DialogLabel label) const;
180 
181     final void setSupportedSchemes(ref const(QStringList) schemes);
182     final QStringList supportedSchemes() const;
183 
184 /+ #if QT_CONFIG(proxymodel) +/
185     final void setProxyModel(QAbstractProxyModel model);
186     final QAbstractProxyModel proxyModel() const;
187 /+ #endif +/
188 
189     final void setOption(Option option, bool on = true);
190     final bool testOption(Option option) const;
191     final void setOptions(Options options);
192     final Options options() const;
193 
194     /+ using QDialog::open; +/
195     final void open(QObject receiver, const(char)* member);
196     override void setVisible(bool visible);
197 
198 /+ Q_SIGNALS +/public:
199     @QSignal final void fileSelected(ref const(QString) file);
200     @QSignal final void filesSelected(ref const(QStringList) files);
201     @QSignal final void currentChanged(ref const(QString) path);
202     @QSignal final void directoryEntered(ref const(QString) directory);
203 
204     @QSignal final void urlSelected(ref const(QUrl) url);
205     @QSignal final void urlsSelected(ref const(QList!(QUrl)) urls);
206     @QSignal final void currentUrlChanged(ref const(QUrl) url);
207     @QSignal final void directoryUrlEntered(ref const(QUrl) directory);
208 
209     @QSignal final void filterSelected(ref const(QString) filter);
210 
211 public:
212 
213     static QString getOpenFileName(QWidget parent = null,
214                                        ref const(QString) caption = globalInitVar!QString,
215                                        ref const(QString) dir = globalInitVar!QString,
216                                        ref const(QString) filter = globalInitVar!QString,
217                                        QString* selectedFilter = null,
218                                        Options options = Options());
219 
220     static QUrl getOpenFileUrl(QWidget parent = null,
221                                    ref const(QString) caption = globalInitVar!QString,
222                                    ref const(QUrl) dir = globalInitVar!QUrl,
223                                    ref const(QString) filter = globalInitVar!QString,
224                                    QString* selectedFilter = null,
225                                    Options options = Options(),
226                                    ref const(QStringList) supportedSchemes = globalInitVar!QStringList);
227 
228     static QString getSaveFileName(QWidget parent = null,
229                                        ref const(QString) caption = globalInitVar!QString,
230                                        ref const(QString) dir = globalInitVar!QString,
231                                        ref const(QString) filter = globalInitVar!QString,
232                                        QString* selectedFilter = null,
233                                        Options options = Options());
234 
235     static QUrl getSaveFileUrl(QWidget parent = null,
236                                    ref const(QString) caption = globalInitVar!QString,
237                                    ref const(QUrl) dir = globalInitVar!QUrl,
238                                    ref const(QString) filter = globalInitVar!QString,
239                                    QString* selectedFilter = null,
240                                    Options options = Options(),
241                                    ref const(QStringList) supportedSchemes = globalInitVar!QStringList);
242 
243     static QString getExistingDirectory(QWidget parent = null,
244                                             ref const(QString) caption = globalInitVar!QString,
245                                             ref const(QString) dir = globalInitVar!QString,
246                                             Options options = Option.ShowDirsOnly);
247 
248     static QUrl getExistingDirectoryUrl(QWidget parent = null,
249                                             ref const(QString) caption = globalInitVar!QString,
250                                             ref const(QUrl) dir = globalInitVar!QUrl,
251                                             Options options = Option.ShowDirsOnly,
252                                             ref const(QStringList) supportedSchemes = globalInitVar!QStringList);
253 
254     static QStringList getOpenFileNames(QWidget parent = null,
255                                             ref const(QString) caption = globalInitVar!QString,
256                                             ref const(QString) dir = globalInitVar!QString,
257                                             ref const(QString) filter = globalInitVar!QString,
258                                             QString* selectedFilter = null,
259                                             Options options = Options());
260 
261     static QList!(QUrl) getOpenFileUrls(QWidget parent = null,
262                                            ref const(QString) caption = globalInitVar!QString,
263                                            ref const(QUrl) dir = globalInitVar!QUrl,
264                                            ref const(QString) filter = globalInitVar!QString,
265                                            QString* selectedFilter = null,
266                                            Options options = Options(),
267                                            ref const(QStringList) supportedSchemes = globalInitVar!QStringList);
268 
269 /+    static void getOpenFileContent(ref const(QString) nameFilter,
270                                        ref const(/+ std:: +/function_!(ExternCPPFunc!(void function(ref const(QString) , ref const(QByteArray) )))) fileContentsReady);+/
271     static void saveFileContent(ref const(QByteArray) fileContent, ref const(QString) fileNameHint = globalInitVar!QString);
272 
273 protected:
274     this(ref const(QFileDialogArgs) args);
275     override void done(int result);
276     override void accept();
277     override void changeEvent(QEvent e);
278 
279 private:
280     /+ Q_DECLARE_PRIVATE(QFileDialog) +/
281     /+ Q_DISABLE_COPY(QFileDialog) +/
282 
283     /+ Q_PRIVATE_SLOT(d_func(), void _q_pathChanged(const QString &))
284 
285     Q_PRIVATE_SLOT(d_func(), void _q_navigateBackward())
286     Q_PRIVATE_SLOT(d_func(), void _q_navigateForward())
287     Q_PRIVATE_SLOT(d_func(), void _q_navigateToParent())
288     Q_PRIVATE_SLOT(d_func(), void _q_createDirectory())
289     Q_PRIVATE_SLOT(d_func(), void _q_showListView())
290     Q_PRIVATE_SLOT(d_func(), void _q_showDetailsView())
291     Q_PRIVATE_SLOT(d_func(), void _q_showContextMenu(const QPoint &))
292     Q_PRIVATE_SLOT(d_func(), void _q_renameCurrent())
293     Q_PRIVATE_SLOT(d_func(), void _q_deleteCurrent())
294     Q_PRIVATE_SLOT(d_func(), void _q_showHidden())
295     Q_PRIVATE_SLOT(d_func(), void _q_updateOkButton())
296     Q_PRIVATE_SLOT(d_func(), void _q_currentChanged(const QModelIndex &index))
297     Q_PRIVATE_SLOT(d_func(), void _q_enterDirectory(const QModelIndex &index))
298     Q_PRIVATE_SLOT(d_func(), void _q_emitUrlSelected(const QUrl &))
299     Q_PRIVATE_SLOT(d_func(), void _q_emitUrlsSelected(const QList<QUrl> &))
300     Q_PRIVATE_SLOT(d_func(), void _q_nativeCurrentChanged(const QUrl &))
301     Q_PRIVATE_SLOT(d_func(), void _q_nativeEnterDirectory(const QUrl&))
302     Q_PRIVATE_SLOT(d_func(), void _q_goToDirectory(const QString &path))
303     Q_PRIVATE_SLOT(d_func(), void _q_useNameFilter(int index))
304     Q_PRIVATE_SLOT(d_func(), void _q_selectionChanged())
305     Q_PRIVATE_SLOT(d_func(), void _q_goToUrl(const QUrl &url))
306     Q_PRIVATE_SLOT(d_func(), void _q_goHome())
307     Q_PRIVATE_SLOT(d_func(), void _q_showHeader(QAction *))
308     Q_PRIVATE_SLOT(d_func(), void _q_autoCompleteFileName(const QString &text))
309     Q_PRIVATE_SLOT(d_func(), void _q_rowsInserted(const QModelIndex & parent))
310     Q_PRIVATE_SLOT(d_func(), void _q_fileRenamed(const QString &path,
311                                                  const QString &oldName,
312                                                  const QString &newName)) +/
313     /+ friend class QPlatformDialogHelper; +/
314 }
315 /+pragma(inline, true) QFlags!(QFileDialog.Options.enum_type) operator |(QFileDialog.Options.enum_type f1, QFileDialog.Options.enum_type f2)/+noexcept+/{return QFlags!(QFileDialog.Options.enum_type)(f1)|f2;}+/
316 /+pragma(inline, true) QFlags!(QFileDialog.Options.enum_type) operator |(QFileDialog.Options.enum_type f1, QFlags!(QFileDialog.Options.enum_type) f2)/+noexcept+/{return f2|f1;}+/
317 /+pragma(inline, true) QIncompatibleFlag operator |(QFileDialog.Options.enum_type f1, int f2)/+noexcept+/{return QIncompatibleFlag(int(f1)|f2);}+/
318 
319 /+ Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDialog::Options) +/