summaryrefslogtreecommitdiff
path: root/indra/newview/llcurrencyuimanager.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'indra/newview/llcurrencyuimanager.cpp')
-rw-r--r--indra/newview/llcurrencyuimanager.cpp121
1 files changed, 95 insertions, 26 deletions
diff --git a/indra/newview/llcurrencyuimanager.cpp b/indra/newview/llcurrencyuimanager.cpp
index c4bfd71999..319cbf8209 100644
--- a/indra/newview/llcurrencyuimanager.cpp
+++ b/indra/newview/llcurrencyuimanager.cpp
@@ -76,8 +76,15 @@ public:
bool mUserEnteredCurrencyBuy;
// from website
- bool mSiteCurrencyEstimated;
- S32 mSiteCurrencyEstimatedCost;
+
+ // pre-viewer 2.0, the server returned estimates as an
+ // integer US cents value, e.g., "1000" for $10.00
+ // post-viewer 2.0, the server may also return estimates
+ // as a string with currency embedded, e.g., "10.00 Euros"
+ bool mUSDCurrencyEstimated;
+ S32 mUSDCurrencyEstimatedCost;
+ bool mLocalCurrencyEstimated;
+ std::string mLocalCurrencyEstimatedCost;
std::string mSiteConfirm;
bool mBought;
@@ -101,6 +108,10 @@ public:
void startCurrencyBuy(const std::string& password);
void finishCurrencyBuy();
+
+ void clearEstimate();
+ bool hasEstimate() const;
+ std::string getLocalEstimate() const;
void startTransaction(TransactionType type,
const char* method, LLXMLRPCValue params);
@@ -126,12 +137,11 @@ LLCurrencyUIManager::Impl::Impl(LLPanel& dialog)
mError(false),
mUserCurrencyBuy(2000), // note, this is a default, real value set in llfloaterbuycurrency.cpp
mUserEnteredCurrencyBuy(false),
- mSiteCurrencyEstimated(false),
- mSiteCurrencyEstimatedCost(0),
mBought(false),
mTransactionType(TransactionNone), mTransaction(0),
mCurrencyChanged(false)
{
+ clearEstimate();
}
LLCurrencyUIManager::Impl::~Impl()
@@ -141,14 +151,13 @@ LLCurrencyUIManager::Impl::~Impl()
void LLCurrencyUIManager::Impl::updateCurrencyInfo()
{
- mSiteCurrencyEstimated = false;
- mSiteCurrencyEstimatedCost = 0;
+ clearEstimate();
mBought = false;
mCurrencyChanged = false;
if (mUserCurrencyBuy == 0)
{
- mSiteCurrencyEstimated = true;
+ mLocalCurrencyEstimated = true;
return;
}
@@ -185,9 +194,21 @@ void LLCurrencyUIManager::Impl::finishCurrencyInfo()
}
LLXMLRPCValue currency = result["currency"];
- mSiteCurrencyEstimated = true;
- mSiteCurrencyEstimatedCost = currency["estimatedCost"].asInt();
-
+
+ // old XML-RPC server: estimatedCost = value in US cents
+ mUSDCurrencyEstimated = currency["estimatedCost"].isValid();
+ if (mUSDCurrencyEstimated)
+ {
+ mUSDCurrencyEstimatedCost = currency["estimatedCost"].asInt();
+ }
+
+ // newer XML-RPC server: estimatedLocalCost = local currency string
+ mLocalCurrencyEstimated = currency["estimatedLocalCost"].isValid();
+ if (mLocalCurrencyEstimated)
+ {
+ mLocalCurrencyEstimatedCost = currency["estimatedLocalCost"].asString();
+ }
+
S32 newCurrencyBuy = currency["currencyBuy"].asInt();
if (newCurrencyBuy != mUserCurrencyBuy)
{
@@ -200,17 +221,20 @@ void LLCurrencyUIManager::Impl::finishCurrencyInfo()
void LLCurrencyUIManager::Impl::startCurrencyBuy(const std::string& password)
{
- mSiteCurrencyEstimated = false;
- mSiteCurrencyEstimatedCost = 0;
- mCurrencyChanged = false;
-
LLXMLRPCValue keywordArgs = LLXMLRPCValue::createStruct();
keywordArgs.appendString("agentId", gAgent.getID().asString());
keywordArgs.appendString(
"secureSessionId",
gAgent.getSecureSessionID().asString());
keywordArgs.appendInt("currencyBuy", mUserCurrencyBuy);
- keywordArgs.appendInt("estimatedCost", mSiteCurrencyEstimatedCost);
+ if (mUSDCurrencyEstimated)
+ {
+ keywordArgs.appendInt("estimatedCost", mUSDCurrencyEstimatedCost);
+ }
+ if (mLocalCurrencyEstimated)
+ {
+ keywordArgs.appendString("estimatedLocalCost", mLocalCurrencyEstimatedCost);
+ }
keywordArgs.appendString("confirm", mSiteConfirm);
if (!password.empty())
{
@@ -226,6 +250,9 @@ void LLCurrencyUIManager::Impl::startCurrencyBuy(const std::string& password)
params.append(keywordArgs);
startTransaction(TransactionBuy, "buyCurrency", params);
+
+ clearEstimate();
+ mCurrencyChanged = false;
}
void LLCurrencyUIManager::Impl::finishCurrencyBuy()
@@ -270,6 +297,34 @@ void LLCurrencyUIManager::Impl::startTransaction(TransactionType type,
clearError();
}
+void LLCurrencyUIManager::Impl::clearEstimate()
+{
+ mUSDCurrencyEstimated = false;
+ mUSDCurrencyEstimatedCost = 0;
+ mLocalCurrencyEstimated = false;
+ mLocalCurrencyEstimatedCost = "0";
+}
+
+bool LLCurrencyUIManager::Impl::hasEstimate() const
+{
+ return (mUSDCurrencyEstimated || mLocalCurrencyEstimated);
+}
+
+std::string LLCurrencyUIManager::Impl::getLocalEstimate() const
+{
+ if (mLocalCurrencyEstimated)
+ {
+ // we have the new-style local currency string
+ return mLocalCurrencyEstimatedCost;
+ }
+ if (mUSDCurrencyEstimated)
+ {
+ // we have the old-style USD-specific value
+ return "US$ " + llformat("%#.2f", mUSDCurrencyEstimatedCost / 100.0);
+ }
+ return "";
+}
+
bool LLCurrencyUIManager::Impl::checkTransaction()
{
if (!mTransaction)
@@ -342,8 +397,8 @@ void LLCurrencyUIManager::Impl::currencyKey(S32 value)
mUserCurrencyBuy = value;
- if (mSiteCurrencyEstimated) {
- mSiteCurrencyEstimated = false;
+ if (hasEstimate()) {
+ clearEstimate();
//cannot just simply refresh the whole UI, as the edit field will
// get reset and the cursor will change...
@@ -406,8 +461,8 @@ void LLCurrencyUIManager::Impl::updateUI()
}
}
- mPanel.childSetTextArg("currency_est", "[LOCALAMOUNT]", "US$ " + llformat("%#.2f", mSiteCurrencyEstimatedCost / 100.0));
- mPanel.childSetVisible("currency_est", mSiteCurrencyEstimated && mUserCurrencyBuy > 0);
+ mPanel.childSetTextArg("currency_est", "[LOCALAMOUNT]", getLocalEstimate());
+ mPanel.childSetVisible("currency_est", hasEstimate() && mUserCurrencyBuy > 0);
if (mPanel.childIsEnabled("buy_btn")
||mPanel.childIsVisible("currency_est")
@@ -448,18 +503,32 @@ void LLCurrencyUIManager::setZeroMessage(const std::string& message)
impl.mZeroMessage = message;
}
-void LLCurrencyUIManager::setEstimate(int amount)
+void LLCurrencyUIManager::setUSDEstimate(int amount)
+{
+ impl.mUSDCurrencyEstimatedCost = amount;
+ impl.mUSDCurrencyEstimated = true;
+ impl.updateUI();
+
+ impl.mCurrencyChanged = false;
+}
+
+int LLCurrencyUIManager::getUSDEstimate()
+{
+ return impl.mUSDCurrencyEstimated ? impl.mUSDCurrencyEstimatedCost : 0;
+}
+
+void LLCurrencyUIManager::setLocalEstimate(const std::string &amount)
{
- impl.mSiteCurrencyEstimatedCost = amount;
- impl.mSiteCurrencyEstimated = true;
+ impl.mLocalCurrencyEstimatedCost = amount;
+ impl.mLocalCurrencyEstimated = true;
impl.updateUI();
impl.mCurrencyChanged = false;
}
-int LLCurrencyUIManager::getEstimate()
+std::string LLCurrencyUIManager::getLocalEstimate() const
{
- return impl.mSiteCurrencyEstimated ? impl.mSiteCurrencyEstimatedCost : 0;
+ return impl.getLocalEstimate();
}
void LLCurrencyUIManager::prepare()
@@ -490,7 +559,7 @@ void LLCurrencyUIManager::buy(const std::string& buy_msg)
LLUIString msg = buy_msg;
msg.setArg("[LINDENS]", llformat("%d", impl.mUserCurrencyBuy));
- msg.setArg("[LOCALAMOUNT]", "US$ " + llformat("%#.2f", impl.mSiteCurrencyEstimatedCost / 100.0));
+ msg.setArg("[LOCALAMOUNT]", getLocalEstimate());
LLConfirmationManager::confirm(impl.mSiteConfirm,
msg,
impl,
@@ -511,7 +580,7 @@ bool LLCurrencyUIManager::canCancel()
bool LLCurrencyUIManager::canBuy()
{
return impl.mTransactionType == Impl::TransactionNone
- && impl.mSiteCurrencyEstimated
+ && impl.hasEstimate()
&& impl.mUserCurrencyBuy > 0;
}