PageRenderTime 46ms CodeModel.GetById 31ms app.highlight 10ms RepoModel.GetById 1ms app.codeStats 1ms

/indra/newview/llconfirmationmanager.cpp

https://bitbucket.org/lindenlab/viewer-beta/
C++ | 112 lines | 66 code | 20 blank | 26 comment | 10 complexity | a02b9541c64492767592d2f0a0a40ce6 MD5 | raw file
  1/** 
  2 * @file llconfirmationmanager.cpp
  3 * @brief LLConfirmationManager class implementation
  4 *
  5 * $LicenseInfo:firstyear=2006&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 "llconfirmationmanager.h"
 30
 31#include "lluictrlfactory.h"
 32
 33// viewer includes
 34#include "llnotificationsutil.h"
 35#include "llstring.h"
 36#include "llxmlnode.h"
 37
 38LLConfirmationManager::ListenerBase::~ListenerBase()
 39{
 40}
 41
 42
 43static bool onConfirmAlert(const LLSD& notification, const LLSD& response, LLConfirmationManager::ListenerBase* listener)
 44{
 45	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
 46	if (option == 0)
 47	{
 48		listener->confirmed("");
 49	}
 50	
 51	delete listener;
 52	return false;
 53}
 54
 55static bool onConfirmAlertPassword(const LLSD& notification, const LLSD& response, LLConfirmationManager::ListenerBase* listener)
 56{
 57	std::string text = response["message"].asString();
 58	S32 option = LLNotificationsUtil::getSelectedOption(notification, response);
 59		
 60	if (option == 0)
 61	{
 62		listener->confirmed(text);
 63	}
 64	
 65	delete listener;
 66	return false;
 67}
 68
 69 
 70void LLConfirmationManager::confirm(Type type,
 71	const std::string& action,
 72	ListenerBase* listener)
 73{
 74	LLSD args;
 75	args["ACTION"] = action;
 76
 77	switch (type)
 78	{
 79		case TYPE_CLICK:
 80			LLNotificationsUtil::add("ConfirmPurchase", args, LLSD(), boost::bind(onConfirmAlert, _1, _2, listener));
 81		  break;
 82
 83		case TYPE_PASSWORD:
 84			LLNotificationsUtil::add("ConfirmPurchasePassword", args, LLSD(), boost::bind(onConfirmAlertPassword, _1, _2, listener));
 85		  break;
 86		case TYPE_NONE:
 87		default:
 88		  listener->confirmed("");
 89		  break;
 90	}
 91}
 92
 93
 94void LLConfirmationManager::confirm(
 95	const std::string& type,
 96	const std::string& action,
 97	ListenerBase* listener)
 98{
 99	Type decodedType = TYPE_NONE;
100	
101	if (type == "click")
102	{
103		decodedType = TYPE_CLICK;
104	}
105	else if (type == "password")
106	{
107		decodedType = TYPE_PASSWORD;
108	}
109	
110	confirm(decodedType, action, listener);
111}
112