PageRenderTime 74ms CodeModel.GetById 30ms app.highlight 23ms RepoModel.GetById 17ms app.codeStats 1ms

/indra/newview/llpanelprofileview.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 247 lines | 155 code | 44 blank | 48 comment | 16 complexity | bb9f30327a4afee8e308da2f593f5604 MD5 | raw file
  1/** 
  2* @file llpanelprofileview.cpp
  3* @brief Side tray "Profile View" panel
  4*
  5* $LicenseInfo:firstyear=2009&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
 29#include "llpanelprofileview.h"
 30
 31#include "llavatarconstants.h"
 32#include "llavatarnamecache.h"	// IDEVO
 33#include "llclipboard.h"
 34#include "lluserrelations.h"
 35
 36#include "llavatarpropertiesprocessor.h"
 37#include "llcallingcard.h"
 38#include "llpanelavatar.h"
 39#include "llpanelpicks.h"
 40#include "llpanelprofile.h"
 41#include "llsidetraypanelcontainer.h"
 42
 43static LLRegisterPanelClassWrapper<LLPanelProfileView> t_panel_target_profile("panel_profile_view");
 44
 45static std::string PANEL_NOTES = "panel_notes";
 46static const std::string PANEL_PROFILE = "panel_profile";
 47static const std::string PANEL_PICKS = "panel_picks";
 48
 49
 50class AvatarStatusObserver : public LLAvatarPropertiesObserver
 51{
 52public:
 53	AvatarStatusObserver(LLPanelProfileView* profile_view)
 54	{
 55		mProfileView = profile_view;
 56	}
 57
 58	void processProperties(void* data, EAvatarProcessorType type)
 59	{
 60		if(APT_PROPERTIES != type) return;
 61		const LLAvatarData* avatar_data = static_cast<const LLAvatarData*>(data);
 62		if(avatar_data && mProfileView->getAvatarId() == avatar_data->avatar_id)
 63		{
 64			mProfileView->processOnlineStatus(avatar_data->flags & AVATAR_ONLINE);
 65			LLAvatarPropertiesProcessor::instance().removeObserver(mProfileView->getAvatarId(), this);
 66		}
 67	}
 68
 69	void subscribe()
 70	{
 71		LLAvatarPropertiesProcessor::instance().addObserver(mProfileView->getAvatarId(), this);
 72	}
 73
 74private:
 75	LLPanelProfileView* mProfileView;
 76};
 77
 78LLPanelProfileView::LLPanelProfileView()
 79:	LLPanelProfile()
 80,	mStatusText(NULL)
 81,	mAvatarStatusObserver(NULL)
 82{
 83	mAvatarStatusObserver = new AvatarStatusObserver(this);
 84}
 85
 86LLPanelProfileView::~LLPanelProfileView(void)
 87{
 88	delete mAvatarStatusObserver;
 89}
 90
 91/*virtual*/ 
 92void LLPanelProfileView::onOpen(const LLSD& key)
 93{
 94	LLUUID id;
 95	if(key.has("id"))
 96	{
 97		id = key["id"];
 98	}
 99
100	if(id.notNull() && getAvatarId() != id)
101	{
102		setAvatarId(id);
103
104		// clear name fields, which might have old data
105		getChild<LLUICtrl>("user_name")->setValue( LLSD() );
106		getChild<LLUICtrl>("user_slid")->setValue( LLSD() );
107	}
108
109	// Update the avatar name.
110	LLAvatarNameCache::get(getAvatarId(),
111		boost::bind(&LLPanelProfileView::onAvatarNameCache, this, _1, _2));
112
113	updateOnlineStatus();
114
115
116	LLPanelProfile::onOpen(key);
117}
118
119BOOL LLPanelProfileView::postBuild()
120{
121	LLPanelProfile::postBuild();
122
123	getTabContainer()[PANEL_NOTES] = findChild<LLPanelAvatarNotes>(PANEL_NOTES);
124	
125	//*TODO remove this, according to style guide we don't use status combobox
126	getTabContainer()[PANEL_PROFILE]->getChildView("online_me_status_text")->setVisible( FALSE);
127	getTabContainer()[PANEL_PROFILE]->getChildView("status_combo")->setVisible( FALSE);
128
129	mStatusText = getChild<LLTextBox>("status");
130	mStatusText->setVisible(false);
131
132	childSetCommitCallback("back",boost::bind(&LLPanelProfileView::onBackBtnClick,this),NULL);
133	childSetCommitCallback("copy_to_clipboard",boost::bind(&LLPanelProfileView::onCopyToClipboard,this),NULL);
134		
135	return TRUE;
136}
137
138
139//private
140
141void LLPanelProfileView::onBackBtnClick()
142{
143	// Set dummy value to make picks panel dirty, 
144	// This will make Picks reload on next open.
145	getTabContainer()[PANEL_PICKS]->setValue(LLSD());
146
147	LLSideTrayPanelContainer* parent = dynamic_cast<LLSideTrayPanelContainer*>(getParent());
148	if(parent)
149	{
150		parent->openPreviousPanel();
151	}
152}
153
154void LLPanelProfileView::onCopyToClipboard()
155{
156	std::string name = getChild<LLUICtrl>("user_name")->getValue().asString() + " (" + getChild<LLUICtrl>("user_slid")->getValue().asString() + ")";
157	gClipboard.copyFromString(utf8str_to_wstring(name));
158}
159
160bool LLPanelProfileView::isGrantedToSeeOnlineStatus()
161{
162	const LLRelationship* relationship = LLAvatarTracker::instance().getBuddyInfo(getAvatarId());
163	if (NULL == relationship)
164		return false;
165
166	// *NOTE: GRANT_ONLINE_STATUS is always set to false while changing any other status.
167	// When avatar disallow me to see her online status processOfflineNotification Message is received by the viewer
168	// see comments for ChangeUserRights template message. EXT-453.
169	// If GRANT_ONLINE_STATUS flag is changed it will be applied when viewer restarts. EXT-3880
170	return relationship->isRightGrantedFrom(LLRelationship::GRANT_ONLINE_STATUS);
171}
172
173// method was disabled according to EXT-2022. Re-enabled & improved according to EXT-3880
174void LLPanelProfileView::updateOnlineStatus()
175{
176	// set text box visible to show online status for non-friends who has not set in Preferences
177	// "Only Friends & Groups can see when I am online"
178	mStatusText->setVisible(TRUE);
179
180	const LLRelationship* relationship = LLAvatarTracker::instance().getBuddyInfo(getAvatarId());
181	if (NULL == relationship)
182	{
183		// this is non-friend avatar. Status will be updated from LLAvatarPropertiesProcessor.
184		// in LLPanelProfileView::processOnlineStatus()
185
186		// subscribe observer to get online status. Request will be sent by LLPanelAvatarProfile itself.
187		// do not subscribe for friend avatar because online status can be wrong overridden
188		// via LLAvatarData::flags if Preferences: "Only Friends & Groups can see when I am online" is set.
189		mAvatarStatusObserver->subscribe();
190		return;
191	}
192	// For friend let check if he allowed me to see his status
193
194	// status should only show if viewer has permission to view online/offline. EXT-453, EXT-3880
195	mStatusText->setVisible(isGrantedToSeeOnlineStatus());
196
197	bool online = relationship->isOnline();
198	processOnlineStatus(online);
199}
200
201void LLPanelProfileView::processOnlineStatus(bool online)
202{
203	std::string status = getString(online ? "status_online" : "status_offline");
204
205	mStatusText->setValue(status);
206}
207
208void LLPanelProfileView::onAvatarNameCache(const LLUUID& agent_id,
209										   const LLAvatarName& av_name)
210{
211	getChild<LLUICtrl>("user_name")->setValue( av_name.mDisplayName );
212	getChild<LLUICtrl>("user_name_small")->setValue( av_name.mDisplayName );
213	getChild<LLUICtrl>("user_slid")->setValue( av_name.mUsername );
214
215	// show smaller display name if too long to display in regular size
216	if (getChild<LLTextBox>("user_name")->getTextPixelWidth() > getChild<LLTextBox>("user_name")->getRect().getWidth())
217	{
218		getChild<LLUICtrl>("user_name_small")->setVisible( true );
219		getChild<LLUICtrl>("user_name")->setVisible( false );
220	}
221	else
222	{
223		getChild<LLUICtrl>("user_name_small")->setVisible( false );
224		getChild<LLUICtrl>("user_name")->setVisible( true );
225	}
226
227	if (LLAvatarNameCache::useDisplayNames())
228	{
229		getChild<LLUICtrl>("user_label")->setVisible( true );
230		getChild<LLUICtrl>("user_slid")->setVisible( true );
231		getChild<LLUICtrl>("display_name_label")->setVisible( true );
232		getChild<LLUICtrl>("copy_to_clipboard")->setVisible( true );
233		getChild<LLUICtrl>("copy_to_clipboard")->setEnabled( true );
234		getChild<LLUICtrl>("solo_username_label")->setVisible( false );
235	}
236	else
237	{
238		getChild<LLUICtrl>("user_label")->setVisible( false );
239		getChild<LLUICtrl>("user_slid")->setVisible( false );
240		getChild<LLUICtrl>("display_name_label")->setVisible( false );
241		getChild<LLUICtrl>("copy_to_clipboard")->setVisible( false );
242		getChild<LLUICtrl>("copy_to_clipboard")->setEnabled( false );
243		getChild<LLUICtrl>("solo_username_label")->setVisible( true );
244	}
245}
246
247// EOF