The Battle for Wesnoth  1.15.1+dev
log_settings.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2017-2018 by the Battle for Wesnoth Project https://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 
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 namespace dialogs
30 {
31 
32 REGISTER_DIALOG(log_settings)
33 
35 {
36  //list of names must match those in logging.cfg
37  widget_id_.push_back("none");
38  widget_id_.push_back("err");
39  widget_id_.push_back("warn");
40  widget_id_.push_back("info");
41  widget_id_.push_back("debug");
42 
43 
44  //empty string is the filter (in other words, this grabs the whole list of domains)
45  std::string temp_string = lg::list_logdomains("");
46  //std::cout<<temp_string; //use to print the full log domain list
47  std::string one_domain;
48 
49  std::istringstream iss(temp_string, std::istringstream::in);
50 
51  while(iss >> one_domain){
52  domain_list_.push_back(one_domain);
53  }
54 }
55 
57 {
58  set_restore(true); //why is this done manually?
59 
60  listbox& logger_box = find_widget<listbox>(&window, "logger_listbox", false);
61 
62  for(unsigned int i = 0; i < domain_list_.size(); i++){
63  std::string this_domain = domain_list_[i];
64  std::map<std::string, string_map> data;
66 
67  item["label"] = this_domain;
68  data["label"] = item;
69 
70  logger_box.add_row(data);
71  group<std::string>& group = groups_[this_domain];
72 
73  grid* this_grid = logger_box.get_row_grid(i);
74  for(std::string this_id : widget_id_){
75  widget* this_widget = this_grid->find(this_id, false);
76  toggle_button* button = dynamic_cast<toggle_button*>(this_widget);
77  if(button != nullptr) {
78  group.add_member(button, this_id);
79  }
80  }
81  int current_sev, max_sev = widget_id_.size();
82  if (lg::get_log_domain_severity(this_domain, current_sev)) {
83  if (current_sev <= max_sev) {
84  group.set_member_states(widget_id_[current_sev + 1]);
85  }
86  }
87  }
88 }
89 
91 {
92  for(std::string this_domain : domain_list_){
93  set_logger(this_domain);
94  }
95 }
96 
97 void log_settings::set_logger(const std::string log_domain)
98 {
99  std::string active_value = groups_[log_domain].get_active_member_value();
100 
101  if(active_value == widget_id_[2]){ //default value, level1: warning
102  lg::set_log_domain_severity(log_domain, lg::warn());
103  } else if(active_value == widget_id_[4]){ //level3: debug
104  lg::set_log_domain_severity(log_domain, lg::debug());
105  } else if(active_value == widget_id_[3]){ //level2: info
106  lg::set_log_domain_severity(log_domain, lg::info());
107  } else if(active_value == widget_id_[1]){ //level0: error
108  lg::set_log_domain_severity(log_domain, lg::err());
109  } else if(active_value == widget_id_[0]){ //level-1: disable
110  lg::set_log_domain_severity(log_domain, -1);
111  }
112 }
113 
114 } // namespace dialogs
115 } // namespace gui2
std::vector< std::string > widget_id_
logger & info()
Definition: log.cpp:90
std::vector< std::string > domain_list_
This file contains the window object, this object is a top level container which has the event manage...
Base class for all widgets.
Definition: widget.hpp:47
void set_logger(const std::basic_string< char > log_domain)
The display function.
Generic file dialog.
Definition: field-fwd.hpp:22
unsigned in
If equal to search_counter, the node is off the list.
The listbox class.
Definition: listbox.hpp:40
Base container class.
Definition: grid.hpp:30
bool get_log_domain_severity(const std::string &name, int &severity)
Definition: log.cpp:142
This file contains the settings handling of the widget library.
virtual void pre_show(window &window) override
Inherited from modal_dialog.
widget * find(const std::string &id, const bool must_be_active) override
See widget::find.
Definition: grid.cpp:655
logger & debug()
Definition: log.cpp:96
Various uncategorised dialogs.
void add_member(selectable_item *w, const T &value)
Adds a widget/value pair to the group map.
Definition: group.hpp:41
std::size_t i
Definition: function.cpp:933
logger & err()
Definition: log.cpp:78
std::map< std::string, t_string > string_map
Definition: widget.hpp:24
grid & 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:66
std::map< std::string, group< std::string > > groups_
bool set_log_domain_severity(const std::string &name, int severity)
Definition: log.cpp:118
const grid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
Definition: listbox.cpp:237
logger & warn()
Definition: log.cpp:84
std::string list_logdomains(const std::string &filter)
Definition: log.cpp:151
Simple push button.
Definition: button.hpp:35
Standard logging facilities (interface).
base class of top level items, the only item which needs to store the final canvases to draw on ...
Definition: window.hpp:63
Class for a toggle button.
void set_restore(const bool restore)
std::pair< std::string, unsigned > item
Definition: help_impl.hpp:371
virtual void post_show(window &window) override
Inherited from modal_dialog.
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:110