Index: trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk	(revision 26656)
+++ trunk/src/VBox/Frontends/VirtualBox/Makefile.kmk	(revision 26691)
@@ -375,4 +375,5 @@
 ifdef VBOX_WITH_NEW_RUNTIME_CORE
 VirtualBox_QT_MOCHDRS += \
+	src/runtime/UISession.h \
 	src/runtime/UIActionsPool.h \
 	src/runtime/UIIndicatorsPool.h \
@@ -496,4 +497,5 @@
 ifdef VBOX_WITH_NEW_RUNTIME_CORE
 VirtualBox_SOURCES += \
+	src/runtime/UISession.cpp \
 	src/runtime/UIActionsPool.cpp \
 	src/runtime/UIIndicatorsPool.cpp \
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIActionsPool.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIActionsPool.cpp	(revision 26656)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIActionsPool.cpp	(revision 26691)
@@ -390,26 +390,4 @@
 };
 
-class PerformResetAction : public UISimpleAction
-{
-    Q_OBJECT;
-
-public:
-
-    PerformResetAction(QObject *pParent)
-        : UISimpleAction(pParent,
-                         ":/reset_16px.png", ":/reset_disabled_16px.png")
-    {
-        retranslateUi();
-    }
-
-protected:
-
-    void retranslateUi()
-    {
-        setText(VBoxGlobal::insertKeyToActionText(tr ("&Reset"), "R"));
-        setStatusTip(tr("Reset the virtual machine"));
-    }
-};
-
 class TogglePauseAction : public UIToggleAction
 {
@@ -442,4 +420,26 @@
 };
 
+class PerformResetAction : public UISimpleAction
+{
+    Q_OBJECT;
+
+public:
+
+    PerformResetAction(QObject *pParent)
+        : UISimpleAction(pParent,
+                         ":/reset_16px.png", ":/reset_disabled_16px.png")
+    {
+        retranslateUi();
+    }
+
+protected:
+
+    void retranslateUi()
+    {
+        setText(VBoxGlobal::insertKeyToActionText(tr ("&Reset"), "R"));
+        setStatusTip(tr("Reset the virtual machine"));
+    }
+};
+
 class PerformShutdownAction : public UISimpleAction
 {
@@ -554,86 +554,4 @@
 };
 
-class MenuNetworkAdaptersAction : public UIMenuAction
-{
-    Q_OBJECT;
-
-public:
-
-    MenuNetworkAdaptersAction(QObject *pParent)
-        : UIMenuAction(pParent)
-    {
-        retranslateUi();
-    }
-
-protected:
-
-    void retranslateUi()
-    {
-    }
-};
-
-class ShowNetworkAdaptersDialogAction : public UISimpleAction
-{
-    Q_OBJECT;
-
-public:
-
-    ShowNetworkAdaptersDialogAction(QObject *pParent)
-        : UISimpleAction(pParent,
-                         ":/nw_16px.png", ":/nw_disabled_16px.png")
-    {
-        retranslateUi();
-    }
-
-protected:
-
-    void retranslateUi()
-    {
-        setText(tr("&Network Adapters..."));
-        setStatusTip(tr("Change the settings of network adapters"));
-    }
-};
-
-class MenuSharedFoldersAction : public UIMenuAction
-{
-    Q_OBJECT;
-
-public:
-
-    MenuSharedFoldersAction(QObject *pParent)
-        : UIMenuAction(pParent)
-    {
-        retranslateUi();
-    }
-
-protected:
-
-    void retranslateUi()
-    {
-    }
-};
-
-class ShowSharedFoldersDialogAction : public UISimpleAction
-{
-    Q_OBJECT;
-
-public:
-
-    ShowSharedFoldersDialogAction(QObject *pParent)
-        : UISimpleAction(pParent,
-                         ":/shared_folder_16px.png", ":/shared_folder_disabled_16px.png")
-    {
-        retranslateUi();
-    }
-
-protected:
-
-    void retranslateUi()
-    {
-        setText(tr("&Shared Folders..."));
-        setStatusTip(tr("Create or modify shared folders"));
-    }
-};
-
 class MenuUSBDevicesAction : public UIMenuAction
 {
@@ -654,4 +572,86 @@
     {
         menu()->setTitle(tr("&USB Devices"));
+    }
+};
+
+class MenuNetworkAdaptersAction : public UIMenuAction
+{
+    Q_OBJECT;
+
+public:
+
+    MenuNetworkAdaptersAction(QObject *pParent)
+        : UIMenuAction(pParent)
+    {
+        retranslateUi();
+    }
+
+protected:
+
+    void retranslateUi()
+    {
+    }
+};
+
+class ShowNetworkAdaptersDialogAction : public UISimpleAction
+{
+    Q_OBJECT;
+
+public:
+
+    ShowNetworkAdaptersDialogAction(QObject *pParent)
+        : UISimpleAction(pParent,
+                         ":/nw_16px.png", ":/nw_disabled_16px.png")
+    {
+        retranslateUi();
+    }
+
+protected:
+
+    void retranslateUi()
+    {
+        setText(tr("&Network Adapters..."));
+        setStatusTip(tr("Change the settings of network adapters"));
+    }
+};
+
+class MenuSharedFoldersAction : public UIMenuAction
+{
+    Q_OBJECT;
+
+public:
+
+    MenuSharedFoldersAction(QObject *pParent)
+        : UIMenuAction(pParent)
+    {
+        retranslateUi();
+    }
+
+protected:
+
+    void retranslateUi()
+    {
+    }
+};
+
+class ShowSharedFoldersDialogAction : public UISimpleAction
+{
+    Q_OBJECT;
+
+public:
+
+    ShowSharedFoldersDialogAction(QObject *pParent)
+        : UISimpleAction(pParent,
+                         ":/shared_folder_16px.png", ":/shared_folder_disabled_16px.png")
+    {
+        retranslateUi();
+    }
+
+protected:
+
+    void retranslateUi()
+    {
+        setText(tr("&Shared Folders..."));
+        setStatusTip(tr("Create or modify shared folders"));
     }
 };
@@ -809,6 +809,6 @@
     m_actionsPool[UIActionIndex_Simple_TakeSnapshot] = new PerformTakeSnapshotAction(this);
     m_actionsPool[UIActionIndex_Simple_InformationDialog] = new ShowInformationDialogAction(this);
+    m_actionsPool[UIActionIndex_Toggle_Pause] = new TogglePauseAction(this);
     m_actionsPool[UIActionIndex_Simple_Reset] = new PerformResetAction(this);
-    m_actionsPool[UIActionIndex_Toggle_Pause] = new TogglePauseAction(this);
     m_actionsPool[UIActionIndex_Simple_Shutdown] = new PerformShutdownAction(this);
     m_actionsPool[UIActionIndex_Simple_Close] = new PerformCloseAction(this);
@@ -818,9 +818,9 @@
     m_actionsPool[UIActionIndex_Menu_OpticalDevices] = new MenuOpticalDevicesAction(this);
     m_actionsPool[UIActionIndex_Menu_FloppyDevices] = new MenuFloppyDevicesAction(this);
+    m_actionsPool[UIActionIndex_Menu_USBDevices] = new MenuUSBDevicesAction(this);
     m_actionsPool[UIActionIndex_Menu_NetworkAdapters] = new MenuNetworkAdaptersAction(this);
     m_actionsPool[UIActionIndex_Simple_NetworkAdaptersDialog] = new ShowNetworkAdaptersDialogAction(this);
     m_actionsPool[UIActionIndex_Menu_SharedFolders] = new MenuSharedFoldersAction(this);
     m_actionsPool[UIActionIndex_Simple_SharedFoldersDialog] = new ShowSharedFoldersDialogAction(this);
-    m_actionsPool[UIActionIndex_Menu_USBDevices] = new MenuUSBDevicesAction(this);
     m_actionsPool[UIActionIndex_Toggle_VRDP] = new ToggleVRDPAction(this);
     m_actionsPool[UIActionIndex_Simple_InstallGuestTools] = new PerformInstallGuestToolsAction(this);
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIActionsPool.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIActionsPool.h	(revision 26656)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIActionsPool.h	(revision 26691)
@@ -72,6 +72,6 @@
     UIActionIndex_Simple_TakeSnapshot,
     UIActionIndex_Simple_InformationDialog,
+    UIActionIndex_Toggle_Pause,
     UIActionIndex_Simple_Reset,
-    UIActionIndex_Toggle_Pause,
     UIActionIndex_Simple_Shutdown,
     UIActionIndex_Simple_Close,
@@ -81,9 +81,9 @@
     UIActionIndex_Menu_OpticalDevices,
     UIActionIndex_Menu_FloppyDevices,
+    UIActionIndex_Menu_USBDevices,
     UIActionIndex_Menu_NetworkAdapters,
     UIActionIndex_Simple_NetworkAdaptersDialog,
     UIActionIndex_Menu_SharedFolders,
     UIActionIndex_Simple_SharedFoldersDialog,
-    UIActionIndex_Menu_USBDevices,
     UIActionIndex_Toggle_VRDP,
     UIActionIndex_Simple_InstallGuestTools,
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp	(revision 26656)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp	(revision 26691)
@@ -24,4 +24,5 @@
 #include "VBoxGlobal.h"
 #include "UIMachine.h"
+#include "UISession.h"
 #include "UIActionsPool.h"
 #include "UIMachineLogic.h"
@@ -33,7 +34,8 @@
 public:
 
+    /* Visual state holder constructor: */
     UIVisualState(QObject *pParent) : QObject(pParent), m_pMachineLogic(0)
     {
-        /* Connect state-change handler */
+        /* Connect state-change handler: */
         connect(this, SIGNAL(sigChangeVisualState(UIVisualStateType)), parent(), SLOT(sltChangeVisualState(UIVisualStateType)));
     }
@@ -45,5 +47,9 @@
 protected:
 
+    /* Protected members: */
     UIMachineLogic *m_pMachineLogic;
+
+    /* Friend classes: */
+    friend class UIMachine;
 };
 
@@ -54,8 +60,9 @@
 public:
 
-    UIVisualStateNormal(QObject *pParent, const CSession &session, UIActionsPool *pActionsPool)
+    /* Normal visual state holder constructor: */
+    UIVisualStateNormal(QObject *pParent, UISession *pSession, UIActionsPool *pActionsPool)
         : UIVisualState(pParent)
     {
-        /* Connect action handlers */
+        /* Connect action handlers: */
         connect(pActionsPool->action(UIActionIndex_Toggle_Fullscreen), SIGNAL(triggered(bool)),
                 this, SLOT(sltGoToFullscreenMode()));
@@ -63,6 +70,6 @@
                 this, SLOT(sltGoToSeamlessMode()));
 
-        /* Create state logic */
-        m_pMachineLogic = UIMachineLogic::create(this, session, pActionsPool, UIVisualStateType_Normal);
+        /* Create state logic: */
+        m_pMachineLogic = UIMachineLogic::create(this, pSession, pActionsPool, UIVisualStateType_Normal);
     }
 
@@ -71,4 +78,5 @@
     void sltGoToFullscreenMode()
     {
+        /* Change visual state to fullscreen: */
         emit sigChangeVisualState(UIVisualStateType_Fullscreen);
     }
@@ -76,4 +84,5 @@
     void sltGoToSeamlessMode()
     {
+        /* Change visual state to seamless: */
         emit sigChangeVisualState(UIVisualStateType_Seamless);
     }
@@ -86,8 +95,9 @@
 public:
 
-    UIVisualStateFullscreen(QObject *pParent, const CSession &session, UIActionsPool *pActionsPool)
+    /* Fullscreen visual state holder constructor: */
+    UIVisualStateFullscreen(QObject *pParent, UISession *pSession, UIActionsPool *pActionsPool)
         : UIVisualState(pParent)
     {
-        /* Connect action handlers */
+        /* Connect action handlers: */
         connect(pActionsPool->action(UIActionIndex_Toggle_Fullscreen), SIGNAL(triggered(bool)),
                 this, SLOT(sltGoToNormalMode()));
@@ -95,6 +105,6 @@
                 this, SLOT(sltGoToSeamlessMode()));
 
-        /* Create state logic */
-        m_pMachineLogic = UIMachineLogic::create(this, session, pActionsPool, UIVisualStateType_Fullscreen);
+        /* Create state logic: */
+        m_pMachineLogic = UIMachineLogic::create(this, pSession, pActionsPool, UIVisualStateType_Fullscreen);
     }
 
@@ -103,4 +113,5 @@
     void sltGoToNormalMode()
     {
+        /* Change visual state to normal: */
         emit sigChangeVisualState(UIVisualStateType_Normal);
     }
@@ -108,4 +119,5 @@
     void sltGoToSeamlessMode()
     {
+        /* Change visual state to seamless: */
         emit sigChangeVisualState(UIVisualStateType_Seamless);
     }
@@ -118,5 +130,6 @@
 public:
 
-    UIVisualStateSeamless(QObject *pParent, const CSession &session, UIActionsPool *pActionsPool)
+    /* Seamless visual state holder constructor: */
+    UIVisualStateSeamless(QObject *pParent, UISession *pSession, UIActionsPool *pActionsPool)
         : UIVisualState(pParent)
     {
@@ -128,5 +141,5 @@
 
         /* Create state logic */
-        m_pMachineLogic = UIMachineLogic::create(this, session, pActionsPool, UIVisualStateType_Seamless);
+        m_pMachineLogic = UIMachineLogic::create(this, pSession, pActionsPool, UIVisualStateType_Seamless);
     }
 
@@ -135,4 +148,5 @@
     void sltGoToFullscreenMode()
     {
+        /* Change visual state to fullscreen: */
         emit sigChangeVisualState(UIVisualStateType_Fullscreen);
     }
@@ -140,4 +154,5 @@
     void sltGoToNormalMode()
     {
+        /* Change visual state to normal: */
         emit sigChangeVisualState(UIVisualStateType_Normal);
     }
@@ -146,5 +161,5 @@
 UIMachine::UIMachine(UIMachine **ppSelf, const CSession &session)
     : QObject(0)
-    , m_session(session)
+    , m_pSession(new UISession(this, session))
     , m_pActionsPool(new UIActionsPool(this))
     , m_pVisualState(0)
@@ -152,7 +167,4 @@
     /* Cache IMedium data: */
     vboxGlobal().startEnumeratingMedia();
-
-    /* Check CSession object */
-    AssertMsg(!m_session.isNull(), ("CSession is not set!\n"));
 
     /* Storing self */
@@ -164,26 +176,34 @@
 }
 
+UIMachineLogic* UIMachine::machineLogic() const
+{
+    return m_pVisualState->m_pMachineLogic;
+}
+
 void UIMachine::sltChangeVisualState(UIVisualStateType visualStateType)
 {
-    /* Delete previous state */
+    /* Delete previous state: */
     delete m_pVisualState;
     m_pVisualState = 0;
 
-    /* Create new state */
+    /* Create new state: */
     switch (visualStateType)
     {
         case UIVisualStateType_Normal:
         {
-            m_pVisualState = new UIVisualStateNormal(this, m_session, m_pActionsPool);
+            /* Create normal visual state: */
+            m_pVisualState = new UIVisualStateNormal(this, m_pSession, m_pActionsPool);
             break;
         }
         case UIVisualStateType_Fullscreen:
         {
-            m_pVisualState = new UIVisualStateFullscreen(this, m_session, m_pActionsPool);
+            /* Create fullscreen visual state: */
+            m_pVisualState = new UIVisualStateFullscreen(this, m_pSession, m_pActionsPool);
             break;
         }
         case UIVisualStateType_Seamless:
         {
-            m_pVisualState = new UIVisualStateSeamless(this, m_session, m_pActionsPool);
+            /* Create seamless visual state: */
+            m_pVisualState = new UIVisualStateSeamless(this, m_pSession, m_pActionsPool);
             break;
         }
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h	(revision 26656)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h	(revision 26691)
@@ -24,11 +24,16 @@
 #define __UIMachine_h__
 
+/* Global includes */
+#include <QObject>
+
 /* Local includes */
-#include "COMDefs.h"
 #include "UIMachineDefs.h"
 
 /* Local forwards */
+class UISession;
 class UIActionsPool;
 class UIVisualState;
+class UIMachineLogic;
+class CSession;
 
 class UIMachine : public QObject
@@ -38,17 +43,27 @@
 public:
 
+    /* Virtual Machine constructor: */
     UIMachine(UIMachine **ppSelf, const CSession &session);
 
 private slots:
 
+    /* Visual state-change handler: */
     void sltChangeVisualState(UIVisualStateType visualStateType);
 
 private:
 
+    /* Move VM to default (normal) state: */
     void enterBaseVisualState();
 
-    CSession m_session;
+    /* Private getters: */
+    UIMachineLogic* machineLogic() const;
+
+    /* Private variables: */
+    UISession *m_pSession;
     UIActionsPool *m_pActionsPool;
     UIVisualState *m_pVisualState;
+
+    /* Friend classes: */
+    friend class UISession;
 };
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp	(revision 26656)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp	(revision 26691)
@@ -41,4 +41,5 @@
 #include "QIHttp.h"
 
+#include "UISession.h"
 #include "UIActionsPool.h"
 #include "UIMachineLogic.h"
@@ -65,12 +66,12 @@
 #endif
 
-struct MountTarget
-{
-    MountTarget() : name(QString("")), port(0), device(0), id(QString()), type(VBoxDefs::MediumType_Invalid) {}
-    MountTarget(const QString &strName, LONG iPort, LONG iDevice)
+struct MediumTarget
+{
+    MediumTarget() : name(QString("")), port(0), device(0), id(QString()), type(VBoxDefs::MediumType_Invalid) {}
+    MediumTarget(const QString &strName, LONG iPort, LONG iDevice)
         : name(strName), port(iPort), device(iDevice), id(QString()), type(VBoxDefs::MediumType_Invalid) {}
-    MountTarget(const QString &strName, LONG iPort, LONG iDevice, const QString &strId)
+    MediumTarget(const QString &strName, LONG iPort, LONG iDevice, const QString &strId)
         : name(strName), port(iPort), device(iDevice), id(strId), type(VBoxDefs::MediumType_Invalid) {}
-    MountTarget(const QString &strName, LONG iPort, LONG iDevice, VBoxDefs::MediumType eType)
+    MediumTarget(const QString &strName, LONG iPort, LONG iDevice, VBoxDefs::MediumType eType)
         : name(strName), port(iPort), device(iDevice), id(QString()), type(eType) {}
     QString name;
@@ -80,5 +81,15 @@
     VBoxDefs::MediumType type;
 };
-Q_DECLARE_METATYPE(MountTarget);
+Q_DECLARE_METATYPE(MediumTarget);
+
+struct USBTarget
+{
+    USBTarget() : attach(false), id(QString()) {}
+    USBTarget(bool bAttach, const QString &strId)
+        : attach(bAttach), id(strId) {}
+    bool attach;
+    QString id;
+};
+Q_DECLARE_METATYPE(USBTarget);
 
 class UINetworkAdaptersDialog : public QIWithRetranslateUI<QDialog>
@@ -331,5 +342,5 @@
 
 UIMachineLogic* UIMachineLogic::create(QObject *pParent,
-                                       const CSession &session,
+                                       UISession *pSession,
                                        UIActionsPool *pActionsPool,
                                        UIVisualStateType visualStateType)
@@ -339,13 +350,13 @@
     {
         case UIVisualStateType_Normal:
-            logic = new UIMachineLogicNormal(pParent, session, pActionsPool);
+            logic = new UIMachineLogicNormal(pParent, pSession, pActionsPool);
             break;
         case UIVisualStateType_Fullscreen:
-            // logic = new UIMachineLogicFullscreen(pParent, session, pActionsPool);
-            logic = new UIMachineLogicNormal(pParent, session, pActionsPool);
+            // logic = new UIMachineLogicFullscreen(pParent, pSession, pActionsPool);
+            logic = new UIMachineLogicNormal(pParent, pSession, pActionsPool);
             break;
         case UIVisualStateType_Seamless:
-            // logic = new UIMachineLogicSeamless(pParent, session, pActionsPool);
-            logic = new UIMachineLogicNormal(pParent, session, pActionsPool);
+            // logic = new UIMachineLogicSeamless(pParent, pSession, pActionsPool);
+            logic = new UIMachineLogicNormal(pParent, pSession, pActionsPool);
             break;
     }
@@ -354,15 +365,20 @@
 
 UIMachineLogic::UIMachineLogic(QObject *pParent,
-                               const CSession &session,
+                               UISession *pSession,
                                UIActionsPool *pActionsPool,
                                UIVisualStateType visualStateType)
+    /* Initialize parent class: */
     : QObject(pParent)
+    /* Initialize protected members: */
     , m_pMachineWindowContainer(0)
-    , m_session(session)
+    /* Initialize private members: */
+    , m_pSession(pSession)
     , m_pActionsPool(pActionsPool)
     , m_machineState(KMachineState_Null)
     , m_visualStateType(visualStateType)
+    /* Action groups: */
     , m_pRunningActions(0)
     , m_pRunningOrPausedActions(0)
+    /* Bool flags: */
     , m_bIsFirstTimeStarted(false)
     , m_bIsOpenViewFinished(false)
@@ -376,28 +392,14 @@
 UIMachineLogic::~UIMachineLogic()
 {
-#ifdef VBOX_WITH_DEBUGGER_GUI
+#ifdef VBOX_WITH_DEBUGGER_GUI // TODO: Should we close debugger now?
     /* Close debugger: */
-    // TODO: Check that logic!
     //dbgDestroy();
 #endif
 }
 
-void UIMachineLogic::updateAppearanceOf(int iElement)
-{
-    /* Update logic: */
-    CMachine machine = session().GetMachine();
-
-    bool isRunningOrPaused = machineState() == KMachineState_Running ||
-                             machineState() == KMachineState_Paused ||
-                             machineState() == KMachineState_Teleporting ||
-                             machineState() == KMachineState_LiveSnapshotting;
-
-    if (iElement & UIVisualElement_PauseStuff)
-    {
-        actionsPool()->action(UIActionIndex_Toggle_Pause)->setEnabled(isRunningOrPaused);
-    }
-
-    /* Update window: */
-    machineWindowWrapper()->updateAppearanceOf(iElement);
+void UIMachineLogic::prepareConsoleConnections()
+{
+    connect(uisession(), SIGNAL(sigStateChange(KMachineState)), this, SLOT(sltMachineStateChanged(KMachineState)));
+    connect(uisession(), SIGNAL(sigAdditionsStateChange()), this, SLOT(sltAdditionsStateChanged()));
 }
 
@@ -416,5 +418,37 @@
     m_pRunningOrPausedActions->setExclusive(false);
 
-    // TODO: Move actions into approprivate action groups!
+    /* Move actions into first group: */
+    m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Toggle_Fullscreen));
+    m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Toggle_Seamless));
+    m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Simple_AdjustWindow));
+    m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Simple_TypeCAD));
+#ifdef Q_WS_X11
+    m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Simple_TypeCABS));
+#endif
+    m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Simple_Reset));
+    m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Simple_Shutdown));
+#ifdef VBOX_WITH_DEBUGGER_GUI
+    m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Simple_Statistics));
+    m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Simple_CommandLine));
+    m_pRunningActions->addAction(actionsPool()->action(UIActionIndex_Toggle_Logging));
+#endif
+
+    /* Move actions into second group: */
+    m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize));
+    m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Menu_MouseIntegration));
+    m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Toggle_MouseIntegration));
+    m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Simple_TakeSnapshot));
+    m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Simple_InformationDialog));
+    m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Toggle_Pause));
+    m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Simple_Close));
+    m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Menu_OpticalDevices));
+    m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Menu_FloppyDevices));
+    m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Menu_USBDevices));
+    m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Menu_NetworkAdapters));
+    m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Simple_NetworkAdaptersDialog));
+    m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Menu_SharedFolders));
+    m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Simple_SharedFoldersDialog));
+    m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Toggle_VRDP));
+    m_pRunningOrPausedActions->addAction(actionsPool()->action(UIActionIndex_Simple_InstallGuestTools));
 }
 
@@ -422,4 +456,6 @@
 {
     /* "Machine" actions connections */
+    connect(actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize), SIGNAL(toggled(bool)),
+            this, SLOT(sltToggleGuestAutoresize(bool)));
     connect(actionsPool()->action(UIActionIndex_Simple_AdjustWindow), SIGNAL(triggered()),
             this, SLOT(sltAdjustWindow()));
@@ -436,8 +472,8 @@
     connect(actionsPool()->action(UIActionIndex_Simple_InformationDialog), SIGNAL(triggered()),
             this, SLOT(sltShowInformationDialog()));
+    connect(actionsPool()->action(UIActionIndex_Toggle_Pause), SIGNAL(toggled(bool)),
+            this, SLOT(sltPause(bool)));
     connect(actionsPool()->action(UIActionIndex_Simple_Reset), SIGNAL(triggered()),
             this, SLOT(sltReset()));
-    connect(actionsPool()->action(UIActionIndex_Toggle_Pause), SIGNAL(toggled(bool)),
-            this, SLOT(sltPause(bool)));
     connect(actionsPool()->action(UIActionIndex_Simple_Shutdown), SIGNAL(triggered()),
             this, SLOT(sltACPIShutdown()));
@@ -450,10 +486,10 @@
     connect(actionsPool()->action(UIActionIndex_Menu_FloppyDevices)->menu(), SIGNAL(aboutToShow()),
             this, SLOT(sltPrepareStorageMenu()));
+    connect(actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu(), SIGNAL(aboutToShow()),
+            this, SLOT(sltPrepareUSBMenu()));
     connect(actionsPool()->action(UIActionIndex_Simple_NetworkAdaptersDialog), SIGNAL(triggered()),
             this, SLOT(sltOpenNetworkAdaptersDialog()));
     connect(actionsPool()->action(UIActionIndex_Simple_SharedFoldersDialog), SIGNAL(triggered()),
             this, SLOT(sltOpenSharedFoldersDialog()));
-    connect(actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu(), SIGNAL(aboutToShow()),
-            this, SLOT(sltPrepareUSBMenu()));
     connect(actionsPool()->action(UIActionIndex_Toggle_VRDP), SIGNAL(toggled(bool)),
             this, SLOT(sltSwitchVrdp(bool)));
@@ -476,4 +512,5 @@
 void UIMachineLogic::prepareRequiredFeatures()
 {
+    /* Get current console: */
     CConsole console = session().GetConsole();
 
@@ -485,22 +522,19 @@
     if (fRecommendVirtEx && !bIsVirtEnabled)
     {
-        bool ret;
-
-        // TODO: Check that logic!
-        //sltPause(true);
+        bool result;
+
+        pause();
 
         bool fVTxAMDVSupported = vboxGlobal().virtualBox().GetHost().GetProcessorFeature(KProcessorFeature_HWVirtEx);
 
         if (bIs64BitsGuest)
-            ret = vboxProblem().warnAboutVirtNotEnabled64BitsGuest(fVTxAMDVSupported);
+            result = vboxProblem().warnAboutVirtNotEnabled64BitsGuest(fVTxAMDVSupported);
         else
-            ret = vboxProblem().warnAboutVirtNotEnabledGuestRequired(fVTxAMDVSupported);
-
-        // TODO: Close application!
-        //if (ret == true)
-        //    machineWindowWrapper()->machineWindow()->close();
-        // TODO: Check that logic!
-        //else
-        //    sltPause(false);
+            result = vboxProblem().warnAboutVirtNotEnabledGuestRequired(fVTxAMDVSupported);
+
+        if (result == true)
+            sltClose();
+        else
+            unpause();
     }
 
@@ -514,7 +548,8 @@
 void UIMachineLogic::loadLogicSettings()
 {
+    /* Get current machine: */
     CMachine machine = session().GetMachine();
 
-    /* Extra-data settings */
+    /* Extra-data settings: */
     {
         QString strSettings;
@@ -533,5 +568,5 @@
     }
 
-    /* Initial settings */
+    /* Initial settings: */
     {
         /* Initialize storage stuff: */
@@ -552,5 +587,5 @@
     }
 
-    /* Availability settings */
+    /* Availability settings: */
     {
         /* USB Stuff: */
@@ -558,11 +593,11 @@
         if (usbController.isNull())
         {
-            /* Hide USB_Menu: */
-            actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu()->setVisible(false);
+            /* Hide USB menu if controller is NULL: */
+            actionsPool()->action(UIActionIndex_Menu_USBDevices)->setVisible(false);
         }
         else
         {
-            /* Enable/Disable USB_Menu: */
-            actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu()->setEnabled(usbController.GetEnabled());
+            /* Enable/Disable USB menu depending on USB controller: */
+            actionsPool()->action(UIActionIndex_Menu_USBDevices)->setEnabled(usbController.GetEnabled());
         }
 
@@ -579,7 +614,8 @@
 void UIMachineLogic::saveLogicSettings()
 {
+    /* Get current machine: */
     CMachine machine = session().GetMachine();
 
-    /* Extra-data settings */
+    /* Extra-data settings: */
     {
         machine.SetExtraData(VBoxDefs::GUI_AutoresizeGuest,
@@ -591,4 +627,182 @@
         //machine.SetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide, mMiniToolBar->isAutoHide() ? "on" : "off");
     }
+}
+
+CSession& UIMachineLogic::session()
+{
+    return m_pSession->session();
+}
+
+void UIMachineLogic::sltMachineStateChanged(KMachineState newMachineState)
+{
+    if (m_machineState != newMachineState)
+    {
+        /* Variable flags: */
+        bool bIsRunning = newMachineState == KMachineState_Running ||
+                          newMachineState == KMachineState_Teleporting ||
+                          newMachineState == KMachineState_LiveSnapshotting;
+        bool bIsRunningOrPaused = bIsRunning ||
+                                  newMachineState == KMachineState_Paused;
+
+        /* Update action groups: */
+        m_pRunningActions->setEnabled(bIsRunning);
+        m_pRunningOrPausedActions->setEnabled(bIsRunningOrPaused);
+
+        /* Do we have GURU? */
+        bool bIsGuruMeditation = false;
+
+        switch (newMachineState)
+        {
+            case KMachineState_Stuck:
+            {
+                bIsGuruMeditation = true;
+                break;
+            }
+            case KMachineState_Paused:
+            {
+                /* Was paused from CMachine side? */
+                QAction *pPauseAction = actionsPool()->action(UIActionIndex_Toggle_Pause);
+                if (!pPauseAction->isChecked())
+                {
+                    pPauseAction->blockSignals(true);
+                    pPauseAction->setChecked(true);
+                    pPauseAction->blockSignals(false);
+                }
+                break;
+            }
+            case KMachineState_Running:
+            case KMachineState_Teleporting:
+            case KMachineState_LiveSnapshotting:
+            {
+                /* Was started from CMachine side? */
+                QAction *pPauseAction = actionsPool()->action(UIActionIndex_Toggle_Pause);
+                if (isPaused() && pPauseAction->isChecked())
+                {
+                    pPauseAction->blockSignals(true);
+                    pPauseAction->setChecked(false);
+                    pPauseAction->blockSignals(false);
+                }
+                break;
+            }
+#ifdef Q_WS_X11
+            case KMachineState_Starting:
+            case KMachineState_Restoring:
+            case KMachineState_TeleportingIn:
+            {
+                /* The keyboard handler may wish to do some release logging on startup.
+                 * Tell it that the logger is now active. */
+                doXKeyboardLogging(QX11Info::display());
+                break;
+            }
+#endif
+            default:
+                break;
+        }
+
+        /* Now storing new state: */
+        m_machineState = newMachineState;
+
+        /* Close VM if was closed someway: */
+        if (m_machineState == KMachineState_PoweredOff || m_machineState == KMachineState_Saved ||
+            m_machineState == KMachineState_Teleported || m_machineState == KMachineState_Aborted)
+        {
+            /* VM has been powered off or saved or aborted, no matter internally or externally.
+             * We must *safely* close the console window unless auto closure is disabled: */
+            if (!m_bIsPreventAutoClose)
+                machineWindowWrapper()->sltTryClose();
+        }
+
+        /* Process GURU: */
+        if (bIsGuruMeditation)
+        {
+            if (machineWindowWrapper()->machineView())
+                machineWindowWrapper()->machineView()->setIgnoreGuestResize(true);
+
+            CConsole console = session().GetConsole();
+            QString strLogFolder = console.GetMachine().GetLogFolder();
+
+            /* Take the screenshot for debugging purposes and save it */
+            QString strFileName = strLogFolder + "/VBox.png";
+            CDisplay display = console.GetDisplay();
+            QImage shot = QImage(display.GetWidth(), display.GetHeight(), QImage::Format_RGB32);
+            display.TakeScreenShot(shot.bits(), shot.width(), shot.height());
+            shot.save(QFile::encodeName(strFileName), "PNG");
+
+            /* Warn the user about GURU: */
+            if (vboxProblem().remindAboutGuruMeditation(console, QDir::toNativeSeparators(strLogFolder)))
+            {
+                qApp->processEvents();
+                console.PowerDown();
+                if (!console.isOk())
+                    vboxProblem().cannotStopMachine(console);
+            }
+        }
+
+#ifdef Q_WS_MAC
+        /* Update Dock Overlay: */
+        if (machineWindowWrapper())
+            machineWindowWrapper()->updateDockOverlay();
+#endif
+    }
+}
+
+void UIMachineLogic::sltAdditionsStateChanged()
+{
+    /* Get console guest: */
+    CGuest guest = session().GetConsole().GetGuest();
+
+    /* Variable flags: */
+    bool bIsActive = guest.GetAdditionsActive();
+    bool bIsGraphicsSupported = guest.GetSupportsGraphics();
+    bool bIsSeamlessSupported = guest.GetSupportsSeamless();
+
+    /* Update action groups: */
+    actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->setEnabled(bIsActive && bIsGraphicsSupported);
+    actionsPool()->action(UIActionIndex_Toggle_Seamless)->setEnabled(bIsActive && bIsGraphicsSupported && bIsSeamlessSupported);
+
+    /* Store new values: */
+    m_bIsSeamlessSupported = bIsSeamlessSupported;
+    m_bIsGraphicsSupported = bIsGraphicsSupported;
+
+#if 0 // TODO: Re-activate seamless if necessary!
+    /* If seamless mode should be enabled then check if it is enabled currently and re-enable it if open-view procedure is finished */
+    if ((m_bIsSeamlessSupported != bIsSeamlessSupported) || (m_bIsGraphicsSupported != bIsGraphicsSupported))
+    {
+        if (actionsPool()->action(UIActionIndex_Toggle_Seamless)->isChecked() && m_bIsOpenViewFinished && bIsGraphicsSupported && bIsSeamlessSupported)
+            toggleFullscreenMode(true, true);
+    }
+#endif
+
+    /* Check the GA version only in case of additions are active: */
+    if (!bIsActive)
+        return;
+
+    /* Check the Guest Additions version and warn the user about possible compatibility issues in case if the installed version is outdated. */
+    QString strVersion = guest.GetAdditionsVersion();
+    uint uVersion = strVersion.toUInt();
+    /** @todo r=bird: This isn't want we want! We want the VirtualBox version of the additions, all three numbers. See @bugref{4084}.*/
+    QString strRealVersion = QString("%1.%2").arg(RT_HIWORD(uVersion)).arg(RT_LOWORD(uVersion));
+    QString strExpectedVersion = QString("%1.%2").arg(VMMDEV_VERSION_MAJOR).arg(VMMDEV_VERSION_MINOR);
+    if (RT_HIWORD(uVersion) < VMMDEV_VERSION_MAJOR)
+    {
+        vboxProblem().warnAboutTooOldAdditions(machineWindowWrapper()->machineWindow(), strRealVersion, strExpectedVersion);
+    }
+    else if (RT_HIWORD(uVersion) == VMMDEV_VERSION_MAJOR && RT_LOWORD(uVersion) <  VMMDEV_VERSION_MINOR)
+    {
+        vboxProblem().warnAboutOldAdditions(machineWindowWrapper()->machineWindow(), strRealVersion, strExpectedVersion);
+    }
+    else if (uVersion > VMMDEV_VERSION)
+    {
+        vboxProblem().warnAboutNewAdditions(machineWindowWrapper()->machineWindow(), strRealVersion, strExpectedVersion);
+    }
+}
+
+void UIMachineLogic::sltToggleGuestAutoresize(bool /* bEnabled */)
+{
+    /* Do not process if window or view is missing! */
+    if (!machineWindowWrapper() || !machineWindowWrapper()->machineView())
+        return;
+
+    // TODO: Enable/Disable guest-autoresize for machine view! */
 }
 
@@ -654,5 +868,5 @@
         /* Suspend the VM and ignore the close event if failed to do so.
          * pause() will show the error message to the user. */
-        if (!pause(true))
+        if (!pause())
             return;
     }
@@ -690,5 +904,5 @@
     /* Restore the running state if needed. */
     if (!bWasPaused)
-        pause(false);
+        unpause();
 }
 
@@ -716,9 +930,5 @@
 void UIMachineLogic::sltPause(bool aOn)
 {
-    /* Do not process if window is missing! */
     pause(aOn);
-
-    /* Update appearance: */
-    updateAppearanceOf(UIVisualElement_PauseStuff);
 }
 
@@ -749,11 +959,14 @@
 void UIMachineLogic::sltPrepareStorageMenu()
 {
+    /* Get the sender() menu: */
     QMenu *pMenu = qobject_cast<QMenu*>(sender());
     AssertMsg(pMenu, ("This slot should only be called on hovering storage menu!\n"));
     pMenu->clear();
 
+    /* Short way to common storage menus: */
     QMenu *pOpticalDevicesMenu = actionsPool()->action(UIActionIndex_Menu_OpticalDevices)->menu();
     QMenu *pFloppyDevicesMenu = actionsPool()->action(UIActionIndex_Menu_FloppyDevices)->menu();
 
+    /* Determine device type: */
     KDeviceType deviceType = pMenu == pOpticalDevicesMenu ? KDeviceType_DVD :
                              pMenu == pFloppyDevicesMenu  ? KDeviceType_Floppy :
@@ -761,4 +974,5 @@
     AssertMsg(deviceType != KDeviceType_Null, ("Incorrect storage device type!\n"));
 
+    /* Determine medium type: */
     VBoxDefs::MediumType mediumType = pMenu == pOpticalDevicesMenu ? VBoxDefs::MediumType_DVD :
                                       pMenu == pFloppyDevicesMenu  ? VBoxDefs::MediumType_Floppy :
@@ -766,4 +980,5 @@
     AssertMsg(mediumType != VBoxDefs::MediumType_Invalid, ("Incorrect storage medium type!\n"));
 
+    /* Fill attachments menu: */
     CMachine machine = session().GetMachine();
     const CMediumAttachmentVector &attachments = machine.GetMediumAttachments();
@@ -773,5 +988,5 @@
         if (!controller.isNull() && (attachment.GetType() == deviceType))
         {
-            /* Attachment menu item */
+            /* Attachment menu item: */
             QMenu *pAttachmentMenu = 0;
             if (pMenu->menuAction()->data().toInt() > 1)
@@ -799,5 +1014,5 @@
             else pAttachmentMenu = pMenu;
 
-            /* Mount Medium actions */
+            /* Mount Medium actions: */
             CMediumVector mediums;
             switch (mediumType)
@@ -815,4 +1030,5 @@
             }
 
+            /* Mediums to be shown: */
             int mediumsToBeShown = 0;
             const int maxMediumsToBeShown = 5;
@@ -846,8 +1062,8 @@
                     mountMediumAction->setCheckable(true);
                     mountMediumAction->setChecked(!currentMedium.isNull() && medium.GetId() == currentId);
-                    mountMediumAction->setData(QVariant::fromValue(MountTarget(controller.GetName(),
-                                                                               attachment.GetPort(),
-                                                                               attachment.GetDevice(),
-                                                                               medium.GetId())));
+                    mountMediumAction->setData(QVariant::fromValue(MediumTarget(controller.GetName(),
+                                                                                attachment.GetPort(),
+                                                                                attachment.GetDevice(),
+                                                                                medium.GetId())));
                     connect(mountMediumAction, SIGNAL(triggered(bool)), this, SLOT(sltMountStorageMedium()));
                     pAttachmentMenu->addAction(mountMediumAction);
@@ -858,23 +1074,23 @@
             }
 
-            /* Virtual Media Manager action */
+            /* Virtual Media Manager action: */
             QAction *callVMMAction = new QAction(pAttachmentMenu);
             callVMMAction->setIcon(QIcon(":/diskimage_16px.png"));
-            callVMMAction->setData(QVariant::fromValue(MountTarget(controller.GetName(),
-                                                                   attachment.GetPort(),
-                                                                   attachment.GetDevice(),
-                                                                   mediumType)));
+            callVMMAction->setData(QVariant::fromValue(MediumTarget(controller.GetName(),
+                                                                    attachment.GetPort(),
+                                                                    attachment.GetDevice(),
+                                                                    mediumType)));
             connect(callVMMAction, SIGNAL(triggered(bool)), this, SLOT(sltMountStorageMedium()));
             pAttachmentMenu->addAction(callVMMAction);
 
-            /* Separator */
+            /* Insert separator: */
             pAttachmentMenu->addSeparator();
 
-            /* Unmount Medium action */
+            /* Unmount Medium action: */
             QAction *unmountMediumAction = new QAction(pAttachmentMenu);
             unmountMediumAction->setEnabled(!currentMedium.isNull());
-            unmountMediumAction->setData(QVariant::fromValue(MountTarget(controller.GetName(),
-                                                                         attachment.GetPort(),
-                                                                         attachment.GetDevice())));
+            unmountMediumAction->setData(QVariant::fromValue(MediumTarget(controller.GetName(),
+                                                                          attachment.GetPort(),
+                                                                          attachment.GetDevice())));
             connect(unmountMediumAction, SIGNAL(triggered(bool)), this, SLOT(sltMountStorageMedium()));
             pAttachmentMenu->addAction(unmountMediumAction);
@@ -905,19 +1121,21 @@
         /* Empty menu item */
         Assert(pMenu->isEmpty());
-        QAction *emptyMenuAction = new QAction(pMenu);
-        emptyMenuAction->setEnabled(false);
+        QAction *pEmptyMenuAction = new QAction(pMenu);
+        pEmptyMenuAction->setEnabled(false);
         switch (mediumType)
         {
             case VBoxDefs::MediumType_DVD:
-                emptyMenuAction->setText(tr("No CD/DVD Devices Attached"));
+                pEmptyMenuAction->setText(tr("No CD/DVD Devices Attached"));
+                pEmptyMenuAction->setToolTip(tr("No CD/DVD devices attached to that VM"));
                 break;
             case VBoxDefs::MediumType_Floppy:
-                emptyMenuAction->setText(tr("No Floppy Devices Attached"));
+                pEmptyMenuAction->setText(tr("No Floppy Devices Attached"));
+                pEmptyMenuAction->setToolTip(tr("No floppy devices attached to that VM"));
                 break;
             default:
                 break;
         }
-        emptyMenuAction->setIcon(VBoxGlobal::iconSet(":/delete_16px.png", ":/delete_dis_16px.png"));
-        pMenu->addAction(emptyMenuAction);
+        pEmptyMenuAction->setIcon(VBoxGlobal::iconSet(":/delete_16px.png", ":/delete_dis_16px.png"));
+        pMenu->addAction(pEmptyMenuAction);
     }
 }
@@ -925,27 +1143,27 @@
 void UIMachineLogic::sltMountStorageMedium()
 {
-    /* Get sender action */
+    /* Get sender action: */
     QAction *action = qobject_cast<QAction*>(sender());
     AssertMsg(action, ("This slot should only be called on selecting storage menu item!\n"));
 
-    /* Get current machine */
+    /* Get current machine: */
     CMachine machine = session().GetMachine();
 
-    /* Get mount-target */
-    MountTarget target = action->data().value<MountTarget>();
-
-    /* Current mount-target attributes */
+    /* Get mount-target: */
+    MediumTarget target = action->data().value<MediumTarget>();
+
+    /* Current mount-target attributes: */
     CMediumAttachment currentAttachment = machine.GetMediumAttachment(target.name, target.port, target.device);
     CMedium currentMedium = currentAttachment.GetMedium();
     QString currentId = currentMedium.isNull() ? QString("") : currentMedium.GetId();
 
-    /* New mount-target attributes */
+    /* New mount-target attributes: */
     QString newId = QString("");
     bool selectWithMediaManager = target.type != VBoxDefs::MediumType_Invalid;
 
-    /* Open Virtual Media Manager to select image id */
+    /* Open Virtual Media Manager to select image id: */
     if (selectWithMediaManager)
     {
-        /* Search for already used images */
+        /* Search for already used images: */
         QStringList usedImages;
         foreach (const CMediumAttachment &attachment, machine.GetMediumAttachments())
@@ -955,5 +1173,5 @@
                 usedImages << medium.GetId();
         }
-        /* Open VMM Dialog */
+        /* Open VMM Dialog: */
         VBoxMediaManagerDlg dlg(machineWindowWrapper()->machineWindow());
         dlg.setup(target.type, true /* select? */, true /* refresh? */, machine, currentId, true, usedImages);
@@ -962,5 +1180,5 @@
         else return;
     }
-    /* Use medium which was sent */
+    /* Use medium which was sent: */
     else if (!target.id.isNull() && target.id != currentId)
         newId = target.id;
@@ -968,5 +1186,5 @@
     bool mount = !newId.isEmpty();
 
-    /* Remount medium to the predefined port/device */
+    /* Remount medium to the predefined port/device: */
     bool wasMounted = false;
     machine.MountMedium(target.name, target.port, target.device, newId, false /* force */);
@@ -975,8 +1193,8 @@
     else
     {
-        /* Ask for force remounting */
+        /* Ask for force remounting: */
         if (vboxProblem().cannotRemountMedium(machineWindowWrapper()->machineWindow(), machine, vboxGlobal().findMedium (mount ? newId : currentId), mount, true /* retry? */) == QIMessageBox::Ok)
         {
-            /* Force remount medium to the predefined port/device. */
+            /* Force remount medium to the predefined port/device: */
             machine.MountMedium(target.name, target.port, target.device, newId, true /* force */);
             if (machine.isOk())
@@ -996,4 +1214,82 @@
 }
 
+void UIMachineLogic::sltPrepareUSBMenu()
+{
+    /* Get the sender() menu: */
+    QMenu *pMenu = qobject_cast<QMenu*>(sender());
+    QMenu *pUSBDevicesMenu = actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu();
+    AssertMsg(pMenu == pUSBDevicesMenu, ("This slot should only be called on hovering USB menu!\n"));
+    pMenu->clear();
+
+    /* Get HOST: */
+    CHost host = vboxGlobal().virtualBox().GetHost();
+
+    /* Get USB devices list: */
+    CHostUSBDeviceVector devices = host.GetUSBDevices();
+
+    /* Fill USB devices menu: */
+    bool bIsUSBListEmpty = devices.size() == 0;
+    if (bIsUSBListEmpty)
+    {
+        /* Fill USB devices menu: */
+        QAction *pEmptyMenuAction = new QAction(pMenu);
+        pEmptyMenuAction->setEnabled(false);
+        pEmptyMenuAction->setText(tr("No USB Devices Connected"));
+        pEmptyMenuAction->setIcon(VBoxGlobal::iconSet(":/delete_16px.png", ":/delete_dis_16px.png"));
+        pEmptyMenuAction->setToolTip(tr("No supported devices connected to the host PC"));
+    }
+    else
+    {
+        foreach (const CHostUSBDevice hostDevice, devices)
+        {
+            /* Get common USB device: */
+            CUSBDevice device(hostDevice);
+
+            /* Create USB device action: */
+            QAction *attachUSBAction = new QAction(vboxGlobal().details(device), pMenu);
+            attachUSBAction->setCheckable(true);
+            connect(attachUSBAction, SIGNAL(triggered(bool)), this, SLOT(sltAttachUSBDevice()));
+            pMenu->addAction(attachUSBAction);
+
+            /* Check if that USB device was alread attached to this session: */
+            CConsole console = session().GetConsole();
+            CUSBDevice attachedDevice = console.FindUSBDeviceById(device.GetId());
+            attachUSBAction->setChecked(!attachedDevice.isNull());
+            attachUSBAction->setEnabled(hostDevice.GetState() != KUSBDeviceState_Unavailable);
+
+            /* Set USB attach data: */
+            attachUSBAction->setData(QVariant::fromValue(USBTarget(!attachUSBAction->isChecked(), device.GetId())));
+        }
+    }
+}
+
+void UIMachineLogic::sltAttachUSBDevice()
+{
+    /* Get sender action: */
+    QAction *action = qobject_cast<QAction*>(sender());
+    AssertMsg(action, ("This slot should only be called on selecting USB menu item!\n"));
+
+    /* Get current console: */
+    CConsole console = session().GetConsole();
+
+    /* Get USB target: */
+    USBTarget target = action->data().value<USBTarget>();
+    CUSBDevice device = console.FindUSBDeviceById(target.id);
+
+    /* Attach USB device: */
+    if (target.attach)
+    {
+        console.AttachUSBDevice(target.id);
+        if (!console.isOk())
+            vboxProblem().cannotAttachUSBDevice(console, vboxGlobal().details(device));
+    }
+    else
+    {
+        console.DetachUSBDevice(target.id);
+        if (!console.isOk())
+            vboxProblem().cannotDetachUSBDevice(console, vboxGlobal().details(device));
+    }
+}
+
 void UIMachineLogic::sltOpenNetworkAdaptersDialog()
 {
@@ -1018,21 +1314,10 @@
 }
 
-void UIMachineLogic::sltPrepareUSBMenu()
-{
-}
-
-void UIMachineLogic::sltAttachUSBDevice()
-{
-}
-
 void UIMachineLogic::sltSwitchVrdp(bool aOn)
 {
     /* Enable VRDP server if possible: */
     CVRDPServer server = session().GetMachine().GetVRDPServer();
-    AssertMsg(!server.isNull(), ("VRDP Server should not be null!\n"));
+    AssertMsg(!server.isNull(), ("VRDP server should not be null!\n"));
     server.SetEnabled(aOn);
-
-    /* Update appearance: */
-    updateAppearanceOf(UIVisualElement_VRDPStuff);
 }
 
@@ -1070,7 +1355,6 @@
     }
 
+#if 0 // TODO: Rework additions downloader logic...
     /* Download the required image */
-    // TODO: Rework additions downloader logic...
-    #if 0
     int result = vboxProblem().cannotFindGuestAdditions(QDir::toNativeSeparators(strSrc1), QDir::toNativeSeparators(strSrc2));
     if (result == QIMessageBox::Yes)
@@ -1083,5 +1367,5 @@
         //pdl->start();
     }
-    #endif
+#endif
 }
 
@@ -1133,152 +1417,5 @@
 #endif
 
-void UIMachineLogic::sltUpdateMachineState(KMachineState machineState)
-{
-    bool bGuruMeditation = false;
-
-    if (machineWindowWrapper() && m_machineState != machineState)
-    {
-        switch (machineState)
-        {
-            case KMachineState_Stuck:
-            {
-                bGuruMeditation = true;
-                break;
-            }
-            case KMachineState_Paused:
-            {
-                if (!actionsPool()->action(UIActionIndex_Toggle_Pause)->isChecked())
-                    actionsPool()->action(UIActionIndex_Toggle_Pause)->setChecked(true);
-                break;
-            }
-            case KMachineState_Running:
-            case KMachineState_Teleporting:
-            case KMachineState_LiveSnapshotting:
-            {
-                if ((m_machineState == KMachineState_Paused ||
-                     m_machineState == KMachineState_TeleportingPausedVM)
-                     && actionsPool()->action(UIActionIndex_Toggle_Pause)->isChecked())
-                     actionsPool()->action(UIActionIndex_Toggle_Pause)->setChecked(false);
-                break;
-            }
-#ifdef Q_WS_X11
-            case KMachineState_Starting:
-            case KMachineState_Restoring:
-            case KMachineState_TeleportingIn:
-            {
-                /* The keyboard handler may wish to do some release logging on startup.
-                 * Tell it that the logger is now active. */
-                doXKeyboardLogging(QX11Info::display());
-                break;
-            }
-#endif
-            default:
-                break;
-        }
-
-        bool bIsRunning = machineState == KMachineState_Running ||
-                          machineState == KMachineState_Teleporting ||
-                          machineState == KMachineState_LiveSnapshotting;
-
-        bool bIsRunningOrPaused = machineState == KMachineState_Running ||
-                                  machineState == KMachineState_Teleporting ||
-                                  machineState == KMachineState_LiveSnapshotting ||
-                                  machineState == KMachineState_Paused;
-
-        m_pRunningActions->setEnabled(bIsRunning);
-        m_pRunningOrPausedActions->setEnabled(bIsRunningOrPaused);
-
-        m_machineState = machineState;
-
-        updateAppearanceOf(UIVisualElement_WindowCaption |
-                           UIVisualElement_HDStuff | UIVisualElement_CDStuff | UIVisualElement_FDStuff |
-                           UIVisualElement_NetworkStuff | UIVisualElement_USBStuff | UIVisualElement_VRDPStuff |
-                           UIVisualElement_PauseStuff | UIVisualElement_MouseIntegrationStuff);
-
-        if (machineState == KMachineState_PoweredOff ||
-            machineState == KMachineState_Saved ||
-            machineState == KMachineState_Teleported ||
-            machineState == KMachineState_Aborted)
-        {
-            /* VM has been powered off or saved or aborted, no matter internally or externally.
-             * We must *safely* close the console window unless auto closure is disabled: */
-            if (!m_bIsPreventAutoClose)
-                machineWindowWrapper()->sltTryClose();
-        }
-    }
-
-    if (bGuruMeditation)
-    {
-        machineWindowWrapper()->machineView()->setIgnoreGuestResize(true);
-
-        CConsole console = session().GetConsole();
-        QString strLogFolder = console.GetMachine().GetLogFolder();
-
-        /* Take the screenshot for debugging purposes and save it */
-        QString strFileName = strLogFolder + "/VBox.png";
-
-        CDisplay display = console.GetDisplay();
-        QImage shot = QImage(display.GetWidth(), display.GetHeight(), QImage::Format_RGB32);
-        display.TakeScreenShot(shot.bits(), shot.width(), shot.height());
-        shot.save(QFile::encodeName(strFileName), "PNG");
-
-        if (vboxProblem().remindAboutGuruMeditation(console, QDir::toNativeSeparators(strLogFolder)))
-        {
-            qApp->processEvents();
-            console.PowerDown();
-            if (!console.isOk())
-                vboxProblem().cannotStopMachine(console);
-        }
-    }
-
-#ifdef Q_WS_MAC
-    if (machineWindowWrapper())
-        machineWindowWrapper()->updateDockOverlay();
-#endif
-}
-
-void UIMachineLogic::sltUpdateAdditionsState(const QString &strVersion, bool bIsActive,
-                                             bool bIsSeamlessSupported, bool bIsGraphicsSupported)
-{
-    actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->setEnabled(bIsActive && bIsGraphicsSupported);
-    actionsPool()->action(UIActionIndex_Toggle_Seamless)->setEnabled(bIsActive && bIsGraphicsSupported && bIsSeamlessSupported);
-
-    if ((m_bIsSeamlessSupported != bIsSeamlessSupported) || (m_bIsGraphicsSupported != bIsGraphicsSupported))
-    {
-        m_bIsSeamlessSupported = bIsSeamlessSupported;
-        m_bIsGraphicsSupported = bIsGraphicsSupported;
-
-        // TODO: How should that be performed now?
-        /* If seamless mode should be enabled then check if it is enabled currently and re-enable it if open-view procedure is finished */
-        //if (actionsPool()->action(UIActionIndex_Toggle_Seamless)->isChecked() && m_bIsOpenViewFinished && bIsGraphicsSupported && bIsSeamlessSupported)
-        //    toggleFullscreenMode(true, true);
-    }
-
-    /* Check the GA version only in case of additions are active */
-    if (!bIsActive)
-        return;
-
-    /* Check the Guest Additions version and warn the user about possible
-     * compatibility issues in case if the installed version is outdated. */
-    uint uVersion = strVersion.toUInt();
-    /** @todo r=bird: This isn't want we want! We want the VirtualBox version of the additions, all three numbers. See @bugref{4084}.*/
-    QString strRealVersion = QString("%1.%2").arg(RT_HIWORD(uVersion)).arg(RT_LOWORD(uVersion));
-    QString strExpectedVersion = QString("%1.%2").arg(VMMDEV_VERSION_MAJOR).arg(VMMDEV_VERSION_MINOR);
-
-    if (RT_HIWORD(uVersion) < VMMDEV_VERSION_MAJOR)
-    {
-        vboxProblem().warnAboutTooOldAdditions(machineWindowWrapper()->machineWindow(), strRealVersion, strExpectedVersion);
-    }
-    else if (RT_HIWORD(uVersion) == VMMDEV_VERSION_MAJOR && RT_LOWORD(uVersion) <  VMMDEV_VERSION_MINOR)
-    {
-        vboxProblem().warnAboutOldAdditions(machineWindowWrapper()->machineWindow(), strRealVersion, strExpectedVersion);
-    }
-    else if (uVersion > VMMDEV_VERSION)
-    {
-        vboxProblem().warnAboutNewAdditions(machineWindowWrapper()->machineWindow(), strRealVersion, strExpectedVersion);
-    }
-}
-
-void UIMachineLogic::sltUpdateMouseState(int iState)
+void UIMachineLogic::sltMouseStateChanged(int iState)
 {
     actionsPool()->action(UIActionIndex_Toggle_MouseIntegration)->setEnabled(iState & UIMouseStateType_MouseAbsolute);
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h	(revision 26656)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h	(revision 26691)
@@ -35,4 +35,5 @@
 
 /* Local forwards */
+class UISession;
 class UIActionsPool;
 class UIMachineWindow;
@@ -46,32 +47,28 @@
     /* Factory function to create required logic sub-child: */
     static UIMachineLogic* create(QObject *pParent,
-                                  const CSession &session,
+                                  UISession *pSession,
                                   UIActionsPool *pActionsPool,
                                   UIVisualStateType visualStateType);
 
     /* Public getters: */
-    CSession& session() { return m_session; }
+    UISession* uisession() { return m_pSession; }
     UIActionsPool* actionsPool() { return m_pActionsPool; }
+    UIVisualStateType visualStateType() const { return m_visualStateType; }
+    UIMachineWindow* machineWindowWrapper() { return m_pMachineWindowContainer; }
     KMachineState machineState() const { return m_machineState; }
-    UIVisualStateType visualStateType() const { return m_visualStateType; }
-    bool isPaused() const { return m_machineState == KMachineState_Paused || m_machineState == KMachineState_TeleportingPausedVM; }
-
-    /* Public setters: */
-    bool pause(bool bPaused);
+    bool isPaused() const { return m_machineState == KMachineState_Paused ||
+                            m_machineState == KMachineState_TeleportingPausedVM; }
 
 protected:
 
-    /* Common machine logic constructor: */
+    /* Machine logic constructor/destructor: */
     UIMachineLogic(QObject *pParent,
-                   const CSession &session,
+                   UISession *pSession,
                    UIActionsPool *pActionsPool,
                    UIVisualStateType visualStateType);
-    /* Common machine logic destructor: */
     virtual ~UIMachineLogic();
 
-    /* Update routines: */
-    virtual void updateAppearanceOf(int iElement);
-
     /* Prepare helpers: */
+    virtual void prepareConsoleConnections();
     virtual void prepareActionGroups();
     virtual void prepareActionConnections();
@@ -84,7 +81,8 @@
     //void cleanupActionConnections();
     //void cleanupActionGroups();
+    //void cleanupConsoleConnections();
 
     /* Protected getters: */
-    UIMachineWindow* machineWindowWrapper() { return m_pMachineWindowContainer; }
+    CSession& session();
     bool isFirstTimeStarted() const { return m_bIsFirstTimeStarted; }
     bool isPreventAutoClose() const { return m_bIsPreventAutoClose; }
@@ -95,4 +93,8 @@
     void setOpenViewFinished(bool bIsOpenViewFinished) { m_bIsOpenViewFinished = bIsOpenViewFinished; }
 
+    /* Console related routines: */
+    bool pause() { return pause(true); }
+    bool unpause() { return pause(false); }
+
     /* Protected variables: */
     UIMachineWindow *m_pMachineWindowContainer;
@@ -100,7 +102,12 @@
 private slots:
 
+    /* Console callback handlers: */
+    void sltMachineStateChanged(KMachineState newMachineState);
+    void sltAdditionsStateChanged();
+
     /* "Machine" menu funtionality */
+    void sltToggleGuestAutoresize(bool bEnabled);
     void sltAdjustWindow();
-    void sltToggleMouseIntegration(bool bOff);
+    void sltToggleMouseIntegration(bool bDisabled);
     void sltTypeCAD();
 #ifdef Q_WS_X11
@@ -117,8 +124,8 @@
     void sltPrepareStorageMenu();
     void sltMountStorageMedium();
+    void sltPrepareUSBMenu();
+    void sltAttachUSBDevice();
     void sltOpenNetworkAdaptersDialog();
     void sltOpenSharedFoldersDialog();
-    void sltPrepareUSBMenu();
-    void sltAttachUSBDevice();
     void sltSwitchVrdp(bool bOn);
     void sltInstallGuestAdditions();
@@ -131,34 +138,18 @@
 #endif
 
-    /* Machine state change handler */
-    void sltUpdateMachineState(KMachineState machineState);
-    /* Guest Additions state change handler */
-    void sltUpdateAdditionsState(const QString &strVersion, bool bActive, bool bSeamlessSupported, bool bGraphicsSupported);
-    /* Mouse Integration state change handler */
-    void sltUpdateMouseState(int iState);
+    /* Machine view handlers: */
+    void sltMouseStateChanged(int iState);
 
 private:
 
     /* Utility functions: */
+    bool pause(bool bPaused);
     void installGuestAdditionsFrom(const QString &strSource);
-    static int searchMaxSnapshotIndex(const CMachine &machine, const CSnapshot &snapshot, const QString &strNameTemplate);
-#ifdef VBOX_WITH_DEBUGGER_GUI
-    bool dbgCreated();
-    void dbgDestroy();
-    void dbgAdjustRelativePos();
-#endif
-
-#if 0 // TODO: Where to move that?
-# ifdef Q_WS_MAC
-    void fadeToBlack();
-    void fadeToNormal();
-# endif
-    bool toggleFullscreenMode(bool aOn, bool aSeamless);
-    void switchToFullscreen(bool aOn, bool aSeamless);
-    void setViewInSeamlessMode(const QRect &aTargetRect);
-#endif
+    static int searchMaxSnapshotIndex(const CMachine &machine,
+                                      const CSnapshot &snapshot,
+                                      const QString &strNameTemplate);
 
     /* Private variables: */
-    CSession m_session;
+    UISession *m_pSession;
     UIActionsPool *m_pActionsPool;
     KMachineState m_machineState;
@@ -175,5 +166,12 @@
     bool m_bIsPreventAutoClose : 1;
 
+    /* Friend classes: */
+    friend class UIMachineWindow;
+
 #ifdef VBOX_WITH_DEBUGGER_GUI
+    /* Debugger functionality: */
+    bool dbgCreated();
+    void dbgDestroy();
+    void dbgAdjustRelativePos();
     /* The handle to the debugger gui: */
     PDBGGUI m_dbgGui;
@@ -181,4 +179,14 @@
     PCDBGGUIVT m_dbgGuiVT;
 #endif
+
+#if 0 // TODO: Where to move that?
+# ifdef Q_WS_MAC
+    void fadeToBlack();
+    void fadeToNormal();
+# endif
+    bool toggleFullscreenMode(bool aOn, bool aSeamless);
+    void switchToFullscreen(bool aOn, bool aSeamless);
+    void setViewInSeamlessMode(const QRect &aTargetRect);
+#endif
 };
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp	(revision 26656)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.cpp	(revision 26691)
@@ -32,4 +32,5 @@
 #include "VBoxProblemReporter.h"
 #include "UIFrameBuffer.h"
+#include "UISession.h"
 #include "UIActionsPool.h"
 #include "UIMachineLogic.h"
@@ -84,121 +85,4 @@
 #endif /* defined (Q_WS_MAC) */
 
-/** Guest mouse pointer shape change event. */
-class MousePointerChangeEvent : public QEvent
-{
-public:
-
-    MousePointerChangeEvent (bool visible, bool alpha, uint xhot, uint yhot, uint width, uint height, const uchar *shape)
-        : QEvent((QEvent::Type)VBoxDefs::MousePointerChangeEventType)
-        , vis(visible), alph(alpha), xh(xhot), yh(yhot), w(width), h(height), data(0)
-    {
-        uint dataSize = ((((width + 7) / 8 * height) + 3) & ~3) + width * 4 * height;
-
-        if (shape)
-        {
-            data = new uchar[dataSize];
-            memcpy((void*)data, (void*)shape, dataSize);
-        }
-    }
-
-    ~MousePointerChangeEvent()
-    {
-        if (data) delete[] data;
-    }
-
-    bool isVisible() const { return vis; }
-    bool hasAlpha() const { return alph; }
-    uint xHot() const { return xh; }
-    uint yHot() const { return yh; }
-    uint width() const { return w; }
-    uint height() const { return h; }
-    const uchar *shapeData() const { return data; }
-
-private:
-
-    bool vis, alph;
-    uint xh, yh, w, h;
-    const uchar *data;
-};
-
-/** Guest mouse absolute positioning capability change event. */
-class MouseCapabilityEvent : public QEvent
-{
-public:
-
-    MouseCapabilityEvent (bool supportsAbsolute, bool needsHostCursor)
-        : QEvent((QEvent::Type) VBoxDefs::MouseCapabilityEventType)
-        , can_abs(supportsAbsolute), needs_host_cursor(needsHostCursor) {}
-
-    bool supportsAbsolute() const { return can_abs; }
-    bool needsHostCursor() const { return needs_host_cursor; }
-
-private:
-
-    bool can_abs;
-    bool needs_host_cursor;
-};
-
-/** Machine state change. */
-class StateChangeEvent : public QEvent
-{
-public:
-
-    StateChangeEvent (KMachineState state)
-        : QEvent((QEvent::Type)VBoxDefs::MachineStateChangeEventType)
-        , s (state) {}
-
-    KMachineState machineState() const { return s; }
-
-private:
-
-    KMachineState s;
-};
-
-/** Guest Additions property changes. */
-class GuestAdditionsEvent : public QEvent
-{
-public:
-
-    GuestAdditionsEvent (const QString &aOsTypeId,
-                         const QString &aAddVersion,
-                         bool aAddActive,
-                         bool aSupportsSeamless,
-                         bool aSupportsGraphics)
-        : QEvent((QEvent::Type)VBoxDefs::AdditionsStateChangeEventType)
-        , mOsTypeId(aOsTypeId), mAddVersion(aAddVersion)
-        , mAddActive(aAddActive), mSupportsSeamless(aSupportsSeamless)
-        , mSupportsGraphics (aSupportsGraphics) {}
-
-    const QString &osTypeId() const { return mOsTypeId; }
-    const QString &additionVersion() const { return mAddVersion; }
-    bool additionActive() const { return mAddActive; }
-    bool supportsSeamless() const { return mSupportsSeamless; }
-    bool supportsGraphics() const { return mSupportsGraphics; }
-
-private:
-
-    QString mOsTypeId;
-    QString mAddVersion;
-    bool mAddActive;
-    bool mSupportsSeamless;
-    bool mSupportsGraphics;
-};
-
-/** DVD/Floppy drive change event */
-class MediaDriveChangeEvent : public QEvent
-{
-public:
-
-    MediaDriveChangeEvent(VBoxDefs::MediumType aType)
-        : QEvent ((QEvent::Type) VBoxDefs::MediaDriveChangeEventType)
-        , mType (aType) {}
-    VBoxDefs::MediumType type() const { return mType; }
-
-private:
-
-    VBoxDefs::MediumType mType;
-};
-
 /** Menu activation event */
 class ActivateMenuEvent : public QEvent
@@ -216,87 +100,4 @@
 };
 
-/** VM Runtime error event */
-class RuntimeErrorEvent : public QEvent
-{
-public:
-
-    RuntimeErrorEvent(bool aFatal, const QString &aErrorID, const QString &aMessage)
-        : QEvent((QEvent::Type)VBoxDefs::RuntimeErrorEventType)
-        , mFatal(aFatal), mErrorID(aErrorID), mMessage(aMessage) {}
-
-    bool fatal() const { return mFatal; }
-    QString errorID() const { return mErrorID; }
-    QString message() const { return mMessage; }
-
-private:
-
-    bool mFatal;
-    QString mErrorID;
-    QString mMessage;
-};
-
-/** Modifier key change event */
-class ModifierKeyChangeEvent : public QEvent
-{
-public:
-
-    ModifierKeyChangeEvent(bool fNumLock, bool fCapsLock, bool fScrollLock)
-        : QEvent((QEvent::Type)VBoxDefs::ModifierKeyChangeEventType)
-        , mNumLock(fNumLock), mCapsLock(fCapsLock), mScrollLock(fScrollLock) {}
-
-    bool numLock()    const { return mNumLock; }
-    bool capsLock()   const { return mCapsLock; }
-    bool scrollLock() const { return mScrollLock; }
-
-private:
-
-    bool mNumLock, mCapsLock, mScrollLock;
-};
-
-/** Network adapter change event */
-class NetworkAdapterChangeEvent : public QEvent
-{
-public:
-
-    NetworkAdapterChangeEvent(INetworkAdapter *aAdapter)
-        : QEvent((QEvent::Type)VBoxDefs::NetworkAdapterChangeEventType)
-        , mAdapter(aAdapter) {}
-
-    INetworkAdapter* networkAdapter() { return mAdapter; }
-
-private:
-
-    INetworkAdapter *mAdapter;
-};
-
-/** USB controller state change event */
-class USBControllerStateChangeEvent : public QEvent
-{
-public:
-
-    USBControllerStateChangeEvent()
-        : QEvent((QEvent::Type)VBoxDefs::USBCtlStateChangeEventType) {}
-};
-
-/** USB device state change event */
-class USBDeviceStateChangeEvent : public QEvent
-{
-public:
-
-    USBDeviceStateChangeEvent(const CUSBDevice &aDevice, bool aAttached, const CVirtualBoxErrorInfo &aError)
-        : QEvent((QEvent::Type)VBoxDefs::USBDeviceStateChangeEventType)
-        , mDevice(aDevice), mAttached(aAttached), mError(aError) {}
-
-    CUSBDevice device() const { return mDevice; }
-    bool attached() const { return mAttached; }
-    CVirtualBoxErrorInfo error() const { return mError; }
-
-private:
-
-    CUSBDevice mDevice;
-    bool mAttached;
-    CVirtualBoxErrorInfo mError;
-};
-
 class VBoxViewport: public QWidget
 {
@@ -317,217 +118,4 @@
     }
 };
-
-class UIConsoleCallback : VBOX_SCRIPTABLE_IMPL(IConsoleCallback)
-{
-public:
-
-    UIConsoleCallback (UIMachineView *v)
-    {
-#if defined (Q_WS_WIN)
-        mRefCnt = 0;
-#endif
-        mView = v;
-    }
-
-    virtual ~UIConsoleCallback() {}
-
-    NS_DECL_ISUPPORTS
-
-#if defined (Q_WS_WIN)
-    STDMETHOD_(ULONG, AddRef)()
-    {
-        return ::InterlockedIncrement(&mRefCnt);
-    }
-    STDMETHOD_(ULONG, Release)()
-    {
-        long cnt = ::InterlockedDecrement(&mRefCnt);
-        if (cnt == 0)
-            delete this;
-        return cnt;
-    }
-#endif
-    VBOX_SCRIPTABLE_DISPATCH_IMPL(IConsoleCallback)
-
-    STDMETHOD(OnMousePointerShapeChange) (BOOL visible, BOOL alpha,
-                                          ULONG xhot, ULONG yhot,
-                                          ULONG width, ULONG height,
-                                          BYTE *shape)
-    {
-        QApplication::postEvent(mView, new MousePointerChangeEvent(visible, alpha, xhot, yhot, width, height, shape));
-        return S_OK;
-    }
-
-    STDMETHOD(OnMouseCapabilityChange)(BOOL supportsAbsolute, BOOL needsHostCursor)
-    {
-        QApplication::postEvent(mView, new MouseCapabilityEvent (supportsAbsolute, needsHostCursor));
-        return S_OK;
-    }
-
-    STDMETHOD(OnKeyboardLedsChange)(BOOL fNumLock, BOOL fCapsLock, BOOL fScrollLock)
-    {
-        QApplication::postEvent(mView, new ModifierKeyChangeEvent (fNumLock, fCapsLock, fScrollLock));
-        return S_OK;
-    }
-
-    STDMETHOD(OnStateChange)(MachineState_T machineState)
-    {
-        QApplication::postEvent(mView, new StateChangeEvent ((KMachineState) machineState));
-        return S_OK;
-    }
-
-    STDMETHOD(OnAdditionsStateChange)()
-    {
-        CGuest guest = mView->console().GetGuest();
-        QApplication::postEvent (mView, new GuestAdditionsEvent(guest.GetOSTypeId(), guest.GetAdditionsVersion(),
-                                                                guest.GetAdditionsActive(), guest.GetSupportsSeamless(),
-                                                                guest.GetSupportsGraphics()));
-        return S_OK;
-    }
-
-    STDMETHOD(OnNetworkAdapterChange) (INetworkAdapter *aNetworkAdapter)
-    {
-        QApplication::postEvent (mView, new NetworkAdapterChangeEvent (aNetworkAdapter));
-        return S_OK;
-    }
-
-    STDMETHOD(OnStorageControllerChange) ()
-    {
-        //QApplication::postEvent(mView, new StorageControllerChangeEvent());
-        return S_OK;
-    }
-
-    STDMETHOD(OnMediumChange)(IMediumAttachment *aMediumAttachment)
-    {
-        CMediumAttachment att(aMediumAttachment);
-        switch (att.GetType())
-        {
-            case KDeviceType_Floppy:
-                QApplication::postEvent(mView, new MediaDriveChangeEvent(VBoxDefs::MediumType_Floppy));
-                break;
-            case KDeviceType_DVD:
-                QApplication::postEvent(mView, new MediaDriveChangeEvent(VBoxDefs::MediumType_DVD));
-                break;
-            default:
-                break;
-        }
-        return S_OK;
-    }
-
-    STDMETHOD(OnCPUChange)(ULONG aCPU, BOOL aRemove)
-    {
-        NOREF(aCPU);
-        NOREF(aRemove);
-        return S_OK;
-    }
-
-    STDMETHOD(OnSerialPortChange) (ISerialPort *aSerialPort)
-    {
-        NOREF(aSerialPort);
-        return S_OK;
-    }
-
-    STDMETHOD(OnParallelPortChange) (IParallelPort *aParallelPort)
-    {
-        NOREF(aParallelPort);
-        return S_OK;
-    }
-
-    STDMETHOD(OnVRDPServerChange)()
-    {
-        return S_OK;
-    }
-
-    STDMETHOD(OnRemoteDisplayInfoChange)()
-    {
-        return S_OK;
-    }
-
-    STDMETHOD(OnUSBControllerChange)()
-    {
-        QApplication::postEvent (mView, new USBControllerStateChangeEvent());
-        return S_OK;
-    }
-
-    STDMETHOD(OnUSBDeviceStateChange)(IUSBDevice *aDevice, BOOL aAttached, IVirtualBoxErrorInfo *aError)
-    {
-        QApplication::postEvent (mView, new USBDeviceStateChangeEvent(CUSBDevice(aDevice), bool(aAttached), CVirtualBoxErrorInfo(aError)));
-        return S_OK;
-    }
-
-    STDMETHOD(OnSharedFolderChange) (Scope_T aScope)
-    {
-        NOREF(aScope);
-        QApplication::postEvent (mView, new QEvent((QEvent::Type)VBoxDefs::SharedFolderChangeEventType));
-        return S_OK;
-    }
-
-    STDMETHOD(OnRuntimeError)(BOOL fatal, IN_BSTR id, IN_BSTR message)
-    {
-        QApplication::postEvent (mView, new RuntimeErrorEvent(!!fatal, QString::fromUtf16(id), QString::fromUtf16(message)));
-        return S_OK;
-    }
-
-    STDMETHOD(OnCanShowWindow) (BOOL *canShow)
-    {
-        if (!canShow)
-            return E_POINTER;
-
-        *canShow = TRUE;
-        return S_OK;
-    }
-
-    STDMETHOD(OnShowWindow) (ULONG64 *winId)
-    {
-        if (!winId)
-            return E_POINTER;
-
-#if defined (Q_WS_MAC)
-        /*
-         * Let's try the simple approach first - grab the focus.
-         * Getting a window out of the dock (minimized or whatever it's called)
-         * needs to be done on the GUI thread, so post it a note.
-         */
-        *winId = 0;
-        if (!mView)
-            return S_OK;
-
-        ProcessSerialNumber psn = { 0, kCurrentProcess };
-        OSErr rc = ::SetFrontProcess (&psn);
-        if (!rc)
-            QApplication::postEvent(mView, new QEvent((QEvent::Type)VBoxDefs::ShowWindowEventType));
-        else
-        {
-            /*
-             * It failed for some reason, send the other process our PSN so it can try.
-             * (This is just a precaution should Mac OS X start imposing the same sensible
-             * focus stealing restrictions that other window managers implement.)
-             */
-            AssertMsgFailed(("SetFrontProcess -> %#x\n", rc));
-            if (::GetCurrentProcess (&psn))
-                *winId = RT_MAKE_U64(psn.lowLongOfPSN, psn.highLongOfPSN);
-        }
-
-#else
-        /* Return the ID of the top-level console window. */
-        *winId = (ULONG64)mView->window()->winId();
-#endif
-
-        return S_OK;
-    }
-
-protected:
-
-    UIMachineView *mView;
-
-#if defined (Q_WS_WIN)
-private:
-    long mRefCnt;
-#endif
-};
-
-#if !defined (Q_WS_WIN)
-NS_DECL_CLASSINFO(UIConsoleCallback)
-NS_IMPL_THREADSAFE_ISUPPORTS1_CI(UIConsoleCallback, IConsoleCallback)
-#endif
 
 UIMachineView* UIMachineView::create(  UIMachineWindow *pMachineWindow
@@ -659,5 +247,5 @@
     /* Private members: */
     , m_pMachineWindow(pMachineWindow)
-    , m_console(pMachineWindow->machineLogic()->session().GetConsole())
+    , m_console(pMachineWindow->machineLogic()->uisession()->session().GetConsole())
     , m_globalSettings(vboxGlobal().settings())
     , m_iLastMouseWheelDelta(0)
@@ -861,9 +449,4 @@
     }
 
-    /* setup the callback */
-    mCallback = CConsoleCallback(new UIConsoleCallback(this));
-    m_console.RegisterCallback(mCallback);
-    AssertWrapperOk(m_console);
-
     QPalette palette(viewport()->palette());
     palette.setColor(viewport()->backgroundRole(), Qt::black);
@@ -942,6 +525,4 @@
         mFrameBuf = NULL;
     }
-
-    m_console.UnregisterCallback(mCallback);
 
 #if defined (Q_WS_MAC)
@@ -1224,110 +805,4 @@
             #endif
 
-            case VBoxDefs::MousePointerChangeEventType:
-            {
-                MousePointerChangeEvent *me = (MousePointerChangeEvent *) e;
-                /* change cursor shape only when mouse integration is
-                 * supported (change mouse shape type event may arrive after
-                 * mouse capability change that disables integration */
-                if (m_bIsMouseAbsolute)
-                    setPointerShape (me);
-                else
-                    /* Note: actually we should still remember the requested
-                     * cursor shape.  If we can't do that, at least remember
-                     * the requested visiblilty. */
-                    mHideHostPointer = !me->isVisible();
-                return true;
-            }
-            case VBoxDefs::MouseCapabilityEventType:
-            {
-                MouseCapabilityEvent *me = (MouseCapabilityEvent *) e;
-                if (m_bIsMouseAbsolute != me->supportsAbsolute())
-                {
-                    m_bIsMouseAbsolute = me->supportsAbsolute();
-                    /* correct the mouse capture state and reset the cursor
-                     * to the default shape if necessary */
-                    if (m_bIsMouseAbsolute)
-                    {
-                        CMouse mouse = m_console.GetMouse();
-                        mouse.PutMouseEventAbsolute (-1, -1, 0,
-                                                     0 /* Horizontal wheel */,
-                                                     0);
-                        captureMouse (false, false);
-                    }
-                    else
-                        viewport()->unsetCursor();
-                    emitMouseStateChanged();
-                    vboxProblem().remindAboutMouseIntegration (m_bIsMouseAbsolute);
-                }
-                if (me->needsHostCursor())
-                    setMouseIntegrationLocked (false);
-                else
-                    setMouseIntegrationLocked (true);
-                return true;
-            }
-
-            case VBoxDefs::ModifierKeyChangeEventType:
-            {
-                ModifierKeyChangeEvent *me = (ModifierKeyChangeEvent* )e;
-                if (me->numLock() != mNumLock)
-                    muNumLockAdaptionCnt = 2;
-                if (me->capsLock() != mCapsLock)
-                    muCapsLockAdaptionCnt = 2;
-                mNumLock    = me->numLock();
-                mCapsLock   = me->capsLock();
-                mScrollLock = me->scrollLock();
-                return true;
-            }
-
-            case VBoxDefs::MachineStateChangeEventType:
-            {
-                StateChangeEvent *me = (StateChangeEvent *) e;
-                LogFlowFunc (("MachineStateChangeEventType: state=%d\n",
-                               me->machineState()));
-                onStateChange (me->machineState());
-                emit machineStateChanged (me->machineState());
-                return true;
-            }
-
-            case VBoxDefs::AdditionsStateChangeEventType:
-            {
-                GuestAdditionsEvent *ge = (GuestAdditionsEvent *) e;
-                LogFlowFunc (("AdditionsStateChangeEventType\n"));
-
-                /* Always send a size hint if we are in fullscreen or seamless
-                 * when the graphics capability is enabled, in case the host
-                 * resolution has changed since the VM was last run. */
-#if 0
-                if (!mDoResize && !m_bIsGuestSupportsGraphics &&
-                    ge->supportsGraphics() &&
-                    (machineWindowWrapper()->isTrueSeamless() || machineWindowWrapper()->isTrueFullscreen()))
-                    mDoResize = true;
-#endif
-
-                m_bIsGuestSupportsGraphics = ge->supportsGraphics();
-
-                maybeRestrictMinimumSize();
-
-#if 0
-                /* This will only be acted upon if mDoResize is true. */
-                doResizeHint();
-#endif
-
-                emit additionsStateChanged (ge->additionVersion(),
-                                            ge->additionActive(),
-                                            ge->supportsSeamless(),
-                                            ge->supportsGraphics());
-                return true;
-            }
-
-            case VBoxDefs::MediaDriveChangeEventType:
-            {
-                MediaDriveChangeEvent *mce = (MediaDriveChangeEvent *) e;
-                LogFlowFunc (("MediaChangeEvent\n"));
-
-                emit mediaDriveChanged (mce->type());
-                return true;
-            }
-
             #if 0
             case VBoxDefs::ActivateMenuEventType:
@@ -1350,55 +825,4 @@
             }
             #endif
-
-            case VBoxDefs::NetworkAdapterChangeEventType:
-            {
-                /* no specific adapter information stored in this
-                 * event is currently used */
-                emit networkStateChange();
-                return true;
-            }
-
-            case VBoxDefs::USBCtlStateChangeEventType:
-            {
-                emit usbStateChange();
-                return true;
-            }
-
-            case VBoxDefs::USBDeviceStateChangeEventType:
-            {
-                USBDeviceStateChangeEvent *ue = (USBDeviceStateChangeEvent *)e;
-
-                bool success = ue->error().isNull();
-
-                if (!success)
-                {
-                    if (ue->attached())
-                        vboxProblem().cannotAttachUSBDevice (
-                            m_console,
-                            vboxGlobal().details (ue->device()), ue->error());
-                    else
-                        vboxProblem().cannotDetachUSBDevice (
-                            m_console,
-                            vboxGlobal().details (ue->device()), ue->error());
-                }
-
-                emit usbStateChange();
-
-                return true;
-            }
-
-            case VBoxDefs::SharedFolderChangeEventType:
-            {
-                emit sharedFoldersChanged();
-                return true;
-            }
-
-            case VBoxDefs::RuntimeErrorEventType:
-            {
-                RuntimeErrorEvent *ee = (RuntimeErrorEvent *) e;
-                vboxProblem().showRuntimeError (m_console, ee->fatal(),
-                                                ee->errorID(), ee->message());
-                return true;
-            }
 
             case QEvent::KeyPress:
@@ -3474,4 +2898,5 @@
 }
 
+#if 0
 void UIMachineView::setPointerShape(MousePointerChangeEvent *pEvent)
 {
@@ -3730,4 +3155,5 @@
     mHideHostPointer = !pEvent->isVisible();
 }
+#endif
 
 inline QRgb qRgbIntensity(QRgb rgb, int mul, int div)
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h	(revision 26656)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineView.h	(revision 26691)
@@ -28,5 +28,4 @@
 class UIMachineWindow;
 class VBoxGlobalSettings;
-class MousePointerChangeEvent;
 
 /* Global includes */
@@ -200,5 +199,5 @@
     void sendChangedKeyStates();
     void updateMouseClipping();
-    void setPointerShape(MousePointerChangeEvent *pEvent);
+    //void setPointerShape(MousePointerChangeEvent *pEvent);
 
     enum DesktopGeo { DesktopGeo_Invalid = 0, DesktopGeo_Fixed, DesktopGeo_Automatic, DesktopGeo_Any };
@@ -264,5 +263,4 @@
 
     UIFrameBuffer *mFrameBuf;
-    CConsoleCallback mCallback;
 
     QPixmap mPausedShot;
@@ -280,6 +278,4 @@
     bool mHideHostPointer;
     QCursor mLastCursor;
-
-    friend class UIConsoleCallback;
 };
 
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp	(revision 26656)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp	(revision 26691)
@@ -23,4 +23,5 @@
 /* Global includes */
 #include <QCloseEvent>
+#include <QTimer>
 
 /* Local includes */
@@ -29,4 +30,5 @@
 #include "VBoxCloseVMDlg.h"
 
+#include "UISession.h"
 #include "UIMachineLogic.h"
 #include "UIMachineWindow.h"
@@ -61,4 +63,22 @@
 }
 
+void UIMachineWindow::sltTryClose()
+{
+    /* First close any open modal & popup widgets.
+     * Use a single shot with timeout 0 to allow the widgets to cleany close and test then again.
+     * If all open widgets are closed destroy ourself: */
+    QWidget *widget = QApplication::activeModalWidget() ?
+                      QApplication::activeModalWidget() :
+                      QApplication::activePopupWidget() ?
+                      QApplication::activePopupWidget() : 0;
+    if (widget)
+    {
+        widget->close();
+        QTimer::singleShot(0, machineWindow(), SLOT(sltTryClose()));
+    }
+    else
+        machineWindow()->close();
+}
+
 UIMachineWindow::UIMachineWindow(UIMachineLogic *pMachineLogic)
     : m_pMachineLogic(pMachineLogic)
@@ -89,5 +109,5 @@
 void UIMachineWindow::updateAppearanceOf(int iElement)
 {
-    CMachine machine = machineLogic()->session().GetMachine();
+    CMachine machine = session().GetMachine();
 
     if (iElement & UIVisualElement_WindowCaption)
@@ -119,7 +139,12 @@
 #ifndef Q_WS_MAC
     /* Set the VM-specific application icon except Mac OS X: */
-    CMachine machine = machineLogic()->session().GetMachine();
-    machineWindow()->setWindowIcon(vboxGlobal().vmGuestOSTypeIcon(machine.GetOSTypeId()));
-#endif
+    machineWindow()->setWindowIcon(vboxGlobal().vmGuestOSTypeIcon(session().GetMachine().GetOSTypeId()));
+#endif
+}
+
+void UIMachineWindow::prepareConsoleConnections()
+{
+    QObject::connect(machineLogic()->uisession(), SIGNAL(sigStateChange(KMachineState)),
+                     machineWindow(), SLOT(sltMachineStateChanged(KMachineState)));
 }
 
@@ -130,6 +155,9 @@
     /* Default to true if it is an empty value */
     bool bIsDockIconEnabled = testStr.isEmpty() || testStr == "true";
-    machineView()->setDockIconEnabled(bIsDockIconEnabled);
-    machineView()->updateDockOverlay();
+    if (machineView())
+    {
+        machineView()->setDockIconEnabled(bIsDockIconEnabled);
+        machineView()->updateDockOverlay();
+    }
 #endif
 }
@@ -142,5 +170,5 @@
     static const char *pstrDiscardCurState = "discardCurState";
 
-    if (!machineView())
+    if (!machineWindow())
     {
         pEvent->accept();
@@ -174,5 +202,5 @@
             pEvent->ignore();
 
-            bool isACPIEnabled = machineLogic()->session().GetConsole().GetGuestEnteredACPIMode();
+            bool isACPIEnabled = session().GetConsole().GetGuestEnteredACPIMode();
 
             bool success = true;
@@ -185,5 +213,5 @@
                 /* Suspend the VM and ignore the close event if failed to do so.
                  * pause() will show the error message to the user. */
-                success = machineLogic()->pause(true);
+                success = machineLogic()->pause();
             }
 
@@ -192,5 +220,5 @@
                 success = false;
 
-                CMachine machine = machineLogic()->session().GetMachine();
+                CMachine machine = session().GetMachine();
                 VBoxCloseVMDlg dlg(machineWindow());
                 QString typeId = machine.GetOSTypeId();
@@ -243,5 +271,5 @@
                     //m_bNoAutoClose = true;
 
-                    CConsole console = machineLogic()->session().GetConsole();
+                    CConsole console = session().GetConsole();
 
                     if (dlg.mRbSave->isChecked())
@@ -264,5 +292,5 @@
                     {
                         /* Unpause the VM to let it grab the ACPI shutdown event */
-                        machineLogic()->pause(false);
+                        machineLogic()->unpause();
                         /* Prevent the subsequent unpause request */
                         wasPaused = true;
@@ -364,5 +392,5 @@
                     /* Restore the running state if needed */
                     if (!wasPaused && machineLogic()->machineState() == KMachineState_Paused)
-                        machineLogic()->pause(false);
+                        machineLogic()->unpause();
                 }
             }
@@ -393,2 +421,12 @@
     }
 }
+
+CSession UIMachineWindow::session()
+{
+    return m_pMachineLogic->uisession()->session();
+}
+
+void UIMachineWindow::sltMachineStateChanged(KMachineState /* machineState */)
+{
+    updateAppearanceOf(UIVisualElement_WindowCaption);
+}
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.h	(revision 26656)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.h	(revision 26691)
@@ -25,8 +25,10 @@
 
 /* Local includes */
+#include "COMDefs.h"
 #include "UIMachineDefs.h"
 
 /* Global forwards */
 class QWidget;
+class QCloseEvent;
 
 /* Local forwards */
@@ -43,5 +45,5 @@
 
     /* Abstract slot to close machine window: */
-    virtual void sltTryClose() = 0;
+    virtual void sltTryClose();
 
     /* Public getters: */
@@ -64,8 +66,10 @@
     /* Prepare helpers: */
     virtual void prepareWindowIcon();
+    virtual void prepareConsoleConnections();
     virtual void loadWindowSettings();
 
     /* Cleanup helpers: */
     //virtual void saveWindowSettings();
+    //virtual void cleanupConsoleConnections();
     //virtual void cleanupWindowIcon();
 
@@ -74,5 +78,9 @@
 
     /* Protected getters: */
+    CSession session();
     const QString& defaultWindowTitle() const { return m_strWindowTitlePrefix; }
+
+    /* Protected signals: */
+    void sltMachineStateChanged(KMachineState machineState);
 
     /* Protected variables: */
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp	(revision 26691)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.cpp	(revision 26691)
@@ -0,0 +1,796 @@
+/** @file
+ *
+ * VBox frontends: Qt GUI ("VirtualBox"):
+ * UISession stuff implementation
+ */
+
+/*
+ * Copyright (C) 2010 Sun Microsystems, Inc.
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
+ * Clara, CA 95054 USA or visit http://www.sun.com if you need
+ * additional information or have any questions.
+ */
+
+/* Global inclues */
+#include <QApplication>
+#include <QWidget>
+
+/* Local includes */
+#include "UISession.h"
+
+#include "UIMachine.h"
+#include "UIMachineLogic.h"
+#include "UIMachineWindow.h"
+
+/* Guest mouse pointer shape change event: */
+class UIMousePointerShapeChangeEvent : public QEvent
+{
+public:
+
+    UIMousePointerShapeChangeEvent(bool bIsVisible, bool bIsAlpha, uint uXHot, uint uYHot, uint uWidth, uint uHeight, const uchar *pShape)
+        : QEvent((QEvent::Type)UIConsoleEventType_MousePointerShapeChange)
+        , m_bIsVisible(bIsVisible), m_bIsAlpha(bIsAlpha), m_uXHot(uXHot), m_uYHot(uYHot), m_uWidth(uWidth), m_uHeight(uHeight), m_pData(0)
+    {
+        uint dataSize = ((((m_uWidth + 7) / 8 * m_uHeight) + 3) & ~3) + m_uWidth * 4 * m_uHeight;
+        if (pShape)
+        {
+            m_pData = new uchar[dataSize];
+            memcpy((void*)m_pData, (void*)pShape, dataSize);
+        }
+    }
+
+    virtual ~UIMousePointerShapeChangeEvent()
+    {
+        if (m_pData) delete[] m_pData;
+    }
+
+    bool isVisible() const { return m_bIsVisible; }
+    bool hasAlpha() const { return m_bIsAlpha; }
+    uint xHot() const { return m_uXHot; }
+    uint yHot() const { return m_uYHot; }
+    uint width() const { return m_uWidth; }
+    uint height() const { return m_uHeight; }
+    const uchar *shapeData() const { return m_pData; }
+
+private:
+
+    bool m_bIsVisible, m_bIsAlpha;
+    uint m_uXHot, m_uYHot, m_uWidth, m_uHeight;
+    const uchar *m_pData;
+};
+
+/* Guest mouse absolute positioning capability change event: */
+class UIMouseCapabilityChangeEvent : public QEvent
+{
+public:
+
+    UIMouseCapabilityChangeEvent(bool bSupportsAbsolute, bool bNeedsHostCursor)
+        : QEvent((QEvent::Type)UIConsoleEventType_MouseCapabilityChange)
+        , m_bSupportsAbsolute(bSupportsAbsolute), m_bNeedsHostCursor(bNeedsHostCursor) {}
+
+    bool supportsAbsolute() const { return m_bSupportsAbsolute; }
+    bool needsHostCursor() const { return m_bNeedsHostCursor; }
+
+private:
+
+    bool m_bSupportsAbsolute;
+    bool m_bNeedsHostCursor;
+};
+
+/* Keyboard LEDs change event: */
+class UIKeyboardLedsChangeEvent : public QEvent
+{
+public:
+
+    UIKeyboardLedsChangeEvent(bool bNumLock, bool bCapsLock, bool bScrollLock)
+        : QEvent((QEvent::Type)UIConsoleEventType_KeyboardLedsChange)
+        , m_bNumLock(bNumLock), m_bCapsLock(bCapsLock), m_bScrollLock(bScrollLock) {}
+
+    bool numLock() const { return m_bNumLock; }
+    bool capsLock() const { return m_bCapsLock; }
+    bool scrollLock() const { return m_bScrollLock; }
+
+private:
+
+    bool m_bNumLock;
+    bool m_bCapsLock;
+    bool m_bScrollLock;
+};
+
+/* Machine state change event: */
+class UIStateChangeEvent : public QEvent
+{
+public:
+
+    UIStateChangeEvent(KMachineState machineState)
+        : QEvent((QEvent::Type)UIConsoleEventType_StateChange)
+        , m_machineState(machineState) {}
+
+    KMachineState machineState() const { return m_machineState; }
+
+private:
+
+    KMachineState m_machineState;
+};
+
+/* Guest Additions state change event: */
+class UIAdditionsStateChangeEvent : public QEvent
+{
+public:
+
+    UIAdditionsStateChangeEvent()
+        : QEvent((QEvent::Type)UIConsoleEventType_AdditionsStateChange) {}
+};
+
+/* Network adapter change event: */
+class UINetworkAdapterChangeEvent : public QEvent
+{
+public:
+
+    UINetworkAdapterChangeEvent(const CNetworkAdapter &networkAdapter)
+        : QEvent((QEvent::Type)UIConsoleEventType_NetworkAdapterChange)
+        , m_networkAdapter(networkAdapter) {}
+
+    const CNetworkAdapter& networkAdapter() { return m_networkAdapter; }
+
+private:
+
+    const CNetworkAdapter &m_networkAdapter;
+};
+
+/* Serial port change event: */
+class UISerialPortChangeEvent : public QEvent
+{
+public:
+
+    UISerialPortChangeEvent(const CSerialPort &serialPort)
+        : QEvent((QEvent::Type)UIConsoleEventType_SerialPortChange)
+        , m_serialPort(serialPort) {}
+
+    const CSerialPort& serialPort() { return m_serialPort; }
+
+private:
+
+    const CSerialPort &m_serialPort;
+};
+
+/* Parallel port change event: */
+class UIParallelPortChangeEvent : public QEvent
+{
+public:
+
+    UIParallelPortChangeEvent(const CParallelPort &parallelPort)
+        : QEvent((QEvent::Type)UIConsoleEventType_ParallelPortChange)
+        , m_parallelPort(parallelPort) {}
+
+    const CParallelPort& parallelPort() { return m_parallelPort; }
+
+private:
+
+    const CParallelPort &m_parallelPort;
+};
+
+/* Storage controller change event: */
+class UIStorageControllerChangeEvent : public QEvent
+{
+public:
+
+    UIStorageControllerChangeEvent()
+        : QEvent((QEvent::Type)UIConsoleEventType_StorageControllerChange) {}
+};
+
+/* Storage medium change event: */
+class UIMediumChangeEvent : public QEvent
+{
+public:
+
+    UIMediumChangeEvent(const CMediumAttachment &mediumAttachment)
+        : QEvent((QEvent::Type)UIConsoleEventType_MediumChange)
+        , m_mediumAttachment(mediumAttachment) {}
+    const CMediumAttachment& mediumAttahment() { return m_mediumAttachment; }
+
+private:
+
+    const CMediumAttachment &m_mediumAttachment;
+};
+
+/* CPU change event: */
+class UICPUChangeEvent : public QEvent
+{
+public:
+
+    UICPUChangeEvent(ulong uCPU, bool bRemove)
+        : QEvent((QEvent::Type)UIConsoleEventType_CPUChange)
+        , m_uCPU(uCPU), m_bRemove(bRemove) {}
+
+    ulong cpu() const { return m_uCPU; }
+    bool remove() const { return m_bRemove; }
+
+private:
+
+    ulong m_uCPU;
+    bool m_bRemove;
+};
+
+/* VRDP server change event: */
+class UIVRDPServerChangeEvent : public QEvent
+{
+public:
+
+    UIVRDPServerChangeEvent()
+        : QEvent((QEvent::Type)UIConsoleEventType_VRDPServerChange) {}
+};
+
+/* Remote display info change event: */
+class UIRemoteDisplayInfoChangeEvent : public QEvent
+{
+public:
+
+    UIRemoteDisplayInfoChangeEvent()
+        : QEvent((QEvent::Type)UIConsoleEventType_RemoteDisplayInfoChange) {}
+};
+
+/* USB controller change event: */
+class UIUSBControllerChangeEvent : public QEvent
+{
+public:
+
+    UIUSBControllerChangeEvent()
+        : QEvent((QEvent::Type)UIConsoleEventType_USBControllerChange) {}
+};
+
+/* USB device state change event: */
+class UIUSBDeviceUIStateChangeEvent : public QEvent
+{
+public:
+
+    UIUSBDeviceUIStateChangeEvent(const CUSBDevice &device, bool bAttached, const CVirtualBoxErrorInfo &error)
+        : QEvent((QEvent::Type)UIConsoleEventType_USBDeviceStateChange)
+        , m_device(device), m_bAttached(bAttached), m_error(error) {}
+
+    const CUSBDevice& device() const { return m_device; }
+    bool attached() const { return m_bAttached; }
+    const CVirtualBoxErrorInfo& error() const { return m_error; }
+
+private:
+
+    const CUSBDevice &m_device;
+    bool m_bAttached;
+    const CVirtualBoxErrorInfo &m_error;
+};
+
+/* Shared folder change event: */
+class UISharedFolderChangeEvent : public QEvent
+{
+public:
+
+    UISharedFolderChangeEvent()
+        : QEvent((QEvent::Type)UIConsoleEventType_SharedFolderChange) {}
+};
+
+/* VM Runtime error event: */
+class UIRuntimeErrorEvent : public QEvent
+{
+public:
+
+    UIRuntimeErrorEvent(bool bFatal, const QString &strErrorID, const QString &strMessage)
+        : QEvent((QEvent::Type)UIConsoleEventType_RuntimeError)
+        , m_bFatal(bFatal), m_strErrorID(strErrorID), m_strMessage(strMessage) {}
+
+    bool fatal() const { return m_bFatal; }
+    QString errorID() const { return m_strErrorID; }
+    QString message() const { return m_strMessage; }
+
+private:
+
+    bool m_bFatal;
+    QString m_strErrorID;
+    QString m_strMessage;
+};
+
+/* Can show window event: */
+class UICanUIShowWindowEvent : public QEvent
+{
+public:
+
+    UICanUIShowWindowEvent()
+        : QEvent((QEvent::Type)UIConsoleEventType_CanShowWindow) {}
+};
+
+/* Show window event: */
+class UIShowWindowEvent : public QEvent
+{
+public:
+
+    UIShowWindowEvent()
+        : QEvent((QEvent::Type)UIConsoleEventType_ShowWindow) {}
+};
+
+class UIConsoleCallback : VBOX_SCRIPTABLE_IMPL(IConsoleCallback)
+{
+public:
+
+    UIConsoleCallback(UISession *pEventHandler)
+        : m_pEventHandler(pEventHandler)
+#if defined (Q_WS_WIN)
+        , m_iRefCount(0)
+#endif
+    {
+    }
+
+    virtual ~UIConsoleCallback()
+    {
+    }
+
+    NS_DECL_ISUPPORTS
+
+#if defined (Q_WS_WIN)
+    STDMETHOD_(ULONG, AddRef)()
+    {
+        return ::InterlockedIncrement(&m_iRefCount);
+    }
+    STDMETHOD_(ULONG, Release)()
+    {
+        long iCount = ::InterlockedDecrement(&m_iRefCount);
+        if (iCount == 0)
+            delete this;
+        return iCount;
+    }
+#endif
+
+    VBOX_SCRIPTABLE_DISPATCH_IMPL(IConsoleCallback)
+
+    STDMETHOD(OnMousePointerShapeChange)(BOOL bIsVisible, BOOL bAlpha, ULONG uXHot, ULONG uYHot, ULONG uWidth, ULONG uHeight, BYTE *pShape)
+    {
+        QApplication::postEvent(m_pEventHandler, new UIMousePointerShapeChangeEvent(bIsVisible, bAlpha, uXHot, uYHot, uWidth, uHeight, pShape));
+        return S_OK;
+    }
+
+    STDMETHOD(OnMouseCapabilityChange)(BOOL bSupportsAbsolute, BOOL bNeedHostCursor)
+    {
+        QApplication::postEvent(m_pEventHandler, new UIMouseCapabilityChangeEvent(bSupportsAbsolute, bNeedHostCursor));
+        return S_OK;
+    }
+
+    STDMETHOD(OnKeyboardLedsChange)(BOOL bNumLock, BOOL bCapsLock, BOOL bScrollLock)
+    {
+        QApplication::postEvent(m_pEventHandler, new UIKeyboardLedsChangeEvent(bNumLock, bCapsLock, bScrollLock));
+        return S_OK;
+    }
+
+    STDMETHOD(OnStateChange)(MachineState_T machineState)
+    {
+        QApplication::postEvent(m_pEventHandler, new UIStateChangeEvent((KMachineState)machineState));
+        return S_OK;
+    }
+
+    STDMETHOD(OnAdditionsStateChange)()
+    {
+        QApplication::postEvent(m_pEventHandler, new UIAdditionsStateChangeEvent);
+        return S_OK;
+    }
+
+    STDMETHOD(OnNetworkAdapterChange)(INetworkAdapter *pNetworkAdapter)
+    {
+        QApplication::postEvent(m_pEventHandler, new UINetworkAdapterChangeEvent(CNetworkAdapter(pNetworkAdapter)));
+        return S_OK;
+    }
+
+    STDMETHOD(OnSerialPortChange)(ISerialPort *pSerialPort)
+    {
+        QApplication::postEvent(m_pEventHandler, new UISerialPortChangeEvent(CSerialPort(pSerialPort)));
+        return S_OK;
+    }
+
+    STDMETHOD(OnParallelPortChange)(IParallelPort *pParallelPort)
+    {
+        QApplication::postEvent(m_pEventHandler, new UIParallelPortChangeEvent(CParallelPort(pParallelPort)));
+        return S_OK;
+    }
+
+    STDMETHOD(OnStorageControllerChange)()
+    {
+        QApplication::postEvent(m_pEventHandler, new UIStorageControllerChangeEvent);
+        return S_OK;
+    }
+
+    STDMETHOD(OnMediumChange)(IMediumAttachment *pMediumAttachment)
+    {
+        QApplication::postEvent(m_pEventHandler, new UIMediumChangeEvent(CMediumAttachment(pMediumAttachment)));
+        return S_OK;
+    }
+
+    STDMETHOD(OnCPUChange)(ULONG uCPU, BOOL bRemove)
+    {
+        QApplication::postEvent(m_pEventHandler, new UICPUChangeEvent(uCPU, bRemove));
+        return S_OK;
+    }
+
+    STDMETHOD(OnVRDPServerChange)()
+    {
+        QApplication::postEvent(m_pEventHandler, new UIVRDPServerChangeEvent);
+        return S_OK;
+    }
+
+    STDMETHOD(OnRemoteDisplayInfoChange)()
+    {
+        QApplication::postEvent(m_pEventHandler, new UIRemoteDisplayInfoChangeEvent);
+        return S_OK;
+    }
+
+    STDMETHOD(OnUSBControllerChange)()
+    {
+        QApplication::postEvent(m_pEventHandler, new UIUSBControllerChangeEvent);
+        return S_OK;
+    }
+
+    STDMETHOD(OnUSBDeviceStateChange)(IUSBDevice *pDevice, BOOL bAttached, IVirtualBoxErrorInfo *pError)
+    {
+        QApplication::postEvent(m_pEventHandler, new UIUSBDeviceUIStateChangeEvent(CUSBDevice(pDevice), bAttached, CVirtualBoxErrorInfo(pError)));
+        return S_OK;
+    }
+
+    STDMETHOD(OnSharedFolderChange)(Scope_T scope)
+    {
+        NOREF(scope);
+        QApplication::postEvent(m_pEventHandler, new UISharedFolderChangeEvent);
+        return S_OK;
+    }
+
+    STDMETHOD(OnRuntimeError)(BOOL bFatal, IN_BSTR strId, IN_BSTR strMessage)
+    {
+        QApplication::postEvent(m_pEventHandler, new UIRuntimeErrorEvent(bFatal, QString::fromUtf16(strId), QString::fromUtf16(strMessage)));
+        return S_OK;
+    }
+
+    STDMETHOD(OnCanShowWindow)(BOOL *pbCanShow)
+    {
+        if (!pbCanShow)
+            return E_POINTER;
+
+        *pbCanShow = TRUE;
+        return S_OK;
+    }
+
+    STDMETHOD(OnShowWindow)(ULONG64 *puWinId)
+    {
+        if (!puWinId)
+            return E_POINTER;
+
+#if defined (Q_WS_MAC)
+        /* Let's try the simple approach first - grab the focus.
+         * Getting a window out of the dock (minimized or whatever it's called)
+         * needs to be done on the GUI thread, so post it a note: */
+        *puWinId = 0;
+        if (!m_pEventHandler)
+            return S_OK;
+
+        ProcessSerialNumber psn = { 0, kCurrentProcess };
+        OSErr rc = ::SetFrontProcess(&psn);
+        if (!rc)
+            QApplication::postEvent(m_pEventHandler, new UIShowWindowEvent);
+        else
+        {
+            /* It failed for some reason, send the other process our PSN so it can try.
+             * (This is just a precaution should Mac OS X start imposing the same sensible
+             * focus stealing restrictions that other window managers implement). */
+            AssertMsgFailed(("SetFrontProcess -> %#x\n", rc));
+            if (::GetCurrentProcess(&psn))
+                *puWinId = RT_MAKE_U64(psn.lowLongOfPSN, psn.highLongOfPSN);
+        }
+#else
+        /* Return the ID of the top-level console window. */
+        *puWinId = m_pEventHandler->winId();
+#endif
+
+        return S_OK;
+    }
+
+private:
+
+    UISession *m_pEventHandler;
+
+#if defined (Q_WS_WIN)
+    long m_iRefCount;
+#endif
+};
+
+#if !defined (Q_WS_WIN)
+NS_DECL_CLASSINFO(UIConsoleCallback)
+NS_IMPL_THREADSAFE_ISUPPORTS1_CI(UIConsoleCallback, IConsoleCallback)
+#endif
+
+UISession::UISession(UIMachine *pMachine, const CSession &session)
+    : QObject(pMachine)
+    , m_pMachine(pMachine)
+    , m_session(session)
+    , m_pCallback(new UIConsoleCallback(this))
+    , m_callback(CConsoleCallback(m_pCallback))
+{
+    /* Check CSession object */
+    AssertMsg(!m_session.isNull(), ("CSession is not set!\n"));
+
+    /* Register console callback: */
+    m_session.GetConsole().RegisterCallback(m_callback);
+}
+
+UISession::~UISession()
+{
+    /* Unregister console callback: */
+    m_session.GetConsole().UnregisterCallback(m_callback);
+    delete m_pCallback;
+    m_pCallback = 0;
+}
+
+bool UISession::event(QEvent *pEvent)
+{
+    switch (pEvent->type())
+    {
+        case UIConsoleEventType_MousePointerShapeChange:
+        {
+#if 0 // TODO: Move to machine view!
+            MousePointerChangeEvent *me = (MousePointerChangeEvent*)pEvent;
+            /* Change cursor shape only when mouse integration is
+             * supported (change mouse shape type event may arrive after
+             * mouse capability change that disables integration. */
+            if (m_bIsMouseAbsolute)
+                setPointerShape (me);
+            else
+                /* Note: actually we should still remember the requested
+                 * cursor shape.  If we can't do that, at least remember
+                 * the requested visiblilty. */
+                mHideHostPointer = !me->isVisible();
+#endif
+            UIMousePointerShapeChangeEvent *pConsoleEvent = static_cast<UIMousePointerShapeChangeEvent*>(pEvent);
+            emit sigMousePointerShapeChange(pConsoleEvent->isVisible(), pConsoleEvent->hasAlpha(),
+                                            pConsoleEvent->xHot(), pConsoleEvent->yHot(),
+                                            pConsoleEvent->width(), pConsoleEvent->height(),
+                                            pConsoleEvent->shapeData());
+            return true;
+        }
+
+        case UIConsoleEventType_MouseCapabilityChange:
+        {
+#if 0 // TODO: Move to machine view!
+            MouseCapabilityEvent *me = (MouseCapabilityEvent*)pEvent;
+            if (m_bIsMouseAbsolute != me->supportsAbsolute())
+            {
+                m_bIsMouseAbsolute = me->supportsAbsolute();
+                /* correct the mouse capture state and reset the cursor
+                 * to the default shape if necessary */
+                if (m_bIsMouseAbsolute)
+                {
+                    CMouse mouse = m_console.GetMouse();
+                    mouse.PutMouseEventAbsolute (-1, -1, 0,
+                                                 0 /* Horizontal wheel */,
+                                                 0);
+                    captureMouse (false, false);
+                }
+                else
+                    viewport()->unsetCursor();
+                emitMouseStateChanged();
+                vboxProblem().remindAboutMouseIntegration (m_bIsMouseAbsolute);
+            }
+            if (me->needsHostCursor())
+                setMouseIntegrationLocked (false);
+            else
+                setMouseIntegrationLocked (true);
+            return true;
+#endif
+            UIMouseCapabilityChangeEvent *pConsoleEvent = static_cast<UIMouseCapabilityChangeEvent*>(pEvent);
+            emit sigMouseCapabilityChange(pConsoleEvent->supportsAbsolute(), pConsoleEvent->needsHostCursor());
+            return true;
+        }
+
+        case UIConsoleEventType_KeyboardLedsChange:
+        {
+#if 0 // TODO: Move to machine view!
+            ModifierKeyChangeEvent *me = (ModifierKeyChangeEvent* )pEvent;
+            if (me->numLock() != mNumLock)
+                muNumLockAdaptionCnt = 2;
+            if (me->capsLock() != mCapsLock)
+                muCapsLockAdaptionCnt = 2;
+            mNumLock    = me->numLock();
+            mCapsLock   = me->capsLock();
+            mScrollLock = me->scrollLock();
+#endif
+            UIKeyboardLedsChangeEvent *pConsoleEvent = static_cast<UIKeyboardLedsChangeEvent*>(pEvent);
+            emit sigKeyboardLedsChange(pConsoleEvent->numLock(), pConsoleEvent->capsLock(), pConsoleEvent->scrollLock());
+            return true;
+        }
+
+        case UIConsoleEventType_StateChange:
+        {
+#if 0 // TODO: Move to machine view!
+            MachineUIStateChangeEvent *me = (MachineUIStateChangeEvent *) pEvent;
+            LogFlowFunc (("MachineUIStateChangeEventType: state=%d\n",
+                           me->machineState()));
+            onStateChange (me->machineState());
+            emit machineStateChanged (me->machineState());
+#endif
+            UIStateChangeEvent *pConsoleEvent = static_cast<UIStateChangeEvent*>(pEvent);
+            emit sigStateChange(pConsoleEvent->machineState());
+            return true;
+        }
+
+        case UIConsoleEventType_AdditionsStateChange:
+        {
+#if 0 // TODO: Move to machine view!
+            GuestAdditionsChangeEvent *ge = (GuestAdditionsChangeEvent *) pEvent;
+            LogFlowFunc (("UIAdditionsStateChangeEventType\n"));
+            /* Always send a size hint if we are in fullscreen or seamless
+             * when the graphics capability is enabled, in case the host
+             * resolution has changed since the VM was last run. */
+#if 0
+            if (!mDoResize && !m_bIsGuestSupportsGraphics &&
+                ge->supportsGraphics() &&
+                (machineWindowWrapper()->isTrueSeamless() || machineWindowWrapper()->isTrueFullscreen()))
+                mDoResize = true;
+#endif
+            m_bIsGuestSupportsGraphics = ge->supportsGraphics();
+
+            maybeRestrictMinimumSize();
+
+#if 0
+            /* This will only be acted upon if mDoResize is true. */
+            doResizeHint();
+#endif
+
+            emit additionsStateChanged (ge->additionVersion(),
+                                        ge->additionActive(),
+                                        ge->supportsSeamless(),
+                                        ge->supportsGraphics());
+#endif
+            emit sigAdditionsStateChange();
+            return true;
+        }
+
+        case UIConsoleEventType_NetworkAdapterChange:
+        {
+#if 0 // TODO: Move to machine view!
+            /* no specific adapter information stored in this
+             * event is currently used */
+            emit networkStateChange();
+#endif
+            UINetworkAdapterChangeEvent *pConsoleEvent = static_cast<UINetworkAdapterChangeEvent*>(pEvent);
+            emit sigNetworkAdapterChange(pConsoleEvent->networkAdapter());
+            return true;
+        }
+
+        case UIConsoleEventType_SerialPortChange:
+        {
+            UISerialPortChangeEvent *pConsoleEvent = static_cast<UISerialPortChangeEvent*>(pEvent);
+            emit sigSerialPortChange(pConsoleEvent->serialPort());
+            return true;
+        }
+
+        case UIConsoleEventType_ParallelPortChange:
+        {
+            UIParallelPortChangeEvent *pConsoleEvent = static_cast<UIParallelPortChangeEvent*>(pEvent);
+            emit sigParallelPortChange(pConsoleEvent->parallelPort());
+            return true;
+        }
+
+        case UIConsoleEventType_StorageControllerChange:
+        {
+            emit sigStorageControllerChange();
+            return true;
+        }
+
+        case UIConsoleEventType_MediumChange:
+        {
+#if 0 // TODO: Move to machine view!
+            MediaDriveChangeEvent *mce = (MediaDriveChangeEvent *) pEvent;
+            LogFlowFunc (("MediaChangeEvent\n"));
+
+            emit mediaDriveChanged (mce->type());
+#endif
+            UIMediumChangeEvent *pConsoleEvent = static_cast<UIMediumChangeEvent*>(pEvent);
+            emit sigMediumChange(pConsoleEvent->mediumAttahment());
+            return true;
+        }
+
+        case UIConsoleEventType_CPUChange:
+        {
+            UICPUChangeEvent *pConsoleEvent = static_cast<UICPUChangeEvent*>(pEvent);
+            emit sigCPUChange(pConsoleEvent->cpu(), pConsoleEvent->remove());
+            return true;
+        }
+
+        case UIConsoleEventType_VRDPServerChange:
+        {
+            emit sigVRDPServerChange();
+            return true;
+        }
+
+        case UIConsoleEventType_RemoteDisplayInfoChange:
+        {
+            emit sigRemoteDisplayInfoChange();
+            return true;
+        }
+
+        case UIConsoleEventType_USBControllerChange:
+        {
+            emit sigUSBControllerChange();
+            return true;
+        }
+
+        case UIConsoleEventType_USBDeviceStateChange:
+        {
+#if 0 // TODO: Move to machine view!
+            UIUSBDeviceUIStateChangeEvent *ue = (UIUSBDeviceUIStateChangeEvent *)pEvent;
+
+            bool success = ue->error().isNull();
+
+            if (!success)
+            {
+                if (ue->attached())
+                    vboxProblem().cannotAttachUSBDevice (
+                        m_console,
+                        vboxGlobal().details (ue->device()), ue->error());
+                else
+                    vboxProblem().cannotDetachUSBDevice (
+                        m_console,
+                        vboxGlobal().details (ue->device()), ue->error());
+            }
+
+            emit usbStateChange();
+#endif
+            UIUSBDeviceUIStateChangeEvent *pConsoleEvent = static_cast<UIUSBDeviceUIStateChangeEvent*>(pEvent);
+            emit sigUSBDeviceStateChange(pConsoleEvent->device(), pConsoleEvent->attached(), pConsoleEvent->error());
+            return true;
+        }
+
+        case UIConsoleEventType_SharedFolderChange:
+        {
+            emit sigSharedFolderChange();
+            return true;
+        }
+
+        case UIConsoleEventType_RuntimeError:
+        {
+#if 0 // TODO: Move to machine view!
+            UIRuntimeErrorEvent *pConsoleEvent = (UIRuntimeErrorEvent *) pEvent;
+            vboxProblem().showRuntimeError(m_console, ee->fatal(), ee->errorID(), ee->message());
+#endif
+            UIRuntimeErrorEvent *pConsoleEvent = static_cast<UIRuntimeErrorEvent*>(pEvent);
+            emit sigRuntimeError(pConsoleEvent->fatal(), pConsoleEvent->errorID(), pConsoleEvent->message());
+            return true;
+        }
+
+#ifdef Q_WS_MAC
+        /* posted OnShowWindow */
+        case UIConsoleEventType_ShowWindow:
+        {
+            /* Dunno what Qt3 thinks a window that has minimized to the dock
+             * should be - it is not hidden, neither is it minimized. OTOH it is
+             * marked shown and visible, but not activated. This latter isn't of
+             * much help though, since at this point nothing is marked activated.
+             * I might have overlooked something, but I'm buggered what if I know
+             * what. So, I'll just always show & activate the stupid window to
+             * make it get out of the dock when the user wishes to show a VM. */
+            window()->show();
+            window()->activateWindow();
+            return true;
+        }
+#endif
+
+        default:
+            break;
+    }
+    return QObject::event(pEvent);
+}
+
+qulonglong UISession::winId() const
+{
+    return machine()->machineLogic()->machineWindowWrapper()->machineWindow()->winId();
+}
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h	(revision 26691)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UISession.h	(revision 26691)
@@ -0,0 +1,116 @@
+/** @file
+ *
+ * VBox frontends: Qt GUI ("VirtualBox"):
+ * UISession class declaration
+ */
+
+/*
+ * Copyright (C) 2010 Sun Microsystems, Inc.
+ *
+ * This file is part of VirtualBox Open Source Edition (OSE), as
+ * available from http://www.virtualbox.org. This file is free software;
+ * you can redistribute it and/or modify it under the terms of the GNU
+ * General Public License (GPL) as published by the Free Software
+ * Foundation, in version 2 as it comes in the "COPYING" file of the
+ * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
+ * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
+ * Clara, CA 95054 USA or visit http://www.sun.com if you need
+ * additional information or have any questions.
+ */
+
+#ifndef ___UIConsole_h___
+#define ___UIConsole_h___
+
+/* Global includes */
+#include <QObject>
+
+/* Local includes */
+#include "COMDefs.h"
+
+/* Local forwards */
+class UIMachine;
+class UIConsoleCallback;
+
+/* CConsole callback event types: */
+enum UIConsoleEventType
+{
+    UIConsoleEventType_MousePointerShapeChange = QEvent::User + 1,
+    UIConsoleEventType_MouseCapabilityChange,
+    UIConsoleEventType_KeyboardLedsChange,
+    UIConsoleEventType_StateChange,
+    UIConsoleEventType_AdditionsStateChange,
+    UIConsoleEventType_NetworkAdapterChange,
+    UIConsoleEventType_SerialPortChange,
+    UIConsoleEventType_ParallelPortChange,
+    UIConsoleEventType_StorageControllerChange,
+    UIConsoleEventType_MediumChange,
+    UIConsoleEventType_CPUChange,
+    UIConsoleEventType_VRDPServerChange,
+    UIConsoleEventType_RemoteDisplayInfoChange,
+    UIConsoleEventType_USBControllerChange,
+    UIConsoleEventType_USBDeviceStateChange,
+    UIConsoleEventType_SharedFolderChange,
+    UIConsoleEventType_RuntimeError,
+    UIConsoleEventType_CanShowWindow,
+    UIConsoleEventType_ShowWindow,
+    UIConsoleEventType_MAX
+};
+
+class UISession : public QObject
+{
+    Q_OBJECT;
+
+public:
+
+    /* Machine session constructor/destructor: */
+    UISession(UIMachine *pMachine, const CSession &session);
+    virtual ~UISession();
+
+    /* Public getters: */
+    CSession& session() { return m_session; }
+
+signals:
+
+    /* Console signals: */
+    void sigMousePointerShapeChange(bool bIsVisible, bool bHasAlpha, bool uXHot, bool uYHot, bool uWidth, bool uHeight, const uchar *pShapeData);
+    void sigMouseCapabilityChange(bool bIsSupportsAbsolute, bool bNeedsHostCursor);
+    void sigKeyboardLedsChange(bool bNumLock, bool bCapsLock, bool bScrollLock);
+    void sigStateChange(KMachineState machineState);
+    void sigAdditionsStateChange();
+    void sigNetworkAdapterChange(const CNetworkAdapter &networkAdapter);
+    void sigSerialPortChange(const CSerialPort &serialPort);
+    void sigParallelPortChange(const CParallelPort &parallelPort);
+    void sigStorageControllerChange();
+    void sigMediumChange(const CMediumAttachment &mediumAttachment);
+    void sigCPUChange(ulong uCPU, bool bRemove);
+    void sigVRDPServerChange();
+    void sigRemoteDisplayInfoChange();
+    void sigUSBControllerChange();
+    void sigUSBDeviceStateChange(const CUSBDevice &device, bool bIsAttached, const CVirtualBoxErrorInfo &error);
+    void sigSharedFolderChange();
+    void sigRuntimeError(bool bIsFatal, QString strErrorId, QString strMessage);
+
+private:
+
+    /* Private getters: */
+    UIMachine* machine() const { return m_pMachine; }
+
+    /* Event handlers: */
+    bool event(QEvent *pEvent);
+
+    /* Helper routines: */
+    qulonglong winId() const;
+
+    /* Private variables: */
+    UIMachine *m_pMachine;
+    CSession m_session;
+    UIConsoleCallback *m_pCallback;
+    const CConsoleCallback &m_callback;
+
+    /* Friend classes: */
+    friend class UIConsoleCallback;
+};
+
+#endif // !___UIConsole_h___
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp	(revision 26656)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp	(revision 26691)
@@ -31,4 +31,5 @@
 #include "UIFirstRunWzd.h"
 
+#include "UISession.h"
 #include "UIActionsPool.h"
 #include "UIMachineLogicNormal.h"
@@ -36,7 +37,10 @@
 #include "UIMachineView.h"
 
-UIMachineLogicNormal::UIMachineLogicNormal(QObject *pParent, const CSession &session, UIActionsPool *pActionsPool)
-    : UIMachineLogic(pParent, session, pActionsPool, UIVisualStateType_Normal)
-{
+UIMachineLogicNormal::UIMachineLogicNormal(QObject *pParent, UISession *pSession, UIActionsPool *pActionsPool)
+    : UIMachineLogic(pParent, pSession, pActionsPool, UIVisualStateType_Normal)
+{
+    /* Prepare console connections: */
+    prepareConsoleConnections();
+
     /* Prepare action groups: */
     prepareActionGroups();
@@ -53,7 +57,4 @@
     /* Load common logic settings: */
     loadLogicSettings();
-
-    /* Update all the elements: */
-    updateAppearanceOf(UIVisualElement_AllStuff);
 }
 
@@ -83,8 +84,10 @@
 }
 
-void UIMachineLogicNormal::updateAppearanceOf(int iElement)
-{
-    /* Update parent-class elements: */
-    UIMachineLogic::updateAppearanceOf(iElement);
+void UIMachineLogicNormal::sltPrepareMouseIntegrationMenu()
+{
+    QMenu *menu = qobject_cast<QMenu*>(sender());
+    AssertMsg(menu, ("This slot should be called only on Mouse Integration Menu show!\n"));
+    menu->clear();
+    menu->addAction(actionsPool()->action(UIActionIndex_Toggle_MouseIntegration));
 }
 
@@ -99,4 +102,6 @@
     connect(actionsPool()->action(UIActionIndex_Menu_SharedFolders)->menu(), SIGNAL(aboutToShow()),
             this, SLOT(sltPrepareSharedFoldersMenu()));
+    connect(actionsPool()->action(UIActionIndex_Menu_MouseIntegration)->menu(), SIGNAL(aboutToShow()),
+            this, SLOT(sltPrepareMouseIntegrationMenu()));
 }
 
@@ -120,105 +125,109 @@
     setMachineState(session().GetConsole().GetState());
 
-    /* Notify user about mouse&keyboard auto-capturing: */
-    if (vboxGlobal().settings().autoCapture())
-        vboxProblem().remindAboutAutoCapture();
-
-    bool saved = machineState() == KMachineState_Saved;
-
-    CMachine machine = session().GetMachine();
-    CConsole console = session().GetConsole();
-
-    /* Shows first run wizard if necessary: */
-    if (isFirstTimeStarted())
+    bool bIsSaved = machineState() == KMachineState_Saved;
+    bool bIsRunning = machineState() == KMachineState_Running ||
+                      machineState() == KMachineState_Teleporting ||
+                      machineState() == KMachineState_LiveSnapshotting;
+    bool bIsRunningOrPaused = bIsRunning ||
+                              machineState() == KMachineState_Paused;
+
+    /* If we are not started yet: */
+    if (!bIsRunningOrPaused)
     {
-        UIFirstRunWzd wzd(machineWindowWrapper()->machineWindow(), machine);
-        wzd.exec();
-        machine.SetExtraData(VBoxDefs::GUI_FirstRun, QString());
-    }
-
-
-    // TODO: Do not start VM yet!
-    return;
-
-
-    /* Start VM: */
-    CProgress progress = vboxGlobal().isStartPausedEnabled() || vboxGlobal().isDebuggerAutoShowEnabled() ?
-                         console.PowerUpPaused() : console.PowerUp();
-    /* Check for an immediate failure */
-    if (!console.isOk())
-    {
-        vboxProblem().cannotStartMachine(console);
-        machineWindowWrapper()->machineWindow()->close();
-        return;
-    }
-
-    /* Disable auto closure because we want to have a chance to show the error dialog on startup failure: */
-    setPreventAutoClose(true);
-
-    /* Show "Starting/Restoring" progress dialog: */
-    if (saved)
-        vboxProblem().showModalProgressDialog(progress, machine.GetName(), machineWindowWrapper()->machineView(), 0);
-    else
-        vboxProblem().showModalProgressDialog(progress, machine.GetName(), machineWindowWrapper()->machineView());
-
-    /* Check for an progress failure */
-    if (progress.GetResultCode() != 0)
-    {
-        vboxProblem().cannotStartMachine(progress);
-        machineWindowWrapper()->machineWindow()->close();
-        return;
-    }
-
-    /* Enable auto closure again: */
-    setPreventAutoClose(false);
-
-    /* Check if we missed a really quick termination after successful startup, and process it if we did: */
-    if (machineState() == KMachineState_PoweredOff || machineState() == KMachineState_Saved ||
-        machineState() == KMachineState_Teleported || machineState() == KMachineState_Aborted)
-    {
-        machineWindowWrapper()->machineWindow()->close();
-        return;
-    }
+        /* Get current machine/console: */
+        CMachine machine = session().GetMachine();
+        CConsole console = session().GetConsole();
+
+        /* Notify user about mouse&keyboard auto-capturing: */
+        if (vboxGlobal().settings().autoCapture())
+            vboxProblem().remindAboutAutoCapture();
+
+        /* Shows first run wizard if necessary: */
+        if (isFirstTimeStarted())
+        {
+            UIFirstRunWzd wzd(machineWindowWrapper()->machineWindow(), machine);
+            wzd.exec();
+        }
+
+        /* Start VM: */
+        CProgress progress = vboxGlobal().isStartPausedEnabled() || vboxGlobal().isDebuggerAutoShowEnabled() ?
+                             console.PowerUpPaused() : console.PowerUp();
+        /* Check for an immediate failure */
+        if (!console.isOk())
+        {
+            vboxProblem().cannotStartMachine(console);
+            machineWindowWrapper()->machineWindow()->close();
+            return;
+        }
+
+        /* Disable auto closure because we want to have a chance to show the error dialog on startup failure: */
+        setPreventAutoClose(true);
+
+        /* Show "Starting/Restoring" progress dialog: */
+        if (bIsSaved)
+            vboxProblem().showModalProgressDialog(progress, machine.GetName(), machineWindowWrapper()->machineWindow(), 0);
+        else
+            vboxProblem().showModalProgressDialog(progress, machine.GetName(), machineWindowWrapper()->machineWindow());
+
+        /* Check for an progress failure */
+        if (progress.GetResultCode() != 0)
+        {
+            vboxProblem().cannotStartMachine(progress);
+            machineWindowWrapper()->machineWindow()->close();
+            return;
+        }
+
+        /* Process pending events: */
+        qApp->processEvents();
+
+        /* Enable auto closure again: */
+        setPreventAutoClose(false);
+
+        /* Check if we missed a really quick termination after successful startup, and process it if we did: */
+        if (machineState() == KMachineState_PoweredOff || machineState() == KMachineState_Saved ||
+            machineState() == KMachineState_Teleported || machineState() == KMachineState_Aborted)
+        {
+            machineWindowWrapper()->machineWindow()->close();
+            return;
+        }
 
 #if 0 // TODO: Rework debugger logic!
 # ifdef VBOX_WITH_DEBUGGER_GUI
-    /* Open the debugger in "full screen" mode requested by the user. */
-    else if (vboxGlobal().isDebuggerAutoShowEnabled())
-    {
-        /* console in upper left corner of the desktop. */
-        QRect rct (0, 0, 0, 0);
-        QDesktopWidget *desktop = QApplication::desktop();
-        if (desktop)
-            rct = desktop->availableGeometry(pos());
-        move (QPoint (rct.x(), rct.y()));
-
-        if (vboxGlobal().isDebuggerAutoShowStatisticsEnabled())
-            sltShowDebugStatistics();
-        if (vboxGlobal().isDebuggerAutoShowCommandLineEnabled())
-            sltShowDebugCommandLine();
-
-        if (!vboxGlobal().isStartPausedEnabled())
-            machineWindowWrapper()->machineView()->pause (false);
-    }
+        /* Open the debugger in "full screen" mode requested by the user. */
+        else if (vboxGlobal().isDebuggerAutoShowEnabled())
+        {
+            /* console in upper left corner of the desktop. */
+            QRect rct (0, 0, 0, 0);
+            QDesktopWidget *desktop = QApplication::desktop();
+            if (desktop)
+                rct = desktop->availableGeometry(pos());
+            move (QPoint (rct.x(), rct.y()));
+
+            if (vboxGlobal().isDebuggerAutoShowStatisticsEnabled())
+                sltShowDebugStatistics();
+            if (vboxGlobal().isDebuggerAutoShowCommandLineEnabled())
+                sltShowDebugCommandLine();
+
+            if (!vboxGlobal().isStartPausedEnabled())
+                machineWindowWrapper()->machineView()->pause (false);
+        }
 # endif
 #endif
 
-    setOpenViewFinished(true);
-
 #ifdef VBOX_WITH_UPDATE_REQUEST
-    /* Check for updates if necessary: */
-    vboxGlobal().showUpdateDialog(false /* aForce */);
+        /* Check for updates if necessary: */
+        vboxGlobal().showUpdateDialog(false /* aForce */);
 #endif
+    }
 
     /* Configure view connections: */
     if (machineWindowWrapper()->machineView())
     {
-        connect(machineWindowWrapper()->machineView(), SIGNAL(machineStateChanged(KMachineState)),
-                this, SLOT(sltUpdateMachineState(KMachineState)));
-        connect(machineWindowWrapper()->machineView(), SIGNAL(additionsStateChanged(const QString&, bool, bool, bool)),
-                this, SLOT(sltUpdateAdditionsState(const QString &, bool, bool, bool)));
         connect(machineWindowWrapper()->machineView(), SIGNAL(mouseStateChanged(int)),
-                this, SLOT(sltUpdateMouseState(int)));
+                this, SLOT(sltMouseStateChanged(int)));
     }
+
+    /* Set what view opened: */
+    setOpenViewFinished(true);
 }
 
@@ -232,8 +241,3 @@
     UIMachineWindow::destroy(m_pMachineWindowContainer);
     m_pMachineWindowContainer = 0;
-
-    // TODO: What should be done on window destruction?
-    //machineWindowWrapper()->machineView()->detach();
-    //m_session.Close();
-    //m_session.detach();
-}
+}
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.h	(revision 26656)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.h	(revision 26691)
@@ -36,21 +36,18 @@
 protected:
 
-    /* Normal machine logic constructor: */
+    /* Normal machine logic constructor/destructor: */
     UIMachineLogicNormal(QObject *pParent,
-                         const CSession &session,
+                         UISession *pSession,
                          UIActionsPool *pActionsPool);
-    /* Normal machine logic destructor: */
     virtual ~UIMachineLogicNormal();
 
 private slots:
 
-    /* Status-bar LED funtionality: */
+    /* Windowed mode funtionality: */
     void sltPrepareNetworkAdaptersMenu();
     void sltPrepareSharedFoldersMenu();
+    void sltPrepareMouseIntegrationMenu();
 
 private:
-
-    /* Update routines: */
-    void updateAppearanceOf(int);
 
     /* Prepare helpers: */
@@ -64,4 +61,5 @@
     //void cleanupActionConnections();
 
+    /* Friend classes: */
     friend class UIMachineLogic;
 };
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.cpp	(revision 26656)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineViewNormal.cpp	(revision 26691)
@@ -45,8 +45,4 @@
                    )
 {
-    /* Connect actions to view: */
-    connect(machineWindowWrapper()->machineLogic()->actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize),
-            SIGNAL(toggled(bool)), this, SLOT(sltToggleGuestAutoresize(bool)));
-
     /* Connect view to handlers */
     connect(this, SIGNAL(additionsStateChanged(const QString&, bool, bool, bool)),
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp	(revision 26656)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp	(revision 26691)
@@ -32,4 +32,5 @@
 #include "VBoxVMInformationDlg.h"
 
+#include "UISession.h"
 #include "UIActionsPool.h"
 #include "UIIndicatorsPool.h"
@@ -54,4 +55,7 @@
     prepareWindowIcon();
 
+    /* Prepare console connections: */
+    prepareConsoleConnections();
+
     /* Prepare menu: */
     prepareMenu();
@@ -90,20 +94,39 @@
 void UIMachineWindowNormal::sltTryClose()
 {
-    // TODO: Could be moved to parent class?
-
-    /* First close any open modal & popup widgets.
-     * Use a single shot with timeout 0 to allow the widgets to cleany close and test then again.
-     * If all open widgets are closed destroy ourself: */
-    QWidget *widget = QApplication::activeModalWidget() ?
-                      QApplication::activeModalWidget() :
-                      QApplication::activePopupWidget() ?
-                      QApplication::activePopupWidget() : 0;
-    if (widget)
-    {
-        widget->close();
-        QTimer::singleShot(0, this, SLOT(sltTryClose()));
-    }
-    else
-        close();
+    UIMachineWindow::sltTryClose();
+}
+
+void UIMachineWindowNormal::sltMachineStateChanged(KMachineState machineState)
+{
+    UIMachineWindow::sltMachineStateChanged(machineState);
+}
+
+void UIMachineWindowNormal::sltMediumChange(const CMediumAttachment &attachment)
+{
+    KDeviceType type = attachment.GetType();
+    Assert(type == KDeviceType_DVD || type == KDeviceType_Floppy);
+    updateAppearanceOf(type == KDeviceType_DVD ? UIVisualElement_CDStuff :
+                       type == KDeviceType_Floppy ? UIVisualElement_FDStuff :
+                       UIVisualElement_AllStuff);
+}
+
+void UIMachineWindowNormal::sltUSBControllerChange()
+{
+    updateAppearanceOf(UIVisualElement_USBStuff);
+}
+
+void UIMachineWindowNormal::sltUSBDeviceStateChange()
+{
+    updateAppearanceOf(UIVisualElement_USBStuff);
+}
+
+void UIMachineWindowNormal::sltNetworkAdapterChange()
+{
+    updateAppearanceOf(UIVisualElement_NetworkStuff);
+}
+
+void UIMachineWindowNormal::sltSharedFolderChange()
+{
+    updateAppearanceOf(UIVisualElement_SharedFolderStuff);
 }
 
@@ -132,6 +155,6 @@
     menu->addAction(machineLogic()->actionsPool()->action(UIActionIndex_Simple_InformationDialog));
     menu->addSeparator();
+    menu->addAction(machineLogic()->actionsPool()->action(UIActionIndex_Toggle_Pause));
     menu->addAction(machineLogic()->actionsPool()->action(UIActionIndex_Simple_Reset));
-    menu->addAction(machineLogic()->actionsPool()->action(UIActionIndex_Toggle_Pause));
     menu->addAction(machineLogic()->actionsPool()->action(UIActionIndex_Simple_Shutdown));
 #ifndef Q_WS_MAC
@@ -152,7 +175,7 @@
     menu->addMenu(machineLogic()->actionsPool()->action(UIActionIndex_Menu_OpticalDevices)->menu());
     menu->addMenu(machineLogic()->actionsPool()->action(UIActionIndex_Menu_FloppyDevices)->menu());
+    menu->addMenu(machineLogic()->actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu());
     menu->addAction(machineLogic()->actionsPool()->action(UIActionIndex_Simple_NetworkAdaptersDialog));
     menu->addAction(machineLogic()->actionsPool()->action(UIActionIndex_Simple_SharedFoldersDialog));
-    menu->addMenu(machineLogic()->actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu());
     menu->addSeparator();
     menu->addAction(machineLogic()->actionsPool()->action(UIActionIndex_Toggle_VRDP));
@@ -179,5 +202,5 @@
 void UIMachineWindowNormal::sltUpdateIndicators()
 {
-    CConsole console = machineLogic()->session().GetConsole();
+    CConsole console = session().GetConsole();
     QIStateIndicator *pStateIndicator = 0;
 
@@ -196,4 +219,11 @@
             pStateIndicator->setState(state);
     }
+    pStateIndicator = indicatorsPool()->indicator(UIIndicatorIndex_USBDevices);
+    if (pStateIndicator->state() != KDeviceActivity_Null)
+    {
+        int state = console.GetDeviceActivity(KDeviceType_USB);
+        if (pStateIndicator->state() != state)
+            pStateIndicator->setState(state);
+    }
     pStateIndicator = indicatorsPool()->indicator(UIIndicatorIndex_NetworkAdapters);
     if (pStateIndicator->state() != KDeviceActivity_Null)
@@ -203,11 +233,4 @@
             pStateIndicator->setState(state);
     }
-    pStateIndicator = indicatorsPool()->indicator(UIIndicatorIndex_USBDevices);
-    if (pStateIndicator->state() != KDeviceActivity_Null)
-    {
-        int state = console.GetDeviceActivity(KDeviceType_USB);
-        if (pStateIndicator->state() != state)
-            pStateIndicator->setState(state);
-    }
     pStateIndicator = indicatorsPool()->indicator(UIIndicatorIndex_SharedFolders);
     if (pStateIndicator->state() != KDeviceActivity_Null)
@@ -223,25 +246,25 @@
     if (pIndicator == indicatorsPool()->indicator(UIIndicatorIndex_OpticalDisks))
     {
-        if (machineLogic()->actionsPool()->action(UIActionIndex_Menu_OpticalDevices)->menu()->isEnabled())
+        if (machineLogic()->actionsPool()->action(UIActionIndex_Menu_OpticalDevices)->isEnabled())
             machineLogic()->actionsPool()->action(UIActionIndex_Menu_OpticalDevices)->menu()->exec(pEvent->globalPos());
     }
+    else if (pIndicator == indicatorsPool()->indicator(UIIndicatorIndex_USBDevices))
+    {
+        if (machineLogic()->actionsPool()->action(UIActionIndex_Menu_USBDevices)->isEnabled())
+            machineLogic()->actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu()->exec(pEvent->globalPos());
+    }
     else if (pIndicator == indicatorsPool()->indicator(UIIndicatorIndex_NetworkAdapters))
     {
-        if (machineLogic()->actionsPool()->action(UIActionIndex_Menu_NetworkAdapters)->menu()->isEnabled())
+        if (machineLogic()->actionsPool()->action(UIActionIndex_Menu_NetworkAdapters)->isEnabled())
             machineLogic()->actionsPool()->action(UIActionIndex_Menu_NetworkAdapters)->menu()->exec(pEvent->globalPos());
     }
-    else if (pIndicator == indicatorsPool()->indicator(UIIndicatorIndex_USBDevices))
-    {
-        if (machineLogic()->actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu()->isEnabled())
-            machineLogic()->actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu()->exec(pEvent->globalPos());
-    }
     else if (pIndicator == indicatorsPool()->indicator(UIIndicatorIndex_SharedFolders))
     {
-        if (machineLogic()->actionsPool()->action(UIActionIndex_Menu_SharedFolders)->menu()->isEnabled())
+        if (machineLogic()->actionsPool()->action(UIActionIndex_Menu_SharedFolders)->isEnabled())
             machineLogic()->actionsPool()->action(UIActionIndex_Menu_SharedFolders)->menu()->exec(pEvent->globalPos());
     }
     else if (pIndicator == indicatorsPool()->indicator(UIIndicatorIndex_Mouse))
     {
-        if (machineLogic()->actionsPool()->action(UIActionIndex_Menu_MouseIntegration)->menu()->isEnabled())
+        if (machineLogic()->actionsPool()->action(UIActionIndex_Menu_MouseIntegration)->isEnabled())
             machineLogic()->actionsPool()->action(UIActionIndex_Menu_MouseIntegration)->menu()->exec(pEvent->globalPos());
     }
@@ -251,27 +274,4 @@
 {
     m_pNameHostkey->setText(QIHotKeyEdit::keyName(vboxGlobal().settings().hostKey()));
-}
-
-void UIMachineWindowNormal::sltUpdateMediaDriveState(VBoxDefs::MediumType type)
-{
-    Assert(type == VBoxDefs::MediumType_DVD || type == VBoxDefs::MediumType_Floppy);
-    updateAppearanceOf(type == VBoxDefs::MediumType_DVD ? UIVisualElement_CDStuff :
-                       type == VBoxDefs::MediumType_Floppy ? UIVisualElement_FDStuff :
-                       UIVisualElement_AllStuff);
-}
-
-void UIMachineWindowNormal::sltUpdateNetworkAdaptersState()
-{
-    updateAppearanceOf(UIVisualElement_NetworkStuff);
-}
-
-void UIMachineWindowNormal::sltUpdateUsbState()
-{
-    updateAppearanceOf(UIVisualElement_USBStuff);
-}
-
-void UIMachineWindowNormal::sltUpdateSharedFoldersState()
-{
-    updateAppearanceOf(UIVisualElement_SharedFolderStuff);
 }
 
@@ -305,8 +305,6 @@
 
     /* Update that machine window: */
-    CMachine machine = machineLogic()->session().GetMachine();
-    CConsole console = machineLogic()->session().GetConsole();
-    bool bIsStrictRunningOrPaused = machineLogic()->machineState() == KMachineState_Running ||
-                                    machineLogic()->machineState() == KMachineState_Paused;
+    CMachine machine = session().GetMachine();
+    CConsole console = session().GetConsole();
 
     if (iElement & UIVisualElement_HDStuff)
@@ -376,37 +374,4 @@
         indicatorsPool()->indicator(UIIndicatorIndex_OpticalDisks)->setState(bAttachmentsPresent ? KDeviceActivity_Idle : KDeviceActivity_Null);
     }
-    if (iElement & UIVisualElement_NetworkStuff)
-    {
-        ulong uMaxCount = vboxGlobal().virtualBox().GetSystemProperties().GetNetworkAdapterCount();
-        ulong uCount = 0;
-        for (ulong uSlot = 0; uSlot < uMaxCount; ++ uSlot)
-            if (machine.GetNetworkAdapter(uSlot).GetEnabled())
-                ++ uCount;
-        indicatorsPool()->indicator(UIIndicatorIndex_NetworkAdapters)->setState(uCount > 0 ? KDeviceActivity_Idle : KDeviceActivity_Null);
-
-        machineLogic()->actionsPool()->action(UIActionIndex_Simple_NetworkAdaptersDialog)->setEnabled(bIsStrictRunningOrPaused && uCount > 0);
-        machineLogic()->actionsPool()->action(UIActionIndex_Menu_NetworkAdapters)->setEnabled(bIsStrictRunningOrPaused && uCount > 0);
-
-        QString strToolTip = tr("<p style='white-space:pre'><nobr>Indicates the activity of the "
-                                "network interfaces:</nobr>%1</p>", "Network adapters tooltip");
-        QString strFullData;
-
-        for (ulong uSlot = 0; uSlot < uMaxCount; ++ uSlot)
-        {
-            CNetworkAdapter adapter = machine.GetNetworkAdapter(uSlot);
-            if (adapter.GetEnabled())
-                strFullData += tr("<br><nobr><b>Adapter %1 (%2)</b>: cable %3</nobr>", "Network adapters tooltip")
-                    .arg(uSlot + 1)
-                    .arg(vboxGlobal().toString(adapter.GetAttachmentType()))
-                    .arg(adapter.GetCableConnected() ?
-                          tr("connected", "Network adapters tooltip") :
-                          tr("disconnected", "Network adapters tooltip"));
-        }
-
-        if (strFullData.isNull())
-            strFullData = tr("<br><nobr><b>All network adapters are disabled</b></nobr>", "Network adapters tooltip");
-
-        indicatorsPool()->indicator(UIIndicatorIndex_NetworkAdapters)->setToolTip(strToolTip.arg(strFullData));
-    }
     if (iElement & UIVisualElement_USBStuff)
     {
@@ -420,6 +385,4 @@
             if (!usbctl.isNull() && usbctl.GetEnabled())
             {
-                machineLogic()->actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu()->setEnabled(bIsStrictRunningOrPaused);
-
                 CUSBDeviceVector devsvec = console.GetUSBDevices();
                 for (int i = 0; i < devsvec.size(); ++ i)
@@ -433,5 +396,4 @@
             else
             {
-                machineLogic()->actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu()->setEnabled(false);
                 strFullData = tr("<br><nobr><b>USB Controller is disabled</b></nobr>", "USB device tooltip");
             }
@@ -440,13 +402,33 @@
         }
     }
-    if (iElement & UIVisualElement_VRDPStuff)
-    {
-        CVRDPServer vrdpsrv = machineLogic()->session().GetMachine().GetVRDPServer();
-        if (!vrdpsrv.isNull())
-        {
-            /* Update menu&status icon state */
-            bool isVRDPEnabled = vrdpsrv.GetEnabled();
-            machineLogic()->actionsPool()->action(UIActionIndex_Toggle_VRDP)->setChecked(isVRDPEnabled);
-        }
+    if (iElement & UIVisualElement_NetworkStuff)
+    {
+        ulong uMaxCount = vboxGlobal().virtualBox().GetSystemProperties().GetNetworkAdapterCount();
+        ulong uCount = 0;
+        for (ulong uSlot = 0; uSlot < uMaxCount; ++ uSlot)
+            if (machine.GetNetworkAdapter(uSlot).GetEnabled())
+                ++ uCount;
+        indicatorsPool()->indicator(UIIndicatorIndex_NetworkAdapters)->setState(uCount > 0 ? KDeviceActivity_Idle : KDeviceActivity_Null);
+
+        QString strToolTip = tr("<p style='white-space:pre'><nobr>Indicates the activity of the "
+                                "network interfaces:</nobr>%1</p>", "Network adapters tooltip");
+        QString strFullData;
+
+        for (ulong uSlot = 0; uSlot < uMaxCount; ++ uSlot)
+        {
+            CNetworkAdapter adapter = machine.GetNetworkAdapter(uSlot);
+            if (adapter.GetEnabled())
+                strFullData += tr("<br><nobr><b>Adapter %1 (%2)</b>: cable %3</nobr>", "Network adapters tooltip")
+                    .arg(uSlot + 1)
+                    .arg(vboxGlobal().toString(adapter.GetAttachmentType()))
+                    .arg(adapter.GetCableConnected() ?
+                          tr("connected", "Network adapters tooltip") :
+                          tr("disconnected", "Network adapters tooltip"));
+        }
+
+        if (strFullData.isNull())
+            strFullData = tr("<br><nobr><b>All network adapters are disabled</b></nobr>", "Network adapters tooltip");
+
+        indicatorsPool()->indicator(UIIndicatorIndex_NetworkAdapters)->setToolTip(strToolTip.arg(strFullData));
     }
     if (iElement & UIVisualElement_SharedFolderStuff)
@@ -457,6 +439,4 @@
         QString strFullData;
         QMap<QString, QString> sfs;
-
-        machineLogic()->actionsPool()->action(UIActionIndex_Menu_SharedFolders)->menu()->setEnabled(true);
 
         /* Permanent folders */
@@ -493,4 +473,14 @@
 
         indicatorsPool()->indicator(UIIndicatorIndex_SharedFolders)->setToolTip(strToolTip.arg(strFullData));
+    }
+    if (iElement & UIVisualElement_VRDPStuff)
+    {
+        CVRDPServer vrdpsrv = session().GetMachine().GetVRDPServer();
+        if (!vrdpsrv.isNull())
+        {
+            /* Update menu&status icon state */
+            bool isVRDPEnabled = vrdpsrv.GetEnabled();
+            machineLogic()->actionsPool()->action(UIActionIndex_Toggle_VRDP)->setChecked(isVRDPEnabled);
+        }
     }
     if (iElement & UIVisualElement_VirtualizationStuff)
@@ -582,4 +572,21 @@
 #endif
 
+void UIMachineWindowNormal::prepareConsoleConnections()
+{
+    /* Parent class connections: */
+    UIMachineWindow::prepareConsoleConnections();
+    /* Other console connections: */
+    connect(machineLogic()->uisession(), SIGNAL(sigMediumChange(const CMediumAttachment &)),
+            this, SLOT(sltMediumChange(const CMediumAttachment &)));
+    connect(machineLogic()->uisession(), SIGNAL(sigUSBControllerChange()),
+            this, SLOT(sltUSBControllerChange()));
+    connect(machineLogic()->uisession(), SIGNAL(sigUSBDeviceStateChange(const CUSBDevice &, bool, const CVirtualBoxErrorInfo &)),
+            this, SLOT(sltUSBDeviceStateChange()));
+    connect(machineLogic()->uisession(), SIGNAL(sigNetworkAdapterChange(const CNetworkAdapter &)),
+            this, SLOT(sltNetworkAdapterChange()));
+    connect(machineLogic()->uisession(), SIGNAL(sigSharedFolderChange()),
+            this, SLOT(sltSharedFolderChange()));
+}
+
 void UIMachineWindowNormal::prepareMenu()
 {
@@ -622,14 +629,14 @@
             this, SLOT(sltShowIndicatorsContextMenu(QIStateIndicator*, QContextMenuEvent*)));
 
+    /* USB Devices: */
+    QIStateIndicator *pLedUSBDevices = indicatorsPool()->indicator(UIIndicatorIndex_USBDevices);
+    pIndicatorBoxHLayout->addWidget(pLedUSBDevices);
+    connect(pLedUSBDevices, SIGNAL(contextMenuRequested(QIStateIndicator*, QContextMenuEvent*)),
+            this, SLOT(sltShowIndicatorsContextMenu(QIStateIndicator*, QContextMenuEvent*)));
+
     /* Network Adapters: */
     QIStateIndicator *pLedNetworkAdapters = indicatorsPool()->indicator(UIIndicatorIndex_NetworkAdapters);
     pIndicatorBoxHLayout->addWidget(pLedNetworkAdapters);
     connect(pLedNetworkAdapters, SIGNAL(contextMenuRequested(QIStateIndicator*, QContextMenuEvent*)),
-            this, SLOT(sltShowIndicatorsContextMenu(QIStateIndicator*, QContextMenuEvent*)));
-
-    /* USB Devices: */
-    QIStateIndicator *pLedUSBDevices = indicatorsPool()->indicator(UIIndicatorIndex_USBDevices);
-    pIndicatorBoxHLayout->addWidget(pLedUSBDevices);
-    connect(pLedUSBDevices, SIGNAL(contextMenuRequested(QIStateIndicator*, QContextMenuEvent*)),
             this, SLOT(sltShowIndicatorsContextMenu(QIStateIndicator*, QContextMenuEvent*)));
 
@@ -689,5 +696,5 @@
     return; // TODO: Do not create view for now!
 
-    CMachine machine = machineLogic()->session().GetMachine();
+    CMachine machine = session().GetMachine();
 
 #ifdef VBOX_WITH_VIDEOHWACCEL
@@ -707,10 +714,4 @@
     connect(machineView(), SIGNAL(keyboardStateChanged(int)),
             indicatorsPool()->indicator(UIIndicatorIndex_Hostkey), SLOT(setState(int)));
-    // TODO: Update these 5 indicators through indicators pool!
-    connect(machineView(), SIGNAL(mediaDriveChanged(VBoxDefs::MediumType)),
-            this, SLOT(sltUpdateMediaDriveState(VBoxDefs::MediumType)));
-    connect(machineView(), SIGNAL(networkStateChange()), this, SLOT(sltUpdateNetworkAdaptersState()));
-    connect(machineView(), SIGNAL(usbStateChange()), this, SLOT(sltUpdateUsbState()));
-    connect(machineView(), SIGNAL(sharedFoldersChanged()), this, SLOT(sltUpdateSharedFoldersState()));
     connect(machineView(), SIGNAL(mouseStateChanged(int)), this, SLOT(sltUpdateMouseState(int)));
 }
@@ -722,5 +723,5 @@
 
     /* Load this class settings: */
-    CMachine machine = machineLogic()->session().GetMachine();
+    CMachine machine = session().GetMachine();
 
     /* Extra-data settings */
@@ -796,5 +797,5 @@
 void UIMachineWindowNormal::saveWindowSettings()
 {
-    CMachine machine = machineLogic()->session().GetMachine();
+    CMachine machine = session().GetMachine();
 
     /* Extra-data settings */
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.h	(revision 26656)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.h	(revision 26691)
@@ -53,4 +53,11 @@
     void sltTryClose();
 
+    void sltMachineStateChanged(KMachineState machineState);
+    void sltMediumChange(const CMediumAttachment &attachment);
+    void sltUSBControllerChange();
+    void sltUSBDeviceStateChange();
+    void sltNetworkAdapterChange();
+    void sltSharedFolderChange();
+
     void sltPrepareMenuMachine();
     void sltPrepareMenuDevices();
@@ -64,8 +71,4 @@
     void sltProcessGlobalSettingChange(const char *aPublicName, const char *aName);
 
-    void sltUpdateMediaDriveState(VBoxDefs::MediumType type);
-    void sltUpdateNetworkAdaptersState();
-    void sltUpdateUsbState();
-    void sltUpdateSharedFoldersState();
     void sltUpdateMouseState(int iState);
 
@@ -88,4 +91,5 @@
 
     /* Prepare helpers: */
+    void prepareConsoleConnections();
     void prepareMenu();
     void prepareStatusBar();
@@ -100,4 +104,5 @@
     void cleanupStatusBar();
     //void cleanupMenu();
+    void cleanupConsoleConnections();
 
     /* Indicators pool: */
