aboutsummaryrefslogtreecommitdiff
path: root/src/alert.cpp
diff options
context:
space:
mode:
authorGavin Andresen <gavinandresen@gmail.com>2014-10-07 13:11:48 -0400
committerGavin Andresen <gavinandresen@gmail.com>2014-10-09 10:25:30 -0400
commite01a7939d3a3b231f68ae2f36cbc4de0cf4d4999 (patch)
tree4abe870bb84c4667b4b901f458457cca7b620029 /src/alert.cpp
parent7c6cbff0e52d4b69fd823426341a4d62d29b2c16 (diff)
Refactor -alertnotify code
Refactor common -alertnotify code into static CAlert::Notify method.
Diffstat (limited to 'src/alert.cpp')
-rw-r--r--src/alert.cpp37
1 files changed, 21 insertions, 16 deletions
diff --git a/src/alert.cpp b/src/alert.cpp
index 3271ecfbfd..d495849206 100644
--- a/src/alert.cpp
+++ b/src/alert.cpp
@@ -233,25 +233,30 @@ bool CAlert::ProcessAlert(bool fThread)
if(AppliesToMe())
{
uiInterface.NotifyAlertChanged(GetHash(), CT_NEW);
- std::string strCmd = GetArg("-alertnotify", "");
- if (!strCmd.empty())
- {
- // Alert text should be plain ascii coming from a trusted source, but to
- // be safe we first strip anything not in safeChars, then add single quotes around
- // the whole string before passing it to the shell:
- std::string singleQuote("'");
- std::string safeStatus = SanitizeString(strStatusBar);
- safeStatus = singleQuote+safeStatus+singleQuote;
- boost::replace_all(strCmd, "%s", safeStatus);
-
- if (fThread)
- boost::thread t(runCommand, strCmd); // thread runs free
- else
- runCommand(strCmd);
- }
+ Notify(strStatusBar, fThread);
}
}
LogPrint("alert", "accepted alert %d, AppliesToMe()=%d\n", nID, AppliesToMe());
return true;
}
+
+void
+CAlert::Notify(const std::string& strMessage, bool fThread)
+{
+ std::string strCmd = GetArg("-alertnotify", "");
+ if (strCmd.empty()) return;
+
+ // Alert text should be plain ascii coming from a trusted source, but to
+ // be safe we first strip anything not in safeChars, then add single quotes around
+ // the whole string before passing it to the shell:
+ std::string singleQuote("'");
+ std::string safeStatus = SanitizeString(strMessage);
+ safeStatus = singleQuote+safeStatus+singleQuote;
+ boost::replace_all(strCmd, "%s", safeStatus);
+
+ if (fThread)
+ boost::thread t(runCommand, strCmd); // thread runs free
+ else
+ runCommand(strCmd);
+}