PageRenderTime 68ms CodeModel.GetById 41ms app.highlight 23ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llpanellandmedia.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 330 lines | 219 code | 56 blank | 55 comment | 23 complexity | f6ee5ae631c07bf444e054afe6193620 MD5 | raw file
  1/**
  2 * @file llpanellandmedia.cpp
  3 * @brief Allows configuration of "media" for a land parcel,
  4 *   for example movies, web pages, and audio.
  5 *
  6 * $LicenseInfo:firstyear=2007&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 "llpanellandmedia.h"
 31
 32// viewer includes
 33#include "llmimetypes.h"
 34#include "llviewerparcelmgr.h"
 35#include "llviewerregion.h"
 36#include "llviewermedia.h"
 37#include "llviewerparcelmedia.h"
 38#include "lluictrlfactory.h"
 39
 40// library includes
 41#include "llcheckboxctrl.h"
 42#include "llcombobox.h"
 43#include "llfloaterurlentry.h"
 44#include "llfocusmgr.h"
 45#include "lllineeditor.h"
 46#include "llparcel.h"
 47#include "lltextbox.h"
 48#include "llradiogroup.h"
 49#include "llspinctrl.h"
 50#include "llsdutil.h"
 51#include "lltexturectrl.h"
 52#include "roles_constants.h"
 53#include "llscrolllistctrl.h"
 54
 55//---------------------------------------------------------------------------
 56// LLPanelLandMedia
 57//---------------------------------------------------------------------------
 58
 59LLPanelLandMedia::LLPanelLandMedia(LLParcelSelectionHandle& parcel)
 60:	LLPanel(),
 61	mParcel(parcel),
 62	mMediaURLEdit(NULL),
 63	mMediaDescEdit(NULL),
 64	mMediaTypeCombo(NULL),
 65	mSetURLButton(NULL),
 66	mMediaHeightCtrl(NULL),
 67	mMediaWidthCtrl(NULL),
 68	mMediaSizeCtrlLabel(NULL),
 69	mMediaTextureCtrl(NULL),
 70	mMediaAutoScaleCheck(NULL),
 71	mMediaLoopCheck(NULL)
 72{
 73}
 74
 75
 76// virtual
 77LLPanelLandMedia::~LLPanelLandMedia()
 78{
 79}
 80
 81BOOL LLPanelLandMedia::postBuild()
 82{
 83
 84	mMediaTextureCtrl = getChild<LLTextureCtrl>("media texture");
 85	mMediaTextureCtrl->setCommitCallback( onCommitAny, this );
 86	mMediaTextureCtrl->setAllowNoTexture ( TRUE );
 87	mMediaTextureCtrl->setImmediateFilterPermMask(PERM_COPY | PERM_TRANSFER);
 88	mMediaTextureCtrl->setNonImmediateFilterPermMask(PERM_COPY | PERM_TRANSFER);
 89
 90	mMediaAutoScaleCheck = getChild<LLCheckBoxCtrl>("media_auto_scale");
 91	childSetCommitCallback("media_auto_scale", onCommitAny, this);
 92
 93	mMediaLoopCheck = getChild<LLCheckBoxCtrl>("media_loop");
 94	childSetCommitCallback("media_loop", onCommitAny, this );
 95
 96	mMediaURLEdit = getChild<LLLineEditor>("media_url");
 97	childSetCommitCallback("media_url", onCommitAny, this );
 98
 99	mMediaDescEdit = getChild<LLLineEditor>("url_description");
100	childSetCommitCallback("url_description", onCommitAny, this);
101
102	mMediaTypeCombo = getChild<LLComboBox>("media type");
103	childSetCommitCallback("media type", onCommitType, this);
104	populateMIMECombo();
105
106	mMediaWidthCtrl = getChild<LLSpinCtrl>("media_size_width");
107	childSetCommitCallback("media_size_width", onCommitAny, this);
108	mMediaHeightCtrl = getChild<LLSpinCtrl>("media_size_height");
109	childSetCommitCallback("media_size_height", onCommitAny, this);
110	mMediaSizeCtrlLabel = getChild<LLTextBox>("media_size");
111
112	mSetURLButton = getChild<LLButton>("set_media_url");
113	childSetAction("set_media_url", onSetBtn, this);
114
115	return TRUE;
116}
117
118
119// public
120void LLPanelLandMedia::refresh()
121{
122	LLParcel *parcel = mParcel->getParcel();
123
124	if (!parcel)
125	{
126		clearCtrls();
127	}
128	else
129	{
130		// something selected, hooray!
131
132		// Display options
133		BOOL can_change_media = LLViewerParcelMgr::isParcelModifiableByAgent(parcel, GP_LAND_CHANGE_MEDIA);
134
135		mMediaURLEdit->setText(parcel->getMediaURL());
136		mMediaURLEdit->setEnabled( FALSE );
137
138		getChild<LLUICtrl>("current_url")->setValue(parcel->getMediaCurrentURL());
139
140		mMediaDescEdit->setText(parcel->getMediaDesc());
141		mMediaDescEdit->setEnabled( can_change_media );
142
143		std::string mime_type = parcel->getMediaType();
144		if (mime_type.empty() || mime_type == LLMIMETypes::getDefaultMimeType())
145		{
146			mime_type = LLMIMETypes::getDefaultMimeTypeTranslation();
147		}
148		setMediaType(mime_type);
149		mMediaTypeCombo->setEnabled( can_change_media );
150		getChild<LLUICtrl>("mime_type")->setValue(mime_type);
151
152		mMediaAutoScaleCheck->set( parcel->getMediaAutoScale () );
153		mMediaAutoScaleCheck->setEnabled ( can_change_media );
154
155		// Special code to disable looping checkbox for HTML MIME type
156		// (DEV-10042 -- Parcel Media: "Loop Media" should be disabled for static media types)
157		bool allow_looping = LLMIMETypes::findAllowLooping( mime_type );
158		if ( allow_looping )
159			mMediaLoopCheck->set( parcel->getMediaLoop () );
160		else
161			mMediaLoopCheck->set( false );
162		mMediaLoopCheck->setEnabled ( can_change_media && allow_looping );
163		
164		// disallow media size change for mime types that don't allow it
165		bool allow_resize = LLMIMETypes::findAllowResize( mime_type );
166		if ( allow_resize )
167			mMediaWidthCtrl->setValue( parcel->getMediaWidth() );
168		else
169			mMediaWidthCtrl->setValue( 0 );
170		mMediaWidthCtrl->setEnabled ( can_change_media && allow_resize );
171
172		if ( allow_resize )
173			mMediaHeightCtrl->setValue( parcel->getMediaHeight() );
174		else
175			mMediaHeightCtrl->setValue( 0 );
176		mMediaHeightCtrl->setEnabled ( can_change_media && allow_resize );
177
178		// enable/disable for text label for completeness
179		mMediaSizeCtrlLabel->setEnabled( can_change_media && allow_resize );
180
181		LLUUID tmp = parcel->getMediaID();
182		mMediaTextureCtrl->setImageAssetID ( parcel->getMediaID() );
183		mMediaTextureCtrl->setEnabled( can_change_media );
184
185		mSetURLButton->setEnabled( can_change_media );
186
187	}
188}
189
190void LLPanelLandMedia::populateMIMECombo()
191{
192	std::string default_mime_type = LLMIMETypes::getDefaultMimeType();
193	std::string default_label;
194	LLMIMETypes::mime_widget_set_map_t::const_iterator it;
195	for (it = LLMIMETypes::sWidgetMap.begin(); it != LLMIMETypes::sWidgetMap.end(); ++it)
196	{
197		const std::string& mime_type = it->first;
198		const LLMIMETypes::LLMIMEWidgetSet& info = it->second;
199		if (info.mDefaultMimeType == default_mime_type)
200		{
201			// Add this label at the end to make UI look cleaner
202			default_label = info.mLabel;
203		}
204		else
205		{
206			mMediaTypeCombo->add(info.mLabel, mime_type);
207		}
208	}
209
210	mMediaTypeCombo->add( default_label, default_mime_type, ADD_BOTTOM );
211}
212
213void LLPanelLandMedia::setMediaType(const std::string& mime_type)
214{
215	LLParcel *parcel = mParcel->getParcel();
216	if(parcel)
217		parcel->setMediaType(mime_type);
218
219	std::string media_key = LLMIMETypes::widgetType(mime_type);
220	mMediaTypeCombo->setValue(media_key);
221
222	std::string mime_str = mime_type;
223	if(LLMIMETypes::getDefaultMimeType() == mime_type)
224	{
225		// Instead of showing predefined "none/none" we are going to show something 
226		// localizable - "none" for example (see EXT-6542)
227		mime_str = LLMIMETypes::getDefaultMimeTypeTranslation();
228	}
229	getChild<LLUICtrl>("mime_type")->setValue(mime_str);
230}
231
232void LLPanelLandMedia::setMediaURL(const std::string& media_url)
233{
234	mMediaURLEdit->setText(media_url);
235	LLParcel *parcel = mParcel->getParcel();
236	if(parcel)
237		parcel->setMediaCurrentURL(media_url);
238	// LLViewerMedia::navigateHome();
239
240
241	mMediaURLEdit->onCommit();
242	// LLViewerParcelMedia::sendMediaNavigateMessage(media_url);
243	getChild<LLUICtrl>("current_url")->setValue(media_url);
244}
245std::string LLPanelLandMedia::getMediaURL()
246{
247	return mMediaURLEdit->getText();	
248}
249
250// static
251void LLPanelLandMedia::onCommitType(LLUICtrl *ctrl, void *userdata)
252{
253	LLPanelLandMedia *self = (LLPanelLandMedia *)userdata;
254	std::string current_type = LLMIMETypes::widgetType(self->getChild<LLUICtrl>("mime_type")->getValue().asString());
255	std::string new_type = self->mMediaTypeCombo->getValue();
256	if(current_type != new_type)
257	{
258		self->getChild<LLUICtrl>("mime_type")->setValue(LLMIMETypes::findDefaultMimeType(new_type));
259	}
260	onCommitAny(ctrl, userdata);
261
262}
263
264// static
265void LLPanelLandMedia::onCommitAny(LLUICtrl*, void *userdata)
266{
267	LLPanelLandMedia *self = (LLPanelLandMedia *)userdata;
268
269	LLParcel* parcel = self->mParcel->getParcel();
270	if (!parcel)
271	{
272		return;
273	}
274
275	// Extract data from UI
276	std::string media_url	= self->mMediaURLEdit->getText();
277	std::string media_desc	= self->mMediaDescEdit->getText();
278	std::string mime_type	= self->getChild<LLUICtrl>("mime_type")->getValue().asString();
279	U8 media_auto_scale		= self->mMediaAutoScaleCheck->get();
280	U8 media_loop           = self->mMediaLoopCheck->get();
281	S32 media_width			= (S32)self->mMediaWidthCtrl->get();
282	S32 media_height		= (S32)self->mMediaHeightCtrl->get();
283	LLUUID media_id			= self->mMediaTextureCtrl->getImageAssetID();
284
285
286	self->getChild<LLUICtrl>("mime_type")->setValue(mime_type);
287
288	// Remove leading/trailing whitespace (common when copying/pasting)
289	LLStringUtil::trim(media_url);
290
291	// Push data into current parcel
292	parcel->setMediaURL(media_url);
293	parcel->setMediaType(mime_type);
294	parcel->setMediaDesc(media_desc);
295	parcel->setMediaWidth(media_width);
296	parcel->setMediaHeight(media_height);
297	parcel->setMediaID(media_id);
298	parcel->setMediaAutoScale ( media_auto_scale );
299	parcel->setMediaLoop ( media_loop );
300
301	// Send current parcel data upstream to server
302	LLViewerParcelMgr::getInstance()->sendParcelPropertiesUpdate( parcel );
303
304	// Might have changed properties, so let's redraw!
305	self->refresh();
306}
307// static
308void LLPanelLandMedia::onSetBtn(void *userdata)
309{
310	LLPanelLandMedia *self = (LLPanelLandMedia *)userdata;
311	self->mURLEntryFloater = LLFloaterURLEntry::show( self->getHandle(), self->getMediaURL() );
312	LLFloater* parent_floater = gFloaterView->getParentFloater(self);
313	if (parent_floater)
314	{
315		parent_floater->addDependentFloater(self->mURLEntryFloater.get());
316	}
317}
318
319// static
320void LLPanelLandMedia::onResetBtn(void *userdata)
321{
322	LLPanelLandMedia *self = (LLPanelLandMedia *)userdata;
323	LLParcel* parcel = self->mParcel->getParcel();
324	// LLViewerMedia::navigateHome();
325	self->refresh();
326	self->getChild<LLUICtrl>("current_url")->setValue(parcel->getMediaURL());
327	// LLViewerParcelMedia::sendMediaNavigateMessage(parcel->getMediaURL());
328
329}
330