The Battle for Wesnoth  1.13.4+dev
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
mp_alerts_options.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2016 by Chris Beck <[email protected]>
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.hpp"
30 #include "formula/string_utils.hpp"
31 
32 #include "utils/functional.hpp"
33 
34 #include "gettext.hpp"
35 
36 namespace gui2
37 {
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 ttoggle_button * setup_pref_toggle_button(const std::string & id, bool def, twindow & window)
66 {
67  ttoggle_button * b = &find_widget<ttoggle_button>(&window, id, false);
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).size() == 0) {
72  preferences::set(id, def);
73  }
74 
75  //Needed to disambiguate overloaded function
76  void (*set) (const std::string &, bool) = &preferences::set;
77 
78  connect_signal_mouse_left_click(*b, std::bind(set, id, std::bind(&ttoggle_button::get_value_bool, b)));
79 
80  return b;
81 }
82 
83 static void setup_item(const std::string & item, twindow & window)
84 {
85  // Set up the sound checkbox
86  setup_pref_toggle_button(item+"_sound", mp_ui_alerts::get_def_pref_sound(item), window);
87 
88  // Set up the notification checkbox
89  ttoggle_button * notif = setup_pref_toggle_button(item+"_notif", mp_ui_alerts::get_def_pref_notif(item), window);
90 
91  // Check if desktop notifications are available
93  notif->set_value(false);
94  notif->set_active(false);
95  preferences::set(item+"_notif", false);
96  } else {
97  notif->set_active(true);
98  }
99 
100  // Set up the in_lobby checkbox
101  setup_pref_toggle_button(item+"_lobby", mp_ui_alerts::get_def_pref_lobby(item), window);
102 }
103 
104 static void set_pref_and_button(const std::string & id, bool value, twindow & window)
105 {
106  preferences::set(id,value);
107  ttoggle_button * button = &find_widget<ttoggle_button>(&window, id, false);
108  button->set_value(value);
109 }
110 
112 {
113  for (const std::string & i : mp_ui_alerts::items) {
117  }
118 }
119 
120 REGISTER_DIALOG(mp_alerts_options)
121 
123 {
124 }
125 
127 {
128  for (const std::string & i : mp_ui_alerts::items) {
129  setup_item(i, window);
130  }
131 
133  tlabel * nlabel = &find_widget<tlabel>(&window, "notification_label", false);
134  nlabel->set_tooltip(_("This build of wesnoth does not include support for desktop notifications, contact your package manager"));
135  }
136 
137  ttoggle_button * in_lobby;
138  in_lobby = &find_widget<ttoggle_button>(&window,"ready_for_start_lobby", false);
140 
141  in_lobby = &find_widget<ttoggle_button>(&window,"game_has_begun_lobby", false);
143 
144  in_lobby = &find_widget<ttoggle_button>(&window,"turn_changed_sound", false); // If we get a sound for this then don't remove this button
146 
147  in_lobby = &find_widget<ttoggle_button>(&window,"turn_changed_lobby", false);
149 
150  tbutton * defaults;
151  defaults = &find_widget<tbutton>(&window,"revert_to_defaults", false);
153 }
154 
156 {
157 }
158 
159 } // end namespace gui2
virtual void set_active(const bool active) override
See tcontrol::set_active.
void post_show(twindow &window)
Inherited from tdialog.
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
Definition: glew.h:1806
void set(CURSOR_TYPE type)
Use the default parameter to reset cursors.
Definition: cursor.cpp:154
static void setup_item(const std::string &item, twindow &window)
This file contains the window object, this object is a top level container which has the event manage...
REGISTER_DIALOG(label_settings)
static void set_pref_and_button(const std::string &id, bool value, twindow &window)
void connect_signal_mouse_left_click(tdispatcher &dispatcher, const tsignal_function &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.hpp:710
void set(const std::string &key, bool value)
const std::vector< std::string > items
Label showing a text.
Definition: label.hpp:29
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.
A class inherited from ttext_box that displays its input as stars.
Definition: field-fwd.hpp:23
Simple push button.
Definition: button.hpp:32
GLdouble GLdouble GLdouble b
Definition: glew.h:6966
The user set the widget invisible, that means:
Definition: widget.hpp:103
static UNUSEDNOWARN std::string _(const char *str)
Definition: gettext.hpp:82
std::string get(const std::string &key)
This file contains the settings handling of the widget library.
bool get_value_bool() const
Definition: selectable.hpp:48
GLsizei const GLfloat * value
Definition: glew.h:1817
bool available()
Returns whether we were compiled with support for desktop notifications.
static size_t id
Ids for the timers.
Definition: timer.cpp:39
void set_tooltip(const t_string &tooltip)
Definition: control.hpp:265
size_t i
Definition: function.cpp:1057
static void revert_to_default_pref_values(twindow &window)
bool get_def_pref_sound(const std::string &id)
GLsizeiptr size
Definition: glew.h:1649
GLenum GLint ref
Definition: glew.h:1813
bool get_def_pref_lobby(const std::string &id)
void set_value(const unsigned selected)
Inherited from tselectable_.
static ttoggle_button * setup_pref_toggle_button(const std::string &id, bool def, twindow &window)
void set_visible(const tvisible::scoped_enum visible)
Definition: widget.cpp:445
GLsizei const GLcharARB ** string
Definition: glew.h:4503
void pre_show(twindow &window)
Inherited from tdialog.
bool get_def_pref_notif(const std::string &id)