PageRenderTime 175ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

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