Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp	(revision 53039)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.cpp	(revision 53040)
@@ -251,18 +251,43 @@
 bool UIMachine::prepare()
 {
+    /* Try to prepare session UI: */
+    if (!prepareSession())
+        return false;
+
+    /* Prevent application from closing when all window(s) closed: */
+    qApp->setQuitOnLastWindowClosed(false);
+
+    /* Cache medium data if necessary: */
+    vboxGlobal().startMediumEnumeration(false /* force start */);
+
+    /* Prepare visual state: */
+    prepareVisualState();
+
+    /* Now power up the machine.
+     * Actually powerUp does more that just a power up,
+     * so call it regardless of isSeparateProcess setting. */
+    uisession()->powerUp();
+
+    /* Initialization of MachineLogic internals after the powerUp.
+     * This is a hack, maybe more generic approach can be used. */
+    machineLogic()->initializePostPowerUp();
+
+    /* True by default: */
+    return true;
+}
+
+bool UIMachine::prepareSession()
+{
     /* Try to create session UI: */
     if (!UISession::create(m_pSession, this))
         return false;
 
-    /* Preventing application from closing in case of window(s) closed: */
-    qApp->setQuitOnLastWindowClosed(false);
-
-    /* Cache medium data only if really necessary: */
-    vboxGlobal().startMediumEnumeration(false /* force start */);
-
-    /* Load settings: */
-    loadSettings();
-
-    /* Prepare async visual-state change handler: */
+    /* True by default: */
+    return true;
+}
+
+void UIMachine::prepareVisualState()
+{
+    /* Prepare async visual state type change handler: */
     qRegisterMetaType<UIVisualStateType>();
     connect(this, SIGNAL(sigRequestAsyncVisualStateChange(UIVisualStateType)),
@@ -270,56 +295,36 @@
             Qt::QueuedConnection);
 
-    /* Enter default (normal) state */
+    /* Load restricted visual states: */
+    UIVisualStateType restrictedVisualStates = gEDataManager->restrictedVisualStates(vboxGlobal().managedVMUuid());
+    /* Acquire allowed visual states: */
+    m_allowedVisualStates = static_cast<UIVisualStateType>(UIVisualStateType_All ^ restrictedVisualStates);
+
+    /* Load requested visual state: */
+    UIVisualStateType requestedVisualState = gEDataManager->requestedVisualState(vboxGlobal().managedVMUuid());
+    /* Check if requested visual state is allowed: */
+    if (isVisualStateAllowed(requestedVisualState))
+    {
+        switch (requestedVisualState)
+        {
+            /* Direct transition to scale/fullscreen mode allowed: */
+            case UIVisualStateType_Scale:      m_initialStateType = UIVisualStateType_Scale; break;
+            case UIVisualStateType_Fullscreen: m_initialStateType = UIVisualStateType_Fullscreen; break;
+            /* While to seamless is not, so we have to make request to do transition later: */
+            case UIVisualStateType_Seamless:   uisession()->setRequestedVisualState(UIVisualStateType_Seamless); break;
+            default: break;
+        }
+    }
+
+    /* Enter initial visual state: */
     enterInitialVisualState();
-
-    /* Now power up the machine.
-     * Actually powerUp does more that just a power up,
-     * so call it regardless of isSeparateProcess setting. */
-    uisession()->powerUp();
-
-    /* Initialization of MachineLogic internals after the powerUp.
-     * This is a hack, maybe more generic approach can be used. */
-    machineLogic()->initializePostPowerUp();
-
-    /* True by default: */
-    return true;
-}
-
-void UIMachine::loadSettings()
-{
-    /* Load 'visual state' option: */
-    if (uisession())
-    {
-        /* Load restricted visual states: */
-        UIVisualStateType restrictedVisualStates = gEDataManager->restrictedVisualStates(vboxGlobal().managedVMUuid());
-        /* Acquire allowed visual states: */
-        m_allowedVisualStates = static_cast<UIVisualStateType>(UIVisualStateType_All ^ restrictedVisualStates);
-
-        /* Load requested visual state: */
-        UIVisualStateType requestedVisualState = gEDataManager->requestedVisualState(vboxGlobal().managedVMUuid());
-        /* Check if requested visual state type allowed: */
-        if (isVisualStateAllowed(requestedVisualState))
-        {
-            switch (requestedVisualState)
-            {
-                /* Direct transition to scale/fullscreen mode allowed: */
-                case UIVisualStateType_Scale: m_initialStateType = UIVisualStateType_Scale; break;
-                case UIVisualStateType_Fullscreen: m_initialStateType = UIVisualStateType_Fullscreen; break;
-                /* While to seamless is not, so we have to request transition on GA capability-change event: */
-                case UIVisualStateType_Seamless: uisession()->setRequestedVisualState(UIVisualStateType_Seamless); break;
-                default: break;
-            }
-        }
-    }
-}
-
-void UIMachine::saveSettings()
-{
-    /* Save 'visual state' option: */
+}
+
+void UIMachine::cleanupVisualState()
+{
+    /* Session UI can have requested visual state: */
     if (uisession())
     {
         /* Get requested visual state: */
         UIVisualStateType requestedVisualState = uisession()->requestedVisualState();
-
         /* If requested state is invalid: */
         if (requestedVisualState == UIVisualStateType_Invalid)
@@ -332,18 +337,24 @@
         gEDataManager->setRequestedVisualState(requestedVisualState, vboxGlobal().managedVMUuid());
     }
-}
-
-void UIMachine::cleanup()
-{
-    /* Save settings: */
-    saveSettings();
 
     /* Delete visual state: */
     delete m_pVisualState;
     m_pVisualState = 0;
-
+}
+
+void UIMachine::cleanupSession()
+{
     /* Destroy session UI if necessary: */
     if (uisession())
         UISession::destroy(m_pSession);
+}
+
+void UIMachine::cleanup()
+{
+    /* Cleanup visual state: */
+    cleanupVisualState();
+
+    /* Cleanup session UI: */
+    cleanupSession();
 
     /* Quit application: */
Index: trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h	(revision 53039)
+++ trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachine.h	(revision 53040)
@@ -84,8 +84,13 @@
     /** Prepare routine. */
     bool prepare();
-    /** Prepare routine: Loading stuff. */
-    void loadSettings();
-    /** Cleanup routine: Saving stuff. */
-    void saveSettings();
+    /** Prepare routine: Session stuff. */
+    bool prepareSession();
+    /** Prepare routine: Visual state stuff. */
+    void prepareVisualState();
+
+    /** Cleanup routine: Visual state stuff. */
+    void cleanupVisualState();
+    /** Cleanup routine: Session stuff. */
+    void cleanupSession();
     /** Cleanup routine. */
     void cleanup();
