2013-04-17 21:43:35 -06:00
|
|
|
// Copyright 2013 Dolphin Emulator Project
|
2015-05-17 17:08:10 -06:00
|
|
|
// Licensed under GPLv2+
|
2013-04-17 21:43:35 -06:00
|
|
|
// Refer to the license.txt file included.
|
2011-02-18 05:34:24 -07:00
|
|
|
|
2014-02-22 15:36:30 -07: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 03:18:15 -07:00
|
|
|
#include "Common/FileUtil.h"
|
2014-02-22 15:36:30 -07:00
|
|
|
#include "Common/IniFile.h"
|
2014-06-05 17:29:54 -06:00
|
|
|
#include "Common/Logging/ConsoleListener.h"
|
|
|
|
#include "Common/Logging/Log.h"
|
|
|
|
#include "Common/Logging/LogManager.h"
|
2014-02-17 03:18:15 -07:00
|
|
|
#include "DolphinWX/LogConfigWindow.h"
|
|
|
|
#include "DolphinWX/LogWindow.h"
|
|
|
|
#include "DolphinWX/WxUtils.h"
|
2011-02-18 05:34:24 -07:00
|
|
|
|
2011-02-21 08:01:00 -07:00
|
|
|
LogConfigWindow::LogConfigWindow(wxWindow* parent, CLogWindow *log_window, wxWindowID id)
|
|
|
|
: wxPanel(parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _("Log Configuration"))
|
2011-02-18 13:03:01 -07:00
|
|
|
, m_LogWindow(log_window), enableAll(true)
|
2011-02-18 05:34:24 -07:00
|
|
|
{
|
2011-02-21 09:50:55 -07:00
|
|
|
SetMinSize(wxSize(100, 100));
|
2011-02-18 05:34:24 -07:00
|
|
|
m_LogManager = LogManager::GetInstance();
|
|
|
|
CreateGUIControls();
|
|
|
|
LoadSettings();
|
|
|
|
}
|
|
|
|
|
2011-02-21 08:01:00 -07:00
|
|
|
LogConfigWindow::~LogConfigWindow()
|
|
|
|
{
|
|
|
|
SaveSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogConfigWindow::CreateGUIControls()
|
2011-02-18 05:34:24 -07: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"),
|
2014-03-05 21:02:34 -07:00
|
|
|
wxDefaultPosition, wxDefaultSize, wxLevelsUse, 0, wxRA_SPECIFY_ROWS);
|
2014-05-17 10:49:00 -06:00
|
|
|
m_verbosity->Bind(wxEVT_RADIOBOX, &LogConfigWindow::OnVerbosityChange, this);
|
2011-02-18 05:34:24 -07:00
|
|
|
|
|
|
|
// Options
|
|
|
|
m_writeFileCB = new wxCheckBox(this, wxID_ANY, _("Write to File"));
|
2014-05-17 10:49:00 -06:00
|
|
|
m_writeFileCB->Bind(wxEVT_CHECKBOX, &LogConfigWindow::OnWriteFileChecked, this);
|
2014-02-22 23:33:03 -07:00
|
|
|
m_writeConsoleCB = new wxCheckBox(this, wxID_ANY, _("Write to Console"));
|
2014-05-17 10:49:00 -06:00
|
|
|
m_writeConsoleCB->Bind(wxEVT_CHECKBOX, &LogConfigWindow::OnWriteConsoleChecked, this);
|
2011-02-18 05:34:24 -07:00
|
|
|
m_writeWindowCB = new wxCheckBox(this, wxID_ANY, _("Write to Window"));
|
2014-05-17 10:49:00 -06:00
|
|
|
m_writeWindowCB->Bind(wxEVT_CHECKBOX, &LogConfigWindow::OnWriteWindowChecked, this);
|
2011-02-18 05:34:24 -07:00
|
|
|
|
|
|
|
wxButton *btn_toggle_all = new wxButton(this, wxID_ANY, _("Toggle All Log Types"),
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
2014-05-17 10:49:00 -06:00
|
|
|
btn_toggle_all->Bind(wxEVT_BUTTON, &LogConfigWindow::OnToggleAll, this);
|
2011-02-18 05:34:24 -07:00
|
|
|
m_checks = new wxCheckListBox(this, wxID_ANY);
|
2014-05-17 10:49:00 -06:00
|
|
|
m_checks->Bind(wxEVT_CHECKLISTBOX, &LogConfigWindow::OnLogCheck, this);
|
2011-02-18 05:34:24 -07:00
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++)
|
2013-02-27 21:37:38 -07:00
|
|
|
m_checks->Append(StrToWxStr(m_LogManager->GetFullName((LogTypes::LOG_TYPE)i)));
|
2011-02-18 05:34:24 -07:00
|
|
|
|
|
|
|
// Sizers
|
2011-02-21 08:01:00 -07:00
|
|
|
wxStaticBoxSizer* sbOutputs = new wxStaticBoxSizer(wxVERTICAL, this, _("Logger Outputs"));
|
|
|
|
sbOutputs->Add(m_writeFileCB, 0, wxDOWN, 1);
|
2014-02-22 23:33:03 -07:00
|
|
|
sbOutputs->Add(m_writeConsoleCB, 0, wxDOWN, 1);
|
2015-03-15 23:11:18 -06:00
|
|
|
sbOutputs->Add(m_writeWindowCB, 0);
|
2011-02-18 05:34:24 -07:00
|
|
|
|
|
|
|
wxStaticBoxSizer* sbLogTypes = new wxStaticBoxSizer(wxVERTICAL, this, _("Log Types"));
|
|
|
|
sbLogTypes->Add(m_checks, 1, wxEXPAND);
|
|
|
|
|
|
|
|
wxBoxSizer *sMain = new wxBoxSizer(wxVERTICAL);
|
2011-02-21 08:01:00 -07:00
|
|
|
sMain->Add(m_verbosity, 0, wxEXPAND | wxLEFT | wxRIGHT, 5);
|
|
|
|
sMain->Add(sbOutputs, 0, wxEXPAND | wxLEFT | wxRIGHT, 5);
|
|
|
|
sMain->Add(btn_toggle_all, 0, wxEXPAND | wxLEFT | wxRIGHT, 5);
|
|
|
|
sMain->Add(sbLogTypes, 1, wxEXPAND | wxLEFT | wxRIGHT, 5);
|
2011-02-18 05:34:24 -07:00
|
|
|
|
|
|
|
SetSizer(sMain);
|
|
|
|
Layout();
|
|
|
|
}
|
|
|
|
|
2011-02-21 08:01:00 -07:00
|
|
|
void LogConfigWindow::LoadSettings()
|
2011-02-18 05:34:24 -07:00
|
|
|
{
|
|
|
|
IniFile ini;
|
|
|
|
ini.Load(File::GetUserPath(F_LOGGERCONFIG_IDX));
|
|
|
|
|
2014-06-15 23:12:43 -06:00
|
|
|
IniFile::Section* options = ini.GetOrCreateSection("Options");
|
|
|
|
|
2013-04-07 23:16:50 -06:00
|
|
|
// Retrieve the verbosity value from the config ini file.
|
2011-02-18 05:34:24 -07:00
|
|
|
int verbosity;
|
2014-06-15 23:12:43 -06:00
|
|
|
options->Get("Verbosity", &verbosity, 0);
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-04-07 23:16:50 -06:00
|
|
|
// Ensure the verbosity level is valid.
|
|
|
|
if (verbosity < 1)
|
|
|
|
verbosity = 1;
|
|
|
|
if (verbosity > MAX_LOGLEVEL)
|
|
|
|
verbosity = MAX_LOGLEVEL;
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-04-07 23:16:50 -06:00
|
|
|
// Actually set the logging verbosity.
|
2011-02-18 05:34:24 -07:00
|
|
|
m_verbosity->SetSelection(verbosity - 1);
|
|
|
|
|
2013-04-07 23:16:50 -06:00
|
|
|
// Get the logger output settings from the config ini file.
|
2014-06-15 23:12:43 -06:00
|
|
|
options->Get("WriteToFile", &m_writeFile, false);
|
2011-02-18 05:34:24 -07:00
|
|
|
m_writeFileCB->SetValue(m_writeFile);
|
2014-06-15 23:12:43 -06:00
|
|
|
options->Get("WriteToConsole", &m_writeConsole, true);
|
2014-02-22 23:33:03 -07:00
|
|
|
m_writeConsoleCB->SetValue(m_writeConsole);
|
2014-06-15 23:12:43 -06:00
|
|
|
options->Get("WriteToWindow", &m_writeWindow, true);
|
2011-02-18 05:34:24 -07:00
|
|
|
m_writeWindowCB->SetValue(m_writeWindow);
|
2013-04-07 23:16:50 -06: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.
|
2011-02-18 05:34:24 -07:00
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
{
|
|
|
|
bool log_enabled;
|
2014-08-26 01:59:17 -06:00
|
|
|
ini.GetOrCreateSection("Logs")->Get(m_LogManager->GetShortName((LogTypes::LOG_TYPE)i), &log_enabled, false);
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-04-07 23:16:50 -06:00
|
|
|
if (log_enabled)
|
|
|
|
enableAll = false;
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2011-02-18 05:34:24 -07:00
|
|
|
m_checks->Check(i, log_enabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-21 08:01:00 -07:00
|
|
|
void LogConfigWindow::SaveSettings()
|
2011-02-18 05:34:24 -07:00
|
|
|
{
|
|
|
|
IniFile ini;
|
|
|
|
ini.Load(File::GetUserPath(F_LOGGERCONFIG_IDX));
|
|
|
|
|
2014-06-15 23:12:43 -06:00
|
|
|
IniFile::Section* options = ini.GetOrCreateSection("Options");
|
|
|
|
options->Set("Verbosity", m_verbosity->GetSelection() + 1);
|
|
|
|
options->Set("WriteToFile", m_writeFile);
|
|
|
|
options->Set("WriteToConsole", m_writeConsole);
|
|
|
|
options->Set("WriteToWindow", m_writeWindow);
|
2013-04-07 23:16:50 -06:00
|
|
|
|
|
|
|
// Save all enabled/disabled states of the log types to the config ini.
|
2011-02-18 05:34:24 -07:00
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
2013-04-07 23:16:50 -06:00
|
|
|
{
|
2014-06-15 23:12:43 -06:00
|
|
|
ini.GetOrCreateSection("Logs")->Set(m_LogManager->GetShortName((LogTypes::LOG_TYPE)i), m_checks->IsChecked(i));
|
2013-04-07 23:16:50 -06:00
|
|
|
}
|
|
|
|
|
2011-02-18 05:34:24 -07:00
|
|
|
ini.Save(File::GetUserPath(F_LOGGERCONFIG_IDX));
|
|
|
|
}
|
|
|
|
|
2013-04-07 23:16:50 -06:00
|
|
|
// If the verbosity changes while logging
|
2011-02-21 08:01:00 -07:00
|
|
|
void LogConfigWindow::OnVerbosityChange(wxCommandEvent& event)
|
2011-02-18 05:34:24 -07:00
|
|
|
{
|
2013-04-07 23:16:50 -06:00
|
|
|
// Get the new verbosity
|
2011-02-18 05:34:24 -07:00
|
|
|
int v = m_verbosity->GetSelection() + 1;
|
2013-10-28 23:23:17 -06:00
|
|
|
|
2013-04-07 23:16:50 -06:00
|
|
|
// Set all log types to that verbosity level
|
2011-02-18 05:34:24 -07:00
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++)
|
2013-04-07 23:16:50 -06:00
|
|
|
{
|
2011-04-01 01:43:02 -06:00
|
|
|
m_LogManager->SetLogLevel((LogTypes::LOG_TYPE)i, (LogTypes::LOG_LEVELS)v);
|
2013-04-07 23:16:50 -06:00
|
|
|
}
|
|
|
|
|
2011-02-18 05:34:24 -07:00
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2011-02-21 08:01:00 -07:00
|
|
|
void LogConfigWindow::OnWriteFileChecked(wxCommandEvent& event)
|
2011-02-18 05:34:24 -07:00
|
|
|
{
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
{
|
|
|
|
m_writeFile = event.IsChecked();
|
|
|
|
if (m_checks->IsChecked(i))
|
|
|
|
{
|
|
|
|
if (m_writeFile)
|
2011-04-01 01:43:02 -06:00
|
|
|
m_LogManager->AddListener((LogTypes::LOG_TYPE)i, m_LogManager->GetFileListener());
|
2011-02-18 05:34:24 -07:00
|
|
|
else
|
2011-04-01 01:43:02 -06:00
|
|
|
m_LogManager->RemoveListener((LogTypes::LOG_TYPE)i, m_LogManager->GetFileListener());
|
2011-02-18 05:34:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-02-22 23:33:03 -07:00
|
|
|
void LogConfigWindow::OnWriteConsoleChecked(wxCommandEvent& event)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
{
|
|
|
|
m_writeConsole = event.IsChecked();
|
|
|
|
if (m_checks->IsChecked(i))
|
|
|
|
{
|
|
|
|
if (m_writeConsole)
|
|
|
|
m_LogManager->AddListener((LogTypes::LOG_TYPE)i, m_LogManager->GetConsoleListener());
|
|
|
|
else
|
|
|
|
m_LogManager->RemoveListener((LogTypes::LOG_TYPE)i, m_LogManager->GetConsoleListener());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-21 08:01:00 -07:00
|
|
|
void LogConfigWindow::OnWriteWindowChecked(wxCommandEvent& event)
|
2011-02-18 05:34:24 -07:00
|
|
|
{
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
{
|
|
|
|
m_writeWindow = event.IsChecked();
|
|
|
|
if (m_checks->IsChecked(i))
|
|
|
|
{
|
|
|
|
if (m_writeWindow)
|
2011-04-01 01:43:02 -06:00
|
|
|
m_LogManager->AddListener((LogTypes::LOG_TYPE)i, (LogListener *)m_LogWindow);
|
2011-02-18 05:34:24 -07:00
|
|
|
else
|
2011-04-01 01:43:02 -06:00
|
|
|
m_LogManager->RemoveListener((LogTypes::LOG_TYPE)i, (LogListener *)m_LogWindow);
|
2011-02-18 05:34:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-21 08:01:00 -07:00
|
|
|
void LogConfigWindow::OnToggleAll(wxCommandEvent& WXUNUSED(event))
|
2011-02-18 05:34:24 -07:00
|
|
|
{
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
ToggleLog(i, enableAll);
|
|
|
|
|
|
|
|
enableAll = !enableAll;
|
|
|
|
}
|
|
|
|
|
2011-02-21 08:01:00 -07:00
|
|
|
void LogConfigWindow::ToggleLog(int _logType, bool enable)
|
2011-02-18 05:34:24 -07:00
|
|
|
{
|
|
|
|
LogTypes::LOG_TYPE logType = (LogTypes::LOG_TYPE)_logType;
|
|
|
|
|
|
|
|
m_checks->Check(_logType, enable);
|
|
|
|
|
2011-04-01 01:43:02 -06:00
|
|
|
m_LogManager->SetEnable(logType, enable);
|
2011-02-18 05:34:24 -07:00
|
|
|
|
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
if (m_writeWindow)
|
2011-04-01 01:43:02 -06:00
|
|
|
m_LogManager->AddListener(logType, (LogListener *)m_LogWindow);
|
2011-02-18 05:34:24 -07:00
|
|
|
if (m_writeFile)
|
2011-04-01 01:43:02 -06:00
|
|
|
m_LogManager->AddListener(logType, m_LogManager->GetFileListener());
|
2014-02-22 23:33:03 -07:00
|
|
|
if (m_writeConsole)
|
|
|
|
m_LogManager->AddListener(logType, m_LogManager->GetConsoleListener());
|
2011-02-18 05:34:24 -07:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-04-01 01:43:02 -06:00
|
|
|
m_LogManager->RemoveListener(logType, (LogListener *)m_LogWindow);
|
|
|
|
m_LogManager->RemoveListener(logType, m_LogManager->GetFileListener());
|
2014-02-22 23:33:03 -07:00
|
|
|
m_LogManager->RemoveListener(logType, m_LogManager->GetConsoleListener());
|
2011-02-18 05:34:24 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-21 08:01:00 -07:00
|
|
|
void LogConfigWindow::OnLogCheck(wxCommandEvent& event)
|
2011-02-18 05:34:24 -07:00
|
|
|
{
|
|
|
|
int i = event.GetInt();
|
|
|
|
ToggleLog(i, m_checks->IsChecked(i));
|
|
|
|
}
|
2014-10-21 00:01:38 -06:00
|
|
|
|