The Battle for Wesnoth  1.15.13+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"
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 <functional>
32 
33 #include "gettext.hpp"
34 
35 namespace gui2::dialogs
36 {
37 
38 static toggle_button * setup_pref_toggle_button(const std::string & id, bool def, window & window)
39 {
40  toggle_button * b = find_widget<toggle_button>(&window, id, false, true);
41  b->set_value(preferences::get(id, def));
42 
43  //ensure we have yes / no for the toggle button, so that the preference matches the toggle button for sure.
44  if (preferences::get(id).empty()) {
45  preferences::set(id, def);
46  }
47 
48  connect_signal_mouse_left_click(*b, std::bind([b, id]() { preferences::set(id, b->get_value_bool()); }));
49 
50  return b;
51 }
52 
53 static void setup_item(const std::string & item, window & window)
54 {
55  // Set up the sound checkbox
56  setup_pref_toggle_button(item+"_sound", mp_ui_alerts::get_def_pref_sound(item), window);
57 
58  // Set up the notification checkbox
59  toggle_button * notif = setup_pref_toggle_button(item+"_notif", mp_ui_alerts::get_def_pref_notif(item), window);
60 
61  // Check if desktop notifications are available
63  notif->set_value(false);
64  notif->set_active(false);
65  preferences::set(item+"_notif", false);
66  } else {
67  notif->set_active(true);
68  }
69 
70  // Set up the in_lobby checkbox
71  setup_pref_toggle_button(item+"_lobby", mp_ui_alerts::get_def_pref_lobby(item), window);
72 }
73 
74 static void set_pref_and_button(const std::string & id, bool value, window & window)
75 {
76  preferences::set(id,value);
77  toggle_button * button = find_widget<toggle_button>(&window, id, false, true);
78  button->set_value(value);
79 }
80 
82 {
83  for (const std::string & i : mp_ui_alerts::items) {
87  }
88 }
89 
91 
93 {
94 }
95 
97 {
98  for (const std::string & i : mp_ui_alerts::items) {
99  setup_item(i, window);
100  }
101 
103  label * nlabel = find_widget<label>(&window, "notification_label", false, true);
104  nlabel->set_tooltip(_("This build of wesnoth does not include support for desktop notifications, contact your package manager"));
105  }
106 
107  toggle_button * in_lobby;
108  in_lobby = find_widget<toggle_button>(&window,"ready_for_start_lobby", false, true);
110 
111  in_lobby = find_widget<toggle_button>(&window,"game_has_begun_lobby", false, true);
113 
114  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
116 
117  in_lobby = find_widget<toggle_button>(&window,"turn_changed_lobby", false, true);
119 
120  button * defaults;
121  defaults = find_widget<button>(&window,"revert_to_defaults", false, true);
122  connect_signal_mouse_left_click(*defaults, std::bind(&revert_to_default_pref_values, std::ref(window)));
123 }
124 
126 {
127 }
128 
129 } // 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:178
const std::vector< std::string > items
A label displays a text, the text can be wrapped but no scrollbars are provided.
Definition: label.hpp:56
static std::string _(const char *str)
Definition: gettext.hpp:92
#define b
std::string get(const std::string &key)
Definition: general.cpp:226
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:475
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:171
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:214
std::size_t i
Definition: function.cpp:940
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:35
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:64
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:409
virtual void set_active(const bool active) override
See styled_widget::set_active.
bool get_def_pref_notif(const std::string &id)