00001
00032
00033
00034
00035
00036
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 "lluictrlfactory.h"
00056 #include "llviewerwindow.h"
00057 #include "llimview.h"
00058
00059
00060 std::map<const LLUUID, LLFloaterGroupPicker*> LLFloaterGroupPicker::sInstances;
00061
00062
00063 void init_group_list(LLScrollListCtrl* ctrl, const LLUUID& highlight_id, U64 powers_mask = GP_ALL_POWERS);
00064
00068
00069
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
00081 LLFloaterGroupPicker* LLFloaterGroupPicker::createInstance(const LLSD &seed)
00082 {
00083 LLFloaterGroupPicker* pickerp = new LLFloaterGroupPicker(seed);
00084 LLUICtrlFactory::getInstance()->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(getChild<LLScrollListCtrl>("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
00168
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 return false;
00177 }
00178
00179
00180 LLPanelGroups::LLPanelGroups() :
00181 LLPanel()
00182 {
00183 gAgent.addListener(this, "new group");
00184 }
00185
00186 LLPanelGroups::~LLPanelGroups()
00187 {
00188 gAgent.removeListener(this);
00189 }
00190
00191
00192 void LLPanelGroups::reset()
00193 {
00194 LLCtrlListInterface *group_list = childGetListInterface("group list");
00195 if (group_list)
00196 {
00197 group_list->operateOnAll(LLCtrlListInterface::OP_DELETE);
00198 }
00199 childSetTextArg("groupcount", "[COUNT]", llformat("%d",gAgent.mGroups.count()));
00200 childSetTextArg("groupcount", "[MAX]", llformat("%d",MAX_AGENT_GROUPS));
00201
00202 init_group_list(getChild<LLScrollListCtrl>("group list"), gAgent.getGroupID());
00203 enableButtons();
00204 }
00205
00206 BOOL LLPanelGroups::postBuild()
00207 {
00208 childSetCommitCallback("group list", onGroupList, this);
00209
00210 childSetTextArg("groupcount", "[COUNT]", llformat("%d",gAgent.mGroups.count()));
00211 childSetTextArg("groupcount", "[MAX]", llformat("%d",MAX_AGENT_GROUPS));
00212
00213 init_group_list(getChild<LLScrollListCtrl>("group list"), gAgent.getGroupID());
00214
00215 childSetAction("Activate", onBtnActivate, this);
00216
00217 childSetAction("Info", onBtnInfo, this);
00218
00219 childSetAction("IM", onBtnIM, this);
00220
00221 childSetAction("Leave", onBtnLeave, this);
00222
00223 childSetAction("Create", onBtnCreate, this);
00224
00225 childSetAction("Search...", onBtnSearch, this);
00226
00227 setDefaultBtn("IM");
00228
00229 childSetDoubleClickCallback("group list", onBtnIM);
00230 childSetUserData("group list", this);
00231
00232 reset();
00233
00234 return TRUE;
00235 }
00236
00237 void LLPanelGroups::enableButtons()
00238 {
00239 LLCtrlListInterface *group_list = childGetListInterface("group list");
00240 LLUUID group_id;
00241 if (group_list)
00242 {
00243 group_id = group_list->getCurrentID();
00244 }
00245
00246 if(group_id != gAgent.getGroupID())
00247 {
00248 childEnable("Activate");
00249 }
00250 else
00251 {
00252 childDisable("Activate");
00253 }
00254 if (group_id.notNull())
00255 {
00256 childEnable("Info");
00257 childEnable("IM");
00258 childEnable("Leave");
00259 }
00260 else
00261 {
00262 childDisable("Info");
00263 childDisable("IM");
00264 childDisable("Leave");
00265 }
00266 if(gAgent.mGroups.count() < MAX_AGENT_GROUPS)
00267 {
00268 childEnable("Create");
00269 }
00270 else
00271 {
00272 childDisable("Create");
00273 }
00274 }
00275
00276
00277 void LLPanelGroups::onBtnCreate(void* userdata)
00278 {
00279 LLPanelGroups* self = (LLPanelGroups*)userdata;
00280 if(self) self->create();
00281 }
00282
00283 void LLPanelGroups::onBtnActivate(void* userdata)
00284 {
00285 LLPanelGroups* self = (LLPanelGroups*)userdata;
00286 if(self) self->activate();
00287 }
00288
00289 void LLPanelGroups::onBtnInfo(void* userdata)
00290 {
00291 LLPanelGroups* self = (LLPanelGroups*)userdata;
00292 if(self) self->info();
00293 }
00294
00295 void LLPanelGroups::onBtnIM(void* userdata)
00296 {
00297 LLPanelGroups* self = (LLPanelGroups*)userdata;
00298 if(self) self->startIM();
00299 }
00300
00301 void LLPanelGroups::onBtnLeave(void* userdata)
00302 {
00303 LLPanelGroups* self = (LLPanelGroups*)userdata;
00304 if(self) self->leave();
00305 }
00306
00307 void LLPanelGroups::onBtnSearch(void* userdata)
00308 {
00309 LLPanelGroups* self = (LLPanelGroups*)userdata;
00310 if(self) self->search();
00311 }
00312
00313 void LLPanelGroups::create()
00314 {
00315 llinfos << "LLPanelGroups::create" << llendl;
00316 LLFloaterGroupInfo::showCreateGroup(NULL);
00317 }
00318
00319 void LLPanelGroups::activate()
00320 {
00321 llinfos << "LLPanelGroups::activate" << llendl;
00322 LLCtrlListInterface *group_list = childGetListInterface("group list");
00323 LLUUID group_id;
00324 if (group_list)
00325 {
00326 group_id = group_list->getCurrentID();
00327 }
00328 LLMessageSystem* msg = gMessageSystem;
00329 msg->newMessageFast(_PREHASH_ActivateGroup);
00330 msg->nextBlockFast(_PREHASH_AgentData);
00331 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
00332 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
00333 msg->addUUIDFast(_PREHASH_GroupID, group_id);
00334 gAgent.sendReliableMessage();
00335 }
00336
00337 void LLPanelGroups::info()
00338 {
00339 llinfos << "LLPanelGroups::info" << llendl;
00340 LLCtrlListInterface *group_list = childGetListInterface("group list");
00341 LLUUID group_id;
00342 if (group_list && (group_id = group_list->getCurrentID()).notNull())
00343 {
00344 LLFloaterGroupInfo::showFromUUID(group_id);
00345 }
00346 }
00347
00348 void LLPanelGroups::startIM()
00349 {
00350
00351 LLCtrlListInterface *group_list = childGetListInterface("group list");
00352 LLUUID group_id;
00353
00354 if (group_list && (group_id = group_list->getCurrentID()).notNull())
00355 {
00356 LLGroupData group_data;
00357 if (gAgent.getGroupData(group_id, group_data))
00358 {
00359 gIMMgr->setFloaterOpen(TRUE);
00360 gIMMgr->addSession(
00361 group_data.mName,
00362 IM_SESSION_GROUP_START,
00363 group_id);
00364 make_ui_sound("UISndStartIM");
00365 }
00366 else
00367 {
00368
00369
00370 make_ui_sound("UISndInvalidOp");
00371 }
00372 }
00373 }
00374
00375 void LLPanelGroups::leave()
00376 {
00377 llinfos << "LLPanelGroups::leave" << llendl;
00378 LLCtrlListInterface *group_list = childGetListInterface("group list");
00379 LLUUID group_id;
00380 if (group_list && (group_id = group_list->getCurrentID()).notNull())
00381 {
00382 S32 count = gAgent.mGroups.count();
00383 S32 i;
00384 for(i = 0; i < count; ++i)
00385 {
00386 if(gAgent.mGroups.get(i).mID == group_id)
00387 break;
00388 }
00389 if(i < count)
00390 {
00391 LLUUID* cb_data = new LLUUID((const LLUUID&)group_id);
00392 LLString::format_map_t args;
00393 args["[GROUP]"] = gAgent.mGroups.get(i).mName;
00394 gViewerWindow->alertXml("GroupLeaveConfirmMember", args, callbackLeaveGroup, (void*)cb_data);
00395 }
00396 }
00397 }
00398
00399 void LLPanelGroups::search()
00400 {
00401 LLFloaterDirectory::showGroups();
00402 }
00403
00404
00405 void LLPanelGroups::callbackLeaveGroup(S32 option, void* userdata)
00406 {
00407 LLUUID* group_id = (LLUUID*)userdata;
00408 if(option == 0 && group_id)
00409 {
00410 LLMessageSystem* msg = gMessageSystem;
00411 msg->newMessageFast(_PREHASH_LeaveGroupRequest);
00412 msg->nextBlockFast(_PREHASH_AgentData);
00413 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
00414 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
00415 msg->nextBlockFast(_PREHASH_GroupData);
00416 msg->addUUIDFast(_PREHASH_GroupID, *group_id);
00417 gAgent.sendReliableMessage();
00418 }
00419 delete group_id;
00420 }
00421
00422 void LLPanelGroups::onGroupList(LLUICtrl* ctrl, void* userdata)
00423 {
00424 LLPanelGroups* self = (LLPanelGroups*)userdata;
00425 if(self) self->enableButtons();
00426 }
00427
00428 void init_group_list(LLScrollListCtrl* ctrl, const LLUUID& highlight_id, U64 powers_mask)
00429 {
00430 S32 count = gAgent.mGroups.count();
00431 LLUUID id;
00432 LLCtrlListInterface *group_list = ctrl->getListInterface();
00433 if (!group_list) return;
00434
00435 group_list->operateOnAll(LLCtrlListInterface::OP_DELETE);
00436
00437 for(S32 i = 0; i < count; ++i)
00438 {
00439 id = gAgent.mGroups.get(i).mID;
00440 LLGroupData* group_datap = &gAgent.mGroups.get(i);
00441 if ((group_datap->mPowers & powers_mask) != 0) {
00442 LLString style = "NORMAL";
00443 if(highlight_id == id)
00444 {
00445 style = "BOLD";
00446 }
00447
00448 LLSD element;
00449 element["id"] = id;
00450 element["columns"][0]["column"] = "name";
00451 element["columns"][0]["value"] = group_datap->mName;
00452 element["columns"][0]["font"] = "SANSSERIF";
00453 element["columns"][0]["font-style"] = style;
00454
00455 group_list->addElement(element, ADD_SORTED);
00456 }
00457 }
00458
00459
00460 {
00461 LLString style = "NORMAL";
00462 if (highlight_id.isNull())
00463 {
00464 style = "BOLD";
00465 }
00466 LLSD element;
00467 element["id"] = LLUUID::null;
00468 element["columns"][0]["column"] = "name";
00469 element["columns"][0]["value"] = "none";
00470 element["columns"][0]["font"] = "SANSSERIF";
00471 element["columns"][0]["font-style"] = style;
00472
00473 group_list->addElement(element, ADD_TOP);
00474 }
00475
00476 group_list->selectByValue(highlight_id);
00477 }
00478