Index: /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp	(revision 37108)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/runtime/UIMachineLogic.cpp	(revision 37109)
@@ -952,37 +952,8 @@
         return;
 
-    /* Open shared session: */
-    CSession sharedSession = vboxGlobal().openSession(session().GetMachine().GetId(), true);
-    if (sharedSession.isNull())
-        return;
-
-    /* Get machine: */
-    CMachine sharedMachine = sharedSession.GetMachine();
-    if (sharedMachine.isNull())
-        return;
-
-    /* Prepare VM settings dialog: */
-    UISettingsDialog *pDlg = new UISettingsDialogMachine(defaultMachineWindow()->machineWindow(),
-                                                         SettingsDialogType_Online,
-                                                         sharedMachine, session().GetConsole(),
-                                                         strCategory, QString());
-    pDlg->loadData();
-
-    /* Show VM settings dialog: */
-    if (pDlg->exec() == QDialog::Accepted)
-    {
-        /* If dialog was accepted => save changed settings: */
-        pDlg->saveData();
-        sharedMachine.SaveSettings();
-        /* If settings were failed to be saved => show the error: */
-        if (!sharedMachine.isOk())
-            vboxProblem().cannotSaveMachineSettings(sharedMachine);
-    }
-
-    /* Delete VM settings dialog: */
-    delete pDlg;
-
-    /* Unlock machine: */
-    sharedSession.UnlockMachine();
+    /* Create and execute current VM settings dialog: */
+    UISettingsDialogMachine dlg(defaultMachineWindow()->machineWindow(),
+                                session().GetMachine().GetId(), strCategory, QString());
+    dlg.execute();
 }
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSelectorWnd.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSelectorWnd.cpp	(revision 37108)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/selector/VBoxSelectorWnd.cpp	(revision 37109)
@@ -592,14 +592,7 @@
 void VBoxSelectorWnd::fileSettings()
 {
-    VBoxGlobalSettings settings = vboxGlobal().settings();
-    CSystemProperties props = vboxGlobal().virtualBox().GetSystemProperties();
-
-    UISettingsDialog *dlg = new UISettingsDialogGlobal(this, SettingsDialogType_Offline);
-    dlg->loadData();
-
-    if (dlg->exec() == QDialog::Accepted)
-        dlg->saveData();
-
-    delete dlg;
+    /* Create and execute global settings dialog: */
+    UISettingsDialogGlobal dlg(this);
+    dlg.execute();
 }
 
@@ -697,20 +690,22 @@
  *  Opens the VM settings dialog.
  */
-void VBoxSelectorWnd::vmSettings(const QString &aCategory /* = QString::null */,
-                                 const QString &aControl /* = QString::null */,
-                                 const QString &aUuid /* = QString::null */)
-{
-    if (!aCategory.isEmpty() && aCategory [0] != '#')
-    {
-        /* Assume it's a href from the Details HTML */
-        vboxGlobal().openURL(aCategory);
+void VBoxSelectorWnd::vmSettings(const QString &strCategoryRef /* = QString::null */,
+                                 const QString &strControlRef /* = QString::null */,
+                                 const QString &strMachineId /* = QString::null */)
+{
+    /* Process href from VM details / description: */
+    if (!strCategoryRef.isEmpty() && strCategoryRef[0] != '#')
+    {
+        vboxGlobal().openURL(strCategoryRef);
         return;
     }
-    QString strCategory = aCategory;
-    QString strControl = aControl;
-    /* Maybe the control is coded into the URL by %% */
-    if (aControl == QString::null)
-    {
-        QStringList parts = aCategory.split("%%");
+
+    /* Get category and control: */
+    QString strCategory = strCategoryRef;
+    QString strControl = strControlRef;
+    /* Check if control is coded into the URL by %%: */
+    if (strControl.isEmpty())
+    {
+        QStringList parts = strCategory.split("%%");
         if (parts.size() == 2)
         {
@@ -720,38 +715,14 @@
     }
 
-    UIVMItem *pItem = aUuid.isNull() ? mVMListView->selectedItem() : mVMModel->itemById(aUuid);
-    AssertMsgReturnVoid(pItem, ("Item must be always selected here"));
-
-    SettingsDialogType dialogType = machineStateToSettingsDialogType(pItem->machineState());
-
-    CSession session = vboxGlobal().openSession(pItem->id(), dialogType != SettingsDialogType_Offline /* connect to existing? */);
-    AssertMsgReturnVoid(!session.isNull(), ("Session must not be null"));
-    CMachine machine = session.GetMachine();
-    AssertMsgReturnVoid(!machine.isNull(), ("Machine must not be null"));
-    CConsole console = dialogType == SettingsDialogType_Offline ? CConsole() : session.GetConsole();
-
-    /* Don't show the inaccessible warning if the user open the vm settings: */
+    /* Don't show the inaccessible warning if the user tries to open VM settings: */
     mDoneInaccessibleWarningOnce = true;
 
-    UISettingsDialog *pDlg = new UISettingsDialogMachine(this, dialogType, machine, console, strCategory, strControl);
-    pDlg->loadData();
-
-    if (pDlg->exec() == QDialog::Accepted)
-    {
-        pDlg->saveData();
-
-        machine.SaveSettings();
-        if (!machine.isOk())
-            vboxProblem().cannotSaveMachineSettings(machine);
-
-        /* To check use the result in future:
-         * vboxProblem().cannotApplyMachineSettings(m, res); */
-    }
-
-    delete pDlg;
-
-    mVMListView->setFocus();
-
-    session.UnlockMachine();
+    /* Get corresponding VM item: */
+    UIVMItem *pItem = strMachineId.isNull() ? mVMListView->selectedItem() : mVMModel->itemById(strMachineId);
+    AssertMsgReturnVoid(pItem, ("Item must be always selected here!\n"));
+
+    /* Create and execute corresponding VM settings dialog: */
+    UISettingsDialogMachine dlg(this, pItem->id(), strCategory, strControl);
+    dlg.execute();
 }
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.cpp	(revision 37108)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.cpp	(revision 37109)
@@ -43,5 +43,5 @@
 
 /* Settings Dialog Constructor: */
-UISettingsDialog::UISettingsDialog(QWidget *pParent, SettingsDialogType settingsDialogType)
+UISettingsDialog::UISettingsDialog(QWidget *pParent)
     /* Parent class: */
     : QIWithRetranslateUI<QIMainDialog>(pParent)
@@ -50,5 +50,5 @@
     , m_pStack(0)
     /* Common variables: */
-    , m_dialogType(settingsDialogType)
+    , m_dialogType(SettingsDialogType_Wrong)
     , m_fPolished(false)
     /* Loading/saving stuff: */
@@ -150,4 +150,17 @@
 }
 
+void UISettingsDialog::execute()
+{
+    /* Load data: */
+    loadData();
+
+    /* Execute dialog and wait for completion: */
+    if (exec() != QDialog::Accepted)
+        return;
+
+    /* Save data: */
+    saveData();
+}
+
 void UISettingsDialog::sltRevalidate(QIWidgetValidator *pValidator)
 {
@@ -254,4 +267,14 @@
         if (!pValidator->isValid())
             sltRevalidate(pValidator);
+    }
+}
+
+void UISettingsDialog::setDialogType(SettingsDialogType settingsDialogType)
+{
+    m_dialogType = settingsDialogType;
+    for (int iWidgetNumber = 0; iWidgetNumber < m_pStack->count(); ++iWidgetNumber)
+    {
+        UISettingsPage *pPage = static_cast<UISettingsPage*>(m_pStack->widget(iWidgetNumber));
+        pPage->setDialogType(dialogType());
     }
 }
Index: /trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.h	(revision 37108)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialog.h	(revision 37109)
@@ -46,10 +46,9 @@
 
     /* Settings Dialog Constructor/Destructor: */
-    UISettingsDialog(QWidget *pParent, SettingsDialogType settingsDialogType);
+    UISettingsDialog(QWidget *pParent);
    ~UISettingsDialog();
 
-    /* Save/Load interface: */
-    virtual void loadData() = 0;
-    virtual void saveData() = 0;
+    /* Execute API: */
+    void execute();
 
 protected slots:
@@ -70,4 +69,8 @@
 protected:
 
+    /* Save/load API: */
+    virtual void loadData() = 0;
+    virtual void saveData() = 0;
+
     /* UI translator: */
     virtual void retranslateUi();
@@ -75,4 +78,5 @@
     /* Dialog type: */
     SettingsDialogType dialogType() { return m_dialogType; }
+    void setDialogType(SettingsDialogType settingsDialogType);
     /* Dialog title: */
     virtual QString title() const = 0;
Index: /trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp	(revision 37108)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.cpp	(revision 37109)
@@ -32,4 +32,5 @@
 #include "QIWidgetValidator.h"
 #include "VBoxSettingsSelector.h"
+#include "UIVirtualBoxEventHandler.h"
 
 #include "UIGlobalSettingsGeneral.h"
@@ -305,6 +306,6 @@
 UISettingsSerializer* UISettingsSerializer::m_pInstance = 0;
 
-UISettingsDialogGlobal::UISettingsDialogGlobal(QWidget *pParent, SettingsDialogType settingsDialogType)
-    : UISettingsDialog(pParent, settingsDialogType)
+UISettingsDialogGlobal::UISettingsDialogGlobal(QWidget *pParent)
+    : UISettingsDialog(pParent)
 {
     /* Window icon: */
@@ -312,4 +313,7 @@
     setWindowIcon(QIcon(":/global_settings_16px.png"));
 #endif /* !Q_WS_MAC */
+
+    /* Assign default dialog type: */
+    setDialogType(SettingsDialogType_Offline);
 
     /* Creating settings pages: */
@@ -524,10 +528,8 @@
 }
 
-UISettingsDialogMachine::UISettingsDialogMachine(QWidget *pParent, SettingsDialogType settingsDialogType,
-                                                 const CMachine &machine, const CConsole &console,
+UISettingsDialogMachine::UISettingsDialogMachine(QWidget *pParent, const QString &strMachineId,
                                                  const QString &strCategory, const QString &strControl)
-    : UISettingsDialog(pParent, settingsDialogType)
-    , m_machine(machine)
-    , m_console(console)
+    : UISettingsDialog(pParent)
+    , m_strMachineId(strMachineId)
     , m_fAllowResetFirstRunFlag(false)
     , m_fResetFirstRunFlag(false)
@@ -540,4 +542,10 @@
     /* Allow to reset first-run flag just when medium enumeration was finished: */
     connect(&vboxGlobal(), SIGNAL(mediumEnumFinished(const VBoxMediaList &)), this, SLOT(sltAllowResetFirstRunFlag()));
+
+    /* Get corresponding machine (required to determine dialog type): */
+    m_machine = vboxGlobal().virtualBox().FindMachine(m_strMachineId);
+    AssertMsg(!m_machine.isNull(), ("Can't find corresponding machine!\n"));
+    /* Assign current dialog type: */
+    setDialogType(machineStateToSettingsDialogType(m_machine.GetState()));
 
     /* Creating settings pages: */
@@ -663,5 +671,5 @@
     retranslateUi();
 
-    /* Setup Settings Dialog: */
+    /* Setup settings dialog: */
     if (!strCategory.isNull())
     {
@@ -695,8 +703,29 @@
     else
         m_pSelector->selectById(0);
+
+    /* Make sure settings dialog will be updated on machine state changes: */
+    connect(gVBoxEvents, SIGNAL(sigMachineStateChange(QString, KMachineState)),
+            this, SLOT(sltMachineStateChanged(QString, KMachineState)));
+    connect(gVBoxEvents, SIGNAL(sigMachineDataChange(QString)),
+            this, SLOT(sltMachineDataChanged(QString)));
 }
 
 void UISettingsDialogMachine::loadData()
 {
+    /* Check that session is NOT created: */
+    if (!m_session.isNull())
+        return;
+
+    /* Prepare session: */
+    m_session = dialogType() == SettingsDialogType_Wrong ? CSession() : vboxGlobal().openSession(m_strMachineId, true /* shared */);
+    /* Check that session was created: */
+    if (m_session.isNull())
+        return;
+
+    /* Get machine from session: */
+    m_machine = m_session.GetMachine();
+    /* Get console from session: */
+    m_console = dialogType() == SettingsDialogType_Offline ? CConsole() : m_session.GetConsole();
+
     /* Prepare machine data: */
     qRegisterMetaType<UISettingsDataMachine>();
@@ -719,4 +748,20 @@
 void UISettingsDialogMachine::saveData()
 {
+    /* Check that session is NOT created: */
+    if (!m_session.isNull())
+        return;
+
+    /* Prepare session: */
+    bool fSessionShared = dialogType() != SettingsDialogType_Offline;
+    m_session = dialogType() == SettingsDialogType_Wrong ? CSession() : vboxGlobal().openSession(m_strMachineId, fSessionShared);
+    /* Check that session was created: */
+    if (m_session.isNull())
+        return;
+
+    /* Get machine from session: */
+    m_machine = m_session.GetMachine();
+    /* Get console from session: */
+    m_console = dialogType() == SettingsDialogType_Offline ? CConsole() : m_session.GetConsole();
+
     /* Prepare machine data: */
     qRegisterMetaType<UISettingsDataMachine>();
@@ -734,5 +779,4 @@
     /* Get updated machine: */
     m_machine = pMachineSettingsSaver->data().value<UISettingsDataMachine>().m_machine;
-    m_console = pMachineSettingsSaver->data().value<UISettingsDataMachine>().m_console;
     /* If machine is ok => perform final operations: */
     if (m_machine.isOk())
@@ -770,11 +814,15 @@
         if (m_fResetFirstRunFlag)
             m_machine.SetExtraData(VBoxDefs::GUI_FirstRun, QString::null);
-    }
-    /* If machine is NOT ok => show error message: */
-    else
-    {
-        /* Show final error message: */
+
+        /* Save settings finally: */
+        m_machine.SaveSettings();
+    }
+
+    /* If machine is NOT ok => show the error message: */
+    if (!m_machine.isOk())
         vboxProblem().cannotSaveMachineSettings(m_machine);
-    }
+
+    /* Mark page processed: */
+    sltMarkProcessed();
 }
 
@@ -967,4 +1015,53 @@
 
     return true;
+}
+
+void UISettingsDialogMachine::sltMarkProcessed()
+{
+    /* Call for base-class: */
+    UISettingsDialog::sltMarkProcessed();
+
+    /* Unlock the session if exists: */
+    if (!m_session.isNull())
+    {
+        m_session.UnlockMachine();
+        m_session = CSession();
+        m_machine = CMachine();
+        m_console = CConsole();
+    }
+}
+
+void UISettingsDialogMachine::sltMachineStateChanged(QString strMachineId, KMachineState machineState)
+{
+    /* Ignore if thats NOT our VM: */
+    if (strMachineId != m_strMachineId)
+        return;
+
+    /* Ignore if state was NOT actually changed: */
+    if (m_machineState == machineState)
+        return;
+
+    /* Update current machine state: */
+    m_machineState = machineState;
+
+    /* Get new dialog type: */
+    SettingsDialogType newDialogType = machineStateToSettingsDialogType(m_machineState);
+
+    /* Ignore if dialog type was NOT actually changed: */
+    if (dialogType() == newDialogType)
+        return;
+
+    /* Update current dialog type: */
+    setDialogType(newDialogType);
+}
+
+void UISettingsDialogMachine::sltMachineDataChanged(QString strMachineId)
+{
+    /* Ignore if thats NOT our VM: */
+    if (strMachineId != m_strMachineId)
+        return;
+
+    /* Reload data: */
+    loadData();
 }
 
Index: /trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.h
===================================================================
--- /trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.h	(revision 37108)
+++ /trunk/src/VBox/Frontends/VirtualBox/src/settings/UISettingsDialogSpecific.h	(revision 37109)
@@ -43,5 +43,5 @@
     };
 
-    UISettingsDialogGlobal(QWidget *pParent, SettingsDialogType settingsDialogType);
+    UISettingsDialogGlobal(QWidget *pParent);
 
 protected:
@@ -82,6 +82,5 @@
     };
 
-    UISettingsDialogMachine(QWidget *pParent, SettingsDialogType settingsDialogType,
-                            const CMachine &machine, const CConsole &console,
+    UISettingsDialogMachine(QWidget *pParent, const QString &strMachineId,
                             const QString &strCategory, const QString &strControl);
 
@@ -99,4 +98,7 @@
 private slots:
 
+    void sltMarkProcessed();
+    void sltMachineStateChanged(QString strMachineId, KMachineState machineState);
+    void sltMachineDataChanged(QString strMachineId);
     void sltCategoryChanged(int cId);
     void sltAllowResetFirstRunFlag();
@@ -108,4 +110,8 @@
     bool isPageAvailable(int iPageId);
 
+    QString m_strMachineId;
+    KMachineState m_machineState;
+
+    CSession m_session;
     CMachine m_machine;
     CConsole m_console;
