PageRenderTime 35ms CodeModel.GetById 12ms app.highlight 19ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llpanelavatar.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 200 lines | 135 code | 26 blank | 39 comment | 9 complexity | 5e43c8807092a416fe208690e4c141ca MD5 | raw file
  1/** 
  2 * @file llpanelavatar.cpp
  3 * @brief LLPanelAvatar and related class implementations
  4 *
  5 * $LicenseInfo:firstyear=2004&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#include "llviewerprecompiledheaders.h"
 28#include "llpanelavatar.h"
 29
 30#include "llagent.h"
 31#include "llavataractions.h"
 32#include "llavatarconstants.h"	// AVATAR_ONLINE
 33#include "llcallingcard.h"
 34#include "llcombobox.h"
 35#include "lldateutil.h"			// ageFromDate()
 36#include "llimview.h"
 37#include "llmenubutton.h"
 38#include "llnotificationsutil.h"
 39#include "llslurl.h"
 40#include "lltexteditor.h"
 41#include "lltexturectrl.h"
 42#include "lltoggleablemenu.h"
 43#include "lltooldraganddrop.h"
 44#include "llscrollcontainer.h"
 45#include "llavatariconctrl.h"
 46#include "llfloaterreg.h"
 47#include "llnotificationsutil.h"
 48#include "llvoiceclient.h"
 49#include "lltextbox.h"
 50#include "lltrans.h"
 51
 52//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 53// Class LLDropTarget
 54//
 55// This handy class is a simple way to drop something on another
 56// view. It handles drop events, always setting itself to the size of
 57// its parent.
 58//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 59
 60class LLDropTarget : public LLView
 61{
 62public:
 63	struct Params : public LLInitParam::Block<Params, LLView::Params>
 64	{
 65		Optional<LLUUID> agent_id;
 66		Params()
 67		:	agent_id("agent_id")
 68		{
 69			changeDefault(mouse_opaque, false);
 70			changeDefault(follows.flags, FOLLOWS_ALL);
 71		}
 72	};
 73
 74	LLDropTarget(const Params&);
 75	~LLDropTarget();
 76
 77	void doDrop(EDragAndDropType cargo_type, void* cargo_data);
 78
 79	//
 80	// LLView functionality
 81	virtual BOOL handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
 82								   EDragAndDropType cargo_type,
 83								   void* cargo_data,
 84								   EAcceptance* accept,
 85								   std::string& tooltip_msg);
 86	void setAgentID(const LLUUID &agent_id)		{ mAgentID = agent_id; }
 87protected:
 88	LLUUID mAgentID;
 89};
 90
 91LLDropTarget::LLDropTarget(const LLDropTarget::Params& p) 
 92:	LLView(p),
 93	mAgentID(p.agent_id)
 94{}
 95
 96LLDropTarget::~LLDropTarget()
 97{}
 98
 99void LLDropTarget::doDrop(EDragAndDropType cargo_type, void* cargo_data)
100{
101	llinfos << "LLDropTarget::doDrop()" << llendl;
102}
103
104BOOL LLDropTarget::handleDragAndDrop(S32 x, S32 y, MASK mask, BOOL drop,
105									 EDragAndDropType cargo_type,
106									 void* cargo_data,
107									 EAcceptance* accept,
108									 std::string& tooltip_msg)
109{
110	if(getParent())
111	{
112		LLToolDragAndDrop::handleGiveDragAndDrop(mAgentID, LLUUID::null, drop,
113												 cargo_type, cargo_data, accept);
114
115		return TRUE;
116	}
117
118	return FALSE;
119}
120
121static LLDefaultChildRegistry::Register<LLDropTarget> r("drop_target");
122
123//////////////////////////////////////////////////////////////////////////
124//////////////////////////////////////////////////////////////////////////
125//////////////////////////////////////////////////////////////////////////
126
127LLPanelProfileTab::LLPanelProfileTab()
128: LLPanel()
129, mAvatarId(LLUUID::null)
130{
131}
132
133LLPanelProfileTab::~LLPanelProfileTab()
134{
135	if(getAvatarId().notNull())
136	{
137		LLAvatarPropertiesProcessor::getInstance()->removeObserver(getAvatarId(),this);
138	}
139}
140
141void LLPanelProfileTab::setAvatarId(const LLUUID& id)
142{
143	if(id.notNull())
144	{
145		if(getAvatarId().notNull())
146		{
147			LLAvatarPropertiesProcessor::getInstance()->removeObserver(mAvatarId,this);
148		}
149		mAvatarId = id;
150		LLAvatarPropertiesProcessor::getInstance()->addObserver(getAvatarId(),this);
151	}
152}
153
154void LLPanelProfileTab::onOpen(const LLSD& key)
155{
156	// Don't reset panel if we are opening it for same avatar.
157	if(getAvatarId() != key.asUUID())
158	{
159		resetControls();
160		resetData();
161
162		scrollToTop();
163	}
164
165	// Update data even if we are viewing same avatar profile as some data might been changed.
166	setAvatarId(key.asUUID());
167	updateData();
168	updateButtons();
169}
170
171void LLPanelProfileTab::scrollToTop()
172{
173	LLScrollContainer* scrollContainer = findChild<LLScrollContainer>("profile_scroll");
174	if (scrollContainer)
175		scrollContainer->goToTop();
176}
177
178void LLPanelProfileTab::onMapButtonClick()
179{
180	LLAvatarActions::showOnMap(getAvatarId());
181}
182
183void LLPanelProfileTab::updateButtons()
184{
185	bool is_buddy_online = LLAvatarTracker::instance().isBuddyOnline(getAvatarId());
186	
187	if(LLAvatarActions::isFriend(getAvatarId()))
188	{
189		getChildView("teleport")->setEnabled(is_buddy_online);
190	}
191	else
192	{
193		getChildView("teleport")->setEnabled(true);
194	}
195
196	bool enable_map_btn = (is_buddy_online &&
197			       is_agent_mappable(getAvatarId()))
198		|| gAgent.isGodlike();
199	getChildView("show_on_map_btn")->setEnabled(enable_map_btn);
200}