summaryrefslogtreecommitdiff
path: root/indra/newview/llfloateravatarpicker.cpp
diff options
context:
space:
mode:
authorAimee Linden <aimee@lindenlab.com>2010-09-03 17:41:39 +0100
committerAimee Linden <aimee@lindenlab.com>2010-09-03 17:41:39 +0100
commitffae589843c2977ae7f70de78d84c936e2a91291 (patch)
tree497660a88fe55382639dea1b2f3499241127470d /indra/newview/llfloateravatarpicker.cpp
parent63f2ddf377fa0fc6a666cdc1001289335d86258b (diff)
parent25c29d59cf658acec5901c6f06775add10cf0bfd (diff)
Post-convert merge by convert_monolith.py from /Users/Aimee/Documents/Work/Linden-Lab/Development/viewer/convert/viewer-identity-evolution
Diffstat (limited to 'indra/newview/llfloateravatarpicker.cpp')
-rw-r--r--indra/newview/llfloateravatarpicker.cpp192
1 files changed, 169 insertions, 23 deletions
diff --git a/indra/newview/llfloateravatarpicker.cpp b/indra/newview/llfloateravatarpicker.cpp
index 9391c761b7..dbe98eda83 100644
--- a/indra/newview/llfloateravatarpicker.cpp
+++ b/indra/newview/llfloateravatarpicker.cpp
@@ -35,10 +35,14 @@
#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 "llhttpclient.h" // IDEVO
#include "lllineeditor.h"
#include "llscrolllistctrl.h"
#include "llscrolllistitem.h"
@@ -47,6 +51,11 @@
#include "lluictrlfactory.h"
#include "message.h"
+//#include "llsdserialize.h"
+
+//put it back as a member once the legacy path is out?
+static std::map<LLUUID, LLAvatarName> sAvatarNameMap;
+
LLFloaterAvatarPicker* LLFloaterAvatarPicker::show(select_callback_t callback,
BOOL allow_multiple,
BOOL closeOnSelect)
@@ -153,7 +162,7 @@ void LLFloaterAvatarPicker::onBtnFind()
find();
}
-static void getSelectedAvatarData(const LLScrollListCtrl* from, std::vector<std::string>& avatar_names, uuid_vec_t& avatar_ids)
+static void getSelectedAvatarData(const LLScrollListCtrl* from, uuid_vec_t& avatar_ids, std::vector<LLAvatarName>& avatar_names)
{
std::vector<LLScrollListItem*> items = from->getAllSelected();
for (std::vector<LLScrollListItem*>::iterator iter = items.begin(); iter != items.end(); ++iter)
@@ -161,8 +170,21 @@ static void getSelectedAvatarData(const LLScrollListCtrl* from, std::vector<std:
LLScrollListItem* item = *iter;
if (item->getUUID().notNull())
{
- avatar_names.push_back(item->getColumn(0)->getValue().asString());
avatar_ids.push_back(item->getUUID());
+
+ std::map<LLUUID, LLAvatarName>::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);
+ }
}
}
}
@@ -198,10 +220,10 @@ void LLFloaterAvatarPicker::onBtnSelect()
if(list)
{
- std::vector<std::string> avatar_names;
uuid_vec_t avatar_ids;
- getSelectedAvatarData(list, avatar_names, avatar_ids);
- mSelectionCallback(avatar_names, avatar_ids);
+ std::vector<LLAvatarName> avatar_names;
+ getSelectedAvatarData(list, avatar_ids, avatar_names);
+ mSelectionCallback(avatar_ids, avatar_names);
}
}
getChild<LLScrollListCtrl>("SearchResults")->deselectAllItems(TRUE);
@@ -251,15 +273,22 @@ void LLFloaterAvatarPicker::populateNearMe()
if(av == gAgent.getID()) continue;
LLSD element;
element["id"] = av; // value
- std::string fullname;
- if(!gCacheName->getFullName(av, fullname))
+ LLAvatarName av_name;
+
+ if (!LLAvatarNameCache::get(av, &av_name))
{
+ element["columns"][0]["column"] = "name";
element["columns"][0]["value"] = LLCacheName::getDefaultName();
all_loaded = FALSE;
}
else
{
- element["columns"][0]["value"] = fullname;
+ element["columns"][0]["column"] = "name";
+ element["columns"][0]["value"] = av_name.mDisplayName;
+ element["columns"][1]["column"] = "username";
+ element["columns"][1]["value"] = av_name.mUsername;
+
+ sAvatarNameMap[av] = av_name;
}
near_me_scroller->addElement(element);
empty = FALSE;
@@ -294,7 +323,6 @@ void LLFloaterAvatarPicker::populateFriend()
LLAvatarTracker::instance().applyFunctor(collector);
LLCollectAllBuddies::buddy_map_t::iterator it;
-
for(it = collector.mOnline.begin(); it!=collector.mOnline.end(); it++)
{
friends_scroller->addStringUUIDItem(it->first, it->second);
@@ -346,23 +374,81 @@ BOOL LLFloaterAvatarPicker::visibleItemsSelected() const
return FALSE;
}
+class LLAvatarPickerResponder : public LLHTTPClient::Responder
+{
+public:
+ LLUUID mQueryID;
+
+ LLAvatarPickerResponder(const LLUUID& id) : mQueryID(id) { }
+
+ /*virtual*/ void completed(U32 status, const std::string& reason, const LLSD& content)
+ {
+ //std::ostringstream ss;
+ //LLSDSerialize::toPrettyXML(content, ss);
+ //llinfos << ss.str() << llendl;
+
+ // in case of invalid characters, the avatar picker returns a 400
+ // just set it to process so it displays 'not found'
+ if (isGoodStatus(status) || status == 400)
+ {
+ LLFloaterAvatarPicker* floater =
+ LLFloaterReg::findTypedInstance<LLFloaterAvatarPicker>("avatar_picker");
+ if (floater)
+ {
+ floater->processResponse(mQueryID, content);
+ }
+ }
+ else
+ {
+ llinfos << "avatar picker failed " << status
+ << " reason " << reason << llendl;
+
+ }
+ }
+};
+
void LLFloaterAvatarPicker::find()
{
+ //clear our stored LLAvatarNames
+ sAvatarNameMap.clear();
+
std::string text = getChild<LLUICtrl>("Edit")->getValue().asString();
mQueryID.generate();
- 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);
+ std::string url;
+ url.reserve(128); // avoid a memory allocation or two
- gAgent.sendReliableMessage();
+ LLViewerRegion* region = gAgent.getRegion();
+ url = region->getCapability("AvatarPickerSearch");
+ // Prefer use of capabilities to search on both SLID and display name
+ // but allow display name search to be manually turned off for test
+ if (!url.empty()
+ && LLAvatarNameCache::useDisplayNames())
+ {
+ // 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=";
+ url += LLURI::escape(text);
+ llinfos << "avatar picker " << url << llendl;
+ LLHTTPClient::get(url, new LLAvatarPickerResponder(mQueryID));
+ }
+ 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<LLScrollListCtrl>("SearchResults")->deleteAllItems();
getChild<LLScrollListCtrl>("SearchResults")->setCommentText(getString("searching"));
@@ -503,12 +589,21 @@ void LLFloaterAvatarPicker::processAvatarPickerReply(LLMessageSystem* msg, void*
}
else
{
- avatar_name = first_name + " " + last_name;
+ avatar_name = LLCacheName::buildFullName(first_name, last_name);
search_results->setEnabled(TRUE);
found_one = TRUE;
+
+ LLAvatarName av_name;
+ av_name.mLegacyFirstName = first_name;
+ av_name.mLegacyLastName = last_name;
+ av_name.mDisplayName = 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);
}
@@ -522,10 +617,61 @@ void LLFloaterAvatarPicker::processAvatarPickerReply(LLMessageSystem* msg, void*
}
}
+void LLFloaterAvatarPicker::processResponse(const LLUUID& query_id, const LLSD& content)
+{
+ // Check for out-of-date query
+ if (query_id != mQueryID) return;
+
+ LLScrollListCtrl* search_results = getChild<LLScrollListCtrl>("SearchResults");
+
+ LLSD agents = content["agents"];
+ if (agents.size() == 0)
+ {
+ LLStringUtil::format_map_t map;
+ map["[TEXT]"] = childGetText("Edit");
+ LLSD item;
+ item["id"] = LLUUID::null;
+ item["columns"][0]["column"] = "name";
+ item["columns"][0]["value"] = getString("not_found", map);
+ search_results->addElement(item);
+ search_results->setEnabled(false);
+ getChildView("ok_btn")->setEnabled(false);
+ return;
+ }
+
+ // clear "Searching" label on first results
+ search_results->deleteAllItems();
+
+ LLSD item;
+ LLSD::array_const_iterator it = agents.beginArray();
+ for ( ; it != agents.endArray(); ++it)
+ {
+ const LLSD& row = *it;
+ 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;
+ }
+
+ getChildView("ok_btn")->setEnabled(true);
+ search_results->setEnabled(true);
+ search_results->selectFirstItem();
+ onList();
+ search_results->setFocus(TRUE);
+}
+
//static
void LLFloaterAvatarPicker::editKeystroke(LLLineEditor* caller, void* user_data)
{
- getChildView("Find")->setEnabled(caller->getText().size() >= 3);
+ getChildView("Find")->setEnabled(caller->getText().size() > 0);
}
// virtual
@@ -583,8 +729,8 @@ bool LLFloaterAvatarPicker::isSelectBtnEnabled()
if(list)
{
uuid_vec_t avatar_ids;
- std::vector<std::string> avatar_names;
- getSelectedAvatarData(list, avatar_names, avatar_ids);
+ std::vector<LLAvatarName> avatar_names;
+ getSelectedAvatarData(list, avatar_ids, avatar_names);
return mOkButtonValidateSignal(avatar_ids);
}
}