Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp	(revision 26655)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp	(revision 26656)
@@ -372,22 +372,8 @@
     , m_bIsPreventAutoClose(false)
 {
-    /* Prepare action groups: */
-    prepareActionGroups();
-
-    /* Prepare action connections: */
-    prepareActionConnections();
-
-    /* Check the status of required features: */
-    prepareRequiredFeatures();
-
-    /* Load common logic settings: */
-    loadLogicSettings();
 }
 
 UIMachineLogic::~UIMachineLogic()
 {
-    /* Save common logic settings: */
-    saveLogicSettings();
-
 #ifdef VBOX_WITH_DEBUGGER_GUI
     /* Close debugger: */
@@ -399,4 +385,5 @@
 void UIMachineLogic::updateAppearanceOf(int iElement)
 {
+    /* Update logic: */
     CMachine machine = session().GetMachine();
 
@@ -410,14 +397,211 @@
         actionsPool()->action(UIActionIndex_Toggle_Pause)->setEnabled(isRunningOrPaused);
     }
+
+    /* Update window: */
+    machineWindowWrapper()->updateAppearanceOf(iElement);
+}
+
+void UIMachineLogic::prepareActionGroups()
+{
+    /* 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);
+
+    // TODO: Move actions into approprivate action groups!
+}
+
+void UIMachineLogic::prepareActionConnections()
+{
+    /* "Machine" actions connections */
+    connect(actionsPool()->action(UIActionIndex_Simple_AdjustWindow), SIGNAL(triggered()),
+            this, SLOT(sltAdjustWindow()));
+    connect(actionsPool()->action(UIActionIndex_Toggle_MouseIntegration), SIGNAL(toggled(bool)),
+            this, SLOT(sltToggleMouseIntegration(bool)));
+    connect(actionsPool()->action(UIActionIndex_Simple_TypeCAD), SIGNAL(triggered()),
+            this, SLOT(sltTypeCAD()));
+#ifdef Q_WS_X11
+    connect(actionsPool()->action(UIActionIndex_Simple_TypeCABS), SIGNAL(triggered()),
+            this, SLOT(sltTypeCABS()));
+#endif
+    connect(actionsPool()->action(UIActionIndex_Simple_TakeSnapshot), SIGNAL(triggered()),
+            this, SLOT(sltTakeSnapshot()));
+    connect(actionsPool()->action(UIActionIndex_Simple_InformationDialog), SIGNAL(triggered()),
+            this, SLOT(sltShowInformationDialog()));
+    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()));
+    connect(actionsPool()->action(UIActionIndex_Simple_Close), SIGNAL(triggered()),
+            this, SLOT(sltClose()));
+
+    /* "Devices" actions connections */
+    connect(actionsPool()->action(UIActionIndex_Menu_OpticalDevices)->menu(), SIGNAL(aboutToShow()),
+            this, SLOT(sltPrepareStorageMenu()));
+    connect(actionsPool()->action(UIActionIndex_Menu_FloppyDevices)->menu(), SIGNAL(aboutToShow()),
+            this, SLOT(sltPrepareStorageMenu()));
+    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)));
+    connect(actionsPool()->action(UIActionIndex_Simple_InstallGuestTools), SIGNAL(triggered()),
+            this, SLOT(sltInstallGuestAdditions()));
+
+#ifdef VBOX_WITH_DEBUGGER_GUI
+    /* "Debug" actions connections */
+    connect(actionsPool()->action(UIActionIndex_Menu_Debug)->menu(), SIGNAL(aboutToShow()),
+            this, SLOT(sltPrepareDebugMenu()));
+    connect(actionsPool()->action(UIActionIndex_Simple_Statistics), SIGNAL(triggered()),
+            this, SLOT(sltShowDebugStatistics()));
+    connect(actionsPool()->action(UIActionIndex_Simple_CommandLine), SIGNAL(triggered()),
+            this, SLOT(sltShowDebugCommandLine()));
+    connect(actionsPool()->action(UIActionIndex_Toggle_Logging), SIGNAL(toggled(bool)),
+            this, SLOT(sltLoggingToggled(bool)));
+#endif
+}
+
+void UIMachineLogic::prepareRequiredFeatures()
+{
+    CConsole console = session().GetConsole();
+
+    /* Check if the virtualization feature is required. */
+    bool bIs64BitsGuest = vboxGlobal().virtualBox().GetGuestOSType(console.GetGuest().GetOSTypeId()).GetIs64Bit();
+    bool fRecommendVirtEx = vboxGlobal().virtualBox().GetGuestOSType(console.GetGuest().GetOSTypeId()).GetRecommendedVirtEx();
+    AssertMsg(!bIs64BitsGuest || fRecommendVirtEx, ("Virtualization support missed for 64bit guest!\n"));
+    bool bIsVirtEnabled = console.GetDebugger().GetHWVirtExEnabled();
+    if (fRecommendVirtEx && !bIsVirtEnabled)
+    {
+        bool ret;
+
+        // TODO: Check that logic!
+        //sltPause(true);
+
+        bool fVTxAMDVSupported = vboxGlobal().virtualBox().GetHost().GetProcessorFeature(KProcessorFeature_HWVirtEx);
+
+        if (bIs64BitsGuest)
+            ret = vboxProblem().warnAboutVirtNotEnabled64BitsGuest(fVTxAMDVSupported);
+        else
+            ret = vboxProblem().warnAboutVirtNotEnabledGuestRequired(fVTxAMDVSupported);
+
+        // TODO: Close application!
+        //if (ret == true)
+        //    machineWindowWrapper()->machineWindow()->close();
+        // TODO: Check that logic!
+        //else
+        //    sltPause(false);
+    }
+
+#ifdef Q_WS_MAC
+# ifdef VBOX_WITH_ICHAT_THEATER
+    initSharedAVManager();
+# endif
+#endif
+}
+
+void UIMachineLogic::loadLogicSettings()
+{
+    CMachine machine = session().GetMachine();
+
+    /* Extra-data settings */
+    {
+        QString strSettings;
+
+        strSettings = machine.GetExtraData(VBoxDefs::GUI_AutoresizeGuest);
+        if (strSettings != "off")
+            actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->setChecked(true);
+
+        strSettings = machine.GetExtraData(VBoxDefs::GUI_FirstRun);
+        if (strSettings == "yes")
+            m_bIsFirstTimeStarted = true;
+
+        strSettings = machine.GetExtraData(VBoxDefs::GUI_SaveMountedAtRuntime);
+        if (strSettings == "no")
+            m_bIsAutoSaveMedia = false;
+    }
+
+    /* Initial settings */
+    {
+        /* Initialize storage stuff: */
+        int iDevicesCountCD = 0;
+        int iDevicesCountFD = 0;
+        const CMediumAttachmentVector &attachments = machine.GetMediumAttachments();
+        foreach (const CMediumAttachment &attachment, attachments)
+        {
+            if (attachment.GetType() == KDeviceType_DVD)
+                ++ iDevicesCountCD;
+            if (attachment.GetType() == KDeviceType_Floppy)
+                ++ iDevicesCountFD;
+        }
+        actionsPool()->action(UIActionIndex_Menu_OpticalDevices)->setData(iDevicesCountCD);
+        actionsPool()->action(UIActionIndex_Menu_FloppyDevices)->setData(iDevicesCountFD);
+        actionsPool()->action(UIActionIndex_Menu_OpticalDevices)->setVisible(iDevicesCountCD);
+        actionsPool()->action(UIActionIndex_Menu_FloppyDevices)->setVisible(iDevicesCountFD);
+    }
+
+    /* Availability settings */
+    {
+        /* USB Stuff: */
+        CUSBController usbController = machine.GetUSBController();
+        if (usbController.isNull())
+        {
+            /* Hide USB_Menu: */
+            actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu()->setVisible(false);
+        }
+        else
+        {
+            /* Enable/Disable USB_Menu: */
+            actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu()->setEnabled(usbController.GetEnabled());
+        }
+
+        /* VRDP Stuff: */
+        CVRDPServer vrdpServer = machine.GetVRDPServer();
+        if (vrdpServer.isNull())
+        {
+            /* Hide VRDP Action: */
+            actionsPool()->action(UIActionIndex_Toggle_VRDP)->setVisible(false);
+        }
+    }
+}
+
+void UIMachineLogic::saveLogicSettings()
+{
+    CMachine machine = session().GetMachine();
+
+    /* Extra-data settings */
+    {
+        machine.SetExtraData(VBoxDefs::GUI_AutoresizeGuest,
+                             actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->isChecked() ? "on" : "off");
+
+        machine.SetExtraData(VBoxDefs::GUI_FirstRun, QString());
+
+        // TODO: Move to fullscreen/seamless logic:
+        //machine.SetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide, mMiniToolBar->isAutoHide() ? "on" : "off");
+    }
 }
 
 void UIMachineLogic::sltAdjustWindow()
 {
-    if (!machineWindowWrapper())
+    /* Do not process if window or view is missing! */
+    if (!machineWindowWrapper() || !machineWindowWrapper()->machineView())
         return;
 
+    /* Exit maximized window state if actual: */
     if (machineWindowWrapper()->machineWindow()->isMaximized())
         machineWindowWrapper()->machineWindow()->showNormal();
 
+    /* Normalize view's geometry: */
     machineWindowWrapper()->machineView()->normalizeGeometry(true);
 }
@@ -425,10 +609,10 @@
 void UIMachineLogic::sltToggleMouseIntegration(bool aOff)
 {
-    if (!machineWindowWrapper())
+    /* Do not process if window or view is missing! */
+    if (!machineWindowWrapper() || !machineWindowWrapper()->machineView())
         return;
 
+    /* Disable/Enable mouse-integration for view: */
     machineWindowWrapper()->machineView()->setMouseIntegrationEnabled(!aOff);
-
-    updateAppearanceOf(UIVisualElement_MouseIntegrationStuff);
 }
 
@@ -445,5 +629,5 @@
 {
     CKeyboard keyboard = session().GetConsole().GetKeyboard();
-    Assert (!keyboard.isNull());
+    Assert(!keyboard.isNull());
     static QVector<LONG> aSequence(6);
     aSequence[0] = 0x1d; /* Ctrl down */
@@ -460,4 +644,5 @@
 void UIMachineLogic::sltTakeSnapshot()
 {
+    /* Do not process if window is missing! */
     if (!machineWindowWrapper())
         return;
@@ -510,4 +695,8 @@
 void UIMachineLogic::sltShowInformationDialog()
 {
+    /* Do not process if window is missing! */
+    if (!machineWindowWrapper())
+        return;
+
     // TODO: Call for singleton information dialog for this machine!
     //VBoxVMInformationDlg::createInformationDlg(session(), machineWindowWrapper()->machineWindow());
@@ -516,7 +705,9 @@
 void UIMachineLogic::sltReset()
 {
+    /* Do not process if window is missing! */
     if (!machineWindowWrapper())
         return;
 
+    /* Confirm/Reset current console: */
     if (vboxProblem().confirmVMReset(machineWindowWrapper()->machineWindow()))
         session().GetConsole().Reset();
@@ -525,9 +716,8 @@
 void UIMachineLogic::sltPause(bool aOn)
 {
-    if (!machineWindowWrapper())
-        return;
-
+    /* Do not process if window is missing! */
     pause(aOn);
 
+    /* Update appearance: */
     updateAppearanceOf(UIVisualElement_PauseStuff);
 }
@@ -535,12 +725,11 @@
 void UIMachineLogic::sltACPIShutdown()
 {
-    if (!machineWindowWrapper())
-        return;
-
     CConsole console = session().GetConsole();
 
+    /* Warn the user about ACPI is not available if so: */
     if (!console.GetGuestEnteredACPIMode())
         return vboxProblem().cannotSendACPIToMachine();
 
+    /* Send ACPI shutdown signal, warn if failed: */
     console.PowerButton();
     if (!console.isOk())
@@ -550,7 +739,9 @@
 void UIMachineLogic::sltClose()
 {
+    /* Do not process if window is missing! */
     if (!machineWindowWrapper())
         return;
 
+    /* Close machine window: */
     machineWindowWrapper()->machineWindow()->close();
 }
@@ -807,7 +998,9 @@
 void UIMachineLogic::sltOpenNetworkAdaptersDialog()
 {
+    /* Do not process if window is missing! */
     if (!machineWindowWrapper())
         return;
 
+    /* Show network settings dialog: */
     UINetworkAdaptersDialog dlg(machineWindowWrapper()->machineWindow(), session());
     dlg.exec();
@@ -816,7 +1009,9 @@
 void UIMachineLogic::sltOpenSharedFoldersDialog()
 {
+    /* Do not process if window is missing! */
     if (!machineWindowWrapper())
         return;
 
+    /* Show shared folders settings dialog: */
     UISharedFoldersDialog dlg(machineWindowWrapper()->machineWindow(), session());
     dlg.exec();
@@ -833,12 +1028,10 @@
 void UIMachineLogic::sltSwitchVrdp(bool aOn)
 {
-    if (!machineWindowWrapper())
-        return;
-
+    /* Enable VRDP server if possible: */
     CVRDPServer server = session().GetMachine().GetVRDPServer();
     AssertMsg(!server.isNull(), ("VRDP Server should not be null!\n"));
-
     server.SetEnabled(aOn);
 
+    /* Update appearance: */
     updateAppearanceOf(UIVisualElement_VRDPStuff);
 }
@@ -846,4 +1039,5 @@
 void UIMachineLogic::sltInstallGuestAdditions()
 {
+    /* Do not process if window is missing! */
     if (!machineWindowWrapper())
         return;
@@ -877,17 +1071,17 @@
 
     /* 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)
     {
-        QString source = QString("http://download.virtualbox.org/virtualbox/%1/")
-                                 .arg (vbox.GetVersion().remove("_OSE")) + name;
+        QString source = QString("http://download.virtualbox.org/virtualbox/%1/").arg(vbox.GetVersion().remove("_OSE")) + name;
         QString target = QDir(vboxGlobal().virtualBox().GetHomeFolder()).absoluteFilePath(name);
 
-        // TODO: Think more about additions downloader...
-        //UIAdditionsDownloader *dl =
-        //    new UIAdditionsDownloader(source, target, mDevicesInstallGuestToolsAction);
-        //machineWindowWrapper()->statusBar()->addWidget(dl, 0);
-        //dl->start();
-    }
+        //UIAdditionsDownloader *pdl = new UIAdditionsDownloader(source, target, mDevicesInstallGuestToolsAction);
+        //machineWindowWrapper()->statusBar()->addWidget(pdl, 0);
+        //pdl->start();
+    }
+    #endif
 }
 
@@ -1091,195 +1285,4 @@
 }
 
-void UIMachineLogic::prepareActionGroups()
-{
-    /* 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);
-
-    // TODO: Move actions into approprivate action groups!
-}
-
-void UIMachineLogic::prepareActionConnections()
-{
-    /* "Machine" actions connections */
-    connect(actionsPool()->action(UIActionIndex_Simple_AdjustWindow), SIGNAL(triggered()),
-            this, SLOT(sltAdjustWindow()));
-    connect(actionsPool()->action(UIActionIndex_Toggle_MouseIntegration), SIGNAL(toggled(bool)),
-            this, SLOT(sltToggleMouseIntegration(bool)));
-    connect(actionsPool()->action(UIActionIndex_Simple_TypeCAD), SIGNAL(triggered()),
-            this, SLOT(sltTypeCAD()));
-#ifdef Q_WS_X11
-    connect(actionsPool()->action(UIActionIndex_Simple_TypeCABS), SIGNAL(triggered()),
-            this, SLOT(sltTypeCABS()));
-#endif
-    connect(actionsPool()->action(UIActionIndex_Simple_TakeSnapshot), SIGNAL(triggered()),
-            this, SLOT(sltTakeSnapshot()));
-    connect(actionsPool()->action(UIActionIndex_Simple_InformationDialog), SIGNAL(triggered()),
-            this, SLOT(sltShowInformationDialog()));
-    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()));
-    connect(actionsPool()->action(UIActionIndex_Simple_Close), SIGNAL(triggered()),
-            this, SLOT(sltClose()));
-
-    /* "Devices" actions connections */
-    connect(actionsPool()->action(UIActionIndex_Menu_OpticalDevices)->menu(), SIGNAL(aboutToShow()),
-            this, SLOT(sltPrepareStorageMenu()));
-    connect(actionsPool()->action(UIActionIndex_Menu_FloppyDevices)->menu(), SIGNAL(aboutToShow()),
-            this, SLOT(sltPrepareStorageMenu()));
-    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)));
-    connect(actionsPool()->action(UIActionIndex_Simple_InstallGuestTools), SIGNAL(triggered()),
-            this, SLOT(sltInstallGuestAdditions()));
-
-#ifdef VBOX_WITH_DEBUGGER_GUI
-    /* "Debug" actions connections */
-    connect(actionsPool()->action(UIActionIndex_Menu_Debug)->menu(), SIGNAL(aboutToShow()),
-            this, SLOT(sltPrepareDebugMenu()));
-    connect(actionsPool()->action(UIActionIndex_Simple_Statistics), SIGNAL(triggered()),
-            this, SLOT(sltShowDebugStatistics()));
-    connect(actionsPool()->action(UIActionIndex_Simple_CommandLine), SIGNAL(triggered()),
-            this, SLOT(sltShowDebugCommandLine()));
-    connect(actionsPool()->action(UIActionIndex_Toggle_Logging), SIGNAL(toggled(bool)),
-            this, SLOT(dbgLoggingToggled(bool)));
-#endif
-}
-
-void UIMachineLogic::prepareRequiredFeatures()
-{
-    CConsole console = session().GetConsole();
-
-    /* Check if the virtualization feature is required. */
-    bool bIs64BitsGuest = vboxGlobal().virtualBox().GetGuestOSType(console.GetGuest().GetOSTypeId()).GetIs64Bit();
-    bool fRecommendVirtEx = vboxGlobal().virtualBox().GetGuestOSType(console.GetGuest().GetOSTypeId()).GetRecommendedVirtEx();
-    AssertMsg(!bIs64BitsGuest || fRecommendVirtEx, ("Virtualization support missed for 64bit guest!\n"));
-    bool bIsVirtEnabled = console.GetDebugger().GetHWVirtExEnabled();
-    if (fRecommendVirtEx && !bIsVirtEnabled)
-    {
-        bool ret;
-
-        // TODO: Check that logic!
-        //sltPause(true);
-
-        bool fVTxAMDVSupported = vboxGlobal().virtualBox().GetHost().GetProcessorFeature(KProcessorFeature_HWVirtEx);
-
-        if (bIs64BitsGuest)
-            ret = vboxProblem().warnAboutVirtNotEnabled64BitsGuest(fVTxAMDVSupported);
-        else
-            ret = vboxProblem().warnAboutVirtNotEnabledGuestRequired(fVTxAMDVSupported);
-
-        // TODO: Close application!
-        //if (ret == true)
-        //    machineWindowWrapper()->machineWindow()->close();
-        // TODO: Check that logic!
-        //else
-        //    sltPause(false);
-    }
-
-#ifdef Q_WS_MAC
-# ifdef VBOX_WITH_ICHAT_THEATER
-    initSharedAVManager();
-# endif
-#endif
-}
-
-void UIMachineLogic::loadLogicSettings()
-{
-    CMachine machine = session().GetMachine();
-
-    /* Extra-data settings */
-    {
-        QString strSettings;
-
-        strSettings = machine.GetExtraData(VBoxDefs::GUI_AutoresizeGuest);
-        if (strSettings != "off")
-            actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->setChecked(true);
-
-        strSettings = machine.GetExtraData(VBoxDefs::GUI_FirstRun);
-        if (strSettings == "yes")
-            m_bIsFirstTimeStarted = true;
-
-        strSettings = machine.GetExtraData(VBoxDefs::GUI_SaveMountedAtRuntime);
-        if (strSettings == "no")
-            m_bIsAutoSaveMedia = false;
-    }
-
-    /* Initial settings */
-    {
-        /* Initialize storage stuff: */
-        int iDevicesCountCD = 0;
-        int iDevicesCountFD = 0;
-        const CMediumAttachmentVector &attachments = machine.GetMediumAttachments();
-        foreach (const CMediumAttachment &attachment, attachments)
-        {
-            if (attachment.GetType() == KDeviceType_DVD)
-                ++ iDevicesCountCD;
-            if (attachment.GetType() == KDeviceType_Floppy)
-                ++ iDevicesCountFD;
-        }
-        actionsPool()->action(UIActionIndex_Menu_OpticalDevices)->setData(iDevicesCountCD);
-        actionsPool()->action(UIActionIndex_Menu_FloppyDevices)->setData(iDevicesCountFD);
-        actionsPool()->action(UIActionIndex_Menu_OpticalDevices)->setVisible(iDevicesCountCD);
-        actionsPool()->action(UIActionIndex_Menu_FloppyDevices)->setVisible(iDevicesCountFD);
-    }
-
-    /* Availability settings */
-    {
-        /* USB Stuff: */
-        CUSBController usbController = machine.GetUSBController();
-        if (usbController.isNull())
-        {
-            /* Hide USB_Menu: */
-            actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu()->setVisible(false);
-        }
-        else
-        {
-            /* Enable/Disable USB_Menu: */
-            actionsPool()->action(UIActionIndex_Menu_USBDevices)->menu()->setEnabled(usbController.GetEnabled());
-        }
-
-        /* VRDP Stuff: */
-        CVRDPServer vrdpServer = machine.GetVRDPServer();
-        if (vrdpServer.isNull())
-        {
-            /* Hide VRDP Action: */
-            actionsPool()->action(UIActionIndex_Toggle_VRDP)->setVisible(false);
-        }
-    }
-}
-
-void UIMachineLogic::saveLogicSettings()
-{
-    CMachine machine = session().GetMachine();
-
-    /* Extra-data settings */
-    {
-        machine.SetExtraData(VBoxDefs::GUI_AutoresizeGuest,
-                             actionsPool()->action(UIActionIndex_Toggle_GuestAutoresize)->isChecked() ? "on" : "off");
-
-        machine.SetExtraData(VBoxDefs::GUI_FirstRun, QString());
-
-        // TODO: Move to fullscreen/seamless logic:
-        //machine.SetExtraData(VBoxDefs::GUI_MiniToolBarAutoHide, mMiniToolBar->isAutoHide() ? "on" : "off");
-    }
-}
-
 bool UIMachineLogic::pause(bool bOn)
 {
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h	(revision 26655)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.h	(revision 26656)
@@ -73,4 +73,16 @@
     virtual void updateAppearanceOf(int iElement);
 
+    /* Prepare helpers: */
+    virtual void prepareActionGroups();
+    virtual void prepareActionConnections();
+    virtual void prepareRequiredFeatures();
+    virtual void loadLogicSettings();
+
+    /* Cleanup helpers: */
+    void saveLogicSettings();
+    //void cleanupRequiredFeatures();
+    //void cleanupActionConnections();
+    //void cleanupActionGroups();
+
     /* Protected getters: */
     UIMachineWindow* machineWindowWrapper() { return m_pMachineWindowContainer; }
@@ -128,16 +140,4 @@
 private:
 
-    /* Prepare helpers: */
-    void prepareActionGroups();
-    void prepareActionConnections();
-    void prepareRequiredFeatures();
-    void loadLogicSettings();
-
-    /* Cleanup helpers: */
-    void saveLogicSettings();
-    //void cleanupRequiredFeatures();
-    //void cleanupActionConnections();
-    //void cleanupActionGroups();
-
     /* Utility functions: */
     void installGuestAdditionsFrom(const QString &strSource);
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp	(revision 26655)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.cpp	(revision 26656)
@@ -56,23 +56,21 @@
 }
 
+void UIMachineWindow::destroy(UIMachineWindow *pWhichWindow)
+{
+    delete pWhichWindow;
+}
+
 UIMachineWindow::UIMachineWindow(UIMachineLogic *pMachineLogic)
     : m_pMachineLogic(pMachineLogic)
-{
-    /* Prepare window icon: */
-    prepareWindowIcon();
-
-    /* Load common window settings: */
-    loadWindowSettings();
-
-    /* Translate common window: */
-    retranslateWindow();
+    , m_pMachineWindow(0)
+    , m_pMachineView(0)
+{
 }
 
 UIMachineWindow::~UIMachineWindow()
 {
-    // Nothing for now!
-}
-
-void UIMachineWindow::retranslateWindow()
+}
+
+void UIMachineWindow::retranslateUi()
 {
 #ifdef VBOX_OSE
@@ -108,4 +106,31 @@
         // mMiniToolBar->setDisplayText(machine.GetName() + strSnapshotName);
     }
+}
+
+void UIMachineWindow::prepareWindowIcon()
+{
+#if !(defined (Q_WS_WIN) || defined (Q_WS_MAC))
+    /* The default application icon (will be changed to VM-specific icon little bit later):
+     * 1. On Win32, it's built-in to the executable;
+     * 2. On Mac OS X the icon referenced in info.plist is used. */
+    machineWindow()->setWindowIcon(QIcon(":/VirtualBox_48px.png"));
+#endif
+
+#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
+}
+
+void UIMachineWindow::loadWindowSettings()
+{
+#ifdef Q_WS_MAC
+    QString testStr = vboxGlobal().virtualBox().GetExtraData(VBoxDefs::GUI_RealtimeDockIconUpdateEnabled).toLower();
+    /* Default to true if it is an empty value */
+    bool bIsDockIconEnabled = testStr.isEmpty() || testStr == "true";
+    machineView()->setDockIconEnabled(bIsDockIconEnabled);
+    machineView()->updateDockOverlay();
+#endif
 }
 
@@ -368,29 +393,2 @@
     }
 }
-
-void UIMachineWindow::prepareWindowIcon()
-{
-#if !(defined (Q_WS_WIN) || defined (Q_WS_MAC))
-    /* The default application icon (will be changed to VM-specific icon little bit later):
-     * 1. On Win32, it's built-in to the executable;
-     * 2. On Mac OS X the icon referenced in info.plist is used. */
-    machineWindow()->setWindowIcon(QIcon(":/VirtualBox_48px.png"));
-#endif
-
-#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
-}
-
-void UIMachineWindow::loadWindowSettings()
-{
-#ifdef Q_WS_MAC
-    QString testStr = vboxGlobal().virtualBox().GetExtraData(VBoxDefs::GUI_RealtimeDockIconUpdateEnabled).toLower();
-    /* Default to true if it is an empty value */
-    bool bIsDockIconEnabled = testStr.isEmpty() || testStr == "true";
-    machineView()->setDockIconEnabled(bIsDockIconEnabled);
-    machineView()->updateDockOverlay();
-#endif
-}
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.h	(revision 26655)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineWindow.h	(revision 26656)
@@ -40,4 +40,5 @@
     /* Factory function to create required machine window child: */
     static UIMachineWindow* create(UIMachineLogic *pMachineLogic, UIVisualStateType visualStateType);
+    static void destroy(UIMachineWindow *pWhichWindow);
 
     /* Abstract slot to close machine window: */
@@ -56,8 +57,16 @@
 
     /* Translate routine: */
-    void retranslateWindow();
+    virtual void retranslateUi();
 
     /* Update routines: */
     virtual void updateAppearanceOf(int iElement);
+
+    /* Prepare helpers: */
+    virtual void prepareWindowIcon();
+    virtual void loadWindowSettings();
+
+    /* Cleanup helpers: */
+    //virtual void saveWindowSettings();
+    //virtual void cleanupWindowIcon();
 
     /* Common machine window event handlers: */
@@ -68,22 +77,10 @@
 
     /* Protected variables: */
+    UIMachineLogic *m_pMachineLogic;
     QWidget *m_pMachineWindow;
     UIMachineView *m_pMachineView;
+    QString m_strWindowTitlePrefix;
 
-private:
-
-    /* Prepare helpers: */
-    void prepareWindowIcon();
-    void loadWindowSettings();
-
-    /* Cleanup helpers: */
-    //void saveWindowSettings();
-    //void cleanupWindowIcon();
-
-    /* Getter variables: */
-    UIMachineLogic *m_pMachineLogic;
-
-    /* Helper variables: */
-    QString m_strWindowTitlePrefix;
+    friend class UIMachineLogic;
 };
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp	(revision 26655)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.cpp	(revision 26656)
@@ -39,13 +39,28 @@
     : UIMachineLogic(pParent, session, pActionsPool, UIVisualStateType_Normal)
 {
+    /* Prepare action groups: */
+    prepareActionGroups();
+
     /* Prepare action connections: */
     prepareActionConnections();
 
+    /* Check the status of required features: */
+    prepareRequiredFeatures();
+
     /* Prepare normal machine window: */
     prepareMachineWindow();
+
+    /* Load common logic settings: */
+    loadLogicSettings();
+
+    /* Update all the elements: */
+    updateAppearanceOf(UIVisualElement_AllStuff);
 }
 
 UIMachineLogicNormal::~UIMachineLogicNormal()
 {
+    /* Save common logic settings: */
+    saveLogicSettings();
+
     /* Cleanup normal machine window: */
     cleanupMachineWindow();
@@ -76,4 +91,8 @@
 void UIMachineLogicNormal::prepareActionConnections()
 {
+    /* Parent class connections: */
+    UIMachineLogic::prepareActionConnections();
+
+    /* This class connections: */
     connect(actionsPool()->action(UIActionIndex_Menu_NetworkAdapters)->menu(), SIGNAL(aboutToShow()),
             this, SLOT(sltPrepareNetworkAdaptersMenu()));
@@ -84,4 +103,5 @@
 void UIMachineLogicNormal::prepareMachineWindow()
 {
+    /* Do not prepare window if its ready: */
     if (machineWindowWrapper())
         return;
@@ -94,4 +114,5 @@
 #endif /* Q_WS_MAC */
 
+    /* Create machine window: */
     m_pMachineWindowContainer = UIMachineWindow::create(this, visualStateType());
 
@@ -99,13 +120,8 @@
     setMachineState(session().GetConsole().GetState());
 
-    /* Update all the stuff: */
-    updateAppearanceOf(UIVisualElement_AllStuff);
-
+    /* Notify user about mouse&keyboard auto-capturing: */
     if (vboxGlobal().settings().autoCapture())
         vboxProblem().remindAboutAutoCapture();
 
-    /* Notify the console scroll-view about the console-window is opened: */
-    machineWindowWrapper()->machineView()->onViewOpened();
-
     bool saved = machineState() == KMachineState_Saved;
 
@@ -113,18 +129,20 @@
     CConsole console = session().GetConsole();
 
+    /* Shows first run wizard if necessary: */
     if (isFirstTimeStarted())
     {
         UIFirstRunWzd wzd(machineWindowWrapper()->machineWindow(), machine);
         wzd.exec();
-
-        /* Remove GUI_FirstRun extra data key from the machine settings
-         * file after showing the wizard once. */
-        machine.SetExtraData (VBoxDefs::GUI_FirstRun, QString::null);
-    }
+        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())
@@ -134,6 +152,4 @@
         return;
     }
-
-    //machineWindowWrapper()->machineView()->attach();
 
     /* Disable auto closure because we want to have a chance to show the error dialog on startup failure: */
@@ -165,15 +181,5 @@
     }
 
-#if 0 // TODO: Is it necessary now?
-     * Checking if the fullscreen mode should be activated: */
-    QString str = machine.GetExtraData (VBoxDefs::GUI_Fullscreen);
-    if (str == "on")
-        mVmFullscreenAction->setChecked (true);
-
-    /* If seamless mode should be enabled then check if it is enabled
-     * currently and re-enable it if seamless is supported: */
-    if (mVmSeamlessAction->isChecked() && m_bIsSeamlessSupported && m_bIsGraphicsSupported)
-        toggleFullscreenMode (true, true);
-
+#if 0 // TODO: Rework debugger logic!
 # ifdef VBOX_WITH_DEBUGGER_GUI
     /* Open the debugger in "full screen" mode requested by the user. */
@@ -205,17 +211,25 @@
 #endif
 
-    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)));
-
-    /* Re-request all the static values finally after view is really opened and attached: */
-    updateAppearanceOf(UIVisualElement_VirtualizationStuff);
+    /* 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)));
+    }
 }
 
 void UIMachineLogicNormal::cleanupMachineWindow()
 {
+    /* Do not cleanup machine window if it is not present: */
     if (!machineWindowWrapper())
         return;
+
+    /* Cleanup machine window: */
+    UIMachineWindow::destroy(m_pMachineWindowContainer);
+    m_pMachineWindowContainer = 0;
 
     // TODO: What should be done on window destruction?
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.h	(revision 26655)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineLogicNormal.h	(revision 26656)
@@ -62,4 +62,5 @@
     //void saveLogicSettings();
     void cleanupMachineWindow();
+    //void cleanupActionConnections();
 
     friend class UIMachineLogic;
Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp	(revision 26655)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/normal/UIMachineWindowNormal.cpp	(revision 26656)
@@ -51,4 +51,7 @@
     m_pMachineWindow = this;
 
+    /* Prepare window icon: */
+    prepareWindowIcon();
+
     /* Prepare menu: */
     prepareMenu();
@@ -68,4 +71,10 @@
     /* Retranslate normal window finally: */
     retranslateUi();
+
+    /* Update all the elements: */
+    updateAppearanceOf(UIVisualElement_AllStuff);
+
+    /* Show window: */
+    show();
 }
 
@@ -285,5 +294,5 @@
 {
     /* Translate parent class: */
-    retranslateWindow();
+    UIMachineWindow::retranslateUi();
 }
 
@@ -678,4 +687,6 @@
 void UIMachineWindowNormal::prepareMachineView()
 {
+    return; // TODO: Do not create view for now!
+
     CMachine machine = machineLogic()->session().GetMachine();
 
@@ -707,4 +718,8 @@
 void UIMachineWindowNormal::loadWindowSettings()
 {
+    /* Load parent class settings: */
+    UIMachineWindow::loadWindowSettings();
+
+    /* Load this class settings: */
     CMachine machine = machineLogic()->session().GetMachine();
 
@@ -733,6 +748,7 @@
             setGeometry(m_normalGeometry);
 
-            /* Normalize to the optimal size */
-            machineView()->normalizeGeometry(true /* adjust position? */);
+            /* Normalize view to the optimal size */
+            if (machineView())
+                machineView()->normalizeGeometry(true /* adjust position? */);
 
             /* Maximize if needed */
@@ -743,5 +759,6 @@
         {
             /* Normalize to the optimal size */
-            machineView()->normalizeGeometry(true /* adjust position? */);
+            if (machineView())
+                machineView()->normalizeGeometry(true /* adjust position? */);
 
             /* Move newly created window to the screen center: */
@@ -784,6 +801,6 @@
     {
         QString strWindowPosition = QString("%1,%2,%3,%4")
-                                .arg(m_normalGeometry.x()).arg(m_normalGeometry.y())
-                                .arg(m_normalGeometry.width()).arg(m_normalGeometry.height());
+                                    .arg(m_normalGeometry.x()).arg(m_normalGeometry.y())
+                                    .arg(m_normalGeometry.width()).arg(m_normalGeometry.height());
         if (isMaximized())
             strWindowPosition += QString(",%1").arg(VBoxDefs::GUI_LastWindowPosition_Max);
@@ -796,4 +813,4 @@
     /* Stop LED-update timer: */
     m_pIdleTimer->stop();
-    m_pIdleTimer->disconnect(SIGNAL(timeout()), this, SLOT(updateDeviceLights()));
-}
+    m_pIdleTimer->disconnect(SIGNAL(timeout()), this, SLOT(sltUpdateIndicators()));
+}
