~ppsspp/ppsspp/ppsspp_1.3.0

« back to all changes in this revision

Viewing changes to Common/MsgHandler.cpp

  • Committer: Sérgio Benjamim
  • Date: 2017-01-02 00:12:05 UTC
  • Revision ID: sergio_br2@yahoo.com.br-20170102001205-cxbta9za203nmjwm
1.3.0 source (from ppsspp_1.3.0-r160.p5.l1762.a165.t83~56~ubuntu16.04.1.tar.xz).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (C) 2003 Dolphin Project.
 
2
 
 
3
// This program is free software: you can redistribute it and/or modify
 
4
// it under the terms of the GNU General Public License as published by
 
5
// the Free Software Foundation, version 2.0 or later versions.
 
6
 
 
7
// This program is distributed in the hope that it will be useful,
 
8
// but WITHOUT ANY WARRANTY; without even the implied warranty of
 
9
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
10
// GNU General Public License 2.0 for more details.
 
11
 
 
12
// A copy of the GPL 2.0 should have been included with the program.
 
13
// If not, see http://www.gnu.org/licenses/
 
14
 
 
15
// Official SVN repository and contact information can be found at
 
16
// http://code.google.com/p/dolphin-emu/
 
17
 
 
18
#include "Common.h" // Local
 
19
#include "StringUtils.h"
 
20
#include "util/text/utf8.h"
 
21
#include <string>
 
22
 
 
23
bool MsgHandler(const char* caption, const char* text, bool yes_no, int Style);
 
24
 
 
25
static bool AlertEnabled = true;
 
26
 
 
27
// enable/disable the alert handler
 
28
void SetEnableAlert(bool enable)
 
29
{
 
30
        AlertEnabled = enable;
 
31
}
 
32
 
 
33
// This is the first stop for gui alerts where the log is updated and the
 
34
// correct window is shown
 
35
bool MsgAlert(bool yes_no, int Style, const char* format, ...)
 
36
{
 
37
        // Read message and write it to the log
 
38
        char buffer[2048];
 
39
 
 
40
        static const char *captions[] = {
 
41
                "Information",
 
42
                "Question",
 
43
                "Warning",
 
44
                "Critical"
 
45
        };
 
46
 
 
47
        const char *caption = captions[Style];
 
48
 
 
49
        va_list args;
 
50
        va_start(args, format);
 
51
        CharArrayFromFormatV(buffer, sizeof(buffer)-1, format, args);
 
52
        va_end(args);
 
53
 
 
54
        ERROR_LOG(MASTER_LOG, "%s: %s", caption, buffer);
 
55
 
 
56
        // Don't ignore questions, especially AskYesNo, PanicYesNo could be ignored
 
57
        if (AlertEnabled || Style == QUESTION || Style == CRITICAL)
 
58
                return MsgHandler(caption, buffer, yes_no, Style);
 
59
 
 
60
        return true;
 
61
}
 
62
 
 
63
#ifdef _WIN32
 
64
#include "CommonWindows.h"
 
65
#endif
 
66
 
 
67
// Default non library dependent panic alert
 
68
bool MsgHandler(const char* caption, const char* text, bool yes_no, int Style)
 
69
{
 
70
#if defined(USING_WIN_UI)
 
71
        int STYLE = MB_ICONINFORMATION;
 
72
        if (Style == QUESTION) STYLE = MB_ICONQUESTION;
 
73
        if (Style == WARNING) STYLE = MB_ICONWARNING;
 
74
 
 
75
        std::wstring wtext = ConvertUTF8ToWString(text);
 
76
        std::wstring wcaption = ConvertUTF8ToWString(caption);
 
77
 
 
78
        return IDYES == MessageBox(0, wtext.c_str(), wcaption.c_str(), STYLE | (yes_no ? MB_YESNO : MB_OK));
 
79
#else
 
80
        printf("%s\n", text);
 
81
        return true;
 
82
#endif
 
83
}