Index: trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsAudio.cpp
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsAudio.cpp	(revision 46634)
+++ trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsAudio.cpp	(revision 46641)
@@ -7,5 +7,5 @@
 
 /*
- * Copyright (C) 2006-2012 Oracle Corporation
+ * Copyright (C) 2006-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -27,8 +27,6 @@
 UIMachineSettingsAudio::UIMachineSettingsAudio()
 {
-    /* Apply UI decorations */
-    Ui::UIMachineSettingsAudio::setupUi (this);
-    /* Applying language settings */
-    retranslateUi();
+    /* Prepare: */
+    prepare();
 }
 
@@ -72,6 +70,6 @@
     /* Load audio data to page: */
     m_pCheckBoxAudio->setChecked(audioData.m_fAudioEnabled);
-    m_pComboAudioDriver->setCurrentIndex(m_pComboAudioDriver->findText(gpConverter->toString(audioData.m_audioDriverType)));
-    m_pComboAudioController->setCurrentIndex(m_pComboAudioController->findText(gpConverter->toString(audioData.m_audioControllerType)));
+    m_pComboAudioDriver->setCurrentIndex(m_pComboAudioDriver->findData((int)audioData.m_audioDriverType));
+    m_pComboAudioController->setCurrentIndex(m_pComboAudioController->findData((int)audioData.m_audioControllerType));
 
     /* Polish page finally: */
@@ -88,6 +86,6 @@
     /* Gather audio data: */
     audioData.m_fAudioEnabled = m_pCheckBoxAudio->isChecked();
-    audioData.m_audioDriverType = gpConverter->fromString<KAudioDriverType>(m_pComboAudioDriver->currentText());
-    audioData.m_audioControllerType = gpConverter->fromString<KAudioControllerType>(m_pComboAudioController->currentText());
+    audioData.m_audioDriverType = static_cast<KAudioDriverType>(m_pComboAudioDriver->itemData(m_pComboAudioDriver->currentIndex()).toInt());
+    audioData.m_audioControllerType = static_cast<KAudioControllerType>(m_pComboAudioController->itemData(m_pComboAudioController->currentIndex()).toInt());
 
     /* Cache audio data: */
@@ -102,10 +100,10 @@
     UISettingsPageMachine::fetchData(data);
 
-    /* Check if audio data was changed: */
-    if (m_cache.wasChanged())
+    /* Make sure machine is in 'offline' mode & audio data was changed: */
+    if (isMachineOffline() && m_cache.wasChanged())
     {
         /* Check if adapter still valid: */
-        CAudioAdapter adapter = m_machine.GetAudioAdapter();
-        if (!adapter.isNull())
+        CAudioAdapter audioAdapter = m_machine.GetAudioAdapter();
+        if (!audioAdapter.isNull())
         {
             /* Get audio data from cache: */
@@ -113,10 +111,7 @@
 
             /* Store audio data: */
-            if (isMachineOffline())
-            {
-                adapter.SetEnabled(audioData.m_fAudioEnabled);
-                adapter.SetAudioDriver(audioData.m_audioDriverType);
-                adapter.SetAudioController(audioData.m_audioControllerType);
-            }
+            audioAdapter.SetEnabled(audioData.m_fAudioEnabled);
+            audioAdapter.SetAudioDriver(audioData.m_audioDriverType);
+            audioAdapter.SetAudioController(audioData.m_audioControllerType);
         }
     }
@@ -126,75 +121,131 @@
 }
 
-void UIMachineSettingsAudio::setOrderAfter (QWidget *aWidget)
-{
-    setTabOrder (aWidget, m_pCheckBoxAudio);
-    setTabOrder (m_pCheckBoxAudio, m_pComboAudioDriver);
-    setTabOrder (m_pComboAudioDriver, m_pComboAudioController);
+void UIMachineSettingsAudio::setOrderAfter(QWidget *pWidget)
+{
+    /* Audio-page order: */
+    setTabOrder(pWidget, m_pCheckBoxAudio);
+    setTabOrder(m_pCheckBoxAudio, m_pComboAudioDriver);
+    setTabOrder(m_pComboAudioDriver, m_pComboAudioController);
 }
 
 void UIMachineSettingsAudio::retranslateUi()
 {
-    /* Translate uic generated strings */
-    Ui::UIMachineSettingsAudio::retranslateUi (this);
-    /* Fill the comboboxes */
-    prepareComboboxes();
-}
-
-void UIMachineSettingsAudio::prepareComboboxes()
-{
-    /* Save the current selected value */
-    int currentDriver = m_pComboAudioDriver->currentIndex();
-    /* Clear the driver box */
-    m_pComboAudioDriver->clear();
-    /* Refill them */
-    m_pComboAudioDriver->addItem (gpConverter->toString (KAudioDriverType_Null));
-#if defined Q_WS_WIN32
-    m_pComboAudioDriver->addItem (gpConverter->toString (KAudioDriverType_DirectSound));
+    /* Translate generated strings: */
+    Ui::UIMachineSettingsAudio::retranslateUi(this);
+
+
+    /* Translate audio-driver combo.
+     * Make sure this order corresponds the same in prepareComboboxes(): */
+    int iIndex = -1;
+
+    m_pComboAudioDriver->setItemText(++iIndex, gpConverter->toString(KAudioDriverType_Null));
+
+#ifdef Q_OS_WIN
+    m_pComboAudioDriver->setItemText(++iIndex, gpConverter->toString(KAudioDriverType_DirectSound));
 # ifdef VBOX_WITH_WINMM
-    m_pComboAudioDriver->addItem (gpConverter->toString (KAudioDriverType_WinMM));
-# endif
-#endif
-#if defined Q_OS_SOLARIS
-    m_pComboAudioDriver->addItem (gpConverter->toString (KAudioDriverType_SolAudio));
-# if defined VBOX_WITH_SOLARIS_OSS
-    m_pComboAudioDriver->addItem (gpConverter->toString (KAudioDriverType_OSS));
-#endif
-#endif
+    m_pComboAudioDriver->setItemText(++iIndex, gpConverter->toString(KAudioDriverType_WinMM));
+# endif /* VBOX_WITH_WINMM */
+#endif /* Q_OS_WIN */
+
+#ifdef Q_OS_SOLARIS
+    m_pComboAudioDriver->setItemText(++iIndex, gpConverter->toString(KAudioDriverType_SolAudio));
+# ifdef VBOX_WITH_SOLARIS_OSS
+    m_pComboAudioDriver->setItemText(++iIndex, gpConverter->toString(KAudioDriverType_OSS));
+# endif /* VBOX_WITH_SOLARIS_OSS */
+#endif /* Q_OS_SOLARIS */
+
 #if defined Q_OS_LINUX || defined Q_OS_FREEBSD
-    m_pComboAudioDriver->addItem (gpConverter->toString (KAudioDriverType_OSS));
+    m_pComboAudioDriver->setItemText(++iIndex, gpConverter->toString(KAudioDriverType_OSS));
 # ifdef VBOX_WITH_PULSE
-    m_pComboAudioDriver->addItem (gpConverter->toString (KAudioDriverType_Pulse));
-# endif
-#endif
-#if defined Q_OS_LINUX
+    m_pComboAudioDriver->setItemText(++iIndex, gpConverter->toString(KAudioDriverType_Pulse));
+# endif /* VBOX_WITH_PULSE */
+#endif /* Q_OS_LINUX | Q_OS_FREEBSD */
+
+#ifdef Q_OS_LINUX
 # ifdef VBOX_WITH_ALSA
-    m_pComboAudioDriver->addItem (gpConverter->toString (KAudioDriverType_ALSA));
-# endif
-#endif
-#if defined Q_OS_MACX
-    m_pComboAudioDriver->addItem (gpConverter->toString (KAudioDriverType_CoreAudio));
-#endif
-    /* Set the old value */
-    m_pComboAudioDriver->setCurrentIndex (currentDriver);
-
-    /* Save the current selected value */
-    int currentController = m_pComboAudioController->currentIndex();
-    /* Clear the controller box */
-    m_pComboAudioController->clear();
-    /* Refill them */
-    m_pComboAudioController->insertItem (m_pComboAudioController->count(),
-        gpConverter->toString (KAudioControllerType_HDA));
-    m_pComboAudioController->insertItem (m_pComboAudioController->count(),
-        gpConverter->toString (KAudioControllerType_AC97));
-    m_pComboAudioController->insertItem (m_pComboAudioController->count(),
-        gpConverter->toString (KAudioControllerType_SB16));
-    /* Set the old value */
-    m_pComboAudioController->setCurrentIndex (currentController);
+    m_pComboAudioDriver->setItemText(++iIndex, gpConverter->toString(KAudioDriverType_ALSA));
+# endif /* VBOX_WITH_ALSA */
+#endif /* Q_OS_LINUX */
+
+#ifdef Q_OS_MACX
+    m_pComboAudioDriver->setItemText(++iIndex, gpConverter->toString(KAudioDriverType_CoreAudio));
+#endif /* Q_OS_MACX */
+
+
+    /* Translate audio-controller combo.
+     * Make sure this order corresponds the same in prepareComboboxes(): */
+    iIndex = -1;
+
+    m_pComboAudioController->setItemText(++iIndex, gpConverter->toString(KAudioControllerType_HDA));
+    m_pComboAudioController->setItemText(++iIndex, gpConverter->toString(KAudioControllerType_AC97));
+    m_pComboAudioController->setItemText(++iIndex, gpConverter->toString(KAudioControllerType_SB16));
 }
 
 void UIMachineSettingsAudio::polishPage()
 {
+    /* Polish audio-page availability: */
     m_pContainerAudioOptions->setEnabled(isMachineOffline());
     m_pContainerAudioSubOptions->setEnabled(m_pCheckBoxAudio->isChecked());
 }
 
+void UIMachineSettingsAudio::prepare()
+{
+    /* Apply UI decorations: */
+    Ui::UIMachineSettingsAudio::setupUi(this);
+
+    /* Prepare combo-boxes: */
+    prepareComboboxes();
+
+    /* Translate finally: */
+    retranslateUi();
+}
+
+void UIMachineSettingsAudio::prepareComboboxes()
+{
+    /* Prepare audio-driver combo.
+     * Make sure this order corresponds the same in retranslateUi(): */
+    int iIndex = -1;
+
+    m_pComboAudioDriver->insertItem(++iIndex, "", KAudioDriverType_Null);
+
+#ifdef Q_OS_WIN
+    m_pComboAudioDriver->insertItem(++iIndex, "", KAudioDriverType_DirectSound);
+# ifdef VBOX_WITH_WINMM
+    m_pComboAudioDriver->insertItem(++iIndex, "", KAudioDriverType_WinMM);
+# endif /* VBOX_WITH_WINMM */
+#endif /* Q_OS_WIN */
+
+#ifdef Q_OS_SOLARIS
+    m_pComboAudioDriver->insertItem(++iIndex, "", KAudioDriverType_SolAudio);
+# ifdef VBOX_WITH_SOLARIS_OSS
+    m_pComboAudioDriver->insertItem(++iIndex, "", KAudioDriverType_OSS);
+# endif /* VBOX_WITH_SOLARIS_OSS */
+#endif /* Q_OS_SOLARIS */
+
+#if defined Q_OS_LINUX || defined Q_OS_FREEBSD
+    m_pComboAudioDriver->insertItem(++iIndex, "", KAudioDriverType_OSS);
+# ifdef VBOX_WITH_PULSE
+    m_pComboAudioDriver->insertItem(++iIndex, "", KAudioDriverType_Pulse);
+# endif /* VBOX_WITH_PULSE */
+#endif /* Q_OS_LINUX | Q_OS_FREEBSD */
+
+#ifdef Q_OS_LINUX
+# ifdef VBOX_WITH_ALSA
+    m_pComboAudioDriver->insertItem(++iIndex, "", KAudioDriverType_ALSA);
+# endif /* VBOX_WITH_ALSA */
+#endif /* Q_OS_LINUX */
+
+#ifdef Q_OS_MACX
+    m_pComboAudioDriver->insertItem(++iIndex, "", KAudioDriverType_CoreAudio);
+#endif /* Q_OS_MACX */
+
+
+    /* Prepare audio-controller combo.
+     * Make sure this order corresponds the same in retranslateUi(): */
+    iIndex = -1;
+
+    m_pComboAudioController->insertItem(++iIndex, "", KAudioControllerType_HDA);
+    m_pComboAudioController->insertItem(++iIndex, "", KAudioControllerType_AC97);
+    m_pComboAudioController->insertItem(++iIndex, "", KAudioControllerType_SB16);
+}
+
Index: trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsAudio.h
===================================================================
--- trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsAudio.h	(revision 46634)
+++ trunk/src/VBox/Frontends/VirtualBox/src/settings/machine/UIMachineSettingsAudio.h	(revision 46641)
@@ -6,5 +6,5 @@
 
 /*
- * Copyright (C) 2006-2012 Oracle Corporation
+ * Copyright (C) 2006-2013 Oracle Corporation
  *
  * This file is part of VirtualBox Open Source Edition (OSE), as
@@ -27,10 +27,11 @@
 struct UIDataSettingsMachineAudio
 {
-    /* Default constructor: */
+    /* Constructor: */
     UIDataSettingsMachineAudio()
         : m_fAudioEnabled(false)
         , m_audioDriverType(KAudioDriverType_Null)
         , m_audioControllerType(KAudioControllerType_AC97) {}
-    /* Functions: */
+
+    /* Helpers: Compare functions/operators: */
     bool equal(const UIDataSettingsMachineAudio &other) const
     {
@@ -39,7 +40,7 @@
                (m_audioControllerType == other.m_audioControllerType);
     }
-    /* Operators: */
     bool operator==(const UIDataSettingsMachineAudio &other) const { return equal(other); }
     bool operator!=(const UIDataSettingsMachineAudio &other) const { return !equal(other); }
+
     /* Variables: */
     bool m_fAudioEnabled;
@@ -50,6 +51,5 @@
 
 /* Machine settings / Audio page: */
-class UIMachineSettingsAudio : public UISettingsPageMachine,
-                            public Ui::UIMachineSettingsAudio
+class UIMachineSettingsAudio : public UISettingsPageMachine, public Ui::UIMachineSettingsAudio
 {
     Q_OBJECT;
@@ -57,7 +57,11 @@
 public:
 
+    /* Constructor: */
     UIMachineSettingsAudio();
 
 protected:
+
+    /* API: Cache stuff: */
+    bool changed() const { return m_cache.wasChanged(); }
 
     /* Load data to cache from corresponding external object(s),
@@ -75,16 +79,18 @@
     void saveFromCacheTo(QVariant &data);
 
-    /* Page changed: */
-    bool changed() const { return m_cache.wasChanged(); }
+    /* API: Focus-order stuff: */
+    void setOrderAfter(QWidget *pWidget);
 
-    void setOrderAfter (QWidget *aWidget);
+    /* Helper: Translate stuff: */
+    void retranslateUi();
 
-    void retranslateUi();
+    /* Helper: Polish stuff: */
+    void polishPage();
 
 private:
 
+    /* Helpers: Prepare stuff: */
+    void prepare();
     void prepareComboboxes();
-
-    void polishPage();
 
     /* Cache: */
