aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/newview/llpanelgroupinvite.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/llpanelgroupinvite.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 'linden/indra/newview/llpanelgroupinvite.cpp')
-rw-r--r--linden/indra/newview/llpanelgroupinvite.cpp411
1 files changed, 411 insertions, 0 deletions
diff --git a/linden/indra/newview/llpanelgroupinvite.cpp b/linden/indra/newview/llpanelgroupinvite.cpp
new file mode 100644
index 0000000..bc0d8d1
--- /dev/null
+++ b/linden/indra/newview/llpanelgroupinvite.cpp
@@ -0,0 +1,411 @@
1/**
2 * @file llpanelgroupinvite.cpp
3 *
4 * Copyright (c) 2006-2007, Linden Research, Inc.
5 *
6 * The source code in this file ("Source Code") is provided by Linden Lab
7 * to you under the terms of the GNU General Public License, version 2.0
8 * ("GPL"), unless you have obtained a separate licensing agreement
9 * ("Other License"), formally executed by you and Linden Lab. Terms of
10 * the GPL can be found in doc/GPL-license.txt in this distribution, or
11 * online at http://secondlife.com/developers/opensource/gplv2
12 *
13 * There are special exceptions to the terms and conditions of the GPL as
14 * it is applied to this Source Code. View the full text of the exception
15 * in the file doc/FLOSS-exception.txt in this software distribution, or
16 * online at http://secondlife.com/developers/opensource/flossexception
17 *
18 * By copying, modifying or distributing this software, you acknowledge
19 * that you have read and understood your obligations described above,
20 * and agree to abide by those obligations.
21 *
22 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
23 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
24 * COMPLETENESS OR PERFORMANCE.
25 */
26
27#include "llviewerprecompiledheaders.h"
28
29#include "llpanelgroupinvite.h"
30
31#include "llagent.h"
32#include "llfloateravatarpicker.h"
33#include "llbutton.h"
34#include "llcombobox.h"
35#include "llgroupmgr.h"
36#include "llnamelistctrl.h"
37#include "llspinctrl.h"
38#include "llvieweruictrlfactory.h"
39
40class LLPanelGroupInvite::impl
41{
42public:
43 impl(const LLUUID& group_id);
44 ~impl();
45
46 void addUsers(const std::vector<std::string>& names,
47 const std::vector<LLUUID>& agent_ids);
48 void submitInvitations();
49 void addRoleNames(LLGroupMgrGroupData* gdatap);
50 void handleRemove();
51 void handleSelection();
52
53 static void callbackClickCancel(void* userdata);
54 static void callbackClickOK(void* userdata);
55 static void callbackClickAdd(void* userdata);
56 static void callbackClickRemove(void* userdata);
57 static void callbackSelect(LLUICtrl* ctrl, void* userdata);
58 static void callbackAddUsers(const std::vector<std::string>& names,
59 const std::vector<LLUUID>& agent_ids,
60 void* user_data);
61
62public:
63 LLUUID mGroupID;
64
65 LLNameListCtrl *mInvitees;
66 LLComboBox *mRoleNames;
67 LLButton *mRemoveButton;
68
69 void (*mCloseCallback)(void* data);
70
71 void* mCloseCallbackUserData;
72};
73
74
75LLPanelGroupInvite::impl::impl(const LLUUID& group_id)
76{
77 mGroupID = group_id;
78
79 mInvitees = NULL;
80 mRoleNames = NULL;
81 mRemoveButton = NULL;
82
83 mCloseCallback = NULL;
84 mCloseCallbackUserData = NULL;
85}
86
87LLPanelGroupInvite::impl::~impl()
88{
89}
90
91void LLPanelGroupInvite::impl::addUsers(const std::vector<std::string>& names,
92 const std::vector<LLUUID>& agent_ids)
93{
94 std::string name;
95 LLUUID id;
96
97 for (S32 i = 0; i < (S32)names.size(); i++)
98 {
99 name = names[i];
100 id = agent_ids[i];
101
102 // Make sure this agent isn't already in the list.
103 bool already_in_list = false;
104 std::vector<LLScrollListItem*> items = mInvitees->getAllData();
105 for (std::vector<LLScrollListItem*>::iterator iter = items.begin();
106 iter != items.end(); ++iter)
107 {
108 LLScrollListItem* item = *iter;
109 if (item->getUUID() == id)
110 {
111 already_in_list = true;
112 break;
113 }
114 }
115 if (already_in_list)
116 {
117 continue;
118 }
119
120 //add the name to the names list
121 const BOOL enabled = TRUE;
122 LLScrollListItem* row = new LLScrollListItem(
123 enabled, NULL, id);
124 row->addColumn(name.c_str(), LLFontGL::sSansSerif);
125 mInvitees->addItem(row);
126 }
127}
128
129void LLPanelGroupInvite::impl::submitInvitations()
130{
131 std::map<LLUUID, LLUUID> role_member_pairs;
132
133 // Default to everyone role.
134 LLUUID role_id = LLUUID::null;
135
136 if (mRoleNames)
137 {
138 role_id = mRoleNames->getCurrentID();
139 }
140
141 //loop over the users
142 std::vector<LLScrollListItem*> items = mInvitees->getAllData();
143 for (std::vector<LLScrollListItem*>::iterator iter = items.begin();
144 iter != items.end(); ++iter)
145 {
146 LLScrollListItem* item = *iter;
147 role_member_pairs[item->getUUID()] = role_id;
148 }
149
150 gGroupMgr->sendGroupMemberInvites(mGroupID, role_member_pairs);
151
152 //then close
153 (*mCloseCallback)(mCloseCallbackUserData);
154}
155
156void LLPanelGroupInvite::impl::addRoleNames(LLGroupMgrGroupData* gdatap)
157{
158 LLGroupMgrGroupData::member_iter agent_iter =
159 gdatap->mMembers.find(gAgent.getID());
160
161 //get the member data for the agent if it exists
162 if ( agent_iter != gdatap->mMembers.end() )
163 {
164 LLGroupMemberData* member_data = (*agent_iter).second;
165
166 //loop over the agent's roles in the group
167 //then add those roles to the list of roles that the agent
168 //can invite people to be
169 if ( member_data && mRoleNames)
170 {
171 //if the user is the owner then we add
172 //all of the roles in the group
173 //else if they have the add to roles power
174 //we add every role but owner,
175 //else if they have the limited add to roles power
176 //we add every role the user is in
177 //else we just add to everyone
178 bool is_owner = member_data->isInRole(gdatap->mOwnerRole);
179 bool can_assign_any = gAgent.hasPowerInGroup(mGroupID,
180 GP_ROLE_ASSIGN_MEMBER);
181 bool can_assign_limited = gAgent.hasPowerInGroup(mGroupID,
182 GP_ROLE_ASSIGN_MEMBER_LIMITED);
183
184 LLGroupMgrGroupData::role_iter rit = gdatap->mRoles.begin();
185 LLGroupMgrGroupData::role_iter end = gdatap->mRoles.end();
186
187 //populate the role list
188 for ( ; rit != end; ++rit)
189 {
190 LLUUID role_id = (*rit).first;
191 LLRoleData rd;
192 if ( gdatap->getRoleData(role_id,rd) )
193 {
194 // Owners can add any role.
195 if ( is_owner
196 // Even 'can_assign_any' can't add owner role.
197 || (can_assign_any && role_id != gdatap->mOwnerRole)
198 // Add all roles user is in
199 || (can_assign_limited && member_data->isInRole(role_id))
200 // Everyone role.
201 || role_id == LLUUID::null )
202 {
203 mRoleNames->add(rd.mRoleName,
204 role_id,
205 ADD_BOTTOM);
206 }
207 }
208 }
209 }//end if member data is not null
210 }//end if agent is in the group
211}
212
213//static
214void LLPanelGroupInvite::impl::callbackClickAdd(void* userdata)
215{
216 LLPanelGroupInvite* panelp = (LLPanelGroupInvite*) userdata;
217
218 if ( panelp )
219 {
220 //Right now this is hard coded with some knowledge that it is part
221 //of a floater since the avatar picker needs to be added as a dependent
222 //floater to the parent floater.
223 //Soon the avatar picker will be embedded into this panel
224 //instead of being it's own separate floater. But that is next week.
225 //This will do for now. -jwolk May 10, 2006
226 LLFloater* parentp;
227
228 parentp = gFloaterView->getParentFloater(panelp);
229 parentp->addDependentFloater(LLFloaterAvatarPicker::show(callbackAddUsers,
230 panelp->mImplementation,
231 TRUE));
232 }
233}
234
235//static
236void LLPanelGroupInvite::impl::callbackClickRemove(void* userdata)
237{
238 impl* selfp = (impl*) userdata;
239
240 if ( selfp ) selfp->handleRemove();
241}
242
243void LLPanelGroupInvite::impl::handleRemove()
244{
245 // Check if there is anything selected.
246 std::vector<LLScrollListItem*> selection =
247 mInvitees->getAllSelected();
248 if (selection.empty()) return;
249
250 // Remove all selected invitees.
251 mInvitees->deleteSelectedItems();
252 mRemoveButton->setEnabled(FALSE);
253}
254
255// static
256void LLPanelGroupInvite::impl::callbackSelect(
257 LLUICtrl* ctrl, void* userdata)
258{
259 impl* selfp = (impl*) userdata;
260 if ( selfp ) selfp->handleSelection();
261}
262
263void LLPanelGroupInvite::impl::handleSelection()
264{
265 // Check if there is anything selected.
266 std::vector<LLScrollListItem*> selection =
267 mInvitees->getAllSelected();
268 if (selection.empty())
269 {
270 mRemoveButton->setEnabled(FALSE);
271 }
272 else
273 {
274 mRemoveButton->setEnabled(TRUE);
275 }
276}
277
278void LLPanelGroupInvite::impl::callbackClickCancel(void* userdata)
279{
280 impl* selfp = (impl*) userdata;
281
282 if ( selfp )
283 {
284 (*(selfp->mCloseCallback))(selfp->mCloseCallbackUserData);
285 }
286}
287
288void LLPanelGroupInvite::impl::callbackClickOK(void* userdata)
289{
290 impl* selfp = (impl*) userdata;
291
292 if ( selfp ) selfp->submitInvitations();
293}
294
295//static
296void LLPanelGroupInvite::impl::callbackAddUsers(const std::vector<std::string>& names,
297 const std::vector<LLUUID>& ids,
298 void* user_data)
299{
300 impl* selfp = (impl*) user_data;
301
302 if ( selfp) selfp->addUsers(names, ids);
303}
304
305LLPanelGroupInvite::LLPanelGroupInvite(const std::string& name,
306 const LLUUID& group_id)
307 : LLPanel(name)
308{
309 mImplementation = new impl(group_id);
310
311 std::string panel_def_file;
312
313 // Pass on construction of this panel to the control factory.
314 gUICtrlFactory->buildPanel(this, "panel_group_invite.xml", &getFactoryMap());
315}
316
317LLPanelGroupInvite::~LLPanelGroupInvite()
318{
319 delete mImplementation;
320}
321
322void LLPanelGroupInvite::setCloseCallback(void (*close_callback)(void*),
323 void* data)
324{
325 mImplementation->mCloseCallback = close_callback;
326 mImplementation->mCloseCallbackUserData = data;
327}
328
329void LLPanelGroupInvite::clear()
330{
331 mImplementation->mInvitees->deleteAllItems();
332 mImplementation->mRoleNames->clear();
333 mImplementation->mRoleNames->removeall();
334}
335
336void LLPanelGroupInvite::update()
337{
338 LLGroupMgrGroupData* gdatap = gGroupMgr->getGroupData(mImplementation->mGroupID);
339
340 if (!gdatap || !gdatap->isRoleDataComplete())
341 {
342 gGroupMgr->sendGroupRoleDataRequest(mImplementation->mGroupID);
343 }
344 else
345 {
346 if ( mImplementation->mRoleNames )
347 {
348 mImplementation->mRoleNames->clear();
349 mImplementation->mRoleNames->removeall();
350
351 //add the role names and select the everybody role by default
352 mImplementation->addRoleNames(gdatap);
353 mImplementation->mRoleNames->setCurrentByID(LLUUID::null);
354 }
355 }
356}
357
358BOOL LLPanelGroupInvite::postBuild()
359{
360 BOOL recurse = TRUE;
361
362 mImplementation->mRoleNames = (LLComboBox*) getChildByName("role_name",
363 recurse);
364 mImplementation->mInvitees =
365 (LLNameListCtrl*) getChildByName("invitee_list", recurse);
366 if ( mImplementation->mInvitees )
367 {
368 mImplementation->mInvitees->setCallbackUserData(mImplementation);
369 mImplementation->mInvitees->setCommitOnSelectionChange(TRUE);
370 mImplementation->mInvitees->setCommitCallback(impl::callbackSelect);
371 }
372
373 LLButton* button = (LLButton*) getChildByName("add_button", recurse);
374 if ( button )
375 {
376 // default to opening avatarpicker automatically
377 // (*impl::callbackClickAdd)((void*)this);
378 button->setClickedCallback(impl::callbackClickAdd);
379 button->setCallbackUserData(this);
380 }
381
382 mImplementation->mRemoveButton =
383 (LLButton*) getChildByName("remove_button", recurse);
384 if ( mImplementation->mRemoveButton )
385 {
386 mImplementation->mRemoveButton->
387 setClickedCallback(impl::callbackClickRemove);
388 mImplementation->mRemoveButton->setCallbackUserData(mImplementation);
389 mImplementation->mRemoveButton->setEnabled(FALSE);
390 }
391
392 button = (LLButton*) getChildByName("ok_button", recurse);
393 if ( button )
394 {
395 button->setClickedCallback(impl::callbackClickOK);
396 button->setCallbackUserData(mImplementation);
397 }
398
399 button = (LLButton*) getChildByName("cancel_button", recurse);
400 if ( button )
401 {
402 button->setClickedCallback(impl::callbackClickCancel);
403 button->setCallbackUserData(mImplementation);
404 }
405
406 update();
407
408 return (mImplementation->mRoleNames &&
409 mImplementation->mInvitees &&
410 mImplementation->mRemoveButton);
411}