Index: /trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIFileDialog.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIFileDialog.cpp	(revision 45376)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/extensions/QIFileDialog.cpp	(revision 45377)
@@ -20,4 +20,6 @@
 /* VBox includes */
 #include "VBoxGlobal.h"
+#include "UIModalWindowManager.h"
+#include "UIMessageCenter.h"
 #include "QIFileDialog.h"
 
@@ -265,5 +267,5 @@
             QString result;
 
-            QWidget *topParent = mParent ? mParent->window() : vboxGlobal().mainWindow();
+            QWidget *topParent = mwManager().realParentWindow(mParent ? mParent : msgCenter().mainWindowShown());
             QString title = mCaption.isNull() ? tr ("Select a directory") : mCaption;
 
@@ -466,5 +468,5 @@
             QString title = mCaption.isNull() ? tr ("Select a file") : mCaption;
 
-            QWidget *topParent = mParent ? mParent->window() : vboxGlobal().mainWindow();
+            QWidget *topParent = mwManager().realParentWindow(mParent ? mParent : msgCenter().mainWindowShown());
             QString winFilters = winFilter (mFilters);
             AssertCompile (sizeof (TCHAR) == sizeof (QChar));
@@ -715,5 +717,5 @@
             QString title = mCaption.isNull() ? tr ("Select a file") : mCaption;
 
-            QWidget *topParent = mParent ? mParent->window() : vboxGlobal().mainWindow();
+            QWidget *topParent = mwManager().realParentWindow(mParent ? mParent : msgCenter().mainWindowShown());
             QString winFilters = winFilter (mFilters);
             AssertCompile (sizeof (TCHAR) == sizeof (QChar));
Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp	(revision 45376)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/UIMessageCenter.cpp	(revision 45377)
@@ -325,7 +325,7 @@
     if (vboxGlobal().isVMConsoleProcess())
     {
-        /* It will be currently active machine window if visible: */
-        if (vboxGlobal().vmWindow()->isVisible())
-            return vboxGlobal().vmWindow();
+        /* It will be currently active machine-window if visible: */
+        if (vboxGlobal().activeMachineWindow()->isVisible())
+            return vboxGlobal().activeMachineWindow();
     }
     /* Otherwise: */
Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp	(revision 45376)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.cpp	(revision 45377)
@@ -270,5 +270,4 @@
     , mSelectorWnd (NULL)
     , m_pVirtualMachine(0)
-    , mMainWindow (NULL)
     , mMediaEnumThread (NULL)
     , mIsKWinManaged (false)
@@ -457,11 +456,11 @@
 }
 
-QWidget* VBoxGlobal::vmWindow()
+QWidget* VBoxGlobal::activeMachineWindow()
 {
     /* Null if that is NOT console-process or machine not yet created: */
     if (!isVMConsoleProcess() || !m_pVirtualMachine)
         return 0;
-    /* Main machine-window otherwise: */
-    return m_pVirtualMachine->mainWindow();
+    /* Active machine-window otherwise: */
+    return m_pVirtualMachine->activeWindow();
 }
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h	(revision 45376)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/globals/VBoxGlobal.h	(revision 45377)
@@ -90,9 +90,5 @@
     bool startMachine(const QString &strMachineId);
     UIMachine* virtualMachine();
-    QWidget* vmWindow();
-
-    /* Main application window storage: */
-    void setMainWindow(QWidget *pMainWindow) { mMainWindow = pMainWindow; }
-    QWidget* mainWindow() const { return mMainWindow; }
+    QWidget* activeMachineWindow();
 
     bool is3DAvailable() const { return m3DAvailable; }
@@ -451,5 +447,4 @@
     UISelectorWindow *mSelectorWnd;
     UIMachine *m_pVirtualMachine;
-    QWidget* mMainWindow;
 
     QString vmUuid;
Index: /trunk/src/VBox/Frontends/VirtualBox/src/main.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/main.cpp	(revision 45376)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/main.cpp	(revision 45377)
@@ -483,9 +483,6 @@
             if (vboxGlobal().isVMConsoleProcess())
             {
-                if (vboxGlobal().startMachine (vboxGlobal().managedVMUuid()))
-                {
-                    vboxGlobal().setMainWindow (vboxGlobal().vmWindow());
+                if (vboxGlobal().startMachine(vboxGlobal().managedVMUuid()))
                     rc = a.exec();
-                }
             }
             else if (noSelector)
@@ -497,5 +494,5 @@
 #ifdef VBOX_BLEEDING_EDGE
                 msgCenter().showBEBWarning();
-#else
+#else /* VBOX_BLEEDING_EDGE */
 # ifndef DEBUG
                 /* Check for BETA version */
@@ -509,10 +506,8 @@
                         msgCenter().showBETAWarning();
                 }
-# endif
-#endif
-
-                vboxGlobal().setMainWindow (&vboxGlobal().selectorWnd());
-                    vboxGlobal().selectorWnd().show();
-                    rc = a.exec();
+# endif /* !DEBUG */
+#endif /* !VBOX_BLEEDING_EDGE*/
+                vboxGlobal().selectorWnd().show();
+                rc = a.exec();
             }
         }
Index: /trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp	(revision 45376)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/medium/UIMediumManager.cpp	(revision 45377)
@@ -218,4 +218,8 @@
     /* Apply UI decorations */
     Ui::UIMediumManager::setupUi (this);
+
+    /* No need to count that window as important for application,
+     * it will NOT be taken into account when other top-level windows will be closed: */
+    setAttribute(Qt::WA_QuitOnClose, false);
 
     /* Apply window icons */
@@ -562,8 +566,4 @@
         mModelessDialog->setup (UIMediumType_All, false /* aDoSelect */, aRefresh);
 
-        /* Setup 'closing' connection if main window is UISelectorWindow: */
-        if (vboxGlobal().mainWindow() && vboxGlobal().mainWindow()->inherits("UISelectorWindow"))
-            connect(vboxGlobal().mainWindow(), SIGNAL(closing()), mModelessDialog, SLOT(close()));
-
         /* listen to events that may change the media status and refresh
          * the contents of the modeless dialog */
Index: /trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManagerDialog.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManagerDialog.cpp	(revision 45376)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/net/UINetworkManagerDialog.cpp	(revision 45377)
@@ -168,5 +168,5 @@
 
     /* Center according current main application window: */
-    vboxGlobal().centerWidget(this, vboxGlobal().mainWindow(), false);
+    vboxGlobal().centerWidget(this, msgCenter().mainWindowShown(), false);
 
     /* Pass event to the base-class: */
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp	(revision 45376)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp	(revision 45377)
@@ -415,11 +415,11 @@
 }
 
-QWidget* UIMachine::mainWindow() const
+QWidget* UIMachine::activeWindow() const
 {
     /* Null if machine-logic not yet created: */
     if (!machineLogic())
         return 0;
-    /* Main machine-window otherwise: */
-    return machineLogic()->mainMachineWindow();
+    /* Active machine-window otherwise: */
+    return machineLogic()->activeMachineWindow();
 }
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h	(revision 45376)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h	(revision 45377)
@@ -47,5 +47,5 @@
 
     /* Public getters: */
-    QWidget* mainWindow() const;
+    QWidget* activeWindow() const;
     UISession *uisession() const { return m_pSession; }
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp	(revision 45376)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp	(revision 45377)
@@ -182,8 +182,4 @@
     setWindowIcon(vboxGlobal().vmGuestOSTypeIcon(machine().GetOSTypeId()));
 #endif /* !Q_WS_MAC */
-
-    /* Set the main application window for VBoxGlobal: */
-    if (m_uScreenId == 0)
-        vboxGlobal().setMainWindow(this);
 }
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp	(revision 45376)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.cpp	(revision 45377)
@@ -1026,11 +1026,4 @@
 }
 
-void UISelectorWindow::closeEvent(QCloseEvent *pEvent)
-{
-    // TODO: Such things are obsolete, rework required!
-    emit closing();
-    QMainWindow::closeEvent(pEvent);
-}
-
 #ifdef Q_WS_MAC
 bool UISelectorWindow::eventFilter(QObject *pObject, QEvent *pEvent)
Index: /trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.h	(revision 45376)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/selector/UISelectorWindow.h	(revision 45377)
@@ -46,9 +46,4 @@
 {
     Q_OBJECT;
-
-signals:
-
-    /* Obsolete: Signal to notify listeners about this dialog closed: */
-    void closing();
 
 public:
@@ -117,5 +112,4 @@
     void showEvent(QShowEvent *pEvent);
     void polishEvent(QShowEvent *pEvent);
-    void closeEvent(QCloseEvent *pEvent);
 #ifdef Q_WS_MAC
     bool eventFilter(QObject *pObject, QEvent *pEvent);
