The Battle for Wesnoth  1.17.0-dev
mp_alerts_options.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2021
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
57  setup_pref_toggle_button(item+"_sound", mp_ui_alerts::get_def_pref_sound(item), window);
58 
59  // Set up the notification checkbox
60  toggle_button * notif = setup_pref_toggle_button(item+"_notif", mp_ui_alerts::get_def_pref_notif(item), window);
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
72  setup_pref_toggle_button(item+"_lobby", mp_ui_alerts::get_def_pref_lobby(item), window);
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 {
95 }
96 
98 {
99  for (const std::string & i : mp_ui_alerts::items) {
100  setup_item(i, window);
101  }
102 
104  label * nlabel = find_widget<label>(&window, "notification_label", false, true);
105  nlabel->set_tooltip(_("This build of wesnoth does not include support for desktop notifications, contact your package manager"));
106  }
107 
108  toggle_button * in_lobby;
109  in_lobby = find_widget<toggle_button>(&window,"ready_for_start_lobby", false, true);
111 
112  in_lobby = find_widget<toggle_button>(&window,"game_has_begun_lobby", false, true);
114 
115  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
117 
118  in_lobby = find_widget<toggle_button>(&window,"turn_changed_lobby", false, true);
120 
121  button * defaults;
122  defaults = find_widget<button>(&window,"revert_to_defaults", false, true);
123  connect_signal_mouse_left_click(*defaults, std::bind(&revert_to_default_pref_values, std::ref(window)));
124 }
125 
127 {
128 }
129 
130 } // namespace dialogs
virtual void set_value(unsigned selected, bool fire_event=false) override
Inherited from selectable_item.
This file contains the window object, this object is a top level container which has the event manage...
void set(const std::string &key, bool value)
Definition: general.cpp:161
const std::vector< std::string > items
A label displays a text, the text can be wrapped but no scrollbars are provided.
Definition: label.hpp:57
static std::string _(const char *str)
Definition: gettext.hpp:93
#define b
std::string get(const std::string &key)
Definition: general.cpp:209
void set_tooltip(const t_string &tooltip)
This file contains the settings handling of the widget library.
void set_visible(const visibility visible)
Definition: widget.cpp:476
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:172
bool available()
Returns whether we were compiled with support for desktop notifications.
std::string id
Text to match against addon_info.tags()
Definition: manager.cpp:215
std::size_t i
Definition: function.cpp:967
The user set the widget invisible, that means:
bool get_def_pref_sound(const std::string &id)
static void setup_item(const std::string &item, window &window)
A Preferences subdialog permitting to configure the sounds and notifications generated in response to...
Simple push button.
Definition: button.hpp:36
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
bool get_def_pref_lobby(const std::string &id)
static void set_pref_and_button(const std::string &id, bool value, window &window)
static void revert_to_default_pref_values(window &window)
base class of top level items, the only item which needs to store the final canvases to draw on...
Definition: window.hpp:65
Class for a toggle button.
static toggle_button * setup_pref_toggle_button(const std::string &id, bool def, window &window)
std::pair< std::string, unsigned > item
Definition: help_impl.hpp:410
virtual void set_active(const bool active) override
See styled_widget::set_active.
bool get_def_pref_notif(const std::string &id)