all repos — mgba @ 80cf9646a6b0f4ad6c24f29be0c9f2855a44d820

mGBA Game Boy Advance Emulator

src/platform/qt/LogController.cpp (view raw)

 1/* Copyright (c) 2013-2015 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "LogController.h"
 7
 8using namespace QGBA;
 9
10LogController LogController::s_global(mLOG_ALL);
11
12LogController::LogController(int levels, QObject* parent)
13	: QObject(parent)
14{
15	mLogFilterInit(&m_filter);
16	mLogFilterSet(&m_filter, "gba.bios", mLOG_STUB);
17	m_filter.defaultLevels = levels;
18
19	if (this != &s_global) {
20		connect(&s_global, &LogController::logPosted, this, &LogController::postLog);
21		connect(this, &LogController::levelsSet, &s_global, &LogController::setLevels);
22		connect(this, &LogController::levelsEnabled, &s_global, &LogController::enableLevels);
23		connect(this, &LogController::levelsDisabled, &s_global, &LogController::disableLevels);
24	}
25}
26
27LogController::Stream LogController::operator()(int category, int level) {
28	return Stream(this, category, level);
29}
30
31void LogController::postLog(int level, int category, const QString& string) {
32	if (!mLogFilterTest(&m_filter, category, static_cast<mLogLevel>(level))) {
33		return;
34	}
35	emit logPosted(level, category, string);
36}
37
38void LogController::setLevels(int levels) {
39	m_filter.defaultLevels = levels;
40	emit levelsSet(levels);
41}
42
43void LogController::enableLevels(int levels) {
44	m_filter.defaultLevels |= levels;
45	emit levelsEnabled(levels);
46}
47
48void LogController::disableLevels(int levels) {
49	m_filter.defaultLevels &= ~levels;
50	emit levelsDisabled(levels);
51}
52
53LogController* LogController::global() {
54	return &s_global;
55}
56
57QString LogController::toString(int level) {
58	switch (level) {
59	case mLOG_DEBUG:
60		return tr("DEBUG");
61	case mLOG_STUB:
62		return tr("STUB");
63	case mLOG_INFO:
64		return tr("INFO");
65	case mLOG_WARN:
66		return tr("WARN");
67	case mLOG_ERROR:
68		return tr("ERROR");
69	case mLOG_FATAL:
70		return tr("FATAL");
71	case mLOG_GAME_ERROR:
72		return tr("GAME ERROR");
73	}
74	return QString();
75}
76
77LogController::Stream::Stream(LogController* controller, int level, int category)
78	: m_level(level)
79	, m_category(category)
80	, m_log(controller)
81{
82}
83
84LogController::Stream::~Stream() {
85	m_log->postLog(m_level, m_category, m_queue.join(" "));
86}
87
88LogController::Stream& LogController::Stream::operator<<(const QString& string) {
89	m_queue.append(string);
90	return *this;
91}