source: trunk/src/gui/dialogs/qfiledialog_p.h@ 100

Last change on this file since 100 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 14.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** 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 are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
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 <qtimeline.h>
77#include <qdebug.h>
78#include "qsidebar_p.h"
79
80#if defined (Q_OS_UNIX)
81#include <unistd.h>
82#endif
83
84QT_BEGIN_NAMESPACE
85
86class QFileDialogListView;
87class QFileDialogTreeView;
88class QFileDialogLineEdit;
89class QGridLayout;
90class QCompleter;
91class QHBoxLayout;
92class Ui_QFileDialog;
93
94#ifndef QT_NO_COMPLETER
95/*!
96 QCompleter that can deal with QFileSystemModel
97 */
98class QFSCompletor : public QCompleter {
99public:
100 QFSCompletor(QAbstractItemModel *model, QObject *parent = 0) : QCompleter(model, parent), proxyModel(0), sourceModel(0)
101 {
102#ifdef Q_OS_WIN
103 setCaseSensitivity(Qt::CaseInsensitive);
104#endif
105 }
106 QString pathFromIndex(const QModelIndex &index) const;
107 QStringList splitPath(const QString& path) const;
108
109 QAbstractProxyModel *proxyModel;
110 QFileSystemModel *sourceModel;
111};
112#endif // QT_NO_COMPLETER
113
114struct QFileDialogArgs
115{
116 QFileDialogArgs() : parent(0), mode(QFileDialog::AnyFile) {}
117
118 QWidget *parent;
119 QString caption;
120 QString directory;
121 QString selection;
122 QString filter;
123 QFileDialog::FileMode mode;
124 QFileDialog::Options options;
125};
126
127#define UrlRole (Qt::UserRole + 1)
128
129class Q_AUTOTEST_EXPORT QFileDialogPrivate : public QDialogPrivate
130{
131 Q_DECLARE_PUBLIC(QFileDialog)
132
133public:
134 QFileDialogPrivate() :
135#ifndef QT_NO_PROXYMODEL
136 proxyModel(0),
137#endif
138 model(0),
139 fileMode(QFileDialog::AnyFile),
140 acceptMode(QFileDialog::AcceptOpen),
141 currentHistoryLocation(-1),
142 renameAction(0),
143 deleteAction(0),
144 showHiddenAction(0),
145 useDefaultCaption(true),
146 defaultFileTypes(true),
147 fileNameLabelExplicitlySat(false),
148 nativeDialogInUse(false),
149#ifdef Q_WS_MAC
150 mDelegate(0),
151#ifndef QT_MAC_USE_COCOA
152 mDialog(0),
153 mDialogStarted(false),
154 mDialogClosed(true),
155#endif
156#endif
157 qFileDialogUi(0)
158 {}
159
160 void createToolButtons();
161 void createMenuActions();
162 void createWidgets();
163
164 void init(const QString &directory = QString(), const QString &nameFilter = QString(),
165 const QString &caption = QString());
166 bool itemViewKeyboardEvent(QKeyEvent *event);
167 QString getEnvironmentVariable(const QString &string);
168 static QString workingDirectory(const QString &path);
169 static QString initialSelection(const QString &path);
170 QStringList typedFiles() const;
171 QStringList addDefaultSuffixToFiles(const QStringList filesToFix) const;
172 bool removeDirectory(const QString &path);
173
174 inline QModelIndex mapToSource(const QModelIndex &index) const;
175 inline QModelIndex mapFromSource(const QModelIndex &index) const;
176 inline QModelIndex rootIndex() const;
177 inline void setRootIndex(const QModelIndex &index) const;
178 inline QModelIndex select(const QModelIndex &index) const;
179 inline QString rootPath() const;
180
181 QLineEdit *lineEdit() const;
182
183 int maxNameLength(const QString &path) {
184#if defined(Q_OS_UNIX)
185 return ::pathconf(QFile::encodeName(path).data(), _PC_NAME_MAX);
186#elif defined(Q_OS_WIN)
187#ifndef Q_OS_WINCE
188 DWORD maxLength;
189 QString drive = path.left(3);
190 if (QT_WA_INLINE(::GetVolumeInformationW(reinterpret_cast<const WCHAR *>(drive.utf16()), NULL, 0, NULL, &maxLength, NULL, NULL, 0),
191 ::GetVolumeInformationA(drive.toLocal8Bit().constData(), NULL, 0, NULL, &maxLength, NULL, NULL, 0)) == FALSE)
192 return -1;
193 return maxLength;
194#else
195 Q_UNUSED(path);
196 return MAX_PATH;
197#endif //Q_OS_WINCE
198#else
199 Q_UNUSED(path);
200#endif
201 return -1;
202 }
203
204 QString basename(const QString &path) const
205 {
206 int separator = QDir::toNativeSeparators(path).lastIndexOf(QDir::separator());
207 if (separator != -1)
208 return path.mid(separator + 1);
209 return path;
210 }
211
212 QDir::Filters filterForMode(QDir::Filters filters) const
213 {
214 if (fileMode == QFileDialog::DirectoryOnly) {
215 filters |= QDir::Drives | QDir::AllDirs | QDir::Dirs;
216 filters &= ~QDir::Files;
217 } else {
218 filters |= QDir::Drives | QDir::AllDirs | QDir::Files | QDir::Dirs;
219 }
220 return filters;
221 }
222
223 QAbstractItemView *currentView() const;
224
225 static inline QString toInternal(const QString &path)
226 {
227#if defined(Q_FS_FAT) || defined(Q_OS_OS2EMX)
228 QString n(path);
229 for (int i = 0; i < (int)n.length(); ++i)
230 if (n[i] == QLatin1Char('\\')) n[i] = QLatin1Char('/');
231#if defined(Q_OS_WINCE)
232 if ((n.size() > 1) && (n.startsWith(QLatin1String("//"))))
233 n = n.mid(1);
234#endif
235 return n;
236#else // the compile should optimize away this
237 return path;
238#endif
239 }
240
241 void setLastVisitedDirectory(const QString &dir);
242 void retranslateWindowTitle();
243 void retranslateStrings();
244 void emitFilesSelected(const QStringList &files);
245
246 void _q_goHome();
247 void _q_pathChanged(const QString &);
248 void _q_navigateBackward();
249 void _q_navigateForward();
250 void _q_navigateToParent();
251 void _q_createDirectory();
252 void _q_showListView();
253 void _q_showDetailsView();
254 void _q_showContextMenu(const QPoint &position);
255 void _q_renameCurrent();
256 void _q_deleteCurrent();
257 void _q_showHidden();
258 void _q_showHeader(QAction *);
259 void _q_updateOkButton();
260 void _q_currentChanged(const QModelIndex &index);
261 void _q_enterDirectory(const QModelIndex &index);
262 void _q_goToDirectory(const QString &);
263 void _q_useNameFilter(int index);
264 void _q_selectionChanged();
265 void _q_goToUrl(const QUrl &url);
266 void _q_autoCompleteFileName(const QString &);
267 void _q_rowsInserted(const QModelIndex & parent);
268 void _q_fileRenamed(const QString &path, const QString oldName, const QString newName);
269
270 // layout
271#ifndef QT_NO_PROXYMODEL
272 QAbstractProxyModel *proxyModel;
273#endif
274
275 // data
276 QStringList watching;
277 QFileSystemModel *model;
278 QFSCompletor *completer;
279
280 QFileDialog::FileMode fileMode;
281 QFileDialog::AcceptMode acceptMode;
282 bool confirmOverwrite;
283 QString defaultSuffix;
284 QString setWindowTitle;
285
286 QStringList currentHistory;
287 int currentHistoryLocation;
288
289 QAction *renameAction;
290 QAction *deleteAction;
291 QAction *showHiddenAction;
292 QAction *newFolderAction;
293
294 bool useDefaultCaption;
295 bool defaultFileTypes;
296 bool fileNameLabelExplicitlySat;
297 QStringList nameFilters;
298
299 // Members for using native dialogs:
300 bool nativeDialogInUse;
301 // setVisible_sys returns true if it ends up showing a native
302 // dialog. Returning false means that a non-native dialog must be
303 // used instead.
304 bool canBeNativeDialog();
305 bool setVisible_sys(bool visible);
306 void deleteNativeDialog_sys();
307 QDialog::DialogCode dialogResultCode_sys();
308
309 void setDirectory_sys(const QString &directory);
310 QString directory_sys() const;
311 void selectFile_sys(const QString &filename);
312 QStringList selectedFiles_sys() const;
313 void setFilter_sys();
314 void setNameFilters_sys(const QStringList &filters);
315 void selectNameFilter_sys(const QString &filter);
316 QString selectedNameFilter_sys() const;
317 //////////////////////////////////////////////
318
319#if defined(Q_WS_MAC)
320 void *mDelegate;
321#ifndef QT_MAC_USE_COCOA
322 NavDialogRef mDialog;
323 bool mDialogStarted;
324 bool mDialogClosed;
325 QString mCurrentLocation;