diff --git a/indra/llcommon/aialert.cpp b/indra/llcommon/aialert.cpp index f3d4f5af3..587a206bc 100644 --- a/indra/llcommon/aialert.cpp +++ b/indra/llcommon/aialert.cpp @@ -35,6 +35,13 @@ namespace AIAlert { +Error::Error(Prefix const& prefix, modal_nt type, + Error const& alert) : mLines(alert.mLines), mModal(type) +{ + if (alert.mModal == modal) mModal = modal; + if (prefix) mLines.push_front(Line(prefix)); +} + Error::Error(Prefix const& prefix, modal_nt type, std::string const& xml_desc, AIArgs const& args) : mModal(type) { diff --git a/indra/llcommon/aialert.h b/indra/llcommon/aialert.h index 574426a9f..4d3704cfb 100644 --- a/indra/llcommon/aialert.h +++ b/indra/llcommon/aialert.h @@ -231,6 +231,9 @@ class LL_COMMON_API Error : public std::exception lines_type const& lines(void) const { return mLines; } bool is_modal(void) const { return mModal == modal; } + // Existing alert, just add a prefix and turn alert into modal if appropriate. + Error(Prefix const& prefix, modal_nt type, Error const& alert); + // A string with zero or more replacements. Error(Prefix const& prefix, modal_nt type, std::string const& xml_desc, AIArgs const& args = AIArgs()); @@ -269,28 +272,33 @@ class LL_COMMON_API ErrorCode : public Error // Accessor. int getCode(void) const { return mCode; } + // Just an Error with a code. + ErrorCode(Prefix const& prefix, modal_nt type, int code, + Error const& alert) : + Error(prefix, type, alert), mCode(code) { } + // A string with zero or more replacements. ErrorCode(Prefix const& prefix, modal_nt type, int code, std::string const& xml_desc, AIArgs const& args = AIArgs()) : - Error(prefix, modal, xml_desc, args) { } + Error(prefix, type, xml_desc, args), mCode(code) { } // Same as above bit prepending the message with the text of another alert. ErrorCode(Prefix const& prefix, modal_nt type, int code, Error const& alert, std::string const& xml_desc, AIArgs const& args = AIArgs()) : - Error(prefix, modal, alert, xml_desc, args) { } + Error(prefix, type, alert, xml_desc, args), mCode(code) { } // Same as above but appending the message with the text of another alert. // (no args) ErrorCode(Prefix const& prefix, modal_nt type, int code, std::string const& xml_desc, Error const& alert) : - Error(prefix, modal, xml_desc, alert) { } + Error(prefix, type, xml_desc, alert), mCode(code) { } // (with args) ErrorCode(Prefix const& prefix, modal_nt type, int code, std::string const& xml_desc, AIArgs const& args, Error const& alert) : - Error(prefix, modal, xml_desc, args, alert) { } + Error(prefix, type, xml_desc, args, alert), mCode(code) { } }; } // namespace AIAlert diff --git a/indra/llui/llnotifications.cpp b/indra/llui/llnotifications.cpp index 73dd99109..b8fab0994 100644 --- a/indra/llui/llnotifications.cpp +++ b/indra/llui/llnotifications.cpp @@ -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)); } diff --git a/indra/llui/llnotificationsutil.cpp b/indra/llui/llnotificationsutil.cpp index 134a5c267..4c24b511e 100644 --- a/indra/llui/llnotificationsutil.cpp +++ b/indra/llui/llnotificationsutil.cpp @@ -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) diff --git a/indra/llui/llnotificationsutil.h b/indra/llui/llnotificationsutil.h index fb0fb1ba4..893d2269c 100644 --- a/indra/llui/llnotificationsutil.h +++ b/indra/llui/llnotificationsutil.h @@ -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