PageRenderTime 403ms CodeModel.GetById 241ms app.highlight 5ms RepoModel.GetById 155ms app.codeStats 1ms

/indra/newview/llproductinforequest.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 86 lines | 46 code | 9 blank | 31 comment | 5 complexity | 5396bad51b7f42dec3a38db3544e8279 MD5 | raw file
 1/** 
 2 * @file llproductinforequest.cpp
 3 * @author Kent Quirk
 4 * @brief Get region type descriptions (translation from SKU to description)
 5 *
 6 * $LicenseInfo:firstyear=2009&license=viewerlgpl$
 7 * Second Life Viewer Source Code
 8 * Copyright (C) 2010, Linden Research, Inc.
 9 * 
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation;
13 * version 2.1 of the License only.
14 * 
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 * Lesser General Public License for more details.
19 * 
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
23 * 
24 * Linden Research, Inc., 945 Battery Street, San Francisco, CA  94111  USA
25 * $/LicenseInfo$
26 */
27
28#include "llviewerprecompiledheaders.h"
29
30#include "llproductinforequest.h"
31
32#include "llagent.h"  // for gAgent
33#include "lltrans.h"
34#include "llviewerregion.h"
35
36class LLProductInfoRequestResponder : public LLHTTPClient::Responder
37{
38public:
39	//If we get back a normal response, handle it here
40	virtual void result(const LLSD& content)
41	{
42		LLProductInfoRequestManager::instance().setSkuDescriptions(content);
43	}
44
45	//If we get back an error (not found, etc...), handle it here
46	virtual void error(U32 status, const std::string& reason)
47	{
48		llwarns << "LLProductInfoRequest::error("
49		<< status << ": " << reason << ")" << llendl;
50	}
51};
52
53LLProductInfoRequestManager::LLProductInfoRequestManager() : mSkuDescriptions()
54{
55}
56
57void LLProductInfoRequestManager::initSingleton()
58{
59	std::string url = gAgent.getRegion()->getCapability("ProductInfoRequest");
60	if (!url.empty())
61	{
62		LLHTTPClient::get(url, new LLProductInfoRequestResponder());
63	}
64}
65
66void LLProductInfoRequestManager::setSkuDescriptions(const LLSD& content)
67{
68	mSkuDescriptions = content;
69}
70
71std::string LLProductInfoRequestManager::getDescriptionForSku(const std::string& sku)
72{
73	// The description LLSD is an array of maps; each array entry
74	// has a map with 3 fields -- description, name, and sku
75	for (LLSD::array_const_iterator it = mSkuDescriptions.beginArray();
76		 it != mSkuDescriptions.endArray();
77		 ++it)
78	{
79		//	llwarns <<  (*it)["sku"].asString() << " = " << (*it)["description"].asString() << llendl;
80		if ((*it)["sku"].asString() == sku)
81		{
82			return (*it)["description"].asString();
83		}
84	}
85	return LLTrans::getString("land_type_unknown");
86}