qfiledialog.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
00004 ** All rights reserved.
00005 ** Contact: Nokia Corporation (qt-info@nokia.com)
00006 **
00007 ** This file is part of the QtGui module of the Qt Toolkit.
00008 **
00009 ** $QT_BEGIN_LICENSE:LGPL$
00010 ** Commercial Usage
00011 ** Licensees holding valid Qt Commercial licenses may use this file in
00012 ** accordance with the Qt Commercial License Agreement provided with the
00013 ** Software or, alternatively, in accordance with the terms contained in
00014 ** a written agreement between you and Nokia.
00015 **
00016 ** GNU Lesser General Public License Usage
00017 ** Alternatively, this file may be used under the terms of the GNU Lesser
00018 ** General Public License version 2.1 as published by the Free Software
00019 ** Foundation and appearing in the file LICENSE.LGPL included in the
00020 ** packaging of this file.  Please review the following information to
00021 ** ensure the GNU Lesser General Public License version 2.1 requirements
00022 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
00023 **
00024 ** In addition, as a special exception, Nokia gives you certain additional
00025 ** rights.  These rights are described in the Nokia Qt LGPL Exception
00026 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this module.
00027 **
00028 ** GNU General Public License Usage
00029 ** Alternatively, this file may be used under the terms of the GNU
00030 ** General Public License version 3.0 as published by the Free Software
00031 ** Foundation and appearing in the file LICENSE.GPL included in the
00032 ** packaging of this file.  Please review the following information to
00033 ** ensure the GNU General Public License version 3.0 requirements will be
00034 ** met: http://www.gnu.org/copyleft/gpl.html.
00035 **
00036 ** If you have questions regarding the use of this file, please contact
00037 ** Nokia at qt-info@nokia.com.
00038 ** $QT_END_LICENSE$
00039 **
00040 ****************************************************************************/
00041 
00042 #ifndef QFILEDIALOG_H
00043 #define QFILEDIALOG_H
00044 
00045 #include <QtCore/qdir.h>
00046 #include <QtCore/qstring.h>
00047 #include <QtGui/qdialog.h>
00048 
00049 QT_BEGIN_HEADER
00050 
00051 QT_BEGIN_NAMESPACE
00052 
00053 QT_MODULE(Gui)
00054 
00055 #ifndef QT_NO_FILEDIALOG
00056 
00057 class QModelIndex;
00058 class QItemSelection;
00059 struct QFileDialogArgs;
00060 class QFileIconProvider;
00061 class QFileDialogPrivate;
00062 class QAbstractItemDelegate;
00063 class QAbstractProxyModel;
00064 class QUrl;
00065 
00066 class Q_GUI_EXPORT QFileDialog : public QDialog
00067 {
00068     Q_OBJECT
00069     Q_ENUMS(ViewMode FileMode AcceptMode Option)
00070     Q_FLAGS(Options)
00071     Q_PROPERTY(ViewMode viewMode READ viewMode WRITE setViewMode)
00072     Q_PROPERTY(FileMode fileMode READ fileMode WRITE setFileMode)
00073     Q_PROPERTY(AcceptMode acceptMode READ acceptMode WRITE setAcceptMode)
00074     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly DESIGNABLE false)
00075     Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks DESIGNABLE false)
00076     Q_PROPERTY(bool confirmOverwrite READ confirmOverwrite WRITE setConfirmOverwrite DESIGNABLE false)
00077     Q_PROPERTY(QString defaultSuffix READ defaultSuffix WRITE setDefaultSuffix)
00078     Q_PROPERTY(bool nameFilterDetailsVisible READ isNameFilterDetailsVisible
00079                WRITE setNameFilterDetailsVisible DESIGNABLE false)
00080     Q_PROPERTY(Options options READ options WRITE setOptions)
00081 
00082 public:
00083     enum ViewMode { Detail, List };
00084     enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly };
00085     enum AcceptMode { AcceptOpen, AcceptSave };
00086     enum DialogLabel { LookIn, FileName, FileType, Accept, Reject };
00087 
00088     // ### Rename to FileDialogOption and FileDialogOptions for Qt 5.0
00089     enum Option
00090     {
00091         ShowDirsOnly          = 0x00000001,
00092         DontResolveSymlinks   = 0x00000002,
00093         DontConfirmOverwrite  = 0x00000004,
00094         DontUseSheet          = 0x00000008,
00095         DontUseNativeDialog   = 0x00000010,
00096         ReadOnly              = 0x00000020,
00097         HideNameFilterDetails = 0x00000040
00098     };
00099     Q_DECLARE_FLAGS(Options, Option)
00100 
00101     QFileDialog(QWidget *parent, Qt::WindowFlags f);
00102     explicit QFileDialog(QWidget *parent = 0,
00103                          const QString &caption = QString(),
00104                          const QString &directory = QString(),
00105                          const QString &filter = QString());
00106     ~QFileDialog();
00107 
00108     void setDirectory(const QString &directory);
00109     inline void setDirectory(const QDir &directory);
00110     QDir directory() const;
00111 
00112     void selectFile(const QString &filename);
00113     QStringList selectedFiles() const;
00114 
00115 #ifdef QT_DEPRECATED
00116     QT_DEPRECATED void setFilter(const QString &filter);
00117     QT_DEPRECATED void setFilters(const QStringList &filters);
00118     QT_DEPRECATED QStringList filters() const;
00119     QT_DEPRECATED void selectFilter(const QString &filter);
00120     QT_DEPRECATED QString selectedFilter() const;
00121 #endif
00122     void setNameFilterDetailsVisible(bool enabled);
00123     bool isNameFilterDetailsVisible() const;
00124 
00125     void setNameFilter(const QString &filter);
00126     void setNameFilters(const QStringList &filters);
00127     QStringList nameFilters() const;
00128     void selectNameFilter(const QString &filter);
00129     QString selectedNameFilter() const;
00130 
00131     QDir::Filters filter() const;
00132     void setFilter(QDir::Filters filters);
00133 
00134     void setViewMode(ViewMode mode);
00135     ViewMode viewMode() const;
00136 
00137     void setFileMode(FileMode mode);
00138     FileMode fileMode() const;
00139 
00140     void setAcceptMode(AcceptMode mode);
00141     AcceptMode acceptMode() const;
00142 
00143     void setReadOnly(bool enabled);
00144     bool isReadOnly() const;
00145 
00146     void setResolveSymlinks(bool enabled);
00147     bool resolveSymlinks() const;
00148 
00149     void setSidebarUrls(const QList<QUrl> &urls);
00150     QList<QUrl> sidebarUrls() const;
00151 
00152     QByteArray saveState() const;
00153     bool restoreState(const QByteArray &state);
00154 
00155     void setConfirmOverwrite(bool enabled);
00156     bool confirmOverwrite() const;
00157 
00158     void setDefaultSuffix(const QString &suffix);
00159     QString defaultSuffix() const;
00160 
00161     void setHistory(const QStringList &paths);
00162     QStringList history() const;
00163 
00164     void setItemDelegate(QAbstractItemDelegate *delegate);
00165     QAbstractItemDelegate *itemDelegate() const;
00166 
00167     void setIconProvider(QFileIconProvider *provider);
00168     QFileIconProvider *iconProvider() const;
00169 
00170     void setLabelText(DialogLabel label, const QString &text);
00171     QString labelText(DialogLabel label) const;
00172 
00173 #ifndef QT_NO_PROXYMODEL
00174     void setProxyModel(QAbstractProxyModel *model);
00175     QAbstractProxyModel *proxyModel() const;
00176 #endif
00177 
00178     void setOption(Option option, bool on = true);
00179     bool testOption(Option option) const;
00180     void setOptions(Options options);
00181     Options options() const;
00182 
00183 #ifdef Q_NO_USING_KEYWORD
00184 #ifndef Q_QDOC
00185     void open() { QDialog::open(); }
00186 #endif
00187 #else
00188     using QDialog::open;
00189 #endif
00190     void open(QObject *receiver, const char *member);
00191     void setVisible(bool visible);
00192 
00193 Q_SIGNALS:
00194     void fileSelected(const QString &file);
00195     void filesSelected(const QStringList &files);
00196     void currentChanged(const QString &path);
00197     void directoryEntered(const QString &directory);
00198     void filterSelected(const QString &filter);
00199 
00200 public:
00201 #ifdef QT3_SUPPORT
00202     typedef FileMode Mode;
00203     inline QT3_SUPPORT void setMode(FileMode m) { setFileMode(m); }
00204     inline QT3_SUPPORT FileMode mode() const { return fileMode(); }
00205     inline QT3_SUPPORT void setDir(const QString &directory) { setDirectory(directory); }
00206     inline QT3_SUPPORT void setDir( const QDir &directory ) { setDirectory(directory); }
00207     QT3_SUPPORT QString selectedFile() const;
00208 #endif
00209 
00210     static QString getOpenFileName(QWidget *parent = 0,
00211                                    const QString &caption = QString(),
00212                                    const QString &dir = QString(),
00213                                    const QString &filter = QString(),
00214                                    QString *selectedFilter = 0,
00215                                    Options options = 0);
00216 
00217     static QString getSaveFileName(QWidget *parent = 0,
00218                                    const QString &caption = QString(),
00219                                    const QString &dir = QString(),
00220                                    const QString &filter = QString(),
00221                                    QString *selectedFilter = 0,
00222                                    Options options = 0);
00223 
00224     static QString getExistingDirectory(QWidget *parent = 0,
00225                                         const QString &caption = QString(),
00226                                         const QString &dir = QString(),
00227                                         Options options = ShowDirsOnly);
00228 
00229     static QStringList getOpenFileNames(QWidget *parent = 0,
00230                                         const QString &caption = QString(),
00231                                         const QString &dir = QString(),
00232                                         const QString &filter = QString(),
00233                                         QString *selectedFilter = 0,
00234                                         Options options = 0);
00235 
00236 #ifdef QT3_SUPPORT
00237     inline static QString QT3_SUPPORT getOpenFileName(const QString &dir,
00238                                                     const QString &filter = QString(),
00239                                                     QWidget *parent = 0, const char* name = 0,
00240                                                     const QString &caption = QString(),
00241                                                     QString *selectedFilter = 0,
00242                                                     bool resolveSymlinks = true)
00243         { Q_UNUSED(name);
00244           return getOpenFileName(parent, caption, dir, filter, selectedFilter,
00245                                  resolveSymlinks ? Option(0) : DontResolveSymlinks); }
00246 
00247     inline static QString QT3_SUPPORT getSaveFileName(const QString &dir,
00248                                                     const QString &filter = QString(),
00249                                                     QWidget *parent = 0, const char* name = 0,
00250                                                     const QString &caption = QString(),
00251                                                     QString *selectedFilter = 0,
00252                                                     bool resolveSymlinks = true)
00253         { Q_UNUSED(name);
00254           return getSaveFileName(parent, caption, dir, filter, selectedFilter,
00255                                  resolveSymlinks ? Option(0) : DontResolveSymlinks); }
00256 
00257     inline static QString QT3_SUPPORT getExistingDirectory(const QString &dir,
00258                                                          QWidget *parent = 0,
00259                                                          const char* name = 0,
00260                                                          const QString &caption = QString(),
00261                                                          bool dirOnly = true,
00262                                                          bool resolveSymlinks = true)
00263         { Q_UNUSED(name);
00264           return getExistingDirectory(parent, caption, dir,
00265                                       Options((resolveSymlinks ? Option(0) : DontResolveSymlinks)
00266                                       | (dirOnly ? ShowDirsOnly : Option(0)))); }
00267 
00268     inline static QStringList QT3_SUPPORT getOpenFileNames(const QString &filter,
00269                                                          const QString &dir = QString(),
00270                                                          QWidget *parent = 0,
00271                                                          const char* name = 0,
00272                                                          const QString &caption = QString(),
00273                                                          QString *selectedFilter = 0,
00274                                                          bool resolveSymlinks = true)
00275         { Q_UNUSED(name);
00276           return getOpenFileNames(parent, caption, dir, filter, selectedFilter,
00277                                   resolveSymlinks ? Option(0) : DontResolveSymlinks); }
00278 #endif // QT3_SUPPORT
00279 
00280 protected:
00281     QFileDialog(const QFileDialogArgs &args);
00282     void done(int result);
00283     void accept();
00284     void changeEvent(QEvent *e);
00285 
00286 private:
00287     Q_DECLARE_PRIVATE(QFileDialog)
00288     Q_DISABLE_COPY(QFileDialog)
00289 
00290     Q_PRIVATE_SLOT(d_func(), void _q_pathChanged(const QString &))
00291 
00292     Q_PRIVATE_SLOT(d_func(), void _q_navigateBackward())
00293     Q_PRIVATE_SLOT(d_func(), void _q_navigateForward())
00294     Q_PRIVATE_SLOT(d_func(), void _q_navigateToParent())
00295     Q_PRIVATE_SLOT(d_func(), void _q_createDirectory())
00296     Q_PRIVATE_SLOT(d_func(), void _q_showListView())
00297     Q_PRIVATE_SLOT(d_func(), void _q_showDetailsView())
00298     Q_PRIVATE_SLOT(d_func(), void _q_showContextMenu(const QPoint &))
00299     Q_PRIVATE_SLOT(d_func(), void _q_renameCurrent())
00300     Q_PRIVATE_SLOT(d_func(), void _q_deleteCurrent())
00301     Q_PRIVATE_SLOT(d_func(), void _q_showHidden())
00302     Q_PRIVATE_SLOT(d_func(), void _q_updateOkButton())
00303     Q_PRIVATE_SLOT(d_func(), void _q_currentChanged(const QModelIndex &index))
00304     Q_PRIVATE_SLOT(d_func(), void _q_enterDirectory(const QModelIndex &index))
00305     Q_PRIVATE_SLOT(d_func(), void _q_goToDirectory(const QString &path))
00306     Q_PRIVATE_SLOT(d_func(), void _q_useNameFilter(int index))
00307     Q_PRIVATE_SLOT(d_func(), void _q_selectionChanged())
00308     Q_PRIVATE_SLOT(d_func(), void _q_goToUrl(const QUrl &url))
00309     Q_PRIVATE_SLOT(d_func(), void _q_goHome())
00310     Q_PRIVATE_SLOT(d_func(), void _q_showHeader(QAction *))
00311     Q_PRIVATE_SLOT(d_func(), void _q_autoCompleteFileName(const QString &text))
00312     Q_PRIVATE_SLOT(d_func(), void _q_rowsInserted(const QModelIndex & parent))
00313     Q_PRIVATE_SLOT(d_func(), void _q_fileRenamed(const QString &path,
00314                 const QString oldName, const QString newName))
00315 #if defined(Q_WS_MAC)
00316     Q_PRIVATE_SLOT(d_func(), void _q_macRunNativeAppModalPanel())
00317 #endif
00318 };
00319 
00320 inline void QFileDialog::setDirectory(const QDir &adirectory)
00321 { setDirectory(adirectory.absolutePath()); }
00322 
00323 Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDialog::Options)
00324 
00325 #endif // QT_NO_FILEDIALOG
00326 
00327 QT_END_NAMESPACE
00328 
00329 QT_END_HEADER
00330 
00331 #endif // QFILEDIALOG_H