PageRenderTime 13ms CodeModel.GetById 2ms app.highlight 8ms RepoModel.GetById 1ms app.codeStats 1ms

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