summaryrefslogtreecommitdiff
path: root/indra/newview/llpanelgroupbulk.cpp
blob: ed05a5c7d1c54d0ca45c8bab834eae792649af19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
/** 
* @file llpanelgroupbulk.cpp
* @brief Implementation of llpanelgroupbulk
* @author Baker@lindenlab.com
*
* $LicenseInfo:firstyear=2013&license=viewerlgpl$
* Second Life Viewer Source Code
* Copyright (C) 2013, Linden Research, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation;
* version 2.1 of the License only.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*
* Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
* $/LicenseInfo$
*/

#include "llviewerprecompiledheaders.h"

#include "llpanelgroupbulk.h"
#include "llpanelgroupbulkimpl.h"

#include "llagent.h"
#include "llavatarnamecache.h"
#include "llfloateravatarpicker.h"
#include "llbutton.h"
#include "llcallingcard.h"
#include "llcombobox.h"
#include "llgroupactions.h"
#include "llgroupmgr.h"
#include "llnamelistctrl.h"
#include "llnotificationsutil.h"
#include "llscrolllistitem.h"
#include "llspinctrl.h"
#include "lltextbox.h"
#include "llviewerobject.h"
#include "llviewerobjectlist.h"
#include "lluictrlfactory.h"
#include "llviewerwindow.h"


//////////////////////////////////////////////////////////////////////////
// Implementation of llpanelgroupbulkimpl.h functions
//////////////////////////////////////////////////////////////////////////
LLPanelGroupBulkImpl::LLPanelGroupBulkImpl(const LLUUID& group_id) :
	mGroupID(group_id),
	mBulkAgentList(NULL),
	mOKButton(NULL),
	mRemoveButton(NULL),
	mGroupName(NULL),
	mLoadingText(),
	mTooManySelected(),
	mCloseCallback(NULL),
	mCloseCallbackUserData(NULL),
	mAvatarNameCacheConnection(),
	mRoleNames(NULL),
	mOwnerWarning(),
	mAlreadyInGroup(),
	mConfirmedOwnerInvite(false)
{}

LLPanelGroupBulkImpl::~LLPanelGroupBulkImpl()
{
	if(mAvatarNameCacheConnection.connected())
	{
		mAvatarNameCacheConnection.disconnect();
	}
}

void LLPanelGroupBulkImpl::callbackClickAdd(void* userdata)
{
	LLPanelGroupBulk* panelp = (LLPanelGroupBulk*)userdata;

	if(panelp)
	{
		//Right now this is hard coded with some knowledge that it is part
		//of a floater since the avatar picker needs to be added as a dependent
		//floater to the parent floater.
		//Soon the avatar picker will be embedded into this panel
		//instead of being it's own separate floater.  But that is next week.
		//This will do for now. -jwolk May 10, 2006
		LLView* button = panelp->findChild<LLButton>("add_button");
		LLFloater* root_floater = gFloaterView->getParentFloater(panelp);
		LLFloaterAvatarPicker* picker = LLFloaterAvatarPicker::show(
			boost::bind(callbackAddUsers, _1, panelp->mImplementation), TRUE, FALSE, FALSE, root_floater->getName(), button);
		if(picker)
		{
			root_floater->addDependentFloater(picker);
		}
	}
}

void LLPanelGroupBulkImpl::callbackClickRemove(void* userdata)
{
	LLPanelGroupBulkImpl* selfp = (LLPanelGroupBulkImpl*)userdata;
	if (selfp) 
		selfp->handleRemove();
}

void LLPanelGroupBulkImpl::callbackClickCancel(void* userdata)
{
	LLPanelGroupBulkImpl* selfp = (LLPanelGroupBulkImpl*)userdata;
	if(selfp) 
		(*(selfp->mCloseCallback))(selfp->mCloseCallbackUserData);
}

void LLPanelGroupBulkImpl::callbackSelect(LLUICtrl* ctrl, void* userdata)
{
	LLPanelGroupBulkImpl* selfp = (LLPanelGroupBulkImpl*)userdata;
	if (selfp) 
		selfp->handleSelection();
}

void LLPanelGroupBulkImpl::callbackAddUsers(const uuid_vec_t& agent_ids, void* user_data)
{
	std::vector<std::string> names;
	for (S32 i = 0; i < (S32)agent_ids.size(); i++)
	{
		LLAvatarName av_name;
		if (LLAvatarNameCache::get(agent_ids[i], &av_name))
		{
			onAvatarNameCache(agent_ids[i], av_name, user_data);
		}
		else 
		{
			LLPanelGroupBulkImpl* selfp = (LLPanelGroupBulkImpl*) user_data;
			if (selfp)
			{
				if (selfp->mAvatarNameCacheConnection.connected())
				{
					selfp->mAvatarNameCacheConnection.disconnect();
				}
				// *TODO : Add a callback per avatar name being fetched.
				selfp->mAvatarNameCacheConnection = LLAvatarNameCache::get(agent_ids[i],boost::bind(onAvatarNameCache, _1, _2, user_data));
			}
		}
	}
}

void LLPanelGroupBulkImpl::onAvatarNameCache(const LLUUID& agent_id, const LLAvatarName& av_name, void* user_data)
{
	LLPanelGroupBulkImpl* selfp = (LLPanelGroupBulkImpl*) user_data;

	if (selfp)
	{
		if (selfp->mAvatarNameCacheConnection.connected())
		{
			selfp->mAvatarNameCacheConnection.disconnect();
		}
		std::vector<std::string> names;
		uuid_vec_t agent_ids;
		agent_ids.push_back(agent_id);
		names.push_back(av_name.getCompleteName());

		selfp->addUsers(names, agent_ids);
	}
}

void LLPanelGroupBulkImpl::handleRemove()
{
	std::vector<LLScrollListItem*> selection = mBulkAgentList->getAllSelected();
	if (selection.empty()) 
		return;

	mBulkAgentList->deleteSelectedItems();
	mRemoveButton->setEnabled(FALSE);

	if(	mOKButton && mOKButton->getEnabled() &&
		mBulkAgentList->isEmpty())
	{
		mOKButton->setEnabled(FALSE);
	}
}

void LLPanelGroupBulkImpl::handleSelection()
{
	std::vector<LLScrollListItem*> selection = mBulkAgentList->getAllSelected();
	if (selection.empty())
		mRemoveButton->setEnabled(FALSE);
	else
		mRemoveButton->setEnabled(TRUE);
}

void LLPanelGroupBulkImpl::addUsers(const std::vector<std::string>& names, const uuid_vec_t& agent_ids)
{
	std::string name;
	LLUUID id;

	for (S32 i = 0; i < (S32)names.size(); ++i)
	{
		name = names[i];
		id = agent_ids[i];

		// Make sure this agent isn't already in the list.
		bool already_in_list = false;
		std::vector<LLScrollListItem*> items = mBulkAgentList->getAllData();
		std::vector<LLScrollListItem*>::iterator iter = items.begin();
		for (; iter != items.end(); ++iter)
		{
			LLScrollListItem* item = *iter;
			if (item->getUUID() == id)
			{
				already_in_list = true;
				break;
			}
		}
		if (already_in_list)
		{
			continue;
		}

		//add the name to the names list
		LLSD row;
		row["id"] = id;
		row["columns"][0]["value"] = name;

		mBulkAgentList->addElement(row);
		
		// We've successfully added someone to the list.
		if(mOKButton && !mOKButton->getEnabled())
			mOKButton->setEnabled(TRUE);
	}
}

void LLPanelGroupBulkImpl::setGroupName(std::string name)
{
	if(mGroupName)
		mGroupName->setText(name);
}


LLPanelGroupBulk::LLPanelGroupBulk(const LLUUID& group_id) : 
	LLPanel(),
	mImplementation(new LLPanelGroupBulkImpl(group_id)),
	mPendingGroupPropertiesUpdate(false),
	mPendingRoleDataUpdate(false),
	mPendingMemberDataUpdate(false)
{}

LLPanelGroupBulk::~LLPanelGroupBulk()
{
	delete mImplementation;
}

void LLPanelGroupBulk::clear()
{
	if(mImplementation->mBulkAgentList)
		mImplementation->mBulkAgentList->deleteAllItems();
	
	if(mImplementation->mOKButton)
		mImplementation->mOKButton->setEnabled(FALSE);
}

void LLPanelGroupBulk::update()
{
	updateGroupName();
	updateGroupData();
}

void LLPanelGroupBulk::draw()
{
	LLPanel::draw();
	update();
}

void LLPanelGroupBulk::updateGroupName()
{
	LLGroupMgrGroupData* gdatap = LLGroupMgr::getInstance()->getGroupData(mImplementation->mGroupID);

	if(	gdatap &&
		gdatap->isGroupPropertiesDataComplete())
	{
		// Only do work if the current group name differs
		if(mImplementation->mGroupName->getText().compare(gdatap->mName) != 0)
			mImplementation->setGroupName(gdatap->mName);
	}
	else
	{
		mImplementation->setGroupName(mImplementation->mLoadingText);
	}
}

void LLPanelGroupBulk::updateGroupData()
{
	LLGroupMgrGroupData* gdatap = LLGroupMgr::getInstance()->getGroupData(mImplementation->mGroupID);
	if(!gdatap)
	{
		LL_WARNS("Groups") << "Unable to get group data for group " << mImplementation->mGroupID << LL_ENDL;
		return;
	}

	if(gdatap->isGroupPropertiesDataComplete())
		mPendingGroupPropertiesUpdate = false;
	else
	{
		if(!mPendingGroupPropertiesUpdate)
		{
			mPendingGroupPropertiesUpdate = true;
			LLGroupMgr::getInstance()->sendGroupPropertiesRequest(mImplementation->mGroupID);
		}
	}

	if(gdatap->isRoleDataComplete())
		mPendingRoleDataUpdate = false;
	else
	{
		if(!mPendingRoleDataUpdate)
		{
			mPendingRoleDataUpdate = true;
			LLGroupMgr::getInstance()->sendGroupRoleDataRequest(mImplementation->mGroupID);
		}
	}

	if(gdatap->isMemberDataComplete())
		mPendingMemberDataUpdate = false;
	else
	{
		if(!mPendingMemberDataUpdate)
		{
			mPendingMemberDataUpdate = true;
			LLGroupMgr::getInstance()->sendCapGroupMembersRequest(mImplementation->mGroupID);
		}
	}
}

void LLPanelGroupBulk::addUserCallback(const LLUUID& id, const LLAvatarName& av_name)
{
	std::vector<std::string> names;
	uuid_vec_t agent_ids;
	agent_ids.push_back(id);
	names.push_back(av_name.getAccountName());

	mImplementation->addUsers(names, agent_ids);
}

void LLPanelGroupBulk::setCloseCallback(void (*close_callback)(void*), void* data)
{
	mImplementation->mCloseCallback         = close_callback;
	mImplementation->mCloseCallbackUserData = data;
}

void LLPanelGroupBulk::addUsers(uuid_vec_t& agent_ids)
{
	std::vector<std::string> names;
	for (S32 i = 0; i < (S32)agent_ids.size(); i++)
	{
		std::string fullname;
		LLUUID agent_id = agent_ids[i];
		LLViewerObject* dest = gObjectList.findObject(agent_id);
		if(dest && dest->isAvatar())
		{
			LLNameValue* nvfirst = dest->getNVPair("FirstName");
			LLNameValue* nvlast = dest->getNVPair("LastName");
			if(nvfirst && nvlast)
			{
				fullname = LLCacheName::buildFullName(
					nvfirst->getString(), nvlast->getString());

			}
			if (!fullname.empty())
			{
				names.push_back(fullname);
			} 
			else 
			{
				llwarns << "llPanelGroupBulk: Selected avatar has no name: " << dest->getID() << llendl;
				names.push_back("(Unknown)");
			}
		}
		else
		{
			//looks like user try to invite offline friend
			//for offline avatar_id gObjectList.findObject() will return null
			//so we need to do this additional search in avatar tracker, see EXT-4732
			if (LLAvatarTracker::instance().isBuddy(agent_id))
			{
				LLAvatarName av_name;
				if (!LLAvatarNameCache::get(agent_id, &av_name))
				{
					// actually it should happen, just in case
					LLAvatarNameCache::get(LLUUID(agent_id), boost::bind(&LLPanelGroupBulk::addUserCallback, this, _1, _2));
					// for this special case!
					//when there is no cached name we should remove resident from agent_ids list to avoid breaking of sequence
					// removed id will be added in callback
					agent_ids.erase(agent_ids.begin() + i);
				}
				else
				{
					names.push_back(av_name.getAccountName());
				}
			}
		}
	}
	mImplementation->addUsers(names, agent_ids);
}