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

/indra/newview/llfloaterbuycurrencyhtml.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 122 lines | 52 code | 18 blank | 52 comment | 2 complexity | c42acb2422dbb65c236d702f87a922ed MD5 | raw file
Possible License(s): LGPL-2.1
  1. /**
  2. * @file llfloaterbuycurrencyhtml.cpp
  3. * @brief buy currency implemented in HTML floater - uses embedded media browser control
  4. *
  5. * $LicenseInfo:firstyear=2010&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 "llfloaterbuycurrencyhtml.h"
  28. #include "llstatusbar.h"
  29. ////////////////////////////////////////////////////////////////////////////////
  30. //
  31. LLFloaterBuyCurrencyHTML::LLFloaterBuyCurrencyHTML( const LLSD& key ):
  32. LLFloater( key ),
  33. mSpecificSumRequested( false ),
  34. mMessage( "" ),
  35. mSum( 0 )
  36. {
  37. }
  38. ////////////////////////////////////////////////////////////////////////////////
  39. //
  40. BOOL LLFloaterBuyCurrencyHTML::postBuild()
  41. {
  42. // observer media events
  43. mBrowser = getChild<LLMediaCtrl>( "browser" );
  44. mBrowser->addObserver( this );
  45. return TRUE;
  46. }
  47. ////////////////////////////////////////////////////////////////////////////////
  48. //
  49. void LLFloaterBuyCurrencyHTML::navigateToFinalURL()
  50. {
  51. // URL for actual currency buy contents is in XUI file
  52. std::string buy_currency_url = getString( "buy_currency_url" );
  53. // replace [LANGUAGE] meta-tag with view language
  54. LLStringUtil::format_map_t replace;
  55. // viewer language
  56. replace[ "[LANGUAGE]" ] = LLUI::getLanguage();
  57. // flag that specific amount requested
  58. replace[ "[SPECIFIC_AMOUNT]" ] = ( mSpecificSumRequested ? "y":"n" );
  59. // amount requested
  60. std::ostringstream codec( "" );
  61. codec << mSum;
  62. replace[ "[SUM]" ] = codec.str();
  63. // users' current balance
  64. codec.clear();
  65. codec.str( "" );
  66. codec << gStatusBar->getBalance();
  67. replace[ "[BAL]" ] = codec.str();
  68. // message - "This cost L$x,xxx for example
  69. replace[ "[MSG]" ] = LLURI::escape( mMessage );
  70. LLStringUtil::format( buy_currency_url, replace );
  71. // write final URL to debug console
  72. llinfos << "Buy currency HTML parsed URL is " << buy_currency_url << llendl;
  73. // kick off the navigation
  74. mBrowser->navigateTo( buy_currency_url, "text/html" );
  75. }
  76. ////////////////////////////////////////////////////////////////////////////////
  77. //
  78. void LLFloaterBuyCurrencyHTML::handleMediaEvent( LLPluginClassMedia* self, EMediaEvent event )
  79. {
  80. // placeholder for now - just in case we want to catch media events
  81. if ( LLPluginClassMediaOwner::MEDIA_EVENT_NAVIGATE_COMPLETE == event )
  82. {
  83. // update currency after we complete a navigation since there are many ways
  84. // this can result in a different L$ balance
  85. LLStatusBar::sendMoneyBalanceRequest();
  86. };
  87. }
  88. ////////////////////////////////////////////////////////////////////////////////
  89. //
  90. void LLFloaterBuyCurrencyHTML::onClose( bool app_quitting )
  91. {
  92. // Update L$ balance one more time
  93. LLStatusBar::sendMoneyBalanceRequest();
  94. destroy();
  95. }
  96. ////////////////////////////////////////////////////////////////////////////////
  97. //
  98. void LLFloaterBuyCurrencyHTML::setParams( bool specific_sum_requested, const std::string& message, S32 sum )
  99. {
  100. // save these away - used to construct URL later
  101. mSpecificSumRequested = specific_sum_requested;
  102. mMessage = message;
  103. mSum = sum;
  104. }