1 | /****************************************************************************
|
---|
2 | **
|
---|
3 | ** Copyright (C) 2011 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 | ** Commercial Usage
|
---|
11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
---|
12 | ** accordance with the Qt Commercial License Agreement provided with the
|
---|
13 | ** Software or, alternatively, in accordance with the terms contained in
|
---|
14 | ** a written agreement between you and Nokia.
|
---|
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 | ** 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 have questions regarding the use of this file, please contact
|
---|
37 | ** Nokia at qt-info@nokia.com.
|
---|
38 | ** $QT_END_LICENSE$
|
---|
39 | **
|
---|
40 | ****************************************************************************/
|
---|
41 |
|
---|
42 | #ifndef QFILEDIALOG_P_H
|
---|
43 | #define QFILEDIALOG_P_H
|
---|
44 |
|
---|
45 | //
|
---|
46 | // W A R N I N G
|
---|
47 | // -------------
|
---|
48 | //
|
---|
49 | // This file is not part of the Qt API. It exists purely as an
|
---|
50 | // implementation detail. This header file may change from version to
|
---|
51 | // version without notice, or even be removed.
|
---|
52 | //
|
---|
53 | // We mean it.
|
---|
54 | //
|
---|
55 |
|
---|
56 | #ifndef QT_NO_FILEDIALOG
|
---|
57 |
|
---|
58 | #include "qfiledialog.h"
|
---|
59 | #include "private/qdialog_p.h"
|
---|
60 | #include "qplatformdefs.h"
|
---|
61 |
|
---|
62 | #include "qfilesystemmodel_p.h"
|
---|
63 | #include <qlistview.h>
|
---|
64 | #include <qtreeview.h>
|
---|
65 | #include <qcombobox.h>
|
---|
66 | #include <qtoolbutton.h>
|
---|
67 | #include <qlabel.h>
|
---|
68 | #include <qevent.h>
|
---|
69 | #include <qlineedit.h>
|
---|
70 | #include <qurl.h>
|
---|
71 | #include <qstackedwidget.h>
|
---|
72 | #include <qdialogbuttonbox.h>
|
---|
73 | #include <qabstractproxymodel.h>
|
---|
74 | #include <qcompleter.h>
|
---|
75 | #include <qpointer.h>
|
---|
76 | #include <qdebug.h>
|
---|
77 | #include "qsidebar_p.h"
|
---|
78 | #include "qfscompleter_p.h"
|
---|
79 | #include "private/qguiplatformplugin_p.h"
|
---|
80 |
|
---|
81 |
|
---|
82 | #if defined (Q_OS_UNIX)
|
---|
83 | #include <unistd.h>
|
---|
84 | #endif
|
---|
85 |
|
---|
86 | QT_BEGIN_NAMESPACE
|
---|
87 |
|
---|
88 | class QFileDialogListView;
|
---|
89 | class QFileDialogTreeView;
|
---|
90 | class QFileDialogLineEdit;
|
---|
91 | class QGridLayout;
|
---|
92 | class QCompleter;
|
---|
93 | class QHBoxLayout;
|
---|
94 | class Ui_QFileDialog;
|
---|
95 |
|
---|
96 |
|
---|
97 | struct QFileDialogArgs
|
---|
98 | {
|
---|
99 | QFileDialogArgs() : parent(0), mode(QFileDialog::AnyFile) {}
|
---|
100 |
|
---|
101 | QWidget *parent;
|
---|
102 | QString caption;
|
---|
103 | QString directory;
|
---|
104 | QString selection;
|
---|
105 | QString filter;
|
---|
106 | QFileDialog::FileMode mode;
|
---|
107 | QFileDialog::Options options;
|
---|
108 | };
|
---|
109 |
|
---|
110 | #define UrlRole (Qt::UserRole + 1)
|
---|
111 |
|
---|
112 | class Q_AUTOTEST_EXPORT QFileDialogPrivate : public QDialogPrivate
|
---|
113 | {
|
---|
114 | Q_DECLARE_PUBLIC(QFileDialog)
|
---|
115 |
|
---|
116 | public:
|
---|
117 | QFileDialogPrivate();
|
---|
118 |
|
---|
119 | void createToolButtons();
|
---|
120 | void createMenuActions();
|
---|
121 | void createWidgets();
|
---|
122 |
|
---|
123 | void init(const QString &directory = QString(), const QString &nameFilter = QString(),
|
---|
124 | const QString &caption = QString());
|
---|
125 | bool itemViewKeyboardEvent(QKeyEvent *event);
|
---|
126 | QString getEnvironmentVariable(const QString &string);
|
---|
127 | static QString workingDirectory(const QString &path);
|
---|
128 | static QString initialSelection(const QString &path);
|
---|
129 | QStringList typedFiles() const;
|
---|
130 | QStringList addDefaultSuffixToFiles(const QStringList filesToFix) const;
|
---|
131 | bool removeDirectory(const QString &path);
|
---|
132 |
|
---|
133 | inline QModelIndex mapToSource(const QModelIndex &index) const;
|
---|
134 | inline QModelIndex mapFromSource(const QModelIndex &index) const;
|
---|
135 | inline QModelIndex rootIndex() const;
|
---|
136 | inline void setRootIndex(const QModelIndex &index) const;
|
---|
137 | inline QModelIndex select(const QModelIndex &index) const;
|
---|
138 | inline QString rootPath() const;
|
---|
139 |
|
---|
140 | QLineEdit *lineEdit() const;
|
---|
141 |
|
---|
142 | int maxNameLength(const QString &path) {
|
---|
143 | #if defined(Q_OS_UNIX)
|
---|
144 | return ::pathconf(QFile::encodeName(path).data(), _PC_NAME_MAX);
|
---|
145 | #elif defined(Q_OS_WIN)
|
---|
146 | #ifndef Q_OS_WINCE
|
---|
147 | DWORD maxLength;
|
---|
148 | QString drive = path.left(3);
|
---|
149 | if (::GetVolumeInformation(reinterpret_cast<const wchar_t *>(drive.utf16()), NULL, 0, NULL, &maxLength, NULL, NULL, 0) == FALSE)
|
---|
150 | return -1;
|
---|
151 | return maxLength;
|
---|
152 | #else
|
---|
153 | Q_UNUSED(path);
|
---|
154 | return MAX_PATH;
|
---|
155 | #endif //Q_OS_WINCE
|
---|
156 | #elif defined(Q_OS_OS2)
|
---|
157 | Q_UNUSED(path);
|
---|
158 | return CCHMAXPATH;
|
---|
159 | #else
|
---|
160 | Q_UNUSED(path);
|
---|
161 | #endif
|
---|
162 | return -1;
|
---|
163 | }
|
---|
164 |
|
---|
165 | QString basename(const QString &path) const
|
---|
166 | {
|
---|
167 | int separator = QDir::toNativeSeparators(path).lastIndexOf(QDir::separator());
|
---|
168 | if (separator != -1)
|
---|
169 | return path.mid(separator + 1);
|
---|
170 | return path;
|
---|
171 | }
|
---|
172 |
|
---|
173 | QDir::Filters filterForMode(QDir::Filters filters) const
|
---|
174 | {
|
---|
175 | if (fileMode == QFileDialog::DirectoryOnly) {
|
---|
176 | filters |= QDir::Drives | QDir::AllDirs | QDir::Dirs;
|
---|
177 | filters &= ~QDir::Files;
|
---|
178 | } else {
|
---|
179 | filters |= QDir::Drives | QDir::AllDirs | QDir::Files | QDir::Dirs;
|
---|
180 | }
|
---|
181 | return filters;
|
---|
182 | }
|
---|
183 |
|
---|
184 | QAbstractItemView *currentView() const;
|
---|
185 |
|
---|
186 | static inline QString toInternal(const QString &path)
|
---|
187 | {
|
---|
188 | #if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN)
|
---|
189 | QString n(path);
|
---|
190 | for (int i = 0; i < (int)n.length(); ++i)
|
---|
191 | if (n[i] == QLatin1Char('\\')) n[i] = QLatin1Char('/');
|
---|
192 | #if defined(Q_OS_WINCE)
|
---|
193 | if ((n.size() > 1) && (n.startsWith(QLatin1String("//"))))
|
---|
194 | n = n.mid(1);
|
---|
195 | #endif
|
---|
196 | return n;
|
---|
197 | #else // the compile should optimize away this
|
---|
198 | return path;
|
---|
199 | #endif
|
---|
200 | }
|
---|
201 |
|
---|
202 | void setLastVisitedDirectory(const QString &dir);
|
---|
203 | void retranslateWindowTitle();
|
---|
204 | void retranslateStrings();
|
---|
205 | void emitFilesSelected(const QStringList &files);
|
---|
206 |
|
---|
207 | void _q_goHome();
|
---|
208 | void _q_pathChanged(const QString &);
|
---|
209 | void _q_navigateBackward();
|
---|
210 | void _q_navigateForward();
|
---|
211 | void _q_navigateToParent();
|
---|
212 | void _q_createDirectory();
|
---|
213 | void _q_showListView();
|
---|
214 | void _q_showDetailsView();
|
---|
215 | void _q_showContextMenu(const QPoint &position);
|
---|
216 | void _q_renameCurrent();
|
---|
217 | void _q_deleteCurrent();
|
---|
218 | void _q_showHidden();
|
---|
219 | void _q_showHeader(QAction *);
|
---|
220 | void _q_updateOkButton();
|
---|
221 | void _q_currentChanged(const QModelIndex &index);
|
---|
222 | void _q_enterDirectory(const QModelIndex &index);
|
---|
223 | void _q_goToDirectory(const QString &);
|
---|
224 | void _q_useNameFilter(int index);
|
---|
225 | void _q_selectionChanged();
|
---|
226 | void _q_goToUrl(const QUrl &url);
|
---|
227 | void _q_autoCompleteFileName(const QString &);
|
---|
228 | void _q_rowsInserted(const QModelIndex & parent);
|
---|
229 | void _q_fileRenamed(const QString &path, const QString oldName, const QString newName);
|
---|
230 |
|
---|
231 | // layout
|
---|
232 | #ifndef QT_NO_PROXYMODEL
|
---|
233 | QAbstractProxyModel *proxyModel;
|
---|
234 | #endif
|
---|
235 |
|
---|
236 | // data
|
---|
237 | QStringList watching;
|
---|
238 | QFileSystemModel *model;
|
---|
239 |
|
---|
240 | #ifndef QT_NO_FSCOMPLETER
|
---|
241 | QFSCompleter *completer;
|
---|
242 | #endif //QT_NO_FSCOMPLETER
|
---|
243 |
|
---|
244 | QFileDialog::FileMode fileMode;
|
---|
245 | QFileDialog::AcceptMode acceptMode;
|
---|
246 | bool confirmOverwrite;
|
---|
247 | QString defaultSuffix;
|
---|
248 | QString setWindowTitle;
|
---|
249 |
|
---|
250 | QStringList currentHistory;
|
---|
251 | int currentHistoryLocation;
|
---|
252 |
|
---|
253 | QAction *renameAction;
|
---|
254 | QAction *deleteAction;
|
---|
255 | QAction *showHiddenAction;
|
---|
256 | QAction *newFolderAction;
|
---|
257 |
|
---|
258 | bool useDefaultCaption;
|
---|
259 | bool defaultFileTypes;
|
---|
260 | bool fileNameLabelExplicitlySat;
|
---|
261 | QStringList nameFilters;
|
---|
262 |
|
---|
263 | // Members for using native dialogs:
|
---|
264 | bool nativeDialogInUse;
|
---|
265 | // setVisible_sys returns true if it ends up showing a native
|
---|
266 | // dialog. Returning false means that a non-native dialog must be
|
---|
267 | // used instead.
|
---|
268 | bool canBeNativeDialog();
|
---|
269 | bool setVisible_sys(bool visible);
|
---|
270 | void deleteNativeDialog_sys();
|
---|
271 | QDialog::DialogCode dialogResultCode_sys();
|
---|
272 |
|
---|
273 | void setDirectory_sys(const QString &directory);
|
---|
274 | QString directory_sys() const;
|
---|
275 | void selectFile_sys(const QString &filename);
|
---|
276 | QStringList selectedFiles_sys() const;
|
---|
277 | void setFilter_sys();
|
---|
278 | void setNameFilters_sys(const QStringList &filters);
|
---|
279 | void selectNameFilter_sys(const QString &filter);
|
---|
280 | QString selectedNameFilter_sys() const;
|
---|
281 | //////////////////////////////////////////////
|
---|
282 |
|
---|
283 | #if defined(Q_WS_MAC)
|
---|
284 | void *mDelegate;
|
---|
285 | #ifndef QT_MAC_USE_COCOA
|
---|
286 | NavDialogRef mDialog;
|
---|
287 | bool mDialogStarted;
|
---|
288 | bool mDialogClosed;
|
---|
289 | QString mCurrentLocation;
|
---|
290 | QString mCurrentSelection;
|
---|
291 | QStringList mCurrentSelectionList;
|
---|
292 |
|
---|
293 | struct QtMacFilterName {
|
---|
294 | QString description;
|
---|
295 | QString regexp;
|
---|
296 | QString filter;
|
---|
297 | };
|
---|
298 | struct QtMacNavFilterInfo {
|
---|
299 | QtMacNavFilterInfo() : currentSelection(-1) {}
|
---|
300 | int currentSelection;
|
---|
301 | QList<QtMacFilterName> filters;
|
---|
302 | } filterInfo;
|
---|
303 |
|
---|
304 | static void qt_mac_filedialog_event_proc(const NavEventCallbackMessage msg, NavCBRecPtr p,
|
---|
305 | NavCallBackUserData data);
|
---|
306 | static Boolean qt_mac_filedialog_filter_proc(AEDesc *theItem, void *info, void *data,
|
---|
307 | NavFilterModes);
|
---|
308 | bool showCarbonNavServicesDialog();
|
---|
309 | bool hideCarbonNavServicesDialog();
|
---|
310 | void createNavServicesDialog();
|
---|
311 | #else
|
---|
312 | bool showCocoaFilePanel();
|
---|
313 | bool hideCocoaFilePanel();
|
---|
314 | #endif
|
---|
315 | void createNSOpenSavePanelDelegate();
|
---|
316 | void QNSOpenSavePanelDelegate_selectionChanged(const QString &newPath);
|
---|
317 | void QNSOpenSavePanelDelegate_panelClosed(bool accepted);
|
---|
318 | void QNSOpenSavePanelDelegate_directoryEntered(const QString &newDir);
|
---|
319 | void QNSOpenSavePanelDelegate_filterSelected(int menuIndex);
|
---|
320 | void _q_macRunNativeAppModalPanel();
|
---|
321 | void mac_nativeDialogModalHelp();
|
---|
322 | #endif
|
---|
323 |
|
---|
324 | QScopedPointer<Ui_QFileDialog> qFileDialogUi;
|
---|
325 |
|
---|
326 | QString acceptLabel;
|
---|
327 |
|
---|
328 | QPointer<QObject> receiverToDisconnectOnClose;
|
---|
329 | QByteArray memberToDisconnectOnClose;
|
---|
330 | QByteArray signalToDisconnectOnClose;
|
---|
331 |
|
---|
332 | QFileDialog::Options opts;
|
---|
333 |
|
---|
334 | ~QFileDialogPrivate();
|
---|
335 |
|
---|
336 | private:
|
---|
337 | Q_DISABLE_COPY(QFileDialogPrivate)
|
---|
338 | };
|
---|
339 |
|
---|
340 | class QFileDialogLineEdit : public QLineEdit
|
---|
341 | {
|
---|
342 | public:
|
---|
343 | QFileDialogLineEdit(QWidget *parent = 0) : QLineEdit(parent), hideOnEsc(false), d_ptr(0){}
|
---|
344 | void init(QFileDialogPrivate *d_pointer) {d_ptr = d_pointer; }
|
---|
345 | void keyPressEvent(QKeyEvent *e);
|
---|
346 | bool hideOnEsc;
|
---|
347 | private:
|
---|
348 | QFileDialogPrivate *d_ptr;
|
---|
349 | };
|
---|
350 |
|
---|
351 | class QFileDialogComboBox : public QComboBox
|
---|
352 | {
|
---|
353 | public:
|
---|
354 | QFileDialogComboBox(QWidget *parent = 0) : QComboBox(parent), urlModel(0) {}
|
---|
355 | void init(QFileDialogPrivate *d_pointer);
|
---|
356 | void showPopup();
|
---|
357 | void setHistory(const QStringList &paths);
|
---|
358 | QStringList history() const { return m_history; }
|
---|
359 | void paintEvent(QPaintEvent *);
|
---|
360 |
|
---|
361 | private:
|
---|
362 | QUrlModel *urlModel;
|
---|
363 | QFileDialogPrivate *d_ptr;
|
---|
364 | QStringList m_history;
|
---|
365 | };
|
---|
366 |
|
---|
367 | class QFileDialogListView : public QListView
|
---|
368 | {
|
---|
369 | public:
|
---|
370 | QFileDialogListView(QWidget *parent = 0);
|
---|
371 | void init(QFileDialogPrivate *d_pointer);
|
---|
372 | QSize sizeHint() const;
|
---|
373 | protected:
|
---|
374 | void keyPressEvent(QKeyEvent *e);
|
---|
375 | private:
|
---|
376 | QFileDialogPrivate *d_ptr;
|
---|
377 | };
|
---|
378 |
|
---|
379 | class QFileDialogTreeView : public QTreeView
|
---|
380 | {
|
---|
381 | public:
|
---|
382 | QFileDialogTreeView(QWidget *parent);
|
---|
383 | void init(QFileDialogPrivate *d_pointer);
|
---|
384 | QSize sizeHint() const;
|
---|
385 |
|
---|
386 | protected:
|
---|
387 | void keyPressEvent(QKeyEvent *e);
|
---|
388 | private:
|
---|
389 | QFileDialogPrivate *d_ptr;
|
---|
390 | };
|
---|
391 |
|
---|
392 | inline QModelIndex QFileDialogPrivate::mapToSource(const QModelIndex &index) const {
|
---|
393 | #ifdef QT_NO_PROXYMODEL
|
---|
394 | return index;
|
---|
395 | #else
|
---|
396 | return proxyModel ? proxyModel->mapToSource(index) : index;
|
---|
397 | #endif
|
---|
398 | }
|
---|
399 | inline QModelIndex QFileDialogPrivate::mapFromSource(const QModelIndex &index) const {
|
---|
400 | #ifdef QT_NO_PROXYMODEL
|
---|
401 | return index;
|
---|
402 | #else
|
---|
403 | return proxyModel ? proxyModel->mapFromSource(index) : index;
|
---|
404 | #endif
|
---|
405 | }
|
---|
406 |
|
---|
407 | inline QString QFileDialogPrivate::rootPath() const {
|
---|
408 | return model->rootPath();
|
---|
409 | }
|
---|
410 |
|
---|
411 | #ifndef Q_WS_MAC
|
---|
412 | // Dummies for platforms that don't use native dialogs:
|
---|
413 | inline void QFileDialogPrivate::deleteNativeDialog_sys() { qt_guiPlatformPlugin()->fileDialogDelete(q_func()); }
|
---|
414 | inline bool QFileDialogPrivate::setVisible_sys(bool visible) { return qt_guiPlatformPlugin()->fileDialogSetVisible(q_func(), visible); }
|
---|
415 | inline QDialog::DialogCode QFileDialogPrivate::dialogResultCode_sys(){ return qt_guiPlatformPlugin()->fileDialogResultCode(q_func()); }
|
---|
416 | inline void QFileDialogPrivate::setDirectory_sys(const QString &directory) { qt_guiPlatformPlugin()->fileDialogSetDirectory(q_func(), directory); }
|
---|
417 | inline QString QFileDialogPrivate::directory_sys() const { return qt_guiPlatformPlugin()->fileDialogDirectory(q_func()); }
|
---|
418 | inline void QFileDialogPrivate::selectFile_sys(const QString &filename) { qt_guiPlatformPlugin()->fileDialogSelectFile(q_func(), filename); }
|
---|
419 | inline QStringList QFileDialogPrivate::selectedFiles_sys() const { return qt_guiPlatformPlugin()->fileDialogSelectedFiles(q_func()); }
|
---|
420 | inline void QFileDialogPrivate::setFilter_sys() { qt_guiPlatformPlugin()->fileDialogSetFilter(q_func()); }
|
---|
421 | inline void QFileDialogPrivate::setNameFilters_sys(const QStringList &filters) { qt_guiPlatformPlugin()->fileDialogSetNameFilters(q_func(), filters); }
|
---|
422 | inline void QFileDialogPrivate::selectNameFilter_sys(const QString &filter) { qt_guiPlatformPlugin()->fileDialogSelectNameFilter(q_func(), filter); }
|
---|
423 | inline QString QFileDialogPrivate::selectedNameFilter_sys() const { return qt_guiPlatformPlugin()->fileDialogSelectedNameFilter(q_func()); }
|
---|
424 | #endif
|
---|
425 |
|
---|
426 | QT_END_NAMESPACE
|
---|
427 |
|
---|
428 | #endif // QT_NO_FILEDIALOG
|
---|
429 |
|
---|
430 | #endif // QFILEDIALOG_P_H
|
---|