The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
logging.cpp
Go to the documentation of this file.
1 /*
2  Part of the Battle for Wesnoth Project http://www.wesnoth.org/
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8  This program is distributed in the hope that it will be useful,
9  but WITHOUT ANY WARRANTY.
10 
11  See the COPYING file for more details.
12  */
13 
14 #define GETTEXT_DOMAIN "wesnoth-lib"
15 
16 #include "gui/dialogs/logging.hpp"
17 
19 #include "gui/widgets/grid.hpp"
20 #include "gui/widgets/listbox.hpp"
21 #include "gui/widgets/settings.hpp"
23 #include "gui/widgets/window.hpp"
24 
25 #include "log.hpp"
26 
27 namespace gui2
28 {
29 
30 REGISTER_DIALOG(logging)
31 
33 {
34  //list of names must match those in logging.cfg
35  widget_id_.push_back("err");
36  widget_id_.push_back("warn");
37  widget_id_.push_back("info");
38  widget_id_.push_back("debug");
39 
40 
41  //empty string is the filter (in other words, this grabs the whole list of domains)
42  std::string temp_string = lg::list_logdomains("");
43  //std::cout<<temp_string; //use to print the full log domain list
44  std::string one_domain;
45 
46  std::istringstream iss(temp_string, std::istringstream::in);
47 
48  while(iss >> one_domain){
49  domain_list_.push_back(one_domain);
50  }
51 }
52 
54 {
55  set_restore(true); //why is this done manually?
56 
57  tlistbox& logger_box = find_widget<tlistbox>(&window, "logger_listbox", false);
58 
59  for(unsigned int i = 0; i < domain_list_.size(); i++){
60  std::string this_domain = domain_list_[i];
61  std::map<std::string, string_map> data;
62  string_map item;
63 
64  item["label"] = this_domain;
65  data["label"] = item;
66 
67  logger_box.add_row(data);
68  tgroup<std::string>& group = groups_[this_domain];
69 
70  tgrid* this_grid = logger_box.get_row_grid(i);
71  for(std::string this_id : widget_id_){
72  twidget* this_widget = this_grid->find(this_id, false);
73  ttoggle_button* button = dynamic_cast<ttoggle_button*>(this_widget);
74  if(button != nullptr) {
75  group.add_member(button, this_id);
76  }
77  }
78  int current_sev;
79  if (lg::get_log_domain_severity(this_domain, current_sev)){
80  group.set_member_states(widget_id_[current_sev]);
81  }
82  }
83 }
84 
85 void tlogging::post_show(twindow& /*window*/)
86 {
87  for(std::string this_domain : domain_list_){
88  set_logger(this_domain);
89  }
90 }
91 
92 void tlogging::set_logger(const std::string log_domain)
93 {
94  std::string active_value = groups_[log_domain].get_active_member_value();
95 
96  if(active_value == widget_id_[1]){ //default value, level1: warning
98  } else if(active_value == widget_id_[3]){ //level3: debug
100  } else if(active_value == widget_id_[2]){ //level2: info
101  lg::set_log_domain_severity(log_domain, lg::info());
102  } else if(active_value == widget_id_[0]){ //level0: error
103  lg::set_log_domain_severity(log_domain, lg::err());
104  }
105 }
106 
107 } // end namespace gui2
std::vector< std::string > widget_id_
Definition: logging.hpp:47
void pre_show(twindow &window)
Inherited from tdialog.
Definition: logging.cpp:53
logger & info()
Definition: log.cpp:91
Base container class.
Definition: grid.hpp:29
This file contains the window object, this object is a top level container which has the event manage...
REGISTER_DIALOG(label_settings)
GLint GLenum GLsizei GLint GLsizei const GLvoid * data
Definition: glew.h:1347
GLuint in
Definition: glew.h:9261
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:62
Class for a toggle button.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
bool set_log_domain_severity(std::string const &name, int severity)
Definition: log.cpp:117
void set_logger(const std::basic_string< char > log_domain)
Definition: logging.cpp:92
This file contains the settings handling of the widget library.
void add_row(const string_map &item, const int index=-1)
When an item in the list is selected by the user we need to update the state.
Definition: listbox.cpp:74
void set_restore(const bool restore)
Definition: dialog.hpp:171
std::map< std::string, tgroup< std::string > > groups_
Definition: logging.hpp:46
logger & debug()
Definition: log.cpp:97
std::map< std::string, t_string > string_map
Definition: generator.hpp:23
logger & err()
Definition: log.cpp:79
The listbox class.
Definition: listbox.hpp:39
size_t i
Definition: function.cpp:1057
bool get_log_domain_severity(std::string const &name, int &severity)
Definition: log.cpp:141
GLboolean GLuint group
Definition: glew.h:2589
logger & warn()
Definition: log.cpp:85
std::string list_logdomains(const std::string &filter)
Definition: log.cpp:150
Base class for all widgets.
Definition: widget.hpp:49
void post_show(twindow &window)
Inherited from tdialog.
Definition: logging.cpp:85
Standard logging facilities (interface).
twidget * find(const std::string &id, const bool must_be_active) override
See twidget::find.
Definition: grid.cpp:612
void add_member(tselectable_ *widget, const T &value)
Adds a widget/value pair to the group vector.
Definition: group.hpp:43
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void set_member_states(const T &value)
Sets the toggle values for all widgets besides the one associated with the specified value to false...
Definition: group.hpp:113
std::vector< std::string > domain_list_
Definition: logging.hpp:47
const tgrid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
Definition: listbox.cpp:215