PageRenderTime 35ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

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