llfloatermediabrowser.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:9k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llfloatermediabrowser.cpp
  3.  * @brief media browser floater - uses embedded media browser control
  4.  *
  5.  * $LicenseInfo:firstyear=2006&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2006-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llfloatermediabrowser.h"
  34. #include "llfloaterreg.h"
  35. #include "llparcel.h"
  36. #include "llpluginclassmedia.h"
  37. #include "lluictrlfactory.h"
  38. #include "llmediactrl.h"
  39. #include "llviewerwindow.h"
  40. #include "llviewercontrol.h"
  41. #include "llviewerparcelmgr.h"
  42. #include "llweb.h"
  43. #include "llui.h"
  44. #include "roles_constants.h"
  45. #include "llurlhistory.h"
  46. #include "llmediactrl.h"
  47. #include "llviewermedia.h"
  48. #include "llviewerparcelmedia.h"
  49. #include "llcombobox.h"
  50. // TEMP
  51. #include "llsdutil.h"
  52. LLFloaterMediaBrowser::LLFloaterMediaBrowser(const LLSD& key)
  53. : LLFloater(key)
  54. {
  55. // LLUICtrlFactory::getInstance()->buildFloater(this, "floater_media_browser.xml");
  56. }
  57. void LLFloaterMediaBrowser::draw()
  58. {
  59. childSetEnabled("go", !mAddressCombo->getValue().asString().empty());
  60. LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
  61. if(parcel)
  62. {
  63. childSetVisible("parcel_owner_controls", LLViewerParcelMgr::isParcelModifiableByAgent(parcel, GP_LAND_CHANGE_MEDIA));
  64. childSetEnabled("assign", !mAddressCombo->getValue().asString().empty());
  65. }
  66. bool show_time_controls = false;
  67. bool media_playing = false;
  68. if(mBrowser)
  69. {
  70. LLPluginClassMedia* media_plugin = mBrowser->getMediaPlugin();
  71. if(media_plugin)
  72. {
  73. show_time_controls = media_plugin->pluginSupportsMediaTime();
  74. media_playing = media_plugin->getStatus() == LLPluginClassMediaOwner::MEDIA_PLAYING;
  75. }
  76. }
  77. childSetVisible("rewind", show_time_controls);
  78. childSetVisible("play", show_time_controls && ! media_playing);
  79. childSetVisible("pause", show_time_controls && media_playing);
  80. childSetVisible("stop", show_time_controls);
  81. childSetVisible("seek", show_time_controls);
  82. childSetEnabled("play", ! media_playing);
  83. childSetEnabled("stop", media_playing);
  84. childSetEnabled("back", mBrowser->canNavigateBack());
  85. childSetEnabled("forward", mBrowser->canNavigateForward());
  86. LLFloater::draw();
  87. }
  88. BOOL LLFloaterMediaBrowser::postBuild()
  89. {
  90. mBrowser = getChild<LLMediaCtrl>("browser");
  91. mBrowser->addObserver(this);
  92. mAddressCombo = getChild<LLComboBox>("address");
  93. mAddressCombo->setCommitCallback(onEnterAddress, this);
  94. childSetAction("back", onClickBack, this);
  95. childSetAction("forward", onClickForward, this);
  96. childSetAction("reload", onClickRefresh, this);
  97. childSetAction("rewind", onClickRewind, this);
  98. childSetAction("play", onClickPlay, this);
  99. childSetAction("stop", onClickStop, this);
  100. childSetAction("pause", onClickPlay, this);
  101. childSetAction("seek", onClickSeek, this);
  102. childSetAction("go", onClickGo, this);
  103. childSetAction("close", onClickClose, this);
  104. childSetAction("open_browser", onClickOpenWebBrowser, this);
  105. childSetAction("assign", onClickAssign, this);
  106. buildURLHistory();
  107. return TRUE;
  108. }
  109. void LLFloaterMediaBrowser::buildURLHistory()
  110. {
  111. LLCtrlListInterface* url_list = childGetListInterface("address");
  112. if (url_list)
  113. {
  114. url_list->operateOnAll(LLCtrlListInterface::OP_DELETE);
  115. }
  116. // Get all of the entries in the "browser" collection
  117. LLSD browser_history = LLURLHistory::getURLHistory("browser");
  118. LLSD::array_iterator iter_history =
  119. browser_history.beginArray();
  120. LLSD::array_iterator end_history =
  121. browser_history.endArray();
  122. for(; iter_history != end_history; ++iter_history)
  123. {
  124. std::string url = (*iter_history).asString();
  125. if(! url.empty())
  126. url_list->addSimpleElement(url);
  127. }
  128. // initialize URL history in the plugin
  129. if(mBrowser && mBrowser->getMediaPlugin())
  130. {
  131. mBrowser->getMediaPlugin()->initializeUrlHistory(browser_history);
  132. }
  133. }
  134. std::string LLFloaterMediaBrowser::getSupportURL()
  135. {
  136. return getString("support_page_url");
  137. }
  138. //virtual
  139. void LLFloaterMediaBrowser::onClose(bool app_quitting)
  140. {
  141. //setVisible(FALSE);
  142. destroy();
  143. }
  144. void LLFloaterMediaBrowser::handleMediaEvent(LLPluginClassMedia* self, EMediaEvent event)
  145. {
  146. if(event == MEDIA_EVENT_LOCATION_CHANGED)
  147. {
  148. setCurrentURL(self->getLocation());
  149. }
  150. else if(event == MEDIA_EVENT_NAVIGATE_COMPLETE)
  151. {
  152. // This is the event these flags are sent with.
  153. childSetEnabled("back", self->getHistoryBackAvailable());
  154. childSetEnabled("forward", self->getHistoryForwardAvailable());
  155. }
  156. }
  157. void LLFloaterMediaBrowser::setCurrentURL(const std::string& url)
  158. {
  159. mCurrentURL = url;
  160. // redirects will navigate momentarily to about:blank, don't add to history
  161. if (mCurrentURL != "about:blank")
  162. {
  163. mAddressCombo->remove(mCurrentURL);
  164. mAddressCombo->add(mCurrentURL, ADD_SORTED);
  165. mAddressCombo->selectByValue(mCurrentURL);
  166. // Serialize url history
  167. LLURLHistory::removeURL("browser", mCurrentURL);
  168. LLURLHistory::addURL("browser", mCurrentURL);
  169. }
  170. childSetEnabled("back", mBrowser->canNavigateBack());
  171. childSetEnabled("forward", mBrowser->canNavigateForward());
  172. childSetEnabled("reload", TRUE);
  173. }
  174. void LLFloaterMediaBrowser::onOpen(const LLSD& media_url)
  175. {
  176. LLFloater::onOpen(media_url);
  177. openMedia(media_url.asString());
  178. }
  179. //static 
  180. void LLFloaterMediaBrowser::onEnterAddress(LLUICtrl* ctrl, void* user_data)
  181. {
  182. LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
  183. self->mBrowser->navigateTo(self->mAddressCombo->getValue().asString());
  184. }
  185. //static 
  186. void LLFloaterMediaBrowser::onClickRefresh(void* user_data)
  187. {
  188. LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
  189. self->mAddressCombo->remove(0);
  190. self->mBrowser->navigateTo(self->mCurrentURL);
  191. }
  192. //static 
  193. void LLFloaterMediaBrowser::onClickForward(void* user_data)
  194. {
  195. LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
  196. self->mBrowser->navigateForward();
  197. }
  198. //static 
  199. void LLFloaterMediaBrowser::onClickBack(void* user_data)
  200. {
  201. LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
  202. self->mBrowser->navigateBack();
  203. }
  204. //static 
  205. void LLFloaterMediaBrowser::onClickGo(void* user_data)
  206. {
  207. LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
  208. self->mBrowser->navigateTo(self->mAddressCombo->getValue().asString());
  209. }
  210. //static 
  211. void LLFloaterMediaBrowser::onClickClose(void* user_data)
  212. {
  213. LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
  214. self->closeFloater();
  215. }
  216. //static 
  217. void LLFloaterMediaBrowser::onClickOpenWebBrowser(void* user_data)
  218. {
  219. LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
  220. std::string url = self->mCurrentURL.empty() ? 
  221. self->mBrowser->getHomePageUrl() :
  222. self->mCurrentURL;
  223. LLWeb::loadURLExternal(url);
  224. }
  225. void LLFloaterMediaBrowser::onClickAssign(void* user_data)
  226. {
  227. LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
  228. LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
  229. if (!parcel)
  230. {
  231. return;
  232. }
  233. std::string media_url = self->mAddressCombo->getValue().asString();
  234. LLStringUtil::trim(media_url);
  235. if(parcel->getMediaType() != "text/html")
  236. {
  237. parcel->setMediaURL(media_url);
  238. parcel->setMediaCurrentURL(media_url);
  239. parcel->setMediaType(std::string("text/html"));
  240. LLViewerParcelMgr::getInstance()->sendParcelPropertiesUpdate( parcel, true );
  241. LLViewerParcelMedia::sendMediaNavigateMessage(media_url);
  242. LLViewerParcelMedia::stop();
  243. // LLViewerParcelMedia::update( parcel );
  244. }
  245. LLViewerParcelMedia::sendMediaNavigateMessage(media_url);
  246. }
  247. //static 
  248. void LLFloaterMediaBrowser::onClickRewind(void* user_data)
  249. {
  250. LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
  251. if(self->mBrowser->getMediaPlugin())
  252. self->mBrowser->getMediaPlugin()->start(-2.0f);
  253. }
  254. //static 
  255. void LLFloaterMediaBrowser::onClickPlay(void* user_data)
  256. {
  257. LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
  258. LLPluginClassMedia* plugin = self->mBrowser->getMediaPlugin();
  259. if(plugin)
  260. {
  261. if(plugin->getStatus() == LLPluginClassMediaOwner::MEDIA_PLAYING)
  262. {
  263. plugin->pause();
  264. }
  265. else
  266. {
  267. plugin->start();
  268. }
  269. }
  270. }
  271. //static 
  272. void LLFloaterMediaBrowser::onClickStop(void* user_data)
  273. {
  274. LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
  275. if(self->mBrowser->getMediaPlugin())
  276. self->mBrowser->getMediaPlugin()->stop();
  277. }
  278. //static 
  279. void LLFloaterMediaBrowser::onClickSeek(void* user_data)
  280. {
  281. LLFloaterMediaBrowser* self = (LLFloaterMediaBrowser*)user_data;
  282. if(self->mBrowser->getMediaPlugin())
  283. self->mBrowser->getMediaPlugin()->start(2.0f);
  284. }
  285. void LLFloaterMediaBrowser::openMedia(const std::string& media_url)
  286. {
  287. mBrowser->setHomePageUrl(media_url);
  288. mBrowser->navigateTo(media_url);
  289. setCurrentURL(media_url);
  290. }