llfloatergroups.cpp

Go to the documentation of this file.
00001 
00032 /*
00033  * Shown from Edit -> Groups...
00034  * Shows the agent's groups and allows the edit window to be invoked.
00035  * Also overloaded to allow picking of a single group for assigning 
00036  * objects and land to groups.
00037  */
00038 
00039 #include "llviewerprecompiledheaders.h"
00040 
00041 #include "llfloatergroups.h"
00042 
00043 #include "message.h"
00044 #include "roles_constants.h"
00045 
00046 #include "llagent.h"
00047 #include "llbutton.h"
00048 #include "llfloatergroupinfo.h"
00049 #include "llfloaterdirectory.h"
00050 #include "llfocusmgr.h"
00051 #include "llalertdialog.h"
00052 #include "llselectmgr.h"
00053 #include "llscrolllistctrl.h"
00054 #include "lltextbox.h"
00055 #include "llvieweruictrlfactory.h"
00056 #include "llviewerwindow.h"
00057 #include "llimview.h"
00058 
00059 // static
00060 std::map<const LLUUID, LLFloaterGroupPicker*> LLFloaterGroupPicker::sInstances;
00061 
00062 // helper functions
00063 void init_group_list(LLScrollListCtrl* ctrl, const LLUUID& highlight_id, U64 powers_mask = GP_ALL_POWERS);
00064 
00068 
00069 // static
00070 LLFloaterGroupPicker* LLFloaterGroupPicker::findInstance(const LLSD& seed)
00071 {
00072         instance_map_t::iterator found_it = sInstances.find(seed.asUUID());
00073         if (found_it != sInstances.end())
00074         {
00075                 return found_it->second;
00076         }
00077         return NULL;
00078 }
00079 
00080 // static
00081 LLFloaterGroupPicker* LLFloaterGroupPicker::createInstance(const LLSD &seed)
00082 {
00083         LLFloaterGroupPicker* pickerp = new LLFloaterGroupPicker(seed);
00084         gUICtrlFactory->buildFloater(pickerp, "floater_choose_group.xml");
00085         return pickerp;
00086 }
00087 
00088 LLFloaterGroupPicker::LLFloaterGroupPicker(const LLSD& seed) : 
00089         mSelectCallback(NULL),
00090         mCallbackUserdata(NULL),
00091         mPowersMask(GP_ALL_POWERS)
00092 {
00093         mID = seed.asUUID();
00094         sInstances.insert(std::make_pair(mID, this));
00095 }
00096 
00097 LLFloaterGroupPicker::~LLFloaterGroupPicker()
00098 {
00099         sInstances.erase(mID);
00100 }
00101 
00102 void LLFloaterGroupPicker::setSelectCallback(void (*callback)(LLUUID, void*), 
00103                                                                         void* userdata)
00104 {
00105         mSelectCallback = callback;
00106         mCallbackUserdata = userdata;
00107 }
00108 
00109 void LLFloaterGroupPicker::setPowersMask(U64 powers_mask)
00110 {
00111         mPowersMask = powers_mask;
00112         postBuild();
00113 }
00114 
00115 
00116 BOOL LLFloaterGroupPicker::postBuild()
00117 {
00118         init_group_list(LLUICtrlFactory::getScrollListByName(this, "group list"), gAgent.getGroupID(), mPowersMask);
00119 
00120         childSetAction("OK", onBtnOK, this);
00121 
00122         childSetAction("Cancel", onBtnCancel, this);
00123 
00124         setDefaultBtn("OK");
00125 
00126         childSetDoubleClickCallback("group list", onBtnOK);
00127         childSetUserData("group list", this);
00128 
00129         childEnable("OK");
00130 
00131         return TRUE;
00132 }
00133 
00134 void LLFloaterGroupPicker::onBtnOK(void* userdata)
00135 {
00136         LLFloaterGroupPicker* self = (LLFloaterGroupPicker*)userdata;
00137         if(self) self->ok();
00138 }
00139 
00140 void LLFloaterGroupPicker::onBtnCancel(void* userdata)
00141 {
00142         LLFloaterGroupPicker* self = (LLFloaterGroupPicker*)userdata;
00143         if(self) self->close();
00144 }
00145 
00146 
00147 void LLFloaterGroupPicker::ok()
00148 {
00149         LLCtrlListInterface *group_list = childGetListInterface("group list");
00150         LLUUID group_id;
00151         if (group_list)
00152         {
00153                 group_id = group_list->getCurrentID();
00154         }
00155         if(mSelectCallback)
00156         {
00157                 mSelectCallback(group_id, mCallbackUserdata);
00158         }
00159 
00160         close();
00161 }
00162 
00166 
00167 //LLEventListener
00168 //virtual
00169 bool LLPanelGroups::handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
00170 {
00171         if (event->desc() == "new group")
00172         {
00173                 reset();
00174                 return true;
00175         }
00176         
00177         return LLView::handleEvent(event, userdata);
00178 }
00179 
00180 // Default constructor
00181 LLPanelGroups::LLPanelGroups() :
00182         LLPanel()
00183 {
00184         gAgent.addListener(this, "new group");
00185 }
00186 
00187 LLPanelGroups::~LLPanelGroups()
00188 {
00189         gAgent.removeListener(this);
00190 }
00191 
00192 // clear the group list, and get a fresh set of info.
00193 void LLPanelGroups::reset()
00194 {
00195         LLCtrlListInterface *group_list = childGetListInterface("group list");
00196         if (group_list)
00197         {
00198                 group_list->operateOnAll(LLCtrlListInterface::OP_DELETE);
00199         }
00200         childSetTextArg("groupcount", "[COUNT]", llformat("%d",gAgent.mGroups.count()));
00201         childSetTextArg("groupcount", "[MAX]", llformat("%d",MAX_AGENT_GROUPS));
00202 
00203         init_group_list(LLUICtrlFactory::getScrollListByName(this, "group list"), gAgent.getGroupID());
00204         enableButtons();
00205 }
00206 
00207 BOOL LLPanelGroups::postBuild()
00208 {
00209         childSetCommitCallback("group list", onGroupList, this);
00210 
00211         childSetTextArg("groupcount", "[COUNT]", llformat("%d",gAgent.mGroups.count()));
00212         childSetTextArg("groupcount", "[MAX]", llformat("%d",MAX_AGENT_GROUPS));
00213 
00214         init_group_list(LLUICtrlFactory::getScrollListByName(this, "group list"), gAgent.getGroupID());
00215 
00216         childSetAction("Activate", onBtnActivate, this);
00217 
00218         childSetAction("Info", onBtnInfo, this);
00219 
00220         childSetAction("IM", onBtnIM, this);
00221 
00222         childSetAction("Leave", onBtnLeave, this);
00223 
00224         childSetAction("Create", onBtnCreate, this);
00225 
00226         childSetAction("Search...", onBtnSearch, this);
00227 
00228         setDefaultBtn("IM");
00229 
00230         childSetDoubleClickCallback("group list", onBtnIM);
00231         childSetUserData("group list", this);
00232 
00233         reset();
00234 
00235         return TRUE;
00236 }
00237 
00238 void LLPanelGroups::enableButtons()
00239 {
00240         LLCtrlListInterface *group_list = childGetListInterface("group list");
00241         LLUUID group_id;
00242         if (group_list)
00243         {
00244                 group_id = group_list->getCurrentID();
00245         }
00246 
00247         if(group_id != gAgent.getGroupID())
00248         {
00249                 childEnable("Activate");
00250         }
00251         else
00252         {
00253                 childDisable("Activate");
00254         }
00255         if (group_id.notNull())
00256         {
00257                 childEnable("Info");
00258                 childEnable("IM");
00259                 childEnable("Leave");
00260         }
00261         else
00262         {
00263                 childDisable("Info");
00264                 childDisable("IM");
00265                 childDisable("Leave");
00266         }
00267         if(gAgent.mGroups.count() < MAX_AGENT_GROUPS)
00268         {
00269                 childEnable("Create");
00270         }
00271         else
00272         {
00273                 childDisable("Create");
00274         }
00275 }
00276 
00277 
00278 void LLPanelGroups::onBtnCreate(void* userdata)
00279 {
00280         LLPanelGroups* self = (LLPanelGroups*)userdata;
00281         if(self) self->create();
00282 }
00283 
00284 void LLPanelGroups::onBtnActivate(void* userdata)
00285 {
00286         LLPanelGroups* self = (LLPanelGroups*)userdata;
00287         if(self) self->activate();
00288 }
00289 
00290 void LLPanelGroups::onBtnInfo(void* userdata)
00291 {
00292         LLPanelGroups* self = (LLPanelGroups*)userdata;
00293         if(self) self->info();
00294 }
00295 
00296 void LLPanelGroups::onBtnIM(void* userdata)
00297 {
00298         LLPanelGroups* self = (LLPanelGroups*)userdata;
00299         if(self) self->startIM();
00300 }
00301 
00302 void LLPanelGroups::onBtnLeave(void* userdata)
00303 {
00304         LLPanelGroups* self = (LLPanelGroups*)userdata;
00305         if(self) self->leave();
00306 }
00307 
00308 void LLPanelGroups::onBtnSearch(void* userdata)
00309 {
00310         LLPanelGroups* self = (LLPanelGroups*)userdata;
00311         if(self) self->search();
00312 }
00313 
00314 void LLPanelGroups::create()
00315 {
00316         llinfos << "LLPanelGroups::create" << llendl;
00317         LLFloaterGroupInfo::showCreateGroup(NULL);
00318 }
00319 
00320 void LLPanelGroups::activate()
00321 {
00322         llinfos << "LLPanelGroups::activate" << llendl;
00323         LLCtrlListInterface *group_list = childGetListInterface("group list");
00324         LLUUID group_id;
00325         if (group_list)
00326         {
00327                 group_id = group_list->getCurrentID();
00328         }
00329         LLMessageSystem* msg = gMessageSystem;
00330         msg->newMessageFast(_PREHASH_ActivateGroup);
00331         msg->nextBlockFast(_PREHASH_AgentData);
00332         msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
00333         msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
00334         msg->addUUIDFast(_PREHASH_GroupID, group_id);
00335         gAgent.sendReliableMessage();
00336 }
00337 
00338 void LLPanelGroups::info()
00339 {
00340         llinfos << "LLPanelGroups::info" << llendl;
00341         LLCtrlListInterface *group_list = childGetListInterface("group list");
00342         LLUUID group_id;
00343         if (group_list && (group_id = group_list->getCurrentID()).notNull())
00344         {
00345                 LLFloaterGroupInfo::showFromUUID(group_id);
00346         }
00347 }
00348 
00349 void LLPanelGroups::startIM()
00350 {
00351         //llinfos << "LLPanelFriends::onClickIM()" << llendl;
00352         LLCtrlListInterface *group_list = childGetListInterface("group list");
00353         LLUUID group_id;
00354 
00355         if (group_list && (group_id = group_list->getCurrentID()).notNull())
00356         {
00357                 LLGroupData group_data;
00358                 if (gAgent.getGroupData(group_id, group_data))
00359                 {
00360                         gIMMgr->setFloaterOpen(TRUE);
00361                         gIMMgr->addSession(
00362                                 group_data.mName,
00363                                 IM_SESSION_GROUP_START,
00364                                 group_id);
00365                         make_ui_sound("UISndStartIM");
00366                 }
00367                 else
00368                 {
00369                         // this should never happen, as starting a group IM session
00370                         // relies on you belonging to the group and hence having the group data
00371                         make_ui_sound("UISndInvalidOp");
00372                 }
00373         }
00374 }
00375 
00376 void LLPanelGroups::leave()
00377 {
00378         llinfos << "LLPanelGroups::leave" << llendl;
00379         LLCtrlListInterface *group_list = childGetListInterface("group list");
00380         LLUUID group_id;
00381         if (group_list && (group_id = group_list->getCurrentID()).notNull())
00382         {
00383                 S32 count = gAgent.mGroups.count();
00384                 S32 i;
00385                 for(i = 0; i < count; ++i)
00386                 {
00387                         if(gAgent.mGroups.get(i).mID == group_id)
00388                                 break;
00389                 }
00390                 if(i < count)
00391                 {
00392                         LLUUID* cb_data = new LLUUID((const LLUUID&)group_id);
00393                         LLString::format_map_t args;
00394                         args["[GROUP]"] = gAgent.mGroups.get(i).mName;
00395                         gViewerWindow->alertXml("GroupLeaveConfirmMember", args, callbackLeaveGroup, (void*)cb_data);
00396                 }
00397         }
00398 }
00399 
00400 void LLPanelGroups::search()
00401 {
00402         LLFloaterDirectory::showGroups();
00403 }
00404 
00405 // static
00406 void LLPanelGroups::callbackLeaveGroup(S32 option, void* userdata)
00407 {
00408         LLUUID* group_id = (LLUUID*)userdata;
00409         if(option == 0 && group_id)
00410         {
00411                 LLMessageSystem* msg = gMessageSystem;
00412                 msg->newMessageFast(_PREHASH_LeaveGroupRequest);
00413                 msg->nextBlockFast(_PREHASH_AgentData);
00414                 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
00415                 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
00416                 msg->nextBlockFast(_PREHASH_GroupData);
00417                 msg->addUUIDFast(_PREHASH_GroupID, *group_id);
00418                 gAgent.sendReliableMessage();
00419         }
00420         delete group_id;
00421 }
00422 
00423 void LLPanelGroups::onGroupList(LLUICtrl* ctrl, void* userdata)
00424 {
00425         LLPanelGroups* self = (LLPanelGroups*)userdata;
00426         if(self) self->enableButtons();
00427 }
00428 
00429 void init_group_list(LLScrollListCtrl* ctrl, const LLUUID& highlight_id, U64 powers_mask)
00430 {
00431         S32 count = gAgent.mGroups.count();
00432         LLUUID id;
00433         LLCtrlListInterface *group_list = ctrl->getListInterface();
00434         if (!group_list) return;
00435 
00436         group_list->operateOnAll(LLCtrlListInterface::OP_DELETE);
00437 
00438         for(S32 i = 0; i < count; ++i)
00439         {
00440                 id = gAgent.mGroups.get(i).mID;
00441                 LLGroupData* group_datap = &gAgent.mGroups.get(i);
00442                 if ((group_datap->mPowers & powers_mask) != 0) {
00443                         LLString style = "NORMAL";
00444                         if(highlight_id == id)
00445                         {
00446                                 style = "BOLD";
00447                         }
00448 
00449                         LLSD element;
00450                         element["id"] = id;
00451                         element["columns"][0]["column"] = "name";
00452                         element["columns"][0]["value"] = group_datap->mName;
00453                         element["columns"][0]["font"] = "SANSSERIF";
00454                         element["columns"][0]["font-style"] = style;
00455 
00456                         group_list->addElement(element, ADD_SORTED);
00457                 }
00458         }
00459 
00460         // add "none" to list at top
00461         {
00462                 LLString style = "NORMAL";
00463                 if (highlight_id.isNull())
00464                 {
00465                         style = "BOLD";
00466                 }
00467                 LLSD element;
00468                 element["id"] = LLUUID::null;
00469                 element["columns"][0]["column"] = "name";
00470                 element["columns"][0]["value"] = "none";
00471                 element["columns"][0]["font"] = "SANSSERIF";
00472                 element["columns"][0]["font-style"] = style;
00473 
00474                 group_list->addElement(element, ADD_TOP);
00475         }
00476 
00477         group_list->selectByValue(highlight_id);
00478 }
00479 

Generated on Thu Jul 1 06:08:33 2010 for Second Life Viewer by  doxygen 1.4.7