Refactored FSGroupTitles

meow-7.2.2
Ansariel 2013-04-25 10:37:34 +02:00
parent efb818d7f1
commit d6cdd9b92f
3 changed files with 41 additions and 74 deletions

View File

@ -32,7 +32,6 @@
#include "llviewermessage.h"
#include "lltrans.h"
/////////////////////////////////////////////////////
// FSGroupTitlesObserver class
//
@ -62,9 +61,7 @@ void FSGroupTitlesObserver::changed(LLGroupChange gc)
// FSGroupTitles class
//
FSGroupTitles::FSGroupTitles(const LLSD& key) :
LLFloater(key),
mIsUpdated(false),
mLastScrollPosition(0)
LLFloater(key)
{
// Register observer and event listener
LLGroupMgr::getInstance()->addObserver(this);
@ -103,23 +100,6 @@ BOOL FSGroupTitles::postBuild()
return TRUE;
}
void FSGroupTitles::draw()
{
if (mIsUpdated && mGroupTitleObserverMap.size() == 0)
{
mIsUpdated = false;
mTitleList->updateSort();
// Add "no group"
bool is_active_group = (LLUUID::null == gAgent.getGroupID());
addListItem(LLUUID::null, LLUUID::null, getString("NoGroupTitle"), LLTrans::getString("GroupsNone"), is_active_group, ADD_TOP);
mTitleList->setScrollPos(mLastScrollPosition);
}
LLFloater::draw();
}
void FSGroupTitles::changed(LLGroupChange gc)
{
switch (gc)
@ -147,14 +127,9 @@ bool FSGroupTitles::handleEvent(LLPointer<LLOldEvents::LLEvent> event, const LLS
void FSGroupTitles::clearObservers()
{
std::map<LLUUID, void*>::iterator it;
while (!mGroupTitleObserverMap.empty())
for (observer_map_t::iterator it = mGroupTitleObserverMap.begin(); it != mGroupTitleObserverMap.end(); ++it)
{
it = mGroupTitleObserverMap.begin();
FSGroupTitlesObserver* observer = (FSGroupTitlesObserver*)it->second;
delete observer;
observer = NULL;
mGroupTitleObserverMap.erase(it);
delete it->second;
}
mGroupTitleObserverMap.clear();
}
@ -165,7 +140,7 @@ void FSGroupTitles::addListItem(const LLUUID& group_id, const LLUUID& role_id, c
std::string font_style = (is_active ? "BOLD" : "NORMAL");
LLSD item;
item["id"] = role_id;
item["id"] = group_id.asString() + role_id.asString(); // Only combination of group id and role id is unique!
item["columns"][0]["column"] = "grouptitle";
item["columns"][0]["type"] = "text";
item["columns"][0]["font"]["style"] = font_style;
@ -181,11 +156,13 @@ void FSGroupTitles::addListItem(const LLUUID& group_id, const LLUUID& role_id, c
item["columns"][3]["type"] = "text";
item["columns"][3]["value"] = group_id;
LLScrollListItem* list_item = mTitleList->addElement(item, position);
mTitleList->addElement(item, position);
// Need to do use the selectByValue method or there would be multiple
// selections on login.
if (is_active)
{
list_item->setSelected(TRUE);
mTitleList->selectByValue(group_id.asString() + role_id.asString());
}
}
@ -198,21 +175,21 @@ void FSGroupTitles::processGroupTitleResults(const LLGroupData& group_data)
const std::vector<LLGroupTitle> group_titles = gmgr_data->mTitles;
// Add group titles
for (std::vector<LLGroupTitle>::const_iterator it = group_titles.begin();
it != group_titles.end(); it++)
for (std::vector<LLGroupTitle>::const_iterator it = group_titles.begin(); it != group_titles.end(); ++it)
{
bool is_active_title = ((*it).mSelected && group_data.mID == gAgent.getGroupID());
addListItem(group_data.mID, (*it).mRoleID, (*it).mTitle, group_name, is_active_title);
LLGroupTitle group_title = *it;
bool is_active_title = (group_title.mSelected && group_data.mID == gAgent.getGroupID());
addListItem(group_data.mID, group_title.mRoleID, group_title.mTitle, group_name, is_active_title);
}
mTitleList->scrollToShowSelected();
// Remove observer
std::map<LLUUID, void*>::iterator it = mGroupTitleObserverMap.find(group_data.mID);
if (it != mGroupTitleObserverMap.end() && it->second != NULL)
observer_map_t::iterator found_it = mGroupTitleObserverMap.find(group_data.mID);
if (found_it != mGroupTitleObserverMap.end())
{
FSGroupTitlesObserver* observer = (FSGroupTitlesObserver*)it->second;
delete observer;
observer = NULL;
mGroupTitleObserverMap.erase(it);
delete found_it->second;
mGroupTitleObserverMap.erase(found_it);
}
}
@ -233,25 +210,19 @@ void FSGroupTitles::activateGroupTitle()
// Send activate group request only if group is different from current group
if (gAgent.getGroupID() != group_id)
{
// Copied from LLGroupActions::activate()
LLMessageSystem* msg = gMessageSystem;
msg->newMessageFast(_PREHASH_ActivateGroup);
msg->nextBlockFast(_PREHASH_AgentData);
msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
msg->addUUIDFast(_PREHASH_GroupID, group_id);
gAgent.sendReliableMessage();
LLGroupActions::activate(group_id);
}
}
}
void FSGroupTitles::refreshGroupTitles()
{
mIsUpdated = false;
clearObservers();
mLastScrollPosition = mTitleList->getScrollPos();
mTitleList->clearRows();
// Add "no group"
addListItem(LLUUID::null, LLUUID::null, getString("NoGroupTitle"), LLTrans::getString("GroupsNone"), gAgent.getGroupID().isNull(), ADD_TOP);
for (S32 i = 0; i < gAgent.mGroups.count(); i++)
{
LLGroupData group_data = gAgent.mGroups.get(i);
@ -259,7 +230,6 @@ void FSGroupTitles::refreshGroupTitles()
mGroupTitleObserverMap[group_data.mID] = roleObserver;
LLGroupMgr::getInstance()->sendGroupTitlesRequest(group_data.mID);
}
mIsUpdated = true;
}
void FSGroupTitles::selectedTitleChanged()

View File

@ -35,14 +35,30 @@
#include "llagent.h"
#include "llgroupmgr.h"
class FSGroupTitles;
class FSGroupTitlesObserver : LLGroupMgrObserver
{
public:
FSGroupTitlesObserver(const LLGroupData& group_data, FSGroupTitles* parent);
virtual ~FSGroupTitlesObserver();
virtual void changed(LLGroupChange gc);
protected:
FSGroupTitles* mParent;
LLGroupData mGroupData;
};
class FSGroupTitles : public LLSingleton<FSGroupTitles>, public LLFloater, public LLGroupMgrObserver, public LLOldEvents::LLSimpleListener
{
public:
FSGroupTitles(const LLSD &);
virtual ~FSGroupTitles();
/*virtual*/ BOOL postBuild();
/*virtual*/ void draw();
virtual void changed(LLGroupChange gc);
bool handleEvent(LLPointer<LLOldEvents::LLEvent> event, const LLSD& userdata); // called on agent group list changes
@ -65,24 +81,8 @@ private:
LLButton* mInfoButton;
LLScrollListCtrl* mTitleList;
bool mIsUpdated;
S32 mLastScrollPosition;
std::map<LLUUID, void*> mGroupTitleObserverMap;
};
class FSGroupTitlesObserver : LLGroupMgrObserver
{
public:
FSGroupTitlesObserver(const LLGroupData& group_data, FSGroupTitles* parent);
virtual ~FSGroupTitlesObserver();
virtual void changed(LLGroupChange gc);
protected:
FSGroupTitles* mParent;
LLGroupData mGroupData;
typedef std::map<LLUUID, FSGroupTitlesObserver*> observer_map_t;
observer_map_t mGroupTitleObserverMap;
};
#endif // FS_GROUPTITLES_H

View File

@ -3857,9 +3857,6 @@ class LLAgentGroupDataUpdateViewerNode : public LLHTTPNode
update_group_floaters(group.mID);
}
}
// <FS:Ansariel> Fire event for group title overview
gAgent.fireEvent(new LLOldEvents::LLEvent(&gAgent, "update grouptitle list"), "");
}
};