diff options
Diffstat (limited to 'indra/newview/llpanelnearbymedia.cpp')
-rw-r--r-- | indra/newview/llpanelnearbymedia.cpp | 154 |
1 files changed, 141 insertions, 13 deletions
diff --git a/indra/newview/llpanelnearbymedia.cpp b/indra/newview/llpanelnearbymedia.cpp index a46894988c..aa60c5cf6c 100644 --- a/indra/newview/llpanelnearbymedia.cpp +++ b/indra/newview/llpanelnearbymedia.cpp @@ -29,7 +29,9 @@ #include "llpanelnearbymedia.h" #include "llaudioengine.h" +#include "llbase64.h" #include "llcheckboxctrl.h" +#include "llclipboard.h" #include "llcombobox.h" #include "llresizebar.h" #include "llresizehandle.h" @@ -53,7 +55,9 @@ #include "llvovolume.h" #include "llstatusbar.h" #include "llsdutil.h" +#include "lltoggleablemenu.h" #include "llvieweraudio.h" +#include "llviewermenu.h" #include "llfloaterreg.h" #include "llfloaterpreference.h" // for the gear icon @@ -74,10 +78,10 @@ static const LLUUID PARCEL_AUDIO_LIST_ITEM_UUID = LLUUID("DF4B020D-8A24-4B95-AB5 LLPanelNearByMedia::LLPanelNearByMedia() : mMediaList(NULL), mEnableAllCtrl(NULL), - mAllMediaDisabled(false), mDebugInfoVisible(false), mParcelMediaItem(NULL), - mParcelAudioItem(NULL) + mParcelAudioItem(NULL), + mMoreLessBtn(NULL) { // This is just an initial value, mParcelAudioAutoStart does not affect ParcelMediaAutoPlayEnable mParcelAudioAutoStart = gSavedSettings.getS32("ParcelMediaAutoPlayEnable") != 0 @@ -97,6 +101,18 @@ LLPanelNearByMedia::LLPanelNearByMedia() mCommitCallbackRegistrar.add("SelectedMediaCtrl.Zoom", boost::bind(&LLPanelNearByMedia::onClickSelectedMediaZoom, this)); mCommitCallbackRegistrar.add("SelectedMediaCtrl.Unzoom", boost::bind(&LLPanelNearByMedia::onClickSelectedMediaUnzoom, this)); + // Context menu handler. + mCommitCallbackRegistrar.add("SelectedMediaCtrl.Action", + [this](LLUICtrl* ctrl, const LLSD& data) + { + onMenuAction(data); + }); + mEnableCallbackRegistrar.add("SelectedMediaCtrl.Visible", + [this](LLUICtrl* ctrl, const LLSD& data) + { + return onMenuVisible(data); + }); + buildFromFile( "panel_nearby_media.xml"); } @@ -104,7 +120,7 @@ LLPanelNearByMedia::~LLPanelNearByMedia() { } -BOOL LLPanelNearByMedia::postBuild() +bool LLPanelNearByMedia::postBuild() { LLPanelPulldown::postBuild(); @@ -147,6 +163,7 @@ BOOL LLPanelNearByMedia::postBuild() mUnzoomCtrl = getChild<LLUICtrl>("unzoom"); mVolumeSlider = getChild<LLSlider>("volume_slider"); mMuteBtn = getChild<LLButton>("mute_btn"); + mMoreLessBtn = getChild<LLButton>("more_btn"); mEmptyNameString = getString("empty_item_text"); mParcelMediaName = getString("parcel_media_name"); @@ -154,8 +171,8 @@ BOOL LLPanelNearByMedia::postBuild() mPlayingString = getString("playing_suffix"); mMediaList->setDoubleClickCallback(onZoomMedia, this); - mMediaList->sortByColumnIndex(PROXIMITY_COLUMN, TRUE); - mMediaList->sortByColumnIndex(VISIBILITY_COLUMN, FALSE); + mMediaList->sortByColumnIndex(PROXIMITY_COLUMN, true); + mMediaList->sortByColumnIndex(VISIBILITY_COLUMN, false); refreshList(); updateControls(); @@ -166,10 +183,15 @@ BOOL LLPanelNearByMedia::postBuild() mLessRect = getRect(); mLessRect.mBottom = minimized_controls->getRect().mBottom; - getChild<LLUICtrl>("more_btn")->setVisible(false); + mMoreLessBtn->setVisible(false); onMoreLess(); - return TRUE; + mContextMenu = LLUICtrlFactory::getInstance()->createFromFile<LLToggleableMenu>( + "menu_nearby_media.xml", + gMenuHolder, + LLViewerMenuHolderGL::child_registry_t::instance()); + + return true; } void LLPanelNearByMedia::handleMediaAutoPlayChanged(const LLSD& newvalue) @@ -189,12 +211,11 @@ void LLPanelNearByMedia::handleMediaAutoPlayChanged(const LLSD& newvalue) } /*virtual*/ -void LLPanelNearByMedia::reshape(S32 width, S32 height, BOOL called_from_parent) +void LLPanelNearByMedia::reshape(S32 width, S32 height, bool called_from_parent) { LLPanelPulldown::reshape(width, height, called_from_parent); - LLButton* more_btn = findChild<LLButton>("more_btn"); - if (more_btn && more_btn->getValue().asBoolean()) + if (mMoreLessBtn && mMoreLessBtn->getValue().asBoolean()) { mMoreRect = getRect(); } @@ -220,7 +241,7 @@ void LLPanelNearByMedia::draw() } /*virtual*/ -BOOL LLPanelNearByMedia::handleHover(S32 x, S32 y, MASK mask) +bool LLPanelNearByMedia::handleHover(S32 x, S32 y, MASK mask) { LLPanelPulldown::handleHover(x, y, mask); @@ -234,6 +255,42 @@ BOOL LLPanelNearByMedia::handleHover(S32 x, S32 y, MASK mask) return true; } +bool LLPanelNearByMedia::handleRightMouseDown(S32 x, S32 y, MASK mask) +{ + S32 x_list, y_list; + localPointToOtherView(x, y, &x_list, &y_list, mMediaList); + if (mMoreLessBtn->getToggleState() + && mMediaList->pointInView(x_list, y_list)) + { + LLScrollListItem* hit_item = mMediaList->hitItem(x_list, y_list); + bool selected = hit_item && hit_item->getSelected(); + if (!selected) + { + selected = mMediaList->selectItemAt(x_list, y_list, mask); + } + + if (selected && mContextMenu) + { + mContextMenu->buildDrawLabels(); + mContextMenu->updateParent(LLMenuGL::sMenuContainer); + LLMenuGL::showPopup(this, mContextMenu, x, y); + return true; + } + } + + return LLPanelPulldown::handleRightMouseDown(x, y, mask); +} + + +void LLPanelNearByMedia::onVisibilityChange(bool new_visibility) +{ + if (!new_visibility && mContextMenu->getVisible()) + { + gMenuHolder->hideMenus(); + } + LLPanelPulldown::onVisibilityChange(new_visibility); +} + bool LLPanelNearByMedia::getParcelAudioAutoStart() { return mParcelAudioAutoStart; @@ -923,7 +980,7 @@ void LLPanelNearByMedia::onAdvancedButtonClick() void LLPanelNearByMedia::onMoreLess() { - bool is_more = getChild<LLButton>("more_btn")->getToggleState(); + bool is_more = mMoreLessBtn->getToggleState(); mNearbyMediaPanel->setVisible(is_more); // enable resizing when expanded @@ -934,7 +991,7 @@ void LLPanelNearByMedia::onMoreLess() setShape(new_rect); - getChild<LLUICtrl>("more_btn")->setVisible(true); + mMoreLessBtn->setVisible(true); } void LLPanelNearByMedia::updateControls() @@ -1174,6 +1231,53 @@ void LLPanelNearByMedia::onClickSelectedMediaUnzoom() LLViewerMediaFocus::getInstance()->unZoom(); } +void LLPanelNearByMedia::onMenuAction(const LLSD& userdata) +{ + const std::string command_name = userdata.asString(); + if ("copy_url" == command_name) + { + LLClipboard::instance().reset(); + std::string url = getSelectedUrl(); + + if (!url.empty()) + { + LLClipboard::instance().copyToClipboard(utf8str_to_wstring(url), 0, url.size()); + } + } + else if ("copy_data" == command_name) + { + LLClipboard::instance().reset(); + std::string url = getSelectedUrl(); + static const std::string encoding_specifier = "base64,"; + size_t pos = url.find(encoding_specifier); + if (pos != std::string::npos) + { + pos += encoding_specifier.size(); + std::string res = LLBase64::decodeAsString(url.substr(pos)); + LLClipboard::instance().copyToClipboard(utf8str_to_wstring(res), 0, res.size()); + } + else + { + url = LLURI::unescape(url); + LLClipboard::instance().copyToClipboard(utf8str_to_wstring(url), 0, url.size()); + } + } +} + +bool LLPanelNearByMedia::onMenuVisible(const LLSD& userdata) +{ + const std::string command_name = userdata.asString(); + if ("copy_data" == command_name) + { + std::string url = getSelectedUrl(); + if (url.rfind("data:", 0) == 0) + { + // might be a a good idea to permit text/html only + return true; + } + } + return false; +} // static void LLPanelNearByMedia::getNameAndUrlHelper(LLViewerMediaImpl* impl, std::string& name, std::string & url, const std::string &defaultName) @@ -1200,3 +1304,27 @@ void LLPanelNearByMedia::getNameAndUrlHelper(LLViewerMediaImpl* impl, std::strin } } +std::string LLPanelNearByMedia::getSelectedUrl() +{ + std::string url; + LLUUID selected_media_id = mMediaList->getValue().asUUID(); + if (selected_media_id == PARCEL_AUDIO_LIST_ITEM_UUID) + { + url = LLViewerMedia::getInstance()->getParcelAudioURL(); + } + else if (selected_media_id == PARCEL_MEDIA_LIST_ITEM_UUID) + { + url = LLViewerParcelMedia::getInstance()->getURL(); + } + else + { + LLViewerMediaImpl* impl = LLViewerMedia::getInstance()->getMediaImplFromTextureID(selected_media_id); + if (NULL != impl) + { + std::string name; + getNameAndUrlHelper(impl, name, url, mEmptyNameString); + } + } + return url; +} + |