llfloatertopobjects.cpp 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. /**
  2. * @file llfloatertopobjects.cpp
  3. * @brief Shows top colliders, top scripts, etc.
  4. *
  5. * $LicenseInfo:firstyear=2005&license=viewergpl$
  6. *
  7. * Copyright (c) 2005-2009, 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 "llfloatertopobjects.h"
  34. #include "lllineeditor.h"
  35. #include "llparcel.h" // For RT_NONE
  36. #include "llscrolllistctrl.h"
  37. #include "lluictrlfactory.h"
  38. #include "llmessage.h"
  39. #include "llagent.h"
  40. #include "lltracker.h"
  41. #include "llviewermessage.h" // For formatted_time()
  42. #include "llviewerregion.h"
  43. LLFloaterTopObjects::LLFloaterTopObjects(const LLSD&)
  44. : mInitialized(false),
  45. mCurrentMode(STAT_REPORT_TOP_SCRIPTS),
  46. mFlags(0),
  47. mTotalScore(0.f)
  48. {
  49. LLUICtrlFactory::getInstance()->buildFloater(this,
  50. "floater_top_objects.xml");
  51. }
  52. //virtual
  53. bool LLFloaterTopObjects::postBuild()
  54. {
  55. mObjectsList = getChild<LLScrollListCtrl>("objects_list");
  56. mObjectsList->setCommitOnSelectionChange(true);
  57. mObjectsList->setCommitCallback(onCommitObjectsList);
  58. mObjectsList->setDoubleClickCallback(onClickShowBeacon);
  59. mObjectsList->setCallbackUserData(this);
  60. mObjectsList->setFocus(true);
  61. childSetAction("show_beacon_btn", onClickShowBeacon, this);
  62. childSetAction("return_selected_btn", onReturnSelected, this);
  63. childSetAction("return_all_btn", onReturnAll, this);
  64. childSetAction("disable_selected_btn", onDisableSelected, this);
  65. childSetAction("disable_all_btn", onDisableAll, this);
  66. childSetAction("refresh_btn", onRefresh, this);
  67. childSetAction("filter_object_btn", onGetByObjectNameClicked, this);
  68. childSetAction("filter_owner_btn", onGetByOwnerNameClicked, this);
  69. setDefaultBtn("show_beacon_btn");
  70. #if 0
  71. LLLineEditor* line_editor = getChild<LLLineEditor>("owner_name_editor");
  72. if (line_editor)
  73. {
  74. line_editor->setCommitOnFocusLost(false);
  75. line_editor->setCommitCallback(onGetByOwnerName);
  76. line_editor->setCallbackUserData(this);
  77. }
  78. line_editor = getChild<LLLineEditor>("object_name_editor");
  79. if (line_editor)
  80. {
  81. line_editor->setCommitOnFocusLost(false);
  82. line_editor->setCommitCallback(onGetByObjectName);
  83. line_editor->setCallbackUserData(this);
  84. }
  85. #endif
  86. center();
  87. return true;
  88. }
  89. void LLFloaterTopObjects::updateSelectionInfo()
  90. {
  91. const LLUUID& object_id = mObjectsList->getCurrentID();
  92. if (object_id.isNull()) return;
  93. std::string id_str = object_id.asString();
  94. childSetValue("id_editor", LLSD(id_str));
  95. childSetValue("object_name_editor",
  96. mObjectsList->getFirstSelected()->getColumn(1)->getValue().asString());
  97. childSetValue("owner_name_editor",
  98. mObjectsList->getFirstSelected()->getColumn(2)->getValue().asString());
  99. }
  100. void LLFloaterTopObjects::doToObjects(S32 action, bool all)
  101. {
  102. LLMessageSystem* msg = gMessageSystemp;
  103. LLViewerRegion* region = gAgent.getRegion();
  104. if (!region || !msg) return;
  105. if (mObjectsList->getItemCount() == 0) return;
  106. bool start_message = true;
  107. for (S32 i = 0, count = mObjectListIDs.size(); i < count; ++i)
  108. {
  109. const LLUUID& task_id = mObjectListIDs[i];
  110. if (!all && !mObjectsList->isSelected(task_id))
  111. {
  112. // Selected only
  113. continue;
  114. }
  115. if (start_message)
  116. {
  117. if (action == ACTION_RETURN)
  118. {
  119. msg->newMessageFast(_PREHASH_ParcelReturnObjects);
  120. }
  121. else
  122. {
  123. msg->newMessageFast(_PREHASH_ParcelDisableObjects);
  124. }
  125. msg->nextBlockFast(_PREHASH_AgentData);
  126. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  127. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  128. msg->nextBlockFast(_PREHASH_ParcelData);
  129. msg->addS32Fast(_PREHASH_LocalID, -1); // Whole region
  130. msg->addS32Fast(_PREHASH_ReturnType, RT_NONE);
  131. start_message = false;
  132. }
  133. msg->nextBlockFast(_PREHASH_TaskIDs);
  134. msg->addUUIDFast(_PREHASH_TaskID, task_id);
  135. if (msg->isSendFullFast(_PREHASH_TaskIDs))
  136. {
  137. msg->sendReliable(region->getHost());
  138. start_message = true;
  139. }
  140. }
  141. if (!start_message)
  142. {
  143. msg->sendReliable(region->getHost());
  144. }
  145. }
  146. void LLFloaterTopObjects::showBeacon()
  147. {
  148. LLScrollListItem* first_selected = mObjectsList->getFirstSelected();
  149. if (!first_selected) return;
  150. std::string name = first_selected->getColumn(1)->getValue().asString();
  151. std::string pos_string = first_selected->getColumn(3)->getValue().asString();
  152. F32 x, y, z;
  153. S32 matched = sscanf(pos_string.c_str(), "<%g,%g,%g>", &x, &y, &z);
  154. if (matched != 3) return;
  155. LLVector3 pos_agent(x, y, z);
  156. LLVector3d pos_global = gAgent.getPosGlobalFromAgent(pos_agent);
  157. gTracker.trackLocation(pos_global, name, "", LLTracker::LOCATION_ITEM);
  158. }
  159. void LLFloaterTopObjects::handleReply(LLMessageSystem* msg, void** data)
  160. {
  161. U32 request_flags;
  162. msg->getU32Fast(_PREHASH_RequestData, _PREHASH_RequestFlags,
  163. request_flags);
  164. U32 total_count;
  165. msg->getU32Fast(_PREHASH_RequestData, _PREHASH_TotalObjectCount,
  166. total_count);
  167. msg->getU32Fast(_PREHASH_RequestData, _PREHASH_ReportType, mCurrentMode);
  168. U64 total_memory = 0;
  169. std::string location, name_buf, owner_buf;
  170. LLUUID task_id;
  171. S32 block_count = msg->getNumberOfBlocks("ReportData");
  172. for (S32 block = 0; block < block_count; ++block)
  173. {
  174. U32 task_local_id;
  175. msg->getU32Fast(_PREHASH_ReportData, _PREHASH_TaskLocalID,
  176. task_local_id, block);
  177. task_id.setNull();
  178. msg->getUUIDFast(_PREHASH_ReportData, _PREHASH_TaskID, task_id, block);
  179. F32 pos_x, pos_y, pos_z;
  180. msg->getF32Fast(_PREHASH_ReportData, _PREHASH_LocationX, pos_x, block);
  181. msg->getF32Fast(_PREHASH_ReportData, _PREHASH_LocationY, pos_y, block);
  182. msg->getF32Fast(_PREHASH_ReportData, _PREHASH_LocationZ, pos_z, block);
  183. F32 score;
  184. msg->getF32Fast(_PREHASH_ReportData, _PREHASH_Score, score, block);
  185. name_buf.clear();
  186. msg->getStringFast(_PREHASH_ReportData, _PREHASH_TaskName, name_buf,
  187. block);
  188. owner_buf.clear();
  189. msg->getStringFast(_PREHASH_ReportData, _PREHASH_OwnerName, owner_buf,
  190. block);
  191. U32 time_stamp = 0;
  192. F32 mono_score = 0.f;
  193. S32 public_urls = 0;
  194. F32 script_size = 0.f;
  195. location.clear();
  196. bool have_extended_data = false;
  197. if (msg->has("DataExtended"))
  198. {
  199. have_extended_data = true;
  200. msg->getU32("DataExtended", "TimeStamp", time_stamp, block);
  201. msg->getF32("DataExtended", "MonoScore", mono_score, block);
  202. msg->getS32("DataExtended", "PublicURLs", public_urls, block);
  203. msg->getString("DataExtended", "ParcelName", location, block);
  204. msg->getF32("DataExtended", "Size", script_size, block);
  205. total_memory += (U64)script_size;
  206. }
  207. LLSD element;
  208. element["id"] = task_id;
  209. element["object_name"] = name_buf;
  210. element["owner_name"] = owner_buf;
  211. element["columns"][0]["column"] = "score";
  212. element["columns"][0]["value"] = llformat("%0.3f", score);
  213. element["columns"][0]["font"] = "SANSSERIF";
  214. element["columns"][1]["column"] = "name";
  215. element["columns"][1]["value"] = name_buf;
  216. element["columns"][1]["font"] = "SANSSERIF";
  217. element["columns"][2]["column"] = "owner";
  218. element["columns"][2]["value"] = owner_buf;
  219. element["columns"][2]["font"] = "SANSSERIF";
  220. element["columns"][3]["column"] = "location";
  221. if (location.empty())
  222. {
  223. location = llformat("<%0.1f,%0.1f,%0.1f>", pos_x, pos_y, pos_z);
  224. }
  225. else
  226. {
  227. location = llformat("<%0.1f,%0.1f,%0.1f> ", pos_x, pos_y, pos_z) +
  228. location;
  229. }
  230. element["columns"][3]["value"] = location;
  231. element["columns"][3]["font"] = "SANSSERIF";
  232. element["columns"][4]["column"] = "time";
  233. element["columns"][4]["value"] = formatted_time((time_t)time_stamp);
  234. element["columns"][4]["font"] = "SANSSERIF";
  235. if (mCurrentMode == STAT_REPORT_TOP_SCRIPTS && have_extended_data)
  236. {
  237. element["columns"][5]["column"] = "mono_time";
  238. element["columns"][5]["value"] = llformat("%0.3f", mono_score);
  239. element["columns"][5]["font"] = "SANSSERIF";
  240. element["columns"][6]["column"] = "memory";
  241. element["columns"][6]["value"] = llformat("%d",
  242. (S32)script_size / 1024);
  243. element["columns"][6]["font"] = "SANSSERIF";
  244. element["columns"][7]["column"] = "URLs";
  245. element["columns"][7]["value"] = llformat("%d", public_urls);
  246. element["columns"][7]["font"] = "SANSSERIF";
  247. }
  248. mObjectsList->addElement(element);
  249. mObjectListData.append(element);
  250. mObjectListIDs.emplace_back(task_id);
  251. mTotalScore += score;
  252. }
  253. if (total_count == 0 && mObjectsList->getItemCount() == 0)
  254. {
  255. mObjectsList->addCommentText(getString("none_descriptor"));
  256. }
  257. else
  258. {
  259. mObjectsList->selectFirstItem();
  260. }
  261. if (mCurrentMode == STAT_REPORT_TOP_SCRIPTS)
  262. {
  263. setTitle(getString("top_scripts_title"));
  264. mObjectsList->setColumnLabel("score",
  265. getString("scripts_score_label"));
  266. mObjectsList->setColumnLabel("mono_time",
  267. getString("scripts_mono_time_label"));
  268. LLUIString format = getString("top_scripts_text");
  269. total_memory /= 1024;
  270. format.setArg("[MEMORY]", llformat("%d", total_memory));
  271. format.setArg("[COUNT]", llformat("%d", total_count));
  272. format.setArg("[TIME]", llformat("%0.1f", mTotalScore));
  273. childSetValue("title_text", LLSD(format));
  274. }
  275. else
  276. {
  277. setTitle(getString("top_colliders_title"));
  278. mObjectsList->setColumnLabel("score",
  279. getString("colliders_score_label"));
  280. mObjectsList->setColumnLabel("mono_time", "");
  281. LLUIString format = getString("top_colliders_text");
  282. format.setArg("[COUNT]", llformat("%d", total_count));
  283. childSetValue("title_text", LLSD(format));
  284. }
  285. }
  286. //static
  287. void LLFloaterTopObjects::handleLandReply(LLMessageSystem* msg, void** data)
  288. {
  289. // Make sure dialog is on screen
  290. LLFloaterTopObjects* self = showInstance();
  291. if (!self) return; // Could be out of memory...
  292. self->handleReply(msg, data);
  293. // *HACK: for some reason sometimes top scripts originally comes back with
  294. // no results even though they are there
  295. if (!self->mObjectListIDs.size() && !self->mInitialized)
  296. {
  297. self->onRefresh(self);
  298. self->mInitialized = true;
  299. }
  300. }
  301. //static
  302. void LLFloaterTopObjects::setMode(U32 mode)
  303. {
  304. LLFloaterTopObjects* self = findInstance();
  305. if (self)
  306. {
  307. self->mCurrentMode = mode;
  308. }
  309. }
  310. //static
  311. void LLFloaterTopObjects::onCommitObjectsList(LLUICtrl* ctrl, void* data)
  312. {
  313. LLFloaterTopObjects* self = (LLFloaterTopObjects*)data;
  314. if (self)
  315. {
  316. self->updateSelectionInfo();
  317. }
  318. }
  319. //static
  320. void LLFloaterTopObjects::onClickShowBeacon(void* data)
  321. {
  322. LLFloaterTopObjects* self = (LLFloaterTopObjects*)data;
  323. if (self)
  324. {
  325. self->showBeacon();
  326. }
  327. }
  328. //static
  329. bool LLFloaterTopObjects::callbackReturnAll(const LLSD& notification,
  330. const LLSD& response)
  331. {
  332. LLFloaterTopObjects* self = findInstance();
  333. if (self && LLNotification::getSelectedOption(notification, response) == 0)
  334. {
  335. self->doToObjects(ACTION_RETURN, true);
  336. }
  337. return false;
  338. }
  339. //static
  340. void LLFloaterTopObjects::onReturnAll(void*)
  341. {
  342. gNotifications.add("ReturnAllTopObjects", LLSD(), LLSD(),
  343. callbackReturnAll);
  344. }
  345. //static
  346. void LLFloaterTopObjects::onReturnSelected(void* data)
  347. {
  348. LLFloaterTopObjects* self = (LLFloaterTopObjects*)data;
  349. if (self)
  350. {
  351. self->doToObjects(ACTION_RETURN, false);
  352. }
  353. }
  354. //static
  355. bool LLFloaterTopObjects::callbackDisableAll(const LLSD& notification,
  356. const LLSD& response)
  357. {
  358. LLFloaterTopObjects* self = findInstance();
  359. if (self && LLNotification::getSelectedOption(notification, response) == 0)
  360. {
  361. self->doToObjects(ACTION_DISABLE, true);
  362. }
  363. return false;
  364. }
  365. void LLFloaterTopObjects::onDisableAll(void*)
  366. {
  367. gNotifications.add("DisableAllTopObjects", LLSD(), LLSD(),
  368. callbackDisableAll);
  369. }
  370. void LLFloaterTopObjects::onDisableSelected(void* data)
  371. {
  372. LLFloaterTopObjects* self = (LLFloaterTopObjects*)data;
  373. if (self)
  374. {
  375. self->doToObjects(ACTION_DISABLE, false);
  376. }
  377. }
  378. //static
  379. void LLFloaterTopObjects::clearList()
  380. {
  381. LLFloaterTopObjects* self = findInstance();
  382. if (self)
  383. {
  384. self->mObjectsList->deleteAllItems();
  385. self->mObjectListData.clear();
  386. self->mObjectListIDs.clear();
  387. self->mTotalScore = 0.f;
  388. }
  389. }
  390. //static
  391. void LLFloaterTopObjects::onRefresh(void* data)
  392. {
  393. U32 mode = STAT_REPORT_TOP_SCRIPTS;
  394. U32 flags = 0;
  395. std::string filter;
  396. LLFloaterTopObjects* self = (LLFloaterTopObjects*)data;
  397. if (self)
  398. {
  399. mode = self->mCurrentMode;
  400. flags = self->mFlags;
  401. filter = self->mFilter;
  402. self->clearList();
  403. }
  404. LLMessageSystem* msg = gMessageSystemp;
  405. msg->newMessageFast(_PREHASH_LandStatRequest);
  406. msg->nextBlockFast(_PREHASH_AgentData);
  407. msg->addUUIDFast(_PREHASH_AgentID, gAgentID);
  408. msg->addUUIDFast(_PREHASH_SessionID, gAgentSessionID);
  409. msg->nextBlockFast(_PREHASH_RequestData);
  410. msg->addU32Fast(_PREHASH_ReportType, mode);
  411. msg->addU32Fast(_PREHASH_RequestFlags, flags);
  412. msg->addStringFast(_PREHASH_Filter, filter);
  413. msg->addS32Fast(_PREHASH_ParcelLocalID, 0);
  414. msg->sendReliable(gAgent.getRegionHost());
  415. if (self)
  416. {
  417. self->mFilter.clear();
  418. self->mFlags = 0;
  419. }
  420. }
  421. //static
  422. void LLFloaterTopObjects::sendRefreshRequest()
  423. {
  424. onRefresh(findInstance());
  425. }
  426. //static
  427. void LLFloaterTopObjects::onGetByObjectName(LLUICtrl*, void* data)
  428. {
  429. LLFloaterTopObjects* self = (LLFloaterTopObjects*)data;
  430. if (self)
  431. {
  432. self->mFlags = STAT_FILTER_BY_OBJECT;
  433. self->mFilter = self->childGetText("object_name_editor");
  434. onRefresh(data);
  435. }
  436. }
  437. //static
  438. void LLFloaterTopObjects::onGetByOwnerNameClicked(void* data)
  439. {
  440. onGetByOwnerName(NULL, data);
  441. }
  442. //static
  443. void LLFloaterTopObjects::onGetByOwnerName(LLUICtrl*, void* data)
  444. {
  445. LLFloaterTopObjects* self = (LLFloaterTopObjects*)data;
  446. if (self)
  447. {
  448. self->mFlags = STAT_FILTER_BY_OWNER;
  449. self->mFilter = self->childGetText("owner_name_editor");
  450. onRefresh(data);
  451. }
  452. }
  453. //static
  454. void LLFloaterTopObjects::onGetByObjectNameClicked(void* data)
  455. {
  456. onGetByObjectName(NULL, data);
  457. }