PageRenderTime 773ms CodeModel.GetById 140ms app.highlight 257ms RepoModel.GetById 369ms app.codeStats 1ms

/indra/newview/llfloatermediabrowser.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 462 lines | 337 code | 68 blank | 57 comment | 57 complexity | 63757381833d4085395d75ce09c9367c MD5 | raw file
  1/** 
  2 * @file llfloatermediabrowser.cpp
  3 * @brief media browser floater - uses embedded media browser control
  4 *
  5 * $LicenseInfo:firstyear=2006&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 "llfloatermediabrowser.h"
 30
 31#include "llfloaterreg.h"
 32#include "llparcel.h"
 33#include "llpluginclassmedia.h"
 34#include "lluictrlfactory.h"
 35#include "llmediactrl.h"
 36#include "llviewerwindow.h"
 37#include "llviewercontrol.h"
 38#include "llviewerparcelmgr.h"
 39#include "llweb.h"
 40#include "llui.h"
 41#include "roles_constants.h"
 42
 43#include "llurlhistory.h"
 44#include "llmediactrl.h"
 45#include "llviewermedia.h"
 46#include "llviewerparcelmedia.h"
 47#include "llcombobox.h"
 48#include "llwindow.h"
 49#include "lllayoutstack.h"
 50#include "llcheckboxctrl.h"
 51
 52#include "llnotifications.h"
 53
 54// TEMP
 55#include "llsdutil.h"
 56
 57LLFloaterMediaBrowser::LLFloaterMediaBrowser(const LLSD& key)
 58	: LLFloater(key)
 59{
 60}
 61
 62//static 
 63void LLFloaterMediaBrowser::create(const std::string &url, const std::string& target, const std::string& uuid)
 64{
 65	lldebugs << "url = " << url << ", target = " << target << ", uuid = " << uuid << llendl;
 66	
 67	std::string tag = target;
 68	
 69	if(target.empty() || target == "_blank")
 70	{
 71		if(!uuid.empty())
 72		{
 73			tag = uuid;
 74		}
 75		else
 76		{
 77		// create a unique tag for this instance
 78		LLUUID id;
 79		id.generate();
 80		tag = id.asString();
 81	}
 82	}
 83	
 84	S32 browser_window_limit = gSavedSettings.getS32("MediaBrowserWindowLimit");
 85	
 86	if(LLFloaterReg::findInstance("media_browser", tag) != NULL)
 87	{
 88		// There's already a media browser for this tag, so we won't be opening a new window.
 89	}
 90	else if(browser_window_limit != 0)
 91	{
 92		// showInstance will open a new window.  Figure out how many media browsers are already open, 
 93		// and close the least recently opened one if this will put us over the limit.
 94		
 95		LLFloaterReg::const_instance_list_t &instances = LLFloaterReg::getFloaterList("media_browser");
 96		lldebugs << "total instance count is " << instances.size() << llendl;
 97		
 98		for(LLFloaterReg::const_instance_list_t::const_iterator iter = instances.begin(); iter != instances.end(); iter++)
 99		{
100			lldebugs << "    " << (*iter)->getKey() << llendl;
101		}
102		
103		if(instances.size() >= (size_t)browser_window_limit)
104		{
105			// Destroy the least recently opened instance
106			(*instances.begin())->closeFloater();
107		}
108	}
109
110	LLFloaterMediaBrowser *browser = dynamic_cast<LLFloaterMediaBrowser*> (LLFloaterReg::showInstance("media_browser", tag));
111	llassert(browser);
112	if(browser)
113	{
114		browser->mUUID = uuid;
115
116		// tell the browser instance to load the specified URL
117		browser->openMedia(url, target);
118		LLViewerMedia::proxyWindowOpened(target, uuid);
119	}
120}
121
122//static 
123void LLFloaterMediaBrowser::closeRequest(const std::string &uuid)
124{
125	LLFloaterReg::const_instance_list_t& inst_list = LLFloaterReg::getFloaterList("media_browser");
126	lldebugs << "instance list size is " << inst_list.size() << ", incoming uuid is " << uuid << llendl;
127	for (LLFloaterReg::const_instance_list_t::const_iterator iter = inst_list.begin(); iter != inst_list.end(); ++iter)
128	{
129		LLFloaterMediaBrowser* i = dynamic_cast<LLFloaterMediaBrowser*>(*iter);
130		lldebugs << "    " << i->mUUID << llendl;
131		if (i && i->mUUID == uuid)
132		{
133			i->closeFloater(false);
134			return;
135 		}
136 	}
137}
138
139//static 
140void LLFloaterMediaBrowser::geometryChanged(const std::string &uuid, S32 x, S32 y, S32 width, S32 height)
141{
142	LLFloaterReg::const_instance_list_t& inst_list = LLFloaterReg::getFloaterList("media_browser");
143	lldebugs << "instance list size is " << inst_list.size() << ", incoming uuid is " << uuid << llendl;
144	for (LLFloaterReg::const_instance_list_t::const_iterator iter = inst_list.begin(); iter != inst_list.end(); ++iter)
145	{
146		LLFloaterMediaBrowser* i = dynamic_cast<LLFloaterMediaBrowser*>(*iter);
147		lldebugs << "    " << i->mUUID << llendl;
148		if (i && i->mUUID == uuid)
149		{
150			i->geometryChanged(x, y, width, height);
151			return;
152	}
153}
154}
155	
156void LLFloaterMediaBrowser::geometryChanged(S32 x, S32 y, S32 width, S32 height)
157{	
158	// Make sure the layout of the browser control is updated, so this calculation is correct.
159	LLLayoutStack::updateClass();
160		
161	// TODO: need to adjust size and constrain position to make sure floaters aren't moved outside the window view, etc.
162	LLCoordWindow window_size;
163	getWindow()->getSize(&window_size);
164
165	// Adjust width and height for the size of the chrome on the Media Browser window.
166	width += getRect().getWidth() - mBrowser->getRect().getWidth();
167	height += getRect().getHeight() - mBrowser->getRect().getHeight();
168	
169	LLRect geom;
170	geom.setOriginAndSize(x, window_size.mY - (y + height), width, height);
171
172	lldebugs << "geometry change: " << geom << llendl;
173	
174	handleReshape(geom,false);
175}
176
177
178void LLFloaterMediaBrowser::draw()
179{
180	getChildView("go")->setEnabled(!mAddressCombo->getValue().asString().empty());
181	LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
182	if(parcel)
183	{
184		getChildView("parcel_owner_controls")->setVisible( LLViewerParcelMgr::isParcelModifiableByAgent(parcel, GP_LAND_CHANGE_MEDIA));
185		getChildView("assign")->setEnabled(!mAddressCombo->getValue().asString().empty());
186	}
187	bool show_time_controls = false;
188	bool media_playing = false;
189	if(mBrowser)
190	{
191		LLPluginClassMedia* media_plugin = mBrowser->getMediaPlugin();
192		if(media_plugin)
193		{
194			show_time_controls = media_plugin->pluginSupportsMediaTime();
195			media_playing = media_plugin->getStatus() == LLPluginClassMediaOwner::MEDIA_PLAYING;
196		}
197	}
198	getChildView("rewind")->setVisible( show_time_controls);
199	getChildView("play")->setVisible( show_time_controls && ! media_playing);
200	getChildView("pause")->setVisible( show_time_controls && media_playing);
201	getChildView("stop")->setVisible( show_time_controls);
202	getChildView("seek")->setVisible( show_time_controls);
203
204	getChildView("play")->setEnabled(! media_playing);
205	getChildView("stop")->setEnabled(media_playing);
206
207	getChildView("back")->setEnabled(mBrowser->canNavigateBack());
208	getChildView("forward")->setEnabled(mBrowser->canNavigateForward());
209
210	LLFloater::draw();
211}
212
213BOOL LLFloaterMediaBrowser::postBuild()
214{
215	mBrowser = getChild<LLMediaCtrl>("browser");
216	mBrowser->addObserver(this);
217
218	mAddressCombo = getChild<LLComboBox>("address");
219	mAddressCombo->setCommitCallback(onEnterAddress, this);
220	mAddressCombo->sortByName();
221
222	childSetAction("back", onClickBack, this);
223	childSetAction("forward", onClickForward, this);
224	childSetAction("reload", onClickRefresh, this);
225	childSetAction("rewind", onClickRewind, this);
226	childSetAction("play", onClickPlay, this);
227	childSetAction("stop", onClickStop, this);
228	childSetAction("pause", onClickPlay, this);
229	childSetAction("seek", onClickSeek, this);
230	childSetAction("go", onClickGo, this);
231	childSetAction("close", onClickClose, this);
232	childSetAction("open_browser", onClickOpenWebBrowser, this);
233	childSetAction("assign", onClickAssign, this);
234
235	buildURLHistory();
236
237	return TRUE;
238}
239
240void LLFloaterMediaBrowser::buildURLHistory()
241{
242	LLCtrlListInterface* url_list = childGetListInterface("address");
243	if (url_list)
244	{
245		url_list->operateOnAll(LLCtrlListInterface::OP_DELETE);
246	}
247
248	// Get all of the entries in the "browser" collection
249	LLSD browser_history = LLURLHistory::getURLHistory("browser");
250
251	LLSD::array_iterator iter_history =
252		browser_history.beginArray();
253	LLSD::array_iterator end_history =
254		browser_history.endArray();
255	for(; iter_history != end_history; ++iter_history)
256	{
257		std::string url = (*iter_history).asString();
258		if(! url.empty())
259			url_list->addSimpleElement(url);
260	}
261
262	// initialize URL history in the plugin
263	if(mBrowser && mBrowser->getMediaPlugin())
264	{
265		mBrowser->getMediaPlugin()->initializeUrlHistory(browser_history);
266	}
267}
268
269std::string LLFloaterMediaBrowser::getSupportURL()
270{
271	return getString("support_page_url");
272}
273
274//virtual
275void LLFloaterMediaBrowser::onClose(bool app_quitting)
276{
277	LLViewerMedia::proxyWindowClosed(mUUID);
278	//setVisible(FALSE);
279	destroy();
280}
281
282void LLFloaterMediaBrowser::handleMediaEvent(LLPluginClassMedia* self, EMediaEvent event)
283{
284	if(event == MEDIA_EVENT_LOCATION_CHANGED)
285	{
286		setCurrentURL(self->getLocation());
287	}
288	else if(event == MEDIA_EVENT_NAVIGATE_COMPLETE)
289	{
290		// This is the event these flags are sent with.
291		getChildView("back")->setEnabled(self->getHistoryBackAvailable());
292		getChildView("forward")->setEnabled(self->getHistoryForwardAvailable());
293	}
294	else if(event == MEDIA_EVENT_CLOSE_REQUEST)
295	{
296		// The browser instance wants its window closed.
297		closeFloater();
298	}
299	else if(event == MEDIA_EVENT_GEOMETRY_CHANGE)
300	{
301		geometryChanged(self->getGeometryX(), self->getGeometryY(), self->getGeometryWidth(), self->getGeometryHeight());
302	}
303}
304
305void LLFloaterMediaBrowser::setCurrentURL(const std::string& url)
306{
307	mCurrentURL = url;
308
309	mAddressCombo->remove(mCurrentURL);
310	mAddressCombo->add(mCurrentURL);
311	mAddressCombo->selectByValue(mCurrentURL);
312
313	// Serialize url history
314	LLURLHistory::removeURL("browser", mCurrentURL);
315	LLURLHistory::addURL("browser", mCurrentURL);
316
317	getChildView("back")->setEnabled(mBrowser->canNavigateBack());
318	getChildView("forward")->setEnabled(mBrowser->canNavigateForward());
319	getChildView("reload")->setEnabled(TRUE);
320}
321
322//static 
323void LLFloaterMediaBrowser::onEnterAddress(LLUICtrl* ctrl, void* user_data)
324{
325	LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
326	self->mBrowser->navigateTo(self->mAddressCombo->getValue().asString());
327}
328
329//static 
330void LLFloaterMediaBrowser::onClickRefresh(void* user_data)
331{
332	LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
333
334	if( self->mBrowser->getMediaPlugin() &&  self->mBrowser->getMediaPlugin()->pluginSupportsMediaBrowser())
335	{
336		bool ignore_cache = true;
337		self->mBrowser->getMediaPlugin()->browse_reload( ignore_cache );
338	}
339	else
340	{
341		self->mBrowser->navigateTo(self->mCurrentURL);
342	}
343}
344
345//static 
346void LLFloaterMediaBrowser::onClickForward(void* user_data)
347{
348	LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
349
350	self->mBrowser->navigateForward();
351}
352
353//static 
354void LLFloaterMediaBrowser::onClickBack(void* user_data)
355{
356	LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
357
358	self->mBrowser->navigateBack();
359}
360
361//static 
362void LLFloaterMediaBrowser::onClickGo(void* user_data)
363{
364	LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
365
366	self->mBrowser->navigateTo(self->mAddressCombo->getValue().asString());
367}
368
369//static 
370void LLFloaterMediaBrowser::onClickClose(void* user_data)
371{
372	LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
373
374	self->closeFloater();
375}
376
377//static 
378void LLFloaterMediaBrowser::onClickOpenWebBrowser(void* user_data)
379{
380	LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
381
382	std::string url = self->mCurrentURL.empty() ? 
383		self->mBrowser->getHomePageUrl() :
384		self->mCurrentURL;
385	LLWeb::loadURLExternal(url);
386}
387
388void LLFloaterMediaBrowser::onClickAssign(void* user_data)
389{
390	LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
391
392	LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
393	if (!parcel)
394	{
395		return;
396	}
397	std::string media_url = self->mAddressCombo->getValue().asString();
398	LLStringUtil::trim(media_url);
399
400	if(parcel->getMediaType() != "text/html")
401	{
402		parcel->setMediaURL(media_url);
403		parcel->setMediaCurrentURL(media_url);
404		parcel->setMediaType(std::string("text/html"));
405		LLViewerParcelMgr::getInstance()->sendParcelPropertiesUpdate( parcel, true );
406		LLViewerParcelMedia::sendMediaNavigateMessage(media_url);
407		LLViewerParcelMedia::stop();
408		// LLViewerParcelMedia::update( parcel );
409	}
410	LLViewerParcelMedia::sendMediaNavigateMessage(media_url);
411}
412//static 
413void LLFloaterMediaBrowser::onClickRewind(void* user_data)
414{
415	LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
416
417	if(self->mBrowser->getMediaPlugin())
418		self->mBrowser->getMediaPlugin()->start(-2.0f);
419}
420//static 
421void LLFloaterMediaBrowser::onClickPlay(void* user_data)
422{
423	LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
424
425	LLPluginClassMedia* plugin = self->mBrowser->getMediaPlugin();
426	if(plugin)
427	{
428		if(plugin->getStatus() == LLPluginClassMediaOwner::MEDIA_PLAYING)
429		{
430			plugin->pause();
431		}
432		else
433		{
434			plugin->start();
435		}
436	}
437}
438//static 
439void LLFloaterMediaBrowser::onClickStop(void* user_data)
440{
441	LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
442
443	if(self->mBrowser->getMediaPlugin())
444		self->mBrowser->getMediaPlugin()->stop();
445}
446//static 
447void LLFloaterMediaBrowser::onClickSeek(void* user_data)
448{
449	LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
450
451	if(self->mBrowser->getMediaPlugin())
452		self->mBrowser->getMediaPlugin()->start(2.0f);
453}
454void LLFloaterMediaBrowser::openMedia(const std::string& media_url, const std::string& target)
455{
456	mBrowser->setHomePageUrl(media_url);
457	mBrowser->setTarget(target);
458	mBrowser->navigateTo(media_url);
459	setCurrentURL(media_url);
460}
461
462