summaryrefslogtreecommitdiff
path: root/Source/Core/Common/MsgHandler.cpp
diff options
context:
space:
mode:
authorPierre Bourdon <delroth@gmail.com>2016-06-24 10:43:46 +0200
committerPierre Bourdon <delroth@gmail.com>2016-06-24 10:43:46 +0200
commit3570c7f03a2aa90aa634f96c0af1969af610f14d (patch)
tree4252e03c0e853ba7cffe022937698c854ad0eaa9 /Source/Core/Common/MsgHandler.cpp
parent2115e8a4a6814e32107b5205ff5c95bbd3c6e99c (diff)
Reformat all the things. Have fun with merge conflicts.
Diffstat (limited to 'Source/Core/Common/MsgHandler.cpp')
-rw-r--r--Source/Core/Common/MsgHandler.cpp122
1 files changed, 62 insertions, 60 deletions
diff --git a/Source/Core/Common/MsgHandler.cpp b/Source/Core/Common/MsgHandler.cpp
index e73efe9020..caf8d99f15 100644
--- a/Source/Core/Common/MsgHandler.cpp
+++ b/Source/Core/Common/MsgHandler.cpp
@@ -8,9 +8,9 @@
#include "Common/Common.h"
#include "Common/CommonTypes.h"
+#include "Common/Logging/Log.h"
#include "Common/MsgHandler.h"
#include "Common/StringUtil.h"
-#include "Common/Logging/Log.h"
bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, int Style);
static MsgAlertHandler msg_handler = DefaultMsgHandler;
@@ -23,97 +23,99 @@ static StringTranslator str_translator = DefaultStringTranslator;
// wxWidgets is enabled we will use wxMsgAlert() that is defined in Main.cpp
void RegisterMsgAlertHandler(MsgAlertHandler handler)
{
- msg_handler = handler;
+ msg_handler = handler;
}
// Select translation function. For wxWidgets use wxStringTranslator in Main.cpp
void RegisterStringTranslator(StringTranslator translator)
{
- str_translator = translator;
+ str_translator = translator;
}
// enable/disable the alert handler
void SetEnableAlert(bool enable)
{
- AlertEnabled = enable;
+ AlertEnabled = enable;
}
std::string GetTranslation(const char* string)
{
- return str_translator(string);
+ return str_translator(string);
}
// This is the first stop for gui alerts where the log is updated and the
// correct window is shown
bool MsgAlert(bool yes_no, int Style, const char* format, ...)
{
- // Read message and write it to the log
- std::string caption;
- char buffer[2048];
-
- static std::string info_caption;
- static std::string warn_caption;
- static std::string ques_caption;
- static std::string crit_caption;
-
- if (!info_caption.length())
- {
- info_caption = str_translator(_trans("Information"));
- ques_caption = str_translator(_trans("Question"));
- warn_caption = str_translator(_trans("Warning"));
- crit_caption = str_translator(_trans("Critical"));
- }
-
- switch (Style)
- {
- case INFORMATION:
- caption = info_caption;
- break;
- case QUESTION:
- caption = ques_caption;
- break;
- case WARNING:
- caption = warn_caption;
- break;
- case CRITICAL:
- caption = crit_caption;
- break;
- }
-
- va_list args;
- va_start(args, format);
- CharArrayFromFormatV(buffer, sizeof(buffer) - 1, str_translator(format).c_str(), args);
- va_end(args);
-
- ERROR_LOG(MASTER_LOG, "%s: %s", caption.c_str(), buffer);
-
- // Don't ignore questions, especially AskYesNo, PanicYesNo could be ignored
- if (msg_handler && (AlertEnabled || Style == QUESTION || Style == CRITICAL))
- return msg_handler(caption.c_str(), buffer, yes_no, Style);
-
- return true;
+ // Read message and write it to the log
+ std::string caption;
+ char buffer[2048];
+
+ static std::string info_caption;
+ static std::string warn_caption;
+ static std::string ques_caption;
+ static std::string crit_caption;
+
+ if (!info_caption.length())
+ {
+ info_caption = str_translator(_trans("Information"));
+ ques_caption = str_translator(_trans("Question"));
+ warn_caption = str_translator(_trans("Warning"));
+ crit_caption = str_translator(_trans("Critical"));
+ }
+
+ switch (Style)
+ {
+ case INFORMATION:
+ caption = info_caption;
+ break;
+ case QUESTION:
+ caption = ques_caption;
+ break;
+ case WARNING:
+ caption = warn_caption;
+ break;
+ case CRITICAL:
+ caption = crit_caption;
+ break;
+ }
+
+ va_list args;
+ va_start(args, format);
+ CharArrayFromFormatV(buffer, sizeof(buffer) - 1, str_translator(format).c_str(), args);
+ va_end(args);
+
+ ERROR_LOG(MASTER_LOG, "%s: %s", caption.c_str(), buffer);
+
+ // Don't ignore questions, especially AskYesNo, PanicYesNo could be ignored
+ if (msg_handler && (AlertEnabled || Style == QUESTION || Style == CRITICAL))
+ return msg_handler(caption.c_str(), buffer, yes_no, Style);
+
+ return true;
}
// Default non library dependent panic alert
bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, int Style)
{
#ifdef _WIN32
- int STYLE = MB_ICONINFORMATION;
- if (Style == QUESTION) STYLE = MB_ICONQUESTION;
- if (Style == WARNING) STYLE = MB_ICONWARNING;
-
- return IDYES == MessageBox(0, UTF8ToTStr(text).c_str(), UTF8ToTStr(caption).c_str(), STYLE | (yes_no ? MB_YESNO : MB_OK));
+ int STYLE = MB_ICONINFORMATION;
+ if (Style == QUESTION)
+ STYLE = MB_ICONQUESTION;
+ if (Style == WARNING)
+ STYLE = MB_ICONWARNING;
+
+ return IDYES == MessageBox(0, UTF8ToTStr(text).c_str(), UTF8ToTStr(caption).c_str(),
+ STYLE | (yes_no ? MB_YESNO : MB_OK));
#else
- fprintf(stderr, "%s\n", text);
+ fprintf(stderr, "%s\n", text);
- // Return no to any question (which will in general crash the emulator)
- return false;
+ // Return no to any question (which will in general crash the emulator)
+ return false;
#endif
}
// Default (non) translator
std::string DefaultStringTranslator(const char* text)
{
- return text;
+ return text;
}
-