BuildmLearn Toolkit  2.0.4
BuildmLearn Toolkit is an easy-to-use program that helps users make mobile apps without any knowledge of application development.
 All Classes Functions Enumerations Groups Pages
debugging.cpp
1 /*
2  Copyright (c) 2012, BuildmLearn Contributors listed at http://buildmlearn.org/people/
3  All rights reserved.
4 
5  Redistribution and use in source and binary forms, with or without
6  modification, are permitted provided that the following conditions are met:
7 
8  * Redistributions of source code must retain the above copyright notice, this
9  list of conditions and the following disclaimer.
10 
11  * Redistributions in binary form must reproduce the above copyright notice,
12  this list of conditions and the following disclaimer in the documentation
13  and/or other materials provided with the distribution.
14 
15  * Neither the name of the BuildmLearn nor the names of its
16  contributors may be used to endorse or promote products derived from
17  this software without specific prior written permission.
18 
19  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
23  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
26  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30 
31 #include "miscellaneous/debugging.h"
32 
33 #include "definitions/definitions.h"
34 #include "miscellaneous/application.h"
35 
36 #include <QDir>
37 
38 #include <cstdio>
39 #include <cstdlib>
40 
41 #ifndef QT_NO_DEBUG_OUTPUT
42 #if QT_VERSION >= 0x050000
43 #define DEBUG_OUTPUT_WORKER(type_string, file, line, message) \
44  fprintf(stderr, "[%s] %s (%s:%d): %s\n", \
45  APP_LOW_NAME, \
46  type_string, \
47  file, \
48  line, \
49  qPrintable(message));
50 #else
51 #define DEBUG_OUTPUT_WORKER(type_string, message) \
52  fprintf(stderr, "[%s] %s: %s\n", \
53  APP_LOW_NAME, \
54  type_string, \
55  message);
56 #endif
57 #endif
58 
59 
60 #if QT_VERSION >= 0x050000
61 void Debugging::debugHandler(QtMsgType type,
62  const QMessageLogContext &placement,
63  const QString &message) {
64 #ifndef QT_NO_DEBUG_OUTPUT
65  const char *file = qPrintable(QString(placement.file).section(QDir::separator(),
66  -1));
67 
68  switch (type) {
69  case QtDebugMsg:
70  DEBUG_OUTPUT_WORKER("INFO", file, placement.line, message);
71  break;
72  case QtWarningMsg:
73  DEBUG_OUTPUT_WORKER("WARNING", file, placement.line, message);
74  break;
75  case QtCriticalMsg:
76  DEBUG_OUTPUT_WORKER("CRITICAL", file, placement.line, message);
77  break;
78  case QtFatalMsg:
79  DEBUG_OUTPUT_WORKER("FATAL", file, placement.line, message);
80  qApp->exit(EXIT_FAILURE);
81  default:
82  break;
83  }
84 #else
85  Q_UNUSED(type)
86  Q_UNUSED(placement)
87  Q_UNUSED(message)
88 #endif
89 }
90 #else
91 void Debugging::debugHandler(QtMsgType type, const char *message) {
92  #ifndef QT_NO_DEBUG_OUTPUT
93  switch (type) {
94  case QtDebugMsg:
95  DEBUG_OUTPUT_WORKER("INFO", message);
96  break;
97  case QtWarningMsg:
98  DEBUG_OUTPUT_WORKER("WARNING", message);
99  break;
100  case QtCriticalMsg:
101  DEBUG_OUTPUT_WORKER("CRITICAL", message);
102  break;
103  case QtFatalMsg:
104  DEBUG_OUTPUT_WORKER("FATAL", message);
105  qApp->exit(EXIT_FAILURE);
106  default:
107  break;
108  }
109 #else
110  Q_UNUSED(type)
111  Q_UNUSED(message)
112 #endif
113 }
114 #endif
115 
116 Debugging::Debugging() {
117 }