VirtualBox

Changeset 1889 in vbox


Ignore:
Timestamp:
Apr 3, 2007 3:42:03 PM (18 years ago)
Author:
vboxsync
svn:sync-xref-src-repo-rev:
20134
Message:

1902: "Select Directory" dialogs are not native:

  1. Fixing getExistingDirectory method over-complexity through inner event loop processing.
  2. Fixing starting directory selection for example, we have “/path/to/dir” directory to be set as the initial directory of the dialog:
    1. For Win32 platform “dir” will be the current selection after opening the contents of “/path/to”.
    2. For the other platforms where it is not possible to select some dir at the beginning, the initial directory will be set to “/path/to/dir” in the dialog instead of “/path/to”.
Location:
trunk/src/VBox/Frontends/VirtualBox
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxDefs.h

    r1863 r1889  
    137137#if defined (Q_WS_WIN)
    138138        ShellExecuteEventType,
    139         GetExistDirectoryEventType,
    140139#endif
    141140        ActivateMenuEventType,
  • trunk/src/VBox/Frontends/VirtualBox/include/VBoxGlobal.h

    r1863 r1889  
    396396    static QString highlight (const QString &aStr, bool aToolTip = false);
    397397
    398     void getExistingDirectory (const QString &aDir, QWidget *aParent,
    399                                const char *aName = 0,
    400                                const QString &aCaption = QString::null,
    401                                bool aDirOnly = TRUE,
    402                                bool resolveSymlinks = TRUE);
     398    static QString getExistingDirectory (const QString &aDir, QWidget *aParent,
     399                                         const char *aName = 0,
     400                                         const QString &aCaption = QString::null,
     401                                         bool aDirOnly = TRUE,
     402                                         bool resolveSymlinks = TRUE);
    403403
    404404    static QString getOpenFileName (const QString &, const QString &, QWidget*,
     
    406406                                    QString *defaultFilter = 0,
    407407                                    bool resolveSymLinks = true);
     408
     409    static QString getStartingDir (const QString &);
    408410
    409411signals:
     
    446448    void sessionStateChanged (const VBoxSessionStateChangeEvent &e);
    447449    void snapshotChanged (const VBoxSnapshotEvent &e);
    448 
    449     /* Emitted upon getExistingDirectory dialog accepting */
    450     void existingDirectoryResult (const QString &);
    451450
    452451protected:
  • trunk/src/VBox/Frontends/VirtualBox/src/VBoxGlobal.cpp

    r1863 r1889  
    4848#ifdef Q_WS_WIN
    4949#include "shlobj.h"
     50#include <qeventloop.h>
    5051#endif
    5152
     
    9596    QString mURL;
    9697    bool mOk;
    97 };
    98 
    99 class VBoxGetExistDirectoryEvent : public QEvent
    100 {
    101 public:
    102 
    103     /** Constructs a regular enum event */
    104     VBoxGetExistDirectoryEvent (QThread *aThread, const QString &aName)
    105         : QEvent ((QEvent::Type) VBoxDefs::GetExistDirectoryEventType)
    106         , mThread (aThread), mName (aName)
    107         {}
    108 
    109     QThread *mThread;
    110     QString mName;
    11198};
    11299#endif
     
    418405        {
    419406            SendMessage (hwnd, BFFM_SETSELECTION, TRUE, Q_ULONG (initDir->ucs2()));
    420             SendMessage (hwnd, BFFM_SETEXPANDED, TRUE, Q_ULONG (initDir->ucs2()));
     407            //SendMessage (hwnd, BFFM_SETEXPANDED, TRUE, Q_ULONG (initDir->ucs2()));
    421408        }
    422409    }
     
    22222209 *  QFileDialog::getExistingDirectory().
    22232210 */
    2224 void VBoxGlobal::getExistingDirectory (const QString &aDir,
    2225                                        QWidget *aParent, const char *aName,
    2226                                        const QString &aCaption,
    2227                                        bool aDirOnly,
    2228                                        bool aResolveSymlinks)
     2211QString VBoxGlobal::getExistingDirectory (const QString &aDir,
     2212                                          QWidget *aParent, const char *aName,
     2213                                          const QString &aCaption,
     2214                                          bool aDirOnly,
     2215                                          bool aResolveSymlinks)
    22292216{
    22302217#if defined Q_WS_WIN
    22312218
    2232     /* open existing directory thread class */
     2219    /**
     2220     *  QEvent type for VBoxGetExistDirectoryEvent event
     2221     */
     2222    enum { GetExistDirectoryEventType = QEvent::User + 300 };
     2223
     2224    /**
     2225     *  QEvent class reimplementation to carry Win32 API native dialog's
     2226     *  result folder information
     2227     */
     2228    class VBoxGetExistDirectoryEvent : public QEvent
     2229    {
     2230    public:
     2231
     2232        VBoxGetExistDirectoryEvent (const QString &aName)
     2233            : QEvent ((QEvent::Type) GetExistDirectoryEventType)
     2234            , mName (aName)
     2235            {}
     2236
     2237        QString mName;
     2238    };
     2239
     2240    /**
     2241     *  QThread class reimplementation to open Win32 API native folder's dialog
     2242     */
    22332243    class Thread : public QThread
    22342244    {
     
    22772287            else
    22782288                result = QString::null;
    2279             QApplication::postEvent (mTarget,
    2280                 new VBoxGetExistDirectoryEvent (this, result));
     2289            QApplication::postEvent (mTarget, new VBoxGetExistDirectoryEvent (result));
    22812290            if (parent) parent->setEnabled (true);
    22822291        }
     
    22902299    };
    22912300
     2301    class LoopObject : public QObject
     2302    {
     2303    public:
     2304
     2305        LoopObject() : mFolder (QString::null) {}
     2306        const QString& folder() { return mFolder; }
     2307
     2308    private:
     2309
     2310        bool event (QEvent *e)
     2311        {
     2312            switch (e->type())
     2313            {
     2314                case GetExistDirectoryEventType:
     2315                {
     2316                    VBoxGetExistDirectoryEvent *ev = (VBoxGetExistDirectoryEvent *) e;
     2317                    mFolder = ev->mName;
     2318                    qApp->eventLoop()->exitLoop();
     2319                    return true;
     2320                }
     2321                default:
     2322                    break;
     2323            }
     2324            return QObject::event (e);
     2325        }
     2326
     2327        QString mFolder;
     2328    };
     2329
    22922330    /* this dialog is proposed to be a modal */
    2293     if (!aParent) return;
     2331    if (!aParent) return QString::null;
    22942332    QString dir = QDir::convertSeparators (aDir);
    2295     Thread *openDirThread = new Thread (aParent->winId(), this, dir, aCaption);
    2296     openDirThread->start();
    2297     /* thread will be deleted in the VBoxGetExistDirectoryEvent handler */
     2333    LoopObject loopObject;
     2334    Thread openDirThread (aParent->winId(), &loopObject, dir, aCaption);
     2335    openDirThread.start();
     2336    qApp->eventLoop()->enterLoop();
     2337    openDirThread.wait();
     2338    return loopObject.folder();
    22982339
    22992340#else
    23002341
    2301     QString result = QFileDialog::getExistingDirectory (aDir, aParent,
    2302         aName, aCaption, aDirOnly, aResolveSymlinks);
    2303     emit existingDirectoryResult (result);
     2342    return QFileDialog::getExistingDirectory (aDir, aParent, aName, aCaption,
     2343                                              aDirOnly, aResolveSymlinks);
    23042344
    23052345#endif
     
    24122452}
    24132453
     2454/**
     2455 *  Search for the first directory that exists starting from the passed one.
     2456 *  In case of there is no directory (and all of its parent except root) exist
     2457 *  the function returns QString::null.
     2458 */
     2459/* static */
     2460QString VBoxGlobal::getStartingDir (const QString &aStartDir)
     2461{
     2462    QString result = QString::null;
     2463    QDir dir (aStartDir);
     2464    while (!dir.exists() && !dir.isRoot())
     2465    {
     2466        QFileInfo dirInfo (dir.absPath());
     2467        dir = dirInfo.dirPath (true);
     2468    }
     2469    if (dir.exists() && !dir.isRoot())
     2470        result = dir.absPath();
     2471    return result;
     2472}
     2473
     2474
    24142475// Protected members
    24152476////////////////////////////////////////////////////////////////////////////////
     
    24282489            ev->mThread->wait();
    24292490            delete ev->mThread;
    2430             return true;
    2431         }
    2432 
    2433         case VBoxDefs::GetExistDirectoryEventType:
    2434         {
    2435             VBoxGetExistDirectoryEvent *ev = (VBoxGetExistDirectoryEvent *) e;
    2436             /* wait for the thread and free resources */
    2437             ev->mThread->wait();
    2438             delete ev->mThread;
    2439             emit existingDirectoryResult (ev->mName);
    24402491            return true;
    24412492        }
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxGlobalSettingsDlg.ui

    r1863 r1889  
    10411041    <variable access="private">bool mUSBFilterListModified;</variable>
    10421042    <variable access="private">VBoxUSBMenu *usbDevicesMenu;</variable>
    1043     <variable access="private">QLineEdit *mLastAccessedField;</variable>
    10441043</variables>
    10451044<slots>
     
    10501049    <slot>tbResetFolder_clicked()</slot>
    10511050    <slot>tbSelectFolder_clicked()</slot>
    1052     <slot>folderSelected( const QString &amp; )</slot>
    10531051    <slot>addUSBFilter( const CUSBDeviceFilter &amp;, bool )</slot>
    10541052    <slot>lvUSBFilters_currentChanged( QListViewItem * )</slot>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxGlobalSettingsDlg.ui.h

    r1863 r1889  
    148148
    149149    /* General page */
    150 
    151     mLastAccessedField = 0;
    152     connect (&vboxGlobal(), SIGNAL (existingDirectoryResult (const QString&)),
    153              this, SLOT (folderSelected (const QString&)));
    154150
    155151/// @todo (dmik) remove
     
    503499    if (tb == tbSelectVDIFolder) le = leVDIFolder;
    504500    else if (tb == tbSelectMachineFolder) le = leMachineFolder;
    505     mLastAccessedField = le;
    506501    Assert (le);
    507502
    508     QString initDir = vboxGlobal().virtualBox().GetHomeFolder();
    509 
    510     if (!le->text().isEmpty())
    511     {
    512         /* set the first parent directory that exists as the current */
    513         const QDir _dir (initDir);
    514         QFileInfo fld (_dir, le->text());
    515         do
    516         {
    517             QString dp = fld.dirPath (false);
    518             fld = QFileInfo (dp);
    519         }
    520         while (!fld.exists() && !QDir (fld.absFilePath()).isRoot());
    521 
    522         if (fld.exists())
    523             initDir = fld.absFilePath();
    524     }
    525 
    526     vboxGlobal().getExistingDirectory (initDir, this);
    527 }
    528 
    529 void VBoxGlobalSettingsDlg::folderSelected (const QString &aFolder)
    530 {
    531     if (aFolder.isNull())
     503    QString initDir = VBoxGlobal::getStartingDir (le->text());
     504    if (initDir.isNull())
     505        initDir = vboxGlobal().virtualBox().GetHomeFolder();
     506    QString folder = VBoxGlobal::getExistingDirectory (initDir, this);
     507    if (folder.isNull())
    532508        return;
    533509
    534     QString folder = QDir::convertSeparators (aFolder);
     510    folder = QDir::convertSeparators (folder);
    535511    /* remove trailing slash if any */
    536512    folder.remove (QRegExp ("[\\\\/]$"));
     
    540516     *  isModified() return true
    541517     */
    542     if (mLastAccessedField)
    543     {
    544         mLastAccessedField->selectAll();
    545         mLastAccessedField->insert (folder);
    546         mLastAccessedField = 0;
    547     }
     518    le->selectAll();
     519    le->insert (folder);
    548520}
    549521
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxSharedFoldersSettings.ui.h

    r1863 r1889  
    188188                 this, SLOT (validate()));
    189189        connect (tbPath, SIGNAL (clicked()), this, SLOT (showFileDialog()));
    190         connect (&vboxGlobal(), SIGNAL (existingDirectoryResult (const QString&)),
    191                  this, SLOT (folderSelected (const QString&)));
    192190        QWhatsThis::add (mLePath, tr ("Enter existing path for the shared folder here"));
    193191        QWhatsThis::add (mLeName, tr ("Enter name for the shared folder to be created"));
     
    233231    void showFileDialog()
    234232    {
    235         vboxGlobal().getExistingDirectory (QDir::convertSeparators (
    236                                            QDir::rootDirPath()),
    237                                            this, "addSharedFolderDialog",
    238                                            tr ("Select a folder to share"));
    239     }
    240 
    241     void folderSelected (const QString &aFolder)
    242     {
    243         if (aFolder.isNull())
     233        QString folder = vboxGlobal().getExistingDirectory (QDir::rootDirPath(),
     234                                                  this, "addSharedFolderDialog",
     235                                                  tr ("Select a folder to share"));
     236        if (folder.isNull())
    244237            return;
    245238
    246         QString folderName = QDir::convertSeparators (aFolder);
     239        QString folderName = QDir::convertSeparators (folder);
    247240        QRegExp commonRule ("[\\\\/]([^\\\\^/]+)[\\\\/]?$");
    248241        QRegExp rootRule ("(([a-zA-Z])[^\\\\^/])?[\\\\/]$");
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui

    r1863 r1889  
    26982698    <slot>tbResetSavedStateFolder_clicked()</slot>
    26992699    <slot>tbSelectSavedStateFolder_clicked()</slot>
    2700     <slot>folderSelected( const QString &amp; )</slot>
    27012700    <slot>addUSBFilter( const CUSBDeviceFilter &amp; aFilter, bool isNew )</slot>
    27022701    <slot>lvUSBFilters_currentChanged( QListViewItem * item )</slot>
  • trunk/src/VBox/Frontends/VirtualBox/ui/VBoxVMSettingsDlg.ui.h

    r1863 r1889  
    18471847void VBoxVMSettingsDlg::tbSelectSavedStateFolder_clicked()
    18481848{
    1849     QString settingsFolder =
    1850         QFileInfo (cmachine.GetSettingsFilePath()).dirPath (true);
    1851 
    1852     if (!leSnapshotFolder->text().isEmpty())
    1853     {
    1854         /* set the first parent directory that exists as the current */
    1855         const QDir dir (settingsFolder);
    1856         QFileInfo fld (dir, leSnapshotFolder->text());
    1857         do
    1858         {
    1859             QString dp = fld.dirPath (false);
    1860             fld = QFileInfo (dp);
    1861         }
    1862         while (!fld.exists() && !QDir (fld.absFilePath()).isRoot());
    1863 
    1864         if (fld.exists())
    1865             settingsFolder = fld.absFilePath();
    1866     }
    1867 
    1868     vboxGlobal().getExistingDirectory (settingsFolder, this);
    1869 }
    1870 
    1871 void VBoxVMSettingsDlg::folderSelected (const QString &aFolder)
    1872 {
    1873     if (aFolder.isNull())
     1849    QString settingsFolder = VBoxGlobal::getStartingDir (leSnapshotFolder->text());
     1850    if (settingsFolder.isNull())
     1851        settingsFolder = QFileInfo (cmachine.GetSettingsFilePath()).dirPath (true);
     1852
     1853    QString folder = vboxGlobal().getExistingDirectory (settingsFolder, this);
     1854    if (folder.isNull())
    18741855        return;
    18751856
    1876     QString folder = QDir::convertSeparators (aFolder);
     1857    folder = QDir::convertSeparators (folder);
    18771858    /* remove trailing slash if any */
    18781859    folder.remove (QRegExp ("[\\\\/]$"));
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