VirtualBox

Changeset 51939 in vbox


Ignore:
Timestamp:
Jul 8, 2014 5:25:27 PM (10 years ago)
Author:
vboxsync
Message:

FE/Qt: Mac OS X: QIFileDialog bug-fixes.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIFileDialog.cpp

    r45437 r51939  
    345345#elif defined (Q_WS_MAC) && (QT_VERSION >= 0x040600)
    346346
    347     /* After 4.5 exec ignores the Qt::Sheet flag. See "New Ways of Using
    348      * Dialogs" in http://doc.trolltech.com/qq/QtQuarterly30.pdf why. Because
    349      * we are lazy, we recreate the old behavior. Unfortunately there is a bug
    350      * in Qt 4.5.x which result in showing the native & the Qt dialog at the
    351      * same time. */
    352     QFileDialog dlg (aParent, Qt::Sheet);
    353     dlg.setWindowTitle (aCaption);
    354     dlg.setDirectory (aDir);
    355     dlg.setResolveSymlinks (aResolveSymlinks);
    356     dlg.setFileMode (aDirOnly ? QFileDialog::DirectoryOnly : QFileDialog::Directory);
     347    /* After 4.5 exec ignores the Qt::Sheet flag.
     348     * See "New Ways of Using Dialogs" in http://doc.trolltech.com/qq/QtQuarterly30.pdf why.
     349     * We want the old behavior for file-save dialog. Unfortunately there is a bug in Qt 4.5.x
     350     * which result in showing the native & the Qt dialog at the same time. */
     351    QFileDialog dlg(aParent);
     352    dlg.setWindowTitle(aCaption);
     353    dlg.setDirectory(aDir);
     354    dlg.setResolveSymlinks(aResolveSymlinks);
     355    dlg.setFileMode(aDirOnly ? QFileDialog::DirectoryOnly : QFileDialog::Directory);
    357356
    358357    QEventLoop eventLoop;
    359358    QObject::connect(&dlg, SIGNAL(finished(int)),
    360359                     &eventLoop, SLOT(quit()));
    361     /* Use the new open call. */
    362360    dlg.open();
    363361    eventLoop.exec();
    364362
    365     return dlg.result() == QDialog::Accepted ? dlg.selectedFiles() [0] : QString::null;
     363    return dlg.result() == QDialog::Accepted ? dlg.selectedFiles().value(0, QString()) : QString();
    366364
    367365#else
     
    568566#elif defined (Q_WS_MAC) && (QT_VERSION >= 0x040600)
    569567
    570     /* After 4.5 exec ignores the Qt::Sheet flag. See "New Ways of Using
    571      * Dialogs" in http://doc.trolltech.com/qq/QtQuarterly30.pdf why. Because
    572      * we are lazy, we recreate the old behavior. Unfortunately there is a bug
    573      * in Qt 4.5.x which result in showing the native & the Qt dialog at the
    574      * same time. */
    575     QFileDialog dlg (aParent);
    576     dlg.setWindowTitle (aCaption);
    577     dlg.setDirectory (aStartWith);
    578     dlg.setFilter (aFilters);
    579     dlg.setFileMode (QFileDialog::QFileDialog::AnyFile);
    580     dlg.setAcceptMode (QFileDialog::AcceptSave);
     568    /* After 4.5 exec ignores the Qt::Sheet flag.
     569     * See "New Ways of Using Dialogs" in http://doc.trolltech.com/qq/QtQuarterly30.pdf why.
     570     * We want the old behavior for file-save dialog. Unfortunately there is a bug in Qt 4.5.x
     571     * which result in showing the native & the Qt dialog at the same time. */
     572    QFileDialog dlg(aParent);
     573    dlg.setWindowTitle(aCaption);
     574
     575    /* Some predictive algorithm which seems missed in native code. */
     576    QDir dir(aStartWith);
     577    while (!dir.isRoot() && !dir.exists())
     578        dir = QDir(QFileInfo(dir.absolutePath()).absolutePath());
     579    const QString strDirectory = dir.absolutePath();
     580    if (!strDirectory.isNull())
     581        dlg.setDirectory(strDirectory);
     582    if (strDirectory != aStartWith)
     583        dlg.selectFile(QFileInfo(aStartWith).absoluteFilePath());
     584
     585    dlg.setNameFilter(aFilters);
     586    dlg.setFileMode(QFileDialog::AnyFile);
     587    dlg.setAcceptMode(QFileDialog::AcceptSave);
    581588    if (aSelectedFilter)
    582         dlg.selectFilter (*aSelectedFilter);
    583     dlg.setResolveSymlinks (aResolveSymlinks);
    584     dlg.setConfirmOverwrite (fConfirmOverwrite);
     589        dlg.selectFilter(*aSelectedFilter);
     590    dlg.setResolveSymlinks(aResolveSymlinks);
     591    dlg.setConfirmOverwrite(fConfirmOverwrite);
    585592
    586593    QEventLoop eventLoop;
    587594    QObject::connect(&dlg, SIGNAL(finished(int)),
    588595                     &eventLoop, SLOT(quit()));
    589     /* Use the new open call. */
    590596    dlg.open();
    591597    eventLoop.exec();
    592598
    593     return dlg.result() == QDialog::Accepted ? dlg.selectedFiles().value (0, "") : QString::null;
     599    return dlg.result() == QDialog::Accepted ? dlg.selectedFiles().value(0, QString()) : QString();
    594600
    595601#else
     
    817823#elif defined (Q_WS_MAC) && (QT_VERSION >= 0x040600)
    818824
    819     /* After 4.5 exec ignores the Qt::Sheet flag. See "New Ways of Using
    820      * Dialogs" in http://doc.trolltech.com/qq/QtQuarterly30.pdf why. Because
    821      * we are lazy, we recreate the old behavior. Unfortunately there is a bug
    822      * in Qt 4.5.x which result in showing the native & the Qt dialog at the
    823      * same time. */
    824     QFileDialog dlg (aParent, Qt::Sheet);
    825     dlg.setWindowTitle (aCaption);
    826     dlg.setDirectory (aStartWith);
    827     dlg.setNameFilter (aFilters);
     825    /* After 4.5 exec ignores the Qt::Sheet flag.
     826     * See "New Ways of Using Dialogs" in http://doc.trolltech.com/qq/QtQuarterly30.pdf why.
     827     * We want the old behavior for file-save dialog. Unfortunately there is a bug in Qt 4.5.x
     828     * which result in showing the native & the Qt dialog at the same time. */
     829    QFileDialog dlg(aParent);
     830    dlg.setWindowTitle(aCaption);
     831
     832    /* Some predictive algorithm which seems missed in native code. */
     833    QDir dir(aStartWith);
     834    while (!dir.isRoot() && !dir.exists())
     835        dir = QDir(QFileInfo(dir.absolutePath()).absolutePath());
     836    const QString strDirectory = dir.absolutePath();
     837    if (!strDirectory.isNull())
     838        dlg.setDirectory(strDirectory);
     839    if (strDirectory != aStartWith)
     840        dlg.selectFile(QFileInfo(aStartWith).absoluteFilePath());
     841
     842    dlg.setNameFilter(aFilters);
    828843    if (aSingleFile)
    829         dlg.setFileMode (QFileDialog::ExistingFile);
     844        dlg.setFileMode(QFileDialog::ExistingFile);
    830845    else
    831         dlg.setFileMode (QFileDialog::ExistingFiles);
     846        dlg.setFileMode(QFileDialog::ExistingFiles);
    832847    if (aSelectedFilter)
    833         dlg.selectFilter (*aSelectedFilter);
    834     dlg.setResolveSymlinks (aResolveSymlinks);
     848        dlg.selectFilter(*aSelectedFilter);
     849    dlg.setResolveSymlinks(aResolveSymlinks);
    835850
    836851    QEventLoop eventLoop;
    837852    QObject::connect(&dlg, SIGNAL(finished(int)),
    838853                     &eventLoop, SLOT(quit()));
    839     /* Use the new open call. */
    840854    dlg.open();
    841855    eventLoop.exec();
    842856
    843     return dlg.result() == QDialog::Accepted ? dlg.selectedFiles() : QStringList() << QString::null;
     857    return dlg.result() == QDialog::Accepted ? dlg.selectedFiles() : QStringList() << QString();
    844858
    845859#else
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette