Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp	(revision 41063)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp	(revision 41064)
@@ -60,7 +60,12 @@
     ~UIVisualState()
     {
-        /* Delete machine logic if exists: */
+        /* Cleanup/delete machine logic if exists: */
         if (m_pMachineLogic)
+        {
+            /* Cleanup the logic object: */
+            m_pMachineLogic->cleanup();
+            /* Destroy the logic object: */
             UIMachineLogic::destroy(m_pMachineLogic);
+        }
     }
 
@@ -95,5 +100,9 @@
 
     /* Method to change one visual state to another: */
-    virtual void change() = 0;
+    virtual void change()
+    {
+        /* Prepare the logic object: */
+        m_pMachineLogic->prepare();
+    }
 
     /* Method to finish change one visual state to another: */
@@ -149,4 +158,7 @@
     void change()
     {
+        /* Call to base-class: */
+        UIVisualState::change();
+
         /* Connect action handlers: */
         connect(gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen), SIGNAL(triggered(bool)),
@@ -156,7 +168,4 @@
         connect(gActionPool->action(UIActionIndexRuntime_Toggle_Scale), SIGNAL(triggered(bool)),
                 this, SLOT(sltGoToScaleMode()), Qt::QueuedConnection);
-
-        /* Initialize the logic object: */
-        m_pMachineLogic->initialize();
     }
 };
@@ -213,4 +222,7 @@
     void change()
     {
+        /* Call to base-class: */
+        UIVisualState::change();
+
         /* Connect action handlers: */
         connect(gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen), SIGNAL(triggered(bool)),
@@ -220,7 +232,4 @@
         connect(gActionPool->action(UIActionIndexRuntime_Toggle_Scale), SIGNAL(triggered(bool)),
                 this, SLOT(sltGoToScaleMode()), Qt::QueuedConnection);
-
-        /* Initialize the logic object: */
-        m_pMachineLogic->initialize();
     }
 };
@@ -277,4 +286,7 @@
     void change()
     {
+        /* Call to base-class: */
+        UIVisualState::change();
+
         /* Connect action handlers: */
         connect(gActionPool->action(UIActionIndexRuntime_Toggle_Seamless), SIGNAL(triggered(bool)),
@@ -284,7 +296,4 @@
         connect(gActionPool->action(UIActionIndexRuntime_Toggle_Scale), SIGNAL(triggered(bool)),
                 this, SLOT(sltGoToScaleMode()), Qt::QueuedConnection);
-
-        /* Initialize the logic object: */
-        m_pMachineLogic->initialize();
     }
 };
@@ -341,4 +350,7 @@
     void change()
     {
+        /* Call to base-class: */
+        UIVisualState::change();
+
         /* Connect action handlers: */
         connect(gActionPool->action(UIActionIndexRuntime_Toggle_Scale), SIGNAL(triggered(bool)),
@@ -348,7 +360,4 @@
         connect(gActionPool->action(UIActionIndexRuntime_Toggle_Seamless), SIGNAL(triggered(bool)),
                 this, SLOT(sltGoToSeamlessMode()), Qt::QueuedConnection);
-
-        /* Initialize the logic object: */
-        m_pMachineLogic->initialize();
     }
 };
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp	(revision 41063)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp	(revision 41064)
@@ -110,21 +110,21 @@
                                        UIVisualStateType visualStateType)
 {
-    UIMachineLogic *logic = 0;
+    UIMachineLogic *pLogic = 0;
     switch (visualStateType)
     {
         case UIVisualStateType_Normal:
-            logic = new UIMachineLogicNormal(pParent, pSession);
+            pLogic = new UIMachineLogicNormal(pParent, pSession);
             break;
         case UIVisualStateType_Fullscreen:
-            logic = new UIMachineLogicFullscreen(pParent, pSession);
+            pLogic = new UIMachineLogicFullscreen(pParent, pSession);
             break;
         case UIVisualStateType_Seamless:
-            logic = new UIMachineLogicSeamless(pParent, pSession);
+            pLogic = new UIMachineLogicSeamless(pParent, pSession);
             break;
         case UIVisualStateType_Scale:
-            logic = new UIMachineLogicScale(pParent, pSession);
+            pLogic = new UIMachineLogicScale(pParent, pSession);
             break;
     }
-    return logic;
+    return pLogic;
 }
 
@@ -135,7 +135,72 @@
 }
 
-bool UIMachineLogic::checkAvailability()
-{
-    return true;
+void UIMachineLogic::prepare()
+{
+    /* Prepare required features: */
+    prepareRequiredFeatures();
+
+    /* Prepare session connections: */
+    prepareSessionConnections();
+
+    /* Prepare action groups:
+     * Note: This has to be done before prepareActionConnections
+     * cause here actions/menus are recreated. */
+    prepareActionGroups();
+    /* Prepare action connections: */
+    prepareActionConnections();
+
+    /* Prepare handlers: */
+    prepareHandlers();
+
+    /* Prepare machine window(s): */
+    prepareMachineWindows();
+
+#ifdef Q_WS_MAC
+    /* Prepare dock: */
+    prepareDock();
+#endif /* Q_WS_MAC */
+
+#ifdef VBOX_WITH_DEBUGGER_GUI
+    /* Prepare debugger: */
+    prepareDebugger();
+#endif /* VBOX_WITH_DEBUGGER_GUI */
+
+    /* Power up machine: */
+    uisession()->powerUp();
+
+    /* Initialization: */
+    sltMachineStateChanged();
+    sltAdditionsStateChanged();
+    sltMouseCapabilityChanged();
+
+    /* Retranslate logic part: */
+    retranslateUi();
+}
+
+void UIMachineLogic::cleanup()
+{
+#ifdef VBOX_WITH_DEBUGGER_GUI
+    /* Cleanup debugger: */
+    cleanupDebugger();
+#endif /* VBOX_WITH_DEBUGGER_GUI */
+
+#ifdef Q_WS_MAC
+    /* Cleanup dock: */
+    cleanupDock();
+#endif /* Q_WS_MAC */
+
+    /* Cleanup machine window(s): */
+    cleanupMachineWindows();
+
+    /* Cleanup handlers: */
+    cleanupHandlers();
+
+    /* Cleanup action groups: */
+    cleanupActionGroups();
+}
+
+CSession& UIMachineLogic::session() const
+{
+    return uisession()->session();
 }
 
@@ -146,4 +211,5 @@
         return 0;
 
+    /* Otherwise return first of windows: */
     return machineWindows()[0];
 }
@@ -208,7 +274,156 @@
 #endif /* Q_WS_MAC */
 
-UIMachineLogic::UIMachineLogic(QObject *pParent,
-                               UISession *pSession,
-                               UIVisualStateType visualStateType)
+void UIMachineLogic::sltMachineStateChanged()
+{
+    /* Get machine state: */
+    KMachineState state = uisession()->machineState();
+
+    /* Update action groups: */
+    m_pRunningActions->setEnabled(uisession()->isRunning());
+    m_pRunningOrPausedActions->setEnabled(uisession()->isRunning() || uisession()->isPaused());
+
+    switch (state)
+    {
+        case KMachineState_Stuck: // TODO: Test it!
+        {
+            /* Prevent machine view from resizing: */
+            uisession()->setGuestResizeIgnored(true);
+
+            /* Get console and log folder. */
+            CConsole console = session().GetConsole();
+            const QString &strLogFolder = console.GetMachine().GetLogFolder();
+
+            /* Take the screenshot for debugging purposes and save it. */
+            takeScreenshot(strLogFolder + "/VBox.png", "png");
+
+            /* Warn the user about GURU: */
+            if (msgCenter().remindAboutGuruMeditation(console, QDir::toNativeSeparators(strLogFolder)))
+            {
+                console.PowerDown();
+                if (!console.isOk())
+                    msgCenter().cannotStopMachine(console);
+            }
+            break;
+        }
+        case KMachineState_Paused:
+        case KMachineState_TeleportingPausedVM:
+        {
+            QAction *pPauseAction = gActionPool->action(UIActionIndexRuntime_Toggle_Pause);
+            if (!pPauseAction->isChecked())
+            {
+                /* Was paused from CSession side: */
+                pPauseAction->blockSignals(true);
+                pPauseAction->setChecked(true);
+                pPauseAction->blockSignals(false);
+            }
+            break;
+        }
+        case KMachineState_Running:
+        case KMachineState_Teleporting:
+        case KMachineState_LiveSnapshotting:
+        {
+            QAction *pPauseAction = gActionPool->action(UIActionIndexRuntime_Toggle_Pause);
+            if (pPauseAction->isChecked())
+            {
+                /* Was resumed from CSession side: */
+                pPauseAction->blockSignals(true);
+                pPauseAction->setChecked(false);
+                pPauseAction->blockSignals(false);
+            }
+            break;
+        }
+        case KMachineState_PoweredOff:
+        case KMachineState_Saved:
+        case KMachineState_Teleported:
+        case KMachineState_Aborted:
+        {
+            /* Close VM if it was turned off and closure allowed: */
+            if (!isPreventAutoClose())
+            {
+                /* VM has been powered off, saved or aborted, no matter
+                 * internally or externally. We must *safely* close VM window(s): */
+                QTimer::singleShot(0, uisession(), SLOT(sltCloseVirtualSession()));
+            }
+            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;
+    }
+
+#ifdef Q_WS_MAC
+    /* Update Dock Overlay: */
+    updateDockOverlay();
+#endif /* Q_WS_MAC */
+}
+
+void UIMachineLogic::sltAdditionsStateChanged()
+{
+    /* Update action states: */
+    gActionPool->action(UIActionIndexRuntime_Toggle_GuestAutoresize)->setEnabled(uisession()->isGuestSupportsGraphics());
+    gActionPool->action(UIActionIndexRuntime_Toggle_Seamless)->setEnabled(uisession()->isGuestSupportsSeamless());
+}
+
+void UIMachineLogic::sltMouseCapabilityChanged()
+{
+    /* Variable falgs: */
+    bool fIsMouseSupportsAbsolute = uisession()->isMouseSupportsAbsolute();
+    bool fIsMouseSupportsRelative = uisession()->isMouseSupportsRelative();
+    bool fIsMouseHostCursorNeeded = uisession()->isMouseHostCursorNeeded();
+
+    /* Update action state: */
+    QAction *pAction = gActionPool->action(UIActionIndexRuntime_Toggle_MouseIntegration);
+    pAction->setEnabled(fIsMouseSupportsAbsolute && fIsMouseSupportsRelative && !fIsMouseHostCursorNeeded);
+    if (fIsMouseHostCursorNeeded)
+        pAction->setChecked(false);
+}
+
+void UIMachineLogic::sltUSBDeviceStateChange(const CUSBDevice &device, bool fIsAttached, const CVirtualBoxErrorInfo &error)
+{
+    /* Check if USB device have anything to tell us: */
+    if (!error.isNull())
+    {
+        if (fIsAttached)
+            msgCenter().cannotAttachUSBDevice(session().GetConsole(), vboxGlobal().details(device), error);
+        else
+            msgCenter().cannotDetachUSBDevice(session().GetConsole(), vboxGlobal().details(device), error);
+    }
+}
+
+void UIMachineLogic::sltRuntimeError(bool fIsFatal, const QString &strErrorId, const QString &strMessage)
+{
+    msgCenter().showRuntimeError(session().GetConsole(), fIsFatal, strErrorId, strMessage);
+}
+
+#ifdef Q_WS_MAC
+void UIMachineLogic::sltShowWindows()
+{
+    for (int i=0; i < m_machineWindowsList.size(); ++i)
+    {
+        UIMachineWindow *pMachineWindow = m_machineWindowsList.at(i);
+        /* Dunno what Qt 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. */
+        pMachineWindow->machineWindow()->raise();
+        pMachineWindow->machineWindow()->activateWindow();
+    }
+}
+#endif /* Q_WS_MAC */
+
+UIMachineLogic::UIMachineLogic(QObject *pParent, UISession *pSession, UIVisualStateType visualStateType)
     : QIWithRetranslateUI3<QObject>(pParent)
     , m_pSession(pSession)
@@ -233,17 +448,4 @@
 }
 
-UIMachineLogic::~UIMachineLogic()
-{
-#ifdef VBOX_WITH_DEBUGGER_GUI
-    /* Close debugger: */
-    dbgDestroy();
-#endif /* VBOX_WITH_DEBUGGER_GUI */
-}
-
-CSession& UIMachineLogic::session() const
-{
-    return uisession()->session();
-}
-
 void UIMachineLogic::addMachineWindow(UIMachineWindow *pMachineWindow)
 {
@@ -300,8 +502,19 @@
 #endif /* Q_WS_MAC */
 
+void UIMachineLogic::prepareRequiredFeatures()
+{
+#ifdef Q_WS_MAC
+# ifdef VBOX_WITH_ICHAT_THEATER
+    /* Init shared AV manager: */
+    initSharedAVManager();
+# endif /* VBOX_WITH_ICHAT_THEATER */
+#endif /* Q_WS_MAC */
+}
+
 void UIMachineLogic::prepareSessionConnections()
 {
-    /* Machine power-up notifier: */
+    /* We should check for entering/exiting requested modes: */
     connect(uisession(), SIGNAL(sigMachineStarted()), this, SLOT(sltCheckRequestedModes()));
+    connect(uisession(), SIGNAL(sigAdditionsStateChange()), this, SLOT(sltCheckRequestedModes()));
 
     /* Machine state-change updater: */
@@ -324,7 +537,59 @@
 #ifdef Q_WS_MAC
     /* Show windows: */
-    connect(uisession(), SIGNAL(sigShowWindows()),
-            this, SLOT(sltShowWindows()));
+    connect(uisession(), SIGNAL(sigShowWindows()), this, SLOT(sltShowWindows()));
 #endif /* Q_WS_MAC */
+}
+
+void UIMachineLogic::prepareActionGroups()
+{
+#ifdef Q_WS_MAC
+    /* On Mac OS X, all QMenu's are consumed by Qt after they are added to
+     * another QMenu or a QMenuBar. This means we have to recreate all QMenus
+     * when creating a new QMenuBar. */
+    gActionPool->recreateMenus();
+#endif /* Q_WS_MAC */
+
+    /* Create group for all actions that are enabled only when the VM is running.
+     * Note that only actions whose enabled state depends exclusively on the
+     * execution state of the VM are added to this group. */
+    m_pRunningActions = new QActionGroup(this);
+    m_pRunningActions->setExclusive(false);
+
+    /* Create group for all actions that are enabled when the VM is running or paused.
+     * Note that only actions whose enabled state depends exclusively on the
+     * execution state of the VM are added to this group. */
+    m_pRunningOrPausedActions = new QActionGroup(this);
+    m_pRunningOrPausedActions->setExclusive(false);
+
+    /* Move actions into running actions group: */
+    m_pRunningActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_TypeCAD));
+#ifdef Q_WS_X11
+    m_pRunningActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_TypeCABS));
+#endif
+    m_pRunningActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_Reset));
+    m_pRunningActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_Shutdown));
+    m_pRunningActions->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen));
+    m_pRunningActions->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Seamless));
+    m_pRunningActions->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Scale));
+    m_pRunningActions->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_GuestAutoresize));
+    m_pRunningActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_AdjustWindow));
+
+    /* Move actions into running-n-paused actions group: */
+    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_SettingsDialog));
+    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_TakeSnapshot));
+    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_TakeScreenshot));
+    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_InformationDialog));
+    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Menu_MouseIntegration));
+    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_MouseIntegration));
+    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Pause));
+    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Menu_OpticalDevices));
+    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Menu_FloppyDevices));
+    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Menu_USBDevices));
+    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Menu_NetworkAdapters));
+    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_NetworkAdaptersDialog));
+    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Menu_SharedFolders));
+    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_SharedFoldersDialog));
+    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_VRDEServer));
+    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_InstallGuestTools));
 }
 
@@ -394,57 +659,4 @@
 }
 
-void UIMachineLogic::prepareActionGroups()
-{
-#ifdef Q_WS_MAC
-    /* On Mac OS X, all QMenu's are consumed by Qt after they are added to
-     * another QMenu or a QMenuBar. This means we have to recreate all QMenus
-     * when creating a new QMenuBar. */
-    gActionPool->recreateMenus();
-#endif /* Q_WS_MAC */
-
-    /* Create group for all actions that are enabled only when the VM is running.
-     * Note that only actions whose enabled state depends exclusively on the
-     * execution state of the VM are added to this group. */
-    m_pRunningActions = new QActionGroup(this);
-    m_pRunningActions->setExclusive(false);
-
-    /* Create group for all actions that are enabled when the VM is running or paused.
-     * Note that only actions whose enabled state depends exclusively on the
-     * execution state of the VM are added to this group. */
-    m_pRunningOrPausedActions = new QActionGroup(this);
-    m_pRunningOrPausedActions->setExclusive(false);
-
-    /* Move actions into running actions group: */
-    m_pRunningActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_TypeCAD));
-#ifdef Q_WS_X11
-    m_pRunningActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_TypeCABS));
-#endif
-    m_pRunningActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_Reset));
-    m_pRunningActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_Shutdown));
-    m_pRunningActions->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen));
-    m_pRunningActions->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Seamless));
-    m_pRunningActions->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Scale));
-    m_pRunningActions->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_GuestAutoresize));
-    m_pRunningActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_AdjustWindow));
-
-    /* Move actions into running-n-paused actions group: */
-    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_SettingsDialog));
-    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_TakeSnapshot));
-    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_TakeScreenshot));
-    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_InformationDialog));
-    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Menu_MouseIntegration));
-    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_MouseIntegration));
-    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_Pause));
-    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Menu_OpticalDevices));
-    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Menu_FloppyDevices));
-    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Menu_USBDevices));
-    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Menu_NetworkAdapters));
-    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_NetworkAdaptersDialog));
-    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Menu_SharedFolders));
-    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_SharedFoldersDialog));
-    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Toggle_VRDEServer));
-    m_pRunningOrPausedActions->addAction(gActionPool->action(UIActionIndexRuntime_Simple_InstallGuestTools));
-}
-
 void UIMachineLogic::prepareHandlers()
 {
@@ -529,14 +741,4 @@
 #endif /* Q_WS_MAC */
 
-void UIMachineLogic::prepareRequiredFeatures()
-{
-#ifdef Q_WS_MAC
-# ifdef VBOX_WITH_ICHAT_THEATER
-    /* Init shared AV manager: */
-    initSharedAVManager();
-# endif
-#endif
-}
-
 #ifdef VBOX_WITH_DEBUGGER_GUI
 void UIMachineLogic::prepareDebugger()
@@ -563,4 +765,12 @@
 #endif /* VBOX_WITH_DEBUGGER_GUI */
 
+#ifdef VBOX_WITH_DEBUGGER_GUI
+void UIMachineLogic::cleanupDebugger()
+{
+    /* Close debugger: */
+    dbgDestroy();
+}
+#endif /* VBOX_WITH_DEBUGGER_GUI */
+
 #ifdef Q_WS_MAC
 void UIMachineLogic::cleanupDock()
@@ -583,162 +793,7 @@
 }
 
-void UIMachineLogic::sltMachineStateChanged()
-{
-    /* Get machine state: */
-    KMachineState state = uisession()->machineState();
-
-    /* Update action groups: */
-    m_pRunningActions->setEnabled(uisession()->isRunning());
-    m_pRunningOrPausedActions->setEnabled(uisession()->isRunning() || uisession()->isPaused());
-
-    switch (state)
-    {
-        case KMachineState_Stuck: // TODO: Test it!
-        {
-            /* Prevent machine view from resizing: */
-            uisession()->setGuestResizeIgnored(true);
-
-            /* Get console and log folder. */
-            CConsole console = session().GetConsole();
-            const QString &strLogFolder = console.GetMachine().GetLogFolder();
-
-            /* Take the screenshot for debugging purposes and save it. */
-            takeScreenshot(strLogFolder + "/VBox.png", "png");
-
-            /* Warn the user about GURU: */
-            if (msgCenter().remindAboutGuruMeditation(console, QDir::toNativeSeparators(strLogFolder)))
-            {
-                console.PowerDown();
-                if (!console.isOk())
-                    msgCenter().cannotStopMachine(console);
-            }
-            break;
-        }
-        case KMachineState_Paused:
-        case KMachineState_TeleportingPausedVM:
-        {
-            QAction *pPauseAction = gActionPool->action(UIActionIndexRuntime_Toggle_Pause);
-            if (!pPauseAction->isChecked())
-            {
-                /* Was paused from CSession side: */
-                pPauseAction->blockSignals(true);
-                pPauseAction->setChecked(true);
-                pPauseAction->blockSignals(false);
-            }
-            break;
-        }
-        case KMachineState_Running:
-        case KMachineState_Teleporting:
-        case KMachineState_LiveSnapshotting:
-        {
-            QAction *pPauseAction = gActionPool->action(UIActionIndexRuntime_Toggle_Pause);
-            if (pPauseAction->isChecked())
-            {
-                /* Was resumed from CSession side: */
-                pPauseAction->blockSignals(true);
-                pPauseAction->setChecked(false);
-                pPauseAction->blockSignals(false);
-            }
-            break;
-        }
-        case KMachineState_PoweredOff:
-        case KMachineState_Saved:
-        case KMachineState_Teleported:
-        case KMachineState_Aborted:
-        {
-            /* Close VM if it was turned off and closure allowed: */
-            if (!isPreventAutoClose())
-            {
-                /* VM has been powered off, saved or aborted, no matter
-                 * internally or externally. We must *safely* close VM window(s): */
-                QTimer::singleShot(0, uisession(), SLOT(sltCloseVirtualSession()));
-            }
-            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;
-    }
-
-#ifdef Q_WS_MAC
-    /* Update Dock Overlay: */
-    updateDockOverlay();
-#endif /* Q_WS_MAC */
-}
-
-void UIMachineLogic::sltAdditionsStateChanged()
-{
-    /* Variable flags: */
-    bool fIsSupportsGraphics = uisession()->isGuestSupportsGraphics();
-    bool fIsSupportsSeamless = uisession()->isGuestSupportsSeamless();
-
-    /* Update action states: */
-    gActionPool->action(UIActionIndexRuntime_Toggle_GuestAutoresize)->setEnabled(fIsSupportsGraphics);
-    gActionPool->action(UIActionIndexRuntime_Toggle_Seamless)->setEnabled(fIsSupportsSeamless);
-
-    /* Check if we should enter some extended mode: */
-    sltCheckRequestedModes();
-}
-
-void UIMachineLogic::sltMouseCapabilityChanged()
-{
-    /* Variable falgs: */
-    bool fIsMouseSupportsAbsolute = uisession()->isMouseSupportsAbsolute();
-    bool fIsMouseSupportsRelative = uisession()->isMouseSupportsRelative();
-    bool fIsMouseHostCursorNeeded = uisession()->isMouseHostCursorNeeded();
-
-    /* Update action state: */
-    QAction *pAction = gActionPool->action(UIActionIndexRuntime_Toggle_MouseIntegration);
-    pAction->setEnabled(fIsMouseSupportsAbsolute && fIsMouseSupportsRelative && !fIsMouseHostCursorNeeded);
-    if (fIsMouseHostCursorNeeded)
-        pAction->setChecked(false);
-}
-
-void UIMachineLogic::sltUSBDeviceStateChange(const CUSBDevice &device, bool fIsAttached, const CVirtualBoxErrorInfo &error)
-{
-    bool fSuccess = error.isNull();
-
-    if (!fSuccess)
-    {
-        if (fIsAttached)
-            msgCenter().cannotAttachUSBDevice(session().GetConsole(), vboxGlobal().details(device), error);
-        else
-            msgCenter().cannotDetachUSBDevice(session().GetConsole(), vboxGlobal().details(device), error);
-    }
-}
-
-void UIMachineLogic::sltRuntimeError(bool fIsFatal, const QString &strErrorId, const QString &strMessage)
-{
-    msgCenter().showRuntimeError(session().GetConsole(), fIsFatal, strErrorId, strMessage);
-}
-
-#ifdef Q_WS_MAC
-void UIMachineLogic::sltShowWindows()
-{
-    for (int i=0; i < m_machineWindowsList.size(); ++i)
-    {
-        UIMachineWindow *pMachineWindow = m_machineWindowsList.at(i);
-        /* Dunno what Qt 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. */
-        pMachineWindow->machineWindow()->raise();
-        pMachineWindow->machineWindow()->activateWindow();
-    }
-}
-#endif /* Q_WS_MAC */
+void UIMachineLogic::cleanupActionGroups()
+{
+}
 
 void UIMachineLogic::sltCheckRequestedModes()
@@ -832,5 +887,5 @@
     AssertWrapperOk(keyboard);
 }
-#endif
+#endif /* Q_WS_X11 */
 
 void UIMachineLogic::sltTakeSnapshot()
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h	(revision 41063)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h	(revision 41064)
@@ -25,5 +25,5 @@
 #ifdef VBOX_WITH_DEBUGGER_GUI
 # include <VBox/dbggui.h>
-#endif
+#endif /* VBOX_WITH_DEBUGGER_GUI */
 
 /* Global forwards */
@@ -44,4 +44,5 @@
 class UIDockIconPreview;
 
+/* Machine logic interface: */
 class UIMachineLogic : public QIWithRetranslateUI3<QObject>
 {
@@ -51,14 +52,13 @@
 
     /* Factory functions to create/destroy required logic sub-child: */
-    static UIMachineLogic* create(QObject *pParent,
-                                  UISession *pSession,
-                                  UIVisualStateType visualStateType);
+    static UIMachineLogic* create(QObject *pParent, UISession *pSession, UIVisualStateType visualStateType);
     static void destroy(UIMachineLogic *pWhichLogic);
 
-    /* Check if this mode is available: */
-    virtual bool checkAvailability();
-
-    /* Do the real initialization of the object: */
-    virtual void initialize() = 0;
+    /* Check if this logic is available: */
+    virtual bool checkAvailability() = 0;
+
+    /* Prepare/cleanup the logic: */
+    virtual void prepare();
+    virtual void cleanup();
 
     /* Main getters/setters: */
@@ -82,50 +82,4 @@
 #endif /* Q_WS_MAC */
 
-protected:
-
-    /* Machine logic constructor/destructor: */
-    UIMachineLogic(QObject *pParent,
-                   UISession *pSession,
-                   UIVisualStateType visualStateType);
-    virtual ~UIMachineLogic();
-
-    /* Protected getters/setters: */
-    bool isMachineWindowsCreated() const { return m_fIsWindowsCreated; }
-    void setMachineWindowsCreated(bool fIsWindowsCreated) { m_fIsWindowsCreated = fIsWindowsCreated; }
-
-    /* Protected members: */
-    void setKeyboardHandler(UIKeyboardHandler *pKeyboardHandler);
-    void setMouseHandler(UIMouseHandler *pMouseHandler);
-    void addMachineWindow(UIMachineWindow *pMachineWindow);
-    void retranslateUi();
-#ifdef Q_WS_MAC
-    bool isDockIconPreviewEnabled() const { return m_fIsDockIconEnabled; }
-    void setDockIconPreviewEnabled(bool fIsDockIconPreviewEnabled) { m_fIsDockIconEnabled = fIsDockIconPreviewEnabled; }
-    void updateDockOverlay();
-#endif /* Q_WS_MAC */
-
-    /* Prepare helpers: */
-    virtual void prepareSessionConnections();
-    virtual void prepareActionConnections();
-    virtual void prepareActionGroups();
-    virtual void prepareHandlers();
-#ifdef Q_WS_MAC
-    virtual void prepareDock();
-#endif /* Q_WS_MAC */
-    virtual void prepareRequiredFeatures();
-#ifdef VBOX_WITH_DEBUGGER_GUI
-    virtual void prepareDebugger();
-#endif /* VBOX_WITH_DEBUGGER_GUI */
-
-    /* Cleanup helpers: */
-    //virtual void cleanupRequiredFeatures() {}
-#ifdef Q_WS_MAC
-    virtual void cleanupDock();
-#endif /* Q_WS_MAC */
-    virtual void cleanupHandlers();
-    //virtual void cleanupActionGroups() {}
-    //virtual void cleanupActionConnections() {}
-    //virtual void cleanupSessionConnections() {}
-
 protected slots:
 
@@ -140,10 +94,58 @@
 #endif /* RT_OS_DARWIN */
 
+protected:
+
+    /* Constructor: */
+    UIMachineLogic(QObject *pParent, UISession *pSession, UIVisualStateType visualStateType);
+
+    /* Protected getters/setters: */
+    bool isMachineWindowsCreated() const { return m_fIsWindowsCreated; }
+    void setMachineWindowsCreated(bool fIsWindowsCreated) { m_fIsWindowsCreated = fIsWindowsCreated; }
+
+    /* Protected members: */
+    void setKeyboardHandler(UIKeyboardHandler *pKeyboardHandler);
+    void setMouseHandler(UIMouseHandler *pMouseHandler);
+    void addMachineWindow(UIMachineWindow *pMachineWindow);
+    void retranslateUi();
+#ifdef Q_WS_MAC
+    bool isDockIconPreviewEnabled() const { return m_fIsDockIconEnabled; }
+    void setDockIconPreviewEnabled(bool fIsDockIconPreviewEnabled) { m_fIsDockIconEnabled = fIsDockIconPreviewEnabled; }
+    void updateDockOverlay();
+#endif /* Q_WS_MAC */
+
+    /* Prepare helpers: */
+    virtual void prepareRequiredFeatures();
+    virtual void prepareSessionConnections();
+    virtual void prepareActionGroups();
+    virtual void prepareActionConnections();
+    virtual void prepareHandlers();
+    virtual void prepareMachineWindows() = 0;
+#ifdef Q_WS_MAC
+    virtual void prepareDock();
+#endif /* Q_WS_MAC */
+#ifdef VBOX_WITH_DEBUGGER_GUI
+    virtual void prepareDebugger();
+#endif /* VBOX_WITH_DEBUGGER_GUI */
+
+    /* Cleanup helpers: */
+#ifdef VBOX_WITH_DEBUGGER_GUI
+    virtual void cleanupDebugger();
+#endif /* VBOX_WITH_DEBUGGER_GUI */
+#ifdef Q_WS_MAC
+    virtual void cleanupDock();
+#endif /* Q_WS_MAC */
+    virtual void cleanupMachineWindows() = 0;
+    virtual void cleanupHandlers();
+    //virtual void cleanupActionConnections() {}
+    virtual void cleanupActionGroups();
+    //virtual void cleanupSessionConnections() {}
+    //virtual void cleanupRequiredFeatures() {}
+
+private slots:
+
     /* Mode request watch dog: */
     void sltCheckRequestedModes();
 
-private slots:
-
-    /* "Machine" menu functionality */
+    /* "Machine" menu functionality: */
     void sltToggleGuestAutoresize(bool fEnabled);
     void sltAdjustWindow();
@@ -152,6 +154,5 @@
 #ifdef Q_WS_X11
     void sltTypeCABS();
-#endif
-
+#endif /* Q_WS_X11 */
     void sltTakeSnapshot();
     void sltTakeScreenshot();
@@ -162,5 +163,5 @@
     void sltClose();
 
-    /* "Device" menu functionality */
+    /* "Device" menu functionality: */
     void sltOpenVMSettingsDialog(const QString &strCategory = QString());
     void sltOpenNetworkAdaptersDialog();
@@ -175,4 +176,5 @@
 
 #ifdef VBOX_WITH_DEBUGGER_GUI
+    /* "Debug" menu functionality: */
     void sltPrepareDebugMenu();
     void sltShowDebugStatistics();
@@ -180,5 +182,5 @@
     void sltLoggingToggled(bool);
     void sltShowLogDialog();
-#endif
+#endif /* VBOX_WITH_DEBUGGER_GUI */
 
 #ifdef RT_OS_DARWIN /* Something is *really* broken in regards of the moc here */
@@ -190,9 +192,6 @@
 private:
 
-    /* Utility functions: */
-    static int searchMaxSnapshotIndex(const CMachine &machine,
-                                      const CSnapshot &snapshot,
-                                      const QString &strNameTemplate);
-
+    /* Helpers: */
+    static int searchMaxSnapshotIndex(const CMachine &machine, const CSnapshot &snapshot, const QString &strNameTemplate);
     void takeScreenshot(const QString &strFile, const QString &strFormat /* = "png" */) const;
 
@@ -219,5 +218,5 @@
     /* The virtual method table for the debugger GUI: */
     PCDBGGUIVT m_pDbgGuiVT;
-#endif
+#endif /* VBOX_WITH_DEBUGGER_GUI */
 
 #ifdef Q_WS_MAC
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp	(revision 41063)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.cpp	(revision 41064)
@@ -7,5 +7,5 @@
 
 /*
- * Copyright (C) 2010 Oracle Corporation
+ * Copyright (C) 2010-2012 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -18,12 +18,11 @@
  */
 
-/* Global includes */
+/* Global includes: */
 #include <QDesktopWidget>
 
-/* Local includes */
+/* Local includes: */
 #include "COMDefs.h"
 #include "VBoxGlobal.h"
 #include "UIMessageCenter.h"
-
 #include "UISession.h"
 #include "UIActionPoolRuntime.h"
@@ -31,5 +30,4 @@
 #include "UIMachineWindowFullscreen.h"
 #include "UIMultiScreenLayout.h"
-
 #ifdef Q_WS_MAC
 # include "UIExtraDataEventHandler.h"
@@ -41,4 +39,5 @@
     : UIMachineLogic(pParent, pSession, UIVisualStateType_Fullscreen)
 {
+    /* Create multiscreen layout: */
     m_pScreenLayout = new UIMultiScreenLayout(this);
 }
@@ -46,18 +45,5 @@
 UIMachineLogicFullscreen::~UIMachineLogicFullscreen()
 {
-#ifdef Q_WS_MAC
-    /* Cleanup the dock stuff before the machine window(s): */
-    cleanupDock();
-#endif /* Q_WS_MAC */
-
-    /* Cleanup machine window(s): */
-    cleanupMachineWindows();
-
-    /* Cleanup handlers: */
-    cleanupHandlers();
-
-    /* Cleanup action related stuff */
-    cleanupActionGroups();
-
+    /* Delete multiscreen layout: */
     delete m_pScreenLayout;
 }
@@ -65,14 +51,10 @@
 bool UIMachineLogicFullscreen::checkAvailability()
 {
-    /* Base class availability: */
-    if (!UIMachineLogic::checkAvailability())
-        return false;
-
     /* Temporary get a machine object: */
     const CMachine &machine = uisession()->session().GetMachine();
 
+    /* Check that there are enough physical screens are connected: */
     int cHostScreens = m_pScreenLayout->hostScreenCount();
     int cGuestScreens = m_pScreenLayout->guestScreenCount();
-    /* Check that there are enough physical screens are connected: */
     if (cHostScreens < cGuestScreens)
     {
@@ -81,17 +63,13 @@
     }
 
-    // TODO_NEW_CORE: this is how it looked in the old version
-    // bool VBoxConsoleView::isAutoresizeGuestActive() { return mGuestSupportsGraphics && mAutoresizeGuest; }
-//    if (uisession()->session().GetConsole().isAutoresizeGuestActive())
+    /* Check if there is enough physical memory to enter fullscreen: */
     if (uisession()->isGuestAdditionsActive())
     {
-        quint64 availBits = machine.GetVRAMSize() /* VRAM */
-                            * _1M /* MiB to bytes */
-                            * 8; /* to bits */
+        quint64 availBits = machine.GetVRAMSize() /* VRAM */ * _1M /* MiB to bytes */ * 8 /* to bits */;
         quint64 usedBits = m_pScreenLayout->memoryRequirements();
         if (availBits < usedBits)
         {
             int result = msgCenter().cannotEnterFullscreenMode(0, 0, 0,
-                                                                 (((usedBits + 7) / 8 + _1M - 1) / _1M) * _1M);
+                                                               (((usedBits + 7) / 8 + _1M - 1) / _1M) * _1M);
             if (result == QIMessageBox::Cancel)
                 return false;
@@ -99,7 +77,7 @@
     }
 
-    /* Take the toggle hot key from the menu item. Since
-     * VBoxGlobal::extractKeyFromActionText gets exactly the
-     * linked key without the 'Host+' part we are adding it here. */
+    /* Take the toggle hot key from the menu item.
+     * Since VBoxGlobal::extractKeyFromActionText gets exactly
+     * the linked key without the 'Host+' part we are adding it here. */
     QString hotKey = QString("Host+%1")
         .arg(VBoxGlobal::extractKeyFromActionText(gActionPool->action(UIActionIndexRuntime_Toggle_Fullscreen)->text()));
@@ -113,50 +91,13 @@
 }
 
-void UIMachineLogicFullscreen::initialize()
-{
-    /* Prepare required features: */
-    prepareRequiredFeatures();
-
-#ifdef Q_WS_MAC
-    /* Prepare common connections: */
-    prepareCommonConnections();
-#endif /* Q_WS_MAC */
-
-    /* Prepare console connections: */
-    prepareSessionConnections();
-
-    /* Prepare action groups:
-     * Note: This has to be done before prepareActionConnections
-     * cause here actions/menus are recreated. */
-    prepareActionGroups();
-
-    /* Prepare action connections: */
-    prepareActionConnections();
-
-    /* Prepare handlers: */
-    prepareHandlers();
-
-    /* Prepare machine window: */
-    prepareMachineWindows();
-
-#ifdef Q_WS_MAC
-    /* Prepare dock: */
-    prepareDock();
-#endif /* Q_WS_MAC */
-
-    /* Power up machine: */
-    uisession()->powerUp();
-
-    /* Initialization: */
-    sltMachineStateChanged();
-    sltAdditionsStateChanged();
-    sltMouseCapabilityChanged();
-
-#ifdef VBOX_WITH_DEBUGGER_GUI
-    prepareDebugger();
-#endif /* VBOX_WITH_DEBUGGER_GUI */
-
-    /* Retranslate logic part: */
-    retranslateUi();
+void UIMachineLogicFullscreen::prepare()
+{
+    /* Call to base-class: */
+    UIMachineLogic::prepare();
+
+#ifdef Q_WS_MAC
+    /* Prepare fullscreen connections: */
+    prepareFullscreenConnections();
+#endif /* Q_WS_MAC */
 }
 
@@ -167,7 +108,7 @@
 
 #ifdef Q_WS_MAC
-void UIMachineLogicFullscreen::prepareCommonConnections()
-{
-    /* Presentation mode connection */
+void UIMachineLogicFullscreen::prepareFullscreenConnections()
+{
+    /* Presentation mode connection: */
     connect(gEDataEvents, SIGNAL(sigPresentationModeChange(bool)),
             this, SLOT(sltChangePresentationMode(bool)));
@@ -177,5 +118,5 @@
 void UIMachineLogicFullscreen::prepareActionGroups()
 {
-    /* Base class action groups: */
+    /* Call to base-class: */
     UIMachineLogic::prepareActionGroups();
 
@@ -186,4 +127,5 @@
     QMenu *pMenu = gActionPool->action(UIActionIndexRuntime_Menu_View)->menu();
     m_pScreenLayout->initialize(pMenu);
+    pMenu->setVisible(true);
 }
 
@@ -242,4 +184,7 @@
 void UIMachineLogicFullscreen::cleanupActionGroups()
 {
+    /* Call to base-class: */
+    UIMachineLogic::cleanupActionGroups();
+
     /* Reenable adjust-window action: */
     gActionPool->action(UIActionIndexRuntime_Simple_AdjustWindow)->setVisible(true);
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.h	(revision 41063)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/fullscreen/UIMachineLogicFullscreen.h	(revision 41064)
@@ -6,5 +6,5 @@
 
 /*
- * Copyright (C) 2010 Oracle Corporation
+ * Copyright (C) 2010-2012 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -20,10 +20,11 @@
 #define __UIMachineLogicFullscreen_h__
 
-/* Local includes */
+/* Local includes: */
 #include "UIMachineLogic.h"
 
-/* Local forwards */
+/* Forward declarations: */
 class UIMultiScreenLayout;
 
+/* Fullscreen machine logic implementation: */
 class UIMachineLogicFullscreen : public UIMachineLogic
 {
@@ -32,11 +33,13 @@
 protected:
 
-    /* Fullscreen machine logic constructor/destructor: */
-    UIMachineLogicFullscreen(QObject *pParent,
-                             UISession *pSession);
+    /* Constructor/destructor: */
+    UIMachineLogicFullscreen(QObject *pParent, UISession *pSession);
     virtual ~UIMachineLogicFullscreen();
 
+    /* Check if this logic is available: */
     bool checkAvailability();
-    void initialize();
+
+    /* Prepare logic: */
+    void prepare();
 
     int hostScreenForGuestScreen(int screenId) const;
@@ -52,9 +55,9 @@
 
     /* Prepare helpers: */
-#ifdef Q_WS_MAC
-    void prepareCommonConnections();
-#endif /* Q_WS_MAC */
     void prepareActionGroups();
     void prepareMachineWindows();
+#ifdef Q_WS_MAC
+    void prepareFullscreenConnections();
+#endif /* Q_WS_MAC */
 
     /* Cleanup helpers: */
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp	(revision 41063)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp	(revision 41064)
@@ -7,5 +7,5 @@
 
 /*
- * Copyright (C) 2010 Oracle Corporation
+ * Copyright (C) 2010-2012 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -18,12 +18,11 @@
  */
 
-/* Global includes */
+/* Global includes: */
 #include <QMenu>
 
-/* Local includes */
+/* Local includes: */
 #include "COMDefs.h"
 #include "VBoxGlobal.h"
 #include "UIMessageCenter.h"
-
 #include "UISession.h"
 #include "UIActionPoolRuntime.h"
@@ -33,5 +32,4 @@
 #include "UIDownloaderUserManual.h"
 #include "UIDownloaderExtensionPack.h"
-
 #ifdef Q_WS_MAC
 #include "VBoxUtils.h"
@@ -43,59 +41,8 @@
 }
 
-UIMachineLogicNormal::~UIMachineLogicNormal()
+bool UIMachineLogicNormal::checkAvailability()
 {
-#ifdef Q_WS_MAC
-    /* Cleanup the dock stuff before the machine window(s): */
-    cleanupDock();
-#endif /* Q_WS_MAC */
-
-    /* Cleanup machine window(s): */
-    cleanupMachineWindow();
-
-    /* Cleanup handlers: */
-    cleanupHandlers();
-}
-
-void UIMachineLogicNormal::initialize()
-{
-    /* Prepare required features: */
-    prepareRequiredFeatures();
-
-    /* Prepare session connections: */
-    prepareSessionConnections();
-
-    /* Prepare action groups:
-     * Note: This has to be done before prepareActionConnections
-     * cause here actions/menus are recreated. */
-    prepareActionGroups();
-
-    /* Prepare action connections: */
-    prepareActionConnections();
-
-    /* Prepare handlers: */
-    prepareHandlers();
-
-    /* Prepare normal machine window: */
-    prepareMachineWindows();
-
-#ifdef Q_WS_MAC
-    /* Prepare dock: */
-    prepareDock();
-#endif /* Q_WS_MAC */
-
-    /* Power up machine: */
-    uisession()->powerUp();
-
-    /* Initialization: */
-    sltMachineStateChanged();
-    sltAdditionsStateChanged();
-    sltMouseCapabilityChanged();
-
-#ifdef VBOX_WITH_DEBUGGER_GUI
-    prepareDebugger();
-#endif /* VBOX_WITH_DEBUGGER_GUI */
-
-    /* Retranslate logic part: */
-    retranslateUi();
+    /* Normal mode is always available: */
+    return true;
 }
 
@@ -163,5 +110,5 @@
 }
 
-void UIMachineLogicNormal::cleanupMachineWindow()
+void UIMachineLogicNormal::cleanupMachineWindows()
 {
     /* Do not cleanup machine window(s) if not present: */
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.h	(revision 41063)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.h	(revision 41064)
@@ -6,5 +6,5 @@
 
 /*
- * Copyright (C) 2010 Oracle Corporation
+ * Copyright (C) 2010-2012 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -20,7 +20,8 @@
 #define __UIMachineLogicNormal_h__
 
-/* Local includes */
+/* Local includes: */
 #include "UIMachineLogic.h"
 
+/* Normal machine logic implementation: */
 class UIMachineLogicNormal : public UIMachineLogic
 {
@@ -29,10 +30,9 @@
 protected:
 
-    /* Normal machine logic constructor/destructor: */
-    UIMachineLogicNormal(QObject *pParent,
-                         UISession *pSession);
-    virtual ~UIMachineLogicNormal();
+    /* Constructor: */
+    UIMachineLogicNormal(QObject *pParent, UISession *pSession);
 
-    void initialize();
+    /* Check if this logic is available: */
+    bool checkAvailability();
 
 private slots:
@@ -50,5 +50,5 @@
 
     /* Cleanup helpers: */
-    void cleanupMachineWindow();
+    void cleanupMachineWindows();
     //void cleanupActionConnections() {}
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.cpp	(revision 41063)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.cpp	(revision 41064)
@@ -7,5 +7,5 @@
 
 /*
- * Copyright (C) 2010 Oracle Corporation
+ * Copyright (C) 2010-2012 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -18,9 +18,8 @@
  */
 
-/* Local includes */
+/* Local includes: */
 #include "COMDefs.h"
 #include "VBoxGlobal.h"
 #include "UIMessageCenter.h"
-
 #include "UISession.h"
 #include "UIActionPoolRuntime.h"
@@ -29,5 +28,4 @@
 #include "UIDownloaderAdditions.h"
 #include "UIDownloaderExtensionPack.h"
-
 #ifdef Q_WS_MAC
 #include "VBoxUtils.h"
@@ -39,30 +37,9 @@
 }
 
-UIMachineLogicScale::~UIMachineLogicScale()
-{
-#ifdef Q_WS_MAC
-    /* Cleanup the dock stuff before the machine window(s): */
-    cleanupDock();
-#endif /* Q_WS_MAC */
-
-    /* Cleanup machine window(s): */
-    cleanupMachineWindow();
-
-    /* Cleanup handlers: */
-    cleanupHandlers();
-
-    /* Cleanup actions groups: */
-    cleanupActionGroups();
-}
-
 bool UIMachineLogicScale::checkAvailability()
 {
-    /* Base class availability: */
-    if (!UIMachineLogic::checkAvailability())
-        return false;
-
-    /* Take the toggle hot key from the menu item. Since
-     * VBoxGlobal::extractKeyFromActionText gets exactly the
-     * linked key without the 'Host+' part we are adding it here. */
+    /* Take the toggle hot key from the menu item.
+     * Since VBoxGlobal::extractKeyFromActionText gets exactly
+     * the linked key without the 'Host+' part we are adding it here. */
     QString strHotKey = QString("Host+%1")
         .arg(VBoxGlobal::extractKeyFromActionText(gActionPool->action(UIActionIndexRuntime_Toggle_Scale)->text()));
@@ -76,50 +53,7 @@
 }
 
-void UIMachineLogicScale::initialize()
-{
-    /* Prepare required features: */
-    prepareRequiredFeatures();
-
-    /* Prepare session connections: */
-    prepareSessionConnections();
-
-    /* Prepare action groups:
-     * Note: This has to be done before prepareActionConnections
-     * cause here actions/menus are recreated. */
-    prepareActionGroups();
-
-    /* Prepare action connections: */
-    prepareActionConnections();
-
-    /* Prepare handlers: */
-    prepareHandlers();
-
-    /* Prepare scale machine window: */
-    prepareMachineWindows();
-
-#ifdef Q_WS_MAC
-    /* Prepare dock: */
-    prepareDock();
-#endif /* Q_WS_MAC */
-
-    /* Power up machine: */
-    uisession()->powerUp();
-
-    /* Initialization: */
-    sltMachineStateChanged();
-    sltAdditionsStateChanged();
-    sltMouseCapabilityChanged();
-
-#ifdef VBOX_WITH_DEBUGGER_GUI
-    prepareDebugger();
-#endif /* VBOX_WITH_DEBUGGER_GUI */
-
-    /* Retranslate logic part: */
-    retranslateUi();
-}
-
 void UIMachineLogicScale::prepareActionGroups()
 {
-    /* Base class action groups: */
+    /* Call to base-class: */
     UIMachineLogic::prepareActionGroups();
 
@@ -156,5 +90,5 @@
 }
 
-void UIMachineLogicScale::cleanupMachineWindow()
+void UIMachineLogicScale::cleanupMachineWindows()
 {
     /* Do not cleanup machine window(s) if not present: */
@@ -169,4 +103,7 @@
 void UIMachineLogicScale::cleanupActionGroups()
 {
+    /* Call to base-class: */
+    UIMachineLogic::cleanupActionGroups();
+
     /* Reenable guest-autoresize action: */
     gActionPool->action(UIActionIndexRuntime_Toggle_GuestAutoresize)->setVisible(true);
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.h	(revision 41063)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/scale/UIMachineLogicScale.h	(revision 41064)
@@ -6,5 +6,5 @@
 
 /*
- * Copyright (C) 2010 Oracle Corporation
+ * Copyright (C) 2010-2012 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -20,7 +20,8 @@
 #define __UIMachineLogicScale_h__
 
-/* Local includes */
+/* Local includes: */
 #include "UIMachineLogic.h"
 
+/* Scale machine logic implementation: */
 class UIMachineLogicScale : public UIMachineLogic
 {
@@ -29,11 +30,9 @@
 protected:
 
-    /* Scale machine logic constructor/destructor: */
-    UIMachineLogicScale(QObject *pParent,
-                        UISession *pSession);
-    virtual ~UIMachineLogicScale();
+    /* Constructor: */
+    UIMachineLogicScale(QObject *pParent, UISession *pSession);
 
+    /* Check if this logic is available: */
     bool checkAvailability();
-    void initialize();
 
 private:
@@ -44,5 +43,5 @@
 
     /* Cleanup helpers: */
-    void cleanupMachineWindow();
+    void cleanupMachineWindows();
     void cleanupActionGroups();
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineLogicSeamless.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineLogicSeamless.cpp	(revision 41063)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineLogicSeamless.cpp	(revision 41064)
@@ -7,5 +7,5 @@
 
 /*
- * Copyright (C) 2010 Oracle Corporation
+ * Copyright (C) 2010-2012 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -18,12 +18,11 @@
  */
 
-/* Global includes */
+/* Global includes: */
 #include <QDesktopWidget>
 
-/* Local includes */
+/* Local includes: */
 #include "COMDefs.h"
 #include "VBoxGlobal.h"
 #include "UIMessageCenter.h"
-
 #include "UISession.h"
 #include "UIActionPoolRuntime.h"
@@ -31,5 +30,4 @@
 #include "UIMachineWindowSeamless.h"
 #include "UIMultiScreenLayout.h"
-
 #ifdef Q_WS_MAC
 # include "VBoxUtils.h"
@@ -39,4 +37,5 @@
     : UIMachineLogic(pParent, pSession, UIVisualStateType_Seamless)
 {
+    /* Create multiscreen layout: */
     m_pScreenLayout = new UIMultiScreenLayout(this);
 }
@@ -44,18 +43,5 @@
 UIMachineLogicSeamless::~UIMachineLogicSeamless()
 {
-#ifdef Q_WS_MAC
-    /* Cleanup the dock stuff before the machine window(s): */
-    cleanupDock();
-#endif /* Q_WS_MAC */
-
-    /* Cleanup machine window(s): */
-    cleanupMachineWindows();
-
-    /* Cleanup handlers: */
-    cleanupHandlers();
-
-    /* Cleanup actions groups: */
-    cleanupActionGroups();
-
+    /* Delete multiscreen layout: */
     delete m_pScreenLayout;
 }
@@ -63,14 +49,10 @@
 bool UIMachineLogicSeamless::checkAvailability()
 {
-    /* Base class availability: */
-    if (!UIMachineLogic::checkAvailability())
-        return false;
-
     /* Temporary get a machine object: */
     const CMachine &machine = uisession()->session().GetMachine();
 
+    /* Check that there are enough physical screens are connected: */
     int cHostScreens = m_pScreenLayout->hostScreenCount();
     int cGuestScreens = m_pScreenLayout->guestScreenCount();
-    /* Check that there are enough physical screens are connected: */
     if (cHostScreens < cGuestScreens)
     {
@@ -79,24 +61,20 @@
     }
 
-    // TODO_NEW_CORE: this is how it looked in the old version
-    // bool VBoxConsoleView::isAutoresizeGuestActive() { return mGuestSupportsGraphics && mAutoresizeGuest; }
-//    if (uisession()->session().GetConsole().isAutoresizeGuestActive())
+    /* Check if there is enough physical memory to enter seamless: */
     if (uisession()->isGuestAdditionsActive())
     {
-        quint64 availBits = machine.GetVRAMSize() /* VRAM */
-                            * _1M /* MiB to bytes */
-                            * 8; /* to bits */
+        quint64 availBits = machine.GetVRAMSize() /* VRAM */ * _1M /* MiB to bytes */ * 8 /* to bits */;
         quint64 usedBits = m_pScreenLayout->memoryRequirements();
         if (availBits < usedBits)
         {
             msgCenter().cannotEnterSeamlessMode(0, 0, 0,
-                                                  (((usedBits + 7) / 8 + _1M - 1) / _1M) * _1M);
+                                                (((usedBits + 7) / 8 + _1M - 1) / _1M) * _1M);
             return false;
         }
     }
 
-    /* Take the toggle hot key from the menu item. Since
-     * VBoxGlobal::extractKeyFromActionText gets exactly the
-     * linked key without the 'Host+' part we are adding it here. */
+    /* Take the toggle hot key from the menu item.
+     * Since VBoxGlobal::extractKeyFromActionText gets exactly
+     * the linked key without the 'Host+' part we are adding it here. */
     QString hotKey = QString("Host+%1")
         .arg(VBoxGlobal::extractKeyFromActionText(gActionPool->action(UIActionIndexRuntime_Toggle_Seamless)->text()));
@@ -110,47 +88,4 @@
 }
 
-void UIMachineLogicSeamless::initialize()
-{
-    /* Prepare required features: */
-    prepareRequiredFeatures();
-
-    /* Prepare console connections: */
-    prepareSessionConnections();
-
-    /* Prepare action groups:
-     * Note: This has to be done before prepareActionConnections
-     * cause here actions/menus are recreated. */
-    prepareActionGroups();
-
-    /* Prepare action connections: */
-    prepareActionConnections();
-
-    /* Prepare handlers: */
-    prepareHandlers();
-
-    /* Prepare normal machine window: */
-    prepareMachineWindows();
-
-#ifdef Q_WS_MAC
-    /* Prepare dock: */
-    prepareDock();
-#endif /* Q_WS_MAC */
-
-    /* Power up machine: */
-    uisession()->powerUp();
-
-    /* Initialization: */
-    sltMachineStateChanged();
-    sltAdditionsStateChanged();
-    sltMouseCapabilityChanged();
-
-#ifdef VBOX_WITH_DEBUGGER_GUI
-    prepareDebugger();
-#endif /* VBOX_WITH_DEBUGGER_GUI */
-
-    /* Retranslate logic part: */
-    retranslateUi();
-}
-
 int UIMachineLogicSeamless::hostScreenForGuestScreen(int screenId) const
 {
@@ -160,5 +95,5 @@
 void UIMachineLogicSeamless::prepareActionGroups()
 {
-    /* Base class action groups: */
+    /* Call to base-class: */
     UIMachineLogic::prepareActionGroups();
 
@@ -219,4 +154,7 @@
 void UIMachineLogicSeamless::cleanupActionGroups()
 {
+    /* Call to base-class: */
+    UIMachineLogic::cleanupActionGroups();
+
     /* Reenable guest-autoresize action: */
     gActionPool->action(UIActionIndexRuntime_Toggle_GuestAutoresize)->setVisible(true);
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineLogicSeamless.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineLogicSeamless.h	(revision 41063)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/seamless/UIMachineLogicSeamless.h	(revision 41064)
@@ -6,5 +6,5 @@
 
 /*
- * Copyright (C) 2010 Oracle Corporation
+ * Copyright (C) 2010-2012 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -20,10 +20,11 @@
 #define __UIMachineLogicSeamless_h__
 
-/* Local includes */
+/* Local includes: */
 #include "UIMachineLogic.h"
 
-/* Local forwards */
+/* Forward declarations: */
 class UIMultiScreenLayout;
 
+/* Seamless machine logic implementation: */
 class UIMachineLogicSeamless : public UIMachineLogic
 {
@@ -32,11 +33,10 @@
 protected:
 
-    /* Seamless machine logic constructor/destructor: */
-    UIMachineLogicSeamless(QObject *pParent,
-                           UISession *pSession);
+    /* Constructor/destructor: */
+    UIMachineLogicSeamless(QObject *pParent, UISession *pSession);
     virtual ~UIMachineLogicSeamless();
 
+    /* Check if this logic is available: */
     bool checkAvailability();
-    void initialize();
 
     int hostScreenForGuestScreen(int screenId) const;
