Merge pull request #650 from ScegfOd/master

gui2: new logging dialog
This commit is contained in:
Celtic Minstrel 2016-06-06 12:48:45 -04:00
commit 893607e077
12 changed files with 395 additions and 0 deletions

View file

@ -182,6 +182,12 @@
type=custom
[/advanced_preference]
[advanced_preference]
field=logging
name= _ "Logging"
type=custom
[/advanced_preference]
#ifdef __UNUSED__
[advanced_preference]
field=joystick_support_enabled

View file

@ -1194,6 +1194,10 @@
name = "John Harvey (johndh)"
comment = "minor race descriptions; bats, goblins, mechanical, merman, monster, naga, ogre"
[/entry]
[entry]
name = "Jonathan Combs (ScegfOd)"
comment = "log activating dialog"
[/entry]
[entry]
name = "Jonas Lihnell (Roze)"
[/entry]

186
data/gui/window/logging.cfg Normal file
View file

@ -0,0 +1,186 @@
#textdomain wesnoth-lib
###
### Definition of the window to select logging options.
### These first five things match the names from logging.cpp
###
#define _NAME
"label"#enddef
#define _DEBUG
"debug"#enddef
#define _INFO
"info"#enddef
#define _WARN
"warn"#enddef
#define _ERR
"err"#enddef
#define _GUI_LOGGER_RADIOS GROUP TOOLTIP
[column]
grow_factor = 0
border = "all"
border_size = 5
[toggle_button]
id = {GROUP}
definition = "default"
linked_group = {GROUP}
tooltip = {TOOLTIP}
[/toggle_button]
[/column]
#enddef
[window]
id = "logging"
description = "Advanced options to control how much information is printed to console."
[resolution]
definition = "default"
automatic_placement = "true"
vertical_placement = "center"
horizontal_placement = "center"
[linked_group]
id = {_NAME}
fixed_width = "true"
[/linked_group]
[linked_group]
id = {_DEBUG}
fixed_width = "true"
[/linked_group]
[linked_group]
id = {_INFO}
fixed_width = "true"
[/linked_group]
[linked_group]
id = {_WARN}
fixed_width = "true"
[/linked_group]
[linked_group]
id = {_ERR}
fixed_width = "true"
[/linked_group]
[tooltip]
id = "tooltip"
[/tooltip]
[helptip]
id = "tooltip"
[/helptip]
[grid]
[row]
[column]
border = "all"
border_size = 5
[label]
definition = "title"
label = _ "Logging Options"
[/label]
[/column]
[/row]
[row]
grow_factor = 1
[column]
grow_factor = 1
border = "all"
border_size = 5
horizontal_grow = "true"
vertical_grow = "true"
[listbox]
id = "logger_listbox"
definition = "default"
horizontal_scrollbar_mode = "never"
[list_definition]
[row]
[column]
vertical_grow = "true"
horizontal_grow = "true"
[toggle_panel]
definition = "default"
[grid]
[row]
[column]
grow_factor = 1
horizontal_alignment = "right"
border = "all"
border_size = 5
[label]
id = {_NAME}
definition = "default"
linked_group = {_NAME}
[/label]
[/column]
{_GUI_LOGGER_RADIOS {_DEBUG} "Debug level logging: maximum information"}
{_GUI_LOGGER_RADIOS {_INFO} "Info level logging: more information"}
{_GUI_LOGGER_RADIOS {_WARN} "Warning level logging: less information"}
{_GUI_LOGGER_RADIOS {_ERR} "Error level logging: minimum information"}
[/row]
[/grid]
[/toggle_panel]
[/column]
[/row]
[/list_definition]
[/listbox]
[/column]
[/row]
[row]
grow_factor = 0
[column]
horizontal_alignment = "right"
[grid]
[row]
grow_factor = 0
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "ok"
definition = "default"
label = _ "OK"
[/button]
[/column]
[column]
border = "all"
border_size = 5
horizontal_alignment = "right"
[button]
id = "cancel"
definition = "default"
label = _ "Cancel"
[/button]
[/column]
[/row]
[/grid]
[/column]
[/row]
[/grid]
[/resolution]
[/window]
#undef _GUI_LOGGER_RADIOS
#undef _NAME
#undef _DEBUG
#undef _INFO
#undef _WARN
#undef _ERR

View file

@ -18,6 +18,10 @@ Version 1.13.4+dev:
horizontal UI resolutions < 1024 (bug #24455).
* Fixed ToD schedule progress indicator appearing behind other top bar items
on vertical UI resolutions < 600.
* Added a gui method to activate loggers (Preferences -> Advanced -> Logging)
loggers activated in the gui print just like loggers activated in the
command line (i.e. messages appear in the console)
* Miscellaneous and bug fixes:
* Allow changing keybindings for scrolling the map.

View file

@ -816,6 +816,7 @@ set(wesnoth-main_SRC
gui/dialogs/lobby/info.cpp
gui/dialogs/lobby/lobby.cpp
gui/dialogs/lobby/player_info.cpp
gui/dialogs/logging.cpp
gui/dialogs/lua_interpreter.cpp
gui/dialogs/message.cpp
gui/dialogs/multiplayer/mp_alerts_options.cpp

View file

@ -393,6 +393,7 @@ wesnoth_sources = Split("""
gui/dialogs/lobby/info.cpp
gui/dialogs/lobby/lobby.cpp
gui/dialogs/lobby/player_info.cpp
gui/dialogs/logging.cpp
gui/dialogs/lua_interpreter.cpp
gui/dialogs/message.cpp
gui/dialogs/multiplayer/mp_alerts_options.cpp

107
src/gui/dialogs/logging.cpp Normal file
View file

@ -0,0 +1,107 @@
/*
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
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; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#define GETTEXT_DOMAIN "wesnoth-lib"
#include "gui/dialogs/logging.hpp"
#include "gui/auxiliary/find_widget.hpp"
#include "gui/widgets/grid.hpp"
#include "gui/widgets/listbox.hpp"
#include "gui/widgets/settings.hpp"
#include "gui/widgets/toggle_button.hpp"
#include "gui/widgets/window.hpp"
#include "log.hpp"
namespace gui2
{
REGISTER_DIALOG(logging)
tlogging::tlogging()
{
//list of names must match those in logging.cfg
widget_id_.push_back("err");
widget_id_.push_back("warn");
widget_id_.push_back("info");
widget_id_.push_back("debug");
//empty string is the filter (in other words, this grabs the whole list of domains)
std::string temp_string = lg::list_logdomains("");
//std::cout<<temp_string; //use to print the full log domain list
std::string one_domain;
std::istringstream iss(temp_string, std::istringstream::in);
while(iss >> one_domain){
domain_list_.push_back(one_domain);
}
}
void tlogging::pre_show(twindow& window)
{
set_restore(true); //why is this done manually?
tlistbox& logger_box = find_widget<tlistbox>(&window, "logger_listbox", false);
for(unsigned int i = 0; i < domain_list_.size(); i++){
std::string this_domain = domain_list_[i];
std::map<std::string, string_map> data;
string_map item;
item["label"] = this_domain;
data["label"] = item;
logger_box.add_row(data);
tgroup<std::string>& group = groups_[this_domain];
tgrid* this_grid = logger_box.get_row_grid(i);
for(std::string this_id : widget_id_){
twidget* this_widget = this_grid->find(this_id, false);
ttoggle_button* button = dynamic_cast<ttoggle_button*>(this_widget);
if(button != nullptr) {
group.add_member(button, this_id);
}
}
int current_sev;
if (lg::get_log_domain_severity(this_domain, current_sev)){
group.set_member_states(widget_id_[current_sev]);
}
}
}
void tlogging::post_show(twindow& /*window*/)
{
for(std::string this_domain : domain_list_){
set_logger(this_domain);
}
}
void tlogging::set_logger(const std::string log_domain)
{
std::string active_value = groups_[log_domain].get_active_member_value();
if(active_value == widget_id_[1]){ //default value, level1: warning
lg::set_log_domain_severity(log_domain, lg::warn());
} else if(active_value == widget_id_[3]){ //level3: debug
lg::set_log_domain_severity(log_domain, lg::debug());
} else if(active_value == widget_id_[2]){ //level2: info
lg::set_log_domain_severity(log_domain, lg::info());
} else if(active_value == widget_id_[0]){ //level0: error
lg::set_log_domain_severity(log_domain, lg::err());
}
}
} // end namespace gui2

View file

@ -0,0 +1,62 @@
/*
Part of the Battle for Wesnoth Project http://www.wesnoth.org/
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; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY.
See the COPYING file for more details.
*/
#ifndef GUI_LOGGING_HPP_INCLUDED
#define GUI_LOGGING_HPP_INCLUDED
#include "gui/dialogs/dialog.hpp"
#include "gui/widgets/group.hpp"
#include <map>
namespace gui2
{
class tlabel;
class ttoggle_button;
class tlogging : public tdialog
{
public:
/** Constructor. */
tlogging();
/**
* The display function.
*
* See @ref tdialog for more information.
*/
static void display(CVideo& video)
{
tlogging().show(video);
}
private:
void set_logger(const std::basic_string<char> log_domain);
std::map<std::string, tgroup<std::string> > groups_;
std::vector<std::string> domain_list_, widget_id_;
/** Inherited from tdialog, implemented by REGISTER_DIALOG. */
virtual const std::string& window_id() const;
/** Inherited from tdialog. */
void pre_show(twindow& window);
/** Inherited from tdialog. */
void post_show(twindow& window);
};
} // end namespace gui2
#endif

View file

@ -33,6 +33,7 @@
// Sub-dialog includes
#include "gui/dialogs/advanced_graphics_options.hpp"
#include "gui/dialogs/game_cache_options.hpp"
#include "gui/dialogs/logging.hpp"
#include "gui/dialogs/multiplayer/mp_alerts_options.hpp"
#include "gui/dialogs/select_orb_colors.hpp"
@ -1039,6 +1040,8 @@ void tpreferences::on_advanced_prefs_list_select(tlistbox& list, twindow& window
if(selected_type == ADVANCED_PREF_TYPE::SPECIAL) {
if (selected_field == "advanced_graphic_options") {
gui2::tadvanced_graphics_options::display(window.video());
} else if (selected_field == "logging") {
gui2::tlogging::display(window.video());
} else if (selected_field == "orb_color") {
gui2::tselect_orb_colors::display(window.video());
} else {

View file

@ -138,6 +138,15 @@ bool set_log_domain_severity(std::string const &name, const logger &lg) {
return set_log_domain_severity(name, lg.get_severity());
}
bool get_log_domain_severity(std::string const &name, int &severity)
{
domain_map::iterator it = domains->find(name);
if (it == domains->end())
return false;
severity = it->second;
return true;
}
std::string list_logdomains(const std::string& filter)
{
std::ostringstream res;

View file

@ -104,6 +104,7 @@ public:
bool set_log_domain_severity(std::string const &name, int severity);
bool set_log_domain_severity(std::string const &name, const logger &lg);
bool get_log_domain_severity(std::string const &name, int &severity);
std::string list_logdomains(const std::string& filter);
void set_strict_severity(int severity);

View file

@ -53,6 +53,7 @@
#include "gui/dialogs/loadscreen.hpp"
#include "gui/dialogs/lobby/lobby.hpp"
#include "gui/dialogs/lobby/player_info.hpp"
#include "gui/dialogs/logging.hpp"
#include "gui/dialogs/lua_interpreter.hpp"
#include "gui/dialogs/message.hpp"
#include "gui/dialogs/multiplayer/mp_alerts_options.hpp"
@ -387,6 +388,7 @@ BOOST_AUTO_TEST_CASE(test_gui2)
// test<gui2::tloadscreen>(); TODO: enable
test<gui2::tlobby_main>();
test<gui2::tlobby_player_info>();
test<gui2::tlogging>();
test<gui2::tmessage>();
test<gui2::tmp_change_control>();
test<gui2::tmp_cmd_wrapper>();
@ -723,6 +725,15 @@ struct twrapper<gui2::tlobby_player_info>
}
};
template<>
struct twrapper<gui2::tlogging>
{
static gui2::tlogging* create()
{
return new gui2::tlogging();
}
};
template<>
struct twrapper<gui2::tmessage>
{