llpanellandmedia.cpp

Go to the documentation of this file.
00001 
00033 #include "llviewerprecompiledheaders.h"
00034 
00035 #include "llpanellandmedia.h"
00036 
00037 // viewer includes
00038 #include "llmimetypes.h"
00039 #include "llviewerparcelmgr.h"
00040 #include "lluictrlfactory.h"
00041 
00042 // library includes
00043 #include "llcheckboxctrl.h"
00044 #include "llcombobox.h"
00045 #include "llfloaterurlentry.h"
00046 #include "llfocusmgr.h"
00047 #include "lllineeditor.h"
00048 #include "llparcel.h"
00049 #include "lltextbox.h"
00050 #include "llradiogroup.h"
00051 #include "llspinctrl.h"
00052 #include "llsdutil.h"
00053 #include "lltexturectrl.h"
00054 #include "roles_constants.h"
00055 
00056 // Values for the parcel voice settings radio group
00057 enum
00058 {
00059         kRadioVoiceChatEstate = 0,
00060         kRadioVoiceChatPrivate = 1,
00061         kRadioVoiceChatDisable = 2
00062 };
00063 
00064 //---------------------------------------------------------------------------
00065 // LLPanelLandMedia
00066 //---------------------------------------------------------------------------
00067 
00068 LLPanelLandMedia::LLPanelLandMedia(LLParcelSelectionHandle& parcel)
00069 :       LLPanel("land_media_panel"), mParcel(parcel)
00070 {
00071 }
00072 
00073 
00074 // virtual
00075 LLPanelLandMedia::~LLPanelLandMedia()
00076 {
00077         // close LLFloaterURLEntry?
00078 }
00079 
00080 
00081 BOOL LLPanelLandMedia::postBuild()
00082 {
00083         mCheckSoundLocal = getChild<LLCheckBoxCtrl>("check sound local");
00084         childSetCommitCallback("check sound local", onCommitAny, this);
00085 
00086         mRadioVoiceChat = getChild<LLRadioGroup>("parcel_voice_channel");
00087         childSetCommitCallback("parcel_voice_channel", onCommitAny, this);
00088 
00089         mMusicURLEdit = getChild<LLLineEditor>("music_url");
00090         childSetCommitCallback("music_url", onCommitAny, this);
00091 
00092         mMediaTextureCtrl = getChild<LLTextureCtrl>("media texture");
00093         mMediaTextureCtrl->setCommitCallback( onCommitAny );
00094         mMediaTextureCtrl->setCallbackUserData( this );
00095         mMediaTextureCtrl->setAllowNoTexture ( TRUE );
00096         mMediaTextureCtrl->setImmediateFilterPermMask(PERM_COPY | PERM_TRANSFER);
00097         mMediaTextureCtrl->setNonImmediateFilterPermMask(PERM_COPY | PERM_TRANSFER);
00098 
00099         mMediaAutoScaleCheck = getChild<LLCheckBoxCtrl>("media_auto_scale");
00100         childSetCommitCallback("media_auto_scale", onCommitAny, this);
00101 
00102         mMediaLoopCheck = getChild<LLCheckBoxCtrl>("media_loop");
00103         childSetCommitCallback("media_loop", onCommitAny, this);
00104 
00105         mMediaUrlCheck = getChild<LLCheckBoxCtrl>("hide_media_url");
00106         childSetCommitCallback("hide_media_url", onCommitAny, this);
00107 
00108         mMusicUrlCheck = getChild<LLCheckBoxCtrl>("hide_music_url");
00109         childSetCommitCallback("hide_music_url", onCommitAny, this);
00110 
00111         mMediaURLEdit = getChild<LLLineEditor>("media_url");
00112         childSetCommitCallback("media_url", onCommitAny, this);
00113 
00114         mMediaDescEdit = getChild<LLLineEditor>("url_description");
00115         childSetCommitCallback("url_description", onCommitAny, this);
00116 
00117         mMediaTypeCombo = getChild<LLComboBox>("media type");
00118         childSetCommitCallback("media type", onCommitType, this);
00119         populateMIMECombo();
00120 
00121         mMediaWidthCtrl = getChild<LLSpinCtrl>("media_size_width");
00122         childSetCommitCallback("media_size_width", onCommitAny, this);
00123         mMediaHeightCtrl = getChild<LLSpinCtrl>("media_size_height");
00124         childSetCommitCallback("media_size_height", onCommitAny, this);
00125         mMediaSizeCtrlLabel = getChild<LLTextBox>("media_size");
00126 
00127         mSetURLButton = getChild<LLButton>("set_media_url");
00128         childSetAction("set_media_url", onSetBtn, this);
00129 
00130         return TRUE;
00131 }
00132 
00133 
00134 // public
00135 void LLPanelLandMedia::refresh()
00136 {
00137         LLParcel *parcel = mParcel->getParcel();
00138 
00139         if (!parcel)
00140         {
00141                 clearCtrls();
00142         }
00143         else
00144         {
00145                 // something selected, hooray!
00146 
00147                 // Display options
00148                 BOOL can_change_media = LLViewerParcelMgr::isParcelModifiableByAgent(parcel, GP_LAND_CHANGE_MEDIA);
00149 
00150                 mCheckSoundLocal->set( parcel->getSoundLocal() );
00151                 mCheckSoundLocal->setEnabled( can_change_media );
00152 
00153                 if(parcel->getVoiceEnabled())
00154                 {
00155                         if(parcel->getVoiceUseEstateChannel())
00156                                 mRadioVoiceChat->setSelectedIndex(kRadioVoiceChatEstate);
00157                         else
00158                                 mRadioVoiceChat->setSelectedIndex(kRadioVoiceChatPrivate);
00159                 }
00160                 else
00161                 {
00162                         mRadioVoiceChat->setSelectedIndex(kRadioVoiceChatDisable);
00163                 }
00164 
00165                 mRadioVoiceChat->setEnabled( can_change_media );
00166 
00167                 mMusicURLEdit->setText(parcel->getMusicURL());
00168                 mMusicURLEdit->setEnabled( can_change_media );
00169 
00170                 mMediaURLEdit->setText(parcel->getMediaURL());
00171                 mMediaURLEdit->setEnabled( FALSE );
00172 
00173                 mMediaDescEdit->setText(LLString(parcel->getMediaDesc()));
00174                 mMediaDescEdit->setEnabled( can_change_media );
00175 
00176                 std::string mime_type = parcel->getMediaType();
00177                 if (mime_type.empty())
00178                 {
00179                         mime_type = "none/none";
00180                 }
00181                 setMediaType(mime_type);
00182                 mMediaTypeCombo->setEnabled( can_change_media );
00183                 childSetText("mime_type", mime_type);
00184 
00185                 mMediaUrlCheck->set( parcel->getObscureMedia() );
00186                 mMediaUrlCheck->setEnabled( can_change_media );
00187 
00188                 mMusicUrlCheck->set( parcel->getObscureMusic() );
00189                 mMusicUrlCheck->setEnabled( can_change_media );
00190 
00191                 // don't display urls if you're not able to change it
00192                 // much requested change in forums so people can't 'steal' urls
00193                 // NOTE: bug#2009 means this is still vunerable - however, bug
00194                 // should be closed since this bug opens up major security issues elsewhere.
00195                 bool obscure_media = ! can_change_media && parcel->getObscureMedia();
00196                 bool obscure_music = ! can_change_media && parcel->getObscureMusic();
00197 
00198                 // Special code to disable asterixes for html type
00199                 if(mime_type == "text/html")
00200                 {
00201                         obscure_media = false;
00202                         mMediaUrlCheck->set( 0 );
00203                         mMediaUrlCheck->setEnabled( false );
00204                 }
00205 
00206                 mMusicURLEdit->setDrawAsterixes( obscure_music );
00207                 mMediaURLEdit->setDrawAsterixes( obscure_media );
00208 
00209                 mMediaAutoScaleCheck->set( parcel->getMediaAutoScale () );
00210                 mMediaAutoScaleCheck->setEnabled ( can_change_media );
00211 
00212                 // Special code to disable looping checkbox for HTML MIME type
00213                 // (DEV-10042 -- Parcel Media: "Loop Media" should be disabled for static media types)
00214                 bool allow_looping = LLMIMETypes::findAllowLooping( mime_type );
00215                 if ( allow_looping )
00216                         mMediaLoopCheck->set( parcel->getMediaLoop () );
00217                 else
00218                         mMediaLoopCheck->set( false );
00219                 mMediaLoopCheck->setEnabled ( can_change_media && allow_looping );
00220 
00221                 // disallow media size change for mime types that don't allow it
00222                 bool allow_resize = LLMIMETypes::findAllowResize( mime_type );
00223                 if ( allow_resize )
00224                         mMediaWidthCtrl->setValue( parcel->getMediaWidth() );
00225                 else
00226                         mMediaWidthCtrl->setValue( 0 );
00227                 mMediaWidthCtrl->setEnabled ( can_change_media && allow_resize );
00228 
00229                 if ( allow_resize )
00230                         mMediaHeightCtrl->setValue( parcel->getMediaHeight() );
00231                 else
00232                         mMediaHeightCtrl->setValue( 0 );
00233                 mMediaHeightCtrl->setEnabled ( can_change_media && allow_resize );
00234 
00235                 // enable/disable for text label for completeness
00236                 mMediaSizeCtrlLabel->setEnabled( can_change_media && allow_resize );
00237 
00238                 LLUUID tmp = parcel->getMediaID();
00239                 mMediaTextureCtrl->setImageAssetID ( parcel->getMediaID() );
00240                 mMediaTextureCtrl->setEnabled( can_change_media );
00241 
00242                 mSetURLButton->setEnabled( can_change_media );
00243 
00244                 #if 0
00245                 // there is a media url and a media texture selected
00246                 if ( ( ! ( std::string ( parcel->getMediaURL() ).empty () ) ) && ( ! ( parcel->getMediaID ().isNull () ) ) )
00247                 {
00248                         // turn on transport controls if allowed for this parcel
00249                         mMediaStopButton->setEnabled ( editable );
00250                         mMediaStartButton->setEnabled ( editable );
00251                 }
00252                 else
00253                 {
00254                         // no media url or no media texture
00255                         mMediaStopButton->setEnabled ( FALSE );
00256                         mMediaStartButton->setEnabled ( FALSE );
00257                 };
00258                 #endif
00259 
00260                 LLFloaterURLEntry* floater_url_entry = (LLFloaterURLEntry*)mURLEntryFloater.get();
00261                 if (floater_url_entry)
00262                 {
00263                         floater_url_entry->updateFromLandMediaPanel();
00264                 }
00265         }
00266 }
00267 
00268 void LLPanelLandMedia::populateMIMECombo()
00269 {
00270         LLString default_mime_type = "none/none";
00271         LLString default_label;
00272         LLMIMETypes::mime_widget_set_map_t::const_iterator it;
00273         for (it = LLMIMETypes::sWidgetMap.begin(); it != LLMIMETypes::sWidgetMap.end(); ++it)
00274         {
00275                 const LLString& mime_type = it->first;
00276                 const LLMIMETypes::LLMIMEWidgetSet& info = it->second;
00277                 if (info.mDefaultMimeType == default_mime_type)
00278                 {
00279                         // Add this label at the end to make UI look cleaner
00280                         default_label = info.mLabel;
00281                 }
00282                 else
00283                 {
00284                         mMediaTypeCombo->add(info.mLabel, mime_type);
00285                 }
00286         }
00287         // *TODO: The sort order is based on std::map key, which is
00288         // ASCII-sorted and is wrong in other languages.  TRANSLATE
00289         mMediaTypeCombo->add( default_label, default_mime_type, ADD_BOTTOM );
00290 }
00291 
00292 void LLPanelLandMedia::setMediaType(const LLString& mime_type)
00293 {
00294         LLParcel *parcel = mParcel->getParcel();
00295         if(parcel)
00296                 parcel->setMediaType(mime_type.c_str());
00297 
00298         LLString media_key = LLMIMETypes::widgetType(mime_type);
00299         mMediaTypeCombo->setValue(media_key);
00300         childSetText("mime_type", mime_type);
00301 }
00302 
00303 void LLPanelLandMedia::setMediaURL(const LLString& media_url)
00304 {
00305         mMediaURLEdit->setText(media_url);
00306         mMediaURLEdit->onCommit();
00307 }
00308 
00309 LLString LLPanelLandMedia::getMediaURL()
00310 {
00311         return mMediaURLEdit->getText();
00312 }
00313 
00314 // static
00315 void LLPanelLandMedia::onCommitType(LLUICtrl *ctrl, void *userdata)
00316 {
00317         LLPanelLandMedia *self = (LLPanelLandMedia *)userdata;
00318         std::string current_type = LLMIMETypes::widgetType(self->childGetText("mime_type"));
00319         std::string new_type = self->mMediaTypeCombo->getValue();
00320         if(current_type != new_type)
00321         {
00322                 self->childSetText("mime_type", LLMIMETypes::findDefaultMimeType(new_type));
00323         }
00324         onCommitAny(ctrl, userdata);
00325 
00326 }
00327 
00328 // static
00329 void LLPanelLandMedia::onCommitAny(LLUICtrl*, void *userdata)
00330 {
00331         LLPanelLandMedia *self = (LLPanelLandMedia *)userdata;
00332 
00333         LLParcel* parcel = self->mParcel->getParcel();
00334         if (!parcel)
00335         {
00336                 return;
00337         }
00338 
00339         // Extract data from UI
00340         BOOL sound_local                = self->mCheckSoundLocal->get();
00341         int voice_setting               = self->mRadioVoiceChat->getSelectedIndex();
00342         std::string music_url   = self->mMusicURLEdit->getText();
00343         std::string media_url   = self->mMediaURLEdit->getText();
00344         std::string media_desc  = self->mMediaDescEdit->getText();
00345         std::string mime_type   = self->childGetText("mime_type");
00346         U8 media_auto_scale             = self->mMediaAutoScaleCheck->get();
00347         U8 media_loop           = self->mMediaLoopCheck->get();
00348         U8 obscure_media                = self->mMediaUrlCheck->get();
00349         U8 obscure_music                = self->mMusicUrlCheck->get();
00350         S32 media_width                 = (S32)self->mMediaWidthCtrl->get();
00351         S32 media_height                = (S32)self->mMediaHeightCtrl->get();
00352         LLUUID media_id                 = self->mMediaTextureCtrl->getImageAssetID();
00353 
00354         self->childSetText("mime_type", mime_type);
00355 
00356         BOOL voice_enabled;
00357         BOOL voice_estate_chan;
00358 
00359         switch(voice_setting)
00360         {
00361                 default:
00362                 case kRadioVoiceChatEstate:
00363                         voice_enabled = TRUE;
00364                         voice_estate_chan = TRUE;
00365                 break;
00366                 case kRadioVoiceChatPrivate:
00367                         voice_enabled = TRUE;
00368                         voice_estate_chan = FALSE;
00369                 break;
00370                 case kRadioVoiceChatDisable:
00371                         voice_enabled = FALSE;
00372                         voice_estate_chan = FALSE;
00373                 break;
00374         }
00375 
00376         // Remove leading/trailing whitespace (common when copying/pasting)
00377         LLString::trim(music_url);
00378         LLString::trim(media_url);
00379 
00380         // Push data into current parcel
00381         parcel->setParcelFlag(PF_ALLOW_VOICE_CHAT, voice_enabled);
00382         parcel->setParcelFlag(PF_USE_ESTATE_VOICE_CHAN, voice_estate_chan);
00383         parcel->setParcelFlag(PF_SOUND_LOCAL, sound_local);
00384         parcel->setMusicURL(music_url.c_str());
00385         parcel->setMediaURL(media_url.c_str());
00386         parcel->setMediaType(mime_type.c_str());
00387         parcel->setMediaDesc(media_desc.c_str());
00388         parcel->setMediaWidth(media_width);
00389         parcel->setMediaHeight(media_height);
00390         parcel->setMediaID(media_id);
00391         parcel->setMediaAutoScale ( media_auto_scale );
00392         parcel->setMediaLoop ( media_loop );
00393         parcel->setObscureMedia( obscure_media );
00394         parcel->setObscureMusic( obscure_music );
00395 
00396         // Send current parcel data upstream to server
00397         LLViewerParcelMgr::getInstance()->sendParcelPropertiesUpdate( parcel );
00398 
00399         // Might have changed properties, so let's redraw!
00400         self->refresh();
00401 }
00402 // static
00403 void LLPanelLandMedia::onSetBtn(void *userdata)
00404 {
00405         LLPanelLandMedia *self = (LLPanelLandMedia *)userdata;
00406         self->mURLEntryFloater = LLFloaterURLEntry::show( self->getHandle() );
00407         LLFloater* parent_floater = gFloaterView->getParentFloater(self);
00408         if (parent_floater)
00409         {
00410                 parent_floater->addDependentFloater(self->mURLEntryFloater.get());
00411         }
00412 }

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