The Battle for Wesnoth  1.15.0-dev
mp_alerts_options.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2018 by Chris Beck <render787@gmail.com>
3  Part of the Battle for Wesnoth Project http://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 
21 #include "gui/dialogs/message.hpp"
22 #include "gui/widgets/button.hpp"
23 #include "gui/widgets/label.hpp"
24 #include "gui/widgets/settings.hpp"
26 #include "gui/widgets/window.hpp"
27 
28 #include "mp_ui_alerts.hpp"
29 #include "preferences/general.hpp"
30 
31 #include "utils/functional.hpp"
32 
33 #include "gettext.hpp"
34 
35 namespace gui2
36 {
37 namespace dialogs
38 {
39 /*WIKI
40  * @page = GUIWindowDefinitionWML
41  * @order = 2_mp_alerts_options
42  *
43  * == Lobby sounds options ==
44  *
45  * A Preferences subdialog permitting to configure the sounds and notifications
46  * generated in response to various mp lobby / game events.
47  *
48  * @begin{table}{dialog_widgets}
49  *
50  * _label & & label & m &
51  * Item name. $
52  *
53  * _sound & & toggle_button & m &
54  * Toggles whether to play the item sound. $
55  *
56  * _notif & & toggle_button & m &
57  * Toggles whether to give a notification. $
58  *
59  * _lobby & & toggle_button & m &
60  * Toggles whether to take actions for this item when in the lobby. $
61  *
62  * @end{table}
63  */
64 
65 static toggle_button * setup_pref_toggle_button(const std::string & id, bool def, window & window)
66 {
67  toggle_button * b = find_widget<toggle_button>(&window, id, false, true);
68  b->set_value(preferences::get(id, def));
69 
70  //ensure we have yes / no for the toggle button, so that the preference matches the toggle button for sure.
71  if (preferences::get(id).empty()) {
72  preferences::set(id, def);
73  }
74 
75  connect_signal_mouse_left_click(*b, std::bind([b, id]() { preferences::set(id, b->get_value_bool()); }));
76 
77  return b;
78 }
79 
80 static void setup_item(const std::string & item, window & window)
81 {
82  // Set up the sound checkbox
83  setup_pref_toggle_button(item+"_sound", mp_ui_alerts::get_def_pref_sound(item), window);
84 
85  // Set up the notification checkbox
86  toggle_button * notif = setup_pref_toggle_button(item+"_notif", mp_ui_alerts::get_def_pref_notif(item), window);
87 
88  // Check if desktop notifications are available
90  notif->set_value(false);
91  notif->set_active(false);
92  preferences::set(item+"_notif", false);
93  } else {
94  notif->set_active(true);
95  }
96 
97  // Set up the in_lobby checkbox
98  setup_pref_toggle_button(item+"_lobby", mp_ui_alerts::get_def_pref_lobby(item), window);
99 }
100 
101 static void set_pref_and_button(const std::string & id, bool value, window & window)
102 {
103  preferences::set(id,value);
104  toggle_button * button = find_widget<toggle_button>(&window, id, false, true);
105  button->set_value(value);
106 }
107 
109 {
110  for (const std::string & i : mp_ui_alerts::items) {
114  }
115 }
116 
118 
120 {
121 }
122 
124 {
125  for (const std::string & i : mp_ui_alerts::items) {
126  setup_item(i, window);
127  }
128 
130  label * nlabel = find_widget<label>(&window, "notification_label", false, true);
131  nlabel->set_tooltip(_("This build of wesnoth does not include support for desktop notifications, contact your package manager"));
132  }
133 
134  toggle_button * in_lobby;
135  in_lobby = find_widget<toggle_button>(&window,"ready_for_start_lobby", false, true);
137 
138  in_lobby = find_widget<toggle_button>(&window,"game_has_begun_lobby", false, true);
140 
141  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
143 
144  in_lobby = find_widget<toggle_button>(&window,"turn_changed_lobby", false, true);
146 
147  button * defaults;
148  defaults = find_widget<button>(&window,"revert_to_defaults", false, true);
149  connect_signal_mouse_left_click(*defaults, std::bind(&revert_to_default_pref_values, std::ref(window)));
150 }
151 
153 {
154 }
155 
156 } // namespace dialogs
157 } // namespace gui2
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:182
const std::vector< std::string > items
Label showing a text.
Definition: label.hpp:32
Generic file dialog.
Definition: field-fwd.hpp:22
#define b
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:89
std::string get(const std::string &key)
Definition: general.cpp:230
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:445
virtual void post_show(window &window) override
Inherited from modal_dialog.
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:164
bool available()
Returns whether we were compiled with support for desktop notifications.
Various uncategorised dialogs.
std::size_t i
Definition: function.cpp:933
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)
Simple push button.
Definition: button.hpp:35
virtual void pre_show(window &window) override
Inherited from modal_dialog.
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:63
Class for a toggle button.
static toggle_button * setup_pref_toggle_button(const std::string &id, bool def, window &window)
virtual void set_active(const bool active) override
See styled_widget::set_active.
bool get_def_pref_notif(const std::string &id)