Updating Doxygen styling and Licenses
[baulk.git] / src / Common / handler.h
blob5dd4dccd41a9ddf66bc69a0ecca813547807cc05
1 // Baulk - Common - Baulk Console Output Handler
2 //
3 // Baulk - Copyright (C) 2008 - Jacob Alexander
4 //
5 // Baulk is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // any later version, including version 3 of the License.
9 //
10 // Baulk is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program. If not, see <http://www.gnu.org/licenses/>.
18 #ifndef __HANDLER_H
19 #define __HANDLER_H
21 #include <iostream>
23 #include <QRegExp>
24 #include <QStringList>
26 #ifdef BAULK
27 QStringList msgLogs;
28 #endif
30 //! Handles all messages sent by the application
31 /*!
32 * Baulk
33 * - QDebug only sends messages into Baulk
34 * - QWarning only sends messages into Baulk
35 * - QCritical sends messages both to Standard Out and into Baulk
36 * - QFatal sends messages both to Standard Out and into Baulk
37 * however, if a QFatal message occurs the application has usually closed
38 * already.
40 * All other executables (ie. InformationServer)
41 * - All messages currently go to Standout Out
43 void handler( QtMsgType type, const char *msg ) {
44 QString log = "";
45 QString logPlain = "";
46 QString css = "<style type=\"text/css\">"
47 "body {"
48 "margin: 0px;"
49 "padding: 0px;"
50 "color: white;"
51 "}"
52 "li {"
53 "margin-left: 20px;"
54 "margin-top: 0px;"
55 "margin-bottom: 0px;"
56 "color: white;"
57 "}"
58 "</style>";
59 switch ( type ) {
60 case QtDebugMsg:
61 log = QObject::tr("%1<font color=\"green\">&lt;Debug&gt; %2<br></font>")
62 .arg( css )
63 .arg( QString( msg )
64 .replace( QRegExp("\t(.*)\n"), QString("<li>\\1</li>") )
65 .replace( QRegExp("\t(.*)"), QString("<li>\\1</li>") )
67 #ifndef BAULK
68 logPlain = QObject::tr("\033[22;32m<Debug>\033[22;0m %1").arg( msg );
69 std::cerr << logPlain.toUtf8().data() << std::endl;
70 #endif
71 break;
72 case QtWarningMsg:
73 log = QObject::tr( "%1<font color=\"orange\">&lt;Warning&gt; %2<br></font>")
74 .arg( css )
75 .arg( QString( msg )
76 .replace( QRegExp("\t(.*)\n"), QString("<li>\\1</li>") )
77 .replace( QRegExp("\t(.*)"), QString("<li>\\1</li>") )
79 #ifndef BAULK
80 logPlain = QObject::tr("\033[22;36m<Warning>\033[22;0m %1").arg( msg );
81 std::cerr << logPlain.toUtf8().data() << std::endl;
82 #endif
83 break;
84 case QtCriticalMsg:
85 log = QObject::tr("%1<font color=\"red\">&lt;Critical&gt; %2<br></font>")
86 .arg( css )
87 .arg( QString( msg )
88 .replace( QRegExp("\t(.*)\n"), QString("<li>\\1</li>") )
89 .replace( QRegExp("\t(.*)"), QString("<li>\\1</li>") )
91 logPlain = QObject::tr("\033[22;33m<Critical>\033[22;0m %1").arg( msg );
92 std::cerr << logPlain.toUtf8().data() << std::endl;
93 break;
94 case QtFatalMsg:
95 log = QObject::tr("%1<font color=\"red\" font-size=\"large\">&lt;Fatal&gt; %2<br></font>")
96 .arg( css )
97 .arg( QString( msg )
98 .replace( QRegExp("\t(.*)\n"), QString("<li>\\1</li>") )
99 .replace( QRegExp("\t(.*)"), QString("<li>\\1</li>") )
101 logPlain = QObject::tr("\033[22;31m<Fatal>\033[22;0m %1").arg( msg );
102 std::cerr << logPlain.toUtf8().data() << std::endl;
103 break;
106 #ifdef BAULK
107 msgLogs << log;
109 if ( baulk != 0 ) {
110 if ( baulk->updateMsgLogs( msgLogs ) )
111 msgLogs.clear();
113 #endif
116 #endif