AIAlert fixup.

This commit is contained in:
Aleric Inglewood
2013-11-09 15:42:29 +01:00
parent a7e72ceb32
commit 5f9c6f1b08
5 changed files with 52 additions and 26 deletions

View File

@@ -1480,29 +1480,11 @@ LLNotificationPtr LLNotifications::add(const LLNotification::Params& p)
return pNotif;
}
namespace AIAlert { std::string text(Error const& error, int suppress_mask = 0); }
LLNotificationPtr LLNotifications::add(AIAlert::Error const& error, int type, unsigned int suppress_mask)
{
std::string alert_text;
bool suppress_newlines = false;
bool last_was_prefix = false;
for (AIAlert::Error::lines_type::const_iterator line = error.lines().begin(); line != error.lines().end(); ++line)
{
// Even if a line is suppressed, we print its leading newline if requested, but never more than one.
if (!suppress_newlines && line->prepend_newline())
{
alert_text += '\n';
suppress_newlines = true;
}
if (!line->suppressed(suppress_mask))
{
if (last_was_prefix) alert_text += ' '; // The translation system strips off spaces... add them back.
alert_text += LLTrans::getString(line->getXmlDesc(), line->args());
suppress_newlines = false;
last_was_prefix = line->is_prefix();
}
}
LLSD substitutions = LLSD::emptyMap();
substitutions["[PAYLOAD]"] = alert_text;
substitutions["[PAYLOAD]"] = AIAlert::text(error, suppress_mask);
return add(LLNotification::Params((type == AIAlert::modal || error.is_modal()) ? "AIAlertModal" : "AIAlert").substitutions(substitutions));
}

View File

@@ -25,6 +25,7 @@
#include "linden_common.h"
#include "llnotificationsutil.h"
#include "lltrans.h"
#include "llnotifications.h"
#include "llsd.h"
@@ -33,7 +34,7 @@
namespace AIAlert
{
LLNotificationPtr add(Error const& error, modal_nt type, unsigned int suppress_mask)
LLNotificationPtr add(Error const& error, unsigned int suppress_mask, modal_nt type)
{
return LLNotifications::instance().add(error, type, suppress_mask);
}
@@ -68,6 +69,30 @@ LLNotificationPtr add(std::string const& xml_desc, AIArgs const& args, Error con
return LLNotifications::instance().add(Error(Prefix(), type, xml_desc, args, error), type, suppress_mask);
}
std::string text(Error const& error, int suppress_mask)
{
std::string alert_text;
bool suppress_newlines = false;
bool last_was_prefix = false;
for (Error::lines_type::const_iterator line = error.lines().begin(); line != error.lines().end(); ++line)
{
// Even if a line is suppressed, we print its leading newline if requested, but never more than one.
if (!suppress_newlines && line->prepend_newline())
{
alert_text += '\n';
suppress_newlines = true;
}
if (!line->suppressed(suppress_mask))
{
if (last_was_prefix) alert_text += ' '; // The translation system strips off spaces... add them back.
alert_text += LLTrans::getString(line->getXmlDesc(), line->args());
suppress_newlines = false;
last_was_prefix = line->is_prefix();
}
}
return alert_text;
}
} // namespace AIAlert
LLNotificationPtr LLNotificationsUtil::add(const std::string& name)

View File

@@ -64,7 +64,7 @@ namespace AIAlert
// Just show the caught alert error.
LLNotificationPtr add(Error const& error,
modal_nt type = not_modal, unsigned int suppress_mask = 0);
unsigned int suppress_mask = 0, modal_nt type = not_modal);
// Short cuts for enforcing modal alerts.
inline LLNotificationPtr add_modal(std::string const& xml_desc) { return add(xml_desc, modal); }
@@ -73,6 +73,10 @@ namespace AIAlert
inline LLNotificationPtr add_modal(Error const& error, std::string const& xml_desc, AIArgs const& args, unsigned int suppress_mask = 0) { return add(error, xml_desc, args, suppress_mask, modal); }
inline LLNotificationPtr add_modal(std::string const& xml_desc, Error const& error, unsigned int suppress_mask = 0) { return add(xml_desc, error, suppress_mask, modal); }
inline LLNotificationPtr add_modal(std::string const& xml_desc, AIArgs const& args, Error const& error, unsigned int suppress_mask = 0) { return add(xml_desc, args, error, suppress_mask, modal); }
inline LLNotificationPtr add_modal(Error const& error, unsigned int suppress_mask = 0) { return add(error, suppress_mask, modal); }
// Return the full, translated, texted of the alert (possibly suppressing certain output).
std::string text(Error const& error, int suppress_mask = 0);
}
namespace LLNotificationsUtil