PageRenderTime 72ms CodeModel.GetById 27ms app.highlight 40ms RepoModel.GetById 2ms app.codeStats 0ms

/indra/newview/llpanelmediasettingspermissions.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 284 lines | 186 code | 29 blank | 69 comment | 21 complexity | 591ecbf8ebdf005d4a2ac744b365b0e2 MD5 | raw file
  1/**
  2 * @file llpanelmediasettingspermissions.cpp
  3 * @brief LLPanelMediaSettingsPermissions class implementation
  4 *
  5 * note that "permissions" tab is really "Controls" tab - refs to 'perms' and
  6 * 'permissions' not changed to 'controls' since we don't want to change 
  7 * shared files in server code and keeping everything the same seemed best.
  8 *
  9 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
 10 * Second Life Viewer Source Code
 11 * Copyright (C) 2010, Linden Research, Inc.
 12 * 
 13 * This library is free software; you can redistribute it and/or
 14 * modify it under the terms of the GNU Lesser General Public
 15 * License as published by the Free Software Foundation;
 16 * version 2.1 of the License only.
 17 * 
 18 * This library is distributed in the hope that it will be useful,
 19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 21 * Lesser General Public License for more details.
 22 * 
 23 * You should have received a copy of the GNU Lesser General Public
 24 * License along with this library; if not, write to the Free Software
 25 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 26 * 
 27 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 28 * $/LicenseInfo$
 29 */
 30
 31#include "llviewerprecompiledheaders.h"
 32
 33#include "llpanelmediasettingspermissions.h"
 34#include "llpanelcontents.h"
 35#include "llcombobox.h"
 36#include "llcheckboxctrl.h"
 37#include "llspinctrl.h"
 38#include "llurlhistory.h"
 39#include "lluictrlfactory.h"
 40#include "llwindow.h"
 41#include "llviewerwindow.h"
 42#include "llsdutil.h"
 43#include "llselectmgr.h"
 44#include "llmediaentry.h"
 45#include "llnamebox.h"
 46#include "lltrans.h"
 47#include "llfloatermediasettings.h"
 48
 49////////////////////////////////////////////////////////////////////////////////
 50//
 51LLPanelMediaSettingsPermissions::LLPanelMediaSettingsPermissions() :
 52	mControls( NULL ),
 53    mPermsOwnerInteract( 0 ),
 54    mPermsOwnerControl( 0 ),
 55	mPermsGroupName( 0 ),
 56    mPermsGroupInteract( 0 ),
 57    mPermsGroupControl( 0 ),
 58    mPermsWorldInteract( 0 ),
 59    mPermsWorldControl( 0 )
 60{
 61    // build dialog from XML
 62    buildFromFile( "panel_media_settings_permissions.xml");
 63}
 64
 65////////////////////////////////////////////////////////////////////////////////
 66//
 67BOOL LLPanelMediaSettingsPermissions::postBuild()
 68{
 69    // connect member vars with UI widgets
 70	mControls = getChild< LLComboBox >( LLMediaEntry::CONTROLS_KEY );
 71    mPermsOwnerInteract = getChild< LLCheckBoxCtrl >( LLPanelContents::PERMS_OWNER_INTERACT_KEY );
 72    mPermsOwnerControl = getChild< LLCheckBoxCtrl >( LLPanelContents::PERMS_OWNER_CONTROL_KEY );
 73    mPermsGroupInteract = getChild< LLCheckBoxCtrl >( LLPanelContents::PERMS_GROUP_INTERACT_KEY );
 74    mPermsGroupControl = getChild< LLCheckBoxCtrl >( LLPanelContents::PERMS_GROUP_CONTROL_KEY );
 75    mPermsWorldInteract = getChild< LLCheckBoxCtrl >( LLPanelContents::PERMS_ANYONE_INTERACT_KEY );
 76    mPermsWorldControl = getChild< LLCheckBoxCtrl >( LLPanelContents::PERMS_ANYONE_CONTROL_KEY );
 77
 78	mPermsGroupName = getChild< LLNameBox >( "perms_group_name" );
 79
 80    return true;
 81}
 82
 83////////////////////////////////////////////////////////////////////////////////
 84// virtual
 85LLPanelMediaSettingsPermissions::~LLPanelMediaSettingsPermissions()
 86{
 87}
 88
 89////////////////////////////////////////////////////////////////////////////////
 90// virtual
 91void LLPanelMediaSettingsPermissions::draw()
 92{
 93	// housekeeping
 94	LLPanel::draw();
 95
 96	getChild<LLUICtrl>("perms_group_name")->setValue(LLStringUtil::null);
 97	LLUUID group_id;
 98	BOOL groups_identical = LLSelectMgr::getInstance()->selectGetGroup(group_id);
 99	if (groups_identical)
100	{
101		if(mPermsGroupName)
102		{
103			mPermsGroupName->setNameID(group_id, true);
104		}
105	}
106	else
107	{
108		if(mPermsGroupName)
109		{
110			mPermsGroupName->setNameID(LLUUID::null, TRUE);
111			mPermsGroupName->refresh(LLUUID::null, std::string(), true);
112		}
113	}
114}
115
116////////////////////////////////////////////////////////////////////////////////
117// static 
118void LLPanelMediaSettingsPermissions::clearValues( void* userdata, bool editable)
119{	
120	LLPanelMediaSettingsPermissions *self =(LLPanelMediaSettingsPermissions *)userdata;
121
122	self->mControls->clear();
123	self->mPermsOwnerInteract->clear();
124	self->mPermsOwnerControl->clear();
125	self->mPermsGroupInteract->clear();
126	self->mPermsGroupControl->clear();
127	self->mPermsWorldInteract->clear();
128	self->mPermsWorldControl->clear();
129	
130	self->mControls->setEnabled(editable);
131	self->mPermsOwnerInteract->setEnabled(editable);
132	self->mPermsOwnerControl->setEnabled(editable);
133	self->mPermsGroupInteract->setEnabled(editable);
134	self->mPermsGroupControl->setEnabled(editable);
135	self->mPermsWorldInteract->setEnabled(editable);
136	self->mPermsWorldControl->setEnabled(editable);
137
138	self->getChild< LLTextBox >("controls_label")->setEnabled(editable);
139	self->getChild< LLTextBox >("owner_label")->setEnabled(editable);
140	self->getChild< LLTextBox >("group_label")->setEnabled(editable);
141	self->getChild< LLNameBox >("perms_group_name")->setEnabled(editable);
142	self->getChild< LLTextBox >("anyone_label")->setEnabled(editable);
143}
144
145////////////////////////////////////////////////////////////////////////////////
146// static 
147void LLPanelMediaSettingsPermissions::initValues( void* userdata, const LLSD& media_settings ,  bool editable)
148{
149    LLPanelMediaSettingsPermissions *self =(LLPanelMediaSettingsPermissions *)userdata;
150    std::string base_key( "" );
151    std::string tentative_key( "" );
152
153    struct 
154    {
155        std::string key_name;
156        LLUICtrl* ctrl_ptr;
157        std::string ctrl_type;
158
159    } data_set [] = 
160    { 
161		{ LLMediaEntry::CONTROLS_KEY,					self->mControls,			"LLComboBox" },
162        { LLPanelContents::PERMS_OWNER_INTERACT_KEY,    self->mPermsOwnerInteract,  "LLCheckBoxCtrl" },
163        { LLPanelContents::PERMS_OWNER_CONTROL_KEY,     self->mPermsOwnerControl,   "LLCheckBoxCtrl" },
164        { LLPanelContents::PERMS_GROUP_INTERACT_KEY,    self->mPermsGroupInteract,  "LLCheckBoxCtrl" },
165        { LLPanelContents::PERMS_GROUP_CONTROL_KEY,     self->mPermsGroupControl,   "LLCheckBoxCtrl" },
166        { LLPanelContents::PERMS_ANYONE_INTERACT_KEY,   self->mPermsWorldInteract,  "LLCheckBoxCtrl" },
167        { LLPanelContents::PERMS_ANYONE_CONTROL_KEY,    self->mPermsWorldControl,   "LLCheckBoxCtrl" },
168        { "", NULL , "" }
169    };
170
171    for( int i = 0; data_set[ i ].key_name.length() > 0; ++i )
172    {
173        base_key = std::string( data_set[ i ].key_name );
174        tentative_key = base_key + std::string( LLPanelContents::TENTATIVE_SUFFIX );
175
176        // TODO: CP - I bet there is a better way to do this using Boost
177        if ( media_settings[ base_key ].isDefined() )
178        {
179            if ( data_set[ i ].ctrl_type == "LLCheckBoxCtrl" )
180            {
181				// Most recent change to the "sense" of these checkboxes
182				// means the value in the checkbox matches that on the server
183                static_cast< LLCheckBoxCtrl* >( data_set[ i ].ctrl_ptr )->
184                    setValue( media_settings[ base_key ].asBoolean() );
185            }
186            else
187            if ( data_set[ i ].ctrl_type == "LLComboBox" )
188                static_cast< LLComboBox* >( data_set[ i ].ctrl_ptr )->
189                    setCurrentByIndex( media_settings[ base_key ].asInteger() );
190
191			data_set[ i ].ctrl_ptr->setEnabled(editable);
192            data_set[ i ].ctrl_ptr->setTentative( media_settings[ tentative_key ].asBoolean() );
193        };
194    };
195
196	// *NOTE: If any of a particular flavor is tentative, we have to disable 
197	// them all because of an architectural issue: namely that we represent 
198	// these as a bit field, and we can't selectively apply only one bit to all selected
199	// faces if they don't match.  Also see the *NOTE below.
200	if ( self->mPermsOwnerInteract->getTentative() ||
201		 self->mPermsGroupInteract->getTentative() ||
202		 self->mPermsWorldInteract->getTentative())
203	{
204		self->mPermsOwnerInteract->setEnabled(false);
205		self->mPermsGroupInteract->setEnabled(false);
206		self->mPermsWorldInteract->setEnabled(false);
207	}	
208	if ( self->mPermsOwnerControl->getTentative() ||
209		 self->mPermsGroupControl->getTentative() ||
210		 self->mPermsWorldControl->getTentative())
211	{
212		self->mPermsOwnerControl->setEnabled(false);
213		self->mPermsGroupControl->setEnabled(false);
214		self->mPermsWorldControl->setEnabled(false);
215	}
216	
217	self->getChild< LLTextBox >("controls_label")->setEnabled(editable);
218	self->getChild< LLTextBox >("owner_label")->setEnabled(editable);
219	self->getChild< LLTextBox >("group_label")->setEnabled(editable);
220	self->getChild< LLNameBox >("perms_group_name")->setEnabled(editable);
221	self->getChild< LLTextBox >("anyone_label")->setEnabled(editable);
222}
223
224////////////////////////////////////////////////////////////////////////////////
225// 
226void LLPanelMediaSettingsPermissions::preApply()
227{
228    // no-op
229}
230
231////////////////////////////////////////////////////////////////////////////////
232//
233void LLPanelMediaSettingsPermissions::getValues( LLSD &fill_me_in, bool include_tentative )
234{
235	// moved over from the 'General settings' tab
236	if (include_tentative || !mControls->getTentative()) fill_me_in[LLMediaEntry::CONTROLS_KEY] = (LLSD::Integer)mControls->getCurrentIndex();
237	
238	// *NOTE: For some reason, gcc does not like these symbol references in the 
239	// expressions below (inside the static_casts).	 I have NO idea why :(.
240	// For some reason, assigning them to const temp vars here fixes the link
241	// error.  Bizarre.
242	const U8 none = LLMediaEntry::PERM_NONE;
243	const U8 owner = LLMediaEntry::PERM_OWNER;
244	const U8 group = LLMediaEntry::PERM_GROUP;
245	const U8 anyone = LLMediaEntry::PERM_ANYONE; 
246	const LLSD::Integer control = static_cast<LLSD::Integer>(
247		(mPermsOwnerControl->getValue() ? owner : none ) |
248		(mPermsGroupControl->getValue() ? group: none  ) |
249		(mPermsWorldControl->getValue() ? anyone : none ));
250	const LLSD::Integer interact = static_cast<LLSD::Integer>(
251		(mPermsOwnerInteract->getValue() ? owner: none	) |
252		(mPermsGroupInteract->getValue() ? group : none ) |
253		(mPermsWorldInteract->getValue() ? anyone : none ));
254	
255	// *TODO: This will fill in the values of all permissions values, even if
256	// one or more is tentative.  This is not quite the user expectation...what
257	// it should do is only change the bit that was made "untentative", but in
258	// a multiple-selection situation, this isn't possible given the architecture
259	// for how settings are applied.
260	if (include_tentative || 
261		!mPermsOwnerControl->getTentative() || 
262		!mPermsGroupControl->getTentative() || 
263		!mPermsWorldControl->getTentative())
264	{
265		fill_me_in[LLMediaEntry::PERMS_CONTROL_KEY] = control;
266	}
267	if (include_tentative || 
268		!mPermsOwnerInteract->getTentative() || 
269		!mPermsGroupInteract->getTentative() || 
270		!mPermsWorldInteract->getTentative())
271	{
272		fill_me_in[LLMediaEntry::PERMS_INTERACT_KEY] = interact;
273	}
274}
275
276
277////////////////////////////////////////////////////////////////////////////////
278// 
279void LLPanelMediaSettingsPermissions::postApply()
280{
281    // no-op
282}
283
284