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 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 
21 #include "gui/dialogs/message.hpp"
22 #include "gui/widgets/button.hpp"
23 #include "gui/widgets/label.hpp"
25 #include "gui/widgets/window.hpp"
26 
27 #include "mp_ui_alerts.hpp"
28 #include "preferences/general.hpp"
29 
30 #include "utils/functional.hpp"
31 
32 #include "gettext.hpp"
33 
34 namespace gui2
35 {
36 namespace dialogs
37 {
38 /*WIKI
39  * @page = GUIWindowDefinitionWML
40  * @order = 2_mp_alerts_options
41  *
42  * == Lobby sounds options ==
43  *
44  * A Preferences subdialog permitting to configure the sounds and notifications
45  * generated in response to various mp lobby / game events.
46  *
47  * @begin{table}{dialog_widgets}
48  *
49  * _label & & label & m &
50  * Item name. $
51  *
52  * _sound & & toggle_button & m &
53  * Toggles whether to play the item sound. $
54  *
55  * _notif & & toggle_button & m &
56  * Toggles whether to give a notification. $
57  *
58  * _lobby & & toggle_button & m &
59  * Toggles whether to take actions for this item when in the lobby. $
60  *
61  * @end{table}
62  */
63 
64 static toggle_button * setup_pref_toggle_button(const std::string & id, bool def, window & window)
65 {
66  toggle_button * b = find_widget<toggle_button>(&window, id, false, true);
67  b->set_value(preferences::get(id, def));
68 
69  //ensure we have yes / no for the toggle button, so that the preference matches the toggle button for sure.
70  if (preferences::get(id).empty()) {
71  preferences::set(id, def);
72  }
73 
74  connect_signal_mouse_left_click(*b, std::bind([b, id]() { preferences::set(id, b->get_value_bool()); }));
75 
76  return b;
77 }
78 
79 static void setup_item(const std::string & item, window & window)
80 {
81  // Set up the sound checkbox
82  setup_pref_toggle_button(item+"_sound", mp_ui_alerts::get_def_pref_sound(item), window);
83 
84  // Set up the notification checkbox
85  toggle_button * notif = setup_pref_toggle_button(item+"_notif", mp_ui_alerts::get_def_pref_notif(item), window);
86 
87  // Check if desktop notifications are available
89  notif->set_value(false);
90  notif->set_active(false);
91  preferences::set(item+"_notif", false);
92  } else {
93  notif->set_active(true);
94  }
95 
96  // Set up the in_lobby checkbox
97  setup_pref_toggle_button(item+"_lobby", mp_ui_alerts::get_def_pref_lobby(item), window);
98 }
99 
100 static void set_pref_and_button(const std::string & id, bool value, window & window)
101 {
102  preferences::set(id,value);
103  toggle_button * button = find_widget<toggle_button>(&window, id, false, true);
104  button->set_value(value);
105 }
106 
108 {
109  for (const std::string & i : mp_ui_alerts::items) {
113  }
114 }
115 
117 
119 {
120 }
121 
123 {
124  for (const std::string & i : mp_ui_alerts::items) {
125  setup_item(i, window);
126  }
127 
129  label * nlabel = find_widget<label>(&window, "notification_label", false, true);
130  nlabel->set_tooltip(_("This build of wesnoth does not include support for desktop notifications, contact your package manager"));
131  }
132 
133  toggle_button * in_lobby;
134  in_lobby = find_widget<toggle_button>(&window,"ready_for_start_lobby", false, true);
136 
137  in_lobby = find_widget<toggle_button>(&window,"game_has_begun_lobby", false, true);
139 
140  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
142 
143  in_lobby = find_widget<toggle_button>(&window,"turn_changed_lobby", false, true);
145 
146  button * defaults;
147  defaults = find_widget<button>(&window,"revert_to_defaults", false, true);
148  connect_signal_mouse_left_click(*defaults, std::bind(&revert_to_default_pref_values, std::ref(window)));
149 }
150 
152 {
153 }
154 
155 } // namespace dialogs
156 } // namespace gui2
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: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)
const t_string id
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:163
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:62
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)