llprefsvoice.cpp 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298
  1. /**
  2. * @file llprefsvoice.cpp
  3. * @author Richard Nelson
  4. * @brief Voice chat preferences panel
  5. *
  6. * $LicenseInfo:firstyear=2003&license=viewergpl$
  7. *
  8. * Copyright (c) 2003-2009, Linden Research, Inc.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #include "llviewerprecompiledheaders.h"
  34. #include "llprefsvoice.h"
  35. #include "llbutton.h"
  36. #include "llcheckboxctrl.h"
  37. #include "llkeyboard.h"
  38. #include "llmodaldialog.h"
  39. #include "lluictrlfactory.h"
  40. #include "llfloatervoicedevicesettings.h"
  41. #include "llstartup.h" // For LLStartUp::isLoggedIn()
  42. #include "llviewercontrol.h"
  43. #include "llvoiceclient.h"
  44. //*****************************************************************************
  45. // LLVoiceSetKeyDialog class
  46. //*****************************************************************************
  47. class LLVoiceSetKeyDialog final : public LLModalDialog
  48. {
  49. public:
  50. LLVoiceSetKeyDialog(LLPrefsVoice* parent);
  51. void onFocusReceived() override;
  52. void onFocusLost() override;
  53. bool handleKeyHere(KEY key, MASK mask) override;
  54. static void onCancel(void* user_data);
  55. private:
  56. LLPrefsVoice* mParent;
  57. };
  58. LLVoiceSetKeyDialog::LLVoiceSetKeyDialog(LLPrefsVoice* parent)
  59. : LLModalDialog(LLStringUtil::null, 240, 100),
  60. mParent(parent)
  61. {
  62. LLUICtrlFactory::getInstance()->buildFloater(this,
  63. "floater_select_key.xml");
  64. childSetAction("Cancel", onCancel, this);
  65. childSetFocus("Cancel");
  66. }
  67. //virtual
  68. void LLVoiceSetKeyDialog::onFocusReceived()
  69. {
  70. gFocusMgr.setKeystrokesOnly(true);
  71. }
  72. //virtual
  73. void LLVoiceSetKeyDialog::onFocusLost()
  74. {
  75. gFocusMgr.setKeystrokesOnly(false);
  76. }
  77. bool LLVoiceSetKeyDialog::handleKeyHere(KEY key, MASK mask)
  78. {
  79. bool result = true;
  80. if (key == 'Q' && mask == MASK_CONTROL)
  81. {
  82. result = false;
  83. }
  84. else
  85. {
  86. mParent->setKey(key);
  87. }
  88. close();
  89. return result;
  90. }
  91. //static
  92. void LLVoiceSetKeyDialog::onCancel(void* user_data)
  93. {
  94. LLVoiceSetKeyDialog* self = (LLVoiceSetKeyDialog*)user_data;
  95. self->close();
  96. }
  97. //*****************************************************************************
  98. // LLPrefsVoice class proper
  99. //*****************************************************************************
  100. LLPrefsVoice::LLPrefsVoice()
  101. : LLPanel(std::string("Voice Chat Panel"))
  102. {
  103. LLUICtrlFactory::getInstance()->buildPanel(this,
  104. "panel_preferences_voice.xml");
  105. }
  106. //virtual
  107. bool LLPrefsVoice::postBuild()
  108. {
  109. mVivoxIcon = getChild<LLView>("vivox");
  110. mWebRTCText = getChild<LLView>("webrtc");
  111. mAGCCheck = getChild<LLView>("agc_check");
  112. mEchoCheck = getChild<LLView>("echo_check");
  113. mNoiseSpinner = getChild<LLView>("noise_suppression_level");
  114. childSetCommitCallback("enable_voice_check", onCommitEnableVoiceChat, this);
  115. childSetAction("set_voice_hotkey_button", onClickSetKey, this);
  116. childSetAction("set_voice_middlemouse_button", onClickSetMiddleMouse, this);
  117. mDeviceSettingsBtn = getChild<LLButton>("device_settings_btn");
  118. mDeviceSettingsBtn->setClickedCallback(onClickVoiceDeviceSettings, this);
  119. bool voice_disabled = gSavedSettings.getBool("CmdLineDisableVoice");
  120. childSetVisible("voice_unavailable", voice_disabled);
  121. childSetVisible("enable_voice_check", !voice_disabled);
  122. childSetEnabled("enable_voice_check", !voice_disabled);
  123. bool enable = !voice_disabled && gSavedSettings.getBool("EnableVoiceChat");
  124. childSetValue("enable_voice_check", enable);
  125. onCommitEnableVoiceChat(getChild<LLCheckBoxCtrl>("enable_voice_check"),
  126. this);
  127. childSetValue("modifier_combo",
  128. gSavedSettings.getString("PushToTalkButton"));
  129. childSetValue("voice_call_friends_only_check",
  130. gSavedSettings.getBool("VoiceCallsFriendsOnly"));
  131. childSetValue("auto_disengage_mic_check",
  132. gSavedSettings.getBool("AutoDisengageMic"));
  133. childSetValue("push_to_talk_toggle_check",
  134. gSavedSettings.getBool("PushToTalkToggle"));
  135. childSetValue("ear_location",
  136. gSavedSettings.getS32("VoiceEarLocation"));
  137. childSetValue("enable_lip_sync_check",
  138. gSavedSettings.getBool("LipSyncEnabled"));
  139. childSetValue("agc_check",
  140. gSavedSettings.getBool("VoiceWebRTCAutomaticGainControl"));
  141. childSetValue("echo_check",
  142. gSavedSettings.getBool("VoiceWebRTCEchoCancellation"));
  143. childSetValue("noise_suppression_level",
  144. gSavedSettings.getU32("VoiceWebRTCNoiseSuppression"));
  145. return true;
  146. }
  147. //virtual
  148. void LLPrefsVoice::draw()
  149. {
  150. bool logged_in = LLStartUp::isLoggedIn();
  151. mDeviceSettingsBtn->setEnabled(logged_in && gVoiceClient.isVoiceWorking());
  152. static LLCachedControl<std::string> server_type(gSavedSettings,
  153. "VoiceServerType");
  154. bool webrtc = server_type() == "webrtc";
  155. mVivoxIcon->setVisible(logged_in && !webrtc);
  156. mWebRTCText->setVisible(logged_in && webrtc);
  157. mAGCCheck->setVisible(logged_in && webrtc);
  158. mEchoCheck->setVisible(logged_in && webrtc);
  159. mNoiseSpinner->setVisible(logged_in && webrtc);
  160. LLPanel::draw();
  161. }
  162. void LLPrefsVoice::apply()
  163. {
  164. gSavedSettings.setBool("EnableVoiceChat",
  165. childGetValue("enable_voice_check"));
  166. gSavedSettings.setString("PushToTalkButton",
  167. childGetValue("modifier_combo"));
  168. gSavedSettings.setBool("VoiceCallsFriendsOnly",
  169. childGetValue("voice_call_friends_only_check"));
  170. gSavedSettings.setBool("AutoDisengageMic",
  171. childGetValue("auto_disengage_mic_check"));
  172. gSavedSettings.setBool("PushToTalkToggle",
  173. childGetValue("push_to_talk_toggle_check"));
  174. gSavedSettings.setS32("VoiceEarLocation",
  175. childGetValue("ear_location"));
  176. gSavedSettings.setBool("LipSyncEnabled",
  177. childGetValue("enable_lip_sync_check"));
  178. gSavedSettings.setBool("VoiceWebRTCAutomaticGainControl",
  179. childGetValue("agc_check"));
  180. gSavedSettings.setBool("VoiceWebRTCEchoCancellation",
  181. childGetValue("echo_check"));
  182. gSavedSettings.setU32("VoiceWebRTCNoiseSuppression",
  183. childGetValue("noise_suppression_level").asInteger());
  184. LLFloaterVoiceDeviceSettings* floaterp =
  185. LLFloaterVoiceDeviceSettings::findInstance();
  186. if (floaterp)
  187. {
  188. floaterp->apply();
  189. }
  190. if (mWebRTCText->getVisible())
  191. {
  192. // Propagate AGC, echo cancellation, noise suppression level...
  193. gVoiceClient.updateSettings();
  194. }
  195. }
  196. void LLPrefsVoice::cancel()
  197. {
  198. LLFloaterVoiceDeviceSettings* floaterp =
  199. LLFloaterVoiceDeviceSettings::findInstance();
  200. if (floaterp)
  201. {
  202. floaterp->cancel();
  203. }
  204. }
  205. void LLPrefsVoice::setKey(KEY key)
  206. {
  207. childSetValue("modifier_combo", LLKeyboard::stringFromKey(key));
  208. }
  209. //static
  210. void LLPrefsVoice::onCommitEnableVoiceChat(LLUICtrl* ctrl, void* user_data)
  211. {
  212. LLPrefsVoice* self = (LLPrefsVoice*)user_data;
  213. LLCheckBoxCtrl* enable_voice_chat = (LLCheckBoxCtrl*)ctrl;
  214. bool enable = enable_voice_chat->getValue();
  215. self->childSetEnabled("modifier_combo", enable);
  216. self->childSetEnabled("push_to_talk_label", enable);
  217. self->childSetEnabled("voice_call_friends_only_check", enable);
  218. self->childSetEnabled("auto_disengage_mic_check", enable);
  219. self->childSetEnabled("push_to_talk_toggle_check", enable);
  220. self->childSetEnabled("ear_location", enable);
  221. self->childSetEnabled("enable_lip_sync_check", enable);
  222. self->childSetEnabled("set_voice_hotkey_button", enable);
  223. self->childSetEnabled("set_voice_middlemouse_button", enable);
  224. self->childSetEnabled("device_settings_btn", enable);
  225. self->childSetEnabled("agc_check", enable);
  226. self->childSetEnabled("echo_check", enable);
  227. self->childSetEnabled("noise_suppression_level", enable);
  228. }
  229. //static
  230. void LLPrefsVoice::onClickSetKey(void* user_data)
  231. {
  232. LLPrefsVoice* self = (LLPrefsVoice*)user_data;
  233. LLVoiceSetKeyDialog* dialog = new LLVoiceSetKeyDialog(self);
  234. dialog->startModal();
  235. }
  236. //static
  237. void LLPrefsVoice::onClickSetMiddleMouse(void* user_data)
  238. {
  239. LLPrefsVoice* self = (LLPrefsVoice*)user_data;
  240. self->childSetValue("modifier_combo", "MiddleMouse");
  241. }
  242. //static
  243. void LLPrefsVoice::onClickVoiceDeviceSettings(void* user_data)
  244. {
  245. LLPrefsVoice* self = (LLPrefsVoice*)user_data;
  246. if (!self) return;
  247. LLFloater* floaterp = LLFloaterVoiceDeviceSettings::showInstance();
  248. if (floaterp && gFloaterViewp)
  249. {
  250. LLFloater* parentp = gFloaterViewp->getParentFloater(self);
  251. if (parentp)
  252. {
  253. parentp->addDependentFloater(floaterp, false);
  254. }
  255. }
  256. }