all repos — mgba @ 2e330b92a73e67aa6b238bb4a07840e235557082

mGBA Game Boy Advance Emulator

src/platform/qt/LogController.h (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#pragma once
 7
 8#include "GBAApp.h"
 9
10#include <mgba/core/log.h>
11
12#include <QObject>
13#include <QStringList>
14
15namespace QGBA {
16
17class LogController : public QObject {
18Q_OBJECT
19
20private:
21	class Stream {
22	public:
23		Stream(LogController* controller, int level, int category);
24		~Stream();
25
26		Stream& operator<<(const QString&);
27
28	private:
29		int m_level;
30		int m_category;
31		LogController* m_log;
32
33		QStringList m_queue;
34	};
35
36public:
37	LogController(int levels, QObject* parent = nullptr);
38
39	int levels() const { return m_filter.defaultLevels; }
40	mLogFilter* filter() { return &m_filter; }
41
42	Stream operator()(int category, int level);
43
44	static LogController* global();
45	static QString toString(int level);
46
47signals:
48	void logPosted(int level, int category, const QString& log);
49	void levelsSet(int levels);
50	void levelsEnabled(int levels);
51	void levelsDisabled(int levels);
52
53public slots:
54	void postLog(int level, int category, const QString& string);
55	void setLevels(int levels);
56	void enableLevels(int levels);
57	void disableLevels(int levels);
58
59private:
60	mLogFilter m_filter;
61
62	static LogController s_global;
63};
64
65#define LOG(C, L) (*LogController::global())(mLOG_ ## L, _mLOG_CAT_ ## C ())
66
67}