/indra/newview/llpanelvoiceeffect.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 165 lines · 103 code · 22 blank · 40 comment · 17 complexity · 10ae0dcc1c04111f249cc1b04b06fdca MD5 · raw file

  1. /**
  2. * @file llpanelvoiceeffect.cpp
  3. * @author Aimee
  4. * @brief Panel to select Voice Morphs.
  5. *
  6. * $LicenseInfo:firstyear=2010&license=viewerlgpl$
  7. * Second Life Viewer Source Code
  8. * Copyright (C) 2010, Linden Research, Inc.
  9. *
  10. * This library is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU Lesser General Public
  12. * License as published by the Free Software Foundation;
  13. * version 2.1 of the License only.
  14. *
  15. * This library is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18. * Lesser General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Lesser General Public
  21. * License along with this library; if not, write to the Free Software
  22. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  23. *
  24. * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
  25. * $/LicenseInfo$
  26. */
  27. #include "llviewerprecompiledheaders.h"
  28. #include "llpanelvoiceeffect.h"
  29. #include "llcombobox.h"
  30. #include "llfloaterreg.h"
  31. #include "llpanel.h"
  32. #include "lltrans.h"
  33. #include "lltransientfloatermgr.h"
  34. #include "llvoiceclient.h"
  35. static LLRegisterPanelClassWrapper<LLPanelVoiceEffect> t_panel_voice_effect("panel_voice_effect");
  36. LLPanelVoiceEffect::LLPanelVoiceEffect()
  37. : mVoiceEffectCombo(NULL)
  38. {
  39. mCommitCallbackRegistrar.add("Voice.CommitVoiceEffect", boost::bind(&LLPanelVoiceEffect::onCommitVoiceEffect, this));
  40. }
  41. LLPanelVoiceEffect::~LLPanelVoiceEffect()
  42. {
  43. LLView* combo_list_view = mVoiceEffectCombo->getChildView("ComboBox");
  44. LLTransientFloaterMgr::getInstance()->removeControlView(combo_list_view);
  45. if(LLVoiceClient::instanceExists())
  46. {
  47. LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
  48. if (effect_interface)
  49. {
  50. effect_interface->removeObserver(this);
  51. }
  52. }
  53. }
  54. // virtual
  55. BOOL LLPanelVoiceEffect::postBuild()
  56. {
  57. mVoiceEffectCombo = getChild<LLComboBox>("voice_effect");
  58. // Need to tell LLTransientFloaterMgr about the combo list, otherwise it can't
  59. // be clicked while in a docked floater as it extends outside the floater area.
  60. LLView* combo_list_view = mVoiceEffectCombo->getChildView("ComboBox");
  61. LLTransientFloaterMgr::getInstance()->addControlView(combo_list_view);
  62. LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
  63. if (effect_interface)
  64. {
  65. effect_interface->addObserver(this);
  66. }
  67. update(true);
  68. return TRUE;
  69. }
  70. //////////////////////////////////////////////////////////////////////////
  71. /// PRIVATE SECTION
  72. //////////////////////////////////////////////////////////////////////////
  73. void LLPanelVoiceEffect::onCommitVoiceEffect()
  74. {
  75. LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
  76. if (!effect_interface)
  77. {
  78. mVoiceEffectCombo->setEnabled(false);
  79. return;
  80. }
  81. LLSD value = mVoiceEffectCombo->getValue();
  82. if (value.asInteger() == PREVIEW_VOICE_EFFECTS)
  83. {
  84. // Open the Voice Morph preview floater
  85. LLFloaterReg::showInstance("voice_effect");
  86. }
  87. else if (value.asInteger() == GET_VOICE_EFFECTS)
  88. {
  89. // Open the voice morphing info web page
  90. LLWeb::loadURL(LLTrans::getString("voice_morphing_url"));
  91. }
  92. else
  93. {
  94. effect_interface->setVoiceEffect(value.asUUID());
  95. }
  96. mVoiceEffectCombo->setValue(effect_interface->getVoiceEffect());
  97. }
  98. // virtual
  99. void LLPanelVoiceEffect::onVoiceEffectChanged(bool effect_list_updated)
  100. {
  101. update(effect_list_updated);
  102. }
  103. void LLPanelVoiceEffect::update(bool list_updated)
  104. {
  105. if (mVoiceEffectCombo)
  106. {
  107. LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
  108. llassert(effect_interface);
  109. if (!effect_interface) return;
  110. if (list_updated)
  111. {
  112. // Add the default "No Voice Morph" entry.
  113. mVoiceEffectCombo->removeall();
  114. mVoiceEffectCombo->add(getString("no_voice_effect"), LLUUID::null);
  115. mVoiceEffectCombo->addSeparator();
  116. // Add entries for each Voice Morph.
  117. const voice_effect_list_t& effect_list = effect_interface->getVoiceEffectList();
  118. if (!effect_list.empty())
  119. {
  120. for (voice_effect_list_t::const_iterator it = effect_list.begin(); it != effect_list.end(); ++it)
  121. {
  122. mVoiceEffectCombo->add(it->first, it->second, ADD_BOTTOM);
  123. }
  124. mVoiceEffectCombo->addSeparator();
  125. }
  126. // Add the fixed entries to go to the preview floater or marketing page.
  127. mVoiceEffectCombo->add(getString("preview_voice_effects"), PREVIEW_VOICE_EFFECTS);
  128. mVoiceEffectCombo->add(getString("get_voice_effects"), GET_VOICE_EFFECTS);
  129. }
  130. if (effect_interface && LLVoiceClient::instance().isVoiceWorking())
  131. {
  132. // Select the current Voice Morph.
  133. mVoiceEffectCombo->setValue(effect_interface->getVoiceEffect());
  134. mVoiceEffectCombo->setEnabled(true);
  135. }
  136. else
  137. {
  138. // If voice isn't working or Voice Effects are not supported disable the control.
  139. mVoiceEffectCombo->setValue(LLUUID::null);
  140. mVoiceEffectCombo->setEnabled(false);
  141. }
  142. }
  143. }