/indra/newview/llbuycurrencyhtml.cpp

https://bitbucket.org/lindenlab/viewer-beta/ · C++ · 163 lines · 91 code · 18 blank · 54 comment · 11 complexity · af131a74676bf03c9c5ecaf802cb17ab MD5 · raw file

  1. /**
  2. * @file llbuycurrencyhtml.cpp
  3. * @brief Manages Buy Currency HTML floater
  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 "llfloaterbuycurrency.h"
  28. #include "llbuycurrencyhtml.h"
  29. #include "llfloaterbuycurrencyhtml.h"
  30. #include "llfloaterreg.h"
  31. #include "llcommandhandler.h"
  32. #include "llviewercontrol.h"
  33. #include "llstatusbar.h"
  34. // support for secondlife:///app/buycurrencyhtml/{ACTION}/{NEXT_ACTION}/{RETURN_CODE} SLapps
  35. class LLBuyCurrencyHTMLHandler :
  36. public LLCommandHandler
  37. {
  38. public:
  39. // requests will be throttled from a non-trusted browser
  40. LLBuyCurrencyHTMLHandler() : LLCommandHandler( "buycurrencyhtml", UNTRUSTED_ALLOW ) {}
  41. bool handle(const LLSD& params, const LLSD& query_map, LLMediaCtrl* web)
  42. {
  43. std::string action( "" );
  44. if ( params.size() >= 1 )
  45. {
  46. action = params[ 0 ].asString();
  47. };
  48. std::string next_action( "" );
  49. if ( params.size() >= 2 )
  50. {
  51. next_action = params[ 1 ].asString();
  52. };
  53. int result_code = 0;
  54. if ( params.size() >= 3 )
  55. {
  56. result_code = params[ 2 ].asInteger();
  57. };
  58. // open the legacy XUI based currency floater
  59. if ( "open_legacy" == next_action )
  60. {
  61. LLFloaterBuyCurrency::buyCurrency();
  62. };
  63. // ask the Buy Currency floater to close
  64. // note: this is the last thing we can do so make
  65. // sure any other actions are processed before this.
  66. if ( "close" == action )
  67. {
  68. LLBuyCurrencyHTML::closeDialog();
  69. };
  70. return true;
  71. };
  72. };
  73. LLBuyCurrencyHTMLHandler gBuyCurrencyHTMLHandler;
  74. ////////////////////////////////////////////////////////////////////////////////
  75. // static
  76. // Opens the legacy XUI based floater or new HTML based one based on
  77. // the QuickBuyCurrency value in settings.xml - this overload is for
  78. // the case where the amount is not requested.
  79. void LLBuyCurrencyHTML::openCurrencyFloater()
  80. {
  81. if ( gSavedSettings.getBOOL( "QuickBuyCurrency" ) )
  82. {
  83. // HTML version
  84. LLBuyCurrencyHTML::showDialog( false, "", 0 );
  85. }
  86. else
  87. {
  88. // legacy version
  89. LLFloaterBuyCurrency::buyCurrency();
  90. };
  91. }
  92. ////////////////////////////////////////////////////////////////////////////////
  93. // static
  94. // Opens the legacy XUI based floater or new HTML based one based on
  95. // the QuickBuyCurrency value in settings.xml - this overload is for
  96. // the case where the amount and a string to display are requested.
  97. void LLBuyCurrencyHTML::openCurrencyFloater( const std::string& message, S32 sum )
  98. {
  99. if ( gSavedSettings.getBOOL( "QuickBuyCurrency" ) )
  100. {
  101. // HTML version
  102. LLBuyCurrencyHTML::showDialog( true, message, sum );
  103. }
  104. else
  105. {
  106. // legacy version
  107. LLFloaterBuyCurrency::buyCurrency( message, sum );
  108. };
  109. }
  110. ////////////////////////////////////////////////////////////////////////////////
  111. // static
  112. void LLBuyCurrencyHTML::showDialog( bool specific_sum_requested, const std::string& message, S32 sum )
  113. {
  114. LLFloaterBuyCurrencyHTML* buy_currency_floater = dynamic_cast< LLFloaterBuyCurrencyHTML* >( LLFloaterReg::getInstance( "buy_currency_html" ) );
  115. if ( buy_currency_floater )
  116. {
  117. // pass on flag indicating if we want to buy specific amount and if so, how much
  118. buy_currency_floater->setParams( specific_sum_requested, message, sum );
  119. // force navigate to new URL
  120. buy_currency_floater->navigateToFinalURL();
  121. // make it visible and raise to front
  122. BOOL visible = TRUE;
  123. buy_currency_floater->setVisible( visible );
  124. BOOL take_focus = TRUE;
  125. buy_currency_floater->setFrontmost( take_focus );
  126. // spec calls for floater to be centered on client window
  127. buy_currency_floater->center();
  128. }
  129. else
  130. {
  131. llwarns << "Buy Currency (HTML) Floater not found" << llendl;
  132. };
  133. }
  134. ////////////////////////////////////////////////////////////////////////////////
  135. //
  136. void LLBuyCurrencyHTML::closeDialog()
  137. {
  138. LLFloaterBuyCurrencyHTML* buy_currency_floater = dynamic_cast< LLFloaterBuyCurrencyHTML* >(LLFloaterReg::getInstance( "buy_currency_html" ) );
  139. if ( buy_currency_floater )
  140. {
  141. buy_currency_floater->closeFloater();
  142. };
  143. // Update L$ balance in the status bar in case L$ were purchased
  144. LLStatusBar::sendMoneyBalanceRequest();
  145. }