Index: /trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIFileDialog.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIFileDialog.cpp	(revision 68311)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIFileDialog.cpp	(revision 68312)
@@ -236,113 +236,5 @@
                                             bool aResolveSymlinks)
 {
-#if defined(VBOX_WS_WIN) && (QT_VERSION < 0x050000)
-
-    /**
-     *  QEvent class reimplementation to carry Win32 API
-     *  native dialog's result folder information
-     */
-    class GetExistDirectoryEvent : public OpenNativeDialogEvent
-    {
-    public:
-
-        enum { TypeId = QEvent::User + 1 };
-
-        GetExistDirectoryEvent (const QString &aResult)
-            : OpenNativeDialogEvent (aResult, (QEvent::Type) TypeId) {}
-    };
-
-    /**
-     *  QThread class reimplementation to open Win32 API
-     *  native folder's dialog
-     */
-    class Thread : public QThread
-    {
-    public:
-
-        Thread (QWidget *aParent, QObject *aTarget,
-                const QString &aDir, const QString &aCaption)
-            : mParent (aParent), mTarget (aTarget), mDir (aDir), mCaption (aCaption) {}
-
-        virtual void run()
-        {
-            QString result;
-
-            QWidget *topParent = windowManager().realParentWindow(mParent ? mParent : windowManager().mainWindowShown());
-            QString title = mCaption.isNull() ? tr ("Select a directory") : mCaption;
-
-            TCHAR path [MAX_PATH];
-            path [0] = 0;
-            TCHAR initPath [MAX_PATH];
-            initPath [0] = 0;
-
-            BROWSEINFO bi;
-            bi.hwndOwner = topParent ? topParent->winId() : 0;
-            bi.pidlRoot = 0;
-            bi.lpszTitle = (TCHAR*)(title.isNull() ? 0 : title.utf16());
-            bi.pszDisplayName = initPath;
-            bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT | BIF_NEWDIALOGSTYLE;
-            bi.lpfn = winGetExistDirCallbackProc;
-            bi.lParam = uintptr_t(&mDir);
-
-            LPITEMIDLIST itemIdList = SHBrowseForFolder (&bi);
-            if (itemIdList)
-            {
-                SHGetPathFromIDList (itemIdList, path);
-                IMalloc *pMalloc;
-                if (SHGetMalloc (&pMalloc) != NOERROR)
-                    result = QString::null;
-                else
-                {
-                    pMalloc->Free (itemIdList);
-                    pMalloc->Release();
-                    result = QString::fromUtf16 ((ushort*)path);
-                }
-            }
-            else
-                result = QString::null;
-            QApplication::postEvent (mTarget, new GetExistDirectoryEvent (result));
-        }
-
-    private:
-
-        QWidget *mParent;
-        QObject *mTarget;
-        QString mDir;
-        QString mCaption;
-    };
-
-    /* Local event loop to run while waiting for the result from another
-     * thread */
-    QEventLoop loop;
-
-    QString dir = QDir::toNativeSeparators (aDir);
-    LoopObject loopObject ((QEvent::Type) GetExistDirectoryEvent::TypeId, loop);
-
-    Thread openDirThread (aParent, &loopObject, dir, aCaption);
-    openDirThread.start();
-    loop.exec();
-    openDirThread.wait();
-
-    return loopObject.result();
-
-#elif defined (VBOX_WS_X11) && (QT_VERSION < 0x040400)
-
-    /* Here is workaround for Qt4.3 bug with QFileDialog which crushes when
-     * gets initial path as hidden directory if no hidden files are shown.
-     * See http://trolltech.com/developer/task-tracker/index_html?method=entry&id=193483
-     * for details */
-    QFileDialog dlg (aParent);
-    dlg.setWindowTitle (aCaption);
-    dlg.setDirectory (aDir);
-    dlg.setResolveSymlinks (aResolveSymlinks);
-    dlg.setFileMode (aDirOnly ? QFileDialog::DirectoryOnly : QFileDialog::Directory);
-    QAction *hidden = dlg.findChild <QAction*> ("qt_show_hidden_action");
-    if (hidden)
-    {
-        hidden->trigger();
-        hidden->setVisible (false);
-    }
-    return dlg.exec() ? dlg.selectedFiles() [0] : QString::null;
-#elif defined (VBOX_WS_MAC) && (QT_VERSION >= 0x040600)
+#ifdef VBOX_WS_MAC
 
     /* After 4.5 exec ignores the Qt::Sheet flag.
@@ -404,166 +296,5 @@
                                        bool           fConfirmOverwrite /* = false */)
 {
-#if defined(VBOX_WS_WIN) && (QT_VERSION < 0x050000)
-
-    /* Further code (WinAPI call to GetSaveFileName() in other thread)
-     * seems not necessary any more since the MS COM issue has been fixed,
-     * we can just call for the default QFileDialog::getSaveFileName(): */
-    Q_UNUSED(aResolveSymlinks);
-    QFileDialog::Options o;
-    if (!fConfirmOverwrite)
-        o |= QFileDialog::DontConfirmOverwrite;
-    return QFileDialog::getSaveFileName(aParent, aCaption, aStartWith,
-                                        aFilters, aSelectedFilter, o);
-
-    /**
-     *  QEvent class reimplementation to carry Win32 API native dialog's
-     *  result folder information
-     */
-    class GetOpenFileNameEvent : public OpenNativeDialogEvent
-    {
-    public:
-
-        enum { TypeId = QEvent::User + 2 };
-
-        GetOpenFileNameEvent (const QString &aResult)
-            : OpenNativeDialogEvent (aResult, (QEvent::Type) TypeId) {}
-    };
-
-    /**
-     *  QThread class reimplementation to open Win32 API native file dialog
-     */
-    class Thread : public QThread
-    {
-    public:
-
-        Thread (QWidget *aParent, QObject *aTarget,
-                const QString &aStartWith, const QString &aFilters,
-                const QString &aCaption, bool fConfirmOverwrite) :
-                mParent (aParent), mTarget (aTarget),
-                mStartWith (aStartWith), mFilters (aFilters),
-                mCaption (aCaption),
-                m_fConfirmOverwrite(fConfirmOverwrite) {}
-
-        virtual void run()
-        {
-            QString result;
-
-            QString workDir;
-            QString initSel;
-            QFileInfo fi (mStartWith);
-
-            if (fi.isDir())
-                workDir = mStartWith;
-            else
-            {
-                workDir = fi.absolutePath();
-                initSel = fi.fileName();
-            }
-
-            workDir = QDir::toNativeSeparators (workDir);
-            if (!workDir.endsWith ("\\"))
-                workDir += "\\";
-
-            QString title = mCaption.isNull() ? tr ("Select a file") : mCaption;
-
-            QWidget *topParent = windowManager().realParentWindow(mParent ? mParent : windowManager().mainWindowShown());
-            QString winFilters = winFilter (mFilters);
-            AssertCompile (sizeof (TCHAR) == sizeof (QChar));
-            TCHAR buf [1024];
-            if (initSel.length() > 0 && initSel.length() < sizeof (buf))
-                memcpy (buf, initSel.isNull() ? 0 : initSel.utf16(),
-                        (initSel.length() + 1) * sizeof (TCHAR));
-            else
-                buf [0] = 0;
-
-            OPENFILENAME ofn;
-            memset (&ofn, 0, sizeof (OPENFILENAME));
-
-            ofn.lStructSize = sizeof (OPENFILENAME);
-            ofn.hwndOwner = topParent ? topParent->winId() : 0;
-            ofn.lpstrFilter = (TCHAR *)(winFilters.isNull() ? 0 : winFilters.utf16());
-            ofn.lpstrFile = buf;
-            ofn.nMaxFile = sizeof (buf) - 1;
-            ofn.lpstrInitialDir = (TCHAR *)(workDir.isNull() ? 0 : workDir.utf16());
-            ofn.lpstrTitle = (TCHAR *)(title.isNull() ? 0 : title.utf16());
-            ofn.Flags = (OFN_NOCHANGEDIR | OFN_HIDEREADONLY |
-                         OFN_EXPLORER | OFN_ENABLEHOOK |
-                         OFN_NOTESTFILECREATE | (m_fConfirmOverwrite ? OFN_OVERWRITEPROMPT : 0));
-            ofn.lpfnHook = OFNHookProc;
-
-            if (GetSaveFileName (&ofn))
-            {
-                result = QString::fromUtf16 ((ushort *) ofn.lpstrFile);
-            }
-
-            // qt_win_eatMouseMove();
-            MSG msg = {0, 0, 0, 0, 0, 0, 0};
-            while (PeekMessage (&msg, 0, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE));
-            if (msg.message == WM_MOUSEMOVE)
-                PostMessage (msg.hwnd, msg.message, 0, msg.lParam);
-
-            result = result.isEmpty() ? result : QFileInfo (result).absoluteFilePath();
-
-            QApplication::postEvent (mTarget, new GetOpenFileNameEvent (result));
-        }
-
-    private:
-
-        QWidget *mParent;
-        QObject *mTarget;
-        QString mStartWith;
-        QString mFilters;
-        QString mCaption;
-        bool    m_fConfirmOverwrite;
-    };
-
-    if (aSelectedFilter)
-        *aSelectedFilter = QString::null;
-
-    /* Local event loop to run while waiting for the result from another
-     * thread */
-    QEventLoop loop;
-
-    QString startWith = QDir::toNativeSeparators (aStartWith);
-    LoopObject loopObject ((QEvent::Type) GetOpenFileNameEvent::TypeId, loop);
-
-    if (aParent)
-        aParent->setWindowModality (Qt::WindowModal);
-
-    Thread openDirThread (aParent, &loopObject, startWith, aFilters, aCaption, fConfirmOverwrite);
-    openDirThread.start();
-    loop.exec();
-    openDirThread.wait();
-
-    if (aParent)
-        aParent->setWindowModality (Qt::NonModal);
-
-    return loopObject.result();
-
-#elif defined (VBOX_WS_X11) && (QT_VERSION < 0x040400)
-
-    /* Here is workaround for Qt4.3 bug with QFileDialog which crushes when
-     * gets initial path as hidden directory if no hidden files are shown.
-     * See http://trolltech.com/developer/task-tracker/index_html?method=entry&id=193483
-     * for details */
-    QFileDialog dlg (aParent);
-    dlg.setWindowTitle (aCaption);
-    dlg.setDirectory (aStartWith);
-    dlg.setFilter (aFilters);
-    dlg.setFileMode (QFileDialog::QFileDialog::AnyFile);
-    dlg.setAcceptMode (QFileDialog::AcceptSave);
-    if (aSelectedFilter)
-        dlg.selectFilter (*aSelectedFilter);
-    dlg.setResolveSymlinks (aResolveSymlinks);
-    dlg.setConfirmOverwrite (fConfirmOverwrite);
-    QAction *hidden = dlg.findChild <QAction*> ("qt_show_hidden_action");
-    if (hidden)
-    {
-        hidden->trigger();
-        hidden->setVisible (false);
-    }
-    return dlg.exec() == QDialog::Accepted ? dlg.selectedFiles().value (0, "") : QString::null;
-
-#elif defined (VBOX_WS_MAC) && (QT_VERSION >= 0x040600) && (QT_VERSION < 0x050000)
+#ifdef VBOX_WS_MAC
 
     /* After 4.5 exec ignores the Qt::Sheet flag.
@@ -588,5 +319,5 @@
     dlg.setAcceptMode(QFileDialog::AcceptSave);
     if (aSelectedFilter)
-        dlg.selectFilter(*aSelectedFilter);
+        dlg.selectNameFilter(*aSelectedFilter);
     dlg.setResolveSymlinks(aResolveSymlinks);
     dlg.setConfirmOverwrite(fConfirmOverwrite);
@@ -671,156 +402,5 @@
                                             bool           aSingleFile /* = false */)
 {
-/* It seems, running QFileDialog in separate thread is NOT needed under windows any more: */
-#if defined (VBOX_WS_WIN) && (QT_VERSION < 0x040403)
-
-    /**
-     *  QEvent class reimplementation to carry Win32 API native dialog's
-     *  result folder information
-     */
-    class GetOpenFileNameEvent : public OpenNativeDialogEvent
-    {
-    public:
-
-        enum { TypeId = QEvent::User + 3 };
-
-        GetOpenFileNameEvent (const QString &aResult)
-            : OpenNativeDialogEvent (aResult, (QEvent::Type) TypeId) {}
-    };
-
-    /**
-     *  QThread class reimplementation to open Win32 API native file dialog
-     */
-    class Thread : public QThread
-    {
-    public:
-
-        Thread (QWidget *aParent, QObject *aTarget,
-                const QString &aStartWith, const QString &aFilters,
-                const QString &aCaption) :
-                mParent (aParent), mTarget (aTarget),
-                mStartWith (aStartWith), mFilters (aFilters),
-                mCaption (aCaption) {}
-
-        virtual void run()
-        {
-            QString result;
-
-            QString workDir;
-            QString initSel;
-            QFileInfo fi (mStartWith);
-
-            if (fi.isDir())
-                workDir = mStartWith;
-            else
-            {
-                workDir = fi.absolutePath();
-                initSel = fi.fileName();
-            }
-
-            workDir = QDir::toNativeSeparators (workDir);
-            if (!workDir.endsWith ("\\"))
-                workDir += "\\";
-
-            QString title = mCaption.isNull() ? tr ("Select a file") : mCaption;
-
-            QWidget *topParent = windowManager().realParentWindow(mParent ? mParent : windowManager().mainWindowShown());
-            QString winFilters = winFilter (mFilters);
-            AssertCompile (sizeof (TCHAR) == sizeof (QChar));
-            TCHAR buf [1024];
-            if (initSel.length() > 0 && initSel.length() < sizeof (buf))
-                memcpy (buf, initSel.isNull() ? 0 : initSel.utf16(),
-                        (initSel.length() + 1) * sizeof (TCHAR));
-            else
-                buf [0] = 0;
-
-            OPENFILENAME ofn;
-            memset (&ofn, 0, sizeof (OPENFILENAME));
-
-            ofn.lStructSize = sizeof (OPENFILENAME);
-            ofn.hwndOwner = topParent ? topParent->winId() : 0;
-            ofn.lpstrFilter = (TCHAR *)(winFilters.isNull() ? 0 : winFilters.utf16());
-            ofn.lpstrFile = buf;
-            ofn.nMaxFile = sizeof (buf) - 1;
-            ofn.lpstrInitialDir = (TCHAR *)(workDir.isNull() ? 0 : workDir.utf16());
-            ofn.lpstrTitle = (TCHAR *)(title.isNull() ? 0 : title.utf16());
-            ofn.Flags = (OFN_NOCHANGEDIR | OFN_HIDEREADONLY |
-                          OFN_EXPLORER | OFN_ENABLEHOOK |
-                          OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST);
-            ofn.lpfnHook = OFNHookProc;
-
-            if (GetOpenFileName (&ofn))
-            {
-                result = QString::fromUtf16 ((ushort *) ofn.lpstrFile);
-            }
-
-            // qt_win_eatMouseMove();
-            MSG msg = {0, 0, 0, 0, 0, 0, 0};
-            while (PeekMessage (&msg, 0, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE));
-            if (msg.message == WM_MOUSEMOVE)
-                PostMessage (msg.hwnd, msg.message, 0, msg.lParam);
-
-            result = result.isEmpty() ? result : QFileInfo (result).absoluteFilePath();
-
-            QApplication::postEvent (mTarget, new GetOpenFileNameEvent (result));
-        }
-
-    private:
-
-        QWidget *mParent;
-        QObject *mTarget;
-        QString mStartWith;
-        QString mFilters;
-        QString mCaption;
-    };
-
-    if (aSelectedFilter)
-        *aSelectedFilter = QString::null;
-
-    /* Local event loop to run while waiting for the result from another
-     * thread */
-    QEventLoop loop;
-
-    QString startWith = QDir::toNativeSeparators (aStartWith);
-    LoopObject loopObject ((QEvent::Type) GetOpenFileNameEvent::TypeId, loop);
-
-    if (aParent)
-        aParent->setWindowModality (Qt::WindowModal);
-
-    Thread openDirThread (aParent, &loopObject, startWith, aFilters, aCaption);
-    openDirThread.start();
-    loop.exec();
-    openDirThread.wait();
-
-    if (aParent)
-        aParent->setWindowModality (Qt::NonModal);
-
-    return QStringList() << loopObject.result();
-
-#elif defined (VBOX_WS_X11) && (QT_VERSION < 0x040400)
-
-    /* Here is workaround for Qt4.3 bug with QFileDialog which crushes when
-     * gets initial path as hidden directory if no hidden files are shown.
-     * See http://trolltech.com/developer/task-tracker/index_html?method=entry&id=193483
-     * for details */
-    QFileDialog dlg (aParent);
-    dlg.setWindowTitle (aCaption);
-    dlg.setDirectory (aStartWith);
-    dlg.setFilter (aFilters);
-    if (aSingleFile)
-        dlg.setFileMode (QFileDialog::ExistingFile);
-    else
-        dlg.setFileMode (QFileDialog::ExistingFiles);
-    if (aSelectedFilter)
-        dlg.selectFilter (*aSelectedFilter);
-    dlg.setResolveSymlinks (aResolveSymlinks);
-    QAction *hidden = dlg.findChild <QAction*> ("qt_show_hidden_action");
-    if (hidden)
-    {
-        hidden->trigger();
-        hidden->setVisible (false);
-    }
-    return dlg.exec() == QDialog::Accepted ? dlg.selectedFiles() : QStringList() << QString::null;
-
-#elif defined (VBOX_WS_MAC) && (QT_VERSION >= 0x040600) && (QT_VERSION < 0x050000)
+#ifdef VBOX_WS_MAC
 
     /* After 4.5 exec ignores the Qt::Sheet flag.
@@ -847,5 +427,5 @@
         dlg.setFileMode(QFileDialog::ExistingFiles);
     if (aSelectedFilter)
-        dlg.selectFilter(*aSelectedFilter);
+        dlg.selectNameFilter(*aSelectedFilter);
     dlg.setResolveSymlinks(aResolveSymlinks);
 
