Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp	(revision 47994)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp	(revision 47995)
@@ -266,5 +266,5 @@
     , mSelectorWnd (NULL)
     , m_pVirtualMachine(0)
-    , mMediaEnumThread (NULL)
+    , m_pMediumEnumerationThread(0)
     , mIsKWinManaged (false)
 #if defined(DEBUG_bird)
@@ -957,19 +957,4 @@
 }
 
-/**
- * Searches for the given hard disk in the list of known media descriptors and
- * calls UIMedium::details() on the found descriptor.
- *
- * If the requested hard disk is not found (for example, it's a new hard disk
- * for a new VM created outside our UI), then media enumeration is requested and
- * the search is repeated. We assume that the second attempt always succeeds and
- * assert otherwise.
- *
- * @note Technically, the second attempt may fail if, for example, the new hard
- *       passed to this method disk gets removed before #startEnumeratingMedia()
- *       succeeds. This (unexpected object uninitialization) is a generic
- *       problem though and needs to be addressed using exceptions (see also the
- *       @todo in UIMedium::details()).
- */
 QString VBoxGlobal::details (const CMedium &aMedium, bool aPredictDiff, bool fUseHtml /* = true */)
 {
@@ -980,5 +965,5 @@
     {
         /* Medium may be new and not already in the media list, request refresh */
-        startEnumeratingMedia(true /*fReallyNecessary*/);
+        startEnumeratingMedia();
         if (!findMedium (cmedium, medium))
             /* Medium might be deleted already, return null string */
@@ -1660,125 +1645,84 @@
 }
 
-/**
- * Appends the NULL medium to the media list.
- * For using with VBoxGlobal::startEnumeratingMedia() only.
- */
-static void addNullMediumToList (VBoxMediaList &aList, VBoxMediaList::iterator aWhere)
-{
+static void addNullMediumToList(VBoxMediaList &mediums, VBoxMediaList::iterator where)
+{
+   /* Append the NULL medium to the medium list: */
     UIMedium medium;
-    aList.insert (aWhere, medium);
-}
-
-/**
- * Appends the given list of mediums to the media list.
- * For using with VBoxGlobal::startEnumeratingMedia() only.
- */
-static void addMediumsToList (const CMediumVector &aVector,
-                              VBoxMediaList &aList,
-                              VBoxMediaList::iterator aWhere,
-                              UIMediumType aType,
-                              UIMedium *aParent = 0)
-{
-    VBoxMediaList::iterator first = aWhere;
-
-    for (CMediumVector::ConstIterator it = aVector.begin(); it != aVector.end(); ++ it)
-    {
-        CMedium cmedium (*it);
-        UIMedium medium (cmedium, aType, aParent);
-
-        /* Search for a proper alphabetic position */
+    mediums.insert(where, medium);
+}
+
+static void addMediumsToList(const CMediumVector &inputMediums,
+                             VBoxMediaList &outputMediums,
+                             VBoxMediaList::iterator where,
+                             UIMediumType mediumType,
+                             UIMedium *pParent = 0)
+{
+    /* Appends the given list of input-mediums to the output-mediums: */
+    VBoxMediaList::iterator first = where;
+
+    for (CMediumVector::ConstIterator it = inputMediums.begin(); it != inputMediums.end(); ++it)
+    {
+        CMedium cmedium(*it);
+        UIMedium medium(cmedium, mediumType, pParent);
+
+        /* Search for a proper alphabetic position: */
         VBoxMediaList::iterator jt = first;
-        for (; jt != aWhere; ++ jt)
-            if ((*jt).name().localeAwareCompare (medium.name()) > 0)
+        for (; jt != where; ++ jt)
+            if ((*jt).name().localeAwareCompare(medium.name()) > 0)
                 break;
 
-        aList.insert (jt, medium);
-
-        /* Adjust the first item if inserted before it */
+        outputMediums.insert(jt, medium);
+
+        /* Adjust the first item if inserted before it: */
         if (jt == first)
-            -- first;
-    }
-}
-
-/**
- * Appends the given list of hard disks and all their children to the media list.
- * For using with VBoxGlobal::startEnumeratingMedia() only.
- */
-static void addHardDisksToList (const CMediumVector &aVector,
-                                VBoxMediaList &aList,
-                                VBoxMediaList::iterator aWhere,
-                                UIMedium *aParent = 0)
-{
-    VBoxMediaList::iterator first = aWhere;
+            --first;
+    }
+}
+
+static void addHardDisksToList(const CMediumVector &inputMediums,
+                               VBoxMediaList &outputMediums,
+                               VBoxMediaList::iterator where,
+                               UIMedium *pParent = 0)
+{
+    /* Appends the given list of input-hard-disks and all their children to the output-mediums: */
+    VBoxMediaList::iterator first = where;
 
     /* First pass: Add siblings sorted */
-    for (CMediumVector::ConstIterator it = aVector.begin(); it != aVector.end(); ++ it)
-    {
-        CMedium cmedium (*it);
-        UIMedium medium (cmedium, UIMediumType_HardDisk, aParent);
-
-        /* Search for a proper alphabetic position */
+    for (CMediumVector::ConstIterator it = inputMediums.begin(); it != inputMediums.end(); ++it)
+    {
+        CMedium cmedium(*it);
+        UIMedium medium(cmedium, UIMediumType_HardDisk, pParent);
+
+        /* Search for a proper alphabetic position: */
         VBoxMediaList::iterator jt = first;
-        for (; jt != aWhere; ++ jt)
-            if ((*jt).name().localeAwareCompare (medium.name()) > 0)
+        for (; jt != where; ++ jt)
+            if ((*jt).name().localeAwareCompare(medium.name()) > 0)
                 break;
 
-        aList.insert (jt, medium);
-
-        /* Adjust the first item if inserted before it */
+        outputMediums.insert(jt, medium);
+
+        /* Adjust the first item if inserted before it: */
         if (jt == first)
-            -- first;
-    }
-
-    /* Second pass: Add children */
-    for (VBoxMediaList::iterator it = first; it != aWhere;)
+            --first;
+    }
+
+    /* Second pass: Add children: */
+    for (VBoxMediaList::iterator it = first; it != where;)
     {
         CMediumVector children = (*it).medium().GetChildren();
         UIMedium *parent = &(*it);
 
-        ++ it; /* go to the next sibling before inserting children */
-        addHardDisksToList (children, aList, it, parent);
-    }
-}
-
-/**
- * Starts a thread that asynchronously enumerates all currently registered
- * media.
- *
- * Before the enumeration is started, the current media list (a list returned by
- * #currentMediaList()) is populated with all registered media and the
- * #mediumEnumStarted() signal is emitted. The enumeration thread then walks this
- * list, checks for media accessibility and emits #mediumEnumerated() signals of
- * each checked medium. When all media are checked, the enumeration thread is
- * stopped and the #mediumEnumFinished() signal is emitted.
- *
- * If the enumeration is already in progress, no new thread is started.
- *
- * The media list returned by #currentMediaList() is always sorted
- * alphabetically by the location attribute and comes in the following order:
- * <ol>
- *  <li>All hard disks. If a hard disk has children, these children
- *      (alphabetically sorted) immediately follow their parent and therefore
- *      appear before its next sibling hard disk.</li>
- *  <li>All CD/DVD images.</li>
- *  <li>All Floppy images.</li>
- * </ol>
- *
- * Note that #mediumEnumerated() signals are emitted in the same order as
- * described above.
- *
- * @param   fReallyNecessary    Whether the caller actually needs the media info
- *                              now, or is just trying to be nice and start the
- *                              IPC storm... er... caching process early.
- *
- * @sa #currentMediaList()
- * @sa #isMediaEnumerationStarted()
- */
-void VBoxGlobal::startEnumeratingMedia(bool fReallyNecessary)
-{
-    AssertReturnVoid (mValid);
-
-    /* check if already started but not yet finished */
-    if (mMediaEnumThread != NULL)
+        ++it; /* go to the next sibling before inserting children */
+        addHardDisksToList(children, outputMediums, it, parent);
+    }
+}
+
+void VBoxGlobal::startEnumeratingMedia(bool fForceStart /*= true*/)
+{
+    /* Make sure VBoxGlobal is already valid: */
+    AssertReturnVoid(mValid);
+
+    /* Make sure enumeration is not already started: */
+    if (m_pMediumEnumerationThread)
         return;
 
@@ -1793,15 +1737,15 @@
 
     /* Developer doesn't want any unnecessary media caching! */
-    if (!fReallyNecessary && !agressiveCaching())
+    if (!fForceStart && !agressiveCaching())
         return;
 
     /* composes a list of all currently known media & their children */
-    mMediaList.clear();
-    addNullMediumToList (mMediaList, mMediaList.end());
-    addHardDisksToList (mVBox.GetHardDisks(), mMediaList, mMediaList.end());
-    addMediumsToList (mHost.GetDVDDrives(), mMediaList, mMediaList.end(), UIMediumType_DVD);
-    addMediumsToList (mVBox.GetDVDImages(), mMediaList, mMediaList.end(), UIMediumType_DVD);
-    addMediumsToList (mHost.GetFloppyDrives(), mMediaList, mMediaList.end(), UIMediumType_Floppy);
-    addMediumsToList (mVBox.GetFloppyImages(), mMediaList, mMediaList.end(), UIMediumType_Floppy);
+    m_mediums.clear();
+    addNullMediumToList (m_mediums, m_mediums.end());
+    addHardDisksToList (mVBox.GetHardDisks(), m_mediums, m_mediums.end());
+    addMediumsToList (mHost.GetDVDDrives(), m_mediums, m_mediums.end(), UIMediumType_DVD);
+    addMediumsToList (mVBox.GetDVDImages(), m_mediums, m_mediums.end(), UIMediumType_DVD);
+    addMediumsToList (mHost.GetFloppyDrives(), m_mediums, m_mediums.end(), UIMediumType_Floppy);
+    addMediumsToList (mVBox.GetFloppyImages(), m_mediums, m_mediums.end(), UIMediumType_Floppy);
 
     /* enumeration thread class */
@@ -1852,12 +1796,12 @@
     };
 
-    mMediaEnumThread = new MediaEnumThread (mMediaList);
-    AssertReturnVoid (mMediaEnumThread);
-
-    /* emit mediumEnumStarted() after we set mMediaEnumThread to != NULL
-     * to cause isMediaEnumerationStarted() to return TRUE from slots */
+    m_pMediumEnumerationThread = new MediaEnumThread(m_mediums);
+    AssertReturnVoid(m_pMediumEnumerationThread);
+
+    /* Emit mediumEnumStarted() after we set m_pMediumEnumerationThread to != NULL
+     * to cause isMediaEnumerationStarted() to return TRUE from slots: */
     emit mediumEnumStarted();
 
-    mMediaEnumThread->start();
+    m_pMediumEnumerationThread->start();
 }
 
@@ -1902,13 +1846,11 @@
 void VBoxGlobal::addMedium (const UIMedium &aMedium)
 {
-    /* Note that we maintain the same order here as #startEnumeratingMedia() */
-
-    VBoxMediaList::iterator it = mMediaList.begin();
+    VBoxMediaList::iterator it = m_mediums.begin();
 
     if (aMedium.type() == UIMediumType_HardDisk)
     {
-        VBoxMediaList::iterator itParent = mMediaList.end();
-
-        for (; it != mMediaList.end(); ++ it)
+        VBoxMediaList::iterator itParent = m_mediums.end();
+
+        for (; it != m_mediums.end(); ++ it)
         {
             /* skip null medium that come first */
@@ -1918,5 +1860,5 @@
                 break;
 
-            if (aMedium.parent() != NULL && itParent == mMediaList.end())
+            if (aMedium.parent() != NULL && itParent == m_mediums.end())
             {
                 if (&*it == aMedium.parent())
@@ -1937,9 +1879,9 @@
         }
 
-        AssertReturnVoid (aMedium.parent() == NULL || itParent != mMediaList.end());
+        AssertReturnVoid (aMedium.parent() == NULL || itParent != m_mediums.end());
     }
     else
     {
-        for (; it != mMediaList.end(); ++ it)
+        for (; it != m_mediums.end(); ++ it)
         {
             /* skip null medium that come first */
@@ -1962,5 +1904,5 @@
     }
 
-    it = mMediaList.insert (it, aMedium);
+    it = m_mediums.insert (it, aMedium);
 
     emit mediumAdded (*it);
@@ -1976,9 +1918,9 @@
 {
     VBoxMediaList::Iterator it;
-    for (it = mMediaList.begin(); it != mMediaList.end(); ++ it)
+    for (it = m_mediums.begin(); it != m_mediums.end(); ++ it)
         if ((*it).id() == aMedium.id())
             break;
 
-    AssertReturnVoid (it != mMediaList.end());
+    AssertReturnVoid (it != m_mediums.end());
 
     if (&*it != &aMedium)
@@ -1997,9 +1939,9 @@
 {
     VBoxMediaList::Iterator it;
-    for (it = mMediaList.begin(); it != mMediaList.end(); ++ it)
+    for (it = m_mediums.begin(); it != m_mediums.end(); ++ it)
         if ((*it).id() == aId)
             break;
 
-    AssertReturnVoid (it != mMediaList.end());
+    AssertReturnVoid (it != m_mediums.end());
 
 #if DEBUG
@@ -2008,5 +1950,5 @@
         VBoxMediaList::Iterator jt = it;
         ++ jt;
-        AssertReturnVoid (jt == mMediaList.end() || (*jt).parent() != &*it);
+        AssertReturnVoid (jt == m_mediums.end() || (*jt).parent() != &*it);
     }
 #endif
@@ -2016,5 +1958,5 @@
     /* remove the medium from the list to keep it in sync with the server "for
      * free" when the medium is deleted from one of our UIs */
-    mMediaList.erase (it);
+    m_mediums.erase (it);
 
     emit mediumRemoved (aType, aId);
@@ -2036,5 +1978,5 @@
 bool VBoxGlobal::findMedium (const CMedium &aObj, UIMedium &aMedium) const
 {
-    for (VBoxMediaList::ConstIterator it = mMediaList.begin(); it != mMediaList.end(); ++ it)
+    for (VBoxMediaList::ConstIterator it = m_mediums.begin(); it != m_mediums.end(); ++ it)
     {
         if (((*it).medium().isNull() && aObj.isNull()) ||
@@ -2055,5 +1997,5 @@
 UIMedium VBoxGlobal::findMedium (const QString &aMediumId) const
 {
-    for (VBoxMediaList::ConstIterator it = mMediaList.begin(); it != mMediaList.end(); ++ it)
+    for (VBoxMediaList::ConstIterator it = m_mediums.begin(); it != m_mediums.end(); ++ it)
         if ((*it).id() == aMediumId)
             return *it;
@@ -2273,6 +2215,6 @@
 
     /* refresh media properties since they contain some translations too  */
-    for (VBoxMediaList::iterator it = mMediaList.begin();
-         it != mMediaList.end(); ++ it)
+    for (VBoxMediaList::iterator it = m_mediums.begin();
+         it != m_mediums.end(); ++ it)
         it->refresh();
 
@@ -4091,5 +4033,5 @@
                     !ev->mMedium.result().isOk())
                     msgCenter().cannotGetMediaAccessibility (ev->mMedium);
-                Assert (ev->mIterator != mMediaList.end());
+                Assert (ev->mIterator != m_mediums.end());
                 *(ev->mIterator) = ev->mMedium;
                 emit mediumEnumerated (*ev->mIterator);
@@ -4098,8 +4040,8 @@
             {
                 /* the thread has posted the last message, wait for termination */
-                mMediaEnumThread->wait();
-                delete mMediaEnumThread;
-                mMediaEnumThread = 0;
-                emit mediumEnumFinished (mMediaList);
+                m_pMediumEnumerationThread->wait();
+                delete m_pMediumEnumerationThread;
+                m_pMediumEnumerationThread = 0;
+                emit mediumEnumFinished (m_mediums);
             }
 
@@ -4627,5 +4569,6 @@
      * but this method should be run anyway just to enumerate null UIMedium object,
      * used by some VBox smart widgets, like VBoxMediaComboBox: */
-    vboxGlobal().startEnumeratingMedia(false /*fReallyNecessary*/);
+    if (agressiveCaching())
+        startEnumeratingMedia();
 
     /* Prepare global settings change handler: */
@@ -4683,9 +4626,9 @@
 
     /* Cleanup medium enumeration thread: */
-    if (mMediaEnumThread)
-    {
-        mMediaEnumThread->wait();
-        delete mMediaEnumThread;
-        mMediaEnumThread = 0;
+    if (m_pMediumEnumerationThread)
+    {
+        m_pMediumEnumerationThread->wait();
+        delete m_pMediumEnumerationThread;
+        m_pMediumEnumerationThread = 0;
     }
 
@@ -4705,5 +4648,5 @@
 
     /* media list contains a lot of CUUnknown, release them */
-    mMediaList.clear();
+    m_mediums.clear();
     /* the last steps to ensure we don't use COM any more */
     mHost.detach();
Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h	(revision 47994)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h	(revision 47995)
@@ -124,5 +124,4 @@
     const QRect availableGeometry(int iScreen = 0) const;
 
-    bool agressiveCaching() const { return mAgressiveCaching; }
     bool shouldRestoreCurrentSnapshot() const { return mRestoreCurrentSnapshot; }
     bool isPatmDisabled() const { return mDisablePatm; }
@@ -241,21 +240,11 @@
     CSession openExistingSession(const QString &aId) { return openSession(aId, KLockType_Shared); }
 
-    void startEnumeratingMedia(bool fReallyNecessary);
-
     void reloadProxySettings();
 
-    /**
-     * Returns a list of all currently registered media. This list is used to
-     * globally track the accessibility state of all media on a dedicated thread.
-     *
-     * Note that the media list is initially empty (i.e. before the enumeration
-     * process is started for the first time using #startEnumeratingMedia()).
-     * See #startEnumeratingMedia() for more information about how meida are
-     * sorted in the returned list.
-     */
-    const VBoxMediaList &currentMediaList() const { return mMediaList; }
-
-    /** Returns true if the media enumeration is in progress. */
-    bool isMediaEnumerationStarted() const { return mMediaEnumThread != NULL; }
+    /* API: Medium-enumeration stuff: */
+    void startEnumeratingMedia(bool fForceStart = true);
+    bool agressiveCaching() const { return mAgressiveCaching; }
+    bool isMediaEnumerationStarted() const { return !!m_pMediumEnumerationThread; }
+    const VBoxMediaList &currentMediaList() const { return m_mediums; }
 
     void addMedium (const UIMedium &);
@@ -395,22 +384,8 @@
 signals:
 
-    /**
-     * Emitted at the beginning of the enumeration process started by
-     * #startEnumeratingMedia().
-     */
+    /* Notifiers: Medium-enumeration stuff: */
     void mediumEnumStarted();
-
-    /**
-     * Emitted when a new medium item from the list has updated its
-     * accessibility state.
-     */
-    void mediumEnumerated (const UIMedium &aMedum);
-
-    /**
-     * Emitted at the end of the enumeration process started by
-     * #startEnumeratingMedia(). The @a aList argument is passed for
-     * convenience, it is exactly the same as returned by #currentMediaList().
-     */
-    void mediumEnumFinished (const VBoxMediaList &aList);
+    void mediumEnumerated(const UIMedium &medum);
+    void mediumEnumFinished(const VBoxMediaList &mediums);
 
     /** Emitted when a new media is added using #addMedia(). */
@@ -469,6 +444,6 @@
     bool mShowStartVMErrors;
 
-    QThread *mMediaEnumThread;
-    VBoxMediaList mMediaList;
+    QThread *m_pMediumEnumerationThread;
+    VBoxMediaList m_mediums;
 
     RenderMode vm_render_mode;
Index: /trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp	(revision 47994)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp	(revision 47995)
@@ -511,5 +511,5 @@
 
     if (aRefresh && !vboxGlobal().isMediaEnumerationStarted())
-        vboxGlobal().startEnumeratingMedia(true /*fReallyNecessary*/);
+        vboxGlobal().startEnumeratingMedia();
     else
     {
@@ -616,5 +616,5 @@
 {
     /* Start enumerating media */
-    vboxGlobal().startEnumeratingMedia(true /*fReallyNecessary*/);
+    vboxGlobal().startEnumeratingMedia();
 }
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp	(revision 47994)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp	(revision 47995)
@@ -382,6 +382,6 @@
     qApp->setQuitOnLastWindowClosed(false);
 
-    /* Cache IMedium data: */
-    vboxGlobal().startEnumeratingMedia(false /*fReallyNecessary*/);
+    /* Cache medium data only if really necessary: */
+    vboxGlobal().startEnumeratingMedia(false /* force start */);
 
     /* Load machine settings: */
Index: /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.cpp	(revision 47994)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsStorage.cpp	(revision 47995)
@@ -1735,5 +1735,5 @@
      * lasted point, where we can start. The rest of the media checking is done
      * in a background thread. */
-    vboxGlobal().startEnumeratingMedia(true /*fReallyNecessary*/);
+    vboxGlobal().startEnumeratingMedia();
 
     /* Initialize pixmap pool */
Index: /trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxMediaComboBox.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxMediaComboBox.cpp	(revision 47994)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/widgets/VBoxMediaComboBox.cpp	(revision 47995)
@@ -90,5 +90,5 @@
 {
     if (!vboxGlobal().isMediaEnumerationStarted())
-        vboxGlobal().startEnumeratingMedia(true /*fReallyNecessary*/);
+        vboxGlobal().startEnumeratingMedia();
     else
         refresh();
