llfloaterinspect.cpp
上传用户:king477883
上传日期:2021-03-01
资源大小:9553k
文件大小:8k
源码类别:

游戏引擎

开发平台:

C++ Builder

  1. /** 
  2.  * @file llfloaterinspect.cpp
  3.  * @brief Floater for object inspection tool
  4.  *
  5.  * $LicenseInfo:firstyear=2006&license=viewergpl$
  6.  * 
  7.  * Copyright (c) 2006-2010, Linden Research, Inc.
  8.  * 
  9.  * Second Life Viewer Source Code
  10.  * The source code in this file ("Source Code") is provided by Linden Lab
  11.  * to you under the terms of the GNU General Public License, version 2.0
  12.  * ("GPL"), unless you have obtained a separate licensing agreement
  13.  * ("Other License"), formally executed by you and Linden Lab.  Terms of
  14.  * the GPL can be found in doc/GPL-license.txt in this distribution, or
  15.  * online at http://secondlifegrid.net/programs/open_source/licensing/gplv2
  16.  * 
  17.  * There are special exceptions to the terms and conditions of the GPL as
  18.  * it is applied to this Source Code. View the full text of the exception
  19.  * in the file doc/FLOSS-exception.txt in this software distribution, or
  20.  * online at
  21.  * http://secondlifegrid.net/programs/open_source/licensing/flossexception
  22.  * 
  23.  * By copying, modifying or distributing this software, you acknowledge
  24.  * that you have read and understood your obligations described above,
  25.  * and agree to abide by those obligations.
  26.  * 
  27.  * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
  28.  * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
  29.  * COMPLETENESS OR PERFORMANCE.
  30.  * $/LicenseInfo$
  31.  */
  32. #include "llviewerprecompiledheaders.h"
  33. #include "llfloaterinspect.h"
  34. #include "llfloaterreg.h"
  35. #include "llfloatertools.h"
  36. #include "llavataractions.h"
  37. #include "llcachename.h"
  38. #include "llscrolllistctrl.h"
  39. #include "llscrolllistitem.h"
  40. #include "llselectmgr.h"
  41. #include "lltoolcomp.h"
  42. #include "lltoolmgr.h"
  43. #include "llviewercontrol.h"
  44. #include "llviewerobject.h"
  45. #include "lluictrlfactory.h"
  46. //LLFloaterInspect* LLFloaterInspect::sInstance = NULL;
  47. LLFloaterInspect::LLFloaterInspect(const LLSD& key)
  48.   : LLFloater(key),
  49. mDirty(FALSE)
  50. {
  51. //LLUICtrlFactory::getInstance()->buildFloater(this, "floater_inspect.xml");
  52. mCommitCallbackRegistrar.add("Inspect.OwnerProfile", boost::bind(&LLFloaterInspect::onClickOwnerProfile, this));
  53. mCommitCallbackRegistrar.add("Inspect.CreatorProfile", boost::bind(&LLFloaterInspect::onClickCreatorProfile, this));
  54. mCommitCallbackRegistrar.add("Inspect.SelectObject", boost::bind(&LLFloaterInspect::onSelectObject, this));
  55. }
  56. BOOL 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. refresh();
  63. return TRUE;
  64. }
  65. LLFloaterInspect::~LLFloaterInspect(void)
  66. {
  67. if(!LLFloaterReg::instanceVisible("build"))
  68. {
  69. if(LLToolMgr::getInstance()->getBaseTool() == LLToolCompInspect::getInstance())
  70. {
  71. LLToolMgr::getInstance()->clearTransientTool();
  72. }
  73. // Switch back to basic toolset
  74. LLToolMgr::getInstance()->setCurrentToolset(gBasicToolset);
  75. }
  76. else
  77. {
  78. LLFloaterReg::showInstance("build", LLSD(), TRUE);
  79. }
  80. //sInstance = NULL;
  81. }
  82. void LLFloaterInspect::onOpen(const LLSD& key)
  83. {
  84. BOOL forcesel = LLSelectMgr::getInstance()->setForceSelection(TRUE);
  85. LLToolMgr::getInstance()->setTransientTool(LLToolCompInspect::getInstance());
  86. LLSelectMgr::getInstance()->setForceSelection(forcesel); // restore previouis value
  87. mObjectSelection = LLSelectMgr::getInstance()->getSelection();
  88. refresh();
  89. }
  90. void LLFloaterInspect::onClickCreatorProfile()
  91. {
  92. if(mObjectList->getAllSelected().size() == 0)
  93. {
  94. return;
  95. }
  96. LLScrollListItem* first_selected =mObjectList->getFirstSelected();
  97. if (first_selected)
  98. {
  99. struct f : public LLSelectedNodeFunctor
  100. {
  101. LLUUID obj_id;
  102. f(const LLUUID& id) : obj_id(id) {}
  103. virtual bool apply(LLSelectNode* node)
  104. {
  105. return (obj_id == node->getObject()->getID());
  106. }
  107. } func(first_selected->getUUID());
  108. LLSelectNode* node = mObjectSelection->getFirstNode(&func);
  109. if(node)
  110. {
  111. LLAvatarActions::showProfile(node->mPermissions->getCreator());
  112. }
  113. }
  114. }
  115. void LLFloaterInspect::onClickOwnerProfile()
  116. {
  117. if(mObjectList->getAllSelected().size() == 0) return;
  118. LLScrollListItem* first_selected =mObjectList->getFirstSelected();
  119. if (first_selected)
  120. {
  121. LLUUID selected_id = first_selected->getUUID();
  122. struct f : public LLSelectedNodeFunctor
  123. {
  124. LLUUID obj_id;
  125. f(const LLUUID& id) : obj_id(id) {}
  126. virtual bool apply(LLSelectNode* node)
  127. {
  128. return (obj_id == node->getObject()->getID());
  129. }
  130. } func(selected_id);
  131. LLSelectNode* node = mObjectSelection->getFirstNode(&func);
  132. if(node)
  133. {
  134. const LLUUID& owner_id = node->mPermissions->getOwner();
  135. LLAvatarActions::showProfile(owner_id);
  136. }
  137. }
  138. }
  139. void LLFloaterInspect::onSelectObject()
  140. {
  141. if(LLFloaterInspect::getSelectedUUID() != LLUUID::null)
  142. {
  143. childSetEnabled("button owner", true);
  144. childSetEnabled("button creator", true);
  145. }
  146. }
  147. LLUUID LLFloaterInspect::getSelectedUUID()
  148. {
  149. if(mObjectList->getAllSelected().size() > 0)
  150. {
  151. LLScrollListItem* first_selected =mObjectList->getFirstSelected();
  152. if (first_selected)
  153. {
  154. return first_selected->getUUID();
  155. }
  156. }
  157. return LLUUID::null;
  158. }
  159. void LLFloaterInspect::refresh()
  160. {
  161. LLUUID creator_id;
  162. std::string creator_name;
  163. S32 pos = mObjectList->getScrollPos();
  164. childSetEnabled("button owner", false);
  165. childSetEnabled("button creator", false);
  166. LLUUID selected_uuid;
  167. S32 selected_index = mObjectList->getFirstSelectedIndex();
  168. if(selected_index > -1)
  169. {
  170. LLScrollListItem* first_selected =
  171. mObjectList->getFirstSelected();
  172. if (first_selected)
  173. {
  174. selected_uuid = first_selected->getUUID();
  175. }
  176. }
  177. mObjectList->operateOnAll(LLScrollListCtrl::OP_DELETE);
  178. //List all transient objects, then all linked objects
  179. for (LLObjectSelection::valid_iterator iter = mObjectSelection->valid_begin();
  180.  iter != mObjectSelection->valid_end(); iter++)
  181. {
  182. LLSelectNode* obj = *iter;
  183. LLSD row;
  184. std::string owner_name, creator_name;
  185. if (obj->mCreationDate == 0)
  186. { // Don't have valid information from the server, so skip this one
  187. continue;
  188. }
  189. time_t timestamp = (time_t) (obj->mCreationDate/1000000);
  190. std::string timeStr = getString("timeStamp");
  191. LLSD substitution;
  192. substitution["datetime"] = (S32) timestamp;
  193. LLStringUtil::format (timeStr, substitution);
  194. gCacheName->getFullName(obj->mPermissions->getOwner(), owner_name);
  195. gCacheName->getFullName(obj->mPermissions->getCreator(), creator_name);
  196. row["id"] = obj->getObject()->getID();
  197. row["columns"][0]["column"] = "object_name";
  198. row["columns"][0]["type"] = "text";
  199. // make sure we're either at the top of the link chain
  200. // or top of the editable chain, for attachments
  201. if(!(obj->getObject()->isRoot() || obj->getObject()->isRootEdit()))
  202. {
  203. row["columns"][0]["value"] = std::string("   ") + obj->mName;
  204. }
  205. else
  206. {
  207. row["columns"][0]["value"] = obj->mName;
  208. }
  209. row["columns"][1]["column"] = "owner_name";
  210. row["columns"][1]["type"] = "text";
  211. row["columns"][1]["value"] = owner_name;
  212. row["columns"][2]["column"] = "creator_name";
  213. row["columns"][2]["type"] = "text";
  214. row["columns"][2]["value"] = creator_name;
  215. row["columns"][3]["column"] = "creation_date";
  216. row["columns"][3]["type"] = "text";
  217. row["columns"][3]["value"] = timeStr;
  218. mObjectList->addElement(row, ADD_TOP);
  219. }
  220. if(selected_index > -1 && mObjectList->getItemIndex(selected_uuid) == selected_index)
  221. {
  222. mObjectList->selectNthItem(selected_index);
  223. }
  224. else
  225. {
  226. mObjectList->selectNthItem(0);
  227. }
  228. onSelectObject();
  229. mObjectList->setScrollPos(pos);
  230. }
  231. void LLFloaterInspect::onFocusReceived()
  232. {
  233. LLToolMgr::getInstance()->setTransientTool(LLToolCompInspect::getInstance());
  234. LLFloater::onFocusReceived();
  235. }
  236. void LLFloaterInspect::dirty()
  237. {
  238. setDirty();
  239. }
  240. void LLFloaterInspect::draw()
  241. {
  242. if (mDirty)
  243. {
  244. refresh();
  245. mDirty = FALSE;
  246. }
  247. LLFloater::draw();
  248. }