PageRenderTime 406ms CodeModel.GetById 160ms app.highlight 117ms RepoModel.GetById 125ms app.codeStats 0ms

/indra/newview/llfloatergroups.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 394 lines | 277 code | 70 blank | 47 comment | 36 complexity | ac678ac5c1ce7bf6c51c11de31902c1d MD5 | raw file
  1/** 
  2 * @file llfloatergroups.cpp
  3 * @brief LLPanelGroups class implementation
  4 *
  5 * $LicenseInfo:firstyear=2002&license=viewerlgpl$
  6 * Second Life Viewer Source Code
  7 * Copyright (C) 2010, Linden Research, Inc.
  8 * 
  9 * This library is free software; you can redistribute it and/or
 10 * modify it under the terms of the GNU Lesser General Public
 11 * License as published by the Free Software Foundation;
 12 * version 2.1 of the License only.
 13 * 
 14 * This library is distributed in the hope that it will be useful,
 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 17 * Lesser General Public License for more details.
 18 * 
 19 * You should have received a copy of the GNU Lesser General Public
 20 * License along with this library; if not, write to the Free Software
 21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 22 * 
 23 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 24 * $/LicenseInfo$
 25 */
 26
 27/*
 28 * Shown from Edit -> Groups...
 29 * Shows the agent's groups and allows the edit window to be invoked.
 30 * Also overloaded to allow picking of a single group for assigning 
 31 * objects and land to groups.
 32 */
 33
 34#include "llviewerprecompiledheaders.h"
 35
 36#include "llfloatergroups.h"
 37
 38#include "roles_constants.h"
 39
 40#include "llagent.h"
 41#include "llbutton.h"
 42#include "llgroupactions.h"
 43#include "llscrolllistctrl.h"
 44#include "llstartup.h"
 45#include "lltextbox.h"
 46#include "lluictrlfactory.h"
 47#include "lltrans.h"
 48
 49using namespace LLOldEvents;
 50
 51// helper functions
 52void init_group_list(LLScrollListCtrl* ctrl, const LLUUID& highlight_id, U64 powers_mask = GP_ALL_POWERS);
 53
 54///----------------------------------------------------------------------------
 55/// Class LLFloaterGroupPicker
 56///----------------------------------------------------------------------------
 57
 58LLFloaterGroupPicker::LLFloaterGroupPicker(const LLSD& seed)
 59: 	LLFloater(seed),
 60	mPowersMask(GP_ALL_POWERS),
 61	mID(seed.asUUID())
 62{
 63// 	LLUICtrlFactory::getInstance()->buildFloater(this, "floater_choose_group.xml");
 64}
 65
 66LLFloaterGroupPicker::~LLFloaterGroupPicker()
 67{
 68}
 69
 70void LLFloaterGroupPicker::setPowersMask(U64 powers_mask)
 71{
 72	mPowersMask = powers_mask;
 73	init_group_list(getChild<LLScrollListCtrl>("group list"), gAgent.getGroupID(), mPowersMask);
 74}
 75
 76
 77BOOL LLFloaterGroupPicker::postBuild()
 78{
 79	LLScrollListCtrl* list_ctrl = getChild<LLScrollListCtrl>("group list");
 80	if (list_ctrl)
 81	{
 82		init_group_list(list_ctrl, gAgent.getGroupID(), mPowersMask);
 83		list_ctrl->setDoubleClickCallback(onBtnOK, this);
 84		list_ctrl->setContextMenu(LLScrollListCtrl::MENU_GROUP);
 85	}
 86	
 87	childSetAction("OK", onBtnOK, this);
 88
 89	childSetAction("Cancel", onBtnCancel, this);
 90
 91	setDefaultBtn("OK");
 92
 93	getChildView("OK")->setEnabled(TRUE);
 94
 95	return TRUE;
 96}
 97
 98void LLFloaterGroupPicker::removeNoneOption()
 99{
100	// Remove group "none" from list. Group "none" is added in init_group_list(). 
101	// Some UI elements use group "none", we need to manually delete it here.
102	// Group "none" ID is LLUUID:null.
103	LLCtrlListInterface* group_list = getChild<LLScrollListCtrl>("group list")->getListInterface();
104	if(group_list)
105	{
106		group_list->selectByValue(LLUUID::null);
107		group_list->operateOnSelection(LLCtrlListInterface::OP_DELETE);
108	}
109}
110
111
112void LLFloaterGroupPicker::onBtnOK(void* userdata)
113{
114	LLFloaterGroupPicker* self = (LLFloaterGroupPicker*)userdata;
115	if(self) self->ok();
116}
117
118void LLFloaterGroupPicker::onBtnCancel(void* userdata)
119{
120	LLFloaterGroupPicker* self = (LLFloaterGroupPicker*)userdata;
121	if(self) self->closeFloater();
122}
123
124
125void LLFloaterGroupPicker::ok()
126{
127	LLCtrlListInterface *group_list = childGetListInterface("group list");
128	LLUUID group_id;
129	if (group_list)
130	{
131		group_id = group_list->getCurrentID();
132	}
133	mGroupSelectSignal(group_id);
134
135	closeFloater();
136}
137
138///----------------------------------------------------------------------------
139/// Class LLPanelGroups
140///----------------------------------------------------------------------------
141
142//LLEventListener
143//virtual
144bool LLPanelGroups::handleEvent(LLPointer<LLEvent> event, const LLSD& userdata)
145{
146	if (event->desc() == "new group")
147	{
148		reset();
149		return true;
150	}
151	return false;
152}
153
154// Default constructor
155LLPanelGroups::LLPanelGroups() :
156	LLPanel()
157{
158	gAgent.addListener(this, "new group");
159}
160
161LLPanelGroups::~LLPanelGroups()
162{
163	gAgent.removeListener(this);
164}
165
166// clear the group list, and get a fresh set of info.
167void LLPanelGroups::reset()
168{
169	LLCtrlListInterface *group_list = childGetListInterface("group list");
170	if (group_list)
171	{
172		group_list->operateOnAll(LLCtrlListInterface::OP_DELETE);
173	}
174	getChild<LLUICtrl>("groupcount")->setTextArg("[COUNT]", llformat("%d",gAgent.mGroups.count()));
175	getChild<LLUICtrl>("groupcount")->setTextArg("[MAX]", llformat("%d",gMaxAgentGroups));
176
177	init_group_list(getChild<LLScrollListCtrl>("group list"), gAgent.getGroupID());
178	enableButtons();
179}
180
181BOOL LLPanelGroups::postBuild()
182{
183	childSetCommitCallback("group list", onGroupList, this);
184
185	getChild<LLUICtrl>("groupcount")->setTextArg("[COUNT]", llformat("%d",gAgent.mGroups.count()));
186	getChild<LLUICtrl>("groupcount")->setTextArg("[MAX]", llformat("%d",gMaxAgentGroups));
187
188	LLScrollListCtrl *list = getChild<LLScrollListCtrl>("group list");
189	if (list)
190	{
191		init_group_list(list, gAgent.getGroupID());
192		list->setDoubleClickCallback(onBtnIM, this);
193		list->setContextMenu(LLScrollListCtrl::MENU_GROUP);
194	}
195
196	childSetAction("Activate", onBtnActivate, this);
197
198	childSetAction("Info", onBtnInfo, this);
199
200	childSetAction("IM", onBtnIM, this);
201
202	childSetAction("Leave", onBtnLeave, this);
203
204	childSetAction("Create", onBtnCreate, this);
205
206	childSetAction("Search...", onBtnSearch, this);
207
208	setDefaultBtn("IM");
209
210	reset();
211
212	return TRUE;
213}
214
215void LLPanelGroups::enableButtons()
216{
217	LLCtrlListInterface *group_list = childGetListInterface("group list");
218	LLUUID group_id;
219	if (group_list)
220	{
221		group_id = group_list->getCurrentID();
222	}
223
224	if(group_id != gAgent.getGroupID())
225	{
226		getChildView("Activate")->setEnabled(TRUE);
227	}
228	else
229	{
230		getChildView("Activate")->setEnabled(FALSE);
231	}
232	if (group_id.notNull())
233	{
234		getChildView("Info")->setEnabled(TRUE);
235		getChildView("IM")->setEnabled(TRUE);
236		getChildView("Leave")->setEnabled(TRUE);
237	}
238	else
239	{
240		getChildView("Info")->setEnabled(FALSE);
241		getChildView("IM")->setEnabled(FALSE);
242		getChildView("Leave")->setEnabled(FALSE);
243	}
244	getChildView("Create")->setEnabled(gAgent.canJoinGroups());
245}
246
247
248void LLPanelGroups::onBtnCreate(void* userdata)
249{
250	LLPanelGroups* self = (LLPanelGroups*)userdata;
251	if(self) self->create();
252}
253
254void LLPanelGroups::onBtnActivate(void* userdata)
255{
256	LLPanelGroups* self = (LLPanelGroups*)userdata;
257	if(self) self->activate();
258}
259
260void LLPanelGroups::onBtnInfo(void* userdata)
261{
262	LLPanelGroups* self = (LLPanelGroups*)userdata;
263	if(self) self->info();
264}
265
266void LLPanelGroups::onBtnIM(void* userdata)
267{
268	LLPanelGroups* self = (LLPanelGroups*)userdata;
269	if(self) self->startIM();
270}
271
272void LLPanelGroups::onBtnLeave(void* userdata)
273{
274	LLPanelGroups* self = (LLPanelGroups*)userdata;
275	if(self) self->leave();
276}
277
278void LLPanelGroups::onBtnSearch(void* userdata)
279{
280	LLPanelGroups* self = (LLPanelGroups*)userdata;
281	if(self) self->search();
282}
283
284void LLPanelGroups::create()
285{
286	LLGroupActions::createGroup();
287}
288
289void LLPanelGroups::activate()
290{
291	LLCtrlListInterface *group_list = childGetListInterface("group list");
292	LLUUID group_id;
293	if (group_list)
294	{
295		group_id = group_list->getCurrentID();
296	}
297	LLGroupActions::activate(group_id);
298}
299
300void LLPanelGroups::info()
301{
302	LLCtrlListInterface *group_list = childGetListInterface("group list");
303	LLUUID group_id;
304	if (group_list && (group_id = group_list->getCurrentID()).notNull())
305	{
306		LLGroupActions::show(group_id);
307	}
308}
309
310void LLPanelGroups::startIM()
311{
312	LLCtrlListInterface *group_list = childGetListInterface("group list");
313	LLUUID group_id;
314
315	if (group_list && (group_id = group_list->getCurrentID()).notNull())
316	{
317		LLGroupActions::startIM(group_id);
318	}
319}
320
321void LLPanelGroups::leave()
322{
323	LLCtrlListInterface *group_list = childGetListInterface("group list");
324	LLUUID group_id;
325	if (group_list && (group_id = group_list->getCurrentID()).notNull())
326	{
327		LLGroupActions::leave(group_id);
328	}
329}
330
331void LLPanelGroups::search()
332{
333	LLGroupActions::search();
334}
335
336void LLPanelGroups::onGroupList(LLUICtrl* ctrl, void* userdata)
337{
338	LLPanelGroups* self = (LLPanelGroups*)userdata;
339	if(self) self->enableButtons();
340}
341
342void init_group_list(LLScrollListCtrl* group_list, const LLUUID& highlight_id, U64 powers_mask)
343{
344	S32 count = gAgent.mGroups.count();
345	LLUUID id;
346	if (!group_list) return;
347
348	group_list->operateOnAll(LLCtrlListInterface::OP_DELETE);
349
350	for(S32 i = 0; i < count; ++i)
351	{
352		id = gAgent.mGroups.get(i).mID;
353		LLGroupData* group_datap = &gAgent.mGroups.get(i);
354		if ((powers_mask == GP_ALL_POWERS) || ((group_datap->mPowers & powers_mask) != 0))
355		{
356			std::string style = "NORMAL";
357			if(highlight_id == id)
358			{
359				style = "BOLD";
360			}
361
362			LLSD element;
363			element["id"] = id;
364			element["columns"][0]["column"] = "name";
365			element["columns"][0]["value"] = group_datap->mName;
366			element["columns"][0]["font"]["name"] = "SANSSERIF";
367			element["columns"][0]["font"]["style"] = style;
368
369			group_list->addElement(element);
370		}
371	}
372
373	group_list->sortOnce(0, TRUE);
374
375	// add "none" to list at top
376	{
377		std::string style = "NORMAL";
378		if (highlight_id.isNull())
379		{
380			style = "BOLD";
381		}
382		LLSD element;
383		element["id"] = LLUUID::null;
384		element["columns"][0]["column"] = "name";
385		element["columns"][0]["value"] = LLTrans::getString("GroupsNone");
386		element["columns"][0]["font"]["name"] = "SANSSERIF";
387		element["columns"][0]["font"]["style"] = style;
388
389		group_list->addElement(element, ADD_TOP);
390	}
391
392	group_list->selectByValue(highlight_id);
393}
394