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