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