summaryrefslogtreecommitdiff
path: root/Source/Core/DolphinQt/Config/LogWidget.h
blob: ab8d20273ecbbd2383cee3aed26b5be76b69af9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
// Copyright 2017 Dolphin Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later

#pragma once

#include <QDockWidget>

#include <mutex>
#include <string>

#include "Common/FixedSizeQueue.h"
#include "Common/Logging/LogManager.h"

class QCheckBox;
class QCloseEvent;
class QComboBox;
class QPlainTextEdit;
class QPushButton;
class QTimer;

class LogWidget final : public QDockWidget
{
  Q_OBJECT
public:
  explicit LogWidget(QWidget* parent = nullptr);
  ~LogWidget() override;

protected:
  void closeEvent(QCloseEvent*) override;

private:
  // LogListener instances are owned by LogManager, so we can't make LogWidget inherit from
  // LogListener, since Qt should be in control of LogWidget's lifetime. Instead we have
  // this LogListenerImpl class to act as an adapter.
  class LogListenerImpl final : public Common::Log::LogListener
  {
  public:
    explicit LogListenerImpl(LogWidget* log_widget) : m_log_widget(log_widget) {}

  private:
    void Log(Common::Log::LogLevel level, const char* text) override
    {
      m_log_widget->Log(level, text);
    }

    LogWidget* m_log_widget;
  };

  void UpdateLog();
  void UpdateFont();
  void CreateWidgets();
  void ConnectWidgets();
  void LoadSettings();
  void SaveSettings();

  void Log(Common::Log::LogLevel level, const char* text);

  // Log
  QCheckBox* m_log_wrap;
  QComboBox* m_log_font;
  QPushButton* m_log_clear;
  QPlainTextEdit* m_log_text;

  QTimer* m_timer;

  using LogEntry = std::pair<std::string, Common::Log::LogLevel>;

  // Maximum number of lines to show in log viewer
  static constexpr int MAX_LOG_LINES = 5000;

  std::mutex m_log_mutex;
  Common::FixedSizeQueue<LogEntry, MAX_LOG_LINES> m_log_ring_buffer;
};