src/gui/dialogs/qfiledialog.h
changeset 0 1918ee327afb
child 4 3b1da2848fc7
equal deleted inserted replaced
-1:000000000000 0:1918ee327afb
       
     1 /****************************************************************************
       
     2 **
       
     3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     4 ** All rights reserved.
       
     5 ** Contact: Nokia Corporation (qt-info@nokia.com)
       
     6 **
       
     7 ** This file is part of the QtGui module of the Qt Toolkit.
       
     8 **
       
     9 ** $QT_BEGIN_LICENSE:LGPL$
       
    10 ** No Commercial Usage
       
    11 ** This file contains pre-release code and may not be distributed.
       
    12 ** You may use this file in accordance with the terms and conditions
       
    13 ** contained in the Technology Preview License Agreement accompanying
       
    14 ** this package.
       
    15 **
       
    16 ** GNU Lesser General Public License Usage
       
    17 ** Alternatively, this file may be used under the terms of the GNU Lesser
       
    18 ** General Public License version 2.1 as published by the Free Software
       
    19 ** Foundation and appearing in the file LICENSE.LGPL included in the
       
    20 ** packaging of this file.  Please review the following information to
       
    21 ** ensure the GNU Lesser General Public License version 2.1 requirements
       
    22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
       
    23 **
       
    24 ** In addition, as a special exception, Nokia gives you certain additional
       
    25 ** rights.  These rights are described in the Nokia Qt LGPL Exception
       
    26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
       
    27 **
       
    28 ** If you have questions regarding the use of this file, please contact
       
    29 ** Nokia at qt-info@nokia.com.
       
    30 **
       
    31 **
       
    32 **
       
    33 **
       
    34 **
       
    35 **
       
    36 **
       
    37 **
       
    38 ** $QT_END_LICENSE$
       
    39 **
       
    40 ****************************************************************************/
       
    41 
       
    42 #ifndef QFILEDIALOG_H
       
    43 #define QFILEDIALOG_H
       
    44 
       
    45 #include <QtCore/qdir.h>
       
    46 #include <QtCore/qstring.h>
       
    47 #include <QtGui/qdialog.h>
       
    48 
       
    49 QT_BEGIN_HEADER
       
    50 
       
    51 QT_BEGIN_NAMESPACE
       
    52 
       
    53 QT_MODULE(Gui)
       
    54 
       
    55 #ifndef QT_NO_FILEDIALOG
       
    56 
       
    57 class QModelIndex;
       
    58 class QItemSelection;
       
    59 struct QFileDialogArgs;
       
    60 class QFileIconProvider;
       
    61 class QFileDialogPrivate;
       
    62 class QAbstractItemDelegate;
       
    63 class QAbstractProxyModel;
       
    64 class QUrl;
       
    65 
       
    66 class Q_GUI_EXPORT QFileDialog : public QDialog
       
    67 {
       
    68     Q_OBJECT
       
    69     Q_ENUMS(ViewMode FileMode AcceptMode Option)
       
    70     Q_PROPERTY(ViewMode viewMode READ viewMode WRITE setViewMode)
       
    71     Q_PROPERTY(FileMode fileMode READ fileMode WRITE setFileMode)
       
    72     Q_PROPERTY(AcceptMode acceptMode READ acceptMode WRITE setAcceptMode)
       
    73     Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly DESIGNABLE false)
       
    74     Q_PROPERTY(bool resolveSymlinks READ resolveSymlinks WRITE setResolveSymlinks DESIGNABLE false)
       
    75     Q_PROPERTY(bool confirmOverwrite READ confirmOverwrite WRITE setConfirmOverwrite DESIGNABLE false)
       
    76     Q_PROPERTY(QString defaultSuffix READ defaultSuffix WRITE setDefaultSuffix)
       
    77     Q_PROPERTY(bool nameFilterDetailsVisible READ isNameFilterDetailsVisible
       
    78                WRITE setNameFilterDetailsVisible DESIGNABLE false)
       
    79     Q_PROPERTY(Options options READ options WRITE setOptions)
       
    80 
       
    81 public:
       
    82     enum ViewMode { Detail, List };
       
    83     enum FileMode { AnyFile, ExistingFile, Directory, ExistingFiles, DirectoryOnly };
       
    84     enum AcceptMode { AcceptOpen, AcceptSave };
       
    85     enum DialogLabel { LookIn, FileName, FileType, Accept, Reject };
       
    86 
       
    87     // ### Rename to FileDialogOption and FileDialogOptions for Qt 5.0
       
    88     enum Option
       
    89     {
       
    90         ShowDirsOnly          = 0x00000001,
       
    91         DontResolveSymlinks   = 0x00000002,
       
    92         DontConfirmOverwrite  = 0x00000004,
       
    93         DontUseSheet          = 0x00000008,
       
    94         DontUseNativeDialog   = 0x00000010,
       
    95         ReadOnly              = 0x00000020,
       
    96         HideNameFilterDetails = 0x00000040
       
    97     };
       
    98     Q_DECLARE_FLAGS(Options, Option)
       
    99 
       
   100     QFileDialog(QWidget *parent, Qt::WindowFlags f);
       
   101     explicit QFileDialog(QWidget *parent = 0,
       
   102                          const QString &caption = QString(),
       
   103                          const QString &directory = QString(),
       
   104                          const QString &filter = QString());
       
   105     ~QFileDialog();
       
   106 
       
   107     void setDirectory(const QString &directory);
       
   108     inline void setDirectory(const QDir &directory);
       
   109     QDir directory() const;
       
   110 
       
   111     void selectFile(const QString &filename);
       
   112     QStringList selectedFiles() const;
       
   113 
       
   114 #ifdef QT_DEPRECATED
       
   115     QT_DEPRECATED void setFilter(const QString &filter);
       
   116     QT_DEPRECATED void setFilters(const QStringList &filters);
       
   117     QT_DEPRECATED QStringList filters() const;
       
   118     QT_DEPRECATED void selectFilter(const QString &filter);
       
   119     QT_DEPRECATED QString selectedFilter() const;
       
   120 #endif
       
   121     void setNameFilterDetailsVisible(bool enabled);
       
   122     bool isNameFilterDetailsVisible() const;
       
   123 
       
   124     void setNameFilter(const QString &filter);
       
   125     void setNameFilters(const QStringList &filters);
       
   126     QStringList nameFilters() const;
       
   127     void selectNameFilter(const QString &filter);
       
   128     QString selectedNameFilter() const;
       
   129 
       
   130     QDir::Filters filter() const;
       
   131     void setFilter(QDir::Filters filters);
       
   132 
       
   133     void setViewMode(ViewMode mode);
       
   134     ViewMode viewMode() const;
       
   135 
       
   136     void setFileMode(FileMode mode);
       
   137     FileMode fileMode() const;
       
   138 
       
   139     void setAcceptMode(AcceptMode mode);
       
   140     AcceptMode acceptMode() const;
       
   141 
       
   142     void setReadOnly(bool enabled);
       
   143     bool isReadOnly() const;
       
   144 
       
   145     void setResolveSymlinks(bool enabled);
       
   146     bool resolveSymlinks() const;
       
   147 
       
   148     void setSidebarUrls(const QList<QUrl> &urls);
       
   149     QList<QUrl> sidebarUrls() const;
       
   150 
       
   151     QByteArray saveState() const;
       
   152     bool restoreState(const QByteArray &state);
       
   153 
       
   154     void setConfirmOverwrite(bool enabled);
       
   155     bool confirmOverwrite() const;
       
   156 
       
   157     void setDefaultSuffix(const QString &suffix);
       
   158     QString defaultSuffix() const;
       
   159 
       
   160     void setHistory(const QStringList &paths);
       
   161     QStringList history() const;
       
   162 
       
   163     void setItemDelegate(QAbstractItemDelegate *delegate);
       
   164     QAbstractItemDelegate *itemDelegate() const;
       
   165 
       
   166     void setIconProvider(QFileIconProvider *provider);
       
   167     QFileIconProvider *iconProvider() const;
       
   168 
       
   169     void setLabelText(DialogLabel label, const QString &text);
       
   170     QString labelText(DialogLabel label) const;
       
   171 
       
   172 #ifndef QT_NO_PROXYMODEL
       
   173     void setProxyModel(QAbstractProxyModel *model);
       
   174     QAbstractProxyModel *proxyModel() const;
       
   175 #endif
       
   176 
       
   177     void setOption(Option option, bool on = true);
       
   178     bool testOption(Option option) const;
       
   179     void setOptions(Options options);
       
   180     Options options() const;
       
   181 
       
   182 #ifdef Q_NO_USING_KEYWORD
       
   183 #ifndef Q_QDOC
       
   184     void open() { QDialog::open(); }
       
   185 #endif
       
   186 #else
       
   187     using QDialog::open;
       
   188 #endif
       
   189     void open(QObject *receiver, const char *member);
       
   190     void setVisible(bool visible);
       
   191 
       
   192 Q_SIGNALS:
       
   193     void fileSelected(const QString &file);
       
   194     void filesSelected(const QStringList &files);
       
   195     void currentChanged(const QString &path);
       
   196     void directoryEntered(const QString &directory);
       
   197     void filterSelected(const QString &filter);
       
   198 
       
   199 public:
       
   200 #ifdef QT3_SUPPORT
       
   201     typedef FileMode Mode;
       
   202     inline QT3_SUPPORT void setMode(FileMode m) { setFileMode(m); }
       
   203     inline QT3_SUPPORT FileMode mode() const { return fileMode(); }
       
   204     inline QT3_SUPPORT void setDir(const QString &directory) { setDirectory(directory); }
       
   205     inline QT3_SUPPORT void setDir( const QDir &directory ) { setDirectory(directory); }
       
   206     QT3_SUPPORT QString selectedFile() const;
       
   207 #endif
       
   208 
       
   209     static QString getOpenFileName(QWidget *parent = 0,
       
   210                                    const QString &caption = QString(),
       
   211                                    const QString &dir = QString(),
       
   212                                    const QString &filter = QString(),
       
   213                                    QString *selectedFilter = 0,
       
   214                                    Options options = 0);
       
   215 
       
   216     static QString getSaveFileName(QWidget *parent = 0,
       
   217                                    const QString &caption = QString(),
       
   218                                    const QString &dir = QString(),
       
   219                                    const QString &filter = QString(),
       
   220                                    QString *selectedFilter = 0,
       
   221                                    Options options = 0);
       
   222 
       
   223     static QString getExistingDirectory(QWidget *parent = 0,
       
   224                                         const QString &caption = QString(),
       
   225                                         const QString &dir = QString(),
       
   226                                         Options options = ShowDirsOnly);
       
   227 
       
   228     static QStringList getOpenFileNames(QWidget *parent = 0,
       
   229                                         const QString &caption = QString(),
       
   230                                         const QString &dir = QString(),
       
   231                                         const QString &filter = QString(),
       
   232                                         QString *selectedFilter = 0,
       
   233                                         Options options = 0);
       
   234 
       
   235 #ifdef QT3_SUPPORT
       
   236     inline static QString QT3_SUPPORT getOpenFileName(const QString &dir,
       
   237                                                     const QString &filter = QString(),
       
   238                                                     QWidget *parent = 0, const char* name = 0,
       
   239                                                     const QString &caption = QString(),
       
   240                                                     QString *selectedFilter = 0,
       
   241                                                     bool resolveSymlinks = true)
       
   242         { Q_UNUSED(name);
       
   243           return getOpenFileName(parent, caption, dir, filter, selectedFilter,
       
   244                                  resolveSymlinks ? Option(0) : DontResolveSymlinks); }
       
   245 
       
   246     inline static QString QT3_SUPPORT getSaveFileName(const QString &dir,
       
   247                                                     const QString &filter = QString(),
       
   248                                                     QWidget *parent = 0, const char* name = 0,
       
   249                                                     const QString &caption = QString(),
       
   250                                                     QString *selectedFilter = 0,
       
   251                                                     bool resolveSymlinks = true)
       
   252         { Q_UNUSED(name);
       
   253           return getSaveFileName(parent, caption, dir, filter, selectedFilter,
       
   254                                  resolveSymlinks ? Option(0) : DontResolveSymlinks); }
       
   255 
       
   256     inline static QString QT3_SUPPORT getExistingDirectory(const QString &dir,
       
   257                                                          QWidget *parent = 0,
       
   258                                                          const char* name = 0,
       
   259                                                          const QString &caption = QString(),
       
   260                                                          bool dirOnly = true,
       
   261                                                          bool resolveSymlinks = true)
       
   262         { Q_UNUSED(name);
       
   263           return getExistingDirectory(parent, caption, dir,
       
   264                                       Options((resolveSymlinks ? Option(0) : DontResolveSymlinks)
       
   265                                       | (dirOnly ? ShowDirsOnly : Option(0)))); }
       
   266 
       
   267     inline static QStringList QT3_SUPPORT getOpenFileNames(const QString &filter,
       
   268                                                          const QString &dir = QString(),
       
   269                                                          QWidget *parent = 0,
       
   270                                                          const char* name = 0,
       
   271                                                          const QString &caption = QString(),
       
   272                                                          QString *selectedFilter = 0,
       
   273                                                          bool resolveSymlinks = true)
       
   274         { Q_UNUSED(name);
       
   275           return getOpenFileNames(parent, caption, dir, filter, selectedFilter,
       
   276                                   resolveSymlinks ? Option(0) : DontResolveSymlinks); }
       
   277 #endif // QT3_SUPPORT
       
   278 
       
   279 protected:
       
   280     QFileDialog(const QFileDialogArgs &args);
       
   281     void done(int result);
       
   282     void accept();
       
   283     void changeEvent(QEvent *e);
       
   284 
       
   285 private:
       
   286     Q_DECLARE_PRIVATE(QFileDialog)
       
   287     Q_DISABLE_COPY(QFileDialog)
       
   288 
       
   289     Q_PRIVATE_SLOT(d_func(), void _q_pathChanged(const QString &))
       
   290 
       
   291     Q_PRIVATE_SLOT(d_func(), void _q_navigateBackward())
       
   292     Q_PRIVATE_SLOT(d_func(), void _q_navigateForward())
       
   293     Q_PRIVATE_SLOT(d_func(), void _q_navigateToParent())
       
   294     Q_PRIVATE_SLOT(d_func(), void _q_createDirectory())
       
   295     Q_PRIVATE_SLOT(d_func(), void _q_showListView())
       
   296     Q_PRIVATE_SLOT(d_func(), void _q_showDetailsView())
       
   297     Q_PRIVATE_SLOT(d_func(), void _q_showContextMenu(const QPoint &))
       
   298     Q_PRIVATE_SLOT(d_func(), void _q_renameCurrent())
       
   299     Q_PRIVATE_SLOT(d_func(), void _q_deleteCurrent())
       
   300     Q_PRIVATE_SLOT(d_func(), void _q_showHidden())
       
   301     Q_PRIVATE_SLOT(d_func(), void _q_updateOkButton())
       
   302     Q_PRIVATE_SLOT(d_func(), void _q_currentChanged(const QModelIndex &index))
       
   303     Q_PRIVATE_SLOT(d_func(), void _q_enterDirectory(const QModelIndex &index))
       
   304     Q_PRIVATE_SLOT(d_func(), void _q_goToDirectory(const QString &path))
       
   305     Q_PRIVATE_SLOT(d_func(), void _q_useNameFilter(int index))
       
   306     Q_PRIVATE_SLOT(d_func(), void _q_selectionChanged())
       
   307     Q_PRIVATE_SLOT(d_func(), void _q_goToUrl(const QUrl &url))
       
   308     Q_PRIVATE_SLOT(d_func(), void _q_goHome())
       
   309     Q_PRIVATE_SLOT(d_func(), void _q_showHeader(QAction *))
       
   310     Q_PRIVATE_SLOT(d_func(), void _q_autoCompleteFileName(const QString &text))
       
   311     Q_PRIVATE_SLOT(d_func(), void _q_rowsInserted(const QModelIndex & parent))
       
   312     Q_PRIVATE_SLOT(d_func(), void _q_fileRenamed(const QString &path,
       
   313                 const QString oldName, const QString newName))
       
   314 #if defined(Q_WS_MAC)
       
   315     Q_PRIVATE_SLOT(d_func(), void _q_macRunNativeAppModalPanel())
       
   316 #endif
       
   317 };
       
   318 
       
   319 inline void QFileDialog::setDirectory(const QDir &adirectory)
       
   320 { setDirectory(adirectory.absolutePath()); }
       
   321 
       
   322 Q_DECLARE_OPERATORS_FOR_FLAGS(QFileDialog::Options)
       
   323 
       
   324 #endif // QT_NO_FILEDIALOG
       
   325 
       
   326 QT_END_NAMESPACE
       
   327 
       
   328 QT_END_HEADER
       
   329 
       
   330 #endif // QFILEDIALOG_H