]> SALOME platform Git repositories - modules/kernel.git/blob - src/PatchQt/qfiledialogP.h
Salome HOME
Porting to Mandrake 10.1 and new products:
[modules/kernel.git] / src / PatchQt / qfiledialogP.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Module      : PatchQt
3 // File        : qfiledialogP.h
4 // Description : the patch for Qt's QFileDialog class (qfiledialog.h)
5 /////////////////////////////////////////////////////////////////////////////
6
7 /****************************************************************************
8 ** $Id$
9 **
10 ** Definition of QFileDialog class
11 **
12 ** Created : 950428
13 **
14 ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
15 **
16 ** This file is part of the dialogs module of the Qt GUI Toolkit.
17 **
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.
21 **
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.
26 **
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.
30 **
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.
33 **
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.
38 **
39 ** Contact info@trolltech.com if any conditions of this licensing are
40 ** not clear to you.
41 **
42 **********************************************************************/
43
44 #ifndef QFILEDIALOGP_H
45 #define QFILEDIALOGP_H
46
47 class QPushButton;
48 class QButton;
49 class QLabel;
50 class QWidget;
51 class QFileDialog;
52 class QTimer;
53 class QNetworkOperation;
54 class QLineEdit;
55 class QListViewItem;
56 class QListBoxItem;
57 class QProgressBar;
58 class QFileDialogPrivate;
59 class QFileDialogQFileListView;
60
61 #ifndef QT_H
62 #include "qdir.h"
63 #include "qdialog.h"
64 #include "qurloperator.h"
65 #include "qurlinfo.h"
66 #include "qlistbox.h"
67 #include "qlistview.h"
68 #include "qlineedit.h"
69 #endif // QT_H
70
71 #if QT_VERSION > 0x030005
72 #include <qfiledialog.h>
73 #define QFileDialogP QFileDialog
74 #else
75
76 #ifndef QT_NO_FILEDIALOG
77
78 class Q_EXPORT QFileIconProviderP : public QObject
79 {
80     Q_OBJECT
81 public:
82     QFileIconProviderP( QObject * parent = 0, const char* name = 0 );
83     virtual const QPixmap * pixmap( const QFileInfo & );
84
85 private:        // Disabled copy constructor and operator=
86 #if defined(Q_DISABLE_COPY)
87     QFileIconProviderP( const QFileIconProviderP & );
88     QFileIconProviderP& operator=( const QFileIconProviderP & );
89 #endif
90 };
91
92 class Q_EXPORT QFilePreviewP
93 {
94 public:
95     QFilePreviewP();
96     virtual void previewUrl( const QUrl &url ) = 0;
97
98 };
99
100 class Q_EXPORT QFileDialogP : public QDialog
101 {
102     Q_OBJECT
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 )
116
117 public:
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 );
121     ~QFileDialogP();
122
123     // recommended static functions
124
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,
138                                          QWidget *parent = 0,
139                                          const char* name = 0,
140                                          const QString &caption = QString::null,
141                                          bool dirOnly = TRUE,
142                                          bool resolveSymlinks = TRUE);
143     static QStringList getOpenFileNames( const QString &filter= QString::null,
144                                          const QString &dir = QString::null,
145                                          QWidget *parent = 0,
146                                          const char* name = 0,
147                                          const QString &caption = QString::null,
148                                          QString *selectedFilter = 0,
149                                          bool resolveSymlinks = TRUE);
150
151     // other static functions
152
153     static void setIconProvider( QFileIconProviderP * );
154     static QFileIconProviderP* iconProvider();
155
156     // non-static function for special needs
157
158     QString selectedFile() const;
159     QString selectedFilter() const;
160     virtual void setSelectedFilter( const QString& );
161     virtual void setSelectedFilter( int );
162
163     void setSelection( const QString &);
164
165     void selectAll( bool b );
166
167     QStringList selectedFiles() const;
168
169     QString dirPath() const;
170
171     void setDir( const QDir & );
172     const QDir *dir() const;
173
174     void setShowHiddenFiles( bool s );
175     bool showHiddenFiles() const;
176
177     void rereadDir();
178     void resortDir();
179
180     enum Mode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly };
181     void setMode( Mode );
182     Mode mode() const;
183
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;
190
191     bool eventFilter( QObject *, QEvent * );
192
193     bool isInfoPreviewEnabled() const;
194     bool isContentsPreviewEnabled() const;
195     void setInfoPreviewEnabled( bool );
196     void setContentsPreviewEnabled( bool );
197
198     void setInfoPreview( QWidget *w, QFilePreviewP *preview );
199     void setContentsPreview( QWidget *w, QFilePreviewP *preview );
200
201     QUrl url() const;
202
203     void addFilter( const QString &filter );
204
205 public slots:
206     void done( int );
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& );
213
214 protected:
215     void resizeEvent( QResizeEvent * );
216     void keyPressEvent( QKeyEvent * );
217
218     void addWidgets( QLabel *, QWidget *, QPushButton * );
219     void addToolButton( QButton *b, bool separator = FALSE );
220     void addLeftWidget( QWidget *w );
221     void addRightWidget( QWidget *w );
222
223 signals:
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& );
229
230 private slots:
231     void detailViewSelectionChanged();
232     void listBoxSelectionChanged();
233     void changeMode( int );
234     void fileNameEditReturnPressed();
235     void stopCopy();
236     void removeProgressDia();
237
238     void fileSelected( int );
239     void fileHighlighted( int );
240     void dirSelected( int );
241     void pathSelected( int );
242
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();
250
251     void okClicked();
252     void filterClicked(); // not used
253     void cancelClicked();
254
255     void cdUpClicked();
256     void newFolderClicked();
257
258     void fixupNameEdit();
259
260     void doMimeTypeLookup();
261
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 * );
271     void goBack();
272
273 private:
274     enum PopupAction {
275         PA_Open = 0,
276         PA_Delete,
277         PA_Rename,
278         PA_SortName,
279         PA_SortSize,
280         PA_SortType,
281         PA_SortDate,
282         PA_SortUnsorted,
283         PA_Cancel,
284         PA_Reload,
285         PA_Hidden
286     };
287
288     void init();
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 );
293
294     QDir reserved; // was cwd
295     QString fileName;
296
297     friend class QFileDialogQFileListView;
298     friend class QFileListBox;
299
300     QFileDialogPrivate *d;
301     QFileDialogQFileListView  *files;
302
303     QLineEdit  *nameEdit; // also filter
304     QPushButton *okB;
305     QPushButton *cancelB;
306
307 #if defined(Q_WS_WIN)
308     static QString winGetOpenFileName( const QString &initialSelection,
309                                        const QString &filter,
310                                        QString* workingDirectory,
311                                        QWidget *parent = 0,
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,
318                                        QWidget *parent = 0,
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,
324                                             QWidget *parent = 0,
325                                             const char* name = 0,
326                                             const QString& caption = QString::null,
327                                             QString* selectedFilter = 0 );
328     static QString winGetExistingDirectory( const QString &initialDirectory,
329                                             QWidget* parent = 0,
330                                             const char* name = 0,
331                                             const QString& caption = QString::null);
332     static QString resolveLinkFile( const QString& linkfile );
333 #endif
334 #if defined(Q_WS_MACX) || defined(Q_WS_MAC9)
335     static QString macGetSaveFileName( const QString &, const QString &, 
336                                        QString *, QWidget *, const char*,
337                                        const QString& );
338     static QStringList macGetOpenFileNames( const QString &, QString*,
339                                             QWidget *, const char *,
340                                             const QString&, bool = TRUE,
341                                             bool = FALSE );
342 #endif
343
344
345 private:        // Disabled copy constructor and operator=
346 #if defined(Q_DISABLE_COPY)
347     QFileDialogP( const QFileDialogP & );
348     QFileDialogP &operator=( const QFileDialogP & );
349 #endif
350 };
351
352 /******************************************************************
353  *
354  * Definitions of view classes
355  *
356  ******************************************************************/
357
358 class QRenameEdit : public QLineEdit
359 {
360     Q_OBJECT
361
362 public:
363     QRenameEdit( QWidget *parent )
364         : QLineEdit( parent, "qt_rename_edit" )
365     {}
366
367 protected:
368     void keyPressEvent( QKeyEvent *e );
369     void focusOutEvent( QFocusEvent *e );
370
371 signals:
372     void escapePressed();
373
374 };
375
376 class QFileListBox : public QListBox
377 {
378     friend class QFileDialogP;
379
380     Q_OBJECT
381
382 private:
383     QFileListBox( QWidget *parent, QFileDialogP *d );
384
385     void clear();
386     void show();
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 );
399 #endif
400     void keyPressEvent( QKeyEvent *e );
401
402 private slots:
403     void rename();
404     void cancelRename();
405     void doubleClickTimeout();
406     void changeDirDuringDrag();
407     void dragObjDestroyed();
408     void contentsMoved( int, int );
409
410 private:
411     QRenameEdit *lined;
412     QFileDialogP *filedialog;
413     bool renaming;
414     QTimer* renameTimer;
415     QListBoxItem *renameItem, *dragItem;
416     QPoint pressPos, oldDragPos;
417     bool mousePressed;
418     int urls;
419     QString startDragDir;
420     QListBoxItem *currDropItem;
421     QTimer *changeDirTimer;
422     bool firstMousePressEvent;
423     QUrlOperator startDragUrl;
424
425 };
426
427
428 class QFileDialogQFileListView : public QListView
429 {
430     Q_OBJECT
431
432 public:
433     QFileDialogQFileListView( QWidget *parent, QFileDialogP *d );
434
435     void clear();
436     void startRename( bool check = TRUE );
437     void setSorting( int column, bool increasing = TRUE );
438
439     QRenameEdit *lined;
440     bool renaming;
441     QListViewItem *renameItem;
442
443 private:
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 );
456 #endif
457
458 private slots:
459     void rename();
460     void cancelRename();
461     void changeSortColumn2( int column );
462     void doubleClickTimeout();
463     void changeDirDuringDrag();
464     void dragObjDestroyed();
465     void contentsMoved( int, int );
466
467 private:
468     QFileDialogP *filedialog;
469     QTimer* renameTimer;
470     QPoint pressPos, oldDragPos;
471     bool mousePressed;
472     int urls;
473     QString startDragDir;
474     QListViewItem *currDropItem, *dragItem;
475     QTimer *changeDirTimer;
476     bool firstMousePressEvent;
477     bool ascending;
478     int sortcolumn;
479     QUrlOperator startDragUrl;
480
481 };
482
483 /****************************************************************************
484  *
485  * Classes for copy progress dialog
486  *
487  ****************************************************************************/
488
489 class QFDProgressAnimation : public QWidget
490 {
491     Q_OBJECT
492
493 public:
494     QFDProgressAnimation( QWidget *parent );
495     void start();
496
497 private slots:
498     void next();
499
500 protected:
501     void paintEvent( QPaintEvent *e );
502
503 private:
504     int step;
505     QTimer *timer;
506
507 };
508
509 class QFDProgressDialog : public QDialog
510 {
511     Q_OBJECT
512
513 public:
514     QFDProgressDialog( QWidget *parent, const QString &fn, int steps );
515
516     void setReadProgress( int p );
517     void setWriteProgress( int p );
518     void setWriteLabel( const QString &s );
519
520 signals:
521     void cancelled();
522
523 private:
524     QProgressBar *readBar;
525     QProgressBar *writeBar;
526     QLabel *writeLabel;
527     QFDProgressAnimation *animation;
528
529 };
530
531 #endif
532
533 #endif // QT_VERSION
534
535 #endif // QFILEDIALOG_H