2011-02-18 12:34:24 +00:00
|
|
|
// Copyright (C) 2003 Dolphin Project.
|
|
|
|
|
|
|
|
// This program is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, version 2.0.
|
|
|
|
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License 2.0 for more details.
|
|
|
|
|
|
|
|
// A copy of the GPL 2.0 should have been included with the program.
|
|
|
|
// If not, see http://www.gnu.org/licenses/
|
|
|
|
|
|
|
|
// Official SVN repository and contact information can be found at
|
|
|
|
// http://code.google.com/p/dolphin-emu/
|
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
#include "LogConfigWindow.h"
|
2011-02-18 12:34:24 +00:00
|
|
|
#include "LogManager.h"
|
|
|
|
#include "ConsoleListener.h"
|
|
|
|
#include "LogWindow.h"
|
|
|
|
#include "FileUtil.h"
|
|
|
|
|
|
|
|
#define _connect_macro_(b, f, c, s) \
|
2011-02-18 20:03:01 +00:00
|
|
|
(b)->Connect(wxID_ANY, (c), wxCommandEventHandler(f), (wxObject*)0, (wxEvtHandler*)s)
|
2011-02-18 12:34:24 +00:00
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
LogConfigWindow::LogConfigWindow(wxWindow* parent, CLogWindow *log_window, wxWindowID id)
|
|
|
|
: wxPanel(parent, id, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL, _("Log Configuration"))
|
2011-02-18 20:03:01 +00:00
|
|
|
, m_LogWindow(log_window), enableAll(true)
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
|
|
|
m_LogManager = LogManager::GetInstance();
|
|
|
|
CreateGUIControls();
|
|
|
|
LoadSettings();
|
|
|
|
}
|
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
LogConfigWindow::~LogConfigWindow()
|
|
|
|
{
|
|
|
|
SaveSettings();
|
|
|
|
}
|
|
|
|
|
|
|
|
void LogConfigWindow::CreateGUIControls()
|
2011-02-18 12:34:24 +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, wxDefaultValidator);
|
2011-02-21 15:01:00 +00:00
|
|
|
_connect_macro_(m_verbosity, LogConfigWindow::OnVerbosityChange, wxEVT_COMMAND_RADIOBOX_SELECTED, this);
|
2011-02-18 12:34:24 +00:00
|
|
|
|
|
|
|
// Options
|
|
|
|
m_writeFileCB = new wxCheckBox(this, wxID_ANY, _("Write to File"));
|
2011-02-21 15:01:00 +00:00
|
|
|
_connect_macro_(m_writeFileCB, LogConfigWindow::OnWriteFileChecked, wxEVT_COMMAND_CHECKBOX_CLICKED, this);
|
2011-02-18 12:34:24 +00:00
|
|
|
m_writeConsoleCB = new wxCheckBox(this, wxID_ANY, _("Write to Console"));
|
2011-02-21 15:01:00 +00:00
|
|
|
_connect_macro_(m_writeConsoleCB, LogConfigWindow::OnWriteConsoleChecked, wxEVT_COMMAND_CHECKBOX_CLICKED, this);
|
2011-02-18 12:34:24 +00:00
|
|
|
m_writeWindowCB = new wxCheckBox(this, wxID_ANY, _("Write to Window"));
|
2011-02-21 15:01:00 +00:00
|
|
|
_connect_macro_(m_writeWindowCB, LogConfigWindow::OnWriteWindowChecked, wxEVT_COMMAND_CHECKBOX_CLICKED, this);
|
2011-02-18 12:34:24 +00:00
|
|
|
|
|
|
|
wxButton *btn_toggle_all = new wxButton(this, wxID_ANY, _("Toggle All Log Types"),
|
|
|
|
wxDefaultPosition, wxDefaultSize, wxBU_EXACTFIT);
|
2011-02-21 15:01:00 +00:00
|
|
|
_connect_macro_(btn_toggle_all, LogConfigWindow::OnToggleAll, wxEVT_COMMAND_BUTTON_CLICKED, this);
|
2011-02-18 12:34:24 +00:00
|
|
|
m_checks = new wxCheckListBox(this, wxID_ANY);
|
2011-02-21 15:01:00 +00:00
|
|
|
_connect_macro_(m_checks, LogConfigWindow::OnLogCheck, wxEVT_COMMAND_CHECKLISTBOX_TOGGLED, this);
|
2011-02-18 12:34:24 +00:00
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++)
|
|
|
|
m_checks->Append(wxString::FromAscii(m_LogManager->getFullName((LogTypes::LOG_TYPE)i)));
|
|
|
|
|
|
|
|
// Sizers
|
2011-02-21 15:01:00 +00:00
|
|
|
wxStaticBoxSizer* sbOutputs = new wxStaticBoxSizer(wxVERTICAL, this, _("Logger Outputs"));
|
|
|
|
sbOutputs->Add(m_writeFileCB, 0, wxDOWN, 1);
|
|
|
|
sbOutputs->Add(m_writeConsoleCB, 0, wxDOWN, 1);
|
|
|
|
sbOutputs->Add(m_writeWindowCB, 0);
|
2011-02-18 12:34:24 +00:00
|
|
|
|
|
|
|
wxStaticBoxSizer* sbLogTypes = new wxStaticBoxSizer(wxVERTICAL, this, _("Log Types"));
|
|
|
|
sbLogTypes->Add(m_checks, 1, wxEXPAND);
|
|
|
|
|
|
|
|
wxBoxSizer *sMain = new wxBoxSizer(wxVERTICAL);
|
2011-02-21 15:01:00 +00: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 12:34:24 +00:00
|
|
|
|
|
|
|
SetSizer(sMain);
|
|
|
|
Layout();
|
|
|
|
}
|
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
void LogConfigWindow::LoadSettings()
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
|
|
|
IniFile ini;
|
|
|
|
ini.Load(File::GetUserPath(F_LOGGERCONFIG_IDX));
|
|
|
|
|
|
|
|
int verbosity;
|
|
|
|
ini.Get("Options", "Verbosity", &verbosity, 0);
|
|
|
|
if (verbosity < 1) verbosity = 1;
|
|
|
|
if (verbosity > MAX_LOGLEVEL) verbosity = MAX_LOGLEVEL;
|
|
|
|
m_verbosity->SetSelection(verbosity - 1);
|
|
|
|
|
|
|
|
ini.Get("Options", "WriteToFile", &m_writeFile, false);
|
|
|
|
m_writeFileCB->SetValue(m_writeFile);
|
|
|
|
ini.Get("Options", "WriteToConsole", &m_writeConsole, true);
|
|
|
|
m_writeConsoleCB->SetValue(m_writeConsole);
|
|
|
|
ini.Get("Options", "WriteToWindow", &m_writeWindow, true);
|
|
|
|
m_writeWindowCB->SetValue(m_writeWindow);
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
{
|
|
|
|
bool log_enabled;
|
|
|
|
ini.Get("Logs", m_LogManager->getShortName((LogTypes::LOG_TYPE)i), &log_enabled, true);
|
2011-02-18 20:03:01 +00:00
|
|
|
if (log_enabled) enableAll=false;
|
2011-02-18 12:34:24 +00:00
|
|
|
m_checks->Check(i, log_enabled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
void LogConfigWindow::SaveSettings()
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
|
|
|
IniFile ini;
|
|
|
|
ini.Load(File::GetUserPath(F_LOGGERCONFIG_IDX));
|
|
|
|
|
|
|
|
ini.Set("Options", "Verbosity", m_verbosity->GetSelection() + 1);
|
|
|
|
ini.Set("Options", "WriteToFile", m_writeFile);
|
|
|
|
ini.Set("Options", "WriteToConsole", m_writeConsole);
|
|
|
|
ini.Set("Options", "WriteToWindow", m_writeWindow);
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
ini.Set("Logs", m_LogManager->getShortName((LogTypes::LOG_TYPE)i), m_checks->IsChecked(i));
|
|
|
|
ini.Save(File::GetUserPath(F_LOGGERCONFIG_IDX));
|
|
|
|
}
|
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
void LogConfigWindow::OnVerbosityChange(wxCommandEvent& event)
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
|
|
|
int v = m_verbosity->GetSelection() + 1;
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; i++)
|
|
|
|
m_LogManager->setLogLevel((LogTypes::LOG_TYPE)i, (LogTypes::LOG_LEVELS)v);
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
void LogConfigWindow::OnWriteFileChecked(wxCommandEvent& event)
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
{
|
|
|
|
m_writeFile = event.IsChecked();
|
|
|
|
if (m_checks->IsChecked(i))
|
|
|
|
{
|
|
|
|
if (m_writeFile)
|
|
|
|
m_LogManager->addListener((LogTypes::LOG_TYPE)i, m_LogManager->getFileListener());
|
|
|
|
else
|
|
|
|
m_LogManager->removeListener((LogTypes::LOG_TYPE)i, m_LogManager->getFileListener());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
void LogConfigWindow::OnWriteConsoleChecked(wxCommandEvent& event)
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
|
|
|
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 15:01:00 +00:00
|
|
|
void LogConfigWindow::OnWriteWindowChecked(wxCommandEvent& event)
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
{
|
|
|
|
m_writeWindow = event.IsChecked();
|
|
|
|
if (m_checks->IsChecked(i))
|
|
|
|
{
|
|
|
|
if (m_writeWindow)
|
|
|
|
m_LogManager->addListener((LogTypes::LOG_TYPE)i, (LogListener *)m_LogWindow);
|
|
|
|
else
|
|
|
|
m_LogManager->removeListener((LogTypes::LOG_TYPE)i, (LogListener *)m_LogWindow);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
void LogConfigWindow::OnToggleAll(wxCommandEvent& WXUNUSED(event))
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
|
|
|
for (int i = 0; i < LogTypes::NUMBER_OF_LOGS; ++i)
|
|
|
|
ToggleLog(i, enableAll);
|
|
|
|
|
|
|
|
enableAll = !enableAll;
|
|
|
|
}
|
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
void LogConfigWindow::ToggleLog(int _logType, bool enable)
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
|
|
|
LogTypes::LOG_TYPE logType = (LogTypes::LOG_TYPE)_logType;
|
|
|
|
|
|
|
|
m_checks->Check(_logType, enable);
|
|
|
|
|
|
|
|
m_LogManager->setEnable(logType, enable);
|
|
|
|
|
|
|
|
if (enable)
|
|
|
|
{
|
|
|
|
if (m_writeWindow)
|
|
|
|
m_LogManager->addListener(logType, (LogListener *)m_LogWindow);
|
|
|
|
if (m_writeFile)
|
|
|
|
m_LogManager->addListener(logType, m_LogManager->getFileListener());
|
|
|
|
if (m_writeConsole)
|
|
|
|
m_LogManager->addListener(logType, m_LogManager->getConsoleListener());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_LogManager->removeListener(logType, (LogListener *)m_LogWindow);
|
|
|
|
m_LogManager->removeListener(logType, m_LogManager->getFileListener());
|
|
|
|
m_LogManager->removeListener(logType, m_LogManager->getConsoleListener());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-02-21 15:01:00 +00:00
|
|
|
void LogConfigWindow::OnLogCheck(wxCommandEvent& event)
|
2011-02-18 12:34:24 +00:00
|
|
|
{
|
|
|
|
int i = event.GetInt();
|
|
|
|
ToggleLog(i, m_checks->IsChecked(i));
|
|
|
|
}
|