PageRenderTime 72ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/indra/newview/llpanellandmarkinfo.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 510 lines | 360 code | 79 blank | 71 comment | 39 complexity | 843437fc8e22c0e300b85ce4915354d5 MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpanellandmarkinfo.cpp
  3. * @brief Displays landmark info in Side Tray.
  4. *
  5. * $LicenseInfo:firstyear=2009&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 "llpanellandmarkinfo.h"
  28. #include "llcombobox.h"
  29. #include "lliconctrl.h"
  30. #include "llinventoryfunctions.h"
  31. #include "lllineeditor.h"
  32. #include "lltextbox.h"
  33. #include "lltexteditor.h"
  34. #include "lltrans.h"
  35. #include "llagent.h"
  36. #include "llagentui.h"
  37. #include "lllandmarkactions.h"
  38. #include "llslurl.h"
  39. #include "llviewerinventory.h"
  40. #include "llviewerparcelmgr.h"
  41. #include "llviewerregion.h"
  42. //----------------------------------------------------------------------------
  43. // Aux types and methods
  44. //----------------------------------------------------------------------------
  45. typedef std::pair<LLUUID, std::string> folder_pair_t;
  46. static bool cmp_folders(const folder_pair_t& left, const folder_pair_t& right);
  47. static void collectLandmarkFolders(LLInventoryModel::cat_array_t& cats);
  48. static LLRegisterPanelClassWrapper<LLPanelLandmarkInfo> t_landmark_info("panel_landmark_info");
  49. // Statics for textures filenames
  50. static std::string icon_pg;
  51. static std::string icon_m;
  52. static std::string icon_r;
  53. LLPanelLandmarkInfo::LLPanelLandmarkInfo()
  54. : LLPanelPlaceInfo()
  55. {}
  56. // virtual
  57. LLPanelLandmarkInfo::~LLPanelLandmarkInfo()
  58. {}
  59. // virtual
  60. BOOL LLPanelLandmarkInfo::postBuild()
  61. {
  62. LLPanelPlaceInfo::postBuild();
  63. mOwner = getChild<LLTextBox>("owner");
  64. mCreator = getChild<LLTextBox>("creator");
  65. mCreated = getChild<LLTextBox>("created");
  66. mLandmarkTitle = getChild<LLTextBox>("title_value");
  67. mLandmarkTitleEditor = getChild<LLLineEditor>("title_editor");
  68. mNotesEditor = getChild<LLTextEditor>("notes_editor");
  69. mFolderCombo = getChild<LLComboBox>("folder_combo");
  70. icon_pg = getString("icon_PG");
  71. icon_m = getString("icon_M");
  72. icon_r = getString("icon_R");
  73. return TRUE;
  74. }
  75. // virtual
  76. void LLPanelLandmarkInfo::resetLocation()
  77. {
  78. LLPanelPlaceInfo::resetLocation();
  79. std::string loading = LLTrans::getString("LoadingData");
  80. mCreator->setText(loading);
  81. mOwner->setText(loading);
  82. mCreated->setText(loading);
  83. mLandmarkTitle->setText(LLStringUtil::null);
  84. mLandmarkTitleEditor->setText(LLStringUtil::null);
  85. mNotesEditor->setText(LLStringUtil::null);
  86. }
  87. // virtual
  88. void LLPanelLandmarkInfo::setInfoType(EInfoType type)
  89. {
  90. LLPanel* landmark_info_panel = getChild<LLPanel>("landmark_info_panel");
  91. bool is_info_type_create_landmark = type == CREATE_LANDMARK;
  92. landmark_info_panel->setVisible(type == LANDMARK);
  93. getChild<LLTextBox>("folder_label")->setVisible(is_info_type_create_landmark);
  94. mFolderCombo->setVisible(is_info_type_create_landmark);
  95. switch(type)
  96. {
  97. case CREATE_LANDMARK:
  98. {
  99. mCurrentTitle = getString("title_create_landmark");
  100. mLandmarkTitle->setVisible(FALSE);
  101. mLandmarkTitleEditor->setVisible(TRUE);
  102. mNotesEditor->setEnabled(TRUE);
  103. LLViewerParcelMgr* parcel_mgr = LLViewerParcelMgr::getInstance();
  104. std::string name = parcel_mgr->getAgentParcelName();
  105. LLVector3 agent_pos = gAgent.getPositionAgent();
  106. if (name.empty())
  107. {
  108. S32 region_x = llround(agent_pos.mV[VX]);
  109. S32 region_y = llround(agent_pos.mV[VY]);
  110. S32 region_z = llround(agent_pos.mV[VZ]);
  111. std::string region_name;
  112. LLViewerRegion* region = parcel_mgr->getSelectionRegion();
  113. if (region)
  114. {
  115. region_name = region->getName();
  116. }
  117. else
  118. {
  119. region_name = getString("unknown");
  120. }
  121. mLandmarkTitleEditor->setText(llformat("%s (%d, %d, %d)",
  122. region_name.c_str(), region_x, region_y, region_z));
  123. }
  124. else
  125. {
  126. mLandmarkTitleEditor->setText(name);
  127. }
  128. std::string desc;
  129. LLAgentUI::buildLocationString(desc, LLAgentUI::LOCATION_FORMAT_FULL, agent_pos);
  130. mNotesEditor->setText(desc);
  131. // Moved landmark creation here from LLPanelLandmarkInfo::processParcelInfo()
  132. // because we use only agent's current coordinates instead of waiting for
  133. // remote parcel request to complete.
  134. if (!LLLandmarkActions::landmarkAlreadyExists())
  135. {
  136. createLandmark(LLUUID());
  137. }
  138. }
  139. break;
  140. case LANDMARK:
  141. default:
  142. mCurrentTitle = getString("title_landmark");
  143. mLandmarkTitle->setVisible(TRUE);
  144. mLandmarkTitleEditor->setVisible(FALSE);
  145. mNotesEditor->setEnabled(FALSE);
  146. break;
  147. }
  148. populateFoldersList();
  149. // Prevent the floater from losing focus (if the sidepanel is undocked).
  150. setFocus(TRUE);
  151. LLPanelPlaceInfo::setInfoType(type);
  152. }
  153. // virtual
  154. void LLPanelLandmarkInfo::processParcelInfo(const LLParcelData& parcel_data)
  155. {
  156. LLPanelPlaceInfo::processParcelInfo(parcel_data);
  157. // HACK: Flag 0x2 == adult region,
  158. // Flag 0x1 == mature region, otherwise assume PG
  159. if (parcel_data.flags & 0x2)
  160. {
  161. mMaturityRatingIcon->setValue(icon_r);
  162. mMaturityRatingText->setText(LLViewerRegion::accessToString(SIM_ACCESS_ADULT));
  163. }
  164. else if (parcel_data.flags & 0x1)
  165. {
  166. mMaturityRatingIcon->setValue(icon_m);
  167. mMaturityRatingText->setText(LLViewerRegion::accessToString(SIM_ACCESS_MATURE));
  168. }
  169. else
  170. {
  171. mMaturityRatingIcon->setValue(icon_pg);
  172. mMaturityRatingText->setText(LLViewerRegion::accessToString(SIM_ACCESS_PG));
  173. }
  174. S32 region_x;
  175. S32 region_y;
  176. S32 region_z;
  177. // If the region position is zero, grab position from the global
  178. if(mPosRegion.isExactlyZero())
  179. {
  180. region_x = llround(parcel_data.global_x) % REGION_WIDTH_UNITS;
  181. region_y = llround(parcel_data.global_y) % REGION_WIDTH_UNITS;
  182. region_z = llround(parcel_data.global_z);
  183. }
  184. else
  185. {
  186. region_x = llround(mPosRegion.mV[VX]);
  187. region_y = llround(mPosRegion.mV[VY]);
  188. region_z = llround(mPosRegion.mV[VZ]);
  189. }
  190. LLSD info;
  191. info["update_verbs"] = true;
  192. info["global_x"] = parcel_data.global_x;
  193. info["global_y"] = parcel_data.global_y;
  194. info["global_z"] = parcel_data.global_z;
  195. notifyParent(info);
  196. }
  197. void LLPanelLandmarkInfo::displayItemInfo(const LLInventoryItem* pItem)
  198. {
  199. if (!pItem)
  200. return;
  201. if(!gCacheName)
  202. return;
  203. const LLPermissions& perm = pItem->getPermissions();
  204. //////////////////
  205. // CREATOR NAME //
  206. //////////////////
  207. if (pItem->getCreatorUUID().notNull())
  208. {
  209. // IDEVO
  210. LLUUID creator_id = pItem->getCreatorUUID();
  211. std::string name =
  212. LLSLURL("agent", creator_id, "inspect").getSLURLString();
  213. mCreator->setText(name);
  214. }
  215. else
  216. {
  217. mCreator->setText(getString("unknown"));
  218. }
  219. ////////////////
  220. // OWNER NAME //
  221. ////////////////
  222. if(perm.isOwned())
  223. {
  224. std::string name;
  225. if (perm.isGroupOwned())
  226. {
  227. LLUUID group_id = perm.getGroup();
  228. name = LLSLURL("group", group_id, "inspect").getSLURLString();
  229. }
  230. else
  231. {
  232. LLUUID owner_id = perm.getOwner();
  233. name = LLSLURL("agent", owner_id, "inspect").getSLURLString();
  234. }
  235. mOwner->setText(name);
  236. }
  237. else
  238. {
  239. mOwner->setText(getString("public"));
  240. }
  241. //////////////////
  242. // ACQUIRE DATE //
  243. //////////////////
  244. time_t time_utc = pItem->getCreationDate();
  245. if (0 == time_utc)
  246. {
  247. mCreated->setText(getString("unknown"));
  248. }
  249. else
  250. {
  251. std::string timeStr = getString("acquired_date");
  252. LLSD substitution;
  253. substitution["datetime"] = (S32) time_utc;
  254. LLStringUtil::format (timeStr, substitution);
  255. mCreated->setText(timeStr);
  256. }
  257. mLandmarkTitle->setText(pItem->getName());
  258. mLandmarkTitleEditor->setText(pItem->getName());
  259. mNotesEditor->setText(pItem->getDescription());
  260. }
  261. void LLPanelLandmarkInfo::toggleLandmarkEditMode(BOOL enabled)
  262. {
  263. // If switching to edit mode while creating landmark
  264. // the "Create Landmark" title remains.
  265. if (enabled && mInfoType != CREATE_LANDMARK)
  266. {
  267. mTitle->setText(getString("title_edit_landmark"));
  268. }
  269. else
  270. {
  271. mTitle->setText(mCurrentTitle);
  272. mLandmarkTitle->setText(mLandmarkTitleEditor->getText());
  273. }
  274. if (mNotesEditor->getReadOnly() == (enabled == TRUE))
  275. {
  276. mLandmarkTitle->setVisible(!enabled);
  277. mLandmarkTitleEditor->setVisible(enabled);
  278. mNotesEditor->setReadOnly(!enabled);
  279. mFolderCombo->setVisible(enabled);
  280. getChild<LLTextBox>("folder_label")->setVisible(enabled);
  281. // HACK: To change the text color in a text editor
  282. // when it was enabled/disabled we set the text once again.
  283. mNotesEditor->setText(mNotesEditor->getText());
  284. }
  285. // Prevent the floater from losing focus (if the sidepanel is undocked).
  286. setFocus(TRUE);
  287. }
  288. const std::string& LLPanelLandmarkInfo::getLandmarkTitle() const
  289. {
  290. return mLandmarkTitleEditor->getText();
  291. }
  292. const std::string LLPanelLandmarkInfo::getLandmarkNotes() const
  293. {
  294. return mNotesEditor->getText();
  295. }
  296. const LLUUID LLPanelLandmarkInfo::getLandmarkFolder() const
  297. {
  298. return mFolderCombo->getValue().asUUID();
  299. }
  300. BOOL LLPanelLandmarkInfo::setLandmarkFolder(const LLUUID& id)
  301. {
  302. return mFolderCombo->setCurrentByID(id);
  303. }
  304. void LLPanelLandmarkInfo::createLandmark(const LLUUID& folder_id)
  305. {
  306. std::string name = mLandmarkTitleEditor->getText();
  307. std::string desc = mNotesEditor->getText();
  308. LLStringUtil::trim(name);
  309. LLStringUtil::trim(desc);
  310. // If typed name is empty use the parcel name instead.
  311. if (name.empty())
  312. {
  313. name = mParcelName->getText();
  314. // If no parcel exists use the region name instead.
  315. if (name.empty())
  316. {
  317. name = mRegionName->getText();
  318. }
  319. }
  320. LLStringUtil::replaceChar(desc, '\n', ' ');
  321. // If no folder chosen use the "Landmarks" folder.
  322. LLLandmarkActions::createLandmarkHere(name, desc,
  323. folder_id.notNull() ? folder_id : gInventory.findCategoryUUIDForType(LLFolderType::FT_LANDMARK));
  324. }
  325. // static
  326. std::string LLPanelLandmarkInfo::getFullFolderName(const LLViewerInventoryCategory* cat)
  327. {
  328. std::string name;
  329. LLUUID parent_id;
  330. llassert(cat);
  331. if (cat)
  332. {
  333. name = cat->getName();
  334. parent_id = cat->getParentUUID();
  335. bool is_under_root_category = parent_id == gInventory.getRootFolderID();
  336. // we don't want "My Inventory" to appear in the name
  337. while ((parent_id = cat->getParentUUID()).notNull())
  338. {
  339. cat = gInventory.getCategory(parent_id);
  340. llassert(cat);
  341. if (cat)
  342. {
  343. if (is_under_root_category || cat->getParentUUID() == gInventory.getRootFolderID())
  344. {
  345. std::string localized_name;
  346. // Looking for translation only for protected type categories
  347. // to avoid warnings about non existent string in strings.xml.
  348. bool is_protected_type = LLFolderType::lookupIsProtectedType(cat->getPreferredType());
  349. if (is_under_root_category)
  350. {
  351. // translate category name, if it's right below the root
  352. bool is_found = is_protected_type && LLTrans::findString(localized_name, "InvFolder " + name);
  353. name = is_found ? localized_name : name;
  354. }
  355. else
  356. {
  357. bool is_found = is_protected_type && LLTrans::findString(localized_name, "InvFolder " + cat->getName());
  358. // add translated category name to folder's full name
  359. name = (is_found ? localized_name : cat->getName()) + "/" + name;
  360. }
  361. break;
  362. }
  363. else
  364. {
  365. name = cat->getName() + "/" + name;
  366. }
  367. }
  368. }
  369. }
  370. return name;
  371. }
  372. void LLPanelLandmarkInfo::populateFoldersList()
  373. {
  374. // Collect all folders that can contain landmarks.
  375. LLInventoryModel::cat_array_t cats;
  376. collectLandmarkFolders(cats);
  377. mFolderCombo->removeall();
  378. // Put the "Landmarks" folder first in list.
  379. LLUUID landmarks_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_LANDMARK);
  380. const LLViewerInventoryCategory* lmcat = gInventory.getCategory(landmarks_id);
  381. if (!lmcat)
  382. {
  383. llwarns << "Cannot find the landmarks folder" << llendl;
  384. }
  385. else
  386. {
  387. std::string cat_full_name = getFullFolderName(lmcat);
  388. mFolderCombo->add(cat_full_name, lmcat->getUUID());
  389. }
  390. typedef std::vector<folder_pair_t> folder_vec_t;
  391. folder_vec_t folders;
  392. // Sort the folders by their full name.
  393. for (S32 i = 0; i < cats.count(); i++)
  394. {
  395. const LLViewerInventoryCategory* cat = cats.get(i);
  396. std::string cat_full_name = getFullFolderName(cat);
  397. folders.push_back(folder_pair_t(cat->getUUID(), cat_full_name));
  398. }
  399. sort(folders.begin(), folders.end(), cmp_folders);
  400. // Finally, populate the combobox.
  401. for (folder_vec_t::const_iterator it = folders.begin(); it != folders.end(); it++)
  402. mFolderCombo->add(it->second, LLSD(it->first));
  403. }
  404. static bool cmp_folders(const folder_pair_t& left, const folder_pair_t& right)
  405. {
  406. return left.second < right.second;
  407. }
  408. static void collectLandmarkFolders(LLInventoryModel::cat_array_t& cats)
  409. {
  410. LLUUID landmarks_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_LANDMARK);
  411. // Add descendent folders of the "Landmarks" category.
  412. LLInventoryModel::item_array_t items; // unused
  413. LLIsType is_category(LLAssetType::AT_CATEGORY);
  414. gInventory.collectDescendentsIf(
  415. landmarks_id,
  416. cats,
  417. items,
  418. LLInventoryModel::EXCLUDE_TRASH,
  419. is_category);
  420. // Add the "My Favorites" category.
  421. LLUUID favorites_id = gInventory.findCategoryUUIDForType(LLFolderType::FT_FAVORITE);
  422. LLViewerInventoryCategory* favorites_cat = gInventory.getCategory(favorites_id);
  423. if (!favorites_cat)
  424. {
  425. llwarns << "Cannot find the favorites folder" << llendl;
  426. }
  427. else
  428. {
  429. cats.put(favorites_cat);
  430. }
  431. }