llmediaremotectrl.cpp 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /**
  2. * @file llmediaremotectrl.cpp
  3. * @brief A remote control for media (video and music)
  4. *
  5. * $LicenseInfo:firstyear=2005&license=viewergpl$
  6. *
  7. * Copyright (c) 2005-2009, 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 "llmediaremotectrl.h"
  34. #include "llaudioengine.h"
  35. #include "llbutton.h"
  36. #include "lliconctrl.h"
  37. #include "llmimetypes.h"
  38. #include "llparcel.h"
  39. #include "llstreamingaudio.h"
  40. #include "lltrans.h"
  41. #include "lluictrlfactory.h"
  42. #include "llfloaternearbymedia.h"
  43. #include "lloverlaybar.h"
  44. #include "llpanelaudiovolume.h"
  45. #include "llviewercontrol.h"
  46. #include "llviewermedia.h"
  47. #include "llviewerparcelmedia.h"
  48. #include "llviewerparcelmgr.h"
  49. void nearby_media_toggle(void* dummy)
  50. {
  51. LLFloaterNearByMedia::toggleInstance();
  52. }
  53. LLMediaRemoteCtrl::LLMediaRemoteCtrl(const std::string& name,
  54. const LLRect& rect,
  55. const std::string& xml_file,
  56. const ERemoteType type)
  57. : LLPanel(name, rect, false),
  58. mType(type),
  59. mIcon(NULL),
  60. mPlay(NULL),
  61. mPause(NULL),
  62. mStop(NULL)
  63. {
  64. setIsChrome(true);
  65. setFocusRoot(true);
  66. LLUICtrlFactory::getInstance()->buildPanel(this, xml_file);
  67. }
  68. bool LLMediaRemoteCtrl::postBuild()
  69. {
  70. if (mType == REMOTE_PARCEL_MEDIA)
  71. {
  72. mIcon = getChild<LLIconCtrl>("media_icon");
  73. mIconToolTip = mIcon->getToolTip();
  74. mPlay = getChild<LLButton>("media_play");
  75. mPlay->setClickedCallback(LLViewerParcelMedia::play, this);
  76. mPause = getChild<LLButton>("media_pause");
  77. mPause->setClickedCallback(LLViewerParcelMedia::pause, this);
  78. mStop = getChild<LLButton>("media_stop");
  79. mStop->setClickedCallback(LLViewerParcelMedia::stop, this);
  80. }
  81. else if (mType == REMOTE_SHARED_MEDIA)
  82. {
  83. childSetAction("media_list", nearby_media_toggle, this);
  84. // The "play" button pointer is used for the button enabling all nearby
  85. // media.
  86. mPlay = getChild<LLButton>("media_play");
  87. mPlay->setClickedCallback(LLViewerMedia::sharedMediaEnable, this);
  88. // The "stop" button pointer is used for the button disabling all
  89. // nearby media.
  90. mStop = getChild<LLButton>("media_stop");
  91. mStop->setClickedCallback(LLViewerMedia::sharedMediaDisable, this);
  92. }
  93. else if (mType == REMOTE_PARCEL_MUSIC)
  94. {
  95. mIcon = getChild<LLIconCtrl>("music_icon");
  96. mIconToolTip = mIcon->getToolTip();
  97. mPlay = getChild<LLButton>("music_play");
  98. mPlay->setClickedCallback(LLViewerParcelMedia::playMusic, this);
  99. mPause = getChild<LLButton>("music_pause");
  100. mPause->setClickedCallback(LLViewerParcelMedia::pauseMusic, this);
  101. mStop = getChild<LLButton>("music_stop");
  102. mStop->setClickedCallback(LLViewerParcelMedia::stopMusic, this);
  103. }
  104. else if (mType == REMOTE_MASTER_VOLUME)
  105. {
  106. childSetAction("volume", LLOverlayBar::toggleAudioVolumeFloater, this);
  107. //childSetControlName("volume", "ShowAudioVolume"); // Set in XML file
  108. }
  109. return true;
  110. }
  111. void LLMediaRemoteCtrl::draw()
  112. {
  113. LLParcel* parcel = gViewerParcelMgr.getAgentParcel();
  114. static LLCachedControl<LLColor4U> icon_disabled_color(gColors,
  115. "IconDisabledColor");
  116. static LLCachedControl<LLColor4U> icon_enabled_color(gColors,
  117. "IconEnabledColor");
  118. static LLCachedControl<bool> enable_streaming_media(gSavedSettings,
  119. "EnableStreamingMedia");
  120. if (mType == REMOTE_PARCEL_MEDIA)
  121. {
  122. bool media_play_enabled = false;
  123. bool media_stop_enabled = false;
  124. bool media_show_pause = false;
  125. LLColor4 media_icon_color = LLColor4(icon_disabled_color);
  126. std::string media_type = LLMIMETypes::getDefaultMimeType();
  127. std::string media_url;
  128. if (enable_streaming_media && parcel &&
  129. LLViewerParcelMedia::hasParcelMedia())
  130. {
  131. media_play_enabled = true;
  132. media_icon_color = LLColor4(icon_enabled_color);
  133. media_type = parcel->getMediaType();
  134. media_url = parcel->getMediaURL();
  135. LLViewerMediaImpl::EMediaStatus status = LLViewerParcelMedia::getStatus();
  136. switch (status)
  137. {
  138. case LLViewerMediaImpl::MEDIA_NONE:
  139. media_show_pause = false;
  140. media_stop_enabled = false;
  141. break;
  142. case LLViewerMediaImpl::MEDIA_LOADING:
  143. case LLViewerMediaImpl::MEDIA_LOADED:
  144. case LLViewerMediaImpl::MEDIA_PLAYING:
  145. // HACK: only show the pause button for movie types
  146. media_show_pause = LLMIMETypes::widgetType(parcel->getMediaType()) == "movie";
  147. media_stop_enabled = true;
  148. media_play_enabled = false;
  149. break;
  150. case LLViewerMediaImpl::MEDIA_PAUSED:
  151. media_show_pause = false;
  152. media_stop_enabled = true;
  153. break;
  154. default:
  155. // inherit defaults above
  156. break;
  157. }
  158. }
  159. mPlay->setEnabled(media_play_enabled);
  160. mPlay->setVisible(!media_show_pause);
  161. mStop->setEnabled(media_stop_enabled);
  162. mPause->setEnabled(media_show_pause);
  163. mPause->setVisible(media_show_pause);
  164. const std::string media_icon_name = LLMIMETypes::findIcon(media_type);
  165. if (mIcon)
  166. {
  167. if (!media_icon_name.empty())
  168. {
  169. mIcon->setImage(media_icon_name);
  170. }
  171. mIcon->setColor(media_icon_color);
  172. if (media_url.empty())
  173. {
  174. media_url = mIconToolTip;
  175. }
  176. else
  177. {
  178. media_url = mIconToolTip + " (" + media_url + ")";
  179. }
  180. mIcon->setToolTip(media_url);
  181. }
  182. }
  183. else if (mType == REMOTE_SHARED_MEDIA)
  184. {
  185. static LLCachedControl<bool> enable_shared_media(gSavedSettings,
  186. "PrimMediaMasterEnabled");
  187. bool show = enable_streaming_media && enable_shared_media;
  188. mPlay->setEnabled(show && LLViewerMedia::isAnyMediaDisabled());
  189. mStop->setEnabled(show && LLViewerMedia::isAnyMediaEnabled());
  190. }
  191. else if (mType == REMOTE_PARCEL_MUSIC)
  192. {
  193. bool music_play_enabled = false;
  194. bool music_stop_enabled = false;
  195. bool music_show_pause = false;
  196. static LLCachedControl<bool> audio_streaming_music(gSavedSettings,
  197. "EnableStreamingMusic");
  198. static std::string artist_str = "\n" + getString("artist_string") +
  199. ": ";
  200. static std::string title_str = "\n" + getString("title_string") + ": ";
  201. LLColor4 music_icon_color = LLColor4(icon_disabled_color);
  202. std::string music_url;
  203. if (gAudiop && audio_streaming_music && parcel &&
  204. LLViewerParcelMedia::hasParcelAudio())
  205. {
  206. music_icon_color = LLColor4(icon_enabled_color);
  207. music_url = parcel->getMusicURL();
  208. music_play_enabled = true;
  209. music_show_pause = LLViewerParcelMedia::parcelMusicPlaying();
  210. music_stop_enabled = !LLViewerParcelMedia::parcelMusicStopped();
  211. }
  212. mPlay->setEnabled(music_play_enabled);
  213. mPlay->setVisible(!music_show_pause);
  214. mStop->setEnabled(music_stop_enabled);
  215. mPause->setEnabled(music_show_pause);
  216. mPause->setVisible(music_show_pause);
  217. if (mIcon)
  218. {
  219. mIcon->setColor(music_icon_color);
  220. std::string tool_tip = mIconToolTip;
  221. if (!music_url.empty())
  222. {
  223. tool_tip += " (" + music_url + ")";
  224. if (mCachedURL != music_url)
  225. {
  226. mCachedURL = music_url;
  227. mCachedMetaData.clear();
  228. }
  229. }
  230. if (music_show_pause && gAudiop)
  231. {
  232. LLStreamingAudioInterface* stream = gAudiop->getStreamingAudioImpl();
  233. if (stream)
  234. {
  235. if (stream->newMetaData())
  236. {
  237. mCachedMetaData.clear();
  238. std::string temp = stream->getArtist();
  239. if (!temp.empty())
  240. {
  241. mCachedMetaData += artist_str + temp;
  242. }
  243. temp = stream->getTitle();
  244. if (!temp.empty())
  245. {
  246. mCachedMetaData += title_str + temp;
  247. }
  248. stream->gotMetaData();
  249. static LLCachedControl<bool> notify_stream_changes(gSavedSettings,
  250. "NotifyStreamChanges");
  251. if (notify_stream_changes && !mCachedMetaData.empty())
  252. {
  253. LLSD args;
  254. args["STREAM_DATA"] = mCachedMetaData;
  255. gNotifications.add("StreamChanged", args);
  256. }
  257. }
  258. }
  259. else
  260. {
  261. mCachedMetaData.clear();
  262. }
  263. tool_tip += mCachedMetaData;
  264. }
  265. mIcon->setToolTip(tool_tip);
  266. }
  267. }
  268. LLPanel::draw();
  269. }