Qt 4.8
qfiledialog_p.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
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 
87 
91 class QGridLayout;
92 class QCompleter;
93 class QHBoxLayout;
94 class Ui_QFileDialog;
95 
96 
98 {
99  QFileDialogArgs() : parent(0), mode(QFileDialog::AnyFile) {}
100 
107  QFileDialog::Options options;
108 };
109 
110 #define UrlRole (Qt::UserRole + 1)
111 
113 {
115 
116 public:
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 #else
157  Q_UNUSED(path);
158 #endif
159  return -1;
160  }
161 
162  QString basename(const QString &path) const
163  {
164  int separator = QDir::toNativeSeparators(path).lastIndexOf(QDir::separator());
165  if (separator != -1)
166  return path.mid(separator + 1);
167  return path;
168  }
169 
170  QDir::Filters filterForMode(QDir::Filters filters) const
171  {
172  if (fileMode == QFileDialog::DirectoryOnly) {
173  filters |= QDir::Drives | QDir::AllDirs | QDir::Dirs;
174  filters &= ~QDir::Files;
175  } else {
177  }
178  return filters;
179  }
180 
181  QAbstractItemView *currentView() const;
182 
183  static inline QString toInternal(const QString &path)
184  {
185 #if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX) || defined(Q_OS_SYMBIAN)
186  QString n(path);
187  for (int i = 0; i < (int)n.length(); ++i)
188  if (n[i] == QLatin1Char('\\')) n[i] = QLatin1Char('/');
189 #if defined(Q_OS_WINCE)
190  if ((n.size() > 1) && (n.startsWith(QLatin1String("//"))))
191  n = n.mid(1);
192 #endif
193  return n;
194 #else // the compile should optimize away this
195  return path;
196 #endif
197  }
198 
199  void setLastVisitedDirectory(const QString &dir);
200  void retranslateWindowTitle();
201  void retranslateStrings();
202  void emitFilesSelected(const QStringList &files);
203 
204  void _q_goHome();
205  void _q_pathChanged(const QString &);
206  void _q_navigateBackward();
207  void _q_navigateForward();
208  void _q_navigateToParent();
209  void _q_createDirectory();
210  void _q_showListView();
211  void _q_showDetailsView();
212  void _q_showContextMenu(const QPoint &position);
213  void _q_renameCurrent();
214  void _q_deleteCurrent();
215  void _q_showHidden();
216  void _q_showHeader(QAction *);
217  void _q_updateOkButton();
218  void _q_currentChanged(const QModelIndex &index);
219  void _q_enterDirectory(const QModelIndex &index);
220  void _q_goToDirectory(const QString &);
221  void _q_useNameFilter(int index);
222  void _q_selectionChanged();
223  void _q_goToUrl(const QUrl &url);
224  void _q_autoCompleteFileName(const QString &);
225  void _q_rowsInserted(const QModelIndex & parent);
226  void _q_fileRenamed(const QString &path, const QString oldName, const QString newName);
227 
228  // layout
229 #ifndef QT_NO_PROXYMODEL
231 #endif
232 
233  // data
236 
237 #ifndef QT_NO_FSCOMPLETER
239 #endif //QT_NO_FSCOMPLETER
240 
246 
249 
254 
259 
260  // Members for using native dialogs:
262  // setVisible_sys returns true if it ends up showing a native
263  // dialog. Returning false means that a non-native dialog must be
264  // used instead.
265  bool canBeNativeDialog();
266  bool setVisible_sys(bool visible);
267  void deleteNativeDialog_sys();
268  QDialog::DialogCode dialogResultCode_sys();
269 
270  void setDirectory_sys(const QString &directory);
271  QString directory_sys() const;
272  void selectFile_sys(const QString &filename);
273  QStringList selectedFiles_sys() const;
274  void setFilter_sys();
275  void setNameFilters_sys(const QStringList &filters);
276  void selectNameFilter_sys(const QString &filter);
277  QString selectedNameFilter_sys() const;
279 
280 #if defined(Q_WS_MAC)
281  void *mDelegate;
282 #ifndef QT_MAC_USE_COCOA
283  NavDialogRef mDialog;
289 
294  };
296  QtMacNavFilterInfo() : currentSelection(-1) {}
299  } filterInfo;
300 
301  static void qt_mac_filedialog_event_proc(const NavEventCallbackMessage msg, NavCBRecPtr p,
302  NavCallBackUserData data);
303  static Boolean qt_mac_filedialog_filter_proc(AEDesc *theItem, void *info, void *data,
304  NavFilterModes);
305  bool showCarbonNavServicesDialog();
306  bool hideCarbonNavServicesDialog();
307  void createNavServicesDialog();
308 #else
309  bool showCocoaFilePanel();
310  bool hideCocoaFilePanel();
311 #endif
312  void createNSOpenSavePanelDelegate();
313  void QNSOpenSavePanelDelegate_selectionChanged(const QString &newPath);
314  void QNSOpenSavePanelDelegate_panelClosed(bool accepted);
315  void QNSOpenSavePanelDelegate_directoryEntered(const QString &newDir);
316  void QNSOpenSavePanelDelegate_filterSelected(int menuIndex);
317  void _q_macRunNativeAppModalPanel();
318  void mac_nativeDialogModalHelp();
319 #endif
320 
322 
324 
328 
329  QFileDialog::Options opts;
330 
332 
333 private:
335 };
336 
338 {
339 public:
340  QFileDialogLineEdit(QWidget *parent = 0) : QLineEdit(parent), hideOnEsc(false), d_ptr(0){}
341  void init(QFileDialogPrivate *d_pointer) {d_ptr = d_pointer; }
342  void keyPressEvent(QKeyEvent *e);
343  bool hideOnEsc;
344 private:
346 };
347 
349 {
350 public:
352  void init(QFileDialogPrivate *d_pointer);
353  void showPopup();
354  void setHistory(const QStringList &paths);
355  QStringList history() const { return m_history; }
356  void paintEvent(QPaintEvent *);
357 
358 private:
362 };
363 
365 {
366 public:
368  void init(QFileDialogPrivate *d_pointer);
369  QSize sizeHint() const;
370 protected:
371  void keyPressEvent(QKeyEvent *e);
372 private:
374 };
375 
377 {
378 public:
380  void init(QFileDialogPrivate *d_pointer);
381  QSize sizeHint() const;
382 
383 protected:
384  void keyPressEvent(QKeyEvent *e);
385 private:
387 };
388 
390 #ifdef QT_NO_PROXYMODEL
391  return index;
392 #else
393  return proxyModel ? proxyModel->mapToSource(index) : index;
394 #endif
395 }
397 #ifdef QT_NO_PROXYMODEL
398  return index;
399 #else
400  return proxyModel ? proxyModel->mapFromSource(index) : index;
401 #endif
402 }
403 
405  return model->rootPath();
406 }
407 
408 #ifndef Q_WS_MAC
409  // Dummies for platforms that don't use native dialogs:
411  inline bool QFileDialogPrivate::setVisible_sys(bool visible) { return qt_guiPlatformPlugin()->fileDialogSetVisible(q_func(), visible); }
415  inline void QFileDialogPrivate::selectFile_sys(const QString &filename) { qt_guiPlatformPlugin()->fileDialogSelectFile(q_func(), filename); }
421 #endif
422 
424 
425 #endif // QT_NO_FILEDIALOG
426 
427 #endif // QFILEDIALOG_P_H
The QDir class provides access to directory structures and their contents.
Definition: qdir.h:58
QModelIndex mapFromSource(const QModelIndex &index) const
The QKeyEvent class describes a key event.
Definition: qevent.h:224
The QFileSystemModel class provides a data model for the local filesystem.
static mach_timebase_info_data_t info
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QFileDialogPrivate * d_ptr
QFileDialog::Options opts
EventRef event
QStringList watching
QDialog::DialogCode dialogResultCode_sys()
void init(QFileDialogPrivate *d_pointer)
QAbstractProxyModel * proxyModel
QByteArray memberToDisconnectOnClose
QFileDialog::FileMode mode
QFileDialog::AcceptMode acceptMode
void selectFile_sys(const QString &filename)
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
virtual QString fileDialogSelectedNameFilter(const QFileDialog *) const
static qreal position(QGraphicsObject *item, QDeclarativeAnchorLine::AnchorLine anchorLine)
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
int select(int, fd_set *, fd_set *, fd_set *, struct timeval *)
QDir::Filters filterForMode(QDir::Filters filters) const
virtual QString fileDialogDirectory(const QFileDialog *) const
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition: qstring.cpp:3734
The QCompleter class provides completions based on an item model.
Definition: qcompleter.h:64
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
QGuiPlatformPlugin * qt_guiPlatformPlugin()
Return (an construct if necesseray) the Gui Platform plugin.
virtual void fileDialogSetNameFilters(QFileDialog *, const QStringList &)
The QUrl class provides a convenient interface for working with URLs.
Definition: qurl.h:61
The QString class provides a Unicode character string.
Definition: qstring.h:83
static QChar separator()
Returns the native directory separator: "/" under Unix (including Mac OS X) and "\\" under Windows...
Definition: qdir.cpp:1831
QFileDialogPrivate * d_ptr
The QFileDialog class provides a dialog that allow users to select files or directories.
Definition: qfiledialog.h:66
QStringList mCurrentSelectionList
virtual bool fileDialogSetVisible(QFileDialog *, bool)
QAction * renameAction
QFileDialogComboBox(QWidget *parent=0)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
virtual QStringList fileDialogSelectedFiles(const QFileDialog *) const
QString left(int n) const Q_REQUIRED_RESULT
Returns a substring that contains the n leftmost characters of the string.
Definition: qstring.cpp:3664
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
static bool init
The QTreeView class provides a default model/view implementation of a tree view.
Definition: qtreeview.h:58
QList< QtMacFilterName > filters
The QStringList class provides a list of strings.
Definition: qstringlist.h:66
The QComboBox widget is a combined button and popup list.
Definition: qcombobox.h:62
QAction * newFolderAction
QString rootPath() const
static const char * data(const QByteArray &arr)
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
#define FALSE
Synonym for false.
Definition: qglobal.h:1019
QString directory_sys() const
QFileDialog::FileMode fileMode
void selectNameFilter_sys(const QString &filter)
QStringList nameFilters
QUrlModel * urlModel
QAction * showHiddenAction
NavDialogRef mDialog
QString selectedNameFilter_sys() const
QStringList selectedFiles_sys() const
QModelIndex mapToSource(const QModelIndex &index) const
The QAbstractProxyModel class provides a base class for proxy item models that can do sorting...
QString mid(int position, int n=-1) const Q_REQUIRED_RESULT
Returns a string that contains n characters of this string, starting at the specified position index...
Definition: qstring.cpp:3706
QWidget * parent
The QAbstractItemView class provides the basic functionality for item view classes.
static const char *const filters[3]
FileMode
This enum is used to indicate what the user may select in the file dialog; i.
Definition: qfiledialog.h:83
QFileDialog::Options options
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
The QListView class provides a list or icon view onto a model.
Definition: qlistview.h:57
QCompleter that can deal with QFileSystemModel.
virtual void fileDialogSelectNameFilter(QFileDialog *, const QString &)
QFSCompleter * completer
QByteArray signalToDisconnectOnClose
virtual void fileDialogSetFilter(QFileDialog *)
int lastIndexOf(QChar c, int from=-1, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Definition: qstring.cpp:3000
QString basename(const QString &path) const
QAction * deleteAction
QStringList history() const
The QPoint class defines a point in the plane using integer precision.
Definition: qpoint.h:53
The QGridLayout class lays out widgets in a grid.
Definition: qgridlayout.h:60
The QModelIndex class is used to locate data in a data model.
QStringList currentHistory
#define Q_AUTOTEST_EXPORT
Definition: qglobal.h:1510
The QHBoxLayout class lines up widgets horizontally.
Definition: qboxlayout.h:129
The QLineEdit widget is a one-line text editor.
Definition: qlineedit.h:66
quint16 index
virtual void fileDialogSetDirectory(QFileDialog *, const QString &)
static QByteArray encodeName(const QString &fileName)
By default, this function converts fileName to the local 8-bit encoding determined by the user&#39;s loca...
Definition: qfile.cpp:528
DialogCode
The value returned by a modal dialog.
Definition: qdialog.h:72
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
static QString toInternal(const QString &path)
int maxNameLength(const QString &path)
void setNameFilters_sys(const QStringList &filters)
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
QFileDialogPrivate * d_ptr
static QString toNativeSeparators(const QString &pathName)
Returns pathName with the &#39;/&#39; separators converted to separators that are appropriate for the underly...
Definition: qdir.cpp:812
QFileDialogPrivate * d_ptr
void setDirectory_sys(const QString &directory)
QStringList m_history
virtual void fileDialogSelectFile(QFileDialog *, const QString &)
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
QFileDialogLineEdit(QWidget *parent=0)
The QAction class provides an abstract user interface action that can be inserted into widgets...
Definition: qaction.h:64
QFileSystemModel * model
virtual QDialog::DialogCode fileDialogResultCode(QFileDialog *)
QScopedPointer< Ui_QFileDialog > qFileDialogUi
The QList class is a template class that provides lists.
Definition: qdatastream.h:62
bool setVisible_sys(bool visible)
const ushort * utf16() const
Returns the QString as a &#39;\0\&#39;-terminated array of unsigned shorts.
Definition: qstring.cpp:5290
QPointer< QObject > receiverToDisconnectOnClose
virtual void fileDialogDelete(QFileDialog *)