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