Ignore:
Timestamp:
Feb 11, 2010, 11:19:06 PM (15 years ago)
Author:
Dmitry A. Kuminov
Message:

trunk: Merged in qt 4.6.1 sources.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk

  • trunk/src/gui/dialogs/qfiledialog.cpp

    r172 r561  
    22**
    33** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
    4 ** Contact: Qt Software Information (qt-info@nokia.com)
     4** All rights reserved.
     5** Contact: Nokia Corporation (qt-info@nokia.com)
    56**
    67** This file is part of the QtGui module of the Qt Toolkit.
     
    2122** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
    2223**
    23 ** In addition, as a special exception, Nokia gives you certain
    24 ** additional rights. These rights are described in the Nokia Qt LGPL
    25 ** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
    26 ** package.
     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.
    2727**
    2828** GNU General Public License Usage
     
    3434** met: http://www.gnu.org/copyleft/gpl.html.
    3535**
    36 ** If you are unsure which license is appropriate for your use, please
    37 ** contact the sales department at qt-sales@nokia.com.
     36** If you have questions regarding the use of this file, please contact
     37** Nokia at qt-info@nokia.com.
    3838** $QT_END_LICENSE$
    3939**
     
    5959#include <qapplication.h>
    6060#include <qstylepainter.h>
    61 #ifndef Q_OS_WINCE
     61#if !defined(Q_WS_WINCE) && !defined(Q_OS_SYMBIAN)
    6262#include "ui_qfiledialog.h"
    6363#else
    64 #include "ui_qfiledialog_wince.h"
     64#define Q_EMBEDDED_SMALLSCREEN
     65#include "ui_qfiledialog_embedded.h"
     66#if defined(Q_OS_WINCE)
    6567extern bool qt_priv_ptr_valid;
     68#endif
    6669#endif
    6770
     
    9093  \class QFileDialog
    9194  \brief The QFileDialog class provides a dialog that allow users to select files or directories.
    92   \ingroup dialogs
    93   \mainclass
     95  \ingroup standard-dialogs
     96
    9497
    9598  The QFileDialog class enables a user to traverse the file system in
     
    97100
    98101  The easiest way to create a QFileDialog is to use the static
    99   functions. On Windows, these static functions will call the native
    100   Windows file dialog, and on Mac OS X these static function will call
    101   the native Mac OS X file dialog.
     102  functions. On Windows, Mac OS X, KDE and GNOME, these static functions will
     103  call the native file dialog when possible.
    102104
    103105  \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 0
     
    211213    \enum QFileDialog::Option
    212214
    213     \value ShowDirsOnly Only show directories in the file dialog. By default both files and
    214     directories are shown. (Valid only in the \l Directory file mode.)
    215     \value DontResolveSymlinks Don't resolve symlinks in the file dialog. By default symlinks
    216     are resolved.
    217     \value DontConfirmOverwrite Don't ask for confirmation if an existing file is selected.
    218     By default confirmation is requested.
    219     \value DontUseNativeDialog Don't use the native file dialog. By default on Mac OS X and Windows,
    220     the native file dialog is used unless you use a subclass of QFileDialog that contains the
    221     Q_OBJECT macro.
     215    \value ShowDirsOnly Only show directories in the file dialog. By
     216    default both files and directories are shown. (Valid only in the
     217    \l Directory file mode.)
     218
     219    \value DontResolveSymlinks Don't resolve symlinks in the file
     220    dialog. By default symlinks are resolved.
     221
     222    \value DontConfirmOverwrite Don't ask for confirmation if an
     223    existing file is selected.  By default confirmation is requested.
     224
     225    \value DontUseNativeDialog Don't use the native file dialog. By
     226    default, the native file dialog is used unless you use a subclass
     227    of QFileDialog that contains the Q_OBJECT macro.
     228
    222229    \value ReadOnly Indicates that the model is readonly.
     230
    223231    \value HideNameFilterDetails Indicates if the is hidden or not.
    224 
    225232    This value is obsolete and does nothing since Qt 4.5:
    226233
    227     \value DontUseSheet In previous versions of Qt, the static functions would
    228     create a sheet by default if the static function was given a parent. This
    229     is no longer supported in Qt 4.5, The static functions will always be an
    230     application modal dialog. If you want to use sheets, use
    231     QFileDialog::open() instead.
     234    \value DontUseSheet In previous versions of Qt, the static
     235    functions would create a sheet by default if the static function
     236    was given a parent. This is no longer supported in Qt 4.5, The
     237    static functions will always be an application modal dialog. If
     238    you want to use sheets, use QFileDialog::open() instead.
    232239
    233240*/
     
    311318    Q_D(QFileDialog);
    312319    d->init();
     320    d->lineEdit()->selectAll();
    313321}
    314322
     
    328336    Q_D(QFileDialog);
    329337    d->init(directory, filter, caption);
     338    d->lineEdit()->selectAll();
    330339}
    331340
     
    355364    settings.setValue(QLatin1String("filedialog"), saveState());
    356365#endif
    357     delete d->qFileDialogUi;
    358366    d->deleteNativeDialog_sys();
    359367}
     
    390398
    391399static const qint32 QFileDialogMagic = 0xbe;
     400
     401const char *qt_file_dialog_filter_reg_exp =
     402"^(.*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$";
    392403
    393404/*!
     
    487498}
    488499
     500QFileDialogPrivate::QFileDialogPrivate()
     501    :
     502#ifndef QT_NO_PROXYMODEL
     503        proxyModel(0),
     504#endif
     505        model(0),
     506        fileMode(QFileDialog::AnyFile),
     507        acceptMode(QFileDialog::AcceptOpen),
     508        currentHistoryLocation(-1),
     509        renameAction(0),
     510        deleteAction(0),
     511        showHiddenAction(0),
     512        useDefaultCaption(true),
     513        defaultFileTypes(true),
     514        fileNameLabelExplicitlySat(false),
     515        nativeDialogInUse(false),
     516#ifdef Q_WS_MAC
     517        mDelegate(0),
     518#ifndef QT_MAC_USE_COCOA
     519        mDialog(0),
     520        mDialogStarted(false),
     521        mDialogClosed(true),
     522#endif
     523#endif
     524        qFileDialogUi(0)
     525{
     526}
     527
     528QFileDialogPrivate::~QFileDialogPrivate()
     529{
     530}
     531
    489532void QFileDialogPrivate::retranslateWindowTitle()
    490533{
     
    567610
    568611/*!
    569     Sets the given \a option to be enabled if \a on is true;
    570     otherwise, clears the given \a option.
     612    \since 4.5
     613    Sets the given \a option to be enabled if \a on is true; otherwise,
     614    clears the given \a option.
    571615
    572616    \sa options, testOption()
     
    639683    \since 4.5
    640684
    641     Opens the dialog and connects its accepted() signal to the slot specified
    642     by \a receiver and \a member.
     685    This function connects one of its signals to the slot specified by \a receiver
     686    and \a member. The specific signal depends is filesSelected() if fileMode is
     687    ExistingFiles and fileSelected() if fileMode is anything else.
    643688
    644689    The signal will be disconnected from the slot when the dialog is closed.
     
    647692{
    648693    Q_D(QFileDialog);
    649     const char *signal = (fileMode() == ExistingFiles) ? SIGNAL(filesSelected(const QStringList&))
    650                                                        : SIGNAL(fileSelected(const QString&));
     694    const char *signal = (fileMode() == ExistingFiles) ? SIGNAL(filesSelected(QStringList))
     695                                                       : SIGNAL(fileSelected(QString));
    651696    connect(this, signal, receiver, member);
    652697    d->signalToDisconnectOnClose = signal;
     
    694739void QFileDialogPrivate::_q_goToUrl(const QUrl &url)
    695740{
    696     QModelIndex idx = model->index(url.toLocalFile());
     741    //The shortcut in the side bar may have a parent that is not fetched yet (e.g. an hidden file)
     742    //so we force the fetching
     743    QFileSystemModelPrivate::QFileSystemNode *node = model->d_func()->node(url.toLocalFile(), true);
     744    QModelIndex idx =  model->d_func()->index(node);
    697745    _q_enterDirectory(idx);
    698746}
     
    730778    d->qFileDialogUi->newFolderButton->setEnabled(d->model->flags(root) & Qt::ItemIsDropEnabled);
    731779    if (root != d->rootIndex()) {
    732 #ifndef QT_NO_COMPLETER
     780#ifndef QT_NO_FSCOMPLETER
    733781    if (directory.endsWith(QLatin1Char('/')))
    734782        d->completer->setCompletionPrefix(newDirectory);
     
    775823
    776824    QModelIndex index = d->model->index(filename);
     825    QString file;
    777826    if (!index.isValid()) {
    778827        // save as dialog where we want to input a default value
     
    789838                text = text.remove(0,1);
    790839        }
    791         if (!isVisible() || !d->lineEdit()->hasFocus())
    792             d->lineEdit()->setText(text);
     840        file = text;
    793841    } else {
    794         d->qFileDialogUi->listView->selectionModel()->clear();
    795         if (!isVisible() || !d->lineEdit()->hasFocus())
    796             d->lineEdit()->setText(index.data().toString());
    797     }
     842        file = index.data().toString();
     843    }
     844    d->qFileDialogUi->listView->selectionModel()->clear();
     845    if (!isVisible() || !d->lineEdit()->hasFocus())
     846        d->lineEdit()->setText(file);
    798847}
    799848
     
    836885            // and on Windows it already ends with slash.
    837886            QString path = rootPath();
    838             if (!path.endsWith(QLatin1String("/")))
    839                 path += QLatin1String("/");
     887            if (!path.endsWith(QLatin1Char('/')))
     888                path += QLatin1Char('/');
    840889            path += name;
    841890            files.append(path);
     
    9581007    Q_D(QFileDialog);
    9591008    d->defaultFileTypes = (filters == QStringList(QFileDialog::tr("All Files (*)")));
    960     d->nameFilters = filters;
     1009    QStringList cleanedFilters;
     1010    for (int i = 0; i < filters.count(); ++i) {
     1011        cleanedFilters << filters[i].simplified();
     1012    }
     1013    d->nameFilters = cleanedFilters;
    9611014
    9621015    if (d->nativeDialogInUse){
    963         d->setNameFilters_sys(filters);
     1016        d->setNameFilters_sys(cleanedFilters);
    9641017        return;
    9651018    }
    9661019
    9671020    d->qFileDialogUi->fileTypeCombo->clear();
    968     if (filters.isEmpty())
     1021    if (cleanedFilters.isEmpty())
    9691022        return;
    9701023
    9711024    if (testOption(HideNameFilterDetails)) {
    9721025        QStringList strippedFilters;
    973         for (int i = 0; i < filters.count(); ++i) {
    974             strippedFilters.append(filters[i].mid(0, filters[i].indexOf(QLatin1String(" ("))));
     1026        QRegExp r(QString::fromLatin1(qt_file_dialog_filter_reg_exp));
     1027        for (int i = 0; i < cleanedFilters.count(); ++i) {
     1028            QString filterName;
     1029            int index = r.indexIn(cleanedFilters[i]);
     1030            if (index >= 0)
     1031                filterName = r.cap(1);
     1032            strippedFilters.append(filterName.simplified());
    9751033        }
    9761034        d->qFileDialogUi->fileTypeCombo->addItems(strippedFilters);
    9771035    } else {
    978         d->qFileDialogUi->fileTypeCombo->addItems(filters);
     1036        d->qFileDialogUi->fileTypeCombo->addItems(cleanedFilters);
    9791037    }
    9801038    d->_q_useNameFilter(0);
     
    14341492    Q_D(QFileDialog);
    14351493    d->model->setIconProvider(provider);
     1494    //It forces the refresh of all entries in the side bar, then we can get new icons
     1495    d->qFileDialogUi->sidebar->setUrls(d->qFileDialogUi->sidebar->urls());
    14361496}
    14371497
     
    15301590
    15311591/*!
    1532   This is a convenience static function that returns an existing file
    1533   selected by the user. If the user presses Cancel, it returns a null
    1534   string.
    1535 
    1536   \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 8
    1537 
    1538   The function creates a modal file dialog with the given \a parent widget.
    1539   If the parent is not 0, the dialog will be shown centered over the
    1540   parent widget.
    1541 
    1542   The file dialog's working directory will be set to \a dir.  If \a
    1543   dir includes a file name, the file will be selected. Only files
    1544   that match the given \a filter are shown. The filter selected is
    1545   set to \a selectedFilter. The parameters \a dir, \a
    1546   selectedFilter, and \a filter may be empty strings. If you want
    1547   multiple filters, separate them with ';;', for example:
    1548 
    1549   \code
     1592    This is a convenience static function that returns an existing file
     1593    selected by the user. If the user presses Cancel, it returns a null string.
     1594
     1595    \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 8
     1596
     1597    The function creates a modal file dialog with the given \a parent widget.
     1598    If \a parent is not 0, the dialog will be shown centered over the parent
     1599    widget.
     1600
     1601    The file dialog's working directory will be set to \a dir. If \a dir
     1602    includes a file name, the file will be selected. Only files that match the
     1603    given \a filter are shown. The filter selected is set to \a selectedFilter.
     1604    The parameters \a dir, \a selectedFilter, and \a filter may be empty
     1605    strings. If you want multiple filters, separate them with ';;', for
     1606    example:
     1607
     1608    \code
    15501609    "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"
    1551   \endcode
    1552 
    1553   The \a options argument holds various
    1554   options about how to run the dialog, see the QFileDialog::Option enum for
    1555   more information on the flags you can pass.
    1556 
    1557   The dialog's caption is set to \a caption. If \a caption is not
    1558   specified then a default caption will be used.
    1559 
    1560   Under Windows and Mac OS X, this static function will use the native
    1561   file dialog and not a QFileDialog.
    1562 
    1563   Note that on Windows the dialog will spin a blocking modal event loop
    1564   that will not dispatch any QTimers, and if parent is not 0 then it will
    1565   position the dialog just under the parent's title bar.
    1566 
    1567   Under Unix/X11, the normal behavior of the file dialog is to resolve
    1568   and follow symlinks. For example, if \c{/usr/tmp} is a symlink to
    1569   \c{/var/tmp}, the file dialog will change to \c{/var/tmp} after
    1570   entering \c{/usr/tmp}. If \a options includes DontResolveSymlinks,
    1571   the file dialog will treat symlinks as regular directories.
    1572 
    1573   \warning Do not delete \a parent during the execution of the dialog.
    1574            If you want to do this, you should create the dialog
    1575            yourself using one of the QFileDialog constructors.
    1576 
    1577   \sa getOpenFileNames(), getSaveFileName(), getExistingDirectory()
     1610    \endcode
     1611
     1612    The \a options argument holds various options about how to run the dialog,
     1613    see the QFileDialog::Option enum for more information on the flags you can
     1614    pass.
     1615
     1616    The dialog's caption is set to \a caption. If \a caption is not specified
     1617    then a default caption will be used.
     1618
     1619    On Windows and Mac OS X, this static function will use the native file
     1620    dialog and not a QFileDialog.
     1621
     1622    On Windows the dialog will spin a blocking modal event loop that will not
     1623    dispatch any QTimers, and if \a parent is not 0 then it will position the
     1624    dialog just below the parent's title bar.
     1625
     1626    On Unix/X11, the normal behavior of the file dialog is to resolve and
     1627    follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp},
     1628    the file dialog will change to \c{/var/tmp} after entering \c{/usr/tmp}. If
     1629    \a options includes DontResolveSymlinks, the file dialog will treat
     1630    symlinks as regular directories.
     1631
     1632    \warning Do not delete \a parent during the execution of the dialog. If you
     1633    want to do this, you should create the dialog yourself using one of the
     1634    QFileDialog constructors.
     1635
     1636    \sa getOpenFileNames(), getSaveFileName(), getExistingDirectory()
    15781637*/
    15791638QString QFileDialog::getOpenFileName(QWidget *parent,
     
    16131672
    16141673/*!
    1615   This is a convenience static function that will return one or more
    1616   existing files selected by the user.
    1617 
    1618   \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 9
    1619 
    1620   This function creates a modal file dialog with the given \a parent
    1621   widget. If the parent is not 0, the dialog will be shown centered
    1622   over the parent widget.
    1623 
    1624   The file dialog's working directory will be set to \a dir. If \a
    1625   dir includes a file name, the file will be selected. The filter
    1626   is set to \a filter so that only those files which match the filter
    1627   are shown. The filter selected is set to \a selectedFilter. The parameters
    1628   \a dir, \a selectedFilter and \a filter may be empty strings. If you
    1629   need multiple filters, separate them with ';;', for instance:
    1630 
    1631   \code
     1674    This is a convenience static function that will return one or more existing
     1675    files selected by the user.
     1676
     1677    \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 9
     1678
     1679    This function creates a modal file dialog with the given \a parent widget.
     1680    If \a parent is not 0, the dialog will be shown centered over the parent
     1681    widget.
     1682
     1683    The file dialog's working directory will be set to \a dir. If \a dir
     1684    includes a file name, the file will be selected. The filter is set to
     1685    \a filter so that only those files which match the filter are shown. The
     1686    filter selected is set to \a selectedFilter. The parameters \a dir,
     1687    \a selectedFilter and \a filter may be empty strings. If you need multiple
     1688    filters, separate them with ';;', for instance:
     1689
     1690    \code
    16321691    "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"
    1633   \endcode
    1634 
    1635   The dialog's caption is set to \a caption. If \a caption is not
    1636   specified then a default caption will be used.
    1637 
    1638   Under Windows and Mac OS X, this static function will use the native
    1639   file dialog and not a QFileDialog. On Mac OS X, the \a dir argument
    1640   is ignored, the native dialog always displays the last visited directory.
    1641 
    1642   Note that on Windows the dialog will spin a blocking modal event loop
    1643   that will not dispatch any QTimers, and if parent is not 0 then it will
    1644   position the dialog just under the parent's title bar.
    1645 
    1646   Under Unix/X11, the normal behavior of the file dialog is to resolve
    1647   and follow symlinks. For example, if \c{/usr/tmp} is a symlink to
    1648   \c{/var/tmp}, the file dialog will change to \c{/var/tmp} after
    1649   entering \c{/usr/tmp}. The \a options argument holds various
    1650   options about how to run the dialog, see the QFileDialog::Option enum for
    1651   more information on the flags you can pass.
    1652 
    1653   Note that if you want to iterate over the list of files, you should
    1654   iterate over a copy. For example:
     1692    \endcode
     1693
     1694    The dialog's caption is set to \a caption. If \a caption is not specified
     1695    then a default caption will be used.
     1696
     1697    On Windows and Mac OS X, this static function will use the native file
     1698    dialog and not a QFileDialog.
     1699
     1700    On Windows the dialog will spin a blocking modal event loop that will not
     1701    dispatch any QTimers, and if \a parent is not 0 then it will position the
     1702    dialog just below the parent's title bar.
     1703
     1704    On Unix/X11, the normal behavior of the file dialog is to resolve and
     1705    follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp},
     1706    the file dialog will change to \c{/var/tmp} after entering \c{/usr/tmp}.
     1707    The \a options argument holds various options about how to run the dialog,
     1708    see the QFileDialog::Option enum for more information on the flags you can
     1709    pass.
     1710
     1711    \note If you want to iterate over the list of files, you should iterate
     1712    over a copy. For example:
    16551713
    16561714    \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 10
    16571715
    1658   \warning Do not delete \a parent during the execution of the dialog.
    1659            If you want to do this, you should create the dialog
    1660            yourself using one of the QFileDialog constructors.
    1661 
    1662   \sa getOpenFileName(), getSaveFileName(), getExistingDirectory()
     1716    \warning Do not delete \a parent during the execution of the dialog. If you
     1717    want to do this, you should create the dialog yourself using one of the
     1718    QFileDialog constructors.
     1719
     1720    \sa getOpenFileName(), getSaveFileName(), getExistingDirectory()
    16631721*/
    16641722QStringList QFileDialog::getOpenFileNames(QWidget *parent,
     
    16691727                                          Options options)
    16701728{
    1671     if (qt_filedialog_open_filenames_hook)
     1729    if (qt_filedialog_open_filenames_hook && !(options & DontUseNativeDialog))
    16721730        return qt_filedialog_open_filenames_hook(parent, caption, dir, filter, selectedFilter, options);
    16731731    QFileDialogArgs args;
     
    16991757
    17001758/*!
    1701   This is a convenience static function that will return a file name
    1702   selected by the user. The file does not have to exist.
    1703 
    1704   It creates a modal file dialog with the given \a parent widget. If the
    1705   parent is not 0, the dialog will be shown centered over the parent
    1706   widget.
    1707 
    1708   \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 11
    1709 
    1710   The file dialog's working directory will be set to \a dir. If \a
    1711   dir includes a file name, the file will be selected. Only files that
    1712   match the \a filter are shown. The filter selected is set to
    1713   \a selectedFilter. The parameters \a dir, \a selectedFilter, and
    1714   \a filter may be empty strings. Multiple filters are separated with ';;'.
    1715   For instance:
    1716 
    1717   \code
     1759    This is a convenience static function that will return a file name selected
     1760    by the user. The file does not have to exist.
     1761
     1762    It creates a modal file dialog with the given \a parent widget. If
     1763    \a parent is not 0, the dialog will be shown centered over the parent
     1764    widget.
     1765
     1766    \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 11
     1767
     1768    The file dialog's working directory will be set to \a dir. If \a dir
     1769    includes a file name, the file will be selected. Only files that match the
     1770    \a filter are shown. The filter selected is set to \a selectedFilter. The
     1771    parameters \a dir, \a selectedFilter, and \a filter may be empty strings.
     1772    Multiple filters are separated with ';;'. For instance:
     1773
     1774    \code
    17181775    "Images (*.png *.xpm *.jpg);;Text files (*.txt);;XML files (*.xml)"
    1719   \endcode
    1720 
    1721   The \a options argument holds various
    1722   options about how to run the dialog, see the QFileDialog::Option enum for
    1723   more information on the flags you can pass.
    1724 
    1725   The default filter can be chosen by setting \a selectedFilter to the desired value.
    1726 
    1727   The dialog's caption is set to \a caption. If \a caption is not
    1728   specified then a default caption will be used.
    1729 
    1730   Under Windows and Mac OS X, this static function will use the native
    1731   file dialog and not a QFileDialog.
    1732 
    1733   Note that on Windows the dialog will spin a blocking modal event loop
    1734   that will not dispatch any QTimers, and if parent is not 0 then it will
    1735   position the dialog just under the parent's title bar.
    1736   On Mac OS X, the filter argument is ignored.
    1737 
    1738   Under Unix/X11, the normal behavior of the file dialog is to resolve
    1739   and follow symlinks. For example, if \c{/usr/tmp} is a symlink to
    1740   \c{/var/tmp}, the file dialog will change to \c{/var/tmp} after
    1741   entering \c{/usr/tmp}. If \a options includes DontResolveSymlinks,
    1742   the file dialog will treat symlinks as regular directories.
    1743 
    1744   \warning Do not delete \a parent during the execution of the dialog.
    1745            If you want to do this, you should create the dialog
    1746            yourself using one of the QFileDialog constructors.
    1747 
    1748   \sa getOpenFileName(), getOpenFileNames(), getExistingDirectory()
     1776    \endcode
     1777
     1778    The \a options argument holds various options about how to run the dialog,
     1779    see the QFileDialog::Option enum for more information on the flags you can
     1780    pass.
     1781
     1782    The default filter can be chosen by setting \a selectedFilter to the
     1783    desired value.
     1784
     1785    The dialog's caption is set to \a caption. If \a caption is not specified,
     1786    a default caption will be used.
     1787
     1788    On Windows and Mac OS X, this static function will use the native file
     1789    dialog and not a QFileDialog.
     1790
     1791    On Windows the dialog will spin a blocking modal event loop that will not
     1792    dispatch any QTimers, and if \a parent is not 0 then it will position the
     1793    dialog just below the parent's title bar. On Mac OS X, with its native file
     1794    dialog, the filter argument is ignored.
     1795
     1796    On Unix/X11, the normal behavior of the file dialog is to resolve and
     1797    follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp},
     1798    the file dialog will change to \c{/var/tmp} after entering \c{/usr/tmp}. If
     1799    \a options includes DontResolveSymlinks the file dialog will treat symlinks
     1800    as regular directories.
     1801
     1802    \warning Do not delete \a parent during the execution of the dialog. If you
     1803    want to do this, you should create the dialog yourself using one of the
     1804    QFileDialog constructors.
     1805
     1806    \sa getOpenFileName(), getOpenFileNames(), getExistingDirectory()
    17491807*/
    17501808QString QFileDialog::getSaveFileName(QWidget *parent,
     
    17551813                                     Options options)
    17561814{
    1757     if (qt_filedialog_save_filename_hook)
     1815    if (qt_filedialog_save_filename_hook && !(options & DontUseNativeDialog))
    17581816        return qt_filedialog_save_filename_hook(parent, caption, dir, filter, selectedFilter, options);
    17591817    QFileDialogArgs args;
     
    17871845
    17881846/*!
    1789   This is a convenience static function that will return an existing
    1790   directory selected by the user.
    1791 
    1792   \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 12
    1793 
    1794   This function creates a modal file dialog with the given \a parent
    1795   widget. If the parent is not 0, the dialog will be shown centered over
    1796   the parent widget.
    1797 
    1798   The dialog's working directory is set to \a dir, and the caption is
    1799   set to \a caption. Either of these may be an empty string in which case
    1800   the current directory and a default caption will be used
    1801   respectively.
    1802 
    1803   The \a options argument holds various
    1804   options about how to run the dialog, see the QFileDialog::Option enum for
    1805   more information on the flags you can pass. Note that \l{QFileDialog::}{ShowDirsOnly}
    1806   must be set to ensure a native file dialog.
    1807 
    1808   Under Windows and Mac OS X, this static function will use the native
    1809   file dialog and not a QFileDialog. On Mac OS X, the \a dir argument
    1810   is ignored, the native dialog always displays the last visited directory.
    1811   On Windows CE, if the device has no native file dialog, a QFileDialog
    1812   will be used.
    1813 
    1814   Under Unix/X11, the normal behavior of the file dialog is to resolve
    1815   and follow symlinks. For example, if \c{/usr/tmp} is a symlink to
    1816   \c{/var/tmp}, the file dialog will change to \c{/var/tmp} after
    1817   entering \c{/usr/tmp}. If \a options includes DontResolveSymlinks,
    1818   the file dialog will treat symlinks as regular directories.
    1819 
    1820   Note that on Windows the dialog will spin a blocking modal event loop
    1821   that will not dispatch any QTimers, and if parent is not 0 then it will
    1822   position the dialog just under the parent's title bar.
    1823 
    1824   \warning Do not delete \a parent during the execution of the dialog.
    1825            If you want to do this, you should create the dialog
    1826            yourself using one of the QFileDialog constructors.
    1827 
    1828   \sa getOpenFileName(), getOpenFileNames(), getSaveFileName()
     1847    This is a convenience static function that will return an existing
     1848    directory selected by the user.
     1849
     1850    \snippet doc/src/snippets/code/src_gui_dialogs_qfiledialog.cpp 12
     1851
     1852    This function creates a modal file dialog with the given \a parent widget.
     1853    If \a parent is not 0, the dialog will be shown centered over the parent
     1854    widget.
     1855
     1856    The dialog's working directory is set to \a dir, and the caption is set to
     1857    \a caption. Either of these may be an empty string in which case the
     1858    current directory and a default caption will be used respectively.
     1859
     1860    The \a options argument holds various options about how to run the dialog,
     1861    see the QFileDialog::Option enum for more information on the flags you can
     1862    pass. To ensure a native file dialog, \l{QFileDialog::}{ShowDirsOnly} must
     1863    be set.
     1864
     1865    On Windows and Mac OS X, this static function will use the native file
     1866    dialog and not a QFileDialog. On Windows CE, if the device has no native
     1867    file dialog, a QFileDialog will be used.
     1868
     1869    On Unix/X11, the normal behavior of the file dialog is to resolve and
     1870    follow symlinks. For example, if \c{/usr/tmp} is a symlink to \c{/var/tmp},
     1871    the file dialog will change to \c{/var/tmp} after entering \c{/usr/tmp}. If
     1872    \a options includes DontResolveSymlinks, the file dialog will treat
     1873    symlinks as regular directories.
     1874
     1875    On Windows the dialog will spin a blocking modal event loop that will not
     1876    dispatch any QTimers, and if \a parent is not 0 then it will position the
     1877    dialog just below the parent's title bar.
     1878
     1879    \warning Do not delete \a parent during the execution of the dialog. If you
     1880    want to do this, you should create the dialog yourself using one of the
     1881    QFileDialog constructors.
     1882
     1883    \sa getOpenFileName(), getOpenFileNames(), getSaveFileName()
    18291884*/
    18301885QString QFileDialog::getExistingDirectory(QWidget *parent,
     
    18331888                                          Options options)
    18341889{
    1835     if (qt_filedialog_existing_directory_hook)
     1890    if (qt_filedialog_existing_directory_hook && !(options & DontUseNativeDialog))
    18361891        return qt_filedialog_existing_directory_hook(parent, caption, dir, options);
    18371892    QFileDialogArgs args;
     
    18441899#if defined(Q_WS_WIN)
    18451900    if (qt_use_native_dialogs && !(args.options & DontUseNativeDialog) && (options & ShowDirsOnly)
    1846 #if defined(Q_OS_WINCE)
     1901#if defined(Q_WS_WINCE)
    18471902        && qt_priv_ptr_valid
    18481903#endif
     
    20582113#endif
    20592114
    2060 #ifdef Q_OS_WINCE
     2115#if defined(Q_EMBEDDED_SMALLSCREEN)
    20612116    qFileDialogUi->lookInLabel->setVisible(false);
    20622117    qFileDialogUi->fileNameLabel->setVisible(false);
     
    20902145    model->setNameFilterDisables(false);
    20912146#endif
    2092     QFileDialog::connect(model, SIGNAL(fileRenamed(const QString &, const QString &, const QString &)), q, SLOT(_q_fileRenamed(const QString &, const QString &, const QString &)));
    2093     QFileDialog::connect(model, SIGNAL(rootPathChanged(const QString &)),
    2094             q, SLOT(_q_pathChanged(const QString &)));
    2095     QFileDialog::connect(model, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
    2096             q, SLOT(_q_rowsInserted(const QModelIndex &)));
     2147    model->d_func()->disableRecursiveSort = true;
     2148    QFileDialog::connect(model, SIGNAL(fileRenamed(QString,QString,QString)), q, SLOT(_q_fileRenamed(QString,QString,QString)));
     2149    QFileDialog::connect(model, SIGNAL(rootPathChanged(QString)),
     2150            q, SLOT(_q_pathChanged(QString)));
     2151    QFileDialog::connect(model, SIGNAL(rowsInserted(QModelIndex,int,int)),
     2152            q, SLOT(_q_rowsInserted(QModelIndex)));
    20972153    model->setReadOnly(false);
    20982154
    2099     qFileDialogUi = new Ui_QFileDialog();
     2155    qFileDialogUi.reset(new Ui_QFileDialog());
    21002156    qFileDialogUi->setupUi(q);
    21012157
     
    21042160                     << QUrl::fromLocalFile(QDir::homePath());
    21052161    qFileDialogUi->sidebar->init(model, initialBookmarks);
    2106     QFileDialog::connect(qFileDialogUi->sidebar, SIGNAL(goToUrl(const QUrl &)),
    2107                          q, SLOT(_q_goToUrl(const QUrl &)));
     2162    QFileDialog::connect(qFileDialogUi->sidebar, SIGNAL(goToUrl(QUrl)),
     2163                         q, SLOT(_q_goToUrl(QUrl)));
    21082164
    21092165    QObject::connect(qFileDialogUi->buttonBox, SIGNAL(accepted()), q, SLOT(accept()));
     
    21222178    qFileDialogUi->fileNameLabel->setBuddy(qFileDialogUi->fileNameEdit);
    21232179#endif
    2124 #ifndef QT_NO_COMPLETER
    2125     completer = new QFSCompletor(model, q);
     2180#ifndef QT_NO_FSCOMPLETER
     2181    completer = new QFSCompleter(model, q);
    21262182    qFileDialogUi->fileNameEdit->setCompleter(completer);
    2127     completer->sourceModel = model;
    21282183    QObject::connect(qFileDialogUi->fileNameEdit, SIGNAL(textChanged(QString)),
    21292184            q, SLOT(_q_autoCompleteFileName(QString)));
    2130 #endif // QT_NO_COMPLETER
     2185#endif // QT_NO_FSCOMPLETER
    21312186    QObject::connect(qFileDialogUi->fileNameEdit, SIGNAL(textChanged(QString)),
    21322187                     q, SLOT(_q_updateOkButton()));
     
    21402195    QObject::connect(qFileDialogUi->fileTypeCombo, SIGNAL(activated(int)),
    21412196                     q, SLOT(_q_useNameFilter(int)));
    2142     QObject::connect(qFileDialogUi->fileTypeCombo, SIGNAL(activated(const QString &)),
    2143                      q, SIGNAL(filterSelected(const QString &)));
     2197    QObject::connect(qFileDialogUi->fileTypeCombo, SIGNAL(activated(QString)),
     2198                     q, SIGNAL(filterSelected(QString)));
    21442199
    21452200    qFileDialogUi->listView->init(this);
     
    21672222    QActionGroup *showActionGroup = new QActionGroup(q);
    21682223    showActionGroup->setExclusive(false);
    2169     QObject::connect(showActionGroup, SIGNAL(triggered(QAction *)),
    2170                      q, SLOT(_q_showHeader(QAction *)));;
     2224    QObject::connect(showActionGroup, SIGNAL(triggered(QAction*)),
     2225                     q, SLOT(_q_showHeader(QAction*)));;
    21712226
    21722227    QAbstractItemModel *abstractModel = model;
     
    21822237    }
    21832238
    2184     QItemSelectionModel *selModel = qFileDialogUi->treeView->selectionModel();
     2239    QScopedPointer<QItemSelectionModel> selModel(qFileDialogUi->treeView->selectionModel());
    21852240    qFileDialogUi->treeView->setSelectionModel(qFileDialogUi->listView->selectionModel());
    2186     delete selModel;
     2241
    21872242    QObject::connect(qFileDialogUi->treeView, SIGNAL(activated(QModelIndex)),
    21882243                     q, SLOT(_q_enterDirectory(QModelIndex)));
     
    21972252    // Selections
    21982253    QItemSelectionModel *selections = qFileDialogUi->listView->selectionModel();
    2199     QObject::connect(selections, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
     2254    QObject::connect(selections, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
    22002255                     q, SLOT(_q_selectionChanged()));
    22012256    QObject::connect(selections, SIGNAL(currentChanged(QModelIndex,QModelIndex)),
     
    22352290    QModelIndex idx = d->rootIndex();
    22362291    if (d->proxyModel) {
    2237         disconnect(d->proxyModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
    2238             this, SLOT(_q_rowsInserted(const QModelIndex &)));
     2292        disconnect(d->proxyModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
     2293            this, SLOT(_q_rowsInserted(QModelIndex)));
    22392294    } else {
    2240         disconnect(d->model, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
    2241             this, SLOT(_q_rowsInserted(const QModelIndex &)));
     2295        disconnect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
     2296            this, SLOT(_q_rowsInserted(QModelIndex)));
    22422297    }
    22432298
     
    22482303        d->qFileDialogUi->listView->setModel(d->proxyModel);
    22492304        d->qFileDialogUi->treeView->setModel(d->proxyModel);
    2250 #ifndef QT_NO_COMPLETER
     2305#ifndef QT_NO_FSCOMPLETER
    22512306        d->completer->setModel(d->proxyModel);
    22522307        d->completer->proxyModel = d->proxyModel;
    22532308#endif
    2254         connect(d->proxyModel, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
    2255             this, SLOT(_q_rowsInserted(const QModelIndex &)));
     2309        connect(d->proxyModel, SIGNAL(rowsInserted(QModelIndex,int,int)),
     2310            this, SLOT(_q_rowsInserted(QModelIndex)));
    22562311    } else {
    22572312        d->proxyModel = 0;
    22582313        d->qFileDialogUi->listView->setModel(d->model);
    22592314        d->qFileDialogUi->treeView->setModel(d->model);
    2260 #ifndef QT_NO_COMPLETER
     2315#ifndef QT_NO_FSCOMPLETER
    22612316        d->completer->setModel(d->model);
    22622317        d->completer->sourceModel = d->model;
    22632318        d->completer->proxyModel = 0;
    22642319#endif
    2265         connect(d->model, SIGNAL(rowsInserted(const QModelIndex &, int, int)),
    2266             this, SLOT(_q_rowsInserted(const QModelIndex &)));
    2267     }
    2268     QItemSelectionModel *selModel = d->qFileDialogUi->treeView->selectionModel();
     2320        connect(d->model, SIGNAL(rowsInserted(QModelIndex,int,int)),
     2321            this, SLOT(_q_rowsInserted(QModelIndex)));
     2322    }
     2323    QScopedPointer<QItemSelectionModel> selModel(d->qFileDialogUi->treeView->selectionModel());
    22692324    d->qFileDialogUi->treeView->setSelectionModel(d->qFileDialogUi->listView->selectionModel());
    2270     delete selModel;
     2325
    22712326    d->setRootIndex(idx);
    22722327
    22732328    // reconnect selection
    22742329    QItemSelectionModel *selections = d->qFileDialogUi->listView->selectionModel();
    2275     QObject::connect(selections, SIGNAL(selectionChanged(const QItemSelection &, const QItemSelection &)),
     2330    QObject::connect(selections, SIGNAL(selectionChanged(QItemSelection,QItemSelection)),
    22762331                     this, SLOT(_q_selectionChanged()));
    22772332    QObject::connect(selections, SIGNAL(currentChanged(QModelIndex,QModelIndex)),
     
    26332688void QFileDialogPrivate::_q_autoCompleteFileName(const QString &text)
    26342689{
    2635     if (text.startsWith(QLatin1String("//")) || text.startsWith(QLatin1String("\\"))) {
     2690    if (text.startsWith(QLatin1String("//")) || text.startsWith(QLatin1Char('\\'))) {
    26362691        qFileDialogUi->listView->selectionModel()->clearSelection();
    26372692        return;
     
    26752730    QString lineEditText = lineEdit()->text();
    26762731
    2677     if (lineEditText.startsWith(QLatin1String("//")) || lineEditText.startsWith(QLatin1String("\\"))) {
     2732    if (lineEditText.startsWith(QLatin1String("//")) || lineEditText.startsWith(QLatin1Char('\\'))) {
    26782733        button->setEnabled(true);
    26792734        if (acceptMode == QFileDialog::AcceptSave)
    2680             button->setText(isOpenDirectory ? QFileDialog::tr("&Open") : acceptLabel);
     2735            button->setText(acceptLabel);
    26812736        return;
    26822737    }
     
    27752830    Q_Q(QFileDialog);
    27762831    // My Computer or a directory
    2777     QModelIndex sourceIndex = mapToSource(index);
     2832    QModelIndex sourceIndex = index.model() == proxyModel ? mapToSource(index) : index;
    27782833    QString path = sourceIndex.data(QFileSystemModel::FilePathRole).toString();
    27792834    if (path.isEmpty() || model->isDir(sourceIndex)) {
     
    28272882}
    28282883
    2829 const char *qt_file_dialog_filter_reg_exp =
    2830     "^([^()]*)\\(([a-zA-Z0-9_.*? +;#\\-\\[\\]@\\{\\}/!<>\\$%&=^~:\\|]*)\\)$";
    2831 
    28322884// Makes a list of filters from a normal filter string "Image Files (*.png *.jpg)"
    28332885QStringList qt_clean_filter_list(const QString &filter)
     
    30883140void QFileDialogListView::keyPressEvent(QKeyEvent *e)
    30893141{
    3090     if (!d_ptr->itemViewKeyboardEvent(e)) {
     3142#ifdef QT_KEYPAD_NAVIGATION
     3143    if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) {
    30913144        QListView::keyPressEvent(e);
    3092     }
     3145        return;
     3146    }
     3147#endif // QT_KEYPAD_NAVIGATION
     3148
     3149    if (!d_ptr->itemViewKeyboardEvent(e))
     3150        QListView::keyPressEvent(e);
    30933151    e->accept();
    30943152}
     
    31173175void QFileDialogTreeView::keyPressEvent(QKeyEvent *e)
    31183176{
    3119     if (!d_ptr->itemViewKeyboardEvent(e)) {
     3177#ifdef QT_KEYPAD_NAVIGATION
     3178    if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) {
    31203179        QTreeView::keyPressEvent(e);
    3121     }
     3180        return;
     3181    }
     3182#endif // QT_KEYPAD_NAVIGATION
     3183
     3184    if (!d_ptr->itemViewKeyboardEvent(e))
     3185        QTreeView::keyPressEvent(e);
    31223186    e->accept();
    31233187}
     
    31363200void QFileDialogLineEdit::keyPressEvent(QKeyEvent *e)
    31373201{
     3202#ifdef QT_KEYPAD_NAVIGATION
     3203    if (QApplication::navigationMode() == Qt::NavigationModeKeypadDirectional) {
     3204        QLineEdit::keyPressEvent(e);
     3205        return;
     3206    }
     3207#endif // QT_KEYPAD_NAVIGATION
     3208
    31383209    int key = e->key();
    31393210    QLineEdit::keyPressEvent(e);
     
    31473218}
    31483219
    3149 #ifndef QT_NO_COMPLETER
    3150 
    3151 QString QFSCompletor::pathFromIndex(const QModelIndex &index) const
     3220#ifndef QT_NO_FSCOMPLETER
     3221
     3222QString QFSCompleter::pathFromIndex(const QModelIndex &index) const
    31523223{
    31533224    const QFileSystemModel *dirModel;
     
    31643235}
    31653236
    3166 QStringList QFSCompletor::splitPath(const QString &path) const
     3237QStringList QFSCompleter::splitPath(const QString &path) const
    31673238{
    31683239    if (path.isEmpty())
     
    31713242    QString pathCopy = QDir::toNativeSeparators(path);
    31723243    QString sep = QDir::separator();
    3173 #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
     3244#if defined(Q_OS_SYMBIAN)
     3245    if (pathCopy == QLatin1String("\\"))
     3246        return QStringList(pathCopy);
     3247#elif defined(Q_OS_WIN) || defined(Q_OS_OS2)
    31743248    if (pathCopy == QLatin1String("\\") || pathCopy == QLatin1String("\\\\"))
    31753249        return QStringList(pathCopy);
     
    31813255#endif
    31823256
    3183     QRegExp re(QLatin1String("[") + QRegExp::escape(sep) + QLatin1String("]"));
    3184 
    3185 #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
     3257    QRegExp re(QLatin1Char('[') + QRegExp::escape(sep) + QLatin1Char(']'));
     3258
     3259#if defined(Q_OS_SYMBIAN)
     3260    QStringList parts = pathCopy.split(re, QString::SkipEmptyParts);
     3261    if (pathCopy.endsWith(sep))
     3262        parts.append(QString());
     3263#elif defined(Q_OS_WIN) || defined(Q_OS_OS2)
    31863264    QStringList parts = pathCopy.split(re, QString::SkipEmptyParts);
    31873265    if (!doubleSlash.isEmpty() && !parts.isEmpty())
     
    31953273#endif
    31963274
    3197 #if defined(Q_OS_WIN) || defined(Q_OS_OS2)
     3275#if defined(Q_OS_WIN) || defined(Q_OS_SYMBIAN) || defined(Q_OS_OS2)
    31983276    bool startsFromRoot = !parts.isEmpty() && parts[0].endsWith(QLatin1Char(':'));
    31993277#else
Note: See TracChangeset for help on using the changeset viewer.