PageRenderTime 40ms CodeModel.GetById 18ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llinspectremoteobject.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 194 lines | 119 code | 25 blank | 50 comment | 4 complexity | 2d1ce4c2c89fe7feefda7c5fad74d480 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llinspectremoteobject.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. #include "llviewerprecompiledheaders.h"
  26. #include "llfloaterreg.h"
  27. #include "llinspectremoteobject.h"
  28. #include "llinspect.h"
  29. #include "llmutelist.h"
  30. #include "llpanelblockedlist.h"
  31. #include "llslurl.h"
  32. #include "lltrans.h"
  33. #include "llui.h"
  34. #include "lluictrl.h"
  35. #include "llurlaction.h"
  36. //////////////////////////////////////////////////////////////////////////////
  37. // LLInspectRemoteObject
  38. //////////////////////////////////////////////////////////////////////////////
  39. // Remote Object Inspector, a small information window used to
  40. // display information about potentially-remote objects. Used
  41. // to display details about objects sending messages to the user.
  42. class LLInspectRemoteObject : public LLInspect
  43. {
  44. friend class LLFloaterReg;
  45. public:
  46. LLInspectRemoteObject(const LLSD& object_id);
  47. virtual ~LLInspectRemoteObject() {};
  48. /*virtual*/ BOOL postBuild(void);
  49. /*virtual*/ void onOpen(const LLSD& avatar_id);
  50. void onClickMap();
  51. void onClickBlock();
  52. void onClickClose();
  53. private:
  54. void update();
  55. private:
  56. LLUUID mObjectID;
  57. LLUUID mOwnerID;
  58. std::string mSLurl;
  59. std::string mName;
  60. bool mGroupOwned;
  61. };
  62. LLInspectRemoteObject::LLInspectRemoteObject(const LLSD& sd) :
  63. LLInspect(LLSD()),
  64. mObjectID(NULL),
  65. mOwnerID(NULL),
  66. mSLurl(""),
  67. mName(""),
  68. mGroupOwned(false)
  69. {
  70. }
  71. /*virtual*/
  72. BOOL LLInspectRemoteObject::postBuild(void)
  73. {
  74. // hook up the inspector's buttons
  75. getChild<LLUICtrl>("map_btn")->setCommitCallback(
  76. boost::bind(&LLInspectRemoteObject::onClickMap, this));
  77. getChild<LLUICtrl>("block_btn")->setCommitCallback(
  78. boost::bind(&LLInspectRemoteObject::onClickBlock, this));
  79. getChild<LLUICtrl>("close_btn")->setCommitCallback(
  80. boost::bind(&LLInspectRemoteObject::onClickClose, this));
  81. return TRUE;
  82. }
  83. /*virtual*/
  84. void LLInspectRemoteObject::onOpen(const LLSD& data)
  85. {
  86. // Start animation
  87. LLInspect::onOpen(data);
  88. // Extract appropriate object information from input LLSD
  89. // (Eventually, it might be nice to query server for details
  90. // rather than require caller to pass in the information.)
  91. mObjectID = data["object_id"].asUUID();
  92. mName = data["name"].asString();
  93. mOwnerID = data["owner_id"].asUUID();
  94. mGroupOwned = data["group_owned"].asBoolean();
  95. mSLurl = data["slurl"].asString();
  96. // update the inspector with the current object state
  97. update();
  98. // Position the inspector relative to the mouse cursor
  99. // Similar to how tooltips are positioned
  100. // See LLToolTipMgr::createToolTip
  101. if (data.has("pos"))
  102. {
  103. LLUI::positionViewNearMouse(this, data["pos"]["x"].asInteger(), data["pos"]["y"].asInteger());
  104. }
  105. else
  106. {
  107. LLUI::positionViewNearMouse(this);
  108. }
  109. }
  110. void LLInspectRemoteObject::onClickMap()
  111. {
  112. std::string url = "secondlife://" + mSLurl;
  113. LLUrlAction::showLocationOnMap(url);
  114. closeFloater();
  115. }
  116. void LLInspectRemoteObject::onClickBlock()
  117. {
  118. LLMute mute(mObjectID, mName, LLMute::OBJECT);
  119. LLMuteList::getInstance()->add(mute);
  120. LLPanelBlockedList::showPanelAndSelect(mute.mID);
  121. closeFloater();
  122. }
  123. void LLInspectRemoteObject::onClickClose()
  124. {
  125. closeFloater();
  126. }
  127. void LLInspectRemoteObject::update()
  128. {
  129. // show the object name as the inspector's title
  130. // (don't hyperlink URLs in object names)
  131. getChild<LLUICtrl>("object_name")->setValue("<nolink>" + mName + "</nolink>");
  132. // show the object's owner - click it to show profile
  133. std::string owner;
  134. if (! mOwnerID.isNull())
  135. {
  136. if (mGroupOwned)
  137. {
  138. owner = LLSLURL("group", mOwnerID, "about").getSLURLString();
  139. }
  140. else
  141. {
  142. owner = LLSLURL("agent", mOwnerID, "about").getSLURLString();
  143. }
  144. }
  145. else
  146. {
  147. owner = LLTrans::getString("Unknown");
  148. }
  149. getChild<LLUICtrl>("object_owner")->setValue(owner);
  150. // display the object's SLurl - click it to teleport
  151. std::string url;
  152. if (! mSLurl.empty())
  153. {
  154. url = "secondlife:///app/teleport/" + mSLurl;
  155. }
  156. getChild<LLUICtrl>("object_slurl")->setValue(url);
  157. // disable the Map button if we don't have a SLurl
  158. getChild<LLUICtrl>("map_btn")->setEnabled(! mSLurl.empty());
  159. // disable the Block button if we don't have the object ID (will this ever happen?)
  160. getChild<LLUICtrl>("block_btn")->setEnabled(! mObjectID.isNull());
  161. }
  162. //////////////////////////////////////////////////////////////////////////////
  163. // LLInspectRemoteObjectUtil
  164. //////////////////////////////////////////////////////////////////////////////
  165. void LLInspectRemoteObjectUtil::registerFloater()
  166. {
  167. LLFloaterReg::add("inspect_remote_object", "inspect_remote_object.xml",
  168. &LLFloaterReg::build<LLInspectRemoteObject>);
  169. }