2015-05-24 04:55:12 +00:00
|
|
|
// Copyright 2011 Dolphin Emulator Project
|
2015-05-17 23:08:10 +00:00
|
|
|
// Licensed under GPLv2+
|
2013-04-18 03:43:35 +00:00
|
|
|
// Refer to the license.txt file included.
|
2011-02-18 12:34:24 +00:00
|
|
|
|
2014-02-22 22:36:30 +00:00
|
|
|
#include <vector>
|
|
|
|
#include <wx/button.h>
|
|
|
|
#include <wx/checkbox.h>
|
|
|
|
#include <wx/checklst.h>
|
|
|
|
#include <wx/panel.h>
|
|
|
|
#include <wx/radiobox.h>
|
|
|
|
#include <wx/sizer.h>
|
|
|
|
#include <wx/validate.h>
|
|
|
|
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "Common/FileUtil.h"
|
2014-06-05 23:29:54 +00:00
|
|
|
#include "Common/Logging/ConsoleListener.h"
|
|
|
|
#include "Common/Logging/Log.h"
|
|
|
|
#include "Common/Logging/LogManager.h"
|
2014-02-17 10:18:15 +00:00
|
|
|
#include "DolphinWX/LogConfigWindow.h"
|
|
|
|
#include "DolphinWX/LogWindow.h"
|
|
|
|
#include "DolphinWX/WxUtils.h"
|
2011-02-18 12:34:24 +00:00
|
|
|
|
2016-01-28 23:53:08 +00:00
|
|
|
LogConfigWindow::LogConfigWindow(wxWindow* parent, wxWindowID id)
|
2016-06-24 08:43:46 +00:00
|
|
|
: wxPanel(parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL,
|
|
|
|
_("Log Configuration")),
|
|
|
|
enableAll(true)
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
m_LogManager = LogManager::GetInstance();
|
|
|
|
CreateGUIControls();
|
|
|
|
LoadSettings();
|
2011-02-18 12:34:24 +00:00
|
|
|
}
|
|
|
|
|
2016-10-04 09:02:07 +00:00
|
|
|
LogConfigWindow::~LogConfigWindow()
|
|
|
|
{
|
|
|
|
SaveSettings();
|
|
|
|
}
|
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
void LogConfigWindow::CreateGUIControls()
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
// Verbosity
|
|
|
|
wxArrayString wxLevels, wxLevelsUse;
|
|
|
|
wxLevels.Add(_("Notice"));
|
|
|
|
wxLevels.Add(_("Error"));
|
|
|
|
wxLevels.Add(_("Warning"));
|
|
|
|
wxLevels.Add(_("Info"));
|
|
|
|
wxLevels.Add(_("Debug"));
|
|
|
|
for (int i = 0; i < MAX_LOGLEVEL; ++i)
|
|
|
|
wxLevelsUse.Add(wxLevels[i]);
|
|
|
|
m_verbosity = new wxRadioBox(this, wxID_ANY, _("Verbosity"), wxDefaultPosition, wxDefaultSize,
|
|
|
|
wxLevelsUse, 0, wxRA_SPECIFY_ROWS);
|
|
|
|
m_verbosity->Bind(wxEVT_RADIOBOX, &LogConfigWindow::OnVerbosityChange, this);
|
|
|
|
|
|
|
|
// Options
|
|
|
|
m_writeFileCB = new wxCheckBox(this, wxID_ANY, _("Write to File"));
|
|
|
|
m_writeFileCB->Bind(wxEVT_CHECKBOX, &LogConfigWindow::OnWriteFileChecked, this);
|
|
|
|
m_writeConsoleCB = new wxCheckBox(this, wxID_ANY, _("Write to Console"));
|
|
|
|
m_writeConsoleCB->Bind(wxEVT_CHECKBOX, &LogConfigWindow::OnWriteConsoleChecked, this);
|
|
|
|
m_writeWindowCB = new wxCheckBox(this, wxID_ANY, _("Write to Window"));
|
|
|
|
m_writeWindowCB->Bind(wxEVT_CHECKBOX, &LogConfigWindow::OnWriteWindowChecked, this);
|
|
|
|
|
|
|
|
wxButton* btn_toggle_all = new wxButton(this, wxID_ANY, _("Toggle All Log Types"),
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
|
|
|
btn_toggle_all->Bind(wxEVT_BUTTON, &LogConfigWindow::OnToggleAll, this);
|
|
|
|
m_checks = new wxCheckListBox(this, wxID_ANY);
|
|
|
|
m_checks->Bind(wxEVT_CHECKLISTBOX, &LogConfigWindow::OnLogCheck, this);
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++)
|
|
|
|
m_checks->Append(StrToWxStr(m_LogManager->GetFullName((LogTypes::LOG_TYPE)i)));
|
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
const int space1 = FromDIP(1);
|
|
|
|
const int space5 = FromDIP(5);
|
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
// Sizers
|
|
|
|
wxStaticBoxSizer* sbOutputs = new wxStaticBoxSizer(wxVERTICAL, this, _("Logger Outputs"));
|
2016-10-03 07:29:50 +00:00
|
|
|
sbOutputs->Add(m_writeFileCB, 0);
|
|
|
|
sbOutputs->Add(m_writeConsoleCB, 0, wxTOP, space1);
|
|
|
|
sbOutputs->Add(m_writeWindowCB, 0, wxTOP, space1);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
wxStaticBoxSizer* sbLogTypes = new wxStaticBoxSizer(wxVERTICAL, this, _("Log Types"));
|
|
|
|
sbLogTypes->Add(m_checks, 1, wxEXPAND);
|
|
|
|
|
|
|
|
wxBoxSizer* sMain = new wxBoxSizer(wxVERTICAL);
|
2016-10-03 07:29:50 +00:00
|
|
|
sMain->Add(m_verbosity, 0, wxEXPAND | wxLEFT | wxRIGHT, space5);
|
|
|
|
sMain->Add(sbOutputs, 0, wxEXPAND | wxLEFT | wxRIGHT, space5);
|
|
|
|
sMain->Add(btn_toggle_all, 0, wxEXPAND | wxLEFT | wxRIGHT, space5);
|
|
|
|
sMain->Add(sbLogTypes, 1, wxEXPAND | wxLEFT | wxRIGHT, space5);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
2016-10-03 07:29:50 +00:00
|
|
|
sMain->SetMinSize(FromDIP(wxSize(100, 100)));
|
|
|
|
SetSizerAndFit(sMain);
|
2011-02-18 12:34:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
void LogConfigWindow::LoadSettings()
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
2017-07-10 01:35:40 +00:00
|
|
|
m_verbosity->SetSelection(m_LogManager->GetLogLevel() - 1);
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
// Get the logger output settings from the config ini file.
|
2017-07-07 23:16:57 +00:00
|
|
|
m_writeFileCB->SetValue(m_LogManager->IsListenerEnabled(LogListener::FILE_LISTENER));
|
|
|
|
m_writeConsoleCB->SetValue(m_LogManager->IsListenerEnabled(LogListener::CONSOLE_LISTENER));
|
|
|
|
m_writeWindowCB->SetValue(m_LogManager->IsListenerEnabled(LogListener::LOG_WINDOW_LISTENER));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
// Run through all of the log types and check each checkbox for each logging type
|
|
|
|
// depending on its set value within the config ini.
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
{
|
2017-07-07 23:16:57 +00:00
|
|
|
bool log_enabled = m_LogManager->IsEnabled(static_cast<LogTypes::LOG_TYPE>(i));
|
2016-06-24 08:43:46 +00:00
|
|
|
|
|
|
|
if (log_enabled)
|
|
|
|
enableAll = false;
|
|
|
|
|
|
|
|
m_checks->Check(i, log_enabled);
|
|
|
|
}
|
2011-02-18 12:34:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
void LogConfigWindow::SaveSettings()
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
2017-07-07 23:10:38 +00:00
|
|
|
m_LogManager->SaveSettings();
|
2011-02-18 12:34:24 +00:00
|
|
|
}
|
|
|
|
|
2013-04-08 05:16:50 +00:00
|
|
|
// If the verbosity changes while logging
|
2011-02-21 15:01:00 +00:00
|
|
|
void LogConfigWindow::OnVerbosityChange(wxCommandEvent& event)
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
2017-07-10 01:35:40 +00:00
|
|
|
m_LogManager->SetLogLevel(static_cast<LogTypes::LOG_LEVELS>(m_verbosity->GetSelection() + 1));
|
2013-04-08 05:16:50 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
event.Skip();
|
2011-02-18 12:34:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
void LogConfigWindow::OnWriteFileChecked(wxCommandEvent& event)
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
2017-07-07 23:16:57 +00:00
|
|
|
m_LogManager->EnableListener(LogListener::FILE_LISTENER, event.IsChecked());
|
2011-02-18 12:34:24 +00:00
|
|
|
}
|
|
|
|
|
2014-02-23 06:33:03 +00:00
|
|
|
void LogConfigWindow::OnWriteConsoleChecked(wxCommandEvent& event)
|
|
|
|
{
|
2017-07-07 23:16:57 +00:00
|
|
|
m_LogManager->EnableListener(LogListener::CONSOLE_LISTENER, event.IsChecked());
|
2014-02-23 06:33:03 +00:00
|
|
|
}
|
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
void LogConfigWindow::OnWriteWindowChecked(wxCommandEvent& event)
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
2017-07-07 23:16:57 +00:00
|
|
|
m_LogManager->EnableListener(LogListener::LOG_WINDOW_LISTENER, event.IsChecked());
|
2011-02-18 12:34:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
void LogConfigWindow::OnToggleAll(wxCommandEvent& WXUNUSED(event))
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
ToggleLog(i, enableAll);
|
2011-02-18 12:34:24 +00:00
|
|
|
|
2016-06-24 08:43:46 +00:00
|
|
|
enableAll = !enableAll;
|
2011-02-18 12:34:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
void LogConfigWindow::ToggleLog(int _logType, bool enable)
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
LogTypes::LOG_TYPE logType = (LogTypes::LOG_TYPE)_logType;
|
|
|
|
m_checks->Check(_logType, enable);
|
|
|
|
m_LogManager->SetEnable(logType, enable);
|
2011-02-18 12:34:24 +00:00
|
|
|
}
|
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
void LogConfigWindow::OnLogCheck(wxCommandEvent& event)
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
2016-06-24 08:43:46 +00:00
|
|
|
int i = event.GetInt();
|
|
|
|
ToggleLog(i, m_checks->IsChecked(i));
|
2011-02-18 12:34:24 +00:00
|
|
|
}
|