diff options
| author | 2014-04-08 19:25:03 -0400 | |
|---|---|---|
| committer | 2014-04-08 19:25:03 -0400 | |
| commit | 63e46abdb8764bc97e91bae862c8d461e61b1965 (patch) | |
| tree | e73f4aa25d7b4015a265e7bbfb6004dab7561027 /src/common/msg_handler.cpp | |
| parent | fixed some license headers that I missed (diff) | |
| download | yuzu-63e46abdb8764bc97e91bae862c8d461e61b1965.tar.gz yuzu-63e46abdb8764bc97e91bae862c8d461e61b1965.tar.xz yuzu-63e46abdb8764bc97e91bae862c8d461e61b1965.zip | |
got rid of 'src' folders in each sub-project
Diffstat (limited to 'src/common/msg_handler.cpp')
| -rw-r--r-- | src/common/msg_handler.cpp | 107 |
1 files changed, 107 insertions, 0 deletions
diff --git a/src/common/msg_handler.cpp b/src/common/msg_handler.cpp new file mode 100644 index 000000000..8e9fe218e --- /dev/null +++ b/src/common/msg_handler.cpp | |||
| @@ -0,0 +1,107 @@ | |||
| 1 | // Copyright 2013 Dolphin Emulator Project | ||
| 2 | // Licensed under GPLv2 | ||
| 3 | // Refer to the license.txt file included. | ||
| 4 | |||
| 5 | #include <stdio.h> // System | ||
| 6 | |||
| 7 | #include "common.h" // Local | ||
| 8 | #include "string_util.h" | ||
| 9 | |||
| 10 | bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, int Style); | ||
| 11 | static MsgAlertHandler msg_handler = DefaultMsgHandler; | ||
| 12 | static bool AlertEnabled = true; | ||
| 13 | |||
| 14 | std::string DefaultStringTranslator(const char* text); | ||
| 15 | static StringTranslator str_translator = DefaultStringTranslator; | ||
| 16 | |||
| 17 | // Select which of these functions that are used for message boxes. If | ||
| 18 | // wxWidgets is enabled we will use wxMsgAlert() that is defined in Main.cpp | ||
| 19 | void RegisterMsgAlertHandler(MsgAlertHandler handler) | ||
| 20 | { | ||
| 21 | msg_handler = handler; | ||
| 22 | } | ||
| 23 | |||
| 24 | // Select translation function. For wxWidgets use wxStringTranslator in Main.cpp | ||
| 25 | void RegisterStringTranslator(StringTranslator translator) | ||
| 26 | { | ||
| 27 | str_translator = translator; | ||
| 28 | } | ||
| 29 | |||
| 30 | // enable/disable the alert handler | ||
| 31 | void SetEnableAlert(bool enable) | ||
| 32 | { | ||
| 33 | AlertEnabled = enable; | ||
| 34 | } | ||
| 35 | |||
| 36 | // This is the first stop for gui alerts where the log is updated and the | ||
| 37 | // correct window is shown | ||
| 38 | bool MsgAlert(bool yes_no, int Style, const char* format, ...) | ||
| 39 | { | ||
| 40 | // Read message and write it to the log | ||
| 41 | std::string caption; | ||
| 42 | char buffer[2048]; | ||
| 43 | |||
| 44 | static std::string info_caption; | ||
| 45 | static std::string warn_caption; | ||
| 46 | static std::string ques_caption; | ||
| 47 | static std::string crit_caption; | ||
| 48 | |||
| 49 | if (!info_caption.length()) | ||
| 50 | { | ||
| 51 | info_caption = str_translator(_trans("Information")); | ||
| 52 | ques_caption = str_translator(_trans("Question")); | ||
| 53 | warn_caption = str_translator(_trans("Warning")); | ||
| 54 | crit_caption = str_translator(_trans("Critical")); | ||
| 55 | } | ||
| 56 | |||
| 57 | switch(Style) | ||
| 58 | { | ||
| 59 | case INFORMATION: | ||
| 60 | caption = info_caption; | ||
| 61 | break; | ||
| 62 | case QUESTION: | ||
| 63 | caption = ques_caption; | ||
| 64 | break; | ||
| 65 | case WARNING: | ||
| 66 | caption = warn_caption; | ||
| 67 | break; | ||
| 68 | case CRITICAL: | ||
| 69 | caption = crit_caption; | ||
| 70 | break; | ||
| 71 | } | ||
| 72 | |||
| 73 | va_list args; | ||
| 74 | va_start(args, format); | ||
| 75 | CharArrayFromFormatV(buffer, sizeof(buffer)-1, str_translator(format).c_str(), args); | ||
| 76 | va_end(args); | ||
| 77 | |||
| 78 | ERROR_LOG(MASTER_LOG, "%s: %s", caption.c_str(), buffer); | ||
| 79 | |||
| 80 | // Don't ignore questions, especially AskYesNo, PanicYesNo could be ignored | ||
| 81 | if (msg_handler && (AlertEnabled || Style == QUESTION || Style == CRITICAL)) | ||
| 82 | return msg_handler(caption.c_str(), buffer, yes_no, Style); | ||
| 83 | |||
| 84 | return true; | ||
| 85 | } | ||
| 86 | |||
| 87 | // Default non library dependent panic alert | ||
| 88 | bool DefaultMsgHandler(const char* caption, const char* text, bool yes_no, int Style) | ||
| 89 | { | ||
| 90 | //#ifdef _WIN32 | ||
| 91 | // int STYLE = MB_ICONINFORMATION; | ||
| 92 | // if (Style == QUESTION) STYLE = MB_ICONQUESTION; | ||
| 93 | // if (Style == WARNING) STYLE = MB_ICONWARNING; | ||
| 94 | // | ||
| 95 | // return IDYES == MessageBox(0, UTF8ToTStr(text).c_str(), UTF8ToTStr(caption).c_str(), STYLE | (yes_no ? MB_YESNO : MB_OK)); | ||
| 96 | //#else | ||
| 97 | printf("%s\n", text); | ||
| 98 | return true; | ||
| 99 | //#endif | ||
| 100 | } | ||
| 101 | |||
| 102 | // Default (non) translator | ||
| 103 | std::string DefaultStringTranslator(const char* text) | ||
| 104 | { | ||
| 105 | return text; | ||
| 106 | } | ||
| 107 | |||