diff options
Diffstat (limited to 'indra/newview/llfloatergroups.cpp')
-rw-r--r-- | indra/newview/llfloatergroups.cpp | 477 |
1 files changed, 234 insertions, 243 deletions
diff --git a/indra/newview/llfloatergroups.cpp b/indra/newview/llfloatergroups.cpp index 4535a11ec3..60cfa3b809 100644 --- a/indra/newview/llfloatergroups.cpp +++ b/indra/newview/llfloatergroups.cpp @@ -1,6 +1,6 @@ /** * @file llfloatergroups.cpp - * @brief LLFloaterGroups class implementation + * @brief LLPanelGroups class implementation * * Copyright (c) 2002-$CurrentYear$, Linden Research, Inc. * $License$ @@ -30,115 +30,135 @@ #include "lltextbox.h" #include "llvieweruictrlfactory.h" #include "llviewerwindow.h" - -const LLRect FLOATER_RECT(0, 258, 280, 0); -const char FLOATER_TITLE[] = "Groups"; +#include "llimview.h" // static -LLMap<const LLUUID, LLFloaterGroups*> LLFloaterGroups::sInstances; +std::map<const LLUUID, LLFloaterGroupPicker*> LLFloaterGroupPicker::sInstances; +// helper functions +void init_group_list(LLScrollListCtrl* ctrl, const LLUUID& highlight_id); ///---------------------------------------------------------------------------- -/// Class LLFloaterGroups +/// Class LLFloaterGroupPicker ///---------------------------------------------------------------------------- -//LLEventListener -//virtual -bool LLFloaterGroups::handleEvent(LLPointer<LLEvent> event, const LLSD& userdata) +// static +LLFloaterGroupPicker* LLFloaterGroupPicker::findInstance(const LLSD& seed) { - if (event->desc() == "new group") + instance_map_t::iterator found_it = sInstances.find(seed.asUUID()); + if (found_it != sInstances.end()) { - reset(); - return true; + return found_it->second; } - - return LLView::handleEvent(event, userdata); + return NULL; } -// Call this with an agent id and AGENT_GROUPS for an agent's -// groups, otherwise, call with an object id and SET_OBJECT_GROUP -// when modifying an object. // static -LLFloaterGroups* LLFloaterGroups::show(const LLUUID& id, EGroupDialog type) +LLFloaterGroupPicker* LLFloaterGroupPicker::createInstance(const LLSD &seed) +{ + LLFloaterGroupPicker* pickerp = new LLFloaterGroupPicker(seed); + gUICtrlFactory->buildFloater(pickerp, "floater_choose_group.xml"); + return pickerp; +} + +LLFloaterGroupPicker::LLFloaterGroupPicker(const LLSD& seed) : + mSelectCallback(NULL), + mCallbackUserdata(NULL) +{ + mID = seed.asUUID(); + sInstances.insert(std::make_pair(mID, this)); +} + +LLFloaterGroupPicker::~LLFloaterGroupPicker() +{ + sInstances.erase(mID); +} + +void LLFloaterGroupPicker::setSelectCallback(void (*callback)(LLUUID, void*), + void* userdata) { - LLFloaterGroups* instance = NULL; - if(sInstances.checkData(id)) + mSelectCallback = callback; + mCallbackUserdata = userdata; +} + +BOOL LLFloaterGroupPicker::postBuild() +{ + init_group_list(LLUICtrlFactory::getScrollListByName(this, "group list"), gAgent.getGroupID()); + + childSetAction("OK", onBtnOK, this); + + childSetAction("Cancel", onBtnCancel, this); + + setDefaultBtn("OK"); + + childSetDoubleClickCallback("group list", onBtnOK); + childSetUserData("group list", this); + + childEnable("OK"); + + return TRUE; +} + +void LLFloaterGroupPicker::onBtnOK(void* userdata) +{ + LLFloaterGroupPicker* self = (LLFloaterGroupPicker*)userdata; + if(self) self->ok(); +} + +void LLFloaterGroupPicker::onBtnCancel(void* userdata) +{ + LLFloaterGroupPicker* self = (LLFloaterGroupPicker*)userdata; + if(self) self->close(); +} + + +void LLFloaterGroupPicker::ok() +{ + LLCtrlListInterface *group_list = childGetListInterface("group list"); + LLUUID group_id; + if (group_list) { - instance = sInstances.getData(id); - if (instance->getType() != type) - { - // not the type we want ==> destroy it and rebuild below - instance->destroy(); - instance = NULL; - } - else - { - // Move the existing view to the front - instance->open(); /* Flawfinder: ignore */ - } + group_id = group_list->getCurrentID(); } - - if (!instance) + if(mSelectCallback) { - S32 left = 0; - S32 top = 0; - LLRect rect = FLOATER_RECT; - rect.translate( left - rect.mLeft, top - rect.mTop ); - instance = new LLFloaterGroups("groups", rect, FLOATER_TITLE, id); - if(instance) - { - sInstances.addData(id, instance); - //instance->init(type); - instance->mType = type; - switch (type) - { - case AGENT_GROUPS: - gUICtrlFactory->buildFloater(instance, "floater_groups.xml"); - break; - case CHOOSE_ONE: - gUICtrlFactory->buildFloater(instance, "floater_choose_group.xml"); - break; - } - instance->center(); - instance->open(); /*Flawfinder: ignore*/ - } + mSelectCallback(group_id, mCallbackUserdata); } - return instance; + + close(); } -// static -LLFloaterGroups* LLFloaterGroups::getInstance(const LLUUID& id) +///---------------------------------------------------------------------------- +/// Class LLPanelGroups +///---------------------------------------------------------------------------- + +//LLEventListener +//virtual +bool LLPanelGroups::handleEvent(LLPointer<LLEvent> event, const LLSD& userdata) { - if(sInstances.checkData(id)) + if (event->desc() == "new group") { - return sInstances.getData(id); + reset(); + return true; } - return NULL; + + return LLView::handleEvent(event, userdata); } // Default constructor -LLFloaterGroups::LLFloaterGroups(const std::string& name, - const LLRect& rect, - const std::string& title, - const LLUUID& id) : - LLFloater(name, rect, title), - mID(id), - mType(AGENT_GROUPS), - mOKCallback(NULL), - mCallbackUserdata(NULL) +LLPanelGroups::LLPanelGroups() : + LLPanel() { + gAgent.addListener(this, "new group"); } -// Destroys the object -LLFloaterGroups::~LLFloaterGroups() +LLPanelGroups::~LLPanelGroups() { - gFocusMgr.releaseFocusIfNeeded( this ); - - sInstances.removeData(mID); + gAgent.removeListener(this); } // clear the group list, and get a fresh set of info. -void LLFloaterGroups::reset() +void LLPanelGroups::reset() { LLCtrlListInterface *group_list = childGetListInterface("group list"); if (group_list) @@ -148,215 +168,126 @@ void LLFloaterGroups::reset() childSetTextArg("groupcount", "[COUNT]", llformat("%d",gAgent.mGroups.count())); childSetTextArg("groupcount", "[MAX]", llformat("%d",MAX_AGENT_GROUPS)); - initAgentGroups(gAgent.getGroupID()); + init_group_list(LLUICtrlFactory::getScrollListByName(this, "group list"), gAgent.getGroupID()); enableButtons(); } -void LLFloaterGroups::setOkCallback(void (*callback)(LLUUID, void*), - void* userdata) -{ - mOKCallback = callback; - mCallbackUserdata = userdata; -} - -BOOL LLFloaterGroups::postBuild() +BOOL LLPanelGroups::postBuild() { childSetCommitCallback("group list", onGroupList, this); - if(mType == AGENT_GROUPS) - { - childSetTextArg("groupcount", "[COUNT]", llformat("%d",gAgent.mGroups.count())); - childSetTextArg("groupcount", "[MAX]", llformat("%d",MAX_AGENT_GROUPS)); - - initAgentGroups(gAgent.getGroupID()); - - childSetAction("Activate", onBtnActivate, this); + childSetTextArg("groupcount", "[COUNT]", llformat("%d",gAgent.mGroups.count())); + childSetTextArg("groupcount", "[MAX]", llformat("%d",MAX_AGENT_GROUPS)); - childSetAction("Info", onBtnInfo, this); + init_group_list(LLUICtrlFactory::getScrollListByName(this, "group list"), gAgent.getGroupID()); - childSetAction("Leave", onBtnLeave, this); + childSetAction("Activate", onBtnActivate, this); - childSetAction("Create", onBtnCreate, this); + childSetAction("Info", onBtnInfo, this); - childSetAction("Search...", onBtnSearch, this); + childSetAction("IM", onBtnIM, this); - childSetAction("Close", onBtnCancel, this); + childSetAction("Leave", onBtnLeave, this); - setDefaultBtn("Info"); + childSetAction("Create", onBtnCreate, this); - childSetDoubleClickCallback("group list", onBtnInfo); - childSetUserData("group list", this); - } - else - { - initAgentGroups(gAgent.getGroupID()); - - childSetAction("OK", onBtnOK, this); + childSetAction("Search...", onBtnSearch, this); - childSetAction("Cancel", onBtnCancel, this); + setDefaultBtn("IM"); - setDefaultBtn("OK"); + childSetDoubleClickCallback("group list", onBtnIM); + childSetUserData("group list", this); - childSetDoubleClickCallback("group list", onBtnOK); - childSetUserData("group list", this); - } - - enableButtons(); + reset(); return TRUE; } -void LLFloaterGroups::initAgentGroups(const LLUUID& highlight_id) +void LLPanelGroups::enableButtons() { - S32 count = gAgent.mGroups.count(); - LLUUID id; LLCtrlListInterface *group_list = childGetListInterface("group list"); - if (!group_list) return; - - group_list->operateOnAll(LLCtrlListInterface::OP_DELETE); - - for(S32 i = 0; i < count; ++i) + LLUUID group_id; + if (group_list) { - id = gAgent.mGroups.get(i).mID; - LLGroupData* group_datap = &gAgent.mGroups.get(i); - LLString style = "NORMAL"; - if(highlight_id == id) - { - style = "BOLD"; - } - - LLSD element; - element["id"] = id; - element["columns"][0]["column"] = "name"; - element["columns"][0]["value"] = group_datap->mName; - element["columns"][0]["font"] = "SANSSERIF"; - element["columns"][0]["font-style"] = style; - - group_list->addElement(element, ADD_SORTED); + group_id = group_list->getCurrentID(); } + if(group_id != gAgent.getGroupID()) { - LLString style = "NORMAL"; - if (highlight_id.isNull()) - { - style = "BOLD"; - } - LLSD element; - element["id"] = LLUUID::null; - element["columns"][0]["column"] = "name"; - element["columns"][0]["value"] = "none"; - element["columns"][0]["font"] = "SANSSERIF"; - element["columns"][0]["font-style"] = style; - - group_list->addElement(element, ADD_TOP); + childEnable("Activate"); } - - group_list->selectByValue(highlight_id); - - childSetFocus("group list"); -} - -void LLFloaterGroups::enableButtons() -{ - LLCtrlListInterface *group_list = childGetListInterface("group list"); - LLUUID group_id; - if (group_list) + else { - group_id = group_list->getCurrentID(); + childDisable("Activate"); } - if(mType == AGENT_GROUPS) + if (group_id.notNull()) { - if(group_id != gAgent.getGroupID()) - { - childEnable("Activate"); - } - else - { - childDisable("Activate"); - } - if (group_id.notNull()) - { - childEnable("Info"); - childEnable("Leave"); - } - else - { - childDisable("Info"); - childDisable("Leave"); - } - if(gAgent.mGroups.count() < MAX_AGENT_GROUPS) - { - childEnable("Create"); - } - else - { - childDisable("Create"); - } + childEnable("Info"); + childEnable("IM"); + childEnable("Leave"); } else { - childEnable("OK"); + childDisable("Info"); + childDisable("IM"); + childDisable("Leave"); + } + if(gAgent.mGroups.count() < MAX_AGENT_GROUPS) + { + childEnable("Create"); + } + else + { + childDisable("Create"); } } -void LLFloaterGroups::onBtnCreate(void* userdata) +void LLPanelGroups::onBtnCreate(void* userdata) { - LLFloaterGroups* self = (LLFloaterGroups*)userdata; + LLPanelGroups* self = (LLPanelGroups*)userdata; if(self) self->create(); } -void LLFloaterGroups::onBtnActivate(void* userdata) +void LLPanelGroups::onBtnActivate(void* userdata) { - LLFloaterGroups* self = (LLFloaterGroups*)userdata; + LLPanelGroups* self = (LLPanelGroups*)userdata; if(self) self->activate(); } -void LLFloaterGroups::onBtnInfo(void* userdata) +void LLPanelGroups::onBtnInfo(void* userdata) { - LLFloaterGroups* self = (LLFloaterGroups*)userdata; + LLPanelGroups* self = (LLPanelGroups*)userdata; if(self) self->info(); } -void LLFloaterGroups::onBtnLeave(void* userdata) +void LLPanelGroups::onBtnIM(void* userdata) { - LLFloaterGroups* self = (LLFloaterGroups*)userdata; - if(self) self->leave(); + LLPanelGroups* self = (LLPanelGroups*)userdata; + if(self) self->startIM(); } -void LLFloaterGroups::onBtnSearch(void* userdata) +void LLPanelGroups::onBtnLeave(void* userdata) { - LLFloaterGroups* self = (LLFloaterGroups*)userdata; - if(self) self->search(); -} - -void LLFloaterGroups::onBtnOK(void* userdata) -{ - LLFloaterGroups* self = (LLFloaterGroups*)userdata; - if(self) self->ok(); -} - -void LLFloaterGroups::onBtnCancel(void* userdata) -{ - LLFloaterGroups* self = (LLFloaterGroups*)userdata; - if(self) self->close(); + LLPanelGroups* self = (LLPanelGroups*)userdata; + if(self) self->leave(); } -void LLFloaterGroups::onGroupList(LLUICtrl* ctrl, void* userdata) +void LLPanelGroups::onBtnSearch(void* userdata) { - LLFloaterGroups* self = (LLFloaterGroups*)userdata; - if(self) self->highlightGroupList(ctrl); + LLPanelGroups* self = (LLPanelGroups*)userdata; + if(self) self->search(); } -void LLFloaterGroups::create() +void LLPanelGroups::create() { - llinfos << "LLFloaterGroups::create" << llendl; + llinfos << "LLPanelGroups::create" << llendl; LLFloaterGroupInfo::showCreateGroup(NULL); } -void LLFloaterGroups::activate() +void LLPanelGroups::activate() { - llinfos << "LLFloaterGroups::activate" << llendl; + llinfos << "LLPanelGroups::activate" << llendl; LLCtrlListInterface *group_list = childGetListInterface("group list"); LLUUID group_id; if (group_list) @@ -372,9 +303,9 @@ void LLFloaterGroups::activate() gAgent.sendReliableMessage(); } -void LLFloaterGroups::info() +void LLPanelGroups::info() { - llinfos << "LLFloaterGroups::info" << llendl; + llinfos << "LLPanelGroups::info" << llendl; LLCtrlListInterface *group_list = childGetListInterface("group list"); LLUUID group_id; if (group_list && (group_id = group_list->getCurrentID()).notNull()) @@ -383,9 +314,36 @@ void LLFloaterGroups::info() } } -void LLFloaterGroups::leave() +void LLPanelGroups::startIM() +{ + //llinfos << "LLPanelFriends::onClickIM()" << llendl; + LLCtrlListInterface *group_list = childGetListInterface("group list"); + LLUUID group_id; + + if (group_list && (group_id = group_list->getCurrentID()).notNull()) + { + LLGroupData group_data; + if (gAgent.getGroupData(group_id, group_data)) + { + gIMMgr->setFloaterOpen(TRUE); + gIMMgr->addSession( + group_data.mName, + IM_SESSION_GROUP_START, + group_id); + make_ui_sound("UISndStartIM"); + } + else + { + // this should never happen, as starting a group IM session + // relies on you belonging to the group and hence having the group data + make_ui_sound("UISndInvalidOp"); + } + } +} + +void LLPanelGroups::leave() { - llinfos << "LLFloaterGroups::leave" << llendl; + llinfos << "LLPanelGroups::leave" << llendl; LLCtrlListInterface *group_list = childGetListInterface("group list"); LLUUID group_id; if (group_list && (group_id = group_list->getCurrentID()).notNull()) @@ -407,13 +365,13 @@ void LLFloaterGroups::leave() } } -void LLFloaterGroups::search() +void LLPanelGroups::search() { LLFloaterDirectory::showGroups(); } // static -void LLFloaterGroups::callbackLeaveGroup(S32 option, void* userdata) +void LLPanelGroups::callbackLeaveGroup(S32 option, void* userdata) { LLUUID* group_id = (LLUUID*)userdata; if(option == 0 && group_id) @@ -430,25 +388,58 @@ void LLFloaterGroups::callbackLeaveGroup(S32 option, void* userdata) delete group_id; } -void LLFloaterGroups::ok() +void LLPanelGroups::onGroupList(LLUICtrl* ctrl, void* userdata) { - llinfos << "LLFloaterGroups::ok" << llendl; - LLCtrlListInterface *group_list = childGetListInterface("group list"); - LLUUID group_id; - if (group_list) + LLPanelGroups* self = (LLPanelGroups*)userdata; + if(self) self->enableButtons(); +} + +void init_group_list(LLScrollListCtrl* ctrl, const LLUUID& highlight_id) +{ + S32 count = gAgent.mGroups.count(); + LLUUID id; + LLCtrlListInterface *group_list = ctrl->getListInterface(); + if (!group_list) return; + + group_list->operateOnAll(LLCtrlListInterface::OP_DELETE); + + for(S32 i = 0; i < count; ++i) { - group_id = group_list->getCurrentID(); + id = gAgent.mGroups.get(i).mID; + LLGroupData* group_datap = &gAgent.mGroups.get(i); + LLString style = "NORMAL"; + if(highlight_id == id) + { + style = "BOLD"; + } + + LLSD element; + element["id"] = id; + element["columns"][0]["column"] = "name"; + element["columns"][0]["value"] = group_datap->mName; + element["columns"][0]["font"] = "SANSSERIF"; + element["columns"][0]["font-style"] = style; + + group_list->addElement(element, ADD_SORTED); } - if(mOKCallback) + + // add "none" to list at top { - mOKCallback(group_id, mCallbackUserdata); + LLString style = "NORMAL"; + if (highlight_id.isNull()) + { + style = "BOLD"; + } + LLSD element; + element["id"] = LLUUID::null; + element["columns"][0]["column"] = "name"; + element["columns"][0]["value"] = "none"; + element["columns"][0]["font"] = "SANSSERIF"; + element["columns"][0]["font-style"] = style; + + group_list->addElement(element, ADD_TOP); } - close(); + group_list->selectByValue(highlight_id); } -void LLFloaterGroups::highlightGroupList(LLUICtrl*) -{ - llinfos << "LLFloaterGroups::highlightGroupList" << llendl; - enableButtons(); -} |