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
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
|
/**
* @file llfloaterfriends.cpp
* @author Phoenix
* @date 2005-01-13
* @brief Implementation of the friends floater
*
* $LicenseInfo:firstyear=2005&license=viewergpl$
*
* Copyright (c) 2005-2008, Linden Research, Inc.
*
* Second Life Viewer Source Code
* The source code in this file ("Source Code") is provided by Linden Lab
* to you under the terms of the GNU General Public License, version 2.0
* ("GPL"), unless you have obtained a separate licensing agreement
* ("Other License"), formally executed by you and Linden Lab. Terms of
* the GPL can be found in doc/GPL-license.txt in this distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
*
* There are special exceptions to the terms and conditions of the GPL as
* it is applied to this Source Code. View the full text of the exception
* in the file doc/FLOSS-exception.txt in this software distribution, or
* online at http://secondlifegrid.net/programs/open_source/licensing/flossexception
*
* By copying, modifying or distributing this software, you acknowledge
* that you have read and understood your obligations described above,
* and agree to abide by those obligations.
*
* ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
* WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
* COMPLETENESS OR PERFORMANCE.
* $/LicenseInfo$
*/
#include "llviewerprecompiledheaders.h"
#include "llfloaterfriends.h"
#include <sstream>
#include "lldir.h"
#include "llagent.h"
#include "llfloateravatarpicker.h"
#include "llviewerwindow.h"
#include "llbutton.h"
#include "llcallingcard.h"
#include "llfloateravatarinfo.h"
#include "llinventorymodel.h"
#include "llnamelistctrl.h"
#include "llnotify.h"
#include "llresmgr.h"
#include "llimview.h"
#include "llvieweruictrlfactory.h"
#include "llmenucommands.h"
#include "llviewercontrol.h"
#include "llviewermessage.h"
#include "lltimer.h"
#include "lltextbox.h"
//Maximum number of people you can select to do an operation on at once.
#define MAX_FRIEND_SELECT 20
#define RIGHTS_CHANGE_TIMEOUT 5.0
#define OBSERVER_TIMEOUT 0.5
// simple class to observe the calling cards.
class LLLocalFriendsObserver : public LLFriendObserver, public LLEventTimer
{
public:
LLLocalFriendsObserver(LLPanelFriends* floater) : mFloater(floater), LLEventTimer(OBSERVER_TIMEOUT)
{
mEventTimer.stop();
}
virtual ~LLLocalFriendsObserver()
{
mFloater = NULL;
}
virtual void changed(U32 mask)
{
// events can arrive quickly in bulk - we need not process EVERY one of them -
// so we wait a short while to let others pile-in, and process them in aggregate.
mEventTimer.start();
mEventTimer.reset();
// save-up all the mask-bits which have come-in
mMask |= mask;
}
virtual BOOL tick()
{
mFloater->updateFriends(mMask);
mEventTimer.stop();
mMask = 0;
return FALSE;
}
protected:
LLPanelFriends* mFloater;
U32 mMask;
};
LLPanelFriends::LLPanelFriends() :
LLPanel(),
LLEventTimer(1000000),
mObserver(NULL),
mShowMaxSelectWarning(TRUE),
mAllowRightsChange(TRUE),
mNumRightsChanged(0)
{
mEventTimer.stop();
mObserver = new LLLocalFriendsObserver(this);
LLAvatarTracker::instance().addObserver(mObserver);
}
LLPanelFriends::~LLPanelFriends()
{
LLAvatarTracker::instance().removeObserver(mObserver);
delete mObserver;
}
BOOL LLPanelFriends::tick()
{
mEventTimer.stop();
mPeriod = 1000000;
mAllowRightsChange = TRUE;
updateFriends(LLFriendObserver::ADD);
return FALSE;
}
void LLPanelFriends::updateFriends(U32 changed_mask)
{
LLUUID selected_id;
LLCtrlListInterface *friends_list = childGetListInterface("friend_list");
if (!friends_list) return;
LLCtrlScrollInterface *friends_scroll = childGetScrollInterface("friend_list");
if (!friends_scroll) return;
// We kill the selection warning, otherwise we'll spam with warning popups
// if the maximum amount of friends are selected
mShowMaxSelectWarning = false;
LLDynamicArray<LLUUID> selected_friends = getSelectedIDs();
if(changed_mask & (LLFriendObserver::ADD | LLFriendObserver::REMOVE | LLFriendObserver::ONLINE))
{
refreshNames();
}
else if(changed_mask & LLFriendObserver::POWERS)
{
--mNumRightsChanged;
if(mNumRightsChanged > 0)
{
mPeriod = RIGHTS_CHANGE_TIMEOUT;
mEventTimer.start();
mEventTimer.reset();
mAllowRightsChange = FALSE;
}
else
{
tick();
}
}
if(selected_friends.size() > 0)
{
// only non-null if friends was already found. This may fail,
// but we don't really care here, because refreshUI() will
// clean up the interface.
friends_list->setCurrentByID(selected_id);
for(LLDynamicArray<LLUUID>::iterator itr = selected_friends.begin(); itr != selected_friends.end(); ++itr)
{
friends_list->setSelectedByValue(*itr, true);
}
}
refreshUI();
mShowMaxSelectWarning = true;
}
// virtual
BOOL LLPanelFriends::postBuild()
{
mFriendsList = LLUICtrlFactory::getScrollListByName(this, "friend_list");
mFriendsList->setMaxSelectable(MAX_FRIEND_SELECT);
mFriendsList->setMaximumSelectCallback(onMaximumSelect);
mFriendsList->setCommitOnSelectionChange(TRUE);
childSetCommitCallback("friend_list", onSelectName, this);
childSetDoubleClickCallback("friend_list", onClickIM);
refreshNames();
childSetAction("im_btn", onClickIM, this);
childSetAction("profile_btn", onClickProfile, this);
childSetAction("offer_teleport_btn", onClickOfferTeleport, this);
childSetAction("pay_btn", onClickPay, this);
childSetAction("add_btn", onClickAddFriend, this);
childSetAction("remove_btn", onClickRemove, this);
setDefaultBtn("im_btn");
updateFriends(LLFriendObserver::ADD);
refreshUI();
// primary sort = online status, secondary sort = name
mFriendsList->sortByColumn("friend_name", TRUE);
mFriendsList->sortByColumn("icon_online_status", TRUE);
return TRUE;
}
void LLPanelFriends::addFriend(const std::string& name, const LLUUID& agent_id)
{
LLAvatarTracker& at = LLAvatarTracker::instance();
const LLRelationship* relationInfo = at.getBuddyInfo(agent_id);
if(!relationInfo) return;
BOOL online = relationInfo->isOnline();
LLSD element;
element["id"] = agent_id;
element["columns"][LIST_FRIEND_NAME]["column"] = "friend_name";
element["columns"][LIST_FRIEND_NAME]["value"] = name.c_str();
element["columns"][LIST_FRIEND_NAME]["font"] = "SANSSERIF";
element["columns"][LIST_FRIEND_NAME]["font-style"] = "NORMAL";
element["columns"][LIST_ONLINE_STATUS]["column"] = "icon_online_status";
element["columns"][LIST_ONLINE_STATUS]["type"] = "icon";
if (online)
{
element["columns"][LIST_FRIEND_NAME]["font-style"] = "BOLD";
element["columns"][LIST_ONLINE_STATUS]["value"] = gViewerArt.getString("icon_avatar_online.tga");
}
element["columns"][LIST_VISIBLE_ONLINE]["column"] = "icon_visible_online";
element["columns"][LIST_VISIBLE_ONLINE]["type"] = "checkbox";
element["columns"][LIST_VISIBLE_ONLINE]["value"] = relationInfo->isRightGrantedTo(LLRelationship::GRANT_ONLINE_STATUS);
element["columns"][LIST_VISIBLE_MAP]["column"] = "icon_visible_map";
element["columns"][LIST_VISIBLE_MAP]["type"] = "checkbox";
element["columns"][LIST_VISIBLE_MAP]["value"] = relationInfo->isRightGrantedTo(LLRelationship::GRANT_MAP_LOCATION);
element["columns"][LIST_EDIT_MINE]["column"] = "icon_edit_mine";
element["columns"][LIST_EDIT_MINE]["type"] = "checkbox";
element["columns"][LIST_EDIT_MINE]["value"] = relationInfo->isRightGrantedTo(LLRelationship::GRANT_MODIFY_OBJECTS);
element["columns"][LIST_EDIT_THEIRS]["column"] = "icon_edit_theirs";
element["columns"][LIST_EDIT_THEIRS]["type"] = "checkbox";
element["columns"][LIST_EDIT_THEIRS]["enabled"] = "";
element["columns"][LIST_EDIT_THEIRS]["value"] = relationInfo->isRightGrantedFrom(LLRelationship::GRANT_MODIFY_OBJECTS);
element["columns"][LIST_FRIEND_UPDATE_GEN]["column"] = "friend_last_update_generation";
element["columns"][LIST_FRIEND_UPDATE_GEN]["value"] = relationInfo->getChangeSerialNum();
mFriendsList->addElement(element, ADD_BOTTOM);
}
// propagate actual relationship to UI
void LLPanelFriends::updateFriendItem(LLScrollListItem* itemp, const LLRelationship* info)
{
if (!itemp) return;
if (!info) return;
itemp->getColumn(LIST_ONLINE_STATUS)->setValue(info->isOnline() ? gViewerArt.getString("icon_avatar_online.tga") : LLString());
// render name of online friends in bold text
((LLScrollListText*)itemp->getColumn(LIST_FRIEND_NAME))->setFontStyle(info->isOnline() ? LLFontGL::BOLD : LLFontGL::NORMAL);
itemp->getColumn(LIST_VISIBLE_ONLINE)->setValue(info->isRightGrantedTo(LLRelationship::GRANT_ONLINE_STATUS));
itemp->getColumn(LIST_VISIBLE_MAP)->setValue(info->isRightGrantedTo(LLRelationship::GRANT_MAP_LOCATION));
itemp->getColumn(LIST_EDIT_MINE)->setValue(info->isRightGrantedTo(LLRelationship::GRANT_MODIFY_OBJECTS));
itemp->getColumn(LIST_FRIEND_UPDATE_GEN)->setValue(info->getChangeSerialNum());
// enable this item, in case it was disabled after user input
itemp->setEnabled(TRUE);
// changed item in place, need to request sort
mFriendsList->sortItems();
}
void LLPanelFriends::refreshRightsChangeList()
{
LLDynamicArray<LLUUID> friends = getSelectedIDs();
S32 num_selected = friends.size();
bool can_offer_teleport = num_selected >= 1;
bool selected_friends_online = true;
LLTextBox* processing_label = LLUICtrlFactory::getTextBoxByName(this, "process_rights_label");
if(!mAllowRightsChange)
{
if(processing_label)
{
processing_label->setVisible(true);
// ignore selection for now
friends.clear();
num_selected = 0;
}
}
else if(processing_label)
{
processing_label->setVisible(false);
}
const LLRelationship* friend_status = NULL;
for(LLDynamicArray<LLUUID>::iterator itr = friends.begin(); itr != friends.end(); ++itr)
{
friend_status = LLAvatarTracker::instance().getBuddyInfo(*itr);
if (friend_status)
{
if(!friend_status->isOnline())
{
can_offer_teleport = false;
selected_friends_online = false;
}
}
else // missing buddy info, don't allow any operations
{
can_offer_teleport = false;
}
}
if (num_selected == 0) // nothing selected
{
childSetEnabled("im_btn", FALSE);
childSetEnabled("offer_teleport_btn", FALSE);
}
else // we have at least one friend selected...
{
// only allow IMs to groups when everyone in the group is online
// to be consistent with context menus in inventory and because otherwise
// offline friends would be silently dropped from the session
childSetEnabled("im_btn", selected_friends_online || num_selected == 1);
childSetEnabled("offer_teleport_btn", can_offer_teleport);
}
}
struct SortFriendsByID
{
bool SortFriendsByID::operator() (const LLScrollListItem* const a, const LLScrollListItem* const b) const
{
return a->getValue().asUUID() < b->getValue().asUUID();
}
};
void LLPanelFriends::refreshNames()
{
LLDynamicArray<LLUUID> selected_ids = getSelectedIDs();
S32 pos = mFriendsList->getScrollPos();
// get all buddies we know about
LLAvatarTracker::buddy_map_t all_buddies;
LLAvatarTracker::instance().copyBuddyList(all_buddies);
// get all friends in list and sort by UUID
std::vector<LLScrollListItem*> items = mFriendsList->getAllData();
std::sort(items.begin(), items.end(), SortFriendsByID());
std::vector<LLScrollListItem*>::iterator item_it = items.begin();
std::vector<LLScrollListItem*>::iterator item_end = items.end();
LLAvatarTracker::buddy_map_t::iterator buddy_it;
for (buddy_it = all_buddies.begin() ; buddy_it != all_buddies.end(); ++buddy_it)
{
// erase any items that reflect residents who are no longer buddies
while(item_it != item_end && buddy_it->first > (*item_it)->getValue().asUUID())
{
mFriendsList->deleteItems((*item_it)->getValue());
++item_it;
}
// update existing friends with new info
if (item_it != item_end && buddy_it->first == (*item_it)->getValue().asUUID())
{
const LLRelationship* info = buddy_it->second;
if (!info)
{
++item_it;
continue;
}
S32 last_change_generation = (*item_it)->getColumn(LIST_FRIEND_UPDATE_GEN)->getValue().asInteger();
if (last_change_generation < info->getChangeSerialNum())
{
// update existing item in UI
updateFriendItem(mFriendsList->getItem(buddy_it->first), info);
}
++item_it;
}
// add new friend to list
else
{
const LLUUID& buddy_id = buddy_it->first;
char first_name[DB_FIRST_NAME_BUF_SIZE]; /*Flawfinder: ignore*/
char last_name[DB_LAST_NAME_BUF_SIZE]; /*Flawfinder: ignore*/
gCacheName->getName(buddy_id, first_name, last_name);
std::ostringstream fullname;
fullname << first_name << " " << last_name;
addFriend(fullname.str(), buddy_id);
}
}
mFriendsList->selectMultiple(selected_ids);
mFriendsList->setScrollPos(pos);
}
void LLPanelFriends::refreshUI()
{
BOOL single_selected = FALSE;
BOOL multiple_selected = FALSE;
int num_selected = mFriendsList->getAllSelected().size();
if(num_selected > 0)
{
single_selected = TRUE;
if(num_selected > 1)
{
childSetText("friend_name_label", childGetText("Multiple"));
multiple_selected = TRUE;
}
else
{
childSetText("friend_name_label", mFriendsList->getFirstSelected()->getColumn(LIST_FRIEND_NAME)->getValue().asString() + "...");
}
}
else
{
childSetText("friend_name_label", LLString::null);
}
//Options that can only be performed with one friend selected
childSetEnabled("profile_btn", single_selected && !multiple_selected);
childSetEnabled("pay_btn", single_selected && !multiple_selected);
//Options that can be performed with up to MAX_FRIEND_SELECT friends selected
//(single_selected will always be true in this situations)
childSetEnabled("remove_btn", single_selected);
childSetEnabled("im_btn", single_selected);
childSetEnabled("friend_rights", single_selected);
refreshRightsChangeList();
}
LLDynamicArray<LLUUID> LLPanelFriends::getSelectedIDs()
{
LLUUID selected_id;
LLDynamicArray<LLUUID> friend_ids;
std::vector<LLScrollListItem*> selected = mFriendsList->getAllSelected();
for(std::vector<LLScrollListItem*>::iterator itr = selected.begin(); itr != selected.end(); ++itr)
{
friend_ids.push_back((*itr)->getUUID());
}
return friend_ids;
}
// static
void LLPanelFriends::onSelectName(LLUICtrl* ctrl, void* user_data)
{
LLPanelFriends* panelp = (LLPanelFriends*)user_data;
if(panelp)
{
panelp->refreshUI();
// check to see if rights have changed
panelp->applyRightsToFriends();
}
}
//static
void LLPanelFriends::onMaximumSelect(void* user_data)
{
LLString::format_map_t args;
args["[MAX_SELECT]"] = llformat("%d", MAX_FRIEND_SELECT);
LLNotifyBox::showXml("MaxListSelectMessage", args);
};
// static
void LLPanelFriends::onClickProfile(void* user_data)
{
LLPanelFriends* panelp = (LLPanelFriends*)user_data;
//llinfos << "LLPanelFriends::onClickProfile()" << llendl;
LLDynamicArray<LLUUID> ids = panelp->getSelectedIDs();
if(ids.size() > 0)
{
LLUUID agent_id = ids[0];
BOOL online;
online = LLAvatarTracker::instance().isBuddyOnline(agent_id);
LLFloaterAvatarInfo::showFromFriend(agent_id, online);
}
}
// static
void LLPanelFriends::onClickIM(void* user_data)
{
LLPanelFriends* panelp = (LLPanelFriends*)user_data;
//llinfos << "LLPanelFriends::onClickIM()" << llendl;
LLDynamicArray<LLUUID> ids = panelp->getSelectedIDs();
if(ids.size() > 0)
{
if(ids.size() == 1)
{
LLUUID agent_id = ids[0];
const LLRelationship* info = LLAvatarTracker::instance().getBuddyInfo(agent_id);
char first[DB_FIRST_NAME_BUF_SIZE]; /* Flawfinder: ignore */
char last[DB_LAST_NAME_BUF_SIZE]; /* Flawfinder: ignore */
if(info && gCacheName->getName(agent_id, first, last))
{
char buffer[MAX_STRING]; /* Flawfinder: ignore */
snprintf(buffer, MAX_STRING, "%s %s", first, last); /* Flawfinder: ignore */
gIMMgr->setFloaterOpen(TRUE);
gIMMgr->addSession(
buffer,
IM_NOTHING_SPECIAL,
agent_id);
}
}
else
{
gIMMgr->setFloaterOpen(TRUE);
gIMMgr->addSession("Friends Conference",
IM_SESSION_CONFERENCE_START,
ids[0],
ids);
}
make_ui_sound("UISndStartIM");
}
}
// static
void LLPanelFriends::requestFriendship(const LLUUID& target_id, const LLString& target_name)
{
// HACK: folder id stored as "message"
LLUUID calling_card_folder_id = gInventory.findCategoryUUIDForType(LLAssetType::AT_CALLINGCARD);
std::string message = calling_card_folder_id.asString();
send_improved_im(target_id,
target_name.c_str(),
message.c_str(),
IM_ONLINE,
IM_FRIENDSHIP_OFFERED);
}
struct LLAddFriendData
{
LLUUID mID;
std::string mName;
};
// static
void LLPanelFriends::callbackAddFriend(S32 option, void* data)
{
LLAddFriendData* add = (LLAddFriendData*)data;
if (option == 0)
{
requestFriendship(add->mID, add->mName);
}
delete add;
}
// static
void LLPanelFriends::onPickAvatar(const std::vector<std::string>& names,
const std::vector<LLUUID>& ids,
void* )
{
if (names.empty()) return;
if (ids.empty()) return;
requestFriendshipDialog(ids[0], names[0]);
}
// static
void LLPanelFriends::requestFriendshipDialog(const LLUUID& id,
const std::string& name)
{
if(id == gAgentID)
{
LLNotifyBox::showXml("AddSelfFriend");
return;
}
LLAddFriendData* data = new LLAddFriendData();
data->mID = id;
data->mName = name;
// TODO: accept a line of text with this dialog
LLString::format_map_t args;
args["[NAME]"] = name;
gViewerWindow->alertXml("AddFriend", args, callbackAddFriend, data);
}
// static
void LLPanelFriends::onClickAddFriend(void* user_data)
{
LLPanelFriends* panelp = (LLPanelFriends*)user_data;
LLFloater* root_floater = gFloaterView->getParentFloater(panelp);
LLFloaterAvatarPicker* picker = LLFloaterAvatarPicker::show(onPickAvatar, user_data, FALSE, TRUE);
if (root_floater)
{
root_floater->addDependentFloater(picker);
}
}
// static
void LLPanelFriends::onClickRemove(void* user_data)
{
LLPanelFriends* panelp = (LLPanelFriends*)user_data;
//llinfos << "LLPanelFriends::onClickRemove()" << llendl;
LLDynamicArray<LLUUID> ids = panelp->getSelectedIDs();
LLStringBase<char>::format_map_t args;
if(ids.size() > 0)
{
LLString msgType = "RemoveFromFriends";
if(ids.size() == 1)
{
LLUUID agent_id = ids[0];
char first[DB_FIRST_NAME_BUF_SIZE]; /*Flawfinder: ignore*/
char last[DB_LAST_NAME_BUF_SIZE]; /*Flawfinder: ignore*/
if(gCacheName->getName(agent_id, first, last))
{
args["[FIRST_NAME]"] = first;
args["[LAST_NAME]"] = last;
}
}
else
{
msgType = "RemoveMultipleFromFriends";
}
gViewerWindow->alertXml(msgType,
args,
&handleRemove,
(void*)new LLDynamicArray<LLUUID>(ids));
}
}
// static
void LLPanelFriends::onClickOfferTeleport(void* user_data)
{
LLPanelFriends* panelp = (LLPanelFriends*)user_data;
LLDynamicArray<LLUUID> ids = panelp->getSelectedIDs();
if(ids.size() > 0)
{
handle_lure(ids);
}
}
// static
void LLPanelFriends::onClickPay(void* user_data)
{
LLPanelFriends* panelp = (LLPanelFriends*)user_data;
LLDynamicArray<LLUUID> ids = panelp->getSelectedIDs();
if(ids.size() == 1)
{
handle_pay_by_id(ids[0]);
}
}
void LLPanelFriends::confirmModifyRights(rights_map_t& ids, EGrantRevoke command)
{
if (ids.empty()) return;
LLStringBase<char>::format_map_t args;
if(ids.size() > 0)
{
// copy map of ids onto heap
rights_map_t* rights = new rights_map_t(ids);
// package with panel pointer
std::pair<LLPanelFriends*, rights_map_t*>* user_data = new std::pair<LLPanelFriends*, rights_map_t*>(this, rights);
// for single friend, show their name
if(ids.size() == 1)
{
LLUUID agent_id = ids.begin()->first;
char first[DB_FIRST_NAME_BUF_SIZE]; /*Flawfinder: ignore*/
char last[DB_LAST_NAME_BUF_SIZE]; /*Flawfinder: ignore*/
if(gCacheName->getName(agent_id, first, last))
{
args["[FIRST_NAME]"] = first;
args["[LAST_NAME]"] = last;
}
if (command == GRANT)
{
gViewerWindow->alertXml("GrantModifyRights", args, modifyRightsConfirmation, user_data);
}
else
{
gViewerWindow->alertXml("RevokeModifyRights", args, modifyRightsConfirmation, user_data);
}
}
else
{
if (command == GRANT)
{
gViewerWindow->alertXml("GrantModifyRightsMultiple", args, modifyRightsConfirmation, user_data);
}
else
{
gViewerWindow->alertXml("RevokeModifyRightsMultiple", args, modifyRightsConfirmation, user_data);
}
}
}
}
// static
void LLPanelFriends::modifyRightsConfirmation(S32 option, void* user_data)
{
std::pair<LLPanelFriends*, rights_map_t*>* data = (std::pair<LLPanelFriends*, rights_map_t*>*)user_data;
LLPanelFriends* panelp = data->first;
if(panelp)
{
if(0 == option)
{
panelp->sendRightsGrant(*(data->second));
}
else
{
// need to resync view with model, since user cancelled operation
rights_map_t* rights = data->second;
rights_map_t::iterator rights_it;
for (rights_it = rights->begin(); rights_it != rights->end(); ++rights_it)
{
LLScrollListItem* itemp = panelp->mFriendsList->getItem(rights_it->first);
const LLRelationship* info = LLAvatarTracker::instance().getBuddyInfo(rights_it->first);
panelp->updateFriendItem(itemp, info);
}
}
panelp->refreshUI();
}
delete data->second;
delete data;
}
void LLPanelFriends::applyRightsToFriends()
{
BOOL rights_changed = FALSE;
// store modify rights separately for confirmation
rights_map_t rights_updates;
BOOL need_confirmation = FALSE;
EGrantRevoke confirmation_type = GRANT;
// this assumes that changes only happened to selected items
std::vector<LLScrollListItem*> selected = mFriendsList->getAllSelected();
for(std::vector<LLScrollListItem*>::iterator itr = selected.begin(); itr != selected.end(); ++itr)
{
LLUUID id = (*itr)->getValue();
const LLRelationship* buddy_relationship = LLAvatarTracker::instance().getBuddyInfo(id);
if (buddy_relationship == NULL) continue;
bool show_online_staus = (*itr)->getColumn(LIST_VISIBLE_ONLINE)->getValue().asBoolean();
bool show_map_location = (*itr)->getColumn(LIST_VISIBLE_MAP)->getValue().asBoolean();
bool allow_modify_objects = (*itr)->getColumn(LIST_EDIT_MINE)->getValue().asBoolean();
S32 rights = buddy_relationship->getRightsGrantedTo();
if(buddy_relationship->isRightGrantedTo(LLRelationship::GRANT_ONLINE_STATUS) != show_online_staus)
{
rights_changed = TRUE;
if(show_online_staus)
{
rights |= LLRelationship::GRANT_ONLINE_STATUS;
}
else
{
// ONLINE_STATUS necessary for MAP_LOCATION
rights &= ~LLRelationship::GRANT_ONLINE_STATUS;
rights &= ~LLRelationship::GRANT_MAP_LOCATION;
// propagate rights constraint to UI
(*itr)->getColumn(LIST_VISIBLE_MAP)->setValue(FALSE);
}
}
if(buddy_relationship->isRightGrantedTo(LLRelationship::GRANT_MAP_LOCATION) != show_map_location)
{
rights_changed = TRUE;
if(show_map_location)
{
// ONLINE_STATUS necessary for MAP_LOCATION
rights |= LLRelationship::GRANT_MAP_LOCATION;
rights |= LLRelationship::GRANT_ONLINE_STATUS;
(*itr)->getColumn(LIST_VISIBLE_ONLINE)->setValue(TRUE);
}
else
{
rights &= ~LLRelationship::GRANT_MAP_LOCATION;
}
}
// now check for change in modify object rights, which requires confirmation
if(buddy_relationship->isRightGrantedTo(LLRelationship::GRANT_MODIFY_OBJECTS) != allow_modify_objects)
{
rights_changed = TRUE;
need_confirmation = TRUE;
if(allow_modify_objects)
{
rights |= LLRelationship::GRANT_MODIFY_OBJECTS;
confirmation_type = GRANT;
}
else
{
rights &= ~LLRelationship::GRANT_MODIFY_OBJECTS;
confirmation_type = REVOKE;
}
}
if (rights_changed)
{
rights_updates.insert(std::make_pair(id, rights));
// disable these ui elements until response from server
// to avoid race conditions
(*itr)->setEnabled(FALSE);
}
}
// separately confirm grant and revoke of modify rights
if (need_confirmation)
{
confirmModifyRights(rights_updates, confirmation_type);
}
else
{
sendRightsGrant(rights_updates);
}
}
void LLPanelFriends::sendRightsGrant(rights_map_t& ids)
{
if (ids.empty()) return;
LLMessageSystem* msg = gMessageSystem;
// setup message header
msg->newMessageFast(_PREHASH_GrantUserRights);
msg->nextBlockFast(_PREHASH_AgentData);
msg->addUUID(_PREHASH_AgentID, gAgent.getID());
msg->addUUID(_PREHASH_SessionID, gAgent.getSessionID());
rights_map_t::iterator id_it;
rights_map_t::iterator end_it = ids.end();
for(id_it = ids.begin(); id_it != end_it; ++id_it)
{
msg->nextBlockFast(_PREHASH_Rights);
msg->addUUID(_PREHASH_AgentRelated, id_it->first);
msg->addS32(_PREHASH_RelatedRights, id_it->second);
}
mNumRightsChanged = ids.size();
gAgent.sendReliableMessage();
}
// static
void LLPanelFriends::handleRemove(S32 option, void* user_data)
{
LLDynamicArray<LLUUID>* ids = static_cast<LLDynamicArray<LLUUID>*>(user_data);
for(LLDynamicArray<LLUUID>::iterator itr = ids->begin(); itr != ids->end(); ++itr)
{
LLUUID id = (*itr);
const LLRelationship* ip = LLAvatarTracker::instance().getBuddyInfo(id);
if(ip)
{
switch(option)
{
case 0: // YES
if( ip->isRightGrantedTo(LLRelationship::GRANT_MODIFY_OBJECTS))
{
LLAvatarTracker::instance().empower(id, FALSE);
LLAvatarTracker::instance().notifyObservers();
}
LLAvatarTracker::instance().terminateBuddy(id);
LLAvatarTracker::instance().notifyObservers();
gInventory.addChangedMask(LLInventoryObserver::LABEL | LLInventoryObserver::CALLING_CARD, LLUUID::null);
gInventory.notifyObservers();
break;
case 1: // NO
default:
llinfos << "No removal performed." << llendl;
break;
}
}
}
delete ids;
}
|