VirtualBox

Ignore:
Timestamp:
Mar 20, 2018 11:04:03 AM (7 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
121357
Message:

FE/Qt: bugref:9049: Full and heavy cleanup for QIFileDialog.

Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
3 edited

Legend:

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

    r71388 r71392  
    626626VirtualBox_QT_MOCSRCS.darwin += \
    627627        src/platform/darwin/UIWindowMenuManager.cpp
    628 VirtualBox_QT_MOCSRCS.win += \
    629         src/extensions/QIFileDialog.cpp
    630628VirtualBox_QT_MOCSRCS.linux += \
    631629        src/globals/UIDesktopWidgetWatchdog.cpp
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIFileDialog.cpp

    r71356 r71392  
    55
    66/*
    7  * Copyright (C) 2009-2017 Oracle Corporation
     7 * Copyright (C) 2009-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1818#ifdef VBOX_WITH_PRECOMPILED_HEADERS
    1919# include <precomp.h>
    20 #else  /* !VBOX_WITH_PRECOMPILED_HEADERS */
     20#else /* !VBOX_WITH_PRECOMPILED_HEADERS */
    2121
    2222/* Qt includes: */
    23 # include <QEventLoop>
     23# ifdef VBOX_WS_MAC
     24#  include <QEventLoop>
     25# endif
    2426
    2527/* GUI includes: */
    26 # include "VBoxGlobal.h"
     28# include "QIFileDialog.h"
    2729# include "UIModalWindowManager.h"
    28 # include "UIMessageCenter.h"
    29 # include "QIFileDialog.h"
    30 
    31 # ifdef VBOX_WS_WIN
    32 /* Qt includes */
    33 #  include <QEvent>
    34 #  include <QThread>
    35 
    36 /* WinAPI includes */
    37 #  include <iprt/win/shlobj.h>
    38 # endif /* !VBOX_WS_WIN */
    3930
    4031#endif /* !VBOX_WITH_PRECOMPILED_HEADERS */
    4132
    4233
    43 #ifdef VBOX_WS_WIN
    44 
    45 static QString extractFilter (const QString &aRawFilter)
    46 {
    47     static const char qt_file_dialog_filter_reg_exp[] =
    48         "([a-zA-Z0-9 ]*)\\(([a-zA-Z0-9_.*? +;#\\[\\]]*)\\)$";
    49 
    50     QString result = aRawFilter;
    51     QRegExp r (QString::fromLatin1 (qt_file_dialog_filter_reg_exp));
    52     int index = r.indexIn (result);
    53     if (index >= 0)
    54         result = r.cap (2);
    55     return result.replace (QChar (' '), QChar (';'));
    56 }
    57 
    58 /**
    59  * Converts QFileDialog filter list to Win32 API filter list.
    60  */
    61 static QString winFilter (const QString &aFilter)
    62 {
    63     QStringList filterLst;
    64 
    65     if (!aFilter.isEmpty())
    66     {
    67         int i = aFilter.indexOf (";;", 0);
    68         QString sep (";;");
    69         if (i == -1)
    70         {
    71             if (aFilter.indexOf ("\n", 0) != -1)
    72             {
    73                 sep = "\n";
    74                 i = aFilter.indexOf (sep, 0);
    75             }
    76         }
    77 
    78         filterLst = aFilter.split (sep);
    79     }
    80 
    81     QStringList::Iterator it = filterLst.begin();
    82     QString winfilters;
    83     for (; it != filterLst.end(); ++ it)
    84     {
    85         winfilters += *it;
    86         winfilters += QChar::Null;
    87         winfilters += extractFilter (*it);
    88         winfilters += QChar::Null;
    89     }
    90     winfilters += QChar::Null;
    91     return winfilters;
    92 }
    93 
    94 /*
    95  * Callback function to control the native Win32 API file dialog
    96  */
    97 UINT_PTR CALLBACK OFNHookProc (HWND aHdlg, UINT aUiMsg, WPARAM aWParam, LPARAM aLParam)
    98 {
    99     RT_NOREF(aWParam);
    100     if (aUiMsg == WM_NOTIFY)
    101     {
    102         OFNOTIFY *notif = (OFNOTIFY*) aLParam;
    103         if (notif->hdr.code == CDN_TYPECHANGE)
    104         {
    105             /* locate native dialog controls */
    106             HWND parent = GetParent (aHdlg);
    107             HWND button = GetDlgItem (parent, IDOK);
    108             HWND textfield = ::GetDlgItem (parent, cmb13);
    109             if (textfield == NULL)
    110                 textfield = ::GetDlgItem (parent, edt1);
    111             if (textfield == NULL)
    112                 return FALSE;
    113             HWND selector = ::GetDlgItem (parent, cmb1);
    114 
    115             /* simulate filter change by pressing apply-key */
    116             int    size = 256;
    117             TCHAR *buffer = (TCHAR*)malloc (size);
    118             SendMessage (textfield, WM_GETTEXT, size, (LPARAM)buffer);
    119             SendMessage (textfield, WM_SETTEXT, 0, (LPARAM)"\0");
    120             SendMessage (button, BM_CLICK, 0, 0);
    121             SendMessage (textfield, WM_SETTEXT, 0, (LPARAM)buffer);
    122             free (buffer);
    123 
    124             /* make request for focus moving to filter selector combo-box */
    125             HWND curFocus = GetFocus();
    126             PostMessage (curFocus, WM_KILLFOCUS, (WPARAM)selector, 0);
    127             PostMessage (selector, WM_SETFOCUS, (WPARAM)curFocus, 0);
    128             WPARAM wParam = MAKEWPARAM (WA_ACTIVE, 0);
    129             PostMessage (selector, WM_ACTIVATE, wParam, (LPARAM)curFocus);
    130         }
    131     }
    132     return FALSE;
    133 }
    134 
    135 /*
    136  * Callback function to control the native Win32 API folders dialog
    137  */
    138 static int __stdcall winGetExistDirCallbackProc (HWND hwnd, UINT uMsg,
    139                                                  LPARAM lParam, LPARAM lpData)
    140 {
    141     if (uMsg == BFFM_INITIALIZED && lpData != 0)
    142     {
    143         QString *initDir = (QString *)(lpData);
    144         if (!initDir->isEmpty())
    145         {
    146             SendMessage (hwnd, BFFM_SETSELECTION, TRUE, uintptr_t(
    147                 initDir->isNull() ? 0 : initDir->utf16()));
    148         }
    149     }
    150     else if (uMsg == BFFM_SELCHANGED)
    151     {
    152         TCHAR path [MAX_PATH];
    153         SHGetPathFromIDList (LPITEMIDLIST (lParam), path);
    154         QString tmpStr = QString::fromUtf16 ((ushort*)path);
    155         if (!tmpStr.isEmpty())
    156             SendMessage (hwnd, BFFM_ENABLEOK, 1, 1);
    157         else
    158             SendMessage (hwnd, BFFM_ENABLEOK, 0, 0);
    159         SendMessage (hwnd, BFFM_SETSTATUSTEXT, 1, uintptr_t(path));
    160     }
    161     return 0;
    162 }
    163 
    164 /**
    165  *  QEvent class to carry Win32 API native dialog's result information
    166  */
    167 class OpenNativeDialogEvent : public QEvent
    168 {
    169 public:
    170 
    171     OpenNativeDialogEvent (const QString &aResult, QEvent::Type aType)
    172         : QEvent (aType), mResult (aResult) {}
    173 
    174     const QString& result() { return mResult; }
    175 
    176 private:
    177 
    178     QString mResult;
    179 };
    180 
    181 /**
    182  *  QObject class reimplementation which is the target for OpenNativeDialogEvent
    183  *  event. It receives OpenNativeDialogEvent event from another thread,
    184  *  stores result information and exits the given local event loop.
    185  */
    186 class LoopObject : public QObject
    187 {
    188     Q_OBJECT;
    189 
    190 public:
    191 
    192     LoopObject (QEvent::Type aType, QEventLoop &aLoop)
    193         : mType (aType), mLoop (aLoop), mResult (QString::null) {}
    194     const QString& result() { return mResult; }
    195 
    196 private:
    197 
    198     bool event (QEvent *aEvent)
    199     {
    200         if (aEvent->type() == mType)
    201         {
    202             OpenNativeDialogEvent *ev = (OpenNativeDialogEvent*) aEvent;
    203             mResult = ev->result();
    204             mLoop.quit();
    205             return true;
    206         }
    207         return QObject::event (aEvent);
    208     }
    209 
    210     QEvent::Type mType;
    211     QEventLoop &mLoop;
    212     QString mResult;
    213 };
    214 
    215 #endif /* VBOX_WS_WIN */
    216 
    217 QIFileDialog::QIFileDialog (QWidget *aParent, Qt::WindowFlags aFlags)
    218     : QFileDialog (aParent, aFlags)
    219 {
    220 }
    221 
    222 /**
    223  *  Reimplementation of QFileDialog::getExistingDirectory() that removes some
    224  *  oddities and limitations.
    225  *
    226  *  On Win32, this function makes sure a native dialog is launched in
    227  *  another thread to avoid dialog visualization errors occurring due to
    228  *  multi-threaded COM apartment initialization on the main UI thread while
    229  *  the appropriate native dialog function expects a single-threaded one.
    230  *
    231  *  On all other platforms, this function is equivalent to
    232  *  QFileDialog::getExistingDirectory().
    233  */
    234 QString QIFileDialog::getExistingDirectory (const QString &aDir,
    235                                             QWidget *aParent,
    236                                             const QString &aCaption,
    237                                             bool aDirOnly,
    238                                             bool aResolveSymlinks)
     34QIFileDialog::QIFileDialog(QWidget *pParent, Qt::WindowFlags enmFlags)
     35    : QFileDialog(pParent, enmFlags)
     36{
     37}
     38
     39/* static */
     40QString QIFileDialog::getExistingDirectory(const QString &strDir,
     41                                           QWidget *pParent,
     42                                           const QString &strCaption,
     43                                           bool fDirOnly,
     44                                           bool fResolveSymLinks)
    23945{
    24046#ifdef VBOX_WS_MAC
    24147
    242     /* After 4.5 exec ignores the Qt::Sheet flag.
    243      * See "New Ways of Using Dialogs" in http://doc.trolltech.com/qq/QtQuarterly30.pdf why.
    244      * We want the old behavior for file-save dialog. Unfortunately there is a bug in Qt 4.5.x
    245      * which result in showing the native & the Qt dialog at the same time. */
    246     QWidget *pParent = windowManager().realParentWindow(aParent);
    247     QFileDialog dlg(pParent);
    248     windowManager().registerNewParent(&dlg, pParent);
    249     dlg.setWindowTitle(aCaption);
    250     dlg.setDirectory(aDir);
    251     dlg.setResolveSymlinks(aResolveSymlinks);
    252     dlg.setFileMode(aDirOnly ? QFileDialog::DirectoryOnly : QFileDialog::Directory);
     48    // WORKAROUND:
     49    // After 4.5 exec ignores the Qt::Sheet flag.
     50    // See "New Ways of Using Dialogs" in http://doc.trolltech.com/qq/QtQuarterly30.pdf why.
     51    // We want the old behavior for file-save dialog. Unfortunately there is a bug in Qt 4.5.x
     52    // which result in showing the native & the Qt dialog at the same time.
     53    QWidget *pRealParent = windowManager().realParentWindow(pParent);
     54    QFileDialog dlg(pRealParent);
     55    windowManager().registerNewParent(&dlg, pRealParent);
     56    dlg.setWindowTitle(strCaption);
     57    dlg.setDirectory(strDir);
     58    dlg.setResolveSymlinks(fResolveSymLinks);
     59    dlg.setFileMode(fDirOnly ? QFileDialog::DirectoryOnly : QFileDialog::Directory);
    25360
    25461    QEventLoop eventLoop;
     
    26067    return dlg.result() == QDialog::Accepted ? dlg.selectedFiles().value(0, QString()) : QString();
    26168
    262 #else
     69#else /* !VBOX_WS_MAC */
    26370
    26471    QFileDialog::Options o;
    265 # if defined (VBOX_WS_X11)
    266     /** @todo see http://bugs.kde.org/show_bug.cgi?id=210904, make it conditional
    267      *        when this bug is fixed (xtracker 5167).
    268      *        Apparently not necessary anymore (xtracker 5748)! */
    269 //    if (vboxGlobal().isKWinManaged())
    270 //      o |= QFileDialog::DontUseNativeDialog;
    271 # endif
    272     if (aDirOnly)
     72    if (fDirOnly)
    27373        o |= QFileDialog::ShowDirsOnly;
    274     if (!aResolveSymlinks)
     74    if (!fResolveSymLinks)
    27575        o |= QFileDialog::DontResolveSymlinks;
    276     return QFileDialog::getExistingDirectory (aParent, aCaption, aDir, o);
    277 
    278 #endif
    279 }
    280 
    281 /**
    282  *  Reimplementation of QFileDialog::getSaveFileName() that removes some
    283  *  oddities and limitations.
    284  *
    285  *  On Win32, this function makes sure a file filter is applied automatically
    286  *  right after it is selected from the drop-down list, to conform to common
    287  *  experience in other applications. Note that currently, @a selectedFilter
    288  *  is always set to null on return.
    289  *
    290  *  On all other platforms, this function is equivalent to
    291  *  QFileDialog::getSaveFileName().
    292  */
    293 /* static */
    294 QString QIFileDialog::getSaveFileName (const QString &aStartWith,
    295                                        const QString &aFilters,
    296                                        QWidget       *aParent,
    297                                        const QString &aCaption,
    298                                        QString       *aSelectedFilter /* = 0 */,
    299                                        bool           aResolveSymlinks /* = true */,
    300                                        bool           fConfirmOverwrite /* = false */)
     76    return QFileDialog::getExistingDirectory(pParent, strCaption, strDir, o);
     77
     78#endif /* !VBOX_WS_MAC */
     79}
     80
     81/* static */
     82QString QIFileDialog::getSaveFileName(const QString &strStartWith,
     83                                      const QString &strFilters,
     84                                      QWidget       *pParent,
     85                                      const QString &strCaption,
     86                                      QString       *pStrSelectedFilter /* = 0 */,
     87                                      bool           fResolveSymLinks /* = true */,
     88                                      bool           fConfirmOverwrite /* = false */)
    30189{
    30290#ifdef VBOX_WS_MAC
    30391
    304     /* After 4.5 exec ignores the Qt::Sheet flag.
    305      * See "New Ways of Using Dialogs" in http://doc.trolltech.com/qq/QtQuarterly30.pdf why.
    306      * We want the old behavior for file-save dialog. Unfortunately there is a bug in Qt 4.5.x
    307      * which result in showing the native & the Qt dialog at the same time. */
    308     QWidget *pParent = windowManager().realParentWindow(aParent);
    309     QFileDialog dlg(pParent);
    310     windowManager().registerNewParent(&dlg, pParent);
    311     dlg.setWindowTitle(aCaption);
     92    // WORKAROUND:
     93    // After 4.5 exec ignores the Qt::Sheet flag.
     94    // See "New Ways of Using Dialogs" in http://doc.trolltech.com/qq/QtQuarterly30.pdf why.
     95    // We want the old behavior for file-save dialog. Unfortunately there is a bug in Qt 4.5.x
     96    // which result in showing the native & the Qt dialog at the same time.
     97    QWidget *pRealParent = windowManager().realParentWindow(pParent);
     98    QFileDialog dlg(pRealParent);
     99    windowManager().registerNewParent(&dlg, pRealParent);
     100    dlg.setWindowTitle(strCaption);
    312101
    313102    /* Some predictive algorithm which seems missed in native code. */
    314     QDir dir(aStartWith);
     103    QDir dir(strStartWith);
    315104    while (!dir.isRoot() && !dir.exists())
    316105        dir = QDir(QFileInfo(dir.absolutePath()).absolutePath());
     
    318107    if (!strDirectory.isNull())
    319108        dlg.setDirectory(strDirectory);
    320     if (strDirectory != aStartWith)
    321         dlg.selectFile(QFileInfo(aStartWith).absoluteFilePath());
    322 
    323     dlg.setNameFilter(aFilters);
     109    if (strDirectory != strStartWith)
     110        dlg.selectFile(QFileInfo(strStartWith).absoluteFilePath());
     111
     112    dlg.setNameFilter(strFilters);
    324113    dlg.setFileMode(QFileDialog::AnyFile);
    325114    dlg.setAcceptMode(QFileDialog::AcceptSave);
    326     if (aSelectedFilter)
    327         dlg.selectNameFilter(*aSelectedFilter);
    328     dlg.setResolveSymlinks(aResolveSymlinks);
     115    if (pStrSelectedFilter)
     116        dlg.selectNameFilter(*pStrSelectedFilter);
     117    dlg.setResolveSymlinks(fResolveSymLinks);
    329118    dlg.setConfirmOverwrite(fConfirmOverwrite);
    330119
     
    337126    return dlg.result() == QDialog::Accepted ? dlg.selectedFiles().value(0, QString()) : QString();
    338127
    339 #else
     128#else /* !VBOX_WS_MAC */
    340129
    341130    QFileDialog::Options o;
    342 # if defined (VBOX_WS_X11)
    343     /** @todo see http://bugs.kde.org/show_bug.cgi?id=210904, make it conditional
    344      *        when this bug is fixed (xtracker 5167)
    345      *        Apparently not necessary anymore (xtracker 5748)! */
    346 //    if (vboxGlobal().isKWinManaged())
    347 //      o |= QFileDialog::DontUseNativeDialog;
    348 # endif
    349     if (!aResolveSymlinks)
     131    if (!fResolveSymLinks)
    350132        o |= QFileDialog::DontResolveSymlinks;
    351133    if (!fConfirmOverwrite)
    352134        o |= QFileDialog::DontConfirmOverwrite;
    353     return QFileDialog::getSaveFileName (aParent, aCaption, aStartWith,
    354                                          aFilters, aSelectedFilter, o);
    355 #endif
    356 }
    357 
    358 /**
    359  *  Reimplementation of QFileDialog::getOpenFileName() that removes some
    360  *  oddities and limitations.
    361  *
    362  *  On Win32, this function makes sure a file filter is applied automatically
    363  *  right after it is selected from the drop-down list, to conform to common
    364  *  experience in other applications. Note that currently, @a selectedFilter
    365  *  is always set to null on return.
    366  *
    367  *  On all other platforms, this function is equivalent to
    368  *  QFileDialog::getOpenFileName().
    369  */
    370 /* static */
    371 QString QIFileDialog::getOpenFileName (const QString &aStartWith,
    372                                        const QString &aFilters,
    373                                        QWidget       *aParent,
    374                                        const QString &aCaption,
    375                                        QString       *aSelectedFilter /* = 0 */,
    376                                        bool           aResolveSymlinks /* = true */)
    377 {
    378     return getOpenFileNames (aStartWith,
    379                              aFilters,
    380                              aParent,
    381                              aCaption,
    382                              aSelectedFilter,
    383                              aResolveSymlinks,
    384                              true /* aSingleFile */).value (0, "");
    385 }
    386 
    387 /**
    388  *  Reimplementation of QFileDialog::getOpenFileNames() that removes some
    389  *  oddities and limitations.
    390  *
    391  *  On Win32, this function makes sure a file filter is applied automatically
    392  *  right after it is selected from the drop-down list, to conform to common
    393  *  experience in other applications. Note that currently, @a selectedFilter
    394  *  is always set to null on return.
    395  *  @todo: implement the multiple file selection on win
    396  *  @todo: is this extra handling on win still necessary with Qt4?
    397  *
    398  *  On all other platforms, this function is equivalent to
    399  *  QFileDialog::getOpenFileNames().
    400  */
    401 /* static */
    402 QStringList QIFileDialog::getOpenFileNames (const QString &aStartWith,
    403                                             const QString &aFilters,
    404                                             QWidget       *aParent,
    405                                             const QString &aCaption,
    406                                             QString       *aSelectedFilter /* = 0 */,
    407                                             bool           aResolveSymlinks /* = true */,
    408                                             bool           aSingleFile /* = false */)
     135    return QFileDialog::getSaveFileName(pParent, strCaption, strStartWith,
     136                                        strFilters, pStrSelectedFilter, o);
     137
     138#endif /* !VBOX_WS_MAC */
     139}
     140
     141/* static */
     142QString QIFileDialog::getOpenFileName(const QString &strStartWith,
     143                                      const QString &strFilters,
     144                                      QWidget       *pParent,
     145                                      const QString &strCaption,
     146                                      QString       *pStrSelectedFilter /* = 0 */,
     147                                      bool           fResolveSymLinks /* = true */)
     148{
     149    return getOpenFileNames(strStartWith,
     150                            strFilters,
     151                            pParent,
     152                            strCaption,
     153                            pStrSelectedFilter,
     154                            fResolveSymLinks,
     155                            true /* fSingleFile */).value(0, "");
     156}
     157
     158/* static */
     159QStringList QIFileDialog::getOpenFileNames(const QString &strStartWith,
     160                                           const QString &strFilters,
     161                                           QWidget       *pParent,
     162                                           const QString &strCaption,
     163                                           QString       *pStrSelectedFilter /* = 0 */,
     164                                           bool           fResolveSymLinks /* = true */,
     165                                           bool           fSingleFile /* = false */)
    409166{
    410167#ifdef VBOX_WS_MAC
    411168
    412     /* After 4.5 exec ignores the Qt::Sheet flag.
    413      * See "New Ways of Using Dialogs" in http://doc.trolltech.com/qq/QtQuarterly30.pdf why.
    414      * We want the old behavior for file-save dialog. Unfortunately there is a bug in Qt 4.5.x
    415      * which result in showing the native & the Qt dialog at the same time. */
    416     QWidget *pParent = windowManager().realParentWindow(aParent);
    417     QFileDialog dlg(pParent);
    418     windowManager().registerNewParent(&dlg, pParent);
    419     dlg.setWindowTitle(aCaption);
     169    // WORKAROUND:
     170    // After 4.5 exec ignores the Qt::Sheet flag.
     171    // See "New Ways of Using Dialogs" in http://doc.trolltech.com/qq/QtQuarterly30.pdf why.
     172    // We want the old behavior for file-save dialog. Unfortunately there is a bug in Qt 4.5.x
     173    // which result in showing the native & the Qt dialog at the same time.
     174    QWidget *pRealParent = windowManager().realParentWindow(pParent);
     175    QFileDialog dlg(pRealParent);
     176    windowManager().registerNewParent(&dlg, pRealParent);
     177    dlg.setWindowTitle(strCaption);
    420178
    421179    /* Some predictive algorithm which seems missed in native code. */
    422     QDir dir(aStartWith);
     180    QDir dir(strStartWith);
    423181    while (!dir.isRoot() && !dir.exists())
    424182        dir = QDir(QFileInfo(dir.absolutePath()).absolutePath());
     
    426184    if (!strDirectory.isNull())
    427185        dlg.setDirectory(strDirectory);
    428     if (strDirectory != aStartWith)
    429         dlg.selectFile(QFileInfo(aStartWith).absoluteFilePath());
    430 
    431     dlg.setNameFilter(aFilters);
    432     if (aSingleFile)
     186    if (strDirectory != strStartWith)
     187        dlg.selectFile(QFileInfo(strStartWith).absoluteFilePath());
     188
     189    dlg.setNameFilter(strFilters);
     190    if (fSingleFile)
    433191        dlg.setFileMode(QFileDialog::ExistingFile);
    434192    else
    435193        dlg.setFileMode(QFileDialog::ExistingFiles);
    436     if (aSelectedFilter)
    437         dlg.selectNameFilter(*aSelectedFilter);
    438     dlg.setResolveSymlinks(aResolveSymlinks);
     194    if (pStrSelectedFilter)
     195        dlg.selectNameFilter(*pStrSelectedFilter);
     196    dlg.setResolveSymlinks(fResolveSymLinks);
    439197
    440198    QEventLoop eventLoop;
     
    449207
    450208    QFileDialog::Options o;
    451     if (!aResolveSymlinks)
     209    if (!fResolveSymLinks)
    452210        o |= QFileDialog::DontResolveSymlinks;
    453 # if defined (VBOX_WS_X11)
    454     /** @todo see http://bugs.kde.org/show_bug.cgi?id=210904, make it conditional
    455      *        when this bug is fixed (xtracker 5167)
    456      *        Apparently not necessary anymore (xtracker 5748)! */
    457 //    if (vboxGlobal().isKWinManaged())
    458 //      o |= QFileDialog::DontUseNativeDialog;
    459 # endif
    460 
    461     if (aSingleFile)
    462         return QStringList() << QFileDialog::getOpenFileName (aParent, aCaption, aStartWith,
    463                                                               aFilters, aSelectedFilter, o);
     211
     212    if (fSingleFile)
     213        return QStringList() << QFileDialog::getOpenFileName(pParent, strCaption, strStartWith,
     214                                                             strFilters, pStrSelectedFilter, o);
    464215    else
    465         return QFileDialog::getOpenFileNames (aParent, aCaption, aStartWith,
    466                                               aFilters, aSelectedFilter, o);
     216        return QFileDialog::getOpenFileNames(pParent, strCaption, strStartWith,
     217                                             strFilters, pStrSelectedFilter, o);
     218
    467219#endif
    468220}
    469221
    470 /**
    471  *  Search for the first directory that exists starting from the passed one
    472  *  and going up through its parents.  In case if none of the directories
    473  *  exist (except the root one), the function returns QString::null.
    474  */
    475 /* static */
    476 QString QIFileDialog::getFirstExistingDir (const QString &aStartDir)
    477 {
    478     QString result = QString::null;
    479     QDir dir (aStartDir);
     222/* static */
     223QString QIFileDialog::getFirstExistingDir(const QString &strStartDir)
     224{
     225    QString strResult = QString();
     226    QDir dir(strStartDir);
    480227    while (!dir.exists() && !dir.isRoot())
    481228    {
    482         QFileInfo dirInfo (dir.absolutePath());
     229        QFileInfo dirInfo(dir.absolutePath());
    483230        if (dir == QDir(dirInfo.absolutePath()))
    484231            break;
     
    486233    }
    487234    if (dir.exists() && !dir.isRoot())
    488         result = dir.absolutePath();
    489     return result;
    490 }
    491 
    492 #if defined VBOX_WS_WIN
    493 #include "QIFileDialog.moc"
    494 #endif
    495 
     235        strResult = dir.absolutePath();
     236    return strResult;
     237}
     238
  • trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIFileDialog.h

    r71027 r71392  
    55
    66/*
    7  * Copyright (C) 2009-2017 Oracle Corporation
     7 * Copyright (C) 2009-2018 Oracle Corporation
    88 *
    99 * This file is part of VirtualBox Open Source Edition (OSE), as
     
    1616 */
    1717
    18 #ifndef __QIFileDialog_h__
    19 #define __QIFileDialog_h__
     18#ifndef ___QIFileDialog_h___
     19#define ___QIFileDialog_h___
    2020
    21 /* Qt includes */
     21/* Qt includes: */
    2222#include <QFileDialog>
    2323
     24/** QFileDialog subclass simplifying access to it's static stuff. */
    2425class QIFileDialog : public QFileDialog
    2526{
    2627    Q_OBJECT;
    2728
     29    /** Constructs our own file-dialog passing @a pParent and enmFlags to the base-class.
     30      * Doesn't mean to be used directly, cause this subclass is a bunch of statics. */
     31    QIFileDialog(QWidget *pParent, Qt::WindowFlags enmFlags);
     32
    2833public:
    2934
    30     QIFileDialog (QWidget *aParent, Qt::WindowFlags aFlags);
     35    /** Returns an existing directory selected by the user.
     36      * @param  strDir            Brings the dir to start from.
     37      * @param  pParent           Brings the parent.
     38      * @param  strCaption        Brings the dialog caption.
     39      * @param  fDirOnly          Brings whether dialog should show dirs only.
     40      * @param  fResolveSymLinks  Brings whether dialog should resolve sym-links. */
     41    static QString getExistingDirectory(const QString &strDir, QWidget *pParent,
     42                                        const QString &strCaption = QString(),
     43                                        bool fDirOnly = true,
     44                                        bool fResolveSymLinks = true);
    3145
    32     static QString getExistingDirectory (const QString &aDir, QWidget *aParent,
    33                                          const QString &aCaption = QString::null,
    34                                          bool aDirOnly = true,
    35                                          bool resolveSymlinks = true);
     46    /** Returns a file name selected by the user. The file does not have to exist.
     47      * @param  strStartWith        Brings the full file path to start from.
     48      * @param  strFilters          Brings the filters.
     49      * @param  pParent             Brings the parent.
     50      * @param  strCaption          Brings the dialog caption.
     51      * @param  pStrSelectedFilter  Brings the selected filter.
     52      * @param  fResolveSymLinks    Brings whether dialog should resolve sym-links.
     53      * @param  fConfirmOverwrite   Brings whether dialog should confirm overwrite. */
     54    static QString getSaveFileName(const QString &strStartWith, const QString &strFilters, QWidget *pParent,
     55                                   const QString &strCaption, QString *pStrSelectedFilter = 0,
     56                                   bool fResolveSymLinks = true, bool fConfirmOverwrite = false);
    3657
    37     static QString getSaveFileName (const QString &aStartWith, const QString &aFilters, QWidget *aParent,
    38                                     const QString &aCaption, QString *aSelectedFilter = 0,
    39                                     bool aResolveSymLinks = true, bool fConfirmOverwrite = false);
     58    /** Returns an existing file selected by the user. If the user presses Cancel, it returns a null string.
     59      * @param  strStartWith        Brings the full file path to start from.
     60      * @param  strFilters          Brings the filters.
     61      * @param  pParent             Brings the parent.
     62      * @param  strCaption          Brings the dialog caption.
     63      * @param  pStrSelectedFilter  Brings the selected filter.
     64      * @param  fResolveSymLinks    Brings whether dialog should resolve sym-links. */
     65    static QString getOpenFileName(const QString &strStartWith, const QString &strFilters, QWidget *pParent,
     66                                   const QString &strCaption, QString *pStrSelectedFilter = 0,
     67                                   bool fResolveSymLinks = true);
    4068
    41     static QString getOpenFileName (const QString &aStartWith, const QString &aFilters, QWidget *aParent,
    42                                     const QString &aCaption, QString *aSelectedFilter = 0,
    43                                     bool aResolveSymLinks = true);
     69    /** Returns one or more existing files selected by the user.
     70      * @param  strStartWith        Brings the full file path to start from.
     71      * @param  strFilters          Brings the filters.
     72      * @param  pParent             Brings the parent.
     73      * @param  strCaption          Brings the dialog caption.
     74      * @param  pStrSelectedFilter  Brings the selected filter.
     75      * @param  fResolveSymLinks    Brings whether dialog should resolve sym-links.
     76      * @param  fSingleFile         Brings whether dialog should allow chosing single file only. */
     77    static QStringList getOpenFileNames(const QString &strStartWith, const QString &strFilters, QWidget *pParent,
     78                                        const QString &strCaption, QString *pStrSelectedFilter = 0,
     79                                        bool fResolveSymLinks = true,
     80                                        bool fSingleFile = false);
    4481
    45     static QStringList getOpenFileNames (const QString &aStartWith, const QString &aFilters, QWidget *aParent,
    46                                          const QString &aCaption, QString *aSelectedFilter = 0,
    47                                          bool aResolveSymLinks = true,
    48                                          bool aSingleFile = false);
    49 
    50     static QString getFirstExistingDir (const QString &aStartDir);
     82    /** Search for the first directory that exists starting from the
     83      * passed one @a strStartDir and going up through its parents. */
     84    static QString getFirstExistingDir(const QString &strStartDir);
    5185};
    5286
    53 #endif /* __QIFileDialog_h__ */
     87#endif /* !___QIFileDialog_h___ */
    5488
Note: See TracChangeset for help on using the changeset viewer.

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