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