PageRenderTime 461ms CodeModel.GetById 172ms app.highlight 71ms RepoModel.GetById 106ms app.codeStats 1ms

/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
 28#include "llviewerprecompiledheaders.h"
 29
 30#include "llpanelvoiceeffect.h"
 31
 32#include "llcombobox.h"
 33#include "llfloaterreg.h"
 34#include "llpanel.h"
 35#include "lltrans.h"
 36#include "lltransientfloatermgr.h"
 37#include "llvoiceclient.h"
 38
 39static LLRegisterPanelClassWrapper<LLPanelVoiceEffect> t_panel_voice_effect("panel_voice_effect");
 40
 41LLPanelVoiceEffect::LLPanelVoiceEffect()
 42	: mVoiceEffectCombo(NULL)
 43{
 44	mCommitCallbackRegistrar.add("Voice.CommitVoiceEffect", boost::bind(&LLPanelVoiceEffect::onCommitVoiceEffect, this));
 45}
 46
 47LLPanelVoiceEffect::~LLPanelVoiceEffect()
 48{
 49	LLView* combo_list_view = mVoiceEffectCombo->getChildView("ComboBox");
 50	LLTransientFloaterMgr::getInstance()->removeControlView(combo_list_view);
 51
 52	if(LLVoiceClient::instanceExists())
 53	{
 54		LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
 55		if (effect_interface)
 56		{
 57			effect_interface->removeObserver(this);
 58		}
 59	}
 60}
 61
 62// virtual
 63BOOL LLPanelVoiceEffect::postBuild()
 64{
 65	mVoiceEffectCombo = getChild<LLComboBox>("voice_effect");
 66
 67	// Need to tell LLTransientFloaterMgr about the combo list, otherwise it can't
 68	// be clicked while in a docked floater as it extends outside the floater area.
 69	LLView* combo_list_view = mVoiceEffectCombo->getChildView("ComboBox");
 70	LLTransientFloaterMgr::getInstance()->addControlView(combo_list_view);
 71
 72	LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
 73	if (effect_interface)
 74	{
 75		effect_interface->addObserver(this);
 76	}
 77
 78	update(true);
 79
 80	return TRUE;
 81}
 82
 83//////////////////////////////////////////////////////////////////////////
 84/// PRIVATE SECTION
 85//////////////////////////////////////////////////////////////////////////
 86
 87void LLPanelVoiceEffect::onCommitVoiceEffect()
 88{
 89	LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
 90	if (!effect_interface)
 91	{
 92		mVoiceEffectCombo->setEnabled(false);
 93		return;
 94	}
 95
 96	LLSD value = mVoiceEffectCombo->getValue();
 97	if (value.asInteger() == PREVIEW_VOICE_EFFECTS)
 98	{
 99		// Open the Voice Morph preview floater
100		LLFloaterReg::showInstance("voice_effect");
101	}
102	else if (value.asInteger() == GET_VOICE_EFFECTS)
103	{
104		// Open the voice morphing info web page
105		LLWeb::loadURL(LLTrans::getString("voice_morphing_url"));
106	}
107	else
108	{
109		effect_interface->setVoiceEffect(value.asUUID());
110	}
111
112	mVoiceEffectCombo->setValue(effect_interface->getVoiceEffect());
113}
114
115// virtual
116void LLPanelVoiceEffect::onVoiceEffectChanged(bool effect_list_updated)
117{
118	update(effect_list_updated);
119}
120
121void LLPanelVoiceEffect::update(bool list_updated)
122{
123	if (mVoiceEffectCombo)
124	{
125		LLVoiceEffectInterface* effect_interface = LLVoiceClient::instance().getVoiceEffectInterface();
126		llassert(effect_interface);
127		if (!effect_interface) return;
128		if (list_updated)
129		{
130			// Add the default "No Voice Morph" entry.
131			mVoiceEffectCombo->removeall();
132			mVoiceEffectCombo->add(getString("no_voice_effect"), LLUUID::null);
133			mVoiceEffectCombo->addSeparator();
134
135			// Add entries for each Voice Morph.
136			const voice_effect_list_t& effect_list = effect_interface->getVoiceEffectList();
137			if (!effect_list.empty())
138			{
139				for (voice_effect_list_t::const_iterator it = effect_list.begin(); it != effect_list.end(); ++it)
140				{
141					mVoiceEffectCombo->add(it->first, it->second, ADD_BOTTOM);
142				}
143
144				mVoiceEffectCombo->addSeparator();
145			}
146
147			// Add the fixed entries to go to the preview floater or marketing page.
148			mVoiceEffectCombo->add(getString("preview_voice_effects"), PREVIEW_VOICE_EFFECTS);
149			mVoiceEffectCombo->add(getString("get_voice_effects"), GET_VOICE_EFFECTS);
150		}
151
152		if (effect_interface && LLVoiceClient::instance().isVoiceWorking())
153		{
154			// Select the current Voice Morph.
155			mVoiceEffectCombo->setValue(effect_interface->getVoiceEffect());
156			mVoiceEffectCombo->setEnabled(true);
157		}
158		else
159		{
160			// If voice isn't working or Voice Effects are not supported disable the control.
161			mVoiceEffectCombo->setValue(LLUUID::null);
162			mVoiceEffectCombo->setEnabled(false);
163		}
164	}
165}