home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / qfiledialog.h < prev    next >
C/C++ Source or Header  |  2001-10-11  |  11KB  |  339 lines

  1. /****************************************************************************
  2. ** $Id:  qt/qfiledialog.h   3.0.0   edited Sep 21 17:17 $
  3. **
  4. ** Definition of QFileDialog class
  5. **
  6. ** Created : 950428
  7. **
  8. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  9. **
  10. ** This file is part of the dialogs module of the Qt GUI Toolkit.
  11. **
  12. ** This file may be distributed under the terms of the Q Public License
  13. ** as defined by Trolltech AS of Norway and appearing in the file
  14. ** LICENSE.QPL included in the packaging of this file.
  15. **
  16. ** This file may be distributed and/or modified under the terms of the
  17. ** GNU General Public License version 2 as published by the Free Software
  18. ** Foundation and appearing in the file LICENSE.GPL included in the
  19. ** packaging of this file.
  20. **
  21. ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
  22. ** licenses may use this file in accordance with the Qt Commercial License
  23. ** Agreement provided with the Software.
  24. **
  25. ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
  26. ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  27. **
  28. ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
  29. **   information about Qt Commercial License Agreements.
  30. ** See http://www.trolltech.com/qpl/ for QPL licensing information.
  31. ** See http://www.trolltech.com/gpl/ for GPL licensing information.
  32. **
  33. ** Contact info@trolltech.com if any conditions of this licensing are
  34. ** not clear to you.
  35. **
  36. **********************************************************************/
  37.  
  38. #ifndef QFILEDIALOG_H
  39. #define QFILEDIALOG_H
  40.  
  41. class QPushButton;
  42. class QButton;
  43. class QLabel;
  44. class QWidget;
  45. class QFileDialog;
  46. class QTimer;
  47. class QNetworkOperation;
  48. class QLineEdit;
  49. class QListViewItem;
  50. class QListBoxItem;
  51. class QFileDialogPrivate;
  52. class QFileDialogQFileListView;
  53.  
  54. #ifndef QT_H
  55. #include "qdir.h"
  56. #include "qdialog.h"
  57. #include "qurloperator.h"
  58. #include "qurlinfo.h"
  59. #endif // QT_H
  60.  
  61. #ifndef QT_NO_FILEDIALOG
  62.  
  63. class Q_EXPORT QFileIconProvider : public QObject
  64. {
  65.     Q_OBJECT
  66. public:
  67.     QFileIconProvider( QObject * parent = 0, const char* name = 0 );
  68.     virtual const QPixmap * pixmap( const QFileInfo & );
  69.  
  70. private:    // Disabled copy constructor and operator=
  71. #if defined(Q_DISABLE_COPY)
  72.     QFileIconProvider( const QFileIconProvider & );
  73.     QFileIconProvider& operator=( const QFileIconProvider & );
  74. #endif
  75. };
  76.  
  77. class Q_EXPORT QFilePreview
  78. {
  79. public:
  80.     QFilePreview();
  81.     virtual void previewUrl( const QUrl &url ) = 0;
  82.  
  83. };
  84.  
  85. class Q_EXPORT QFileDialog : public QDialog
  86. {
  87.     Q_OBJECT
  88.     Q_ENUMS( Mode ViewMode PreviewMode )
  89.     // ##### Why are this read-only properties ?
  90.     Q_PROPERTY( QString selectedFile READ selectedFile )
  91.     Q_PROPERTY( QString selectedFilter READ selectedFilter )
  92.     Q_PROPERTY( QStringList selectedFiles READ selectedFiles )
  93.     // #### Should not we be able to set the path ?
  94.     Q_PROPERTY( QString dirPath READ dirPath )
  95.     Q_PROPERTY( bool showHiddenFiles READ showHiddenFiles WRITE setShowHiddenFiles )
  96.     Q_PROPERTY( Mode mode READ mode WRITE setMode )
  97.     Q_PROPERTY( ViewMode viewMode READ viewMode WRITE setViewMode )
  98.     Q_PROPERTY( PreviewMode previewMode READ previewMode WRITE setPreviewMode )
  99.     Q_PROPERTY( bool infoPreview READ isInfoPreviewEnabled WRITE setInfoPreviewEnabled )
  100.     Q_PROPERTY( bool contentsPreview READ isContentsPreviewEnabled WRITE setContentsPreviewEnabled )
  101.  
  102. public:
  103.     QFileDialog( const QString& dirName, const QString& filter = QString::null,
  104.          QWidget* parent=0, const char* name=0, bool modal = FALSE );
  105.     QFileDialog( QWidget* parent=0, const char* name=0, bool modal = FALSE );
  106.     ~QFileDialog();
  107.  
  108.     // recommended static functions
  109.  
  110.     static QString getOpenFileName( const QString &initially = QString::null,
  111.                     const QString &filter = QString::null,
  112.                     QWidget *parent = 0, const char* name = 0,
  113.                     const QString &caption = QString::null,
  114.                     QString *selectedFilter = 0,
  115.                     bool resolveSymlinks = TRUE);
  116.     static QString getSaveFileName( const QString &initially = QString::null,
  117.                     const QString &filter = QString::null,
  118.                     QWidget *parent = 0, const char* name = 0,
  119.                     const QString &caption = QString::null,
  120.                     QString *selectedFilter = 0,
  121.                     bool resolveSymlinks = TRUE);
  122.     static QString getExistingDirectory( const QString &dir = QString::null,
  123.                      QWidget *parent = 0,
  124.                      const char* name = 0,
  125.                      const QString &caption = QString::null,
  126.                      bool dirOnly = TRUE,
  127.                      bool resolveSymlinks = TRUE);
  128.     static QStringList getOpenFileNames( const QString &filter= QString::null,
  129.                      const QString &dir = QString::null,
  130.                      QWidget *parent = 0,
  131.                      const char* name = 0,
  132.                      const QString &caption = QString::null,
  133.                      QString *selectedFilter = 0,
  134.                      bool resolveSymlinks = TRUE);
  135.  
  136.     // other static functions
  137.  
  138.     static void setIconProvider( QFileIconProvider * );
  139.     static QFileIconProvider * iconProvider();
  140.  
  141.     // non-static function for special needs
  142.  
  143.     QString selectedFile() const;
  144.     QString selectedFilter() const;
  145.     virtual void setSelectedFilter( const QString& );
  146.     virtual void setSelectedFilter( int );
  147.  
  148.     void setSelection( const QString &);
  149.  
  150.     void selectAll( bool b );
  151.  
  152.     QStringList selectedFiles() const;
  153.  
  154.     QString dirPath() const;
  155.  
  156.     void setDir( const QDir & );
  157.     const QDir *dir() const;
  158.  
  159.     void setShowHiddenFiles( bool s );
  160.     bool showHiddenFiles() const;
  161.  
  162.     void rereadDir();
  163.     void resortDir();
  164.  
  165.     enum Mode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly };
  166.     void setMode( Mode );
  167.     Mode mode() const;
  168.  
  169.     enum ViewMode { Detail, List };
  170.     enum PreviewMode { NoPreview, Contents, Info };
  171.     void setViewMode( ViewMode m );
  172.     ViewMode viewMode() const;
  173.     void setPreviewMode( PreviewMode m );
  174.     PreviewMode previewMode() const;
  175.  
  176.     bool eventFilter( QObject *, QEvent * );
  177.  
  178.     bool isInfoPreviewEnabled() const;
  179.     bool isContentsPreviewEnabled() const;
  180.     void setInfoPreviewEnabled( bool );
  181.     void setContentsPreviewEnabled( bool );
  182.  
  183.     void setInfoPreview( QWidget *w, QFilePreview *preview );
  184.     void setContentsPreview( QWidget *w, QFilePreview *preview );
  185.  
  186.     QUrl url() const;
  187.  
  188.     void addFilter( const QString &filter );
  189.  
  190. public slots:
  191.     void done( int );
  192.     void setDir( const QString& );
  193.     void setUrl( const QUrlOperator &url );
  194.     void setFilter( const QString& );
  195.     void setFilters( const QString& );
  196.     void setFilters( const char ** );
  197.     void setFilters( const QStringList& );
  198.  
  199. protected:
  200.     void resizeEvent( QResizeEvent * );
  201.     void keyPressEvent( QKeyEvent * );
  202.  
  203.     void addWidgets( QLabel *, QWidget *, QPushButton * );
  204.     void addToolButton( QButton *b, bool separator = FALSE );
  205.     void addLeftWidget( QWidget *w );
  206.     void addRightWidget( QWidget *w );
  207.  
  208. signals:
  209.     void fileHighlighted( const QString& );
  210.     void fileSelected( const QString& );
  211.     void filesSelected( const QStringList& );
  212.     void dirEntered( const QString& );
  213.     void filterSelected( const QString& );
  214.  
  215. private slots:
  216.     void detailViewSelectionChanged();
  217.     void listBoxSelectionChanged();
  218.     void changeMode( int );
  219.     void fileNameEditReturnPressed();
  220.     void stopCopy();
  221.     void removeProgressDia();
  222.  
  223.     void fileSelected( int );
  224.     void fileHighlighted( int );
  225.     void dirSelected( int );
  226.     void pathSelected( int );
  227.  
  228.     void updateFileNameEdit( QListViewItem *);
  229.     void selectDirectoryOrFile( QListViewItem * );
  230.     void popupContextMenu( QListViewItem *, const QPoint &, int );
  231.     void popupContextMenu( QListBoxItem *, const QPoint & );
  232.     void updateFileNameEdit( QListBoxItem *);
  233.     void selectDirectoryOrFile( QListBoxItem * );
  234.     void fileNameEditDone();
  235.  
  236.     void okClicked();
  237.     void filterClicked(); // not used
  238.     void cancelClicked();
  239.  
  240.     void cdUpClicked();
  241.     void newFolderClicked();
  242.  
  243.     void fixupNameEdit();
  244.  
  245.     void doMimeTypeLookup();
  246.  
  247.     void updateGeometries();
  248.     void modeButtonsDestroyed();
  249.     void urlStart( QNetworkOperation *op );
  250.     void urlFinished( QNetworkOperation *op );
  251.     void dataTransferProgress( int bytesDone, int bytesTotal, QNetworkOperation * );
  252.     void insertEntry( const QValueList<QUrlInfo> &fi, QNetworkOperation *op );
  253.     void removeEntry( QNetworkOperation * );
  254.     void createdDirectory( const QUrlInfo &info, QNetworkOperation * );
  255.     void itemChanged( QNetworkOperation * );
  256.     void goBack();
  257.  
  258. private:
  259.     enum PopupAction {
  260.     PA_Open = 0,
  261.     PA_Delete,
  262.     PA_Rename,
  263.     PA_SortName,
  264.     PA_SortSize,
  265.     PA_SortType,
  266.     PA_SortDate,
  267.     PA_SortUnsorted,
  268.     PA_Cancel,
  269.     PA_Reload,
  270.     PA_Hidden
  271.     };
  272.  
  273.     void init();
  274.     bool trySetSelection( bool isDir, const QUrlOperator &, bool );
  275.     void deleteFile( const QString &filename );
  276.     void popupContextMenu( const QString &filename, bool withSort,
  277.                PopupAction &action, const QPoint &p );
  278.  
  279.     QDir reserved; // was cwd
  280.     QString fileName;
  281.  
  282.     friend class QFileDialogQFileListView;
  283.     friend class QFileListBox;
  284.  
  285.     QFileDialogPrivate *d;
  286.     QFileDialogQFileListView  *files;
  287.  
  288.     QLineEdit  *nameEdit; // also filter
  289.     QPushButton *okB;
  290.     QPushButton *cancelB;
  291.  
  292. #if defined(Q_WS_WIN)
  293.     static QString winGetOpenFileName( const QString &initialSelection,
  294.                        const QString &filter,
  295.                        QString* workingDirectory,
  296.                        QWidget *parent = 0,
  297.                        const char* name = 0,
  298.                        const QString& caption = QString::null,
  299.                        QString* selectedFilter = 0 );
  300.     static QString winGetSaveFileName( const QString &initialSelection,
  301.                        const QString &filter,
  302.                        QString* workingDirectory,
  303.                        QWidget *parent = 0,
  304.                        const char* name = 0,
  305.                        const QString& caption = QString::null,
  306.                            QString* selectedFilter = 0 );
  307.     static QStringList winGetOpenFileNames( const QString &filter,
  308.                         QString* workingDirectory,
  309.                         QWidget *parent = 0,
  310.                         const char* name = 0,
  311.                         const QString& caption = QString::null,
  312.                         QString* selectedFilter = 0 );
  313.     static QString winGetExistingDirectory( const QString &initialDirectory,
  314.                         QWidget* parent = 0,
  315.                         const char* name = 0,
  316.                         const QString& caption = QString::null);
  317.     static QString resolveLinkFile( const QString& linkfile );
  318. #endif
  319. #if defined(Q_WS_MACX) || defined(Q_WS_MAC9)
  320.     static QString macGetSaveFileName( const QString &, const QString &, 
  321.                        QString *, QWidget *, const char*,
  322.                        const QString& );
  323.     static QStringList macGetOpenFileNames( const QString &, QString*,
  324.                         QWidget *, const char *,
  325.                         const QString&, bool = TRUE);
  326. #endif
  327.  
  328.  
  329. private:    // Disabled copy constructor and operator=
  330. #if defined(Q_DISABLE_COPY)
  331.     QFileDialog( const QFileDialog & );
  332.     QFileDialog &operator=( const QFileDialog & );
  333. #endif
  334. };
  335.  
  336. #endif
  337.  
  338. #endif // QFILEDIALOG_H
  339.