VirtualBox

Changeset 20078 in vbox for trunk/src/VBox/Frontends


Ignore:
Timestamp:
May 27, 2009 12:31:07 PM (16 years ago)
Author:
vboxsync
Message:

FE/Qt4: 3701: Remove native file dialog handling on Windows if possible - moving re-implementation into separate QIFileDialog class.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
2 added
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk

    r20047 r20078  
    242242        include/QIHelpButton.h \
    243243        include/QIDialog.h \
     244        include/QIFileDialog.h \
    244245        include/VBoxFilePathSelectorWidget.h \
    245246        include/VBoxOSTypeSelectorButton.h \
     
    313314        src/COMDefs.cpp
    314315endif
     316ifeq ($(KBUILD_TARGET),win)
     317VirtualBox_QT_MOCSRCS += \
     318        src/QIFileDialog.cpp
     319endif
    315320
    316321VirtualBox_SOURCES = \
     
    326331        src/QIAbstractWizard.cpp \
    327332        src/QIDialog.cpp \
     333        src/QIFileDialog.cpp \
    328334        src/QIDialogButtonBox.cpp \
    329335        src/QIListView.cpp \
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxGlobal.h

    r19837 r20078  
    719719    static QString systemLanguageId();
    720720
    721     static QString getExistingDirectory (const QString &aDir, QWidget *aParent,
    722                                          const QString &aCaption = QString::null,
    723                                          bool aDirOnly = TRUE,
    724                                          bool resolveSymlinks = TRUE);
    725 
    726     static QString getSaveFileName (const QString &aStartWith, const QString &aFilters, QWidget *aParent,
    727                                     const QString &aCaption, QString *aSelectedFilter = NULL,
    728                                     bool aResolveSymLinks = true);
    729 
    730     static QString getOpenFileName (const QString &aStartWith, const QString &aFilters, QWidget *aParent,
    731                                     const QString &aCaption, QString *aSelectedFilter = NULL,
    732                                     bool aResolveSymLinks = true);
    733 
    734     static QStringList getOpenFileNames (const QString &aStartWith, const QString &aFilters, QWidget *aParent,
    735                                          const QString &aCaption, QString *aSelectedFilter = NULL,
    736                                          bool aResolveSymLinks = true,
    737                                          bool aSingleFile = false);
    738 
    739     static QString getFirstExistingDir (const QString &);
    740 
    741721    static bool activateWindow (WId aWId, bool aSwitchDesktop = true);
    742722
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxConsoleWnd.cpp

    r20047 r20078  
    2121 */
    2222
     23/* VBox includes */
    2324#include "VBoxConsoleWnd.h"
    2425#include "VBoxConsoleView.h"
    2526#include "VBoxCloseVMDlg.h"
     27#include "VBoxDownloaderWgt.h"
     28#include "VBoxGlobal.h"
     29#include "VBoxMediaManagerDlg.h"
     30#include "VBoxMiniToolBar.h"
     31#include "VBoxProblemReporter.h"
    2632#include "VBoxTakeSnapshotDlg.h"
    27 #include "VBoxMediaManagerDlg.h"
    2833#include "VBoxVMFirstRunWzd.h"
    2934#include "VBoxVMSettingsSF.h"
    3035#include "VBoxVMInformationDlg.h"
    31 #include "VBoxDownloaderWgt.h"
    32 #include "VBoxGlobal.h"
    33 #include "VBoxProblemReporter.h"
    34 #include "VBoxMiniToolBar.h"
    35 
     36#include "QIFileDialog.h"
     37#include "QIHotKeyEdit.h"
     38#include "QIHttp.h"
    3639#include "QIStateIndicator.h"
    3740#include "QIStatusBar.h"
    38 #include "QIHotKeyEdit.h"
    39 #include "QIHttp.h"
    4041
    4142/* Qt includes */
    4243#include <QActionGroup>
    4344#include <QDesktopWidget>
     45#include <QDir>
     46#include <QFileInfo>
    4447#include <QMenuBar>
    45 #include <QFileInfo>
    46 #include <QDir>
     48#include <QProgressBar>
    4749#include <QTimer>
    48 #include <QProgressBar>
    4950#ifdef Q_WS_X11
    5051# include <QX11Info>
     
    159160                }
    160161
    161                 QString target = vboxGlobal().getExistingDirectory (
     162                QString target = QIFileDialog::getExistingDirectory (
    162163                    QFileInfo (mTarget).absolutePath(), this,
    163164                    tr ("Select folder to save Guest Additions image to"), true);
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxFilePathSelectorWidget.cpp

    r19670 r20078  
    2121 */
    2222
     23/* VBox includes */
    2324#include "VBoxFilePathSelectorWidget.h"
    2425#include "VBoxGlobal.h"
     26#include "QIFileDialog.h"
    2527#include "QILabel.h"
    2628
     
    3133#include <QDir>
    3234#include <QFileIconProvider>
     35#include <QFocusEvent>
    3336#include <QLineEdit>
     37#include <QPushButton>
    3438#include <QTimer>
    35 #include <QPushButton>
    36 #include <QFocusEvent>
    3739
    3840////////////////////////////////////////////////////////////////////////////////
     
    383385    /* Preparing initial directory. */
    384386    QString initDir = mPath.isNull() ? mHomeDir :
    385         VBoxGlobal::getFirstExistingDir (mPath);
     387        QIFileDialog::getFirstExistingDir (mPath);
    386388    if (initDir.isNull())
    387389        initDir = mHomeDir;
     
    391393    {
    392394        case Mode_File_Open:
    393             path = VBoxGlobal::getOpenFileName (initDir, mFileFilters, parentWidget(), mFileDialogTitle); break;
     395            path = QIFileDialog::getOpenFileName (initDir, mFileFilters, parentWidget(), mFileDialogTitle); break;
    394396        case Mode_File_Save:
    395397            {
    396                 path = VBoxGlobal::getSaveFileName (initDir, mFileFilters, parentWidget(), mFileDialogTitle);
     398                path = QIFileDialog::getSaveFileName (initDir, mFileFilters, parentWidget(), mFileDialogTitle);
    397399                if (!path.isEmpty() && QFileInfo (path).suffix().isEmpty())
    398400                    path = QString ("%1.%2").arg (path).arg (mDefaultSaveExt);
     
    400402            }
    401403        case Mode_Folder:
    402             path = VBoxGlobal::getExistingDirectory (initDir, parentWidget(), mFileDialogTitle); break;
     404            path = QIFileDialog::getExistingDirectory (initDir, parentWidget(), mFileDialogTitle); break;
    403405    }
    404406
     
    633635    /* Preparing initial directory. */
    634636    QString initDir = path.isNull() ? mHomeDir :
    635         VBoxGlobal::getFirstExistingDir (path);
     637        QIFileDialog::getFirstExistingDir (path);
    636638    if (initDir.isNull())
    637639        initDir = mHomeDir;
    638640
    639     path = VBoxGlobal::getOpenFileName (initDir, mFileFilters, parentWidget(), mFileDialogTitle);
     641    path = QIFileDialog::getOpenFileName (initDir, mFileFilters, parentWidget(), mFileDialogTitle);
    640642    if (!path.isEmpty())
    641643    {
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp

    r19864 r20078  
    485485#endif
    486486
    487 // Helpers for VBoxGlobal::getOpenFileName() & getExistingDirectory()
    488 /////////////////////////////////////////////////////////////////////////////
    489 
    490 #if defined Q_WS_WIN
    491 
    492 extern void qt_enter_modal (QWidget*);
    493 extern void qt_leave_modal (QWidget*);
    494 
    495 static QString extractFilter (const QString &aRawFilter)
    496 {
    497     static const char qt_file_dialog_filter_reg_exp[] =
    498         "([a-zA-Z0-9 ]*)\\(([a-zA-Z0-9_.*? +;#\\[\\]]*)\\)$";
    499 
    500     QString result = aRawFilter;
    501     QRegExp r (QString::fromLatin1 (qt_file_dialog_filter_reg_exp));
    502     int index = r.indexIn (result);
    503     if (index >= 0)
    504         result = r.cap (2);
    505     return result.replace (QChar (' '), QChar (';'));
    506 }
    507 
    508 /**
    509  * Converts QFileDialog filter list to Win32 API filter list.
    510  */
    511 static QString winFilter (const QString &aFilter)
    512 {
    513     QStringList filterLst;
    514 
    515     if (!aFilter.isEmpty())
    516     {
    517         int i = aFilter.indexOf (";;", 0);
    518         QString sep (";;");
    519         if (i == -1)
    520         {
    521             if (aFilter.indexOf ("\n", 0) != -1)
    522             {
    523                 sep = "\n";
    524                 i = aFilter.indexOf (sep, 0);
    525             }
    526         }
    527 
    528         filterLst = aFilter.split (sep);
    529     }
    530 
    531     QStringList::Iterator it = filterLst.begin();
    532     QString winfilters;
    533     for (; it != filterLst.end(); ++it)
    534     {
    535         winfilters += *it;
    536         winfilters += QChar::Null;
    537         winfilters += extractFilter (*it);
    538         winfilters += QChar::Null;
    539     }
    540     winfilters += QChar::Null;
    541     return winfilters;
    542 }
    543 
    544 /*
    545  * Callback function to control the native Win32 API file dialog
    546  */
    547 UINT_PTR CALLBACK OFNHookProc (HWND aHdlg, UINT aUiMsg, WPARAM aWParam, LPARAM aLParam)
    548 {
    549     if (aUiMsg == WM_NOTIFY)
    550     {
    551         OFNOTIFY *notif = (OFNOTIFY*) aLParam;
    552         if (notif->hdr.code == CDN_TYPECHANGE)
    553         {
    554             /* locate native dialog controls */
    555             HWND parent = GetParent (aHdlg);
    556             HWND button = GetDlgItem (parent, IDOK);
    557             HWND textfield = ::GetDlgItem (parent, cmb13);
    558             if (textfield == NULL)
    559                 textfield = ::GetDlgItem (parent, edt1);
    560             if (textfield == NULL)
    561                 return FALSE;
    562             HWND selector = ::GetDlgItem (parent, cmb1);
    563 
    564             /* simulate filter change by pressing apply-key */
    565             int    size = 256;
    566             TCHAR *buffer = (TCHAR*)malloc (size);
    567             SendMessage (textfield, WM_GETTEXT, size, (LPARAM)buffer);
    568             SendMessage (textfield, WM_SETTEXT, 0, (LPARAM)"\0");
    569             SendMessage (button, BM_CLICK, 0, 0);
    570             SendMessage (textfield, WM_SETTEXT, 0, (LPARAM)buffer);
    571             free (buffer);
    572 
    573             /* make request for focus moving to filter selector combo-box */
    574             HWND curFocus = GetFocus();
    575             PostMessage (curFocus, WM_KILLFOCUS, (WPARAM)selector, 0);
    576             PostMessage (selector, WM_SETFOCUS, (WPARAM)curFocus, 0);
    577             WPARAM wParam = MAKEWPARAM (WA_ACTIVE, 0);
    578             PostMessage (selector, WM_ACTIVATE, wParam, (LPARAM)curFocus);
    579         }
    580     }
    581     return FALSE;
    582 }
    583 
    584 /*
    585  * Callback function to control the native Win32 API folders dialog
    586  */
    587 static int __stdcall winGetExistDirCallbackProc (HWND hwnd, UINT uMsg,
    588                                                  LPARAM lParam, LPARAM lpData)
    589 {
    590     if (uMsg == BFFM_INITIALIZED && lpData != 0)
    591     {
    592         QString *initDir = (QString *)(lpData);
    593         if (!initDir->isEmpty())
    594         {
    595             SendMessage (hwnd, BFFM_SETSELECTION, TRUE, Q_ULONG (
    596                 initDir->isNull() ? 0 : initDir->utf16()));
    597             //SendMessage (hwnd, BFFM_SETEXPANDED, TRUE, Q_ULONG (initDir->utf16()));
    598         }
    599     }
    600     else if (uMsg == BFFM_SELCHANGED)
    601     {
    602         TCHAR path [MAX_PATH];
    603         SHGetPathFromIDList (LPITEMIDLIST (lParam), path);
    604         QString tmpStr = QString::fromUtf16 ((ushort*)path);
    605         if (!tmpStr.isEmpty())
    606             SendMessage (hwnd, BFFM_ENABLEOK, 1, 1);
    607         else
    608             SendMessage (hwnd, BFFM_ENABLEOK, 0, 0);
    609         SendMessage (hwnd, BFFM_SETSTATUSTEXT, 1, Q_ULONG (path));
    610     }
    611     return 0;
    612 }
    613 
    614 /**
    615  *  QEvent class to carry Win32 API native dialog's result information
    616  */
    617 class OpenNativeDialogEvent : public QEvent
    618 {
    619 public:
    620 
    621     OpenNativeDialogEvent (const QString &aResult, QEvent::Type aType)
    622         : QEvent (aType), mResult (aResult) {}
    623 
    624     const QString& result() { return mResult; }
    625 
    626 private:
    627 
    628     QString mResult;
    629 };
    630 
    631 /**
    632  *  QObject class reimplementation which is the target for OpenNativeDialogEvent
    633  *  event. It receives OpenNativeDialogEvent event from another thread,
    634  *  stores result information and exits the given local event loop.
    635  */
    636 class LoopObject : public QObject
    637 {
    638 public:
    639 
    640     LoopObject (QEvent::Type aType, QEventLoop &aLoop)
    641         : mType (aType), mLoop (aLoop), mResult (QString::null) {}
    642     const QString& result() { return mResult; }
    643 
    644 private:
    645 
    646     bool event (QEvent *aEvent)
    647     {
    648         if (aEvent->type() == mType)
    649         {
    650             OpenNativeDialogEvent *ev = (OpenNativeDialogEvent*) aEvent;
    651             mResult = ev->result();
    652             mLoop.quit();
    653             return true;
    654         }
    655         return QObject::event (aEvent);
    656     }
    657 
    658     QEvent::Type mType;
    659     QEventLoop &mLoop;
    660     QString mResult;
    661 };
    662 
    663 #endif /* Q_WS_WIN */
    664 
    665 
    666487// VBoxGlobal
    667488////////////////////////////////////////////////////////////////////////////////
     
    39713792#endif
    39723793    return  QLocale::system().name();
    3973 }
    3974 
    3975 /**
    3976  *  Reimplementation of QFileDialog::getExistingDirectory() that removes some
    3977  *  oddities and limitations.
    3978  *
    3979  *  On Win32, this function makes sure a native dialog is launched in
    3980  *  another thread to avoid dialog visualization errors occuring due to
    3981  *  multi-threaded COM apartment initialization on the main UI thread while
    3982  *  the appropriate native dialog function expects a single-threaded one.
    3983  *
    3984  *  On all other platforms, this function is equivalent to
    3985  *  QFileDialog::getExistingDirectory().
    3986  */
    3987 QString VBoxGlobal::getExistingDirectory (const QString &aDir,
    3988                                           QWidget *aParent,
    3989                                           const QString &aCaption,
    3990                                           bool aDirOnly,
    3991                                           bool aResolveSymlinks)
    3992 {
    3993 #if defined Q_WS_WIN
    3994 
    3995     /**
    3996      *  QEvent class reimplementation to carry Win32 API native dialog's
    3997      *  result folder information
    3998      */
    3999     class GetExistDirectoryEvent : public OpenNativeDialogEvent
    4000     {
    4001     public:
    4002 
    4003         enum { TypeId = QEvent::User + 300 };
    4004 
    4005         GetExistDirectoryEvent (const QString &aResult)
    4006             : OpenNativeDialogEvent (aResult, (QEvent::Type) TypeId) {}
    4007     };
    4008 
    4009     /**
    4010      *  QThread class reimplementation to open Win32 API native folder's dialog
    4011      */
    4012     class Thread : public QThread
    4013     {
    4014     public:
    4015 
    4016         Thread (QWidget *aParent, QObject *aTarget,
    4017                 const QString &aDir, const QString &aCaption)
    4018             : mParent (aParent), mTarget (aTarget), mDir (aDir), mCaption (aCaption) {}
    4019 
    4020         virtual void run()
    4021         {
    4022             QString result;
    4023 
    4024             QWidget *topParent = mParent ? mParent->window() : vboxGlobal().mainWindow();
    4025             QString title = mCaption.isNull() ? tr ("Select a directory") : mCaption;
    4026 
    4027             TCHAR path[MAX_PATH];
    4028             path [0] = 0;
    4029             TCHAR initPath [MAX_PATH];
    4030             initPath [0] = 0;
    4031 
    4032             BROWSEINFO bi;
    4033             bi.hwndOwner = topParent ? topParent->winId() : 0;
    4034             bi.pidlRoot = NULL;
    4035             bi.lpszTitle = (TCHAR*)(title.isNull() ? 0 : title.utf16());
    4036             bi.pszDisplayName = initPath;
    4037             bi.ulFlags = BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT | BIF_NEWDIALOGSTYLE;
    4038             bi.lpfn = winGetExistDirCallbackProc;
    4039             bi.lParam = Q_ULONG (&mDir);
    4040 
    4041             LPITEMIDLIST itemIdList = SHBrowseForFolder (&bi);
    4042             if (itemIdList)
    4043             {
    4044                 SHGetPathFromIDList (itemIdList, path);
    4045                 IMalloc *pMalloc;
    4046                 if (SHGetMalloc (&pMalloc) != NOERROR)
    4047                     result = QString::null;
    4048                 else
    4049                 {
    4050                     pMalloc->Free (itemIdList);
    4051                     pMalloc->Release();
    4052                     result = QString::fromUtf16 ((ushort*)path);
    4053                 }
    4054             }
    4055             else
    4056                 result = QString::null;
    4057             QApplication::postEvent (mTarget, new GetExistDirectoryEvent (result));
    4058         }
    4059 
    4060     private:
    4061 
    4062         QWidget *mParent;
    4063         QObject *mTarget;
    4064         QString mDir;
    4065         QString mCaption;
    4066     };
    4067 
    4068     /* Local event loop to run while waiting for the result from another
    4069      * thread */
    4070     QEventLoop loop;
    4071 
    4072     QString dir = QDir::toNativeSeparators (aDir);
    4073     LoopObject loopObject ((QEvent::Type) GetExistDirectoryEvent::TypeId, loop);
    4074 
    4075     Thread openDirThread (aParent, &loopObject, dir, aCaption);
    4076     openDirThread.start();
    4077     loop.exec();
    4078     openDirThread.wait();
    4079 
    4080     return loopObject.result();
    4081 
    4082 #elif defined (Q_WS_X11) && (QT_VERSION < 0x040400)
    4083 
    4084     /* Here is workaround for Qt4.3 bug with QFileDialog which crushes when
    4085      * gets initial path as hidden directory if no hidden files are shown.
    4086      * See http://trolltech.com/developer/task-tracker/index_html?method=entry&id=193483
    4087      * for details */
    4088     QFileDialog dlg (aParent);
    4089     dlg.setWindowTitle (aCaption);
    4090     dlg.setDirectory (aDir);
    4091     dlg.setResolveSymlinks (aResolveSymlinks);
    4092     dlg.setFileMode (aDirOnly ? QFileDialog::DirectoryOnly : QFileDialog::Directory);
    4093     QAction *hidden = dlg.findChild <QAction*> ("qt_show_hidden_action");
    4094     if (hidden)
    4095     {
    4096         hidden->trigger();
    4097         hidden->setVisible (false);
    4098     }
    4099     return dlg.exec() ? dlg.selectedFiles() [0] : QString::null;
    4100 
    4101 #else
    4102 
    4103     QFileDialog::Options o;
    4104     if (aDirOnly)
    4105         o = QFileDialog::ShowDirsOnly;
    4106     if (!aResolveSymlinks)
    4107         o |= QFileDialog::DontResolveSymlinks;
    4108     return QFileDialog::getExistingDirectory (aParent, aCaption, aDir, o);
    4109 
    4110 #endif
    4111 }
    4112 
    4113 /**
    4114  *  Reimplementation of QFileDialog::getSaveFileName() that removes some
    4115  *  oddities and limitations.
    4116  *
    4117  *  On Win32, this function makes sure a file filter is applied automatically
    4118  *  right after it is selected from the drop-down list, to conform to common
    4119  *  experience in other applications. Note that currently, @a selectedFilter
    4120  *  is always set to null on return.
    4121  *
    4122  *  On all other platforms, this function is equivalent to
    4123  *  QFileDialog::getSaveFileName().
    4124  */
    4125 /* static */
    4126 QString VBoxGlobal::getSaveFileName (const QString &aStartWith,
    4127                                      const QString &aFilters,
    4128                                      QWidget       *aParent,
    4129                                      const QString &aCaption,
    4130                                      QString       *aSelectedFilter /* = NULL */,
    4131                                      bool           aResolveSymlinks /* = true */)
    4132 {
    4133 #if defined Q_WS_WIN
    4134 
    4135     /**
    4136      *  QEvent class reimplementation to carry Win32 API native dialog's
    4137      *  result folder information
    4138      */
    4139     class GetOpenFileNameEvent : public OpenNativeDialogEvent
    4140     {
    4141     public:
    4142 
    4143         enum { TypeId = QEvent::User + 301 };
    4144 
    4145         GetOpenFileNameEvent (const QString &aResult)
    4146             : OpenNativeDialogEvent (aResult, (QEvent::Type) TypeId) {}
    4147     };
    4148 
    4149     /**
    4150      *  QThread class reimplementation to open Win32 API native file dialog
    4151      */
    4152     class Thread : public QThread
    4153     {
    4154     public:
    4155 
    4156         Thread (QWidget *aParent, QObject *aTarget,
    4157                 const QString &aStartWith, const QString &aFilters,
    4158                 const QString &aCaption) :
    4159                 mParent (aParent), mTarget (aTarget),
    4160                 mStartWith (aStartWith), mFilters (aFilters),
    4161                 mCaption (aCaption) {}
    4162 
    4163         virtual void run()
    4164         {
    4165             QString result;
    4166 
    4167             QString workDir;
    4168             QString initSel;
    4169             QFileInfo fi (mStartWith);
    4170 
    4171             if (fi.isDir())
    4172                 workDir = mStartWith;
    4173             else
    4174             {
    4175                 workDir = fi.absolutePath();
    4176                 initSel = fi.fileName();
    4177             }
    4178 
    4179             workDir = QDir::toNativeSeparators (workDir);
    4180             if (!workDir.endsWith ("\\"))
    4181                 workDir += "\\";
    4182 
    4183             QString title = mCaption.isNull() ? tr ("Select a file") : mCaption;
    4184 
    4185             QWidget *topParent = mParent ? mParent->window() : vboxGlobal().mainWindow();
    4186             QString winFilters = winFilter (mFilters);
    4187             AssertCompile (sizeof (TCHAR) == sizeof (QChar));
    4188             TCHAR buf [1024];
    4189             if (initSel.length() > 0 && initSel.length() < sizeof (buf))
    4190                 memcpy (buf, initSel.isNull() ? 0 : initSel.utf16(),
    4191                         (initSel.length() + 1) * sizeof (TCHAR));
    4192             else
    4193                 buf [0] = 0;
    4194 
    4195             OPENFILENAME ofn;
    4196             memset (&ofn, 0, sizeof (OPENFILENAME));
    4197 
    4198             ofn.lStructSize = sizeof (OPENFILENAME);
    4199             ofn.hwndOwner = topParent ? topParent->winId() : 0;
    4200             ofn.lpstrFilter = (TCHAR *) winFilters.isNull() ? 0 : winFilters.utf16();
    4201             ofn.lpstrFile = buf;
    4202             ofn.nMaxFile = sizeof (buf) - 1;
    4203             ofn.lpstrInitialDir = (TCHAR *) workDir.isNull() ? 0 : workDir.utf16();
    4204             ofn.lpstrTitle = (TCHAR *) title.isNull() ? 0 : title.utf16();
    4205             ofn.Flags = (OFN_NOCHANGEDIR | OFN_HIDEREADONLY |
    4206                          OFN_EXPLORER | OFN_ENABLEHOOK |
    4207                          OFN_NOTESTFILECREATE);
    4208             ofn.lpfnHook = OFNHookProc;
    4209 
    4210             if (GetSaveFileName (&ofn))
    4211             {
    4212                 result = QString::fromUtf16 ((ushort *) ofn.lpstrFile);
    4213             }
    4214 
    4215             // qt_win_eatMouseMove();
    4216             MSG msg = {0, 0, 0, 0, 0, 0, 0};
    4217             while (PeekMessage (&msg, 0, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE));
    4218             if (msg.message == WM_MOUSEMOVE)
    4219                 PostMessage (msg.hwnd, msg.message, 0, msg.lParam);
    4220 
    4221             result = result.isEmpty() ? result : QFileInfo (result).absoluteFilePath();
    4222 
    4223             QApplication::postEvent (mTarget, new GetOpenFileNameEvent (result));
    4224         }
    4225 
    4226     private:
    4227 
    4228         QWidget *mParent;
    4229         QObject *mTarget;
    4230         QString mStartWith;
    4231         QString mFilters;
    4232         QString mCaption;
    4233     };
    4234 
    4235     if (aSelectedFilter)
    4236         *aSelectedFilter = QString::null;
    4237 
    4238     /* Local event loop to run while waiting for the result from another
    4239      * thread */
    4240     QEventLoop loop;
    4241 
    4242     QString startWith = QDir::toNativeSeparators (aStartWith);
    4243     LoopObject loopObject ((QEvent::Type) GetOpenFileNameEvent::TypeId, loop);
    4244 
    4245 //#warning check me!
    4246     if (aParent)
    4247         aParent->setWindowModality (Qt::WindowModal);
    4248 
    4249     Thread openDirThread (aParent, &loopObject, startWith, aFilters, aCaption);
    4250     openDirThread.start();
    4251     loop.exec();
    4252     openDirThread.wait();
    4253 
    4254 //#warning check me!
    4255     if (aParent)
    4256         aParent->setWindowModality (Qt::NonModal);
    4257 
    4258     return loopObject.result();
    4259 
    4260 #elif defined (Q_WS_X11) && (QT_VERSION < 0x040400)
    4261 
    4262     /* Here is workaround for Qt4.3 bug with QFileDialog which crushes when
    4263      * gets initial path as hidden directory if no hidden files are shown.
    4264      * See http://trolltech.com/developer/task-tracker/index_html?method=entry&id=193483
    4265      * for details */
    4266     QFileDialog dlg (aParent);
    4267     dlg.setWindowTitle (aCaption);
    4268     dlg.setDirectory (aStartWith);
    4269     dlg.setFilter (aFilters);
    4270     dlg.setFileMode (QFileDialog::QFileDialog::AnyFile);
    4271     dlg.setAcceptMode (QFileDialog::AcceptSave);
    4272     if (aSelectedFilter)
    4273         dlg.selectFilter (*aSelectedFilter);
    4274     dlg.setResolveSymlinks (aResolveSymlinks);
    4275     dlg.setConfirmOverwrite (false);
    4276     QAction *hidden = dlg.findChild <QAction*> ("qt_show_hidden_action");
    4277     if (hidden)
    4278     {
    4279         hidden->trigger();
    4280         hidden->setVisible (false);
    4281     }
    4282     return dlg.exec() == QDialog::Accepted ? dlg.selectedFiles().value (0, "") : QString::null;
    4283 
    4284 #else
    4285 
    4286     QFileDialog::Options o;
    4287     if (!aResolveSymlinks)
    4288         o |= QFileDialog::DontResolveSymlinks;
    4289     o |= QFileDialog::DontConfirmOverwrite;
    4290     return QFileDialog::getSaveFileName (aParent, aCaption, aStartWith,
    4291                                          aFilters, aSelectedFilter, o);
    4292 #endif
    4293 }
    4294 
    4295 /**
    4296  *  Reimplementation of QFileDialog::getOpenFileName() that removes some
    4297  *  oddities and limitations.
    4298  *
    4299  *  On Win32, this function makes sure a file filter is applied automatically
    4300  *  right after it is selected from the drop-down list, to conform to common
    4301  *  experience in other applications. Note that currently, @a selectedFilter
    4302  *  is always set to null on return.
    4303  *
    4304  *  On all other platforms, this function is equivalent to
    4305  *  QFileDialog::getOpenFileName().
    4306  */
    4307 /* static */
    4308 QString VBoxGlobal::getOpenFileName (const QString &aStartWith,
    4309                                      const QString &aFilters,
    4310                                      QWidget       *aParent,
    4311                                      const QString &aCaption,
    4312                                      QString       *aSelectedFilter /* = NULL */,
    4313                                      bool           aResolveSymlinks /* = true */)
    4314 {
    4315     return getOpenFileNames (aStartWith,
    4316                              aFilters,
    4317                              aParent,
    4318                              aCaption,
    4319                              aSelectedFilter,
    4320                              aResolveSymlinks,
    4321                              true /* aSingleFile */).value (0, "");
    4322 }
    4323 
    4324 /**
    4325  *  Reimplementation of QFileDialog::getOpenFileNames() that removes some
    4326  *  oddities and limitations.
    4327  *
    4328  *  On Win32, this function makes sure a file filter is applied automatically
    4329  *  right after it is selected from the drop-down list, to conform to common
    4330  *  experience in other applications. Note that currently, @a selectedFilter
    4331  *  is always set to null on return.
    4332  *  @todo: implement the multiple file selection on win
    4333  *  @todo: is this extra handling on win still necessary with Qt4?
    4334  *
    4335  *  On all other platforms, this function is equivalent to
    4336  *  QFileDialog::getOpenFileNames().
    4337  */
    4338 /* static */
    4339 QStringList VBoxGlobal::getOpenFileNames (const QString &aStartWith,
    4340                                           const QString &aFilters,
    4341                                           QWidget       *aParent,
    4342                                           const QString &aCaption,
    4343                                           QString       *aSelectedFilter /* = NULL */,
    4344                                           bool           aResolveSymlinks /* = true */,
    4345                                           bool           aSingleFile /* = false */)
    4346 {
    4347 #if defined Q_WS_WIN
    4348 
    4349     /**
    4350      *  QEvent class reimplementation to carry Win32 API native dialog's
    4351      *  result folder information
    4352      */
    4353     class GetOpenFileNameEvent : public OpenNativeDialogEvent
    4354     {
    4355     public:
    4356 
    4357         enum { TypeId = QEvent::User + 301 };
    4358 
    4359         GetOpenFileNameEvent (const QString &aResult)
    4360             : OpenNativeDialogEvent (aResult, (QEvent::Type) TypeId) {}
    4361     };
    4362 
    4363     /**
    4364      *  QThread class reimplementation to open Win32 API native file dialog
    4365      */
    4366     class Thread : public QThread
    4367     {
    4368     public:
    4369 
    4370         Thread (QWidget *aParent, QObject *aTarget,
    4371                 const QString &aStartWith, const QString &aFilters,
    4372                 const QString &aCaption) :
    4373                 mParent (aParent), mTarget (aTarget),
    4374                 mStartWith (aStartWith), mFilters (aFilters),
    4375                 mCaption (aCaption) {}
    4376 
    4377         virtual void run()
    4378         {
    4379             QString result;
    4380 
    4381             QString workDir;
    4382             QString initSel;
    4383             QFileInfo fi (mStartWith);
    4384 
    4385             if (fi.isDir())
    4386                 workDir = mStartWith;
    4387             else
    4388             {
    4389                 workDir = fi.absolutePath();
    4390                 initSel = fi.fileName();
    4391             }
    4392 
    4393             workDir = QDir::toNativeSeparators (workDir);
    4394             if (!workDir.endsWith ("\\"))
    4395                 workDir += "\\";
    4396 
    4397             QString title = mCaption.isNull() ? tr ("Select a file") : mCaption;
    4398 
    4399             QWidget *topParent = mParent ? mParent->window() : vboxGlobal().mainWindow();
    4400             QString winFilters = winFilter (mFilters);
    4401             AssertCompile (sizeof (TCHAR) == sizeof (QChar));
    4402             TCHAR buf [1024];
    4403             if (initSel.length() > 0 && initSel.length() < sizeof (buf))
    4404                 memcpy (buf, initSel.isNull() ? 0 : initSel.utf16(),
    4405                         (initSel.length() + 1) * sizeof (TCHAR));
    4406             else
    4407                 buf [0] = 0;
    4408 
    4409             OPENFILENAME ofn;
    4410             memset (&ofn, 0, sizeof (OPENFILENAME));
    4411 
    4412             ofn.lStructSize = sizeof (OPENFILENAME);
    4413             ofn.hwndOwner = topParent ? topParent->winId() : 0;
    4414             ofn.lpstrFilter = (TCHAR *) winFilters.isNull() ? 0 : winFilters.utf16();
    4415             ofn.lpstrFile = buf;
    4416             ofn.nMaxFile = sizeof (buf) - 1;
    4417             ofn.lpstrInitialDir = (TCHAR *) workDir.isNull() ? 0 : workDir.utf16();
    4418             ofn.lpstrTitle = (TCHAR *) title.isNull() ? 0 : title.utf16();
    4419             ofn.Flags = (OFN_NOCHANGEDIR | OFN_HIDEREADONLY |
    4420                           OFN_EXPLORER | OFN_ENABLEHOOK |
    4421                           OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST);
    4422             ofn.lpfnHook = OFNHookProc;
    4423 
    4424             if (GetOpenFileName (&ofn))
    4425             {
    4426                 result = QString::fromUtf16 ((ushort *) ofn.lpstrFile);
    4427             }
    4428 
    4429             // qt_win_eatMouseMove();
    4430             MSG msg = {0, 0, 0, 0, 0, 0, 0};
    4431             while (PeekMessage (&msg, 0, WM_MOUSEMOVE, WM_MOUSEMOVE, PM_REMOVE));
    4432             if (msg.message == WM_MOUSEMOVE)
    4433                 PostMessage (msg.hwnd, msg.message, 0, msg.lParam);
    4434 
    4435             result = result.isEmpty() ? result : QFileInfo (result).absoluteFilePath();
    4436 
    4437             QApplication::postEvent (mTarget, new GetOpenFileNameEvent (result));
    4438         }
    4439 
    4440     private:
    4441 
    4442         QWidget *mParent;
    4443         QObject *mTarget;
    4444         QString mStartWith;
    4445         QString mFilters;
    4446         QString mCaption;
    4447     };
    4448 
    4449     if (aSelectedFilter)
    4450         *aSelectedFilter = QString::null;
    4451 
    4452     /* Local event loop to run while waiting for the result from another
    4453      * thread */
    4454     QEventLoop loop;
    4455 
    4456     QString startWith = QDir::toNativeSeparators (aStartWith);
    4457     LoopObject loopObject ((QEvent::Type) GetOpenFileNameEvent::TypeId, loop);
    4458 
    4459 //#warning check me!
    4460     if (aParent)
    4461         aParent->setWindowModality (Qt::WindowModal);
    4462 
    4463     Thread openDirThread (aParent, &loopObject, startWith, aFilters, aCaption);
    4464     openDirThread.start();
    4465     loop.exec();
    4466     openDirThread.wait();
    4467 
    4468 //#warning check me!
    4469     if (aParent)
    4470         aParent->setWindowModality (Qt::NonModal);
    4471 
    4472     return QStringList() << loopObject.result();
    4473 
    4474 #elif defined (Q_WS_X11) && (QT_VERSION < 0x040400)
    4475 
    4476     /* Here is workaround for Qt4.3 bug with QFileDialog which crushes when
    4477      * gets initial path as hidden directory if no hidden files are shown.
    4478      * See http://trolltech.com/developer/task-tracker/index_html?method=entry&id=193483
    4479      * for details */
    4480     QFileDialog dlg (aParent);
    4481     dlg.setWindowTitle (aCaption);
    4482     dlg.setDirectory (aStartWith);
    4483     dlg.setFilter (aFilters);
    4484     if (aSingleFile)
    4485         dlg.setFileMode (QFileDialog::ExistingFile);
    4486     else
    4487         dlg.setFileMode (QFileDialog::ExistingFiles);
    4488     if (aSelectedFilter)
    4489         dlg.selectFilter (*aSelectedFilter);
    4490     dlg.setResolveSymlinks (aResolveSymlinks);
    4491     QAction *hidden = dlg.findChild <QAction*> ("qt_show_hidden_action");
    4492     if (hidden)
    4493     {
    4494         hidden->trigger();
    4495         hidden->setVisible (false);
    4496     }
    4497     return dlg.exec() == QDialog::Accepted ? dlg.selectedFiles() : QStringList() << QString::null;
    4498 
    4499 #else
    4500 
    4501     QFileDialog::Options o;
    4502     if (!aResolveSymlinks)
    4503         o |= QFileDialog::DontResolveSymlinks;
    4504     if (aSingleFile)
    4505         return QStringList() << QFileDialog::getOpenFileName (aParent, aCaption, aStartWith,
    4506                                                               aFilters, aSelectedFilter, o);
    4507     else
    4508         return QFileDialog::getOpenFileNames (aParent, aCaption, aStartWith,
    4509                                               aFilters, aSelectedFilter, o);
    4510 #endif
    4511 }
    4512 
    4513 /**
    4514  *  Search for the first directory that exists starting from the passed one
    4515  *  and going up through its parents.  In case if none of the directories
    4516  *  exist (except the root one), the function returns QString::null.
    4517  */
    4518 /* static */
    4519 QString VBoxGlobal::getFirstExistingDir (const QString &aStartDir)
    4520 {
    4521     QString result = QString::null;
    4522     QDir dir (aStartDir);
    4523     while (!dir.exists() && !dir.isRoot())
    4524     {
    4525         QFileInfo dirInfo (dir.absolutePath());
    4526         dir = dirInfo.absolutePath();
    4527     }
    4528     if (dir.exists() && !dir.isRoot())
    4529         result = dir.absolutePath();
    4530     return result;
    45313794}
    45323795
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxImportApplianceWzd.cpp

    r18410 r20078  
    2222
    2323/* VBox includes */
     24#include "VBoxGlobal.h"
    2425#include "VBoxImportApplianceWzd.h"
    25 #include "VBoxGlobal.h"
     26#include "VBoxProblemReporter.h"
     27#include "QIFileDialog.h"
    2628#include "QIWidgetValidator.h"
    27 #include "VBoxProblemReporter.h"
    2829
    2930/* Qt includes */
     31#include <QDialogButtonBox>
    3032#include <QFileInfo>
    31 #include <QDialogButtonBox>
     33#include <QPrintDialog>
    3234#include <QPrinter>
    33 #include <QPrintDialog>
    3435#include <QTextStream>
    3536
     
    100101void VBoxImportLicenseViewer::save()
    101102{
    102     QString fileName = vboxGlobal().getSaveFileName (vboxGlobal().documentsPath(), tr("Text (*.txt)"), this, tr("Save license to file..."));
     103    QString fileName = QIFileDialog::getSaveFileName (vboxGlobal().documentsPath(), tr("Text (*.txt)"), this, tr("Save license to file..."));
    103104    if (!fileName.isEmpty())
    104105    {
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxLineTextEdit.cpp

    r18378 r20078  
    2222
    2323/* VBox includes */
     24#include "VBoxGlobal.h"
    2425#include "VBoxLineTextEdit.h"
    25 #include "VBoxGlobal.h"
     26#include "QIFileDialog.h"
    2627
    2728/* Qt includes */
    28 #include <QPushButton>
    29 #include <QLineEdit>
    3029#include <QDialogButtonBox>
    3130#include <QFile>
     31#include <QLineEdit>
     32#include <QPushButton>
     33#include <QTextEdit>
    3234#include <QTextStream>
    33 #include <QTextEdit>
    3435
    3536////////////////////////////////////////////////////////////////////////////////
     
    8182void VBoxTextEditor::open()
    8283{
    83     QString fileName = vboxGlobal().getOpenFileName (vboxGlobal().documentsPath(), tr("Text (*.txt);;All (*.*)"), this, tr("Select a file to open..."));
     84    QString fileName = QIFileDialog::getOpenFileName (vboxGlobal().documentsPath(), tr("Text (*.txt);;All (*.*)"), this, tr("Select a file to open..."));
    8485    if (!fileName.isEmpty())
    8586    {
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxMediaManagerDlg.cpp

    r19670 r20078  
    2121 */
    2222
     23/* VBox includes */
     24#include "VBoxGlobal.h"
    2325#include "VBoxMediaManagerDlg.h"
    24 #include "VBoxToolBar.h"
    25 #include "QILabel.h"
    2626#include "VBoxNewHDWzd.h"
    2727#include "VBoxProblemReporter.h"
    28 #include "VBoxGlobal.h"
     28#include "VBoxToolBar.h"
     29#include "QIFileDialog.h"
     30#include "QILabel.h"
    2931
    3032/* Qt includes */
     33#include <QCloseEvent>
    3134#include <QDir>
     35#include <QDragEnterEvent>
     36#include <QDropEvent>
    3237#include <QFileInfo>
    3338#include <QHeaderView>
    3439#include <QMenuBar>
     40#include <QProgressBar>
    3541#include <QPushButton>
     42#include <QTimer>
    3643#include <QUrl>
    37 #include <QProgressBar>
    38 #include <QTimer>
    39 #include <QCloseEvent>
    40 #include <QDragEnterEvent>
    41 #include <QDropEvent>
    4244
    4345class AddVDMUrlsEvent: public QEvent
     
    10471049    }
    10481050
    1049     QStringList files = VBoxGlobal::getOpenFileNames (dir, filter, this, title);
     1051    QStringList files = QIFileDialog::getOpenFileNames (dir, filter, this, title);
    10501052    foreach (QString loc, files)
    10511053    {
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