The Battle for Wesnoth  1.17.17+dev
mp_alerts_options.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2023
3  by Chris Beck <render787@gmail.com>
4  Part of the Battle for Wesnoth Project https://www.wesnoth.org/
5 
6  This program is free software; you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation; either version 2 of the License, or
9  (at your option) any later version.
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY.
12 
13  See the COPYING file for more details.
14 */
15 
16 #define GETTEXT_DOMAIN "wesnoth-lib"
17 
19 
22 #include "gui/dialogs/message.hpp"
23 #include "gui/widgets/button.hpp"
24 #include "gui/widgets/label.hpp"
25 #include "gui/widgets/settings.hpp"
27 #include "gui/widgets/window.hpp"
28 
29 #include "mp_ui_alerts.hpp"
30 #include "preferences/general.hpp"
31 
32 #include <functional>
33 
34 #include "gettext.hpp"
35 
36 namespace gui2::dialogs
37 {
38 
39 static toggle_button * setup_pref_toggle_button(const std::string & id, bool def, window & window)
40 {
41  toggle_button * b = find_widget<toggle_button>(&window, id, false, true);
42  b->set_value(preferences::get(id, def));
43 
44  //ensure we have yes / no for the toggle button, so that the preference matches the toggle button for sure.
45  if (preferences::get(id).empty()) {
46  preferences::set(id, def);
47  }
48 
49  connect_signal_mouse_left_click(*b, std::bind([b, id]() { preferences::set(id, b->get_value_bool()); }));
50 
51  return b;
52 }
53 
54 static void setup_item(const std::string & item, window & window)
55 {
56  // Set up the sound checkbox
58 
59  // Set up the notification checkbox
61 
62  // Check if desktop notifications are available
64  notif->set_value(false);
65  notif->set_active(false);
66  preferences::set(item+"_notif", false);
67  } else {
68  notif->set_active(true);
69  }
70 
71  // Set up the in_lobby checkbox
73 }
74 
75 static void set_pref_and_button(const std::string & id, bool value, window & window)
76 {
77  preferences::set(id,value);
78  toggle_button * button = find_widget<toggle_button>(&window, id, false, true);
79  button->set_value(value);
80 }
81 
83 {
84  for (const std::string & i : mp::ui_alerts::items) {
88  }
89 }
90 
92 
94  : modal_dialog(window_id())
95 {
96 }
97 
99 {
100  for (const std::string & i : mp::ui_alerts::items) {
101  setup_item(i, window);
102  }
103 
105  label * nlabel = find_widget<label>(&window, "notification_label", false, true);
106  nlabel->set_tooltip(_("This build of wesnoth does not include support for desktop notifications, contact your package manager"));
107  }
108 
109  toggle_button * in_lobby;
110  in_lobby = find_widget<toggle_button>(&window,"ready_for_start_lobby", false, true);
112 
113  in_lobby = find_widget<toggle_button>(&window,"game_has_begun_lobby", false, true);
115 
116  in_lobby = find_widget<toggle_button>(&window,"turn_changed_sound", false, true); // If we get a sound for this then don't remove this button
118 
119  in_lobby = find_widget<toggle_button>(&window,"turn_changed_lobby", false, true);
121 
122  button * defaults;
123  defaults = find_widget<button>(&window,"revert_to_defaults", false, true);
124  connect_signal_mouse_left_click(*defaults, std::bind(&revert_to_default_pref_values, std::ref(window)));
125 }
126 
128 {
129 }
130 
131 } // namespace dialogs
Simple push button.
Definition: button.hpp:37
Abstract base class for all modal dialogs.
A Preferences subdialog permitting to configure the sounds and notifications generated in response to...
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
A label displays a text, the text can be wrapped but no scrollbars are provided.
Definition: label.hpp:58
void set_tooltip(const t_string &tooltip)
Class for a toggle button.
virtual void set_value(unsigned selected, bool fire_event=false) override
Inherited from selectable_item.
virtual void set_active(const bool active) override
See styled_widget::set_active.
void set_visible(const visibility visible)
Definition: widget.cpp:456
@ invisible
The user set the widget invisible, that means:
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:67
std::size_t i
Definition: function.cpp:968
static std::string _(const char *str)
Definition: gettext.hpp:93
This file contains the window object, this object is a top level container which has the event manage...
#define REGISTER_DIALOG(window_id)
Wrapper for REGISTER_DIALOG2.
bool available()
Returns whether we were compiled with support for desktop notifications.
static void set_pref_and_button(const std::string &id, bool value, window &window)
static void revert_to_default_pref_values(window &window)
static void setup_item(const std::string &item, window &window)
static toggle_button * setup_pref_toggle_button(const std::string &id, bool def, window &window)
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:179
std::pair< std::string, unsigned > item
Definition: help_impl.hpp:414
const std::vector< std::string > items
bool get_def_pref_lobby(const std::string &id)
bool get_def_pref_sound(const std::string &id)
bool get_def_pref_notif(const std::string &id)
void set(const std::string &key, bool value)
Definition: general.cpp:165
std::string get(const std::string &key)
Definition: general.cpp:213
This file contains the settings handling of the widget library.
#define b