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