PageRenderTime 38ms CodeModel.GetById 18ms app.highlight 17ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llfloatermediasettings.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 314 lines | 203 code | 46 blank | 65 comment | 18 complexity | 7bf76fa964ae09ef01e6bbbec2af9803 MD5 | raw file
  1/** 
  2 * @file llfloatermediasettings.cpp
  3 * @brief Tabbed dialog for media settings - class implementation
  4 *
  5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27#include "llviewerprecompiledheaders.h"
 28
 29#include "llfloaterreg.h"
 30#include "llfloatermediasettings.h"
 31#include "llpanelmediasettingsgeneral.h"
 32#include "llpanelmediasettingssecurity.h"
 33#include "llpanelmediasettingspermissions.h"
 34#include "llviewercontrol.h"
 35#include "lluictrlfactory.h"
 36#include "llbutton.h"
 37#include "llselectmgr.h"
 38#include "llsdutil.h"
 39
 40LLFloaterMediaSettings* LLFloaterMediaSettings::sInstance = NULL;
 41
 42////////////////////////////////////////////////////////////////////////////////
 43// 
 44LLFloaterMediaSettings::LLFloaterMediaSettings(const LLSD& key)
 45	: LLFloater(key),
 46	mTabContainer(NULL),
 47	mPanelMediaSettingsGeneral(NULL),
 48	mPanelMediaSettingsSecurity(NULL),
 49	mPanelMediaSettingsPermissions(NULL),
 50	mWaitingToClose( false ),
 51	mIdenticalHasMediaInfo( true ),
 52	mMultipleMedia(false),
 53	mMultipleValidMedia(false)
 54{
 55}
 56
 57////////////////////////////////////////////////////////////////////////////////
 58//
 59LLFloaterMediaSettings::~LLFloaterMediaSettings()
 60{
 61	if ( mPanelMediaSettingsGeneral )
 62	{
 63		delete mPanelMediaSettingsGeneral;
 64		mPanelMediaSettingsGeneral = NULL;
 65	}
 66
 67	if ( mPanelMediaSettingsSecurity )
 68	{
 69		delete mPanelMediaSettingsSecurity;
 70		mPanelMediaSettingsSecurity = NULL;
 71	}
 72
 73	if ( mPanelMediaSettingsPermissions )
 74	{
 75		delete mPanelMediaSettingsPermissions;
 76		mPanelMediaSettingsPermissions = NULL;
 77	}
 78
 79	sInstance = NULL;
 80}
 81
 82////////////////////////////////////////////////////////////////////////////////
 83//
 84BOOL LLFloaterMediaSettings::postBuild()
 85{
 86	mApplyBtn = getChild<LLButton>("Apply");
 87	mApplyBtn->setClickedCallback(onBtnApply, this);
 88		
 89	mCancelBtn = getChild<LLButton>("Cancel");
 90	mCancelBtn->setClickedCallback(onBtnCancel, this);
 91
 92	mOKBtn = getChild<LLButton>("OK");
 93	mOKBtn->setClickedCallback(onBtnOK, this);
 94			
 95	mTabContainer = getChild<LLTabContainer>( "tab_container" );
 96	
 97	mPanelMediaSettingsGeneral = new LLPanelMediaSettingsGeneral();
 98	mTabContainer->addTabPanel( 
 99			LLTabContainer::TabPanelParams().
100			panel(mPanelMediaSettingsGeneral));
101	mPanelMediaSettingsGeneral->setParent( this );
102
103	// note that "permissions" tab is really "Controls" tab - refs to 'perms' and
104	// 'permissions' not changed to 'controls' since we don't want to change 
105	// shared files in server code and keeping everything the same seemed best.
106	mPanelMediaSettingsPermissions = new LLPanelMediaSettingsPermissions();
107	mTabContainer->addTabPanel( 
108			LLTabContainer::TabPanelParams().
109			panel(mPanelMediaSettingsPermissions));
110
111	mPanelMediaSettingsSecurity = new LLPanelMediaSettingsSecurity();
112	mTabContainer->addTabPanel( 
113			LLTabContainer::TabPanelParams().
114			panel(mPanelMediaSettingsSecurity));
115	mPanelMediaSettingsSecurity->setParent( this );
116		
117	// restore the last tab viewed from persistance variable storage
118	if (!mTabContainer->selectTab(gSavedSettings.getS32("LastMediaSettingsTab")))
119	{
120		mTabContainer->selectFirstTab();
121	};
122
123	sInstance = this;
124
125	return TRUE;
126}
127
128//static 
129LLFloaterMediaSettings* LLFloaterMediaSettings::getInstance()
130{
131	if ( !sInstance )
132	{
133		sInstance = (LLFloaterReg::getTypedInstance<LLFloaterMediaSettings>("media_settings"));
134	}
135	
136	return sInstance;
137}
138
139//static 
140void LLFloaterMediaSettings::apply()
141{
142	if (sInstance->haveValuesChanged())
143	{
144		LLSD settings;
145		sInstance->mPanelMediaSettingsGeneral->preApply();
146		sInstance->mPanelMediaSettingsGeneral->getValues( settings, false );
147		sInstance->mPanelMediaSettingsSecurity->preApply();
148		sInstance->mPanelMediaSettingsSecurity->getValues( settings, false );
149		sInstance->mPanelMediaSettingsPermissions->preApply();
150		sInstance->mPanelMediaSettingsPermissions->getValues( settings, false );
151			
152		LLSelectMgr::getInstance()->selectionSetMedia( LLTextureEntry::MF_HAS_MEDIA, settings );
153
154		sInstance->mPanelMediaSettingsGeneral->postApply();
155		sInstance->mPanelMediaSettingsSecurity->postApply();
156		sInstance->mPanelMediaSettingsPermissions->postApply();
157	}
158}
159
160////////////////////////////////////////////////////////////////////////////////
161void LLFloaterMediaSettings::onClose(bool app_quitting)
162{
163	if(mPanelMediaSettingsGeneral)
164	{
165		mPanelMediaSettingsGeneral->onClose(app_quitting);
166	}
167	LLFloaterReg::hideInstance("whitelist_entry");
168}
169
170////////////////////////////////////////////////////////////////////////////////
171//static 
172void LLFloaterMediaSettings::initValues( const LLSD& media_settings, bool editable )
173{
174	if (sInstance->hasFocus()) return;
175	
176	sInstance->clearValues(editable);
177	// update all panels with values from simulator
178	sInstance->mPanelMediaSettingsGeneral->
179		initValues( sInstance->mPanelMediaSettingsGeneral, media_settings, editable );
180
181	sInstance->mPanelMediaSettingsSecurity->
182		initValues( sInstance->mPanelMediaSettingsSecurity, media_settings, editable );
183
184	sInstance->mPanelMediaSettingsPermissions->
185		initValues( sInstance->mPanelMediaSettingsPermissions, media_settings, editable );
186	
187	// Squirrel away initial values 
188	sInstance->mInitialValues.clear();
189	sInstance->mPanelMediaSettingsGeneral->getValues( sInstance->mInitialValues );
190	sInstance->mPanelMediaSettingsSecurity->getValues( sInstance->mInitialValues );
191	sInstance->mPanelMediaSettingsPermissions->getValues( sInstance->mInitialValues );
192	
193	sInstance->mApplyBtn->setEnabled(editable);
194	sInstance->mOKBtn->setEnabled(editable);
195}
196
197////////////////////////////////////////////////////////////////////////////////
198// 
199void LLFloaterMediaSettings::commitFields()
200{
201	if (hasFocus())
202	{
203		LLUICtrl* cur_focus = dynamic_cast<LLUICtrl*>(gFocusMgr.getKeyboardFocus());
204		if (cur_focus && cur_focus->acceptsTextInput())
205		{
206			cur_focus->onCommit();
207		};
208	};
209}
210
211////////////////////////////////////////////////////////////////////////////////
212//static 
213void LLFloaterMediaSettings::clearValues( bool editable)
214{
215	if (sInstance)
216	{
217		// clean up all panels before updating
218		sInstance->mPanelMediaSettingsGeneral	 ->clearValues(sInstance->mPanelMediaSettingsGeneral,  editable);
219		sInstance->mPanelMediaSettingsSecurity	 ->clearValues(sInstance->mPanelMediaSettingsSecurity,	editable);
220		sInstance->mPanelMediaSettingsPermissions->clearValues(sInstance->mPanelMediaSettingsPermissions,  editable);
221	}
222}
223
224////////////////////////////////////////////////////////////////////////////////
225// static
226void LLFloaterMediaSettings::onBtnOK( void* userdata )
227{
228	sInstance->commitFields();
229
230	sInstance->apply();
231
232	sInstance->closeFloater();
233}
234
235////////////////////////////////////////////////////////////////////////////////
236// static
237void LLFloaterMediaSettings::onBtnApply( void* userdata )
238{
239	sInstance->commitFields();
240
241	sInstance->apply();
242
243	sInstance->mInitialValues.clear();
244	sInstance->mPanelMediaSettingsGeneral->getValues( sInstance->mInitialValues );
245	sInstance->mPanelMediaSettingsSecurity->getValues( sInstance->mInitialValues );
246	sInstance->mPanelMediaSettingsPermissions->getValues( sInstance->mInitialValues );
247
248}
249
250////////////////////////////////////////////////////////////////////////////////
251// static
252void LLFloaterMediaSettings::onBtnCancel( void* userdata )
253{
254	sInstance->closeFloater(); 
255}
256
257////////////////////////////////////////////////////////////////////////////////
258// static
259void LLFloaterMediaSettings::onTabChanged(void* user_data, bool from_click)
260{
261	LLTabContainer* self = (LLTabContainer*)user_data;
262	gSavedSettings.setS32("LastMediaSettingsTab", self->getCurrentPanelIndex());
263}
264////////////////////////////////////////////////////////////////////////////////
265//
266const std::string LLFloaterMediaSettings::getHomeUrl()
267{
268	if ( mPanelMediaSettingsGeneral )
269		return mPanelMediaSettingsGeneral->getHomeUrl();
270	else
271		return std::string( "" );
272}
273
274////////////////////////////////////////////////////////////////////////////////
275// virtual 
276void LLFloaterMediaSettings::draw()
277{
278	if (NULL != mApplyBtn)
279	{
280		// Set the enabled state of the "Apply" button if values changed
281		mApplyBtn->setEnabled( haveValuesChanged() );
282	}
283	
284	LLFloater::draw();
285}
286
287
288//private
289bool LLFloaterMediaSettings::haveValuesChanged() const
290{
291	bool values_changed = false;
292	// *NOTE: The code below is very inefficient.  Better to do this
293	// only when data change.
294	// Every frame, check to see what the values are.  If they are not
295	// the same as the initial media data, enable the OK/Apply buttons
296	LLSD settings;
297	sInstance->mPanelMediaSettingsGeneral->getValues( settings );
298	sInstance->mPanelMediaSettingsSecurity->getValues( settings );
299	sInstance->mPanelMediaSettingsPermissions->getValues( settings );	
300	LLSD::map_const_iterator iter = settings.beginMap();
301	LLSD::map_const_iterator end = settings.endMap();
302	for ( ; iter != end; ++iter )
303	{
304		const std::string &current_key = iter->first;
305		const LLSD &current_value = iter->second;
306		if ( ! llsd_equals(current_value, mInitialValues[current_key]))
307		{
308			values_changed = true;
309			break;
310		}
311	}
312	return values_changed;
313}
314