PageRenderTime 59ms CodeModel.GetById 24ms app.highlight 32ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llfloaterinspect.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 301 lines | 235 code | 29 blank | 37 comment | 32 complexity | 1716e1ebac4b6b45af3145dadc97338d MD5 | raw file
  1/** 
  2 * @file llfloaterinspect.cpp
  3 * @brief Floater for object inspection tool
  4 *
  5 * $LicenseInfo:firstyear=2006&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 "llfloaterinspect.h"
 30
 31#include "llfloaterreg.h"
 32#include "llfloatertools.h"
 33#include "llavataractions.h"
 34#include "llavatarnamecache.h"
 35#include "llscrolllistctrl.h"
 36#include "llscrolllistitem.h"
 37#include "llselectmgr.h"
 38#include "lltoolcomp.h"
 39#include "lltoolmgr.h"
 40#include "lltrans.h"
 41#include "llviewercontrol.h"
 42#include "llviewerobject.h"
 43#include "lluictrlfactory.h"
 44
 45//LLFloaterInspect* LLFloaterInspect::sInstance = NULL;
 46
 47LLFloaterInspect::LLFloaterInspect(const LLSD& key)
 48  : LLFloater(key),
 49	mDirty(FALSE)
 50{
 51	mCommitCallbackRegistrar.add("Inspect.OwnerProfile",	boost::bind(&LLFloaterInspect::onClickOwnerProfile, this));
 52	mCommitCallbackRegistrar.add("Inspect.CreatorProfile",	boost::bind(&LLFloaterInspect::onClickCreatorProfile, this));
 53	mCommitCallbackRegistrar.add("Inspect.SelectObject",	boost::bind(&LLFloaterInspect::onSelectObject, this));
 54}
 55
 56BOOL LLFloaterInspect::postBuild()
 57{
 58	mObjectList = getChild<LLScrollListCtrl>("object_list");
 59//	childSetAction("button owner",onClickOwnerProfile, this);
 60//	childSetAction("button creator",onClickCreatorProfile, this);
 61//	childSetCommitCallback("object_list", onSelectObject, NULL);
 62	
 63	refresh();
 64	
 65	return TRUE;
 66}
 67
 68LLFloaterInspect::~LLFloaterInspect(void)
 69{
 70	if(!LLFloaterReg::instanceVisible("build"))
 71	{
 72		if(LLToolMgr::getInstance()->getBaseTool() == LLToolCompInspect::getInstance())
 73		{
 74			LLToolMgr::getInstance()->clearTransientTool();
 75		}
 76		// Switch back to basic toolset
 77		LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);	
 78	}
 79	else
 80	{
 81		LLFloaterReg::showInstance("build", LLSD(), TRUE);
 82	}
 83	//sInstance = NULL;
 84}
 85
 86void LLFloaterInspect::onOpen(const LLSD& key)
 87{
 88	BOOL forcesel = LLSelectMgr::getInstance()->setForceSelection(TRUE);
 89	LLToolMgr::getInstance()->setTransientTool(LLToolCompInspect::getInstance());
 90	LLSelectMgr::getInstance()->setForceSelection(forcesel);	// restore previouis value
 91	mObjectSelection = LLSelectMgr::getInstance()->getSelection();
 92	refresh();
 93}
 94void LLFloaterInspect::onClickCreatorProfile()
 95{
 96	if(mObjectList->getAllSelected().size() == 0)
 97	{
 98		return;
 99	}
100	LLScrollListItem* first_selected =mObjectList->getFirstSelected();
101
102	if (first_selected)
103	{
104		struct f : public LLSelectedNodeFunctor
105		{
106			LLUUID obj_id;
107			f(const LLUUID& id) : obj_id(id) {}
108			virtual bool apply(LLSelectNode* node)
109			{
110				return (obj_id == node->getObject()->getID());
111			}
112		} func(first_selected->getUUID());
113		LLSelectNode* node = mObjectSelection->getFirstNode(&func);
114		if(node)
115		{
116			LLAvatarActions::showProfile(node->mPermissions->getCreator());
117		}
118	}
119}
120
121void LLFloaterInspect::onClickOwnerProfile()
122{
123	if(mObjectList->getAllSelected().size() == 0) return;
124	LLScrollListItem* first_selected =mObjectList->getFirstSelected();
125
126	if (first_selected)
127	{
128		LLUUID selected_id = first_selected->getUUID();
129		struct f : public LLSelectedNodeFunctor
130		{
131			LLUUID obj_id;
132			f(const LLUUID& id) : obj_id(id) {}
133			virtual bool apply(LLSelectNode* node)
134			{
135				return (obj_id == node->getObject()->getID());
136			}
137		} func(selected_id);
138		LLSelectNode* node = mObjectSelection->getFirstNode(&func);
139		if(node)
140		{
141			const LLUUID& owner_id = node->mPermissions->getOwner();
142			LLAvatarActions::showProfile(owner_id);
143		}
144	}
145}
146
147void LLFloaterInspect::onSelectObject()
148{
149	if(LLFloaterInspect::getSelectedUUID() != LLUUID::null)
150	{
151		getChildView("button owner")->setEnabled(true);
152		getChildView("button creator")->setEnabled(true);
153	}
154}
155
156LLUUID LLFloaterInspect::getSelectedUUID()
157{
158	if(mObjectList->getAllSelected().size() > 0)
159	{
160		LLScrollListItem* first_selected =mObjectList->getFirstSelected();
161		if (first_selected)
162		{
163			return first_selected->getUUID();
164		}
165		
166	}
167	return LLUUID::null;
168}
169
170void LLFloaterInspect::onGetAvNameCallback(const LLUUID& idCreator, const LLAvatarName& av_name, void* FloaterPtr)
171{
172	if (FloaterPtr)
173	{
174		LLFloaterInspect* floater = (LLFloaterInspect*)FloaterPtr;
175		floater->dirty();
176	}
177}
178
179void LLFloaterInspect::refresh()
180{
181	LLUUID creator_id;
182	std::string creator_name;
183	S32 pos = mObjectList->getScrollPos();
184	getChildView("button owner")->setEnabled(false);
185	getChildView("button creator")->setEnabled(false);
186	LLUUID selected_uuid;
187	S32 selected_index = mObjectList->getFirstSelectedIndex();
188	if(selected_index > -1)
189	{
190		LLScrollListItem* first_selected =
191			mObjectList->getFirstSelected();
192		if (first_selected)
193		{
194			selected_uuid = first_selected->getUUID();
195		}
196	}
197	mObjectList->operateOnAll(LLScrollListCtrl::OP_DELETE);
198	//List all transient objects, then all linked objects
199
200	for (LLObjectSelection::valid_iterator iter = mObjectSelection->valid_begin();
201		 iter != mObjectSelection->valid_end(); iter++)
202	{
203		LLSelectNode* obj = *iter;
204		LLSD row;
205		std::string owner_name, creator_name;
206
207		if (obj->mCreationDate == 0)
208		{	// Don't have valid information from the server, so skip this one
209			continue;
210		}
211
212		time_t timestamp = (time_t) (obj->mCreationDate/1000000);
213		std::string timeStr = getString("timeStamp");
214		LLSD substitution;
215		substitution["datetime"] = (S32) timestamp;
216		LLStringUtil::format (timeStr, substitution);
217
218		const LLUUID& idOwner = obj->mPermissions->getOwner();
219		const LLUUID& idCreator = obj->mPermissions->getCreator();
220		LLAvatarName av_name;
221
222		// Only work with the names if we actually get a result
223		// from the name cache. If not, defer setting the
224		// actual name and set a placeholder.
225		if (LLAvatarNameCache::get(idOwner, &av_name))
226		{
227			owner_name = av_name.getCompleteName();
228		}
229		else
230		{
231			owner_name = LLTrans::getString("RetrievingData");
232			LLAvatarNameCache::get(idOwner, boost::bind(&LLFloaterInspect::onGetAvNameCallback, _1, _2, this));
233		}
234
235		if (LLAvatarNameCache::get(idCreator, &av_name))
236		{
237			creator_name = av_name.getCompleteName();
238		}
239		else
240		{
241			creator_name = LLTrans::getString("RetrievingData");
242			LLAvatarNameCache::get(idCreator, boost::bind(&LLFloaterInspect::onGetAvNameCallback, _1, _2, this));
243		}
244		
245		row["id"] = obj->getObject()->getID();
246		row["columns"][0]["column"] = "object_name";
247		row["columns"][0]["type"] = "text";
248		// make sure we're either at the top of the link chain
249		// or top of the editable chain, for attachments
250		if(!(obj->getObject()->isRoot() || obj->getObject()->isRootEdit()))
251		{
252			row["columns"][0]["value"] = std::string("   ") + obj->mName;
253		}
254		else
255		{
256			row["columns"][0]["value"] = obj->mName;
257		}
258		row["columns"][1]["column"] = "owner_name";
259		row["columns"][1]["type"] = "text";
260		row["columns"][1]["value"] = owner_name;
261		row["columns"][2]["column"] = "creator_name";
262		row["columns"][2]["type"] = "text";
263		row["columns"][2]["value"] = creator_name;
264		row["columns"][3]["column"] = "creation_date";
265		row["columns"][3]["type"] = "text";
266		row["columns"][3]["value"] = timeStr;
267		mObjectList->addElement(row, ADD_TOP);
268	}
269	if(selected_index > -1 && mObjectList->getItemIndex(selected_uuid) == selected_index)
270	{
271		mObjectList->selectNthItem(selected_index);
272	}
273	else
274	{
275		mObjectList->selectNthItem(0);
276	}
277	onSelectObject();
278	mObjectList->setScrollPos(pos);
279}
280
281void LLFloaterInspect::onFocusReceived()
282{
283	LLToolMgr::getInstance()->setTransientTool(LLToolCompInspect::getInstance());
284	LLFloater::onFocusReceived();
285}
286
287void LLFloaterInspect::dirty()
288{
289	setDirty();
290}
291
292void LLFloaterInspect::draw()
293{
294	if (mDirty)
295	{
296		refresh();
297		mDirty = FALSE;
298	}
299
300	LLFloater::draw();
301}