aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llfloatergroups.cpp
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/newview/llfloatergroups.cpp
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to '')
-rw-r--r--linden/indra/newview/llfloatergroups.cpp473
1 files changed, 473 insertions, 0 deletions
diff --git a/linden/indra/newview/llfloatergroups.cpp b/linden/indra/newview/llfloatergroups.cpp
new file mode 100644
index 0000000..05a6927
--- /dev/null
+++ b/linden/indra/newview/llfloatergroups.cpp
@@ -0,0 +1,473 @@
1/**
2 * @file llfloatergroups.cpp
3 * @brief LLFloaterGroups class implementation
4 *
5 * Copyright (c) 2002-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28/*
29 * Shown from Edit -> Groups...
30 * Shows the agent's groups and allows the edit window to be invoked.
31 * Also overloaded to allow picking of a single group for assigning
32 * objects and land to groups.
33 */
34
35#include "llviewerprecompiledheaders.h"
36
37#include "llfloatergroups.h"
38
39#include "message.h"
40
41#include "llagent.h"
42#include "llbutton.h"
43#include "llfloatergroupinfo.h"
44#include "llfloaterdirectory.h"
45#include "llfocusmgr.h"
46#include "llalertdialog.h"
47#include "llselectmgr.h"
48#include "llscrolllistctrl.h"
49#include "lltextbox.h"
50#include "llvieweruictrlfactory.h"
51#include "llviewerwindow.h"
52
53const LLRect FLOATER_RECT(0, 258, 280, 0);
54const char FLOATER_TITLE[] = "Groups";
55
56// static
57LLMap<const LLUUID, LLFloaterGroups*> LLFloaterGroups::sInstances;
58
59
60///----------------------------------------------------------------------------
61/// Class LLFloaterGroups
62///----------------------------------------------------------------------------
63
64//LLEventListener
65//virtual
66bool LLFloaterGroups::handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
67{
68 if (event->desc() == "new group")
69 {
70 reset();
71 return true;
72 }
73
74 return LLView::handleEvent(event, userdata);
75}
76
77// Call this with an agent id and AGENT_GROUPS for an agent's
78// groups, otherwise, call with an object id and SET_OBJECT_GROUP
79// when modifying an object.
80// static
81LLFloaterGroups* LLFloaterGroups::show(const LLUUID& id, EGroupDialog type)
82{
83 LLFloaterGroups* instance = NULL;
84 if(sInstances.checkData(id))
85 {
86 instance = sInstances.getData(id);
87 if (instance->getType() != type)
88 {
89 // not the type we want ==> destroy it and rebuild below
90 instance->destroy();
91 instance = NULL;
92 }
93 else
94 {
95 // Move the existing view to the front
96 instance->open();
97 }
98 }
99
100 if (!instance)
101 {
102 S32 left = 0;
103 S32 top = 0;
104 LLRect rect = FLOATER_RECT;
105 rect.translate( left - rect.mLeft, top - rect.mTop );
106 instance = new LLFloaterGroups("groups", rect, FLOATER_TITLE, id);
107 if(instance)
108 {
109 sInstances.addData(id, instance);
110 //instance->init(type);
111 instance->mType = type;
112 switch (type)
113 {
114 case AGENT_GROUPS:
115 gUICtrlFactory->buildFloater(instance, "floater_groups.xml");
116 break;
117 case CHOOSE_ONE:
118 gUICtrlFactory->buildFloater(instance, "floater_choose_group.xml");
119 break;
120 }
121 instance->center();
122 instance->open();
123 }
124 }
125 return instance;
126}
127
128// static
129LLFloaterGroups* LLFloaterGroups::getInstance(const LLUUID& id)
130{
131 if(sInstances.checkData(id))
132 {
133 return sInstances.getData(id);
134 }
135 return NULL;
136}
137
138// Default constructor
139LLFloaterGroups::LLFloaterGroups(const std::string& name,
140 const LLRect& rect,
141 const std::string& title,
142 const LLUUID& id) :
143 LLFloater(name, rect, title),
144 mID(id),
145 mType(AGENT_GROUPS),
146 mOKCallback(NULL),
147 mCallbackUserdata(NULL)
148{
149}
150
151// Destroys the object
152LLFloaterGroups::~LLFloaterGroups()
153{
154 gFocusMgr.releaseFocusIfNeeded( this );
155
156 sInstances.removeData(mID);
157}
158
159// clear the group list, and get a fresh set of info.
160void LLFloaterGroups::reset()
161{
162 LLCtrlListInterface *group_list = childGetListInterface("group list");
163 if (group_list)
164 {
165 group_list->operateOnAll(LLCtrlListInterface::OP_DELETE);
166 }
167 childSetTextArg("groupcount", "[COUNT]", llformat("%d",gAgent.mGroups.count()));
168 childSetTextArg("groupcount", "[MAX]", llformat("%d",MAX_AGENT_GROUPS));
169
170 initAgentGroups(gAgent.getGroupID());
171 enableButtons();
172}
173
174void LLFloaterGroups::setOkCallback(void (*callback)(LLUUID, void*),
175 void* userdata)
176{
177 mOKCallback = callback;
178 mCallbackUserdata = userdata;
179}
180
181BOOL LLFloaterGroups::postBuild()
182{
183 childSetCommitCallback("group list", onGroupList, this);
184
185 if(mType == AGENT_GROUPS)
186 {
187 childSetTextArg("groupcount", "[COUNT]", llformat("%d",gAgent.mGroups.count()));
188 childSetTextArg("groupcount", "[MAX]", llformat("%d",MAX_AGENT_GROUPS));
189
190 initAgentGroups(gAgent.getGroupID());
191
192 childSetAction("Activate", onBtnActivate, this);
193
194 childSetAction("Info", onBtnInfo, this);
195
196 childSetAction("Leave", onBtnLeave, this);
197
198 childSetAction("Create", onBtnCreate, this);
199
200 childSetAction("Search...", onBtnSearch, this);
201
202 childSetAction("Close", onBtnCancel, this);
203
204 setDefaultBtn("Info");
205
206 childSetDoubleClickCallback("group list", onBtnInfo);
207 childSetUserData("group list", this);
208 }
209 else
210 {
211 initAgentGroups(gAgent.getGroupID());
212
213 childSetAction("OK", onBtnOK, this);
214
215 childSetAction("Cancel", onBtnCancel, this);
216
217 setDefaultBtn("OK");
218
219 childSetDoubleClickCallback("group list", onBtnOK);
220 childSetUserData("group list", this);
221 }
222
223 enableButtons();
224
225 return TRUE;
226}
227
228void LLFloaterGroups::initAgentGroups(const LLUUID& highlight_id)
229{
230 S32 count = gAgent.mGroups.count();
231 LLUUID id;
232 LLCtrlListInterface *group_list = childGetListInterface("group list");
233 if (!group_list) return;
234
235 group_list->operateOnAll(LLCtrlListInterface::OP_DELETE);
236
237 for(S32 i = 0; i < count; ++i)
238 {
239 id = gAgent.mGroups.get(i).mID;
240 LLGroupData* group_datap = &gAgent.mGroups.get(i);
241 LLString style = "NORMAL";
242 if(highlight_id == id)
243 {
244 style = "BOLD";
245 }
246
247 LLSD element;
248 element["id"] = id;
249 element["columns"][0]["column"] = "name";
250 element["columns"][0]["value"] = group_datap->mName;
251 element["columns"][0]["font"] = "SANSSERIF";
252 element["columns"][0]["font-style"] = style;
253
254 group_list->addElement(element, ADD_SORTED);
255 }
256
257 {
258 LLString style = "NORMAL";
259 if (highlight_id.isNull())
260 {
261 style = "BOLD";
262 }
263 LLSD element;
264 element["id"] = LLUUID::null;
265 element["columns"][0]["column"] = "name";
266 element["columns"][0]["value"] = "none";
267 element["columns"][0]["font"] = "SANSSERIF";
268 element["columns"][0]["font-style"] = style;
269
270 group_list->addElement(element, ADD_TOP);
271 }
272
273 group_list->selectByValue(highlight_id);
274
275 childSetFocus("group list");
276}
277
278void LLFloaterGroups::enableButtons()
279{
280 LLCtrlListInterface *group_list = childGetListInterface("group list");
281 LLUUID group_id;
282 if (group_list)
283 {
284 group_id = group_list->getCurrentID();
285 }
286 if(mType == AGENT_GROUPS)
287 {
288 if(group_id != gAgent.getGroupID())
289 {
290 childEnable("Activate");
291 }
292 else
293 {
294 childDisable("Activate");
295 }
296 if (group_id.notNull())
297 {
298 childEnable("Info");
299 childEnable("Leave");
300 }
301 else
302 {
303 childDisable("Info");
304 childDisable("Leave");
305 }
306 if(gAgent.mGroups.count() < MAX_AGENT_GROUPS)
307 {
308 childEnable("Create");
309 }
310 else
311 {
312 childDisable("Create");
313 }
314 }
315 else
316 {
317 childEnable("OK");
318 }
319}
320
321
322void LLFloaterGroups::onBtnCreate(void* userdata)
323{
324 LLFloaterGroups* self = (LLFloaterGroups*)userdata;
325 if(self) self->create();
326}
327
328void LLFloaterGroups::onBtnActivate(void* userdata)
329{
330 LLFloaterGroups* self = (LLFloaterGroups*)userdata;
331 if(self) self->activate();
332}
333
334void LLFloaterGroups::onBtnInfo(void* userdata)
335{
336 LLFloaterGroups* self = (LLFloaterGroups*)userdata;
337 if(self) self->info();
338}
339
340void LLFloaterGroups::onBtnLeave(void* userdata)
341{
342 LLFloaterGroups* self = (LLFloaterGroups*)userdata;
343 if(self) self->leave();
344}
345
346void LLFloaterGroups::onBtnSearch(void* userdata)
347{
348 LLFloaterGroups* self = (LLFloaterGroups*)userdata;
349 if(self) self->search();
350}
351
352void LLFloaterGroups::onBtnOK(void* userdata)
353{
354 LLFloaterGroups* self = (LLFloaterGroups*)userdata;
355 if(self) self->ok();
356}
357
358void LLFloaterGroups::onBtnCancel(void* userdata)
359{
360 LLFloaterGroups* self = (LLFloaterGroups*)userdata;
361 if(self) self->close();
362}
363
364void LLFloaterGroups::onGroupList(LLUICtrl* ctrl, void* userdata)
365{
366 LLFloaterGroups* self = (LLFloaterGroups*)userdata;
367 if(self) self->highlightGroupList(ctrl);
368}
369
370void LLFloaterGroups::create()
371{
372 llinfos << "LLFloaterGroups::create" << llendl;
373 LLFloaterGroupInfo::showCreateGroup(NULL);
374}
375
376void LLFloaterGroups::activate()
377{
378 llinfos << "LLFloaterGroups::activate" << llendl;
379 LLCtrlListInterface *group_list = childGetListInterface("group list");
380 LLUUID group_id;
381 if (group_list)
382 {
383 group_id = group_list->getCurrentID();
384 }
385 LLMessageSystem* msg = gMessageSystem;
386 msg->newMessageFast(_PREHASH_ActivateGroup);
387 msg->nextBlockFast(_PREHASH_AgentData);
388 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
389 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
390 msg->addUUIDFast(_PREHASH_GroupID, group_id);
391 gAgent.sendReliableMessage();
392}
393
394void LLFloaterGroups::info()
395{
396 llinfos << "LLFloaterGroups::info" << llendl;
397 LLCtrlListInterface *group_list = childGetListInterface("group list");
398 LLUUID group_id;
399 if (group_list && (group_id = group_list->getCurrentID()).notNull())
400 {
401 LLFloaterGroupInfo::showFromUUID(group_id);
402 }
403}
404
405void LLFloaterGroups::leave()
406{
407 llinfos << "LLFloaterGroups::leave" << llendl;
408 LLCtrlListInterface *group_list = childGetListInterface("group list");
409 LLUUID group_id;
410 if (group_list && (group_id = group_list->getCurrentID()).notNull())
411 {
412 S32 count = gAgent.mGroups.count();
413 S32 i;
414 for(i = 0; i < count; ++i)
415 {
416 if(gAgent.mGroups.get(i).mID == group_id)
417 break;
418 }
419 if(i < count)
420 {
421 LLUUID* cb_data = new LLUUID((const LLUUID&)group_id);
422 LLString::format_map_t args;
423 args["[GROUP]"] = gAgent.mGroups.get(i).mName;
424 gViewerWindow->alertXml("GroupLeaveConfirmMember", args, callbackLeaveGroup, (void*)cb_data);
425 }
426 }
427}
428
429void LLFloaterGroups::search()
430{
431 LLFloaterDirectory::showGroups();
432}
433
434// static
435void LLFloaterGroups::callbackLeaveGroup(S32 option, void* userdata)
436{
437 LLUUID* group_id = (LLUUID*)userdata;
438 if(option == 0 && group_id)
439 {
440 LLMessageSystem* msg = gMessageSystem;
441 msg->newMessageFast(_PREHASH_LeaveGroupRequest);
442 msg->nextBlockFast(_PREHASH_AgentData);
443 msg->addUUIDFast(_PREHASH_AgentID, gAgent.getID());
444 msg->addUUIDFast(_PREHASH_SessionID, gAgent.getSessionID());
445 msg->nextBlockFast(_PREHASH_GroupData);
446 msg->addUUIDFast(_PREHASH_GroupID, *group_id);
447 gAgent.sendReliableMessage();
448 }
449 delete group_id;
450}
451
452void LLFloaterGroups::ok()
453{
454 llinfos << "LLFloaterGroups::ok" << llendl;
455 LLCtrlListInterface *group_list = childGetListInterface("group list");
456 LLUUID group_id;
457 if (group_list)
458 {
459 group_id = group_list->getCurrentID();
460 }
461 if(mOKCallback)
462 {
463 mOKCallback(group_id, mCallbackUserdata);
464 }
465
466 close();
467}
468
469void LLFloaterGroups::highlightGroupList(LLUICtrl*)
470{
471 llinfos << "LLFloaterGroups::highlightGroupList" << llendl;
472 enableButtons();
473}