llpanellandmedia.cpp 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372
  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=viewergpl$
  7. *
  8. * Copyright (c) 2007-2009, Linden Research, Inc.
  9. *
  10. * Second Life Viewer Source Code
  11. * The source code in this file ("Source Code") is provided by Linden Lab
  12. * to you under the terms of the GNU General Public License, version 2.0
  13. * ("GPL"), unless you have obtained a separate licensing agreement
  14. * ("Other License"), formally executed by you and Linden Lab. Terms of
  15. * the GPL can be found in doc/GPL-license.txt in this distribution, or
  16. * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  17. *
  18. * There are special exceptions to the terms and conditions of the GPL as
  19. * it is applied to this Source Code. View the full text of the exception
  20. * in the file doc/FLOSS-exception.txt in this software distribution, or
  21. * online at
  22. * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  23. *
  24. * By copying, modifying or distributing this software, you acknowledge
  25. * that you have read and understood your obligations described above,
  26. * and agree to abide by those obligations.
  27. *
  28. * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  29. * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  30. * COMPLETENESS OR PERFORMANCE.
  31. * $/LicenseInfo$
  32. */
  33. #include "llviewerprecompiledheaders.h"
  34. #include "llpanellandmedia.h"
  35. #include "llcheckboxctrl.h"
  36. #include "llcombobox.h"
  37. #include "lllineeditor.h"
  38. #include "llmimetypes.h"
  39. #include "llparcel.h"
  40. #include "llradiogroup.h"
  41. #include "llsdutil.h"
  42. #include "llspinctrl.h"
  43. #include "llscrolllistctrl.h"
  44. #include "lluictrlfactory.h"
  45. #include "roles_constants.h"
  46. #include "llfloaterurlentry.h"
  47. #include "lltexturectrl.h"
  48. #include "llviewermedia.h"
  49. #include "llviewerparcelmedia.h"
  50. #include "llviewerparcelmgr.h"
  51. #include "llviewerregion.h"
  52. LLPanelLandMedia::LLPanelLandMedia(LLParcelSelectionHandle& parcel)
  53. : mParcel(parcel)
  54. {
  55. }
  56. //virtual
  57. bool LLPanelLandMedia::postBuild()
  58. {
  59. mMediaTextureCtrl = getChild<LLTextureCtrl>("media_texture_ctrl");
  60. mMediaTextureCtrl->setCommitCallback(onCommitAny);
  61. mMediaTextureCtrl->setCallbackUserData(this);
  62. mMediaTextureCtrl->setAllowNoTexture (true);
  63. mMediaTextureCtrl->setImmediateFilterPermMask(PERM_COPY | PERM_TRANSFER);
  64. mMediaTextureCtrl->setNonImmediateFilterPermMask(PERM_COPY | PERM_TRANSFER);
  65. mMediaAutoScaleCheck = getChild<LLCheckBoxCtrl>("media_auto_scale");
  66. mMediaAutoScaleCheck->setCommitCallback(onCommitAny);
  67. mMediaAutoScaleCheck->setCallbackUserData(this);
  68. mMediaLoopCheck = getChild<LLCheckBoxCtrl>("media_loop");
  69. mMediaLoopCheck->setCommitCallback(onCommitAny);
  70. mMediaLoopCheck->setCallbackUserData(this);
  71. mMediaURLEdit = getChild<LLLineEditor>("media_url");
  72. mMediaURLEdit->setCommitCallback(onCommitAny);
  73. mMediaURLEdit->setCallbackUserData(this);
  74. mMediaDescEdit = getChild<LLLineEditor>("url_description");
  75. mMediaDescEdit->setCommitCallback(onCommitAny);
  76. mMediaDescEdit->setCallbackUserData(this);
  77. mMediaTypeCombo = getChild<LLComboBox>("media_type_combo");
  78. childSetCommitCallback("media_type_combo", onCommitType, this);
  79. populateMIMECombo();
  80. mMediaResetCtrl = getChild<LLSpinCtrl>("media_reset_time");
  81. mMediaResetCtrl->setCommitCallback(onCommitAny);
  82. mMediaResetCtrl->setCallbackUserData(this);
  83. mMediaWidthCtrl = getChild<LLSpinCtrl>("media_size_width");
  84. mMediaWidthCtrl->setCommitCallback(onCommitAny);
  85. mMediaWidthCtrl->setCallbackUserData(this);
  86. mMediaHeightCtrl = getChild<LLSpinCtrl>("media_size_height");
  87. mMediaHeightCtrl->setCommitCallback(onCommitAny);
  88. mMediaHeightCtrl->setCallbackUserData(this);
  89. mSetURLButton = getChild<LLButton>("set_media_url");
  90. mSetURLButton->setClickedCallback(onSetBtn, this);
  91. mResetURLButton = getChild<LLButton>("reset_media_url");
  92. mResetURLButton->setClickedCallback(onResetBtn, this);
  93. mRadioNavigateControl = getChild<LLRadioGroup>("radio_navigate_allow");
  94. mRadioNavigateControl->setCommitCallback(onCommitAny);
  95. mRadioNavigateControl->setCallbackUserData(this);
  96. mCheckObscureMOAP = getChild<LLCheckBoxCtrl>("obscure moap check");
  97. mCheckObscureMOAP->setCommitCallback(onCommitAny);
  98. mCheckObscureMOAP->setCallbackUserData(this);
  99. return true;
  100. }
  101. //virtual
  102. void LLPanelLandMedia::refresh()
  103. {
  104. LLParcel* parcel = mParcel->getParcel();
  105. if (!parcel)
  106. {
  107. clearCtrls();
  108. }
  109. else // Something selected, hooray !
  110. {
  111. // Display options
  112. bool can_change_media =
  113. LLViewerParcelMgr::isParcelModifiableByAgent(parcel,
  114. GP_LAND_CHANGE_MEDIA);
  115. mMediaURLEdit->setText(parcel->getMediaURL());
  116. mMediaURLEdit->setEnabled(false);
  117. childSetText("current_url", parcel->getMediaCurrentURL());
  118. mMediaDescEdit->setText(parcel->getMediaDesc());
  119. mMediaDescEdit->setEnabled(can_change_media);
  120. std::string mime_type = parcel->getMediaType();
  121. if (mime_type.empty())
  122. {
  123. mime_type = LLMIMETypes::getDefaultMimeType();
  124. }
  125. setMediaType(mime_type);
  126. mMediaTypeCombo->setEnabled(can_change_media);
  127. childSetText("mime_type", mime_type);
  128. mMediaAutoScaleCheck->set(parcel->getMediaAutoScale());
  129. mMediaAutoScaleCheck->setEnabled(can_change_media);
  130. // Special code to disable looping checkbox for HTML MIME type
  131. // (DEV-10042 -- Parcel Media: "Loop Media" should be disabled for
  132. // static media types)
  133. bool allow_looping = LLMIMETypes::findAllowLooping(mime_type);
  134. if (allow_looping)
  135. {
  136. mMediaLoopCheck->set(parcel->getMediaLoop());
  137. }
  138. else
  139. {
  140. mMediaLoopCheck->set(false);
  141. }
  142. mMediaLoopCheck->setEnabled (can_change_media && allow_looping);
  143. mMediaResetCtrl->set(parcel->getMediaURLTimeout());
  144. mMediaResetCtrl->setEnabled(can_change_media);
  145. // disallow media size change for mime types that don't allow it
  146. bool allow_resize = LLMIMETypes::findAllowResize(mime_type);
  147. if (allow_resize)
  148. {
  149. mMediaWidthCtrl->setValue(parcel->getMediaWidth());
  150. }
  151. else
  152. {
  153. mMediaWidthCtrl->setValue(0);
  154. }
  155. mMediaWidthCtrl->setEnabled(can_change_media && allow_resize);
  156. if (allow_resize)
  157. {
  158. mMediaHeightCtrl->setValue(parcel->getMediaHeight());
  159. }
  160. else
  161. {
  162. mMediaHeightCtrl->setValue(0);
  163. }
  164. mMediaHeightCtrl->setEnabled(can_change_media && allow_resize);
  165. mMediaTextureCtrl->setImageAssetID (parcel->getMediaID());
  166. mMediaTextureCtrl->setEnabled(can_change_media);
  167. mSetURLButton->setEnabled(can_change_media);
  168. mResetURLButton->setEnabled(can_change_media);
  169. LLFloaterURLEntry* floaterp =
  170. (LLFloaterURLEntry*)mURLEntryFloater.get();
  171. if (floaterp)
  172. {
  173. floaterp->addURLToCombobox(getMediaURL());
  174. }
  175. // This radial control is really just an inverse mapping to the boolean
  176. // allow_navigate value. It is set as a radial merely for user
  177. // readability.
  178. mRadioNavigateControl->setSelectedIndex(!parcel->getMediaAllowNavigate());
  179. mRadioNavigateControl->setEnabled(can_change_media);
  180. mCheckObscureMOAP->set(parcel->getObscureMOAP());
  181. mCheckObscureMOAP->setEnabled(can_change_media);
  182. }
  183. }
  184. void LLPanelLandMedia::populateMIMECombo()
  185. {
  186. std::string default_mime_type = LLMIMETypes::getDefaultMimeType();
  187. std::string default_label;
  188. LLMIMETypes::mime_widget_set_map_t::const_iterator it;
  189. for (it = LLMIMETypes::sWidgetMap.begin();
  190. it != LLMIMETypes::sWidgetMap.end(); ++it)
  191. {
  192. const std::string& mime_type = it->first;
  193. const LLMIMETypes::LLMIMEWidgetSet& info = it->second;
  194. if (info.mDefaultMimeType == default_mime_type)
  195. {
  196. // Add this label at the end to make UI look cleaner
  197. default_label = info.mLabel;
  198. }
  199. else
  200. {
  201. mMediaTypeCombo->add(info.mLabel, mime_type);
  202. }
  203. }
  204. // *TODO: The sort order is based on std::map key, which is
  205. // ASCII-sorted and is wrong in other languages. TRANSLATE
  206. mMediaTypeCombo->add(default_label, default_mime_type, ADD_BOTTOM);
  207. }
  208. void LLPanelLandMedia::setMediaType(const std::string& mime_type)
  209. {
  210. LLParcel *parcel = mParcel->getParcel();
  211. if (parcel)
  212. {
  213. parcel->setMediaType(mime_type);
  214. }
  215. std::string media_key = LLMIMETypes::widgetType(mime_type);
  216. mMediaTypeCombo->setValue(media_key);
  217. childSetText("mime_type", mime_type);
  218. }
  219. void LLPanelLandMedia::setMediaURL(const std::string& media_url)
  220. {
  221. mMediaURLEdit->setText(media_url);
  222. LLParcel* parcel = mParcel->getParcel();
  223. if (parcel)
  224. {
  225. parcel->setMediaCurrentURL(media_url);
  226. }
  227. //LLViewerMedia::navigateHome();
  228. mMediaURLEdit->onCommit();
  229. //LLViewerParcelMedia::sendMediaNavigateMessage(media_url);
  230. childSetText("current_url", media_url);
  231. }
  232. std::string LLPanelLandMedia::getMediaURL()
  233. {
  234. return mMediaURLEdit->getText();
  235. }
  236. //static
  237. void LLPanelLandMedia::onCommitType(LLUICtrl* ctrl, void* userdata)
  238. {
  239. LLPanelLandMedia* self = (LLPanelLandMedia*)userdata;
  240. if (!self || !ctrl) return;
  241. std::string current_type =
  242. LLMIMETypes::widgetType(self->childGetText("mime_type"));
  243. std::string new_type = self->mMediaTypeCombo->getValue();
  244. if (current_type != new_type)
  245. {
  246. self->childSetText("mime_type",
  247. LLMIMETypes::findDefaultMimeType(new_type));
  248. }
  249. onCommitAny(ctrl, userdata);
  250. }
  251. //static
  252. void LLPanelLandMedia::onCommitAny(LLUICtrl*, void* userdata)
  253. {
  254. LLPanelLandMedia* self = (LLPanelLandMedia*)userdata;
  255. if (!self) return;
  256. LLParcel* parcel = self->mParcel->getParcel();
  257. if (!parcel) return;
  258. // Extract data from UI
  259. std::string media_url = self->mMediaURLEdit->getText();
  260. std::string media_desc = self->mMediaDescEdit->getText();
  261. std::string mime_type = self->childGetText("mime_type");
  262. bool media_auto_scale = self->mMediaAutoScaleCheck->get();
  263. bool media_loop = self->mMediaLoopCheck->get();
  264. F32 media_reset_time = (F32)self->mMediaResetCtrl->get();
  265. S32 media_width = (S32)self->mMediaWidthCtrl->get();
  266. S32 media_height = (S32)self->mMediaHeightCtrl->get();
  267. LLUUID media_id = self->mMediaTextureCtrl->getImageAssetID();
  268. U8 navigate_allow = !self->mRadioNavigateControl->getSelectedIndex();
  269. bool obscure_moap = self->mCheckObscureMOAP->get();
  270. self->childSetText("mime_type", mime_type);
  271. // Remove leading/trailing whitespace (common when copying/pasting)
  272. LLStringUtil::trim(media_url);
  273. // Push data into current parcel
  274. parcel->setMediaURL(media_url);
  275. parcel->setMediaType(mime_type);
  276. parcel->setMediaDesc(media_desc);
  277. parcel->setMediaWidth(media_width);
  278. parcel->setMediaHeight(media_height);
  279. parcel->setMediaID(media_id);
  280. parcel->setMediaAutoScale(media_auto_scale);
  281. parcel->setMediaLoop(media_loop);
  282. parcel->setMediaAllowNavigate(navigate_allow);
  283. parcel->setMediaURLTimeout(media_reset_time);
  284. parcel->setObscureMOAP(obscure_moap);
  285. // Send current parcel data upstream to server
  286. gViewerParcelMgr.sendParcelPropertiesUpdate(parcel);
  287. // Might have changed properties, so let's redraw!
  288. self->refresh();
  289. }
  290. //static
  291. void LLPanelLandMedia::onSetBtn(void* userdata)
  292. {
  293. LLPanelLandMedia* self = (LLPanelLandMedia*)userdata;
  294. if (!self) return;
  295. self->mURLEntryFloater = LLFloaterURLEntry::show(self->getHandle(),
  296. self->getMediaURL());
  297. if (gFloaterViewp)
  298. {
  299. LLFloater* parentp = gFloaterViewp->getParentFloater(self);
  300. if (parentp)
  301. {
  302. parentp->addDependentFloater(self->mURLEntryFloater.get());
  303. }
  304. }
  305. }
  306. //static
  307. void LLPanelLandMedia::onResetBtn(void* userdata)
  308. {
  309. LLPanelLandMedia* self = (LLPanelLandMedia*)userdata;
  310. if (self)
  311. {
  312. LLParcel* parcel = self->mParcel->getParcel();
  313. //LLViewerMedia::navigateHome();
  314. self->refresh();
  315. self->childSetText("current_url", parcel->getMediaURL());
  316. //LLViewerParcelMedia::sendMediaNavigateMessage(parcel->getMediaURL());
  317. }
  318. }