From 4e23f4b74c05d23aeb52b822e1ffbcc871118a51 Mon Sep 17 00:00:00 2001
From: Vadim ProductEngine <vsavchuk@productengine.com>
Date: Tue, 26 Jul 2011 23:14:02 +0300
Subject: [PATCH] STORM-1405 WIP Localized the "No Device" and "Default System
 Device" strings in the sound devices panel.

By the way, fixed improper localization of the "Default" device name
which caused saving a localized string in settings.
---
 indra/newview/llpanelvoicedevicesettings.cpp  | 50 +++++++++++++------
 indra/newview/llpanelvoicedevicesettings.h    |  3 ++
 .../default/xui/en/panel_sound_devices.xml    |  8 +++
 3 files changed, 45 insertions(+), 16 deletions(-)

diff --git a/indra/newview/llpanelvoicedevicesettings.cpp b/indra/newview/llpanelvoicedevicesettings.cpp
index 94d65c5db2c..6be2ea6481c 100644
--- a/indra/newview/llpanelvoicedevicesettings.cpp
+++ b/indra/newview/llpanelvoicedevicesettings.cpp
@@ -41,6 +41,7 @@
 
 
 static LLRegisterPanelClassWrapper<LLPanelVoiceDeviceSettings> t_panel_group_general("panel_voice_device_settings");
+static const std::string DEFAULT_DEVICE("Default");
 
 
 LLPanelVoiceDeviceSettings::LLPanelVoiceDeviceSettings()
@@ -75,6 +76,10 @@ BOOL LLPanelVoiceDeviceSettings::postBuild()
 		boost::bind(&LLPanelVoiceDeviceSettings::onCommitInputDevice, this));
 	mCtrlOutputDevices->setCommitCallback(
 		boost::bind(&LLPanelVoiceDeviceSettings::onCommitOutputDevice, this));
+
+	mLocalizedDeviceNames[DEFAULT_DEVICE]				= getString("default_text");
+	mLocalizedDeviceNames["No Device"]					= getString("name_no_device");
+	mLocalizedDeviceNames["Default System Device"]		= getString("name_default_system_device");
 	
 	return TRUE;
 }
@@ -141,14 +146,14 @@ void LLPanelVoiceDeviceSettings::apply()
 	std::string s;
 	if(mCtrlInputDevices)
 	{
-		s = mCtrlInputDevices->getSimple();
+		s = mCtrlInputDevices->getValue().asString();
 		gSavedSettings.setString("VoiceInputAudioDevice", s);
 		mInputDevice = s;
 	}
 
 	if(mCtrlOutputDevices)
 	{
-		s = mCtrlOutputDevices->getSimple();
+		s = mCtrlOutputDevices->getValue().asString();
 		gSavedSettings.setString("VoiceOutputAudioDevice", s);
 		mOutputDevice = s;
 	}
@@ -169,10 +174,10 @@ void LLPanelVoiceDeviceSettings::cancel()
 	gSavedSettings.setString("VoiceOutputAudioDevice", mOutputDevice);
 
 	if(mCtrlInputDevices)
-		mCtrlInputDevices->setSimple(mInputDevice);
+		mCtrlInputDevices->setValue(mInputDevice);
 
 	if(mCtrlOutputDevices)
-		mCtrlOutputDevices->setSimple(mOutputDevice);
+		mCtrlOutputDevices->setValue(mOutputDevice);
 
 	gSavedSettings.setF32("AudioLevelMic", mMicVolume);
 	LLSlider* volume_slider = getChild<LLSlider>("mic_volume_slider");
@@ -212,14 +217,14 @@ void LLPanelVoiceDeviceSettings::refresh()
 		if(mCtrlInputDevices)
 		{
 			mCtrlInputDevices->removeall();
-			mCtrlInputDevices->add( mInputDevice, ADD_BOTTOM );
-			mCtrlInputDevices->setSimple(mInputDevice);
+			mCtrlInputDevices->add(getLocalizedDeviceName(mInputDevice), mInputDevice, ADD_BOTTOM);
+			mCtrlInputDevices->setValue(mInputDevice);
 		}
 		if(mCtrlOutputDevices)
 		{
 			mCtrlOutputDevices->removeall();
-			mCtrlOutputDevices->add( mOutputDevice, ADD_BOTTOM );
-			mCtrlOutputDevices->setSimple(mOutputDevice);
+			mCtrlOutputDevices->add(getLocalizedDeviceName(mOutputDevice), mOutputDevice, ADD_BOTTOM);
+			mCtrlOutputDevices->setValue(mOutputDevice);
 		}
 		mDevicesUpdated = FALSE;
 	}
@@ -230,35 +235,41 @@ void LLPanelVoiceDeviceSettings::refresh()
 		if(mCtrlInputDevices)
 		{
 			mCtrlInputDevices->removeall();
-			mCtrlInputDevices->add( getString("default_text"), ADD_BOTTOM );
+			mCtrlInputDevices->add(getLocalizedDeviceName(DEFAULT_DEVICE), DEFAULT_DEVICE, ADD_BOTTOM);
 
 			for(iter=LLVoiceClient::getInstance()->getCaptureDevices().begin(); 
 				iter != LLVoiceClient::getInstance()->getCaptureDevices().end();
 				iter++)
 			{
-				mCtrlInputDevices->add( *iter, ADD_BOTTOM );
+				mCtrlInputDevices->add(getLocalizedDeviceName(*iter), *iter, ADD_BOTTOM);
 			}
 
-			if(!mCtrlInputDevices->setSimple(mInputDevice))
+			// Fix invalid input audio device preference.
+			if (!mCtrlInputDevices->setSelectedByValue(mInputDevice, TRUE))
 			{
-				mCtrlInputDevices->setSimple(getString("default_text"));
+				mCtrlInputDevices->setValue(DEFAULT_DEVICE);
+				gSavedSettings.setString("VoiceInputAudioDevice", DEFAULT_DEVICE);
+				mInputDevice = DEFAULT_DEVICE;
 			}
 		}
 		
 		if(mCtrlOutputDevices)
 		{
 			mCtrlOutputDevices->removeall();
-			mCtrlOutputDevices->add( getString("default_text"), ADD_BOTTOM );
+			mCtrlOutputDevices->add(getLocalizedDeviceName(DEFAULT_DEVICE), DEFAULT_DEVICE, ADD_BOTTOM);
 
 			for(iter= LLVoiceClient::getInstance()->getRenderDevices().begin(); 
 				iter !=  LLVoiceClient::getInstance()->getRenderDevices().end(); iter++)
 			{
-				mCtrlOutputDevices->add( *iter, ADD_BOTTOM );
+				mCtrlOutputDevices->add(getLocalizedDeviceName(*iter), *iter, ADD_BOTTOM);
 			}
 
-			if(!mCtrlOutputDevices->setSimple(mOutputDevice))
+			// Fix invalid output audio device preference.
+			if (!mCtrlOutputDevices->setSelectedByValue(mOutputDevice, TRUE))
 			{
-				mCtrlOutputDevices->setSimple(getString("default_text"));
+				mCtrlOutputDevices->setValue(DEFAULT_DEVICE);
+				gSavedSettings.setString("VoiceOutputAudioDevice", DEFAULT_DEVICE);
+				mOutputDevice = DEFAULT_DEVICE;
 			}
 		}
 		mDevicesUpdated = TRUE;
@@ -292,6 +303,13 @@ void LLPanelVoiceDeviceSettings::cleanup()
 	}
 }
 
+// returns English name if no translation found
+std::string LLPanelVoiceDeviceSettings::getLocalizedDeviceName(const std::string& en_dev_name)
+{
+	std::map<std::string, std::string>::const_iterator it = mLocalizedDeviceNames.find(en_dev_name);
+	return it != mLocalizedDeviceNames.end() ? it->second : en_dev_name;
+}
+
 void LLPanelVoiceDeviceSettings::onCommitInputDevice()
 {
 	if(LLVoiceClient::getInstance())
diff --git a/indra/newview/llpanelvoicedevicesettings.h b/indra/newview/llpanelvoicedevicesettings.h
index d09476d4697..ba3bcad0dc2 100644
--- a/indra/newview/llpanelvoicedevicesettings.h
+++ b/indra/newview/llpanelvoicedevicesettings.h
@@ -49,6 +49,8 @@ class LLPanelVoiceDeviceSettings : public LLPanel
 	void setUseTuningMode(bool use) { mUseTuningMode = use; };
 	
 protected:
+	std::string getLocalizedDeviceName(const std::string& en_dev_name);
+
 	void onCommitInputDevice();
 	void onCommitOutputDevice();
 
@@ -59,6 +61,7 @@ class LLPanelVoiceDeviceSettings : public LLPanel
 	class LLComboBox		*mCtrlOutputDevices;
 	BOOL mDevicesUpdated;
 	bool mUseTuningMode;
+	std::map<std::string, std::string> mLocalizedDeviceNames;
 };
 
 #endif // LL_LLPANELVOICEDEVICESETTINGS_H
diff --git a/indra/newview/skins/default/xui/en/panel_sound_devices.xml b/indra/newview/skins/default/xui/en/panel_sound_devices.xml
index 0a20a4a9656..46cbc1e87fd 100644
--- a/indra/newview/skins/default/xui/en/panel_sound_devices.xml
+++ b/indra/newview/skins/default/xui/en/panel_sound_devices.xml
@@ -11,6 +11,14 @@
       name="default_text">
         Default
     </panel.string>
+    <string
+     name="name_no_device">
+        No Device
+    </string>
+    <string
+     name="name_default_system_device">
+        Default System Device
+    </string>
     <icon
      follows="left|top"
      height="18"
-- 
GitLab