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 ~LogController();
39
40 int levels() const { return m_filter.defaultLevels; }
41 mLogFilter* filter() { return &m_filter; }
42
43 Stream operator()(int category, int level);
44
45 static LogController* global();
46 static QString toString(int level);
47
48signals:
49 void logPosted(int level, int category, const QString& log);
50 void levelsSet(int levels);
51 void levelsEnabled(int levels);
52 void levelsDisabled(int levels);
53
54public slots:
55 void postLog(int level, int category, const QString& string);
56 void setLevels(int levels);
57 void enableLevels(int levels);
58 void disableLevels(int levels);
59
60private:
61 mLogFilter m_filter;
62
63 static LogController s_global;
64};
65
66#define LOG(C, L) (*LogController::global())(mLOG_ ## L, _mLOG_CAT_ ## C ())
67
68}