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