PageRenderTime 230ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/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
Possible License(s): LGPL-2.1
  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. #include "llviewerprecompiledheaders.h"
  28. #include "llproductinforequest.h"
  29. #include "llagent.h" // for gAgent
  30. #include "lltrans.h"
  31. #include "llviewerregion.h"
  32. class LLProductInfoRequestResponder : public LLHTTPClient::Responder
  33. {
  34. public:
  35. //If we get back a normal response, handle it here
  36. virtual void result(const LLSD& content)
  37. {
  38. LLProductInfoRequestManager::instance().setSkuDescriptions(content);
  39. }
  40. //If we get back an error (not found, etc...), handle it here
  41. virtual void error(U32 status, const std::string& reason)
  42. {
  43. llwarns << "LLProductInfoRequest::error("
  44. << status << ": " << reason << ")" << llendl;
  45. }
  46. };
  47. LLProductInfoRequestManager::LLProductInfoRequestManager() : mSkuDescriptions()
  48. {
  49. }
  50. void LLProductInfoRequestManager::initSingleton()
  51. {
  52. std::string url = gAgent.getRegion()->getCapability("ProductInfoRequest");
  53. if (!url.empty())
  54. {
  55. LLHTTPClient::get(url, new LLProductInfoRequestResponder());
  56. }
  57. }
  58. void LLProductInfoRequestManager::setSkuDescriptions(const LLSD& content)
  59. {
  60. mSkuDescriptions = content;
  61. }
  62. std::string LLProductInfoRequestManager::getDescriptionForSku(const std::string& sku)
  63. {
  64. // The description LLSD is an array of maps; each array entry
  65. // has a map with 3 fields -- description, name, and sku
  66. for (LLSD::array_const_iterator it = mSkuDescriptions.beginArray();
  67. it != mSkuDescriptions.endArray();
  68. ++it)
  69. {
  70. // llwarns << (*it)["sku"].asString() << " = " << (*it)["description"].asString() << llendl;
  71. if ((*it)["sku"].asString() == sku)
  72. {
  73. return (*it)["description"].asString();
  74. }
  75. }
  76. return LLTrans::getString("land_type_unknown");
  77. }