aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llfloatergroups.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'linden/indra/newview/llfloatergroups.cpp')
-rw-r--r--linden/indra/newview/llfloatergroups.cpp477
1 files changed, 234 insertions, 243 deletions
diff --git a/linden/indra/newview/llfloatergroups.cpp b/linden/indra/newview/llfloatergroups.cpp
index 53d5147..74526e1 100644
--- a/linden/indra/newview/llfloatergroups.cpp
+++ b/linden/indra/newview/llfloatergroups.cpp
@@ -1,6 +1,6 @@
1/** 1/**
2 * @file llfloatergroups.cpp 2 * @file llfloatergroups.cpp
3 * @brief LLFloaterGroups class implementation 3 * @brief LLPanelGroups class implementation
4 * 4 *
5 * Copyright (c) 2002-2007, Linden Research, Inc. 5 * Copyright (c) 2002-2007, Linden Research, Inc.
6 * 6 *
@@ -50,115 +50,135 @@
50#include "lltextbox.h" 50#include "lltextbox.h"
51#include "llvieweruictrlfactory.h" 51#include "llvieweruictrlfactory.h"
52#include "llviewerwindow.h" 52#include "llviewerwindow.h"
53 53#include "llimview.h"
54const LLRect FLOATER_RECT(0, 258, 280, 0);
55const char FLOATER_TITLE[] = "Groups";
56 54
57// static 55// static
58LLMap<const LLUUID, LLFloaterGroups*> LLFloaterGroups::sInstances; 56std::map<const LLUUID, LLFloaterGroupPicker*> LLFloaterGroupPicker::sInstances;
59 57
58// helper functions
59void init_group_list(LLScrollListCtrl* ctrl, const LLUUID& highlight_id);
60 60
61///---------------------------------------------------------------------------- 61///----------------------------------------------------------------------------
62/// Class LLFloaterGroups 62/// Class LLFloaterGroupPicker
63///---------------------------------------------------------------------------- 63///----------------------------------------------------------------------------
64 64
65//LLEventListener 65// static
66//virtual 66LLFloaterGroupPicker* LLFloaterGroupPicker::findInstance(const LLSD& seed)
67bool LLFloaterGroups::handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
68{ 67{
69 if (event->desc() == "new group") 68 instance_map_t::iterator found_it = sInstances.find(seed.asUUID());
69 if (found_it != sInstances.end())
70 { 70 {
71 reset(); 71 return found_it->second;
72 return true;
73 } 72 }
74 73 return NULL;
75 return LLView::handleEvent(event, userdata);
76} 74}
77 75
78// Call this with an agent id and AGENT_GROUPS for an agent's
79// groups, otherwise, call with an object id and SET_OBJECT_GROUP
80// when modifying an object.
81// static 76// static
82LLFloaterGroups* LLFloaterGroups::show(const LLUUID& id, EGroupDialog type) 77LLFloaterGroupPicker* LLFloaterGroupPicker::createInstance(const LLSD &seed)
78{
79 LLFloaterGroupPicker* pickerp = new LLFloaterGroupPicker(seed);
80 gUICtrlFactory->buildFloater(pickerp, "floater_choose_group.xml");
81 return pickerp;
82}
83
84LLFloaterGroupPicker::LLFloaterGroupPicker(const LLSD& seed) :
85 mSelectCallback(NULL),
86 mCallbackUserdata(NULL)
87{
88 mID = seed.asUUID();
89 sInstances.insert(std::make_pair(mID, this));
90}
91
92LLFloaterGroupPicker::~LLFloaterGroupPicker()
93{
94 sInstances.erase(mID);
95}
96
97void LLFloaterGroupPicker::setSelectCallback(void (*callback)(LLUUID, void*),
98 void* userdata)
83{ 99{
84 LLFloaterGroups* instance = NULL; 100 mSelectCallback = callback;
85 if(sInstances.checkData(id)) 101 mCallbackUserdata = userdata;
102}
103
104BOOL LLFloaterGroupPicker::postBuild()
105{
106 init_group_list(LLUICtrlFactory::getScrollListByName(this, "group list"), gAgent.getGroupID());
107
108 childSetAction("OK", onBtnOK, this);
109
110 childSetAction("Cancel", onBtnCancel, this);
111
112 setDefaultBtn("OK");
113
114 childSetDoubleClickCallback("group list", onBtnOK);
115 childSetUserData("group list", this);
116
117 childEnable("OK");
118
119 return TRUE;
120}
121
122void LLFloaterGroupPicker::onBtnOK(void* userdata)
123{
124 LLFloaterGroupPicker* self = (LLFloaterGroupPicker*)userdata;
125 if(self) self->ok();
126}
127
128void LLFloaterGroupPicker::onBtnCancel(void* userdata)
129{
130 LLFloaterGroupPicker* self = (LLFloaterGroupPicker*)userdata;
131 if(self) self->close();
132}
133
134
135void LLFloaterGroupPicker::ok()
136{
137 LLCtrlListInterface *group_list = childGetListInterface("group list");
138 LLUUID group_id;
139 if (group_list)
86 { 140 {
87 instance = sInstances.getData(id); 141 group_id = group_list->getCurrentID();
88 if (instance->getType() != type)
89 {
90 // not the type we want ==> destroy it and rebuild below
91 instance->destroy();
92 instance = NULL;
93 }
94 else
95 {
96 // Move the existing view to the front
97 instance->open(); /* Flawfinder: ignore */
98 }
99 } 142 }
100 143 if(mSelectCallback)
101 if (!instance)
102 { 144 {
103 S32 left = 0; 145 mSelectCallback(group_id, mCallbackUserdata);
104 S32 top = 0;
105 LLRect rect = FLOATER_RECT;
106 rect.translate( left - rect.mLeft, top - rect.mTop );
107 instance = new LLFloaterGroups("groups", rect, FLOATER_TITLE, id);
108 if(instance)
109 {
110 sInstances.addData(id, instance);
111 //instance->init(type);
112 instance->mType = type;
113 switch (type)
114 {
115 case AGENT_GROUPS:
116 gUICtrlFactory->buildFloater(instance, "floater_groups.xml");
117 break;
118 case CHOOSE_ONE:
119 gUICtrlFactory->buildFloater(instance, "floater_choose_group.xml");
120 break;
121 }
122 instance->center();
123 instance->open(); /*Flawfinder: ignore*/
124 }
125 } 146 }
126 return instance; 147
148 close();
127} 149}
128 150
129// static 151///----------------------------------------------------------------------------
130LLFloaterGroups* LLFloaterGroups::getInstance(const LLUUID& id) 152/// Class LLPanelGroups
153///----------------------------------------------------------------------------
154
155//LLEventListener
156//virtual
157bool LLPanelGroups::handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
131{ 158{
132 if(sInstances.checkData(id)) 159 if (event->desc() == "new group")
133 { 160 {
134 return sInstances.getData(id); 161 reset();
162 return true;
135 } 163 }
136 return NULL; 164
165 return LLView::handleEvent(event, userdata);
137} 166}
138 167
139// Default constructor 168// Default constructor
140LLFloaterGroups::LLFloaterGroups(const std::string& name, 169LLPanelGroups::LLPanelGroups() :
141 const LLRect& rect, 170 LLPanel()
142 const std::string& title,
143 const LLUUID& id) :
144 LLFloater(name, rect, title),
145 mID(id),
146 mType(AGENT_GROUPS),
147 mOKCallback(NULL),
148 mCallbackUserdata(NULL)
149{ 171{
172 gAgent.addListener(this, "new group");
150} 173}
151 174
152// Destroys the object 175LLPanelGroups::~LLPanelGroups()
153LLFloaterGroups::~LLFloaterGroups()
154{ 176{
155 gFocusMgr.releaseFocusIfNeeded( this ); 177 gAgent.removeListener(this);
156
157 sInstances.removeData(mID);
158} 178}
159 179
160// clear the group list, and get a fresh set of info. 180// clear the group list, and get a fresh set of info.
161void LLFloaterGroups::reset() 181void LLPanelGroups::reset()
162{ 182{
163 LLCtrlListInterface *group_list = childGetListInterface("group list"); 183 LLCtrlListInterface *group_list = childGetListInterface("group list");
164 if (group_list) 184 if (group_list)
@@ -168,215 +188,126 @@ void LLFloaterGroups::reset()
168 childSetTextArg("groupcount", "[COUNT]", llformat("%d",gAgent.mGroups.count())); 188 childSetTextArg("groupcount", "[COUNT]", llformat("%d",gAgent.mGroups.count()));
169 childSetTextArg("groupcount", "[MAX]", llformat("%d",MAX_AGENT_GROUPS)); 189 childSetTextArg("groupcount", "[MAX]", llformat("%d",MAX_AGENT_GROUPS));
170 190
171 initAgentGroups(gAgent.getGroupID()); 191 init_group_list(LLUICtrlFactory::getScrollListByName(this, "group list"), gAgent.getGroupID());
172 enableButtons(); 192 enableButtons();
173} 193}
174 194
175void LLFloaterGroups::setOkCallback(void (*callback)(LLUUID, void*), 195BOOL LLPanelGroups::postBuild()
176 void* userdata)
177{
178 mOKCallback = callback;
179 mCallbackUserdata = userdata;
180}
181
182BOOL LLFloaterGroups::postBuild()
183{ 196{
184 childSetCommitCallback("group list", onGroupList, this); 197 childSetCommitCallback("group list", onGroupList, this);
185 198
186 if(mType == AGENT_GROUPS) 199 childSetTextArg("groupcount", "[COUNT]", llformat("%d",gAgent.mGroups.count()));
187 { 200 childSetTextArg("groupcount", "[MAX]", llformat("%d",MAX_AGENT_GROUPS));
188 childSetTextArg("groupcount", "[COUNT]", llformat("%d",gAgent.mGroups.count()));
189 childSetTextArg("groupcount", "[MAX]", llformat("%d",MAX_AGENT_GROUPS));
190
191 initAgentGroups(gAgent.getGroupID());
192
193 childSetAction("Activate", onBtnActivate, this);
194 201
195 childSetAction("Info", onBtnInfo, this); 202 init_group_list(LLUICtrlFactory::getScrollListByName(this, "group list"), gAgent.getGroupID());
196 203
197 childSetAction("Leave", onBtnLeave, this); 204 childSetAction("Activate", onBtnActivate, this);
198 205
199 childSetAction("Create", onBtnCreate, this); 206 childSetAction("Info", onBtnInfo, this);
200 207
201 childSetAction("Search...", onBtnSearch, this); 208 childSetAction("IM", onBtnIM, this);
202 209
203 childSetAction("Close", onBtnCancel, this); 210 childSetAction("Leave", onBtnLeave, this);
204 211
205 setDefaultBtn("Info"); 212 childSetAction("Create", onBtnCreate, this);
206 213
207 childSetDoubleClickCallback("group list", onBtnInfo); 214 childSetAction("Search...", onBtnSearch, this);
208 childSetUserData("group list", this);
209 }
210 else
211 {
212 initAgentGroups(gAgent.getGroupID());
213
214 childSetAction("OK", onBtnOK, this);
215 215
216 childSetAction("Cancel", onBtnCancel, this); 216 setDefaultBtn("IM");
217 217
218 setDefaultBtn("OK"); 218 childSetDoubleClickCallback("group list", onBtnIM);
219 childSetUserData("group list", this);
219 220
220 childSetDoubleClickCallback("group list", onBtnOK); 221 reset();
221 childSetUserData("group list", this);
222 }
223
224 enableButtons();
225 222
226 return TRUE; 223 return TRUE;
227} 224}
228 225
229void LLFloaterGroups::initAgentGroups(const LLUUID& highlight_id) 226void LLPanelGroups::enableButtons()
230{ 227{
231 S32 count = gAgent.mGroups.count();
232 LLUUID id;
233 LLCtrlListInterface *group_list = childGetListInterface("group list"); 228 LLCtrlListInterface *group_list = childGetListInterface("group list");
234 if (!group_list) return; 229 LLUUID group_id;
235 230 if (group_list)
236 group_list->operateOnAll(LLCtrlListInterface::OP_DELETE);
237
238 for(S32 i = 0; i < count; ++i)
239 { 231 {
240 id = gAgent.mGroups.get(i).mID; 232 group_id = group_list->getCurrentID();
241 LLGroupData* group_datap = &gAgent.mGroups.get(i);
242 LLString style = "NORMAL";
243 if(highlight_id == id)
244 {
245 style = "BOLD";
246 }
247
248 LLSD element;
249 element["id"] = id;
250 element["columns"][0]["column"] = "name";
251 element["columns"][0]["value"] = group_datap->mName;
252 element["columns"][0]["font"] = "SANSSERIF";
253 element["columns"][0]["font-style"] = style;
254
255 group_list->addElement(element, ADD_SORTED);
256 } 233 }
257 234
235 if(group_id != gAgent.getGroupID())
258 { 236 {
259 LLString style = "NORMAL"; 237 childEnable("Activate");
260 if (highlight_id.isNull())
261 {
262 style = "BOLD";
263 }
264 LLSD element;
265 element["id"] = LLUUID::null;
266 element["columns"][0]["column"] = "name";
267 element["columns"][0]["value"] = "none";
268 element["columns"][0]["font"] = "SANSSERIF";
269 element["columns"][0]["font-style"] = style;
270
271 group_list->addElement(element, ADD_TOP);
272 } 238 }
273 239 else
274 group_list->selectByValue(highlight_id);
275
276 childSetFocus("group list");
277}
278
279void LLFloaterGroups::enableButtons()
280{
281 LLCtrlListInterface *group_list = childGetListInterface("group list");
282 LLUUID group_id;
283 if (group_list)
284 { 240 {
285 group_id = group_list->getCurrentID(); 241 childDisable("Activate");
286 } 242 }
287 if(mType == AGENT_GROUPS) 243 if (group_id.notNull())
288 { 244 {
289 if(group_id != gAgent.getGroupID()) 245 childEnable("Info");
290 { 246 childEnable("IM");
291 childEnable("Activate"); 247 childEnable("Leave");
292 }
293 else
294 {
295 childDisable("Activate");
296 }
297 if (group_id.notNull())
298 {
299 childEnable("Info");
300 childEnable("Leave");
301 }
302 else
303 {
304 childDisable("Info");
305 childDisable("Leave");
306 }
307 if(gAgent.mGroups.count() < MAX_AGENT_GROUPS)
308 {
309 childEnable("Create");
310 }
311 else
312 {
313 childDisable("Create");
314 }
315 } 248 }
316 else 249 else
317 { 250 {
318 childEnable("OK"); 251 childDisable("Info");
252 childDisable("IM");
253 childDisable("Leave");
254 }
255 if(gAgent.mGroups.count() < MAX_AGENT_GROUPS)
256 {
257 childEnable("Create");
258 }
259 else
260 {
261 childDisable("Create");
319 } 262 }
320} 263}
321 264
322 265
323void LLFloaterGroups::onBtnCreate(void* userdata) 266void LLPanelGroups::onBtnCreate(void* userdata)
324{ 267{
325 LLFloaterGroups* self = (LLFloaterGroups*)userdata; 268 LLPanelGroups* self = (LLPanelGroups*)userdata;
326 if(self) self->create(); 269 if(self) self->create();
327} 270}
328 271
329void LLFloaterGroups::onBtnActivate(void* userdata) 272void LLPanelGroups::onBtnActivate(void* userdata)
330{ 273{
331 LLFloaterGroups* self = (LLFloaterGroups*)userdata; 274 LLPanelGroups* self = (LLPanelGroups*)userdata;
332 if(self) self->activate(); 275 if(self) self->activate();
333} 276}
334 277
335void LLFloaterGroups::onBtnInfo(void* userdata) 278void LLPanelGroups::onBtnInfo(void* userdata)
336{ 279{
337 LLFloaterGroups* self = (LLFloaterGroups*)userdata; 280 LLPanelGroups* self = (LLPanelGroups*)userdata;
338 if(self) self->info(); 281 if(self) self->info();
339} 282}
340 283
341void LLFloaterGroups::onBtnLeave(void* userdata) 284void LLPanelGroups::onBtnIM(void* userdata)
342{ 285{
343 LLFloaterGroups* self = (LLFloaterGroups*)userdata; 286 LLPanelGroups* self = (LLPanelGroups*)userdata;
344 if(self) self->leave(); 287 if(self) self->startIM();
345} 288}
346 289
347void LLFloaterGroups::onBtnSearch(void* userdata) 290void LLPanelGroups::onBtnLeave(void* userdata)
348{ 291{
349 LLFloaterGroups* self = (LLFloaterGroups*)userdata; 292 LLPanelGroups* self = (LLPanelGroups*)userdata;
350 if(self) self->search(); 293 if(self) self->leave();
351}
352
353void LLFloaterGroups::onBtnOK(void* userdata)
354{
355 LLFloaterGroups* self = (LLFloaterGroups*)userdata;
356 if(self) self->ok();
357}
358
359void LLFloaterGroups::onBtnCancel(void* userdata)
360{
361 LLFloaterGroups* self = (LLFloaterGroups*)userdata;
362 if(self) self->close();
363} 294}
364 295
365void LLFloaterGroups::onGroupList(LLUICtrl* ctrl, void* userdata) 296void LLPanelGroups::onBtnSearch(void* userdata)
366{ 297{
367 LLFloaterGroups* self = (LLFloaterGroups*)userdata; 298 LLPanelGroups* self = (LLPanelGroups*)userdata;
368 if(self) self->highlightGroupList(ctrl); 299 if(self) self->search();
369} 300}
370 301
371void LLFloaterGroups::create() 302void LLPanelGroups::create()
372{ 303{
373 llinfos << "LLFloaterGroups::create" << llendl; 304 llinfos << "LLPanelGroups::create" << llendl;
374 LLFloaterGroupInfo::showCreateGroup(NULL); 305 LLFloaterGroupInfo::showCreateGroup(NULL);
375} 306}
376 307
377void LLFloaterGroups::activate() 308void LLPanelGroups::activate()
378{ 309{
379 llinfos << "LLFloaterGroups::activate" << llendl; 310 llinfos << "LLPanelGroups::activate" << llendl;
380 LLCtrlListInterface *group_list = childGetListInterface("group list"); 311 LLCtrlListInterface *group_list = childGetListInterface("group list");
381 LLUUID group_id; 312 LLUUID group_id;
382 if (group_list) 313 if (group_list)
@@ -392,9 +323,9 @@ void LLFloaterGroups::activate()
392 gAgent.sendReliableMessage(); 323 gAgent.sendReliableMessage();
393} 324}
394 325
395void LLFloaterGroups::info() 326void LLPanelGroups::info()
396{ 327{
397 llinfos << "LLFloaterGroups::info" << llendl; 328 llinfos << "LLPanelGroups::info" << llendl;
398 LLCtrlListInterface *group_list = childGetListInterface("group list"); 329 LLCtrlListInterface *group_list = childGetListInterface("group list");
399 LLUUID group_id; 330 LLUUID group_id;
400 if (group_list && (group_id = group_list->getCurrentID()).notNull()) 331 if (group_list && (group_id = group_list->getCurrentID()).notNull())
@@ -403,9 +334,36 @@ void LLFloaterGroups::info()
403 } 334 }
404} 335}
405 336
406void LLFloaterGroups::leave() 337void LLPanelGroups::startIM()
338{
339 //llinfos << "LLPanelFriends::onClickIM()" << llendl;
340 LLCtrlListInterface *group_list = childGetListInterface("group list");
341 LLUUID group_id;
342
343 if (group_list && (group_id = group_list->getCurrentID()).notNull())
344 {
345 LLGroupData group_data;
346 if (gAgent.getGroupData(group_id, group_data))
347 {
348 gIMMgr->setFloaterOpen(TRUE);
349 gIMMgr->addSession(
350 group_data.mName,
351 IM_SESSION_GROUP_START,
352 group_id);
353 make_ui_sound("UISndStartIM");
354 }
355 else
356 {
357 // this should never happen, as starting a group IM session
358 // relies on you belonging to the group and hence having the group data
359 make_ui_sound("UISndInvalidOp");
360 }
361 }
362}
363
364void LLPanelGroups::leave()
407{ 365{
408 llinfos << "LLFloaterGroups::leave" << llendl; 366 llinfos << "LLPanelGroups::leave" << llendl;
409 LLCtrlListInterface *group_list = childGetListInterface("group list"); 367 LLCtrlListInterface *group_list = childGetListInterface("group list");
410 LLUUID group_id; 368 LLUUID group_id;
411 if (group_list && (group_id = group_list->getCurrentID()).notNull()) 369 if (group_list && (group_id = group_list->getCurrentID()).notNull())
@@ -427,13 +385,13 @@ void LLFloaterGroups::leave()
427 } 385 }
428} 386}
429 387
430void LLFloaterGroups::search() 388void LLPanelGroups::search()
431{ 389{
432 LLFloaterDirectory::showGroups(); 390 LLFloaterDirectory::showGroups();
433} 391}
434 392
435// static 393// static
436void LLFloaterGroups::callbackLeaveGroup(S32 option, void* userdata) 394void LLPanelGroups::callbackLeaveGroup(S32 option, void* userdata)
437{ 395{
438 LLUUID* group_id = (LLUUID*)userdata; 396 LLUUID* group_id = (LLUUID*)userdata;
439 if(option == 0 && group_id) 397 if(option == 0 && group_id)
@@ -450,25 +408,58 @@ void LLFloaterGroups::callbackLeaveGroup(S32 option, void* userdata)
450 delete group_id; 408 delete group_id;
451} 409}
452 410
453void LLFloaterGroups::ok() 411void LLPanelGroups::onGroupList(LLUICtrl* ctrl, void* userdata)
454{ 412{
455 llinfos << "LLFloaterGroups::ok" << llendl; 413 LLPanelGroups* self = (LLPanelGroups*)userdata;
456 LLCtrlListInterface *group_list = childGetListInterface("group list"); 414 if(self) self->enableButtons();
457 LLUUID group_id; 415}
458 if (group_list) 416
417void init_group_list(LLScrollListCtrl* ctrl, const LLUUID& highlight_id)
418{
419 S32 count = gAgent.mGroups.count();
420 LLUUID id;
421 LLCtrlListInterface *group_list = ctrl->getListInterface();
422 if (!group_list) return;
423
424 group_list->operateOnAll(LLCtrlListInterface::OP_DELETE);
425
426 for(S32 i = 0; i < count; ++i)
459 { 427 {
460 group_id = group_list->getCurrentID(); 428 id = gAgent.mGroups.get(i).mID;
429 LLGroupData* group_datap = &gAgent.mGroups.get(i);
430 LLString style = "NORMAL";
431 if(highlight_id == id)
432 {
433 style = "BOLD";
434 }
435
436 LLSD element;
437 element["id"] = id;
438 element["columns"][0]["column"] = "name";
439 element["columns"][0]["value"] = group_datap->mName;
440 element["columns"][0]["font"] = "SANSSERIF";
441 element["columns"][0]["font-style"] = style;
442
443 group_list->addElement(element, ADD_SORTED);
461 } 444 }
462 if(mOKCallback) 445
446 // add "none" to list at top
463 { 447 {
464 mOKCallback(group_id, mCallbackUserdata); 448 LLString style = "NORMAL";
449 if (highlight_id.isNull())
450 {
451 style = "BOLD";
452 }
453 LLSD element;
454 element["id"] = LLUUID::null;
455 element["columns"][0]["column"] = "name";
456 element["columns"][0]["value"] = "none";
457 element["columns"][0]["font"] = "SANSSERIF";
458 element["columns"][0]["font-style"] = style;
459
460 group_list->addElement(element, ADD_TOP);
465 } 461 }
466 462
467 close(); 463 group_list->selectByValue(highlight_id);
468} 464}
469 465
470void LLFloaterGroups::highlightGroupList(LLUICtrl*)
471{
472 llinfos << "LLFloaterGroups::highlightGroupList" << llendl;
473 enableButtons();
474}