llmediaremotectrl.cpp

Go to the documentation of this file.
00001 
00032 #include "llviewerprecompiledheaders.h"
00033 
00034 #include "llmediaremotectrl.h"
00035 
00036 #include "audioengine.h"
00037 #include "lliconctrl.h"
00038 #include "llmimetypes.h"
00039 #include "lloverlaybar.h"
00040 #include "llviewermedia.h"
00041 #include "llviewerparcelmedia.h"
00042 #include "llviewerparcelmgr.h"
00043 #include "lluictrlfactory.h"
00044 #include "llpanelaudiovolume.h"
00045 #include "llparcel.h"
00046 #include "llviewercontrol.h"
00047 #include "llbutton.h"
00048 
00050 //
00051 //
00052 
00053 static LLRegisterWidget<LLMediaRemoteCtrl> r("media_remote");
00054 
00055 LLMediaRemoteCtrl::LLMediaRemoteCtrl()
00056 {
00057         setIsChrome(TRUE);
00058         setFocusRoot(TRUE);
00059 
00060         mFactoryMap["Volume Panel"]     = LLCallbackMap(createVolumePanel, NULL);
00061         build();
00062 }
00063 
00064 void LLMediaRemoteCtrl::build()
00065 {
00066         //HACK: only works because we don't have any implicit children (i.e. titlebars, close button, etc)
00067         deleteAllChildren();
00068         if (gSavedSettings.getBOOL("ShowVolumeSettingsPopup"))
00069         {
00070                 LLUICtrlFactory::getInstance()->buildPanel(this, "panel_media_remote_expanded.xml", &getFactoryMap());
00071         }
00072         else
00073         {
00074                 LLUICtrlFactory::getInstance()->buildPanel(this, "panel_media_remote.xml", &getFactoryMap());
00075         }
00076 }
00077 
00078 BOOL LLMediaRemoteCtrl::postBuild()
00079 {
00080         mControls = getChild<LLPanel>("media_controls");
00081         llassert_always(mControls);
00082         
00083         childSetAction("media_play",LLOverlayBar::toggleMediaPlay,this);
00084         childSetAction("music_play",LLOverlayBar::toggleMusicPlay,this);
00085         childSetAction("media_stop",LLOverlayBar::mediaStop,this);
00086         childSetAction("music_stop",LLOverlayBar::toggleMusicPlay,this);
00087         childSetAction("media_pause",LLOverlayBar::toggleMediaPlay,this);
00088         childSetAction("music_pause",LLOverlayBar::toggleMusicPlay,this);
00089 
00090         childSetAction("expand", onClickExpandBtn, this);       
00091         return TRUE;
00092 }
00093 
00094 void LLMediaRemoteCtrl::draw()
00095 {
00096         enableMediaButtons();
00097         
00098         LLButton* expand_button = getChild<LLButton>("expand");
00099         if (expand_button)
00100         {
00101                 if (expand_button->getToggleState())
00102                 {
00103                         expand_button->setImageOverlay("arrow_down.tga");
00104                 }
00105                 else
00106                 {
00107                         expand_button->setImageOverlay("arrow_up.tga");
00108                 }
00109         }
00110 
00111         LLPanel::draw();
00112 }
00113 
00114 LLMediaRemoteCtrl::~LLMediaRemoteCtrl ()
00115 {
00116 }
00117 
00118 //static 
00119 void LLMediaRemoteCtrl::onClickExpandBtn(void* user_data)
00120 {
00121         LLMediaRemoteCtrl* remotep = (LLMediaRemoteCtrl*)user_data;
00122 
00123         remotep->build();
00124         gOverlayBar->layoutButtons();
00125 
00126 }
00127 
00128 //static
00129 void* LLMediaRemoteCtrl::createVolumePanel(void* data)
00130 {
00131         LLPanelAudioVolume* panel = new LLPanelAudioVolume();
00132         return panel;
00133 }
00134 
00135 // Virtual
00136 void LLMediaRemoteCtrl::setToolTip(const LLString& msg)
00137 {
00138         LLString mime_type = LLMIMETypes::translate(LLViewerMedia::getMimeType());
00139         LLString tool_tip = LLMIMETypes::findToolTip(LLViewerMedia::getMimeType());
00140         LLString play_tip = LLMIMETypes::findPlayTip(LLViewerMedia::getMimeType());
00141         // childSetToolTip("media_stop", mControls->getString("stop_label") + "\n" + tool_tip);
00142         childSetToolTip("media_icon", tool_tip);
00143         childSetToolTip("media_play", play_tip);
00144 }
00145 
00146 void LLMediaRemoteCtrl::enableMediaButtons()
00147 {
00148         // Media
00149         bool play_media_enabled = false;
00150         bool stop_media_enabled = false;
00151         bool play_music_enabled = false;
00152         bool stop_music_enabled = false;
00153         bool music_show_pause = false;
00154         bool media_show_pause = false;
00155         LLColor4 music_icon_color = LLUI::sColorsGroup->getColor( "IconDisabledColor" );
00156         LLColor4 media_icon_color = LLUI::sColorsGroup->getColor( "IconDisabledColor" );
00157         LLString media_type = "none/none";
00158 
00159         // Put this in xui file
00160         LLString media_url = mControls->getString("default_tooltip_label");
00161         LLParcel* parcel = LLViewerParcelMgr::getInstance()->getAgentParcel();
00162 
00163         if (gSavedSettings.getBOOL("AudioStreamingVideo"))
00164         {
00165                 if ( parcel && parcel->getMediaURL()[0])
00166                 {
00167                         // Set the tooltip
00168                         // Put this text into xui file
00169                         media_url = parcel->getObscureMedia() ? mControls->getString("media_hidden_label") : parcel->getMediaURL();
00170                         media_type = parcel->getMediaType();
00171 
00172                         play_media_enabled = true;
00173                         media_icon_color = LLUI::sColorsGroup->getColor( "IconEnabledColor" );
00174 
00175                         LLMediaBase::EStatus status = LLViewerParcelMedia::getStatus();
00176                         switch(status)
00177                         {
00178                         case LLMediaBase::STATUS_STOPPED:
00179                         case LLMediaBase::STATUS_UNKNOWN:
00180                                 media_show_pause = false;
00181                                 stop_media_enabled = false;
00182                                 break;
00183                         case LLMediaBase::STATUS_STARTED:
00184                         case LLMediaBase::STATUS_NAVIGATING:
00185                         case LLMediaBase::STATUS_RESETTING:
00186                                 // HACK: only show the pause button for movie types
00187                                 media_show_pause = LLMIMETypes::widgetType(parcel->getMediaType()) == "movie" ? true : false;
00188                                 stop_media_enabled = true;
00189                                 play_media_enabled = false;
00190                                 break;
00191                         case LLMediaBase::STATUS_PAUSED:
00192                                 media_show_pause = false;
00193                                 stop_media_enabled = true;
00194                                 break;
00195                         default:
00196                                 // inherit defaults above
00197                                 break;
00198                         }
00199                 }
00200         }
00201         if (gSavedSettings.getBOOL("AudioStreamingMusic") && gAudiop)
00202         {
00203         
00204                 if ( parcel && parcel->getMusicURL()[0])
00205                 {
00206                         play_music_enabled = true;
00207                         music_icon_color = LLUI::sColorsGroup->getColor( "IconEnabledColor" );
00208 
00209                         if (gOverlayBar->musicPlaying())
00210                         {
00211                                 music_show_pause = true;
00212                                 stop_music_enabled = true;
00213                         }
00214                         else
00215                         {
00216                                 music_show_pause = false;
00217                                 stop_music_enabled = false;
00218                         }
00219                 }
00220                 // if no mime type has been set disable play
00221                 if( LLViewerMedia::getMimeType().empty() 
00222                         || LLViewerMedia::getMimeType() == "none/none")
00223                 {
00224                         play_media_enabled = false;
00225                         stop_media_enabled = false;
00226                 }
00227         }
00228         const LLString media_icon_name = LLMIMETypes::findIcon(media_type);
00229         LLButton* music_play_btn = getChild<LLButton>("music_play");
00230         LLButton* music_stop_btn = getChild<LLButton>("music_stop");
00231         LLButton* music_pause_btn = getChild<LLButton>("music_pause");
00232         LLButton* media_play_btn = getChild<LLButton>("media_play");
00233         LLButton* media_stop_btn = getChild<LLButton>("media_stop");
00234         LLButton* media_pause_btn = getChild<LLButton>("media_pause");
00235         LLIconCtrl* media_icon = getChild<LLIconCtrl>("media_icon");
00236 
00237         music_play_btn->setEnabled(play_music_enabled);
00238         music_stop_btn->setEnabled(stop_music_enabled);
00239         music_pause_btn->setEnabled(music_show_pause);
00240         music_pause_btn->setVisible(music_show_pause);
00241         music_play_btn->setVisible(! music_show_pause);
00242         childSetColor("music_icon", music_icon_color);
00243         if(!media_icon_name.empty())
00244         {
00245                 media_icon->setImage(media_icon_name);
00246         }
00247 
00248         media_play_btn->setEnabled(play_media_enabled);
00249         media_stop_btn->setEnabled(stop_media_enabled);
00250         media_pause_btn->setEnabled(media_show_pause);
00251         media_pause_btn->setVisible(media_show_pause);
00252         media_play_btn->setVisible(! media_show_pause);
00253         childSetColor("media_icon", media_icon_color);
00254 
00255         setToolTip(media_url);
00256 }
00257 
00258 

Generated on Fri May 16 08:33:47 2008 for SecondLife by  doxygen 1.5.5