1 /////////////////////////////////////////////////////////////////////////////
3 // File : qfiledialogP.h
4 // Description : the patch for Qt's QFileDialog class (qfiledialog.h)
5 /////////////////////////////////////////////////////////////////////////////
7 /****************************************************************************
10 ** Definition of QFileDialog class
14 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
16 ** This file is part of the dialogs module of the Qt GUI Toolkit.
18 ** This file may be distributed under the terms of the Q Public License
19 ** as defined by Trolltech AS of Norway and appearing in the file
20 ** LICENSE.QPL included in the packaging of this file.
22 ** This file may be distributed and/or modified under the terms of the
23 ** GNU General Public License version 2 as published by the Free Software
24 ** Foundation and appearing in the file LICENSE.GPL included in the
25 ** packaging of this file.
27 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
28 ** licenses may use this file in accordance with the Qt Commercial License
29 ** Agreement provided with the Software.
31 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
32 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
34 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
35 ** information about Qt Commercial License Agreements.
36 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
37 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
39 ** Contact info@trolltech.com if any conditions of this licensing are
42 **********************************************************************/
44 #ifndef QFILEDIALOGP_H
45 #define QFILEDIALOGP_H
53 class QNetworkOperation;
58 class QFileDialogPrivate;
59 class QFileDialogQFileListView;
64 #include "qurloperator.h"
67 #include "qlistview.h"
68 #include "qlineedit.h"
71 #if QT_VERSION > 0x030005
72 #include <qfiledialog.h>
73 #define QFileDialogP QFileDialog
76 #ifndef QT_NO_FILEDIALOG
78 class Q_EXPORT QFileIconProviderP : public QObject
82 QFileIconProviderP( QObject * parent = 0, const char* name = 0 );
83 virtual const QPixmap * pixmap( const QFileInfo & );
85 private: // Disabled copy constructor and operator=
86 #if defined(Q_DISABLE_COPY)
87 QFileIconProviderP( const QFileIconProviderP & );
88 QFileIconProviderP& operator=( const QFileIconProviderP & );
92 class Q_EXPORT QFilePreviewP
96 virtual void previewUrl( const QUrl &url ) = 0;
100 class Q_EXPORT QFileDialogP : public QDialog
103 Q_ENUMS( Mode ViewMode PreviewMode )
104 // ##### Why are this read-only properties ?
105 Q_PROPERTY( QString selectedFile READ selectedFile )
106 Q_PROPERTY( QString selectedFilter READ selectedFilter )
107 Q_PROPERTY( QStringList selectedFiles READ selectedFiles )
108 // #### Should not we be able to set the path ?
109 Q_PROPERTY( QString dirPath READ dirPath )
110 Q_PROPERTY( bool showHiddenFiles READ showHiddenFiles WRITE setShowHiddenFiles )
111 Q_PROPERTY( Mode mode READ mode WRITE setMode )
112 Q_PROPERTY( ViewMode viewMode READ viewMode WRITE setViewMode )
113 Q_PROPERTY( PreviewMode previewMode READ previewMode WRITE setPreviewMode )
114 Q_PROPERTY( bool infoPreview READ isInfoPreviewEnabled WRITE setInfoPreviewEnabled )
115 Q_PROPERTY( bool contentsPreview READ isContentsPreviewEnabled WRITE setContentsPreviewEnabled )
118 QFileDialogP( const QString& dirName, const QString& filter = QString::null,
119 QWidget* parent=0, const char* name=0, bool modal = FALSE );
120 QFileDialogP( QWidget* parent=0, const char* name=0, bool modal = FALSE );
123 // recommended static functions
125 static QString getOpenFileName( const QString &initially = QString::null,
126 const QString &filter = QString::null,
127 QWidget *parent = 0, const char* name = 0,
128 const QString &caption = QString::null,
129 QString *selectedFilter = 0,
130 bool resolveSymlinks = TRUE);
131 static QString getSaveFileName( const QString &initially = QString::null,
132 const QString &filter = QString::null,
133 QWidget *parent = 0, const char* name = 0,
134 const QString &caption = QString::null,
135 QString *selectedFilter = 0,
136 bool resolveSymlinks = TRUE);
137 static QString getExistingDirectory( const QString &dir = QString::null,
139 const char* name = 0,
140 const QString &caption = QString::null,
142 bool resolveSymlinks = TRUE);
143 static QStringList getOpenFileNames( const QString &filter= QString::null,
144 const QString &dir = QString::null,
146 const char* name = 0,
147 const QString &caption = QString::null,
148 QString *selectedFilter = 0,
149 bool resolveSymlinks = TRUE);
151 // other static functions
153 static void setIconProvider( QFileIconProviderP * );
154 static QFileIconProviderP* iconProvider();
156 // non-static function for special needs
158 QString selectedFile() const;
159 QString selectedFilter() const;
160 virtual void setSelectedFilter( const QString& );
161 virtual void setSelectedFilter( int );
163 void setSelection( const QString &);
165 void selectAll( bool b );
167 QStringList selectedFiles() const;
169 QString dirPath() const;
171 void setDir( const QDir & );
172 const QDir *dir() const;
174 void setShowHiddenFiles( bool s );
175 bool showHiddenFiles() const;
180 enum Mode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly };
181 void setMode( Mode );
184 enum ViewMode { Detail, List };
185 enum PreviewMode { NoPreview, Contents, Info };
186 void setViewMode( ViewMode m );
187 ViewMode viewMode() const;
188 void setPreviewMode( PreviewMode m );
189 PreviewMode previewMode() const;
191 bool eventFilter( QObject *, QEvent * );
193 bool isInfoPreviewEnabled() const;
194 bool isContentsPreviewEnabled() const;
195 void setInfoPreviewEnabled( bool );
196 void setContentsPreviewEnabled( bool );
198 void setInfoPreview( QWidget *w, QFilePreviewP *preview );
199 void setContentsPreview( QWidget *w, QFilePreviewP *preview );
203 void addFilter( const QString &filter );
207 void setDir( const QString& );
208 void setUrl( const QUrlOperator &url );
209 void setFilter( const QString& );
210 void setFilters( const QString& );
211 void setFilters( const char ** );
212 void setFilters( const QStringList& );
215 void resizeEvent( QResizeEvent * );
216 void keyPressEvent( QKeyEvent * );
218 void addWidgets( QLabel *, QWidget *, QPushButton * );
219 void addToolButton( QButton *b, bool separator = FALSE );
220 void addLeftWidget( QWidget *w );
221 void addRightWidget( QWidget *w );
224 void fileHighlighted( const QString& );
225 void fileSelected( const QString& );
226 void filesSelected( const QStringList& );
227 void dirEntered( const QString& );
228 void filterSelected( const QString& );
231 void detailViewSelectionChanged();
232 void listBoxSelectionChanged();
233 void changeMode( int );
234 void fileNameEditReturnPressed();
236 void removeProgressDia();
238 void fileSelected( int );
239 void fileHighlighted( int );
240 void dirSelected( int );
241 void pathSelected( int );
243 void updateFileNameEdit( QListViewItem *);
244 void selectDirectoryOrFile( QListViewItem * );
245 void popupContextMenu( QListViewItem *, const QPoint &, int );
246 void popupContextMenu( QListBoxItem *, const QPoint & );
247 void updateFileNameEdit( QListBoxItem *);
248 void selectDirectoryOrFile( QListBoxItem * );
249 void fileNameEditDone();
252 void filterClicked(); // not used
253 void cancelClicked();
256 void newFolderClicked();
258 void fixupNameEdit();
260 void doMimeTypeLookup();
262 void updateGeometries();
263 void modeButtonsDestroyed();
264 void urlStart( QNetworkOperation *op );
265 void urlFinished( QNetworkOperation *op );
266 void dataTransferProgress( int bytesDone, int bytesTotal, QNetworkOperation * );
267 void insertEntry( const QValueList<QUrlInfo> &fi, QNetworkOperation *op );
268 void removeEntry( QNetworkOperation * );
269 void createdDirectory( const QUrlInfo &info, QNetworkOperation * );
270 void itemChanged( QNetworkOperation * );
289 bool trySetSelection( bool isDir, const QUrlOperator &, bool );
290 void deleteFile( const QString &filename );
291 void popupContextMenu( const QString &filename, bool withSort,
292 PopupAction &action, const QPoint &p );
294 QDir reserved; // was cwd
297 friend class QFileDialogQFileListView;
298 friend class QFileListBox;
300 QFileDialogPrivate *d;
301 QFileDialogQFileListView *files;
303 QLineEdit *nameEdit; // also filter
305 QPushButton *cancelB;
307 #if defined(Q_WS_WIN)
308 static QString winGetOpenFileName( const QString &initialSelection,
309 const QString &filter,
310 QString* workingDirectory,
312 const char* name = 0,
313 const QString& caption = QString::null,
314 QString* selectedFilter = 0 );
315 static QString winGetSaveFileName( const QString &initialSelection,
316 const QString &filter,
317 QString* workingDirectory,
319 const char* name = 0,
320 const QString& caption = QString::null,
321 QString* selectedFilter = 0 );
322 static QStringList winGetOpenFileNames( const QString &filter,
323 QString* workingDirectory,
325 const char* name = 0,
326 const QString& caption = QString::null,
327 QString* selectedFilter = 0 );
328 static QString winGetExistingDirectory( const QString &initialDirectory,
330 const char* name = 0,
331 const QString& caption = QString::null);
332 static QString resolveLinkFile( const QString& linkfile );
334 #if defined(Q_WS_MACX) || defined(Q_WS_MAC9)
335 static QString macGetSaveFileName( const QString &, const QString &,
336 QString *, QWidget *, const char*,
338 static QStringList macGetOpenFileNames( const QString &, QString*,
339 QWidget *, const char *,
340 const QString&, bool = TRUE,
345 private: // Disabled copy constructor and operator=
346 #if defined(Q_DISABLE_COPY)
347 QFileDialogP( const QFileDialogP & );
348 QFileDialogP &operator=( const QFileDialogP & );
352 /******************************************************************
354 * Definitions of view classes
356 ******************************************************************/
358 class QRenameEdit : public QLineEdit
363 QRenameEdit( QWidget *parent )
364 : QLineEdit( parent, "qt_rename_edit" )
368 void keyPressEvent( QKeyEvent *e );
369 void focusOutEvent( QFocusEvent *e );
372 void escapePressed();
376 class QFileListBox : public QListBox
378 friend class QFileDialogP;
383 QFileListBox( QWidget *parent, QFileDialogP *d );
387 void startRename( bool check = TRUE );
388 void viewportMousePressEvent( QMouseEvent *e );
389 void viewportMouseReleaseEvent( QMouseEvent *e );
390 void viewportMouseDoubleClickEvent( QMouseEvent *e );
391 void viewportMouseMoveEvent( QMouseEvent *e );
392 #ifndef QT_NO_DRAGANDDROP
393 void viewportDragEnterEvent( QDragEnterEvent *e );
394 void viewportDragMoveEvent( QDragMoveEvent *e );
395 void viewportDragLeaveEvent( QDragLeaveEvent *e );
396 void viewportDropEvent( QDropEvent *e );
397 bool acceptDrop( const QPoint &pnt, QWidget *source );
398 void setCurrentDropItem( const QPoint &pnt );
400 void keyPressEvent( QKeyEvent *e );
405 void doubleClickTimeout();
406 void changeDirDuringDrag();
407 void dragObjDestroyed();
408 void contentsMoved( int, int );
412 QFileDialogP *filedialog;
415 QListBoxItem *renameItem, *dragItem;
416 QPoint pressPos, oldDragPos;
419 QString startDragDir;
420 QListBoxItem *currDropItem;
421 QTimer *changeDirTimer;
422 bool firstMousePressEvent;
423 QUrlOperator startDragUrl;
428 class QFileDialogQFileListView : public QListView
433 QFileDialogQFileListView( QWidget *parent, QFileDialogP *d );
436 void startRename( bool check = TRUE );
437 void setSorting( int column, bool increasing = TRUE );
441 QListViewItem *renameItem;
444 void viewportMousePressEvent( QMouseEvent *e );
445 void viewportMouseDoubleClickEvent( QMouseEvent *e );
446 void keyPressEvent( QKeyEvent *e );
447 void viewportMouseReleaseEvent( QMouseEvent *e );
448 void viewportMouseMoveEvent( QMouseEvent *e );
449 #ifndef QT_NO_DRAGANDDROP
450 void viewportDragEnterEvent( QDragEnterEvent *e );
451 void viewportDragMoveEvent( QDragMoveEvent *e );
452 void viewportDragLeaveEvent( QDragLeaveEvent *e );
453 void viewportDropEvent( QDropEvent *e );
454 bool acceptDrop( const QPoint &pnt, QWidget *source );
455 void setCurrentDropItem( const QPoint &pnt );
461 void changeSortColumn2( int column );
462 void doubleClickTimeout();
463 void changeDirDuringDrag();
464 void dragObjDestroyed();
465 void contentsMoved( int, int );
468 QFileDialogP *filedialog;
470 QPoint pressPos, oldDragPos;
473 QString startDragDir;
474 QListViewItem *currDropItem, *dragItem;
475 QTimer *changeDirTimer;
476 bool firstMousePressEvent;
479 QUrlOperator startDragUrl;
483 /****************************************************************************
485 * Classes for copy progress dialog
487 ****************************************************************************/
489 class QFDProgressAnimation : public QWidget
494 QFDProgressAnimation( QWidget *parent );
501 void paintEvent( QPaintEvent *e );
509 class QFDProgressDialog : public QDialog
514 QFDProgressDialog( QWidget *parent, const QString &fn, int steps );
516 void setReadProgress( int p );
517 void setWriteProgress( int p );
518 void setWriteLabel( const QString &s );
524 QProgressBar *readBar;
525 QProgressBar *writeBar;
527 QFDProgressAnimation *animation;
535 #endif // QFILEDIALOG_H