PageRenderTime 123ms CodeModel.GetById 31ms app.highlight 85ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llinspectavatar.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 859 lines | 612 code | 134 blank | 113 comment | 57 complexity | 0c9ec0a60eaddd46af83b72991949acc MD5 | raw file
  1/** 
  2 * @file llinspectavatar.cpp
  3 *
  4 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
  5 * Second Life Viewer Source Code
  6 * Copyright (C) 2010, Linden Research, Inc.
  7 * 
  8 * This library is free software; you can redistribute it and/or
  9 * modify it under the terms of the GNU Lesser General Public
 10 * License as published by the Free Software Foundation;
 11 * version 2.1 of the License only.
 12 * 
 13 * This library is distributed in the hope that it will be useful,
 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 16 * Lesser General Public License for more details.
 17 * 
 18 * You should have received a copy of the GNU Lesser General Public
 19 * License along with this library; if not, write to the Free Software
 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 21 * 
 22 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
 23 * $/LicenseInfo$
 24 */
 25
 26#include "llviewerprecompiledheaders.h"
 27
 28#include "llinspectavatar.h"
 29
 30// viewer files
 31#include "llagent.h"
 32#include "llagentdata.h"
 33#include "llavataractions.h"
 34#include "llavatarnamecache.h"
 35#include "llavatarpropertiesprocessor.h"
 36#include "llcallingcard.h"
 37#include "lldateutil.h"
 38#include "llfloaterreporter.h"
 39#include "llfloaterworldmap.h"
 40#include "llimview.h"
 41#include "llinspect.h"
 42#include "llmutelist.h"
 43#include "llpanelblockedlist.h"
 44#include "llstartup.h"
 45#include "llspeakers.h"
 46#include "llviewermenu.h"
 47#include "llvoiceclient.h"
 48#include "llviewerobjectlist.h"
 49#include "lltransientfloatermgr.h"
 50#include "llnotificationsutil.h"
 51
 52// Linden libraries
 53#include "llfloater.h"
 54#include "llfloaterreg.h"
 55#include "llmenubutton.h"
 56#include "lltextbox.h"
 57#include "lltoggleablemenu.h"
 58#include "lltooltip.h"	// positionViewNearMouse()
 59#include "lltrans.h"
 60#include "lluictrl.h"
 61
 62#include "llavatariconctrl.h"
 63
 64class LLFetchAvatarData;
 65
 66
 67//////////////////////////////////////////////////////////////////////////////
 68// LLInspectAvatar
 69//////////////////////////////////////////////////////////////////////////////
 70
 71// Avatar Inspector, a small information window used when clicking
 72// on avatar names in the 2D UI and in the ambient inspector widget for
 73// the 3D world.
 74class LLInspectAvatar : public LLInspect, LLTransientFloater
 75{
 76	friend class LLFloaterReg;
 77	
 78public:
 79	// avatar_id - Avatar ID for which to show information
 80	// Inspector will be positioned relative to current mouse position
 81	LLInspectAvatar(const LLSD& avatar_id);
 82	virtual ~LLInspectAvatar();
 83	
 84	/*virtual*/ BOOL postBuild(void);
 85	
 86	// Because floater is single instance, need to re-parse data on each spawn
 87	// (for example, inspector about same avatar but in different position)
 88	/*virtual*/ void onOpen(const LLSD& avatar_id);
 89
 90	// When closing they should close their gear menu 
 91	/*virtual*/ void onClose(bool app_quitting);
 92	
 93	// Update view based on information from avatar properties processor
 94	void processAvatarData(LLAvatarData* data);
 95	
 96	// override the inspector mouse leave so timer is only paused if 
 97	// gear menu is not open
 98	/* virtual */ void onMouseLeave(S32 x, S32 y, MASK mask);
 99	
100	virtual LLTransientFloaterMgr::ETransientGroup getGroup() { return LLTransientFloaterMgr::GLOBAL; }
101
102private:
103	// Make network requests for all the data to display in this view.
104	// Used on construction and if avatar id changes.
105	void requestUpdate();
106	
107	// Set the volume slider to this user's current client-side volume setting,
108	// hiding/disabling if the user is not nearby.
109	void updateVolumeSlider();
110
111	// Shows/hides moderator panel depending on voice state 
112	void updateModeratorPanel();
113
114	// Moderator ability to enable/disable voice chat for avatar
115	void toggleSelectedVoice(bool enabled);
116	
117	// Button callbacks
118	void onClickAddFriend();
119	void onClickViewProfile();
120	void onClickIM();
121	void onClickCall();
122	void onClickTeleport();
123	void onClickInviteToGroup();
124	void onClickPay();
125	void onClickShare();
126	void onToggleMute();
127	void onClickReport();
128	void onClickFreeze();
129	void onClickEject();
130	void onClickKick();
131	void onClickCSR();
132	void onClickZoomIn();  
133	void onClickFindOnMap();
134	bool onVisibleFindOnMap();
135	bool onVisibleEject();
136	bool onVisibleFreeze();
137	bool onVisibleZoomIn();
138	void onClickMuteVolume();
139	void onVolumeChange(const LLSD& data);
140	bool enableMute();
141	bool enableUnmute();
142	bool enableTeleportOffer();
143	bool godModeEnabled();
144
145	// Is used to determine if "Add friend" option should be enabled in gear menu
146	bool isNotFriend();
147	
148	void onAvatarNameCache(const LLUUID& agent_id,
149						   const LLAvatarName& av_name);
150	
151private:
152	LLUUID				mAvatarID;
153	// Need avatar name information to spawn friend add request
154	LLAvatarName		mAvatarName;
155	// an in-flight request for avatar properties from LLAvatarPropertiesProcessor
156	// is represented by this object
157	LLFetchAvatarData*	mPropertiesRequest;
158};
159
160//////////////////////////////////////////////////////////////////////////////
161// LLFetchAvatarData
162//////////////////////////////////////////////////////////////////////////////
163
164// This object represents a pending request for avatar properties information
165class LLFetchAvatarData : public LLAvatarPropertiesObserver
166{
167public:
168	// If the inspector closes it will delete the pending request object, so the
169	// inspector pointer will be valid for the lifetime of this object
170	LLFetchAvatarData(const LLUUID& avatar_id, LLInspectAvatar* inspector)
171	:	mAvatarID(avatar_id),
172		mInspector(inspector)
173	{
174		LLAvatarPropertiesProcessor* processor = 
175			LLAvatarPropertiesProcessor::getInstance();
176		// register ourselves as an observer
177		processor->addObserver(mAvatarID, this);
178		// send a request (duplicates will be suppressed inside the avatar
179		// properties processor)
180		processor->sendAvatarPropertiesRequest(mAvatarID);
181	}
182	
183	~LLFetchAvatarData()
184	{
185		// remove ourselves as an observer
186		LLAvatarPropertiesProcessor::getInstance()->
187		removeObserver(mAvatarID, this);
188	}
189	
190	void processProperties(void* data, EAvatarProcessorType type)
191	{
192		// route the data to the inspector
193		if (data
194			&& type == APT_PROPERTIES)
195		{
196			LLAvatarData* avatar_data = static_cast<LLAvatarData*>(data);
197			mInspector->processAvatarData(avatar_data);
198		}
199	}
200	
201	// Store avatar ID so we can un-register the observer on destruction
202	LLUUID mAvatarID;
203	LLInspectAvatar* mInspector;
204};
205
206LLInspectAvatar::LLInspectAvatar(const LLSD& sd)
207:	LLInspect( LLSD() ),	// single_instance, doesn't really need key
208	mAvatarID(),			// set in onOpen()  *Note: we used to show partner's name but we dont anymore --angela 3rd Dec* 
209	mAvatarName(),
210	mPropertiesRequest(NULL)
211{
212	mCommitCallbackRegistrar.add("InspectAvatar.ViewProfile",	boost::bind(&LLInspectAvatar::onClickViewProfile, this));	
213	mCommitCallbackRegistrar.add("InspectAvatar.AddFriend",	boost::bind(&LLInspectAvatar::onClickAddFriend, this));	
214	mCommitCallbackRegistrar.add("InspectAvatar.IM",
215		boost::bind(&LLInspectAvatar::onClickIM, this));	
216	mCommitCallbackRegistrar.add("InspectAvatar.Call",		boost::bind(&LLInspectAvatar::onClickCall, this));	
217	mCommitCallbackRegistrar.add("InspectAvatar.Teleport",	boost::bind(&LLInspectAvatar::onClickTeleport, this));	
218	mCommitCallbackRegistrar.add("InspectAvatar.InviteToGroup",	boost::bind(&LLInspectAvatar::onClickInviteToGroup, this));	
219	mCommitCallbackRegistrar.add("InspectAvatar.Pay",	boost::bind(&LLInspectAvatar::onClickPay, this));	
220	mCommitCallbackRegistrar.add("InspectAvatar.Share",	boost::bind(&LLInspectAvatar::onClickShare, this));
221	mCommitCallbackRegistrar.add("InspectAvatar.ToggleMute",	boost::bind(&LLInspectAvatar::onToggleMute, this));	
222	mCommitCallbackRegistrar.add("InspectAvatar.Freeze", boost::bind(&LLInspectAvatar::onClickFreeze, this));	
223	mCommitCallbackRegistrar.add("InspectAvatar.Eject", boost::bind(&LLInspectAvatar::onClickEject, this));	
224	mCommitCallbackRegistrar.add("InspectAvatar.Kick", boost::bind(&LLInspectAvatar::onClickKick, this));	
225	mCommitCallbackRegistrar.add("InspectAvatar.CSR", boost::bind(&LLInspectAvatar::onClickCSR, this));	
226	mCommitCallbackRegistrar.add("InspectAvatar.Report",	boost::bind(&LLInspectAvatar::onClickReport, this));	
227	mCommitCallbackRegistrar.add("InspectAvatar.FindOnMap",	boost::bind(&LLInspectAvatar::onClickFindOnMap, this));	
228	mCommitCallbackRegistrar.add("InspectAvatar.ZoomIn", boost::bind(&LLInspectAvatar::onClickZoomIn, this));
229	mCommitCallbackRegistrar.add("InspectAvatar.DisableVoice", boost::bind(&LLInspectAvatar::toggleSelectedVoice, this, false));
230	mCommitCallbackRegistrar.add("InspectAvatar.EnableVoice", boost::bind(&LLInspectAvatar::toggleSelectedVoice, this, true));
231
232	mEnableCallbackRegistrar.add("InspectAvatar.EnableGod",	boost::bind(&LLInspectAvatar::godModeEnabled, this));	
233	mEnableCallbackRegistrar.add("InspectAvatar.VisibleFindOnMap",	boost::bind(&LLInspectAvatar::onVisibleFindOnMap, this));	
234	mEnableCallbackRegistrar.add("InspectAvatar.VisibleEject",	boost::bind(&LLInspectAvatar::onVisibleEject, this));	
235	mEnableCallbackRegistrar.add("InspectAvatar.VisibleFreeze",	boost::bind(&LLInspectAvatar::onVisibleFreeze, this));	
236	mEnableCallbackRegistrar.add("InspectAvatar.VisibleZoomIn", boost::bind(&LLInspectAvatar::onVisibleZoomIn, this));
237	mEnableCallbackRegistrar.add("InspectAvatar.Gear.Enable", boost::bind(&LLInspectAvatar::isNotFriend, this));
238	mEnableCallbackRegistrar.add("InspectAvatar.Gear.EnableCall", boost::bind(&LLAvatarActions::canCall));
239	mEnableCallbackRegistrar.add("InspectAvatar.Gear.EnableTeleportOffer", boost::bind(&LLInspectAvatar::enableTeleportOffer, this));
240	mEnableCallbackRegistrar.add("InspectAvatar.EnableMute", boost::bind(&LLInspectAvatar::enableMute, this));
241	mEnableCallbackRegistrar.add("InspectAvatar.EnableUnmute", boost::bind(&LLInspectAvatar::enableUnmute, this));
242
243	// can't make the properties request until the widgets are constructed
244	// as it might return immediately, so do it in postBuild.
245
246	LLTransientFloaterMgr::getInstance()->addControlView(LLTransientFloaterMgr::GLOBAL, this);
247	LLTransientFloater::init(this);
248}
249
250LLInspectAvatar::~LLInspectAvatar()
251{
252	// clean up any pending requests so they don't call back into a deleted
253	// view
254	delete mPropertiesRequest;
255	mPropertiesRequest = NULL;
256
257	LLTransientFloaterMgr::getInstance()->removeControlView(this);
258}
259
260/*virtual*/
261BOOL LLInspectAvatar::postBuild(void)
262{
263	getChild<LLUICtrl>("add_friend_btn")->setCommitCallback(
264		boost::bind(&LLInspectAvatar::onClickAddFriend, this) );
265
266	getChild<LLUICtrl>("view_profile_btn")->setCommitCallback(
267		boost::bind(&LLInspectAvatar::onClickViewProfile, this) );
268
269	getChild<LLUICtrl>("mute_btn")->setCommitCallback(
270		boost::bind(&LLInspectAvatar::onClickMuteVolume, this) );
271
272	getChild<LLUICtrl>("volume_slider")->setCommitCallback(
273		boost::bind(&LLInspectAvatar::onVolumeChange, this, _2));
274
275	return TRUE;
276}
277
278
279// Multiple calls to showInstance("inspect_avatar", foo) will provide different
280// LLSD for foo, which we will catch here.
281//virtual
282void LLInspectAvatar::onOpen(const LLSD& data)
283{
284	// Start open animation
285	LLInspect::onOpen(data);
286
287	// Extract appropriate avatar id
288	mAvatarID = data["avatar_id"];
289
290	BOOL self = mAvatarID == gAgent.getID();
291	
292	getChild<LLUICtrl>("gear_self_btn")->setVisible(self);
293	getChild<LLUICtrl>("gear_btn")->setVisible(!self);
294
295	// Position the inspector relative to the mouse cursor
296	// Similar to how tooltips are positioned
297	// See LLToolTipMgr::createToolTip
298	if (data.has("pos"))
299	{
300		LLUI::positionViewNearMouse(this, data["pos"]["x"].asInteger(), data["pos"]["y"].asInteger());
301	}
302	else
303	{
304		LLUI::positionViewNearMouse(this);
305	}
306
307	// can't call from constructor as widgets are not built yet
308	requestUpdate();
309
310	updateVolumeSlider();
311
312	updateModeratorPanel();
313}
314
315// virtual
316void LLInspectAvatar::onClose(bool app_quitting)
317{  
318  getChild<LLMenuButton>("gear_btn")->hideMenu();
319}	
320
321void LLInspectAvatar::requestUpdate()
322{
323	// Don't make network requests when spawning from the debug menu at the
324	// login screen (which is useful to work on the layout).
325	if (mAvatarID.isNull())
326	{
327		if (LLStartUp::getStartupState() >= STATE_STARTED)
328		{
329			// once we're running we don't want to show the test floater
330			// for bogus LLUUID::null links
331			closeFloater();
332		}
333		return;
334	}
335
336	// Clear out old data so it doesn't flash between old and new
337	getChild<LLUICtrl>("user_name")->setValue("");
338	getChild<LLUICtrl>("user_name_small")->setValue("");
339	getChild<LLUICtrl>("user_slid")->setValue("");
340	getChild<LLUICtrl>("user_subtitle")->setValue("");
341	getChild<LLUICtrl>("user_details")->setValue("");
342	
343	// Make a new request for properties
344	delete mPropertiesRequest;
345	mPropertiesRequest = new LLFetchAvatarData(mAvatarID, this);
346
347	// You can't re-add someone as a friend if they are already your friend
348	bool is_friend = LLAvatarTracker::instance().getBuddyInfo(mAvatarID) != NULL;
349	bool is_self = (mAvatarID == gAgentID);
350	if (is_self)
351	{
352		getChild<LLUICtrl>("add_friend_btn")->setVisible(false);
353		getChild<LLUICtrl>("im_btn")->setVisible(false);
354	}
355	else if (is_friend)
356	{
357		getChild<LLUICtrl>("add_friend_btn")->setVisible(false);
358		getChild<LLUICtrl>("im_btn")->setVisible(true);
359	}
360	else
361	{
362		getChild<LLUICtrl>("add_friend_btn")->setVisible(true);
363		getChild<LLUICtrl>("im_btn")->setVisible(false);
364	}
365
366	// Use an avatar_icon even though the image id will come down with the
367	// avatar properties because the avatar_icon code maintains a cache of icons
368	// and this may result in the image being visible sooner.
369	// *NOTE: This may generate a duplicate avatar properties request, but that
370	// will be suppressed internally in the avatar properties processor.
371	
372	//remove avatar id from cache to get fresh info
373	LLAvatarIconIDCache::getInstance()->remove(mAvatarID);
374
375	getChild<LLUICtrl>("avatar_icon")->setValue(LLSD(mAvatarID) );
376
377	LLAvatarNameCache::get(mAvatarID,
378			boost::bind(&LLInspectAvatar::onAvatarNameCache,
379				this, _1, _2));
380}
381
382void LLInspectAvatar::processAvatarData(LLAvatarData* data)
383{
384	LLStringUtil::format_map_t args;
385	{
386		std::string birth_date = LLTrans::getString("AvatarBirthDateFormat");
387		LLStringUtil::format(birth_date, LLSD().with("datetime", (S32) data->born_on.secondsSinceEpoch()));
388		args["[BORN_ON]"] = birth_date;
389	}
390	args["[AGE]"] = LLDateUtil::ageFromDate(data->born_on, LLDate::now());
391	args["[SL_PROFILE]"] = data->about_text;
392	args["[RW_PROFILE"] = data->fl_about_text;
393	args["[ACCTTYPE]"] = LLAvatarPropertiesProcessor::accountType(data);
394	std::string payment_info = LLAvatarPropertiesProcessor::paymentInfo(data);
395	args["[PAYMENTINFO]"] = payment_info;
396	args["[COMMA]"] = (payment_info.empty() ? "" : ",");
397
398	std::string subtitle = getString("Subtitle", args);
399	getChild<LLUICtrl>("user_subtitle")->setValue( LLSD(subtitle) );
400	std::string details = getString("Details", args);
401	getChild<LLUICtrl>("user_details")->setValue( LLSD(details) );
402
403	// Delete the request object as it has been satisfied
404	delete mPropertiesRequest;
405	mPropertiesRequest = NULL;
406}
407
408// For the avatar inspector, we only want to unpause the fade timer 
409// if neither the gear menu or self gear menu are open
410void LLInspectAvatar::onMouseLeave(S32 x, S32 y, MASK mask)
411{
412	LLToggleableMenu* gear_menu = getChild<LLMenuButton>("gear_btn")->getMenu();
413	LLToggleableMenu* gear_menu_self = getChild<LLMenuButton>("gear_self_btn")->getMenu();
414	if ( gear_menu && gear_menu->getVisible() &&
415		 gear_menu_self && gear_menu_self->getVisible() )
416	{
417		return;
418	}
419
420	if(childHasVisiblePopupMenu())
421	{
422		return;
423	}
424
425	mOpenTimer.unpause();
426}
427
428void LLInspectAvatar::updateModeratorPanel()
429{
430	bool enable_moderator_panel = false;
431
432    if (LLVoiceChannel::getCurrentVoiceChannel() &&
433		mAvatarID != gAgent.getID())
434    {
435		LLUUID session_id = LLVoiceChannel::getCurrentVoiceChannel()->getSessionID();
436
437		if (session_id != LLUUID::null)
438		{
439			LLIMSpeakerMgr* speaker_mgr = LLIMModel::getInstance()->getSpeakerManager(session_id);
440
441			if (speaker_mgr)
442			{
443				LLPointer<LLSpeaker> self_speakerp = speaker_mgr->findSpeaker(gAgent.getID());
444				LLPointer<LLSpeaker> selected_speakerp = speaker_mgr->findSpeaker(mAvatarID);
445				
446				if(speaker_mgr->isVoiceActive() && selected_speakerp && 
447					selected_speakerp->isInVoiceChannel() &&
448					((self_speakerp && self_speakerp->mIsModerator) || gAgent.isGodlike()))
449				{
450					getChild<LLUICtrl>("enable_voice")->setVisible(selected_speakerp->mModeratorMutedVoice);
451					getChild<LLUICtrl>("disable_voice")->setVisible(!selected_speakerp->mModeratorMutedVoice);
452
453					enable_moderator_panel = true;
454				}
455			}
456		}
457	}
458
459	if (enable_moderator_panel)
460	{
461		if (!getChild<LLUICtrl>("moderator_panel")->getVisible())
462		{
463			getChild<LLUICtrl>("moderator_panel")->setVisible(true);
464			// stretch the floater so it can accommodate the moderator panel
465			reshape(getRect().getWidth(), getRect().getHeight() + getChild<LLUICtrl>("moderator_panel")->getRect().getHeight());
466		}
467	}
468	else if (getChild<LLUICtrl>("moderator_panel")->getVisible())
469	{
470		getChild<LLUICtrl>("moderator_panel")->setVisible(false);
471		// shrink the inspector floater back to original size
472		reshape(getRect().getWidth(), getRect().getHeight() - getChild<LLUICtrl>("moderator_panel")->getRect().getHeight());					
473	}
474}
475
476void LLInspectAvatar::toggleSelectedVoice(bool enabled)
477{
478	LLUUID session_id = LLVoiceChannel::getCurrentVoiceChannel()->getSessionID();
479	LLIMSpeakerMgr* speaker_mgr = LLIMModel::getInstance()->getSpeakerManager(session_id);
480
481	if (speaker_mgr)
482	{
483		if (!gAgent.getRegion())
484			return;
485
486		std::string url = gAgent.getRegion()->getCapability("ChatSessionRequest");
487		LLSD data;
488		data["method"] = "mute update";
489		data["session-id"] = session_id;
490		data["params"] = LLSD::emptyMap();
491		data["params"]["agent_id"] = mAvatarID;
492		data["params"]["mute_info"] = LLSD::emptyMap();
493		// ctrl value represents ability to type, so invert
494		data["params"]["mute_info"]["voice"] = !enabled;
495
496		class MuteVoiceResponder : public LLHTTPClient::Responder
497		{
498		public:
499			MuteVoiceResponder(const LLUUID& session_id)
500			{
501				mSessionID = session_id;
502			}
503
504			virtual void error(U32 status, const std::string& reason)
505			{
506				llwarns << status << ": " << reason << llendl;
507
508				if ( gIMMgr )
509				{
510					//403 == you're not a mod
511					//should be disabled if you're not a moderator
512					if ( 403 == status )
513					{
514						gIMMgr->showSessionEventError(
515							"mute",
516							"not_a_moderator",
517							mSessionID);
518					}
519					else
520					{
521						gIMMgr->showSessionEventError(
522							"mute",
523							"generic",
524							mSessionID);
525					}
526				}
527			}
528
529		private:
530			LLUUID mSessionID;
531		};
532
533		LLHTTPClient::post(
534			url,
535			data,
536			new MuteVoiceResponder(speaker_mgr->getSessionID()));
537	}
538
539	closeFloater();
540
541}
542
543void LLInspectAvatar::updateVolumeSlider()
544{
545	bool voice_enabled = LLVoiceClient::getInstance()->getVoiceEnabled(mAvatarID);
546
547	// Do not display volume slider and mute button if it 
548	// is ourself or we are not in a voice channel together
549	if (!voice_enabled || (mAvatarID == gAgent.getID()))
550	{
551		getChild<LLUICtrl>("mute_btn")->setVisible(false);
552		getChild<LLUICtrl>("volume_slider")->setVisible(false);
553	}
554
555	else 
556	{
557		getChild<LLUICtrl>("mute_btn")->setVisible(true);
558		getChild<LLUICtrl>("volume_slider")->setVisible(true);
559
560		// By convention, we only display and toggle voice mutes, not all mutes
561		bool is_muted = LLMuteList::getInstance()->
562							isMuted(mAvatarID, LLMute::flagVoiceChat);
563
564		LLUICtrl* mute_btn = getChild<LLUICtrl>("mute_btn");
565
566		bool is_linden = LLStringUtil::endsWith(mAvatarName.getLegacyName(), " Linden");
567
568		mute_btn->setEnabled( !is_linden);
569		mute_btn->setValue( is_muted );
570
571		LLUICtrl* volume_slider = getChild<LLUICtrl>("volume_slider");
572		volume_slider->setEnabled( !is_muted );
573
574		F32 volume;
575		
576		if (is_muted)
577		{
578			// it's clearer to display their volume as zero
579			volume = 0.f;
580		}
581		else
582		{
583			// actual volume
584			volume = LLVoiceClient::getInstance()->getUserVolume(mAvatarID);
585		}
586		volume_slider->setValue( (F64)volume );
587	}
588
589}
590
591void LLInspectAvatar::onClickMuteVolume()
592{
593	// By convention, we only display and toggle voice mutes, not all mutes
594	LLMuteList* mute_list = LLMuteList::getInstance();
595	bool is_muted = mute_list->isMuted(mAvatarID, LLMute::flagVoiceChat);
596
597	LLMute mute(mAvatarID, mAvatarName.getLegacyName(), LLMute::AGENT);
598	if (!is_muted)
599	{
600		mute_list->add(mute, LLMute::flagVoiceChat);
601	}
602	else
603	{
604		mute_list->remove(mute, LLMute::flagVoiceChat);
605	}
606
607	updateVolumeSlider();
608}
609
610void LLInspectAvatar::onVolumeChange(const LLSD& data)
611{
612	F32 volume = (F32)data.asReal();
613	LLVoiceClient::getInstance()->setUserVolume(mAvatarID, volume);
614}
615
616void LLInspectAvatar::onAvatarNameCache(
617		const LLUUID& agent_id,
618		const LLAvatarName& av_name)
619{
620	if (agent_id == mAvatarID)
621	{
622		getChild<LLUICtrl>("user_name")->setValue(av_name.mDisplayName);
623		getChild<LLUICtrl>("user_name_small")->setValue(av_name.mDisplayName);
624		getChild<LLUICtrl>("user_slid")->setValue(av_name.mUsername);
625		mAvatarName = av_name;
626		
627		// show smaller display name if too long to display in regular size
628		if (getChild<LLTextBox>("user_name")->getTextPixelWidth() > getChild<LLTextBox>("user_name")->getRect().getWidth())
629		{
630			getChild<LLUICtrl>("user_name_small")->setVisible( true );
631			getChild<LLUICtrl>("user_name")->setVisible( false );
632		}
633		else
634		{
635			getChild<LLUICtrl>("user_name_small")->setVisible( false );
636			getChild<LLUICtrl>("user_name")->setVisible( true );
637
638		}
639
640	}
641}
642
643void LLInspectAvatar::onClickAddFriend()
644{
645	LLAvatarActions::requestFriendshipDialog(mAvatarID, mAvatarName.getLegacyName());
646	closeFloater();
647}
648
649void LLInspectAvatar::onClickViewProfile()
650{
651	LLAvatarActions::showProfile(mAvatarID);
652	closeFloater();
653}
654
655bool LLInspectAvatar::isNotFriend()
656{
657	return !LLAvatarActions::isFriend(mAvatarID);
658}
659
660bool LLInspectAvatar::onVisibleFindOnMap()
661{
662	return gAgent.isGodlike() || is_agent_mappable(mAvatarID);
663}
664
665bool LLInspectAvatar::onVisibleEject()
666{
667	return enable_freeze_eject( LLSD(mAvatarID) );
668}
669
670bool LLInspectAvatar::onVisibleFreeze()
671{
672	// either user is a god and can do long distance freeze
673	// or check for target proximity and permissions
674	return gAgent.isGodlike() || enable_freeze_eject(LLSD(mAvatarID));
675}
676
677bool LLInspectAvatar::onVisibleZoomIn()
678{
679	return gObjectList.findObject(mAvatarID);
680}
681
682void LLInspectAvatar::onClickIM()
683{ 
684	LLAvatarActions::startIM(mAvatarID);
685	closeFloater();
686}
687
688void LLInspectAvatar::onClickCall()
689{ 
690	LLAvatarActions::startCall(mAvatarID);
691	closeFloater();
692}
693
694void LLInspectAvatar::onClickTeleport()
695{
696	LLAvatarActions::offerTeleport(mAvatarID);
697	closeFloater();
698}
699
700void LLInspectAvatar::onClickInviteToGroup()
701{
702	LLAvatarActions::inviteToGroup(mAvatarID);
703	closeFloater();
704}
705
706void LLInspectAvatar::onClickPay()
707{
708	LLAvatarActions::pay(mAvatarID);
709	closeFloater();
710}
711
712void LLInspectAvatar::onClickShare()
713{
714	LLAvatarActions::share(mAvatarID);
715	closeFloater();
716}
717
718void LLInspectAvatar::onToggleMute()
719{
720	LLMute mute(mAvatarID, mAvatarName.mDisplayName, LLMute::AGENT);
721
722	if (LLMuteList::getInstance()->isMuted(mute.mID, mute.mName))
723	{
724		LLMuteList::getInstance()->remove(mute);
725	}
726	else
727	{
728		LLMuteList::getInstance()->add(mute);
729	}
730
731	LLPanelBlockedList::showPanelAndSelect(mute.mID);
732	closeFloater();
733}
734
735void LLInspectAvatar::onClickReport()
736{
737	LLFloaterReporter::showFromAvatar(mAvatarID, mAvatarName.getCompleteName());
738	closeFloater();
739}
740
741bool godlike_freeze(const LLSD& notification, const LLSD& response)
742{
743	LLUUID avatar_id = notification["payload"]["avatar_id"].asUUID();
744	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
745
746	switch (option)
747	{
748	case 0:
749		LLAvatarActions::freeze(avatar_id);
750		break;
751	case 1:
752		LLAvatarActions::unfreeze(avatar_id);
753		break;
754	default:
755		break;
756	}
757
758	return false;
759}
760
761void LLInspectAvatar::onClickFreeze()
762{
763	if (gAgent.isGodlike())
764	{
765		// use godlike freeze-at-a-distance, with confirmation
766		LLNotificationsUtil::add("FreezeAvatar",
767			LLSD(),
768			LLSD().with("avatar_id", mAvatarID),
769			godlike_freeze);
770	}
771	else
772	{
773		// use default "local" version of freezing that requires avatar to be in range
774		handle_avatar_freeze( LLSD(mAvatarID) );
775	}
776	closeFloater();
777}
778
779void LLInspectAvatar::onClickEject()
780{
781	handle_avatar_eject( LLSD(mAvatarID) );
782	closeFloater();
783}
784
785void LLInspectAvatar::onClickKick()
786{
787	LLAvatarActions::kick(mAvatarID);
788	closeFloater();
789}
790
791void LLInspectAvatar::onClickCSR()
792{
793	std::string name;
794	gCacheName->getFullName(mAvatarID, name);
795	LLAvatarActions::csr(mAvatarID, name);
796	closeFloater();
797}
798
799void LLInspectAvatar::onClickZoomIn() 
800{
801	handle_zoom_to_object(mAvatarID);
802	closeFloater();
803}
804
805void LLInspectAvatar::onClickFindOnMap()
806{
807	gFloaterWorldMap->trackAvatar(mAvatarID, mAvatarName.mDisplayName);
808	LLFloaterReg::showInstance("world_map");
809}
810
811
812bool LLInspectAvatar::enableMute()
813{
814		bool is_linden = LLStringUtil::endsWith(mAvatarName.getLegacyName(), " Linden");
815		bool is_self = mAvatarID == gAgent.getID();
816
817		if (!is_linden && !is_self && !LLMuteList::getInstance()->isMuted(mAvatarID, mAvatarName.getLegacyName()))
818		{
819			return true;
820		}
821		else
822		{
823			return false;
824		}
825}
826
827bool LLInspectAvatar::enableUnmute()
828{
829		bool is_linden = LLStringUtil::endsWith(mAvatarName.getLegacyName(), " Linden");
830		bool is_self = mAvatarID == gAgent.getID();
831
832		if (!is_linden && !is_self && LLMuteList::getInstance()->isMuted(mAvatarID, mAvatarName.getLegacyName()))
833		{
834			return true;
835		}
836		else
837		{
838			return false;
839		}
840}
841
842bool LLInspectAvatar::enableTeleportOffer()
843{
844	return LLAvatarActions::canOfferTeleport(mAvatarID);
845}
846
847bool LLInspectAvatar::godModeEnabled()
848{
849	return gAgent.isGodlike();
850}
851
852//////////////////////////////////////////////////////////////////////////////
853// LLInspectAvatarUtil
854//////////////////////////////////////////////////////////////////////////////
855void LLInspectAvatarUtil::registerFloater()
856{
857	LLFloaterReg::add("inspect_avatar", "inspect_avatar.xml",
858					  &LLFloaterReg::build<LLInspectAvatar>);
859}