From a5261a5fa8fad810ecb5c260d92c3e771822bf58 Mon Sep 17 00:00:00 2001 From: Ansariel Date: Tue, 20 Feb 2024 23:46:23 +0100 Subject: Convert BOOL to bool in llui --- indra/newview/llfloateravatarpicker.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'indra/newview/llfloateravatarpicker.cpp') diff --git a/indra/newview/llfloateravatarpicker.cpp b/indra/newview/llfloateravatarpicker.cpp index 2422596f60..9b5e084b34 100644 --- a/indra/newview/llfloateravatarpicker.cpp +++ b/indra/newview/llfloateravatarpicker.cpp @@ -118,19 +118,19 @@ LLFloaterAvatarPicker::LLFloaterAvatarPicker(const LLSD& key) mContextConeFadeTime = gSavedSettings.getF32("ContextConeFadeTime"); } -BOOL LLFloaterAvatarPicker::postBuild() +bool LLFloaterAvatarPicker::postBuild() { getChild("Edit")->setKeystrokeCallback( boost::bind(&LLFloaterAvatarPicker::editKeystroke, this, _1, _2),NULL); childSetAction("Find", boost::bind(&LLFloaterAvatarPicker::onBtnFind, this)); - getChildView("Find")->setEnabled(FALSE); + getChildView("Find")->setEnabled(false); childSetAction("Refresh", boost::bind(&LLFloaterAvatarPicker::onBtnRefresh, this)); getChild("near_me_range")->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onRangeAdjust, this)); LLScrollListCtrl* searchresults = getChild("SearchResults"); searchresults->setDoubleClickCallback( boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); searchresults->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onList, this)); - getChildView("SearchResults")->setEnabled(FALSE); + getChildView("SearchResults")->setEnabled(false); LLScrollListCtrl* nearme = getChild("NearMe"); nearme->setDoubleClickCallback(boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); @@ -141,10 +141,10 @@ BOOL LLFloaterAvatarPicker::postBuild() getChild("Friends")->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onList, this)); childSetAction("ok_btn", boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); - getChildView("ok_btn")->setEnabled(FALSE); + getChildView("ok_btn")->setEnabled(false); childSetAction("cancel_btn", boost::bind(&LLFloaterAvatarPicker::onBtnClose, this)); - getChild("Edit")->setFocus(TRUE); + getChild("Edit")->setFocus(true); LLPanel* search_panel = getChild("SearchPanel"); if (search_panel) @@ -164,7 +164,7 @@ BOOL LLFloaterAvatarPicker::postBuild() populateFriend(); - return TRUE; + return true; } void LLFloaterAvatarPicker::setOkBtnEnableCb(validate_callback_t cb) @@ -540,8 +540,8 @@ LLScrollListCtrl* LLFloaterAvatarPicker::getActiveList() return list; } -BOOL LLFloaterAvatarPicker::handleDragAndDrop(S32 x, S32 y, MASK mask, - BOOL drop, EDragAndDropType cargo_type, +bool LLFloaterAvatarPicker::handleDragAndDrop(S32 x, S32 y, MASK mask, + bool drop, EDragAndDropType cargo_type, void *cargo_data, EAcceptance *accept, std::string& tooltip_msg) { @@ -553,7 +553,7 @@ BOOL LLFloaterAvatarPicker::handleDragAndDrop(S32 x, S32 y, MASK mask, if (localRectToOtherView(rc_point, &rc_list, list)) { // Keep selected only one item - list->deselectAllItems(TRUE); + list->deselectAllItems(true); list->selectItemAt(rc_list.mLeft, rc_list.mBottom, mask); LLScrollListItem* selection = list->getFirstSelected(); if (selection) @@ -575,7 +575,7 @@ BOOL LLFloaterAvatarPicker::handleDragAndDrop(S32 x, S32 y, MASK mask, } } *accept = ACCEPT_NO; - return TRUE; + return true; } @@ -748,7 +748,7 @@ void LLFloaterAvatarPicker::editKeystroke(LLLineEditor* caller, void* user_data) } // virtual -BOOL LLFloaterAvatarPicker::handleKeyHere(KEY key, MASK mask) +bool LLFloaterAvatarPicker::handleKeyHere(KEY key, MASK mask) { if (key == KEY_RETURN && mask == MASK_NONE) { @@ -760,12 +760,12 @@ BOOL LLFloaterAvatarPicker::handleKeyHere(KEY key, MASK mask) { onBtnSelect(); } - return TRUE; + return true; } else if (key == KEY_ESCAPE && mask == MASK_NONE) { closeFloater(); - return TRUE; + return true; } return LLFloater::handleKeyHere(key, mask); -- cgit v1.2.3 From 60d3dd98a44230c21803c1606552ee098ed9fa7c Mon Sep 17 00:00:00 2001 From: Ansariel Date: Wed, 21 Feb 2024 21:05:14 +0100 Subject: Convert remaining BOOL to bool --- indra/newview/llfloateravatarpicker.cpp | 76 ++++++++++++++++----------------- 1 file changed, 38 insertions(+), 38 deletions(-) (limited to 'indra/newview/llfloateravatarpicker.cpp') diff --git a/indra/newview/llfloateravatarpicker.cpp b/indra/newview/llfloateravatarpicker.cpp index 9b5e084b34..8c4e7ff627 100644 --- a/indra/newview/llfloateravatarpicker.cpp +++ b/indra/newview/llfloateravatarpicker.cpp @@ -61,9 +61,9 @@ static const U32 AVATAR_PICKER_SEARCH_TIMEOUT = 180U; static std::map sAvatarNameMap; LLFloaterAvatarPicker* LLFloaterAvatarPicker::show(select_callback_t callback, - BOOL allow_multiple, - BOOL closeOnSelect, - BOOL skip_agent, + bool allow_multiple, + bool closeOnSelect, + bool skip_agent, const std::string& name, LLView * frustumOrigin) { @@ -78,7 +78,7 @@ LLFloaterAvatarPicker* LLFloaterAvatarPicker::show(select_callback_t callback, floater->mSelectionCallback = callback; floater->setAllowMultiple(allow_multiple); - floater->mNearMeListComplete = FALSE; + floater->mNearMeListComplete = false; floater->mCloseOnSelect = closeOnSelect; floater->mExcludeAgentFromSearchResults = skip_agent; @@ -103,9 +103,9 @@ LLFloaterAvatarPicker* LLFloaterAvatarPicker::show(select_callback_t callback, LLFloaterAvatarPicker::LLFloaterAvatarPicker(const LLSD& key) : LLFloater(key), mNumResultsReturned(0), - mNearMeListComplete(FALSE), - mCloseOnSelect(FALSE), - mExcludeAgentFromSearchResults(FALSE), + mNearMeListComplete(false), + mCloseOnSelect(false), + mExcludeAgentFromSearchResults(false), mContextConeOpacity (0.f), mContextConeInAlpha(0.f), mContextConeOutAlpha(0.f), @@ -158,7 +158,7 @@ bool LLFloaterAvatarPicker::postBuild() getChild("ResidentChooserTabs")->setCommitCallback( boost::bind(&LLFloaterAvatarPicker::onTabChanged, this)); - setAllowMultiple(FALSE); + setAllowMultiple(false); center(); @@ -252,12 +252,12 @@ void LLFloaterAvatarPicker::onBtnSelect() mSelectionCallback(avatar_ids, avatar_names); } } - getChild("SearchResults")->deselectAllItems(TRUE); - getChild("NearMe")->deselectAllItems(TRUE); - getChild("Friends")->deselectAllItems(TRUE); + getChild("SearchResults")->deselectAllItems(true); + getChild("NearMe")->deselectAllItems(true); + getChild("Friends")->deselectAllItems(true); if(mCloseOnSelect) { - mCloseOnSelect = FALSE; + mCloseOnSelect = false; closeFloater(); } } @@ -266,7 +266,7 @@ void LLFloaterAvatarPicker::onBtnRefresh() { getChild("NearMe")->deleteAllItems(); getChild("NearMe")->setCommentText(getString("searching")); - mNearMeListComplete = FALSE; + mNearMeListComplete = false; } void LLFloaterAvatarPicker::onBtnClose() @@ -286,8 +286,8 @@ void LLFloaterAvatarPicker::onList() void LLFloaterAvatarPicker::populateNearMe() { - BOOL all_loaded = TRUE; - BOOL empty = TRUE; + bool all_loaded = true; + bool empty = true; LLScrollListCtrl* near_me_scroller = getChild("NearMe"); near_me_scroller->deleteAllItems(); @@ -305,7 +305,7 @@ void LLFloaterAvatarPicker::populateNearMe() { element["columns"][0]["column"] = "name"; element["columns"][0]["value"] = LLCacheName::getDefaultName(); - all_loaded = FALSE; + all_loaded = false; } else { @@ -317,27 +317,27 @@ void LLFloaterAvatarPicker::populateNearMe() sAvatarNameMap[av] = av_name; } near_me_scroller->addElement(element); - empty = FALSE; + empty = false; } if (empty) { - getChildView("NearMe")->setEnabled(FALSE); - getChildView("ok_btn")->setEnabled(FALSE); + getChildView("NearMe")->setEnabled(false); + getChildView("ok_btn")->setEnabled(false); near_me_scroller->setCommentText(getString("no_one_near")); } else { - getChildView("NearMe")->setEnabled(TRUE); - getChildView("ok_btn")->setEnabled(TRUE); + getChildView("NearMe")->setEnabled(true); + getChildView("ok_btn")->setEnabled(true); near_me_scroller->selectFirstItem(); onList(); - near_me_scroller->setFocus(TRUE); + near_me_scroller->setFocus(true); } if (all_loaded) { - mNearMeListComplete = TRUE; + mNearMeListComplete = true; } } @@ -357,7 +357,7 @@ void LLFloaterAvatarPicker::populateFriend() { friends_scroller->addStringUUIDItem(it->second, it->first); } - friends_scroller->sortByColumnIndex(0, TRUE); + friends_scroller->sortByColumnIndex(0, true); } void LLFloaterAvatarPicker::drawFrustum() @@ -389,7 +389,7 @@ void LLFloaterAvatarPicker::draw() } } -BOOL LLFloaterAvatarPicker::visibleItemsSelected() const +bool LLFloaterAvatarPicker::visibleItemsSelected() const { LLPanel* active_panel = getChild("ResidentChooserTabs")->getCurrentPanel(); @@ -405,7 +405,7 @@ BOOL LLFloaterAvatarPicker::visibleItemsSelected() const { return getChild("Friends")->getFirstSelectedIndex() >= 0; } - return FALSE; + return false; } /*static*/ @@ -505,11 +505,11 @@ void LLFloaterAvatarPicker::find() getChild("SearchResults")->deleteAllItems(); getChild("SearchResults")->setCommentText(getString("searching")); - getChildView("ok_btn")->setEnabled(FALSE); + getChildView("ok_btn")->setEnabled(false); mNumResultsReturned = 0; } -void LLFloaterAvatarPicker::setAllowMultiple(BOOL allow_multiple) +void LLFloaterAvatarPicker::setAllowMultiple(bool allow_multiple) { getChild("SearchResults")->setAllowMultipleSelection(allow_multiple); getChild("NearMe")->setAllowMultipleSelection(allow_multiple); @@ -622,7 +622,7 @@ void LLFloaterAvatarPicker::processAvatarPickerReply(LLMessageSystem* msg, void* search_results->deleteAllItems(); } - BOOL found_one = FALSE; + bool found_one = false; S32 num_new_rows = msg->getNumberOfBlocks("Data"); for (S32 i = 0; i < num_new_rows; i++) { @@ -638,14 +638,14 @@ void LLFloaterAvatarPicker::processAvatarPickerReply(LLMessageSystem* msg, void* LLStringUtil::format_map_t map; map["[TEXT]"] = floater->getChild("Edit")->getValue().asString(); avatar_name = floater->getString("not_found", map); - search_results->setEnabled(FALSE); - floater->getChildView("ok_btn")->setEnabled(FALSE); + search_results->setEnabled(false); + floater->getChildView("ok_btn")->setEnabled(false); } else { avatar_name = LLCacheName::buildFullName(first_name, last_name); - search_results->setEnabled(TRUE); - found_one = TRUE; + search_results->setEnabled(true); + found_one = true; LLAvatarName av_name; av_name.fromString(avatar_name); @@ -663,10 +663,10 @@ void LLFloaterAvatarPicker::processAvatarPickerReply(LLMessageSystem* msg, void* if (found_one) { - floater->getChildView("ok_btn")->setEnabled(TRUE); + floater->getChildView("ok_btn")->setEnabled(true); search_results->selectFirstItem(); floater->onList(); - search_results->setFocus(TRUE); + search_results->setFocus(true); } } @@ -728,14 +728,14 @@ void LLFloaterAvatarPicker::processResponse(const LLUUID& query_id, const LLSD& { getChildView("ok_btn")->setEnabled(true); search_results->setEnabled(true); - search_results->sortByColumnIndex(1, TRUE); + search_results->sortByColumnIndex(1, true); std::string text = getChild("Edit")->getValue().asString(); - if (!search_results->selectItemByLabel(text, TRUE, 1)) + if (!search_results->selectItemByLabel(text, true, 1)) { search_results->selectFirstItem(); } onList(); - search_results->setFocus(TRUE); + search_results->setFocus(true); } } } -- cgit v1.2.3 From e2e37cced861b98de8c1a7c9c0d3a50d2d90e433 Mon Sep 17 00:00:00 2001 From: Ansariel Date: Wed, 22 May 2024 21:25:21 +0200 Subject: Fix line endlings --- indra/newview/llfloateravatarpicker.cpp | 1628 +++++++++++++++---------------- 1 file changed, 814 insertions(+), 814 deletions(-) (limited to 'indra/newview/llfloateravatarpicker.cpp') diff --git a/indra/newview/llfloateravatarpicker.cpp b/indra/newview/llfloateravatarpicker.cpp index 22dc17e217..6087e6c0ee 100644 --- a/indra/newview/llfloateravatarpicker.cpp +++ b/indra/newview/llfloateravatarpicker.cpp @@ -1,814 +1,814 @@ -/** - * @file llfloateravatarpicker.cpp - * - * $LicenseInfo:firstyear=2003&license=viewerlgpl$ - * Second Life Viewer Source Code - * Copyright (C) 2010, Linden Research, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; - * version 2.1 of the License only. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - * - * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA - * $/LicenseInfo$ - */ - -#include "llviewerprecompiledheaders.h" - -#include "llfloateravatarpicker.h" - -// Viewer includes -#include "llagent.h" -#include "llcallingcard.h" -#include "llfocusmgr.h" -#include "llfloaterreg.h" -#include "llimview.h" // for gIMMgr -#include "lltooldraganddrop.h" // for LLToolDragAndDrop -#include "llviewercontrol.h" -#include "llviewerregion.h" // getCapability() -#include "llworld.h" - -// Linden libraries -#include "llavatarnamecache.h" // IDEVO -#include "llbutton.h" -#include "llcachename.h" -#include "lllineeditor.h" -#include "llscrolllistctrl.h" -#include "llscrolllistitem.h" -#include "llscrolllistcell.h" -#include "lltabcontainer.h" -#include "lluictrlfactory.h" -#include "llfocusmgr.h" -#include "lldraghandle.h" -#include "message.h" -#include "llcorehttputil.h" - -//#include "llsdserialize.h" - -static const U32 AVATAR_PICKER_SEARCH_TIMEOUT = 180U; - -//put it back as a member once the legacy path is out? -static std::map sAvatarNameMap; - -LLFloaterAvatarPicker* LLFloaterAvatarPicker::show(select_callback_t callback, - bool allow_multiple, - bool closeOnSelect, - bool skip_agent, - const std::string& name, - LLView * frustumOrigin) -{ - // *TODO: Use a key to allow this not to be an effective singleton - LLFloaterAvatarPicker* floater = - LLFloaterReg::showTypedInstance("avatar_picker", LLSD(name)); - if (!floater) - { - LL_WARNS() << "Cannot instantiate avatar picker" << LL_ENDL; - return NULL; - } - - floater->mSelectionCallback = callback; - floater->setAllowMultiple(allow_multiple); - floater->mNearMeListComplete = false; - floater->mCloseOnSelect = closeOnSelect; - floater->mExcludeAgentFromSearchResults = skip_agent; - - if (!closeOnSelect) - { - // Use Select/Close - std::string select_string = floater->getString("Select"); - std::string close_string = floater->getString("Close"); - floater->getChild("ok_btn")->setLabel(select_string); - floater->getChild("cancel_btn")->setLabel(close_string); - } - - if(frustumOrigin) - { - floater->mFrustumOrigin = frustumOrigin->getHandle(); - } - - return floater; -} - -// Default constructor -LLFloaterAvatarPicker::LLFloaterAvatarPicker(const LLSD& key) - : LLFloater(key), - mNumResultsReturned(0), - mNearMeListComplete(false), - mCloseOnSelect(false), - mExcludeAgentFromSearchResults(false), - mContextConeOpacity (0.f), - mContextConeInAlpha(CONTEXT_CONE_IN_ALPHA), - mContextConeOutAlpha(CONTEXT_CONE_OUT_ALPHA), - mContextConeFadeTime(CONTEXT_CONE_FADE_TIME) -{ - mCommitCallbackRegistrar.add("Refresh.FriendList", boost::bind(&LLFloaterAvatarPicker::populateFriend, this)); -} - -bool LLFloaterAvatarPicker::postBuild() -{ - getChild("Edit")->setKeystrokeCallback( boost::bind(&LLFloaterAvatarPicker::editKeystroke, this, _1, _2),NULL); - - childSetAction("Find", boost::bind(&LLFloaterAvatarPicker::onBtnFind, this)); - getChildView("Find")->setEnabled(false); - childSetAction("Refresh", boost::bind(&LLFloaterAvatarPicker::onBtnRefresh, this)); - getChild("near_me_range")->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onRangeAdjust, this)); - - LLScrollListCtrl* searchresults = getChild("SearchResults"); - searchresults->setDoubleClickCallback( boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); - searchresults->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onList, this)); - getChildView("SearchResults")->setEnabled(false); - - LLScrollListCtrl* nearme = getChild("NearMe"); - nearme->setDoubleClickCallback(boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); - nearme->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onList, this)); - - LLScrollListCtrl* friends = getChild("Friends"); - friends->setDoubleClickCallback(boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); - getChild("Friends")->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onList, this)); - - childSetAction("ok_btn", boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); - getChildView("ok_btn")->setEnabled(false); - childSetAction("cancel_btn", boost::bind(&LLFloaterAvatarPicker::onBtnClose, this)); - - getChild("Edit")->setFocus(true); - - LLPanel* search_panel = getChild("SearchPanel"); - if (search_panel) - { - // Start searching when Return is pressed in the line editor. - search_panel->setDefaultBtn("Find"); - } - - getChild("SearchResults")->setCommentText(getString("no_results")); - - getChild("ResidentChooserTabs")->setCommitCallback( - boost::bind(&LLFloaterAvatarPicker::onTabChanged, this)); - - setAllowMultiple(false); - - center(); - - populateFriend(); - - return true; -} - -void LLFloaterAvatarPicker::setOkBtnEnableCb(validate_callback_t cb) -{ - mOkButtonValidateSignal.connect(cb); -} - -void LLFloaterAvatarPicker::onTabChanged() -{ - getChildView("ok_btn")->setEnabled(isSelectBtnEnabled()); -} - -// Destroys the object -LLFloaterAvatarPicker::~LLFloaterAvatarPicker() -{ - gFocusMgr.releaseFocusIfNeeded( this ); -} - -void LLFloaterAvatarPicker::onBtnFind() -{ - find(); -} - -static void getSelectedAvatarData(const LLScrollListCtrl* from, uuid_vec_t& avatar_ids, std::vector& avatar_names) -{ - std::vector items = from->getAllSelected(); - for (std::vector::iterator iter = items.begin(); iter != items.end(); ++iter) - { - LLScrollListItem* item = *iter; - if (item->getUUID().notNull()) - { - avatar_ids.push_back(item->getUUID()); - - std::map::iterator iter = sAvatarNameMap.find(item->getUUID()); - if (iter != sAvatarNameMap.end()) - { - avatar_names.push_back(iter->second); - } - else - { - // the only case where it isn't in the name map is friends - // but it should be in the name cache - LLAvatarName av_name; - LLAvatarNameCache::get(item->getUUID(), &av_name); - avatar_names.push_back(av_name); - } - } - } -} - -void LLFloaterAvatarPicker::onBtnSelect() -{ - - // If select btn not enabled then do not callback - if (!isSelectBtnEnabled()) - return; - - if(mSelectionCallback) - { - std::string acvtive_panel_name; - LLScrollListCtrl* list = NULL; - LLPanel* active_panel = getChild("ResidentChooserTabs")->getCurrentPanel(); - if(active_panel) - { - acvtive_panel_name = active_panel->getName(); - } - if(acvtive_panel_name == "SearchPanel") - { - list = getChild("SearchResults"); - } - else if(acvtive_panel_name == "NearMePanel") - { - list = getChild("NearMe"); - } - else if (acvtive_panel_name == "FriendsPanel") - { - list = getChild("Friends"); - } - - if(list) - { - uuid_vec_t avatar_ids; - std::vector avatar_names; - getSelectedAvatarData(list, avatar_ids, avatar_names); - mSelectionCallback(avatar_ids, avatar_names); - } - } - getChild("SearchResults")->deselectAllItems(true); - getChild("NearMe")->deselectAllItems(true); - getChild("Friends")->deselectAllItems(true); - if(mCloseOnSelect) - { - mCloseOnSelect = false; - closeFloater(); - } -} - -void LLFloaterAvatarPicker::onBtnRefresh() -{ - getChild("NearMe")->deleteAllItems(); - getChild("NearMe")->setCommentText(getString("searching")); - mNearMeListComplete = false; -} - -void LLFloaterAvatarPicker::onBtnClose() -{ - closeFloater(); -} - -void LLFloaterAvatarPicker::onRangeAdjust() -{ - onBtnRefresh(); -} - -void LLFloaterAvatarPicker::onList() -{ - getChildView("ok_btn")->setEnabled(isSelectBtnEnabled()); -} - -void LLFloaterAvatarPicker::populateNearMe() -{ - bool all_loaded = true; - bool empty = true; - LLScrollListCtrl* near_me_scroller = getChild("NearMe"); - near_me_scroller->deleteAllItems(); - - uuid_vec_t avatar_ids; - LLWorld::getInstance()->getAvatars(&avatar_ids, NULL, gAgent.getPositionGlobal(), gSavedSettings.getF32("NearMeRange")); - for(U32 i=0; iaddElement(element); - empty = false; - } - - if (empty) - { - getChildView("NearMe")->setEnabled(false); - getChildView("ok_btn")->setEnabled(false); - near_me_scroller->setCommentText(getString("no_one_near")); - } - else - { - getChildView("NearMe")->setEnabled(true); - getChildView("ok_btn")->setEnabled(true); - near_me_scroller->selectFirstItem(); - onList(); - near_me_scroller->setFocus(true); - } - - if (all_loaded) - { - mNearMeListComplete = true; - } -} - -void LLFloaterAvatarPicker::populateFriend() -{ - LLScrollListCtrl* friends_scroller = getChild("Friends"); - friends_scroller->deleteAllItems(); - LLCollectAllBuddies collector; - LLAvatarTracker::instance().applyFunctor(collector); - LLCollectAllBuddies::buddy_map_t::iterator it; - - for(it = collector.mOnline.begin(); it!=collector.mOnline.end(); it++) - { - friends_scroller->addStringUUIDItem(it->second, it->first); - } - for(it = collector.mOffline.begin(); it!=collector.mOffline.end(); it++) - { - friends_scroller->addStringUUIDItem(it->second, it->first); - } - friends_scroller->sortByColumnIndex(0, true); -} - -void LLFloaterAvatarPicker::drawFrustum() -{ - static LLCachedControl max_opacity(gSavedSettings, "PickerContextOpacity", 0.4f); - drawConeToOwner(mContextConeOpacity, max_opacity, mFrustumOrigin.get(), mContextConeFadeTime, mContextConeInAlpha, mContextConeOutAlpha); -} - -void LLFloaterAvatarPicker::draw() -{ - drawFrustum(); - - // sometimes it is hard to determine when Select/Ok button should be disabled (see LLAvatarActions::shareWithAvatars). - // lets check this via mOkButtonValidateSignal callback periodically. - static LLFrameTimer timer; - if (timer.hasExpired()) - { - timer.setTimerExpirySec(0.33f); // three times per second should be enough. - - // simulate list changes. - onList(); - timer.start(); - } - - LLFloater::draw(); - if (!mNearMeListComplete && getChild("ResidentChooserTabs")->getCurrentPanel() == getChild("NearMePanel")) - { - populateNearMe(); - } -} - -bool LLFloaterAvatarPicker::visibleItemsSelected() const -{ - LLPanel* active_panel = getChild("ResidentChooserTabs")->getCurrentPanel(); - - if(active_panel == getChild("SearchPanel")) - { - return getChild("SearchResults")->getFirstSelectedIndex() >= 0; - } - else if(active_panel == getChild("NearMePanel")) - { - return getChild("NearMe")->getFirstSelectedIndex() >= 0; - } - else if(active_panel == getChild("FriendsPanel")) - { - return getChild("Friends")->getFirstSelectedIndex() >= 0; - } - return false; -} - -/*static*/ -void LLFloaterAvatarPicker::findCoro(std::string url, LLUUID queryID, std::string name) -{ - LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID); - LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t - httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("genericPostCoro", httpPolicy)); - LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest); - LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions); - - LL_INFOS("HttpCoroutineAdapter", "genericPostCoro") << "Generic POST for " << url << LL_ENDL; - - httpOpts->setTimeout(AVATAR_PICKER_SEARCH_TIMEOUT); - - LLSD result = httpAdapter->getAndSuspend(httpRequest, url, httpOpts); - - LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; - LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); - - if (status || (status == LLCore::HttpStatus(HTTP_BAD_REQUEST))) - { - result.erase(LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS); - } - else - { - result["failure_reason"] = status.toString(); - } - - LLFloaterAvatarPicker* floater = - LLFloaterReg::findTypedInstance("avatar_picker", name); - if (floater) - { - floater->processResponse(queryID, result); - } -} - - -void LLFloaterAvatarPicker::find() -{ - //clear our stored LLAvatarNames - sAvatarNameMap.clear(); - - std::string text = getChild("Edit")->getValue().asString(); - - size_t separator_index = text.find_first_of(" ._"); - if (separator_index != text.npos) - { - std::string first = text.substr(0, separator_index); - std::string last = text.substr(separator_index+1, text.npos); - LLStringUtil::trim(last); - if("Resident" == last) - { - text = first; - } - } - - mQueryID.generate(); - - std::string url; - url.reserve(128); // avoid a memory allocation or two - - LLViewerRegion* region = gAgent.getRegion(); - if(region) - { - url = region->getCapability("AvatarPickerSearch"); - // Prefer use of capabilities to search on both SLID and display name - if (!url.empty()) - { - // capability urls don't end in '/', but we need one to parse - // query parameters correctly - if (url.size() > 0 && url[url.size()-1] != '/') - { - url += "/"; - } - url += "?page_size=100&names="; - std::replace(text.begin(), text.end(), '.', ' '); - url += LLURI::escape(text); - LL_INFOS() << "avatar picker " << url << LL_ENDL; - - LLCoros::instance().launch("LLFloaterAvatarPicker::findCoro", - boost::bind(&LLFloaterAvatarPicker::findCoro, url, mQueryID, getKey().asString())); - } - else - { - LLMessageSystem* msg = gMessageSystem; - msg->newMessage("AvatarPickerRequest"); - msg->nextBlock("AgentData"); - msg->addUUID("AgentID", gAgent.getID()); - msg->addUUID("SessionID", gAgent.getSessionID()); - msg->addUUID("QueryID", mQueryID); // not used right now - msg->nextBlock("Data"); - msg->addString("Name", text); - gAgent.sendReliableMessage(); - } - } - getChild("SearchResults")->deleteAllItems(); - getChild("SearchResults")->setCommentText(getString("searching")); - - getChildView("ok_btn")->setEnabled(false); - mNumResultsReturned = 0; -} - -void LLFloaterAvatarPicker::setAllowMultiple(bool allow_multiple) -{ - getChild("SearchResults")->setAllowMultipleSelection(allow_multiple); - getChild("NearMe")->setAllowMultipleSelection(allow_multiple); - getChild("Friends")->setAllowMultipleSelection(allow_multiple); -} - -LLScrollListCtrl* LLFloaterAvatarPicker::getActiveList() -{ - std::string acvtive_panel_name; - LLScrollListCtrl* list = NULL; - LLPanel* active_panel = getChild("ResidentChooserTabs")->getCurrentPanel(); - if(active_panel) - { - acvtive_panel_name = active_panel->getName(); - } - if(acvtive_panel_name == "SearchPanel") - { - list = getChild("SearchResults"); - } - else if(acvtive_panel_name == "NearMePanel") - { - list = getChild("NearMe"); - } - else if (acvtive_panel_name == "FriendsPanel") - { - list = getChild("Friends"); - } - return list; -} - -bool LLFloaterAvatarPicker::handleDragAndDrop(S32 x, S32 y, MASK mask, - bool drop, EDragAndDropType cargo_type, - void *cargo_data, EAcceptance *accept, - std::string& tooltip_msg) -{ - LLScrollListCtrl* list = getActiveList(); - if(list) - { - LLRect rc_list; - LLRect rc_point(x,y,x,y); - if (localRectToOtherView(rc_point, &rc_list, list)) - { - // Keep selected only one item - list->deselectAllItems(true); - list->selectItemAt(rc_list.mLeft, rc_list.mBottom, mask); - LLScrollListItem* selection = list->getFirstSelected(); - if (selection) - { - LLUUID session_id = LLUUID::null; - LLUUID dest_agent_id = selection->getUUID(); - std::string avatar_name = selection->getColumn(0)->getValue().asString(); - if (dest_agent_id.notNull() && dest_agent_id != gAgentID) - { - if (drop) - { - // Start up IM before give the item - session_id = gIMMgr->addSession(avatar_name, IM_NOTHING_SPECIAL, dest_agent_id); - } - return LLToolDragAndDrop::handleGiveDragAndDrop(dest_agent_id, session_id, drop, - cargo_type, cargo_data, accept, getName()); - } - } - } - } - *accept = ACCEPT_NO; - return true; -} - - -void LLFloaterAvatarPicker::openFriendsTab() -{ - LLTabContainer* tab_container = getChild("ResidentChooserTabs"); - if (tab_container == NULL) - { - llassert(tab_container != NULL); - return; - } - - tab_container->selectTabByName("FriendsPanel"); -} - -// static -void LLFloaterAvatarPicker::processAvatarPickerReply(LLMessageSystem* msg, void**) -{ - LLUUID agent_id; - LLUUID query_id; - LLUUID avatar_id; - std::string first_name; - std::string last_name; - - msg->getUUID("AgentData", "AgentID", agent_id); - msg->getUUID("AgentData", "QueryID", query_id); - - // Not for us - if (agent_id != gAgent.getID()) return; - - LLFloaterAvatarPicker* floater = LLFloaterReg::findTypedInstance("avatar_picker"); - - // floater is closed or these are not results from our last request - if (NULL == floater || query_id != floater->mQueryID) - { - return; - } - - LLScrollListCtrl* search_results = floater->getChild("SearchResults"); - - // clear "Searching" label on first results - if (floater->mNumResultsReturned++ == 0) - { - search_results->deleteAllItems(); - } - - bool found_one = false; - S32 num_new_rows = msg->getNumberOfBlocks("Data"); - for (S32 i = 0; i < num_new_rows; i++) - { - msg->getUUIDFast( _PREHASH_Data,_PREHASH_AvatarID, avatar_id, i); - msg->getStringFast(_PREHASH_Data,_PREHASH_FirstName, first_name, i); - msg->getStringFast(_PREHASH_Data,_PREHASH_LastName, last_name, i); - - if (avatar_id != agent_id || !floater->isExcludeAgentFromSearchResults()) // exclude agent from search results? - { - std::string avatar_name; - if (avatar_id.isNull()) - { - LLStringUtil::format_map_t map; - map["[TEXT]"] = floater->getChild("Edit")->getValue().asString(); - avatar_name = floater->getString("not_found", map); - search_results->setEnabled(false); - floater->getChildView("ok_btn")->setEnabled(false); - } - else - { - avatar_name = LLCacheName::buildFullName(first_name, last_name); - search_results->setEnabled(true); - found_one = true; - - LLAvatarName av_name; - av_name.fromString(avatar_name); - const LLUUID& agent_id = avatar_id; - sAvatarNameMap[agent_id] = av_name; - - } - LLSD element; - element["id"] = avatar_id; // value - element["columns"][0]["column"] = "name"; - element["columns"][0]["value"] = avatar_name; - search_results->addElement(element); - } - } - - if (found_one) - { - floater->getChildView("ok_btn")->setEnabled(true); - search_results->selectFirstItem(); - floater->onList(); - search_results->setFocus(true); - } -} - -void LLFloaterAvatarPicker::processResponse(const LLUUID& query_id, const LLSD& content) -{ - // Check for out-of-date query - if (query_id == mQueryID) - { - LLScrollListCtrl* search_results = getChild("SearchResults"); - - // clear "Searching" label on first results - search_results->deleteAllItems(); - - if (content.has("failure_reason")) - { - getChild("SearchResults")->setCommentText(content["failure_reason"].asString()); - getChildView("ok_btn")->setEnabled(false); - } - else - { - LLSD agents = content["agents"]; - - LLSD item; - LLSD::array_const_iterator it = agents.beginArray(); - for (; it != agents.endArray(); ++it) - { - const LLSD& row = *it; - if (row["id"].asUUID() != gAgent.getID() || !mExcludeAgentFromSearchResults) - { - item["id"] = row["id"]; - LLSD& columns = item["columns"]; - columns[0]["column"] = "name"; - columns[0]["value"] = row["display_name"]; - columns[1]["column"] = "username"; - columns[1]["value"] = row["username"]; - search_results->addElement(item); - - // add the avatar name to our list - LLAvatarName avatar_name; - avatar_name.fromLLSD(row); - sAvatarNameMap[row["id"].asUUID()] = avatar_name; - } - } - - if (search_results->isEmpty()) - { - std::string name = "'" + getChild("Edit")->getValue().asString() + "'"; - LLSD item; - item["id"] = LLUUID::null; - item["columns"][0]["column"] = "name"; - item["columns"][0]["value"] = name; - item["columns"][1]["column"] = "username"; - item["columns"][1]["value"] = getString("not_found_text"); - search_results->addElement(item); - search_results->setEnabled(false); - getChildView("ok_btn")->setEnabled(false); - } - else - { - getChildView("ok_btn")->setEnabled(true); - search_results->setEnabled(true); - search_results->sortByColumnIndex(1, true); - std::string text = getChild("Edit")->getValue().asString(); - if (!search_results->selectItemByLabel(text, true, 1)) - { - search_results->selectFirstItem(); - } - onList(); - search_results->setFocus(true); - } - } - } -} - -void LLFloaterAvatarPicker::editKeystroke(LLLineEditor* caller, void* user_data) -{ - getChildView("Find")->setEnabled(caller->getText().size() > 0); -} - -// virtual -bool LLFloaterAvatarPicker::handleKeyHere(KEY key, MASK mask) -{ - if (key == KEY_RETURN && mask == MASK_NONE) - { - if (getChild("Edit")->hasFocus()) - { - onBtnFind(); - } - else - { - onBtnSelect(); - } - return true; - } - else if (key == KEY_ESCAPE && mask == MASK_NONE) - { - closeFloater(); - return true; - } - - return LLFloater::handleKeyHere(key, mask); -} - -bool LLFloaterAvatarPicker::isSelectBtnEnabled() -{ - bool ret_val = visibleItemsSelected(); - - if ( ret_val && !isMinimized()) - { - std::string acvtive_panel_name; - LLScrollListCtrl* list = NULL; - LLPanel* active_panel = getChild("ResidentChooserTabs")->getCurrentPanel(); - - if(active_panel) - { - acvtive_panel_name = active_panel->getName(); - } - - if(acvtive_panel_name == "SearchPanel") - { - list = getChild("SearchResults"); - } - else if(acvtive_panel_name == "NearMePanel") - { - list = getChild("NearMe"); - } - else if (acvtive_panel_name == "FriendsPanel") - { - list = getChild("Friends"); - } - - if(list) - { - uuid_vec_t avatar_ids; - std::vector avatar_names; - getSelectedAvatarData(list, avatar_ids, avatar_names); - if (avatar_ids.size() >= 1) - { - ret_val = mOkButtonValidateSignal.num_slots()?mOkButtonValidateSignal(avatar_ids):true; - } - else - { - ret_val = false; - } - } - } - - return ret_val; -} +/** + * @file llfloateravatarpicker.cpp + * + * $LicenseInfo:firstyear=2003&license=viewerlgpl$ + * Second Life Viewer Source Code + * Copyright (C) 2010, Linden Research, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA + * $/LicenseInfo$ + */ + +#include "llviewerprecompiledheaders.h" + +#include "llfloateravatarpicker.h" + +// Viewer includes +#include "llagent.h" +#include "llcallingcard.h" +#include "llfocusmgr.h" +#include "llfloaterreg.h" +#include "llimview.h" // for gIMMgr +#include "lltooldraganddrop.h" // for LLToolDragAndDrop +#include "llviewercontrol.h" +#include "llviewerregion.h" // getCapability() +#include "llworld.h" + +// Linden libraries +#include "llavatarnamecache.h" // IDEVO +#include "llbutton.h" +#include "llcachename.h" +#include "lllineeditor.h" +#include "llscrolllistctrl.h" +#include "llscrolllistitem.h" +#include "llscrolllistcell.h" +#include "lltabcontainer.h" +#include "lluictrlfactory.h" +#include "llfocusmgr.h" +#include "lldraghandle.h" +#include "message.h" +#include "llcorehttputil.h" + +//#include "llsdserialize.h" + +static const U32 AVATAR_PICKER_SEARCH_TIMEOUT = 180U; + +//put it back as a member once the legacy path is out? +static std::map sAvatarNameMap; + +LLFloaterAvatarPicker* LLFloaterAvatarPicker::show(select_callback_t callback, + bool allow_multiple, + bool closeOnSelect, + bool skip_agent, + const std::string& name, + LLView * frustumOrigin) +{ + // *TODO: Use a key to allow this not to be an effective singleton + LLFloaterAvatarPicker* floater = + LLFloaterReg::showTypedInstance("avatar_picker", LLSD(name)); + if (!floater) + { + LL_WARNS() << "Cannot instantiate avatar picker" << LL_ENDL; + return NULL; + } + + floater->mSelectionCallback = callback; + floater->setAllowMultiple(allow_multiple); + floater->mNearMeListComplete = false; + floater->mCloseOnSelect = closeOnSelect; + floater->mExcludeAgentFromSearchResults = skip_agent; + + if (!closeOnSelect) + { + // Use Select/Close + std::string select_string = floater->getString("Select"); + std::string close_string = floater->getString("Close"); + floater->getChild("ok_btn")->setLabel(select_string); + floater->getChild("cancel_btn")->setLabel(close_string); + } + + if(frustumOrigin) + { + floater->mFrustumOrigin = frustumOrigin->getHandle(); + } + + return floater; +} + +// Default constructor +LLFloaterAvatarPicker::LLFloaterAvatarPicker(const LLSD& key) + : LLFloater(key), + mNumResultsReturned(0), + mNearMeListComplete(false), + mCloseOnSelect(false), + mExcludeAgentFromSearchResults(false), + mContextConeOpacity (0.f), + mContextConeInAlpha(CONTEXT_CONE_IN_ALPHA), + mContextConeOutAlpha(CONTEXT_CONE_OUT_ALPHA), + mContextConeFadeTime(CONTEXT_CONE_FADE_TIME) +{ + mCommitCallbackRegistrar.add("Refresh.FriendList", boost::bind(&LLFloaterAvatarPicker::populateFriend, this)); +} + +bool LLFloaterAvatarPicker::postBuild() +{ + getChild("Edit")->setKeystrokeCallback( boost::bind(&LLFloaterAvatarPicker::editKeystroke, this, _1, _2),NULL); + + childSetAction("Find", boost::bind(&LLFloaterAvatarPicker::onBtnFind, this)); + getChildView("Find")->setEnabled(false); + childSetAction("Refresh", boost::bind(&LLFloaterAvatarPicker::onBtnRefresh, this)); + getChild("near_me_range")->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onRangeAdjust, this)); + + LLScrollListCtrl* searchresults = getChild("SearchResults"); + searchresults->setDoubleClickCallback( boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); + searchresults->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onList, this)); + getChildView("SearchResults")->setEnabled(false); + + LLScrollListCtrl* nearme = getChild("NearMe"); + nearme->setDoubleClickCallback(boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); + nearme->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onList, this)); + + LLScrollListCtrl* friends = getChild("Friends"); + friends->setDoubleClickCallback(boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); + getChild("Friends")->setCommitCallback(boost::bind(&LLFloaterAvatarPicker::onList, this)); + + childSetAction("ok_btn", boost::bind(&LLFloaterAvatarPicker::onBtnSelect, this)); + getChildView("ok_btn")->setEnabled(false); + childSetAction("cancel_btn", boost::bind(&LLFloaterAvatarPicker::onBtnClose, this)); + + getChild("Edit")->setFocus(true); + + LLPanel* search_panel = getChild("SearchPanel"); + if (search_panel) + { + // Start searching when Return is pressed in the line editor. + search_panel->setDefaultBtn("Find"); + } + + getChild("SearchResults")->setCommentText(getString("no_results")); + + getChild("ResidentChooserTabs")->setCommitCallback( + boost::bind(&LLFloaterAvatarPicker::onTabChanged, this)); + + setAllowMultiple(false); + + center(); + + populateFriend(); + + return true; +} + +void LLFloaterAvatarPicker::setOkBtnEnableCb(validate_callback_t cb) +{ + mOkButtonValidateSignal.connect(cb); +} + +void LLFloaterAvatarPicker::onTabChanged() +{ + getChildView("ok_btn")->setEnabled(isSelectBtnEnabled()); +} + +// Destroys the object +LLFloaterAvatarPicker::~LLFloaterAvatarPicker() +{ + gFocusMgr.releaseFocusIfNeeded( this ); +} + +void LLFloaterAvatarPicker::onBtnFind() +{ + find(); +} + +static void getSelectedAvatarData(const LLScrollListCtrl* from, uuid_vec_t& avatar_ids, std::vector& avatar_names) +{ + std::vector items = from->getAllSelected(); + for (std::vector::iterator iter = items.begin(); iter != items.end(); ++iter) + { + LLScrollListItem* item = *iter; + if (item->getUUID().notNull()) + { + avatar_ids.push_back(item->getUUID()); + + std::map::iterator iter = sAvatarNameMap.find(item->getUUID()); + if (iter != sAvatarNameMap.end()) + { + avatar_names.push_back(iter->second); + } + else + { + // the only case where it isn't in the name map is friends + // but it should be in the name cache + LLAvatarName av_name; + LLAvatarNameCache::get(item->getUUID(), &av_name); + avatar_names.push_back(av_name); + } + } + } +} + +void LLFloaterAvatarPicker::onBtnSelect() +{ + + // If select btn not enabled then do not callback + if (!isSelectBtnEnabled()) + return; + + if(mSelectionCallback) + { + std::string acvtive_panel_name; + LLScrollListCtrl* list = NULL; + LLPanel* active_panel = getChild("ResidentChooserTabs")->getCurrentPanel(); + if(active_panel) + { + acvtive_panel_name = active_panel->getName(); + } + if(acvtive_panel_name == "SearchPanel") + { + list = getChild("SearchResults"); + } + else if(acvtive_panel_name == "NearMePanel") + { + list = getChild("NearMe"); + } + else if (acvtive_panel_name == "FriendsPanel") + { + list = getChild("Friends"); + } + + if(list) + { + uuid_vec_t avatar_ids; + std::vector avatar_names; + getSelectedAvatarData(list, avatar_ids, avatar_names); + mSelectionCallback(avatar_ids, avatar_names); + } + } + getChild("SearchResults")->deselectAllItems(true); + getChild("NearMe")->deselectAllItems(true); + getChild("Friends")->deselectAllItems(true); + if(mCloseOnSelect) + { + mCloseOnSelect = false; + closeFloater(); + } +} + +void LLFloaterAvatarPicker::onBtnRefresh() +{ + getChild("NearMe")->deleteAllItems(); + getChild("NearMe")->setCommentText(getString("searching")); + mNearMeListComplete = false; +} + +void LLFloaterAvatarPicker::onBtnClose() +{ + closeFloater(); +} + +void LLFloaterAvatarPicker::onRangeAdjust() +{ + onBtnRefresh(); +} + +void LLFloaterAvatarPicker::onList() +{ + getChildView("ok_btn")->setEnabled(isSelectBtnEnabled()); +} + +void LLFloaterAvatarPicker::populateNearMe() +{ + bool all_loaded = true; + bool empty = true; + LLScrollListCtrl* near_me_scroller = getChild("NearMe"); + near_me_scroller->deleteAllItems(); + + uuid_vec_t avatar_ids; + LLWorld::getInstance()->getAvatars(&avatar_ids, NULL, gAgent.getPositionGlobal(), gSavedSettings.getF32("NearMeRange")); + for(U32 i=0; iaddElement(element); + empty = false; + } + + if (empty) + { + getChildView("NearMe")->setEnabled(false); + getChildView("ok_btn")->setEnabled(false); + near_me_scroller->setCommentText(getString("no_one_near")); + } + else + { + getChildView("NearMe")->setEnabled(true); + getChildView("ok_btn")->setEnabled(true); + near_me_scroller->selectFirstItem(); + onList(); + near_me_scroller->setFocus(true); + } + + if (all_loaded) + { + mNearMeListComplete = true; + } +} + +void LLFloaterAvatarPicker::populateFriend() +{ + LLScrollListCtrl* friends_scroller = getChild("Friends"); + friends_scroller->deleteAllItems(); + LLCollectAllBuddies collector; + LLAvatarTracker::instance().applyFunctor(collector); + LLCollectAllBuddies::buddy_map_t::iterator it; + + for(it = collector.mOnline.begin(); it!=collector.mOnline.end(); it++) + { + friends_scroller->addStringUUIDItem(it->second, it->first); + } + for(it = collector.mOffline.begin(); it!=collector.mOffline.end(); it++) + { + friends_scroller->addStringUUIDItem(it->second, it->first); + } + friends_scroller->sortByColumnIndex(0, true); +} + +void LLFloaterAvatarPicker::drawFrustum() +{ + static LLCachedControl max_opacity(gSavedSettings, "PickerContextOpacity", 0.4f); + drawConeToOwner(mContextConeOpacity, max_opacity, mFrustumOrigin.get(), mContextConeFadeTime, mContextConeInAlpha, mContextConeOutAlpha); +} + +void LLFloaterAvatarPicker::draw() +{ + drawFrustum(); + + // sometimes it is hard to determine when Select/Ok button should be disabled (see LLAvatarActions::shareWithAvatars). + // lets check this via mOkButtonValidateSignal callback periodically. + static LLFrameTimer timer; + if (timer.hasExpired()) + { + timer.setTimerExpirySec(0.33f); // three times per second should be enough. + + // simulate list changes. + onList(); + timer.start(); + } + + LLFloater::draw(); + if (!mNearMeListComplete && getChild("ResidentChooserTabs")->getCurrentPanel() == getChild("NearMePanel")) + { + populateNearMe(); + } +} + +bool LLFloaterAvatarPicker::visibleItemsSelected() const +{ + LLPanel* active_panel = getChild("ResidentChooserTabs")->getCurrentPanel(); + + if(active_panel == getChild("SearchPanel")) + { + return getChild("SearchResults")->getFirstSelectedIndex() >= 0; + } + else if(active_panel == getChild("NearMePanel")) + { + return getChild("NearMe")->getFirstSelectedIndex() >= 0; + } + else if(active_panel == getChild("FriendsPanel")) + { + return getChild("Friends")->getFirstSelectedIndex() >= 0; + } + return false; +} + +/*static*/ +void LLFloaterAvatarPicker::findCoro(std::string url, LLUUID queryID, std::string name) +{ + LLCore::HttpRequest::policy_t httpPolicy(LLCore::HttpRequest::DEFAULT_POLICY_ID); + LLCoreHttpUtil::HttpCoroutineAdapter::ptr_t + httpAdapter(new LLCoreHttpUtil::HttpCoroutineAdapter("genericPostCoro", httpPolicy)); + LLCore::HttpRequest::ptr_t httpRequest(new LLCore::HttpRequest); + LLCore::HttpOptions::ptr_t httpOpts(new LLCore::HttpOptions); + + LL_INFOS("HttpCoroutineAdapter", "genericPostCoro") << "Generic POST for " << url << LL_ENDL; + + httpOpts->setTimeout(AVATAR_PICKER_SEARCH_TIMEOUT); + + LLSD result = httpAdapter->getAndSuspend(httpRequest, url, httpOpts); + + LLSD httpResults = result[LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS]; + LLCore::HttpStatus status = LLCoreHttpUtil::HttpCoroutineAdapter::getStatusFromLLSD(httpResults); + + if (status || (status == LLCore::HttpStatus(HTTP_BAD_REQUEST))) + { + result.erase(LLCoreHttpUtil::HttpCoroutineAdapter::HTTP_RESULTS); + } + else + { + result["failure_reason"] = status.toString(); + } + + LLFloaterAvatarPicker* floater = + LLFloaterReg::findTypedInstance("avatar_picker", name); + if (floater) + { + floater->processResponse(queryID, result); + } +} + + +void LLFloaterAvatarPicker::find() +{ + //clear our stored LLAvatarNames + sAvatarNameMap.clear(); + + std::string text = getChild("Edit")->getValue().asString(); + + size_t separator_index = text.find_first_of(" ._"); + if (separator_index != text.npos) + { + std::string first = text.substr(0, separator_index); + std::string last = text.substr(separator_index+1, text.npos); + LLStringUtil::trim(last); + if("Resident" == last) + { + text = first; + } + } + + mQueryID.generate(); + + std::string url; + url.reserve(128); // avoid a memory allocation or two + + LLViewerRegion* region = gAgent.getRegion(); + if(region) + { + url = region->getCapability("AvatarPickerSearch"); + // Prefer use of capabilities to search on both SLID and display name + if (!url.empty()) + { + // capability urls don't end in '/', but we need one to parse + // query parameters correctly + if (url.size() > 0 && url[url.size()-1] != '/') + { + url += "/"; + } + url += "?page_size=100&names="; + std::replace(text.begin(), text.end(), '.', ' '); + url += LLURI::escape(text); + LL_INFOS() << "avatar picker " << url << LL_ENDL; + + LLCoros::instance().launch("LLFloaterAvatarPicker::findCoro", + boost::bind(&LLFloaterAvatarPicker::findCoro, url, mQueryID, getKey().asString())); + } + else + { + LLMessageSystem* msg = gMessageSystem; + msg->newMessage("AvatarPickerRequest"); + msg->nextBlock("AgentData"); + msg->addUUID("AgentID", gAgent.getID()); + msg->addUUID("SessionID", gAgent.getSessionID()); + msg->addUUID("QueryID", mQueryID); // not used right now + msg->nextBlock("Data"); + msg->addString("Name", text); + gAgent.sendReliableMessage(); + } + } + getChild("SearchResults")->deleteAllItems(); + getChild("SearchResults")->setCommentText(getString("searching")); + + getChildView("ok_btn")->setEnabled(false); + mNumResultsReturned = 0; +} + +void LLFloaterAvatarPicker::setAllowMultiple(bool allow_multiple) +{ + getChild("SearchResults")->setAllowMultipleSelection(allow_multiple); + getChild("NearMe")->setAllowMultipleSelection(allow_multiple); + getChild("Friends")->setAllowMultipleSelection(allow_multiple); +} + +LLScrollListCtrl* LLFloaterAvatarPicker::getActiveList() +{ + std::string acvtive_panel_name; + LLScrollListCtrl* list = NULL; + LLPanel* active_panel = getChild("ResidentChooserTabs")->getCurrentPanel(); + if(active_panel) + { + acvtive_panel_name = active_panel->getName(); + } + if(acvtive_panel_name == "SearchPanel") + { + list = getChild("SearchResults"); + } + else if(acvtive_panel_name == "NearMePanel") + { + list = getChild("NearMe"); + } + else if (acvtive_panel_name == "FriendsPanel") + { + list = getChild("Friends"); + } + return list; +} + +bool LLFloaterAvatarPicker::handleDragAndDrop(S32 x, S32 y, MASK mask, + bool drop, EDragAndDropType cargo_type, + void *cargo_data, EAcceptance *accept, + std::string& tooltip_msg) +{ + LLScrollListCtrl* list = getActiveList(); + if(list) + { + LLRect rc_list; + LLRect rc_point(x,y,x,y); + if (localRectToOtherView(rc_point, &rc_list, list)) + { + // Keep selected only one item + list->deselectAllItems(true); + list->selectItemAt(rc_list.mLeft, rc_list.mBottom, mask); + LLScrollListItem* selection = list->getFirstSelected(); + if (selection) + { + LLUUID session_id = LLUUID::null; + LLUUID dest_agent_id = selection->getUUID(); + std::string avatar_name = selection->getColumn(0)->getValue().asString(); + if (dest_agent_id.notNull() && dest_agent_id != gAgentID) + { + if (drop) + { + // Start up IM before give the item + session_id = gIMMgr->addSession(avatar_name, IM_NOTHING_SPECIAL, dest_agent_id); + } + return LLToolDragAndDrop::handleGiveDragAndDrop(dest_agent_id, session_id, drop, + cargo_type, cargo_data, accept, getName()); + } + } + } + } + *accept = ACCEPT_NO; + return true; +} + + +void LLFloaterAvatarPicker::openFriendsTab() +{ + LLTabContainer* tab_container = getChild("ResidentChooserTabs"); + if (tab_container == NULL) + { + llassert(tab_container != NULL); + return; + } + + tab_container->selectTabByName("FriendsPanel"); +} + +// static +void LLFloaterAvatarPicker::processAvatarPickerReply(LLMessageSystem* msg, void**) +{ + LLUUID agent_id; + LLUUID query_id; + LLUUID avatar_id; + std::string first_name; + std::string last_name; + + msg->getUUID("AgentData", "AgentID", agent_id); + msg->getUUID("AgentData", "QueryID", query_id); + + // Not for us + if (agent_id != gAgent.getID()) return; + + LLFloaterAvatarPicker* floater = LLFloaterReg::findTypedInstance("avatar_picker"); + + // floater is closed or these are not results from our last request + if (NULL == floater || query_id != floater->mQueryID) + { + return; + } + + LLScrollListCtrl* search_results = floater->getChild("SearchResults"); + + // clear "Searching" label on first results + if (floater->mNumResultsReturned++ == 0) + { + search_results->deleteAllItems(); + } + + bool found_one = false; + S32 num_new_rows = msg->getNumberOfBlocks("Data"); + for (S32 i = 0; i < num_new_rows; i++) + { + msg->getUUIDFast( _PREHASH_Data,_PREHASH_AvatarID, avatar_id, i); + msg->getStringFast(_PREHASH_Data,_PREHASH_FirstName, first_name, i); + msg->getStringFast(_PREHASH_Data,_PREHASH_LastName, last_name, i); + + if (avatar_id != agent_id || !floater->isExcludeAgentFromSearchResults()) // exclude agent from search results? + { + std::string avatar_name; + if (avatar_id.isNull()) + { + LLStringUtil::format_map_t map; + map["[TEXT]"] = floater->getChild("Edit")->getValue().asString(); + avatar_name = floater->getString("not_found", map); + search_results->setEnabled(false); + floater->getChildView("ok_btn")->setEnabled(false); + } + else + { + avatar_name = LLCacheName::buildFullName(first_name, last_name); + search_results->setEnabled(true); + found_one = true; + + LLAvatarName av_name; + av_name.fromString(avatar_name); + const LLUUID& agent_id = avatar_id; + sAvatarNameMap[agent_id] = av_name; + + } + LLSD element; + element["id"] = avatar_id; // value + element["columns"][0]["column"] = "name"; + element["columns"][0]["value"] = avatar_name; + search_results->addElement(element); + } + } + + if (found_one) + { + floater->getChildView("ok_btn")->setEnabled(true); + search_results->selectFirstItem(); + floater->onList(); + search_results->setFocus(true); + } +} + +void LLFloaterAvatarPicker::processResponse(const LLUUID& query_id, const LLSD& content) +{ + // Check for out-of-date query + if (query_id == mQueryID) + { + LLScrollListCtrl* search_results = getChild("SearchResults"); + + // clear "Searching" label on first results + search_results->deleteAllItems(); + + if (content.has("failure_reason")) + { + getChild("SearchResults")->setCommentText(content["failure_reason"].asString()); + getChildView("ok_btn")->setEnabled(false); + } + else + { + LLSD agents = content["agents"]; + + LLSD item; + LLSD::array_const_iterator it = agents.beginArray(); + for (; it != agents.endArray(); ++it) + { + const LLSD& row = *it; + if (row["id"].asUUID() != gAgent.getID() || !mExcludeAgentFromSearchResults) + { + item["id"] = row["id"]; + LLSD& columns = item["columns"]; + columns[0]["column"] = "name"; + columns[0]["value"] = row["display_name"]; + columns[1]["column"] = "username"; + columns[1]["value"] = row["username"]; + search_results->addElement(item); + + // add the avatar name to our list + LLAvatarName avatar_name; + avatar_name.fromLLSD(row); + sAvatarNameMap[row["id"].asUUID()] = avatar_name; + } + } + + if (search_results->isEmpty()) + { + std::string name = "'" + getChild("Edit")->getValue().asString() + "'"; + LLSD item; + item["id"] = LLUUID::null; + item["columns"][0]["column"] = "name"; + item["columns"][0]["value"] = name; + item["columns"][1]["column"] = "username"; + item["columns"][1]["value"] = getString("not_found_text"); + search_results->addElement(item); + search_results->setEnabled(false); + getChildView("ok_btn")->setEnabled(false); + } + else + { + getChildView("ok_btn")->setEnabled(true); + search_results->setEnabled(true); + search_results->sortByColumnIndex(1, true); + std::string text = getChild("Edit")->getValue().asString(); + if (!search_results->selectItemByLabel(text, true, 1)) + { + search_results->selectFirstItem(); + } + onList(); + search_results->setFocus(true); + } + } + } +} + +void LLFloaterAvatarPicker::editKeystroke(LLLineEditor* caller, void* user_data) +{ + getChildView("Find")->setEnabled(caller->getText().size() > 0); +} + +// virtual +bool LLFloaterAvatarPicker::handleKeyHere(KEY key, MASK mask) +{ + if (key == KEY_RETURN && mask == MASK_NONE) + { + if (getChild("Edit")->hasFocus()) + { + onBtnFind(); + } + else + { + onBtnSelect(); + } + return true; + } + else if (key == KEY_ESCAPE && mask == MASK_NONE) + { + closeFloater(); + return true; + } + + return LLFloater::handleKeyHere(key, mask); +} + +bool LLFloaterAvatarPicker::isSelectBtnEnabled() +{ + bool ret_val = visibleItemsSelected(); + + if ( ret_val && !isMinimized()) + { + std::string acvtive_panel_name; + LLScrollListCtrl* list = NULL; + LLPanel* active_panel = getChild("ResidentChooserTabs")->getCurrentPanel(); + + if(active_panel) + { + acvtive_panel_name = active_panel->getName(); + } + + if(acvtive_panel_name == "SearchPanel") + { + list = getChild("SearchResults"); + } + else if(acvtive_panel_name == "NearMePanel") + { + list = getChild("NearMe"); + } + else if (acvtive_panel_name == "FriendsPanel") + { + list = getChild("Friends"); + } + + if(list) + { + uuid_vec_t avatar_ids; + std::vector avatar_names; + getSelectedAvatarData(list, avatar_ids, avatar_names); + if (avatar_ids.size() >= 1) + { + ret_val = mOkButtonValidateSignal.num_slots()?mOkButtonValidateSignal(avatar_ids):true; + } + else + { + ret_val = false; + } + } + } + + return ret_val; +} -- cgit v1.2.3