The Battle for Wesnoth 1.21.0-dev
 
Loading...
Searching...
No Matches
log_settings.cpp
Go to the documentation of this file.
1/*
2 Copyright (C) 2017 - 2025
3 Part of the Battle for Wesnoth Project https://www.wesnoth.org/
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY.
11
12 See the COPYING file for more details.
13*/
14
15#define GETTEXT_DOMAIN "wesnoth-lib"
16
18
19#include "gettext.hpp"
20#include "gui/widgets/grid.hpp"
25#include "utils/ci_searcher.hpp"
26
27#include "log.hpp"
28
29namespace gui2::dialogs
30{
31
32REGISTER_DIALOG(log_settings)
33
35 : modal_dialog(window_id())
36{
37 //list of names must match those in logging.cfg
38 widget_id_.push_back("none");
39 widget_id_.push_back("err");
40 widget_id_.push_back("warn");
41 widget_id_.push_back("info");
42 widget_id_.push_back("debug");
43
44
45 //empty string is the filter (in other words, this grabs the whole list of domains)
46 std::string temp_string = lg::list_log_domains("");
47 //std::cout<<temp_string; //use to print the full log domain list
48 std::string one_domain;
49
50 std::istringstream iss(temp_string, std::istringstream::in);
51
52 while(iss >> one_domain){
53 domain_list_.push_back(one_domain);
54 }
55}
56
58{
59 listbox& logger_box = find_widget<listbox>("logger_listbox");
60
61 for(unsigned int i = 0; i < domain_list_.size(); i++){
62 std::string this_domain = domain_list_[i];
63
64 logger_box.add_row(widget_data{{ "label", {{ "label", this_domain }}}});
65 group<std::string>& group = groups_[this_domain];
66
67 grid* this_grid = logger_box.get_row_grid(i);
68 for(std::string this_id : widget_id_){
69 widget* this_widget = this_grid->find(this_id, false);
70 toggle_button* button = dynamic_cast<toggle_button*>(this_widget);
71 if(button != nullptr) {
72 group.add_member(button, this_id);
73 }
74 }
75 lg::severity current_sev;
77 if (lg::get_log_domain_severity(this_domain, current_sev)) {
78 if (current_sev <= max_sev) {
79 group.set_member_states(widget_id_[static_cast<int>(current_sev) + 1]);
80 }
81 }
82 }
83
84 text_box* filter = find_widget<text_box>("filter_box", false, true);
85 filter->on_modified([this](const auto& box) { filter_text_changed(box.text()); });
86
87#ifdef __IPHONEOS__
88 // On iOS, opening log settings should not immediately summon the
89 // software keyboard just because the optional filter field exists.
90 keyboard_capture(&logger_box);
91#else
92 keyboard_capture(filter);
93#endif
94 add_to_keyboard_chain(&logger_box);
95}
96
97void log_settings::filter_text_changed(const std::string& text)
98{
99 find_widget<listbox>("logger_listbox").filter_rows_by(
100 [this, match = translation::make_ci_matcher(text)](std::size_t row) { return match(domain_list_[row]); });
101}
102
104{
105 for(std::string this_domain : domain_list_){
106 set_logger(this_domain);
107 }
108}
109
110void log_settings::set_logger(const std::string& log_domain)
111{
112 std::string active_value = groups_[log_domain].get_active_member_value();
113
114 if(active_value == widget_id_[2]){ //default value, level1: warning
116 } else if(active_value == widget_id_[4]){ //level3: debug
118 } else if(active_value == widget_id_[3]){ //level2: info
120 } else if(active_value == widget_id_[1]){ //level0: error
122 } else if(active_value == widget_id_[0]){ //level-1: disable
124 }
125}
126
127} // namespace dialogs
Simple push button.
Definition button.hpp:36
void set_logger(const std::basic_string< char > &log_domain)
The display function.
std::vector< std::string > domain_list_
void filter_text_changed(const std::string &text)
virtual void post_show() override
Actions to be taken after the window has been shown.
std::map< std::string, group< std::string > > groups_
std::vector< std::string > widget_id_
virtual void pre_show() override
Actions to be taken before showing the window.
Abstract base class for all modal dialogs.
Base container class.
Definition grid.hpp:32
widget * find(const std::string_view id, const bool must_be_active) override
See widget::find.
Definition grid.cpp:645
void add_member(selectable_item *w, const T &value)
Adds a widget/value pair to the group map.
Definition group.hpp:41
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
The listbox class.
Definition listbox.hpp:41
grid & add_row(const widget_item &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:92
const grid * get_row_grid(const unsigned row) const
Returns the grid of the wanted row.
Definition listbox.cpp:256
A widget that allows the user to input text in single line.
Definition text_box.hpp:125
Base class for all widgets.
Definition widget.hpp:55
void keyboard_capture(widget *widget)
Definition window.cpp:1197
void add_to_keyboard_chain(widget *widget)
Adds the widget to the keyboard chain.
Definition window.cpp:1211
This file contains the window object, this object is a top level container which has the event manage...
Standard logging facilities (interface).
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
std::map< std::string, widget_item > widget_data
Definition widget.hpp:36
bool get_log_domain_severity(const std::string &name, severity &severity)
Definition log.cpp:401
logger & err()
Definition log.cpp:339
severity
Definition log.hpp:82
std::string list_log_domains(const std::string &filter)
Definition log.cpp:410
logger & debug()
Definition log.cpp:357
logger & warn()
Definition log.cpp:345
logger & info()
Definition log.cpp:351
bool set_log_domain_severity(const std::string &name, severity severity)
Definition log.cpp:379
auto make_ci_matcher(std::string_view filter_text)
Returns a function which performs locale-aware case-insensitive search.
#define i