A system to throw errors that allow for easy error reporting to the user by showing a translated pop-up alert box with the error message. The messages use strings.xml for translation and allow the usual replacement args (ie [FILE] is replaced with a filename). The exceptions can be cascaded, by adding more (translated) text when caught and then re-throwing the result. Macros are being used to support adding a function name prefix to a message of the current function that the exception is thrown from. The syntax is: <macro>(<line>); to show 'line' <macro>(<alert>, <line>); to append 'line' to a caught alert. <macro>(<line>, <alert>); to prepend 'line' to a caught alert. where <macro> is one of: THROW_ALERT, THROW_MALERT, THROW_FALERT, THROW_FMALERT, THROW_ALERTE, THROW_MALERTE, THROW_FALERTE, THROW_FMALERTE, where M = modal, F = Function name. and where <line> is one of: <xmldesc> <xmldesc>, AIArgs<args> where <xmldesc> is a string literal that will be looked up in strings.xml, and <args> is: (<key>, <replacement>)[<args>] There are more variations of the macros to throw an arbitrary class (append _CLASS), include an int code (append C) or to store the current errno as code (append E). For example, THROW_MALERTC(code, ...), or THROW_FALERT_CLASS(Foobar, ...), where the ... is the same as for the macros above. Documentation and example usage has been added to aialert.h.
91 lines
3.0 KiB
C++
91 lines
3.0 KiB
C++
/**
|
|
* @file llnotificationsutil.cpp
|
|
*
|
|
* $LicenseInfo:firstyear=2008&license=viewerlgpl$
|
|
* Second Life Viewer Source Code
|
|
* Copyright (C) 2010, Linden Research, Inc.
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
* License as published by the Free Software Foundation;
|
|
* version 2.1 of the License only.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Lesser General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
* License along with this library; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
*
|
|
* Linden Research, Inc., 945 Battery Street, San Francisco, CA 94111 USA
|
|
* $/LicenseInfo$
|
|
*/
|
|
#include "linden_common.h"
|
|
|
|
#include "llnotificationsutil.h"
|
|
|
|
#include "llnotifications.h"
|
|
#include "llsd.h"
|
|
#include "llxmlnode.h" // apparently needed to call LLNotifications::instance()
|
|
|
|
LLNotificationPtr LLNotificationsUtil::add(AIAlert const& alert, unsigned int suppress_mask)
|
|
{
|
|
return LLNotifications::instance().add(alert, suppress_mask);
|
|
}
|
|
|
|
LLNotificationPtr LLNotificationsUtil::add(const std::string& name)
|
|
{
|
|
return LLNotifications::instance().add(
|
|
LLNotification::Params(name).substitutions(LLSD()).payload(LLSD()));
|
|
}
|
|
|
|
LLNotificationPtr LLNotificationsUtil::add(const std::string& name,
|
|
const LLSD& substitutions)
|
|
{
|
|
return LLNotifications::instance().add(
|
|
LLNotification::Params(name).substitutions(substitutions).payload(LLSD()));
|
|
}
|
|
|
|
LLNotificationPtr LLNotificationsUtil::add(const std::string& name,
|
|
const LLSD& substitutions,
|
|
const LLSD& payload)
|
|
{
|
|
return LLNotifications::instance().add(
|
|
LLNotification::Params(name).substitutions(substitutions).payload(payload));
|
|
}
|
|
|
|
LLNotificationPtr LLNotificationsUtil::add(const std::string& name,
|
|
const LLSD& substitutions,
|
|
const LLSD& payload,
|
|
const std::string& functor_name)
|
|
{
|
|
return LLNotifications::instance().add(
|
|
LLNotification::Params(name).substitutions(substitutions).payload(payload).functor_name(functor_name));
|
|
}
|
|
|
|
LLNotificationPtr LLNotificationsUtil::add(const std::string& name,
|
|
const LLSD& substitutions,
|
|
const LLSD& payload,
|
|
boost::function<void (const LLSD&, const LLSD&)> functor)
|
|
{
|
|
return LLNotifications::instance().add(
|
|
LLNotification::Params(name).substitutions(substitutions).payload(payload).functor(functor));
|
|
}
|
|
|
|
S32 LLNotificationsUtil::getSelectedOption(const LLSD& notification, const LLSD& response)
|
|
{
|
|
return LLNotification::getSelectedOption(notification, response);
|
|
}
|
|
|
|
void LLNotificationsUtil::cancel(LLNotificationPtr pNotif)
|
|
{
|
|
LLNotifications::instance().cancel(pNotif);
|
|
}
|
|
|
|
LLNotificationPtr LLNotificationsUtil::find(LLUUID uuid)
|
|
{
|
|
return LLNotifications::instance().find(uuid);
|
|
}
|