PageRenderTime 43ms CodeModel.GetById 27ms RepoModel.GetById 0ms app.codeStats 0ms

/indra/newview/llpanelplaceinfo.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 315 lines | 225 code | 48 blank | 42 comment | 22 complexity | ccae8c77f7500e92a5734532291881da MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llpanelplaceinfo.cpp
  3. * @brief Base class for place information 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 "llpanelplaceinfo.h"
  28. #include "llavatarname.h"
  29. #include "llsdutil.h"
  30. #include "llsdutil_math.h"
  31. #include "llregionhandle.h"
  32. #include "lliconctrl.h"
  33. #include "lltextbox.h"
  34. #include "lltrans.h"
  35. #include "llagent.h"
  36. #include "llexpandabletextbox.h"
  37. #include "llpanelpick.h"
  38. #include "lltexturectrl.h"
  39. #include "llviewerregion.h"
  40. LLPanelPlaceInfo::LLPanelPlaceInfo()
  41. : LLPanel(),
  42. mParcelID(),
  43. mRequestedID(),
  44. mPosRegion(),
  45. mScrollingPanelMinHeight(0),
  46. mScrollingPanelWidth(0),
  47. mInfoType(UNKNOWN),
  48. mScrollingPanel(NULL),
  49. mScrollContainer(NULL),
  50. mDescEditor(NULL)
  51. {}
  52. //virtual
  53. LLPanelPlaceInfo::~LLPanelPlaceInfo()
  54. {
  55. if (mParcelID.notNull())
  56. {
  57. LLRemoteParcelInfoProcessor::getInstance()->removeObserver(mParcelID, this);
  58. }
  59. }
  60. //virtual
  61. BOOL LLPanelPlaceInfo::postBuild()
  62. {
  63. mTitle = getChild<LLTextBox>("title");
  64. mCurrentTitle = mTitle->getText();
  65. mSnapshotCtrl = getChild<LLTextureCtrl>("logo");
  66. mRegionName = getChild<LLTextBox>("region_title");
  67. mParcelName = getChild<LLTextBox>("parcel_title");
  68. mDescEditor = getChild<LLExpandableTextBox>("description");
  69. mMaturityRatingIcon = getChild<LLIconCtrl>("maturity_icon");
  70. mMaturityRatingText = getChild<LLTextBox>("maturity_value");
  71. mScrollingPanel = getChild<LLPanel>("scrolling_panel");
  72. mScrollContainer = getChild<LLScrollContainer>("place_scroll");
  73. mScrollingPanelMinHeight = mScrollContainer->getScrolledViewRect().getHeight();
  74. mScrollingPanelWidth = mScrollingPanel->getRect().getWidth();
  75. return TRUE;
  76. }
  77. //virtual
  78. void LLPanelPlaceInfo::resetLocation()
  79. {
  80. mParcelID.setNull();
  81. mRequestedID.setNull();
  82. mPosRegion.clearVec();
  83. std::string loading = LLTrans::getString("LoadingData");
  84. mMaturityRatingText->setValue(loading);
  85. mRegionName->setText(loading);
  86. mParcelName->setText(loading);
  87. mDescEditor->setText(loading);
  88. mMaturityRatingIcon->setValue(LLUUID::null);
  89. mSnapshotCtrl->setImageAssetID(LLUUID::null);
  90. }
  91. //virtual
  92. void LLPanelPlaceInfo::setParcelID(const LLUUID& parcel_id)
  93. {
  94. mParcelID = parcel_id;
  95. sendParcelInfoRequest();
  96. }
  97. //virtual
  98. void LLPanelPlaceInfo::setInfoType(EInfoType type)
  99. {
  100. mTitle->setText(mCurrentTitle);
  101. mTitle->setToolTip(mCurrentTitle);
  102. mInfoType = type;
  103. }
  104. void LLPanelPlaceInfo::sendParcelInfoRequest()
  105. {
  106. if (mParcelID != mRequestedID)
  107. {
  108. LLRemoteParcelInfoProcessor::getInstance()->addObserver(mParcelID, this);
  109. LLRemoteParcelInfoProcessor::getInstance()->sendParcelInfoRequest(mParcelID);
  110. mRequestedID = mParcelID;
  111. }
  112. }
  113. void LLPanelPlaceInfo::displayParcelInfo(const LLUUID& region_id,
  114. const LLVector3d& pos_global)
  115. {
  116. LLViewerRegion* region = gAgent.getRegion();
  117. if (!region)
  118. return;
  119. mPosRegion.setVec((F32)fmod(pos_global.mdV[VX], (F64)REGION_WIDTH_METERS),
  120. (F32)fmod(pos_global.mdV[VY], (F64)REGION_WIDTH_METERS),
  121. (F32)pos_global.mdV[VZ]);
  122. LLSD body;
  123. std::string url = region->getCapability("RemoteParcelRequest");
  124. if (!url.empty())
  125. {
  126. body["location"] = ll_sd_from_vector3(mPosRegion);
  127. if (!region_id.isNull())
  128. {
  129. body["region_id"] = region_id;
  130. }
  131. if (!pos_global.isExactlyZero())
  132. {
  133. U64 region_handle = to_region_handle(pos_global);
  134. body["region_handle"] = ll_sd_from_U64(region_handle);
  135. }
  136. LLHTTPClient::post(url, body, new LLRemoteParcelRequestResponder(getObserverHandle()));
  137. }
  138. else
  139. {
  140. mDescEditor->setText(getString("server_update_text"));
  141. }
  142. }
  143. // virtual
  144. void LLPanelPlaceInfo::setErrorStatus(U32 status, const std::string& reason)
  145. {
  146. // We only really handle 404 and 499 errors
  147. std::string error_text;
  148. if(status == 404)
  149. {
  150. error_text = getString("server_error_text");
  151. }
  152. else if(status == 499)
  153. {
  154. error_text = getString("server_forbidden_text");
  155. }
  156. else
  157. {
  158. error_text = getString("server_error_text");
  159. }
  160. mDescEditor->setText(error_text);
  161. std::string not_available = getString("not_available");
  162. mMaturityRatingText->setValue(not_available);
  163. mRegionName->setText(not_available);
  164. mParcelName->setText(not_available);
  165. mMaturityRatingIcon->setValue(LLUUID::null);
  166. // Enable "Back" button that was disabled when parcel request was sent.
  167. getChild<LLButton>("back_btn")->setEnabled(TRUE);
  168. }
  169. // virtual
  170. void LLPanelPlaceInfo::processParcelInfo(const LLParcelData& parcel_data)
  171. {
  172. if(parcel_data.snapshot_id.notNull())
  173. {
  174. mSnapshotCtrl->setImageAssetID(parcel_data.snapshot_id);
  175. }
  176. if(!parcel_data.sim_name.empty())
  177. {
  178. mRegionName->setText(parcel_data.sim_name);
  179. }
  180. else
  181. {
  182. mRegionName->setText(LLStringUtil::null);
  183. }
  184. if(!parcel_data.desc.empty())
  185. {
  186. mDescEditor->setText(parcel_data.desc);
  187. }
  188. else
  189. {
  190. mDescEditor->setText(getString("not_available"));
  191. }
  192. S32 region_x;
  193. S32 region_y;
  194. S32 region_z;
  195. // If the region position is zero, grab position from the global
  196. if(mPosRegion.isExactlyZero())
  197. {
  198. region_x = llround(parcel_data.global_x) % REGION_WIDTH_UNITS;
  199. region_y = llround(parcel_data.global_y) % REGION_WIDTH_UNITS;
  200. region_z = llround(parcel_data.global_z);
  201. }
  202. else
  203. {
  204. region_x = llround(mPosRegion.mV[VX]);
  205. region_y = llround(mPosRegion.mV[VY]);
  206. region_z = llround(mPosRegion.mV[VZ]);
  207. }
  208. if (!parcel_data.name.empty())
  209. {
  210. mParcelTitle = parcel_data.name;
  211. mParcelName->setText(llformat("%s (%d, %d, %d)",
  212. mParcelTitle.c_str(), region_x, region_y, region_z));
  213. }
  214. else
  215. {
  216. mParcelName->setText(getString("not_available"));
  217. }
  218. }
  219. // virtual
  220. void LLPanelPlaceInfo::reshape(S32 width, S32 height, BOOL called_from_parent)
  221. {
  222. // This if was added to force collapsing description textbox on Windows at the beginning of reshape
  223. // (the only case when reshape is skipped here is when it's caused by this textbox, so called_from_parent is FALSE)
  224. // This way it is consistent with Linux where topLost collapses textbox at the beginning of reshape.
  225. // On windows it collapsed only after reshape which caused EXT-8342.
  226. if(called_from_parent)
  227. {
  228. if(mDescEditor) mDescEditor->onTopLost();
  229. }
  230. LLPanel::reshape(width, height, called_from_parent);
  231. if (!mScrollContainer || !mScrollingPanel)
  232. return;
  233. static LLUICachedControl<S32> scrollbar_size ("UIScrollbarSize", 0);
  234. S32 scroll_height = mScrollContainer->getRect().getHeight();
  235. if (mScrollingPanelMinHeight > scroll_height)
  236. {
  237. mScrollingPanel->reshape(mScrollingPanelWidth, mScrollingPanelMinHeight);
  238. }
  239. else
  240. {
  241. mScrollingPanel->reshape(mScrollingPanelWidth + scrollbar_size, scroll_height);
  242. }
  243. }
  244. void LLPanelPlaceInfo::createPick(const LLVector3d& pos_global, LLPanelPickEdit* pick_panel)
  245. {
  246. std::string region_name = mRegionName->getText();
  247. LLPickData data;
  248. data.pos_global = pos_global;
  249. data.name = mParcelTitle.empty() ? region_name : mParcelTitle;
  250. data.sim_name = region_name;
  251. data.desc = mDescEditor->getText();
  252. data.snapshot_id = mSnapshotCtrl->getImageAssetID();
  253. data.parcel_id = mParcelID;
  254. pick_panel->setPickData(&data);
  255. }
  256. // static
  257. void LLPanelPlaceInfo::onNameCache(LLTextBox* text, const std::string& full_name)
  258. {
  259. text->setText(full_name);
  260. }
  261. // static
  262. void LLPanelPlaceInfo::onAvatarNameCache(const LLUUID& agent_id,
  263. const LLAvatarName& av_name,
  264. LLTextBox* text)
  265. {
  266. text->setText( av_name.getCompleteName() );
  267. }