The Battle for Wesnoth  1.19.0-dev
mp_alerts_options.cpp
Go to the documentation of this file.
1 /*
2  Copyright (C) 2014 - 2024
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/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 <functional>
31 
32 #include "gettext.hpp"
33 
34 namespace gui2::dialogs
35 {
36 
37 static toggle_button * setup_pref_toggle_button(const std::string & id, bool def, window & window)
38 {
39  toggle_button * b = find_widget<toggle_button>(&window, id, false, true);
40  b->set_value(preferences::get(id, def));
41 
42  //ensure we have yes / no for the toggle button, so that the preference matches the toggle button for sure.
43  if (preferences::get(id).empty()) {
44  preferences::set(id, def);
45  }
46 
47  connect_signal_mouse_left_click(*b, std::bind([b, id]() { preferences::set(id, b->get_value_bool()); }));
48 
49  return b;
50 }
51 
52 static void setup_item(const std::string & item, window & window)
53 {
54  // Set up the sound checkbox
56 
57  // Set up the notification checkbox
59 
60  // Check if desktop notifications are available
62  notif->set_value(false);
63  notif->set_active(false);
64  preferences::set(item+"_notif", false);
65  } else {
66  notif->set_active(true);
67  }
68 
69  // Set up the in_lobby checkbox
71 }
72 
73 static void set_pref_and_button(const std::string & id, bool value, window & window)
74 {
75  preferences::set(id,value);
76  toggle_button * button = find_widget<toggle_button>(&window, id, false, true);
77  button->set_value(value);
78 }
79 
81 {
82  for (const std::string & i : mp::ui_alerts::items) {
86  }
87 }
88 
90 
92  : modal_dialog(window_id())
93 {
94 }
95 
97 {
98  for (const std::string & i : mp::ui_alerts::items) {
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
Simple push button.
Definition: button.hpp:36
Abstract base class for all modal dialogs.
virtual void post_show(window &window) override
Actions to be taken after the window has been shown.
virtual void pre_show(window &window) override
Actions to be taken before showing the window.
void set_tooltip(const t_string &tooltip)
virtual void set_value(unsigned selected, bool fire_event=false) override
Inherited from selectable_item.
virtual void set_active(const bool active) override
See styled_widget::set_active.
void set_visible(const visibility visible)
Definition: widget.cpp:469
@ invisible
The user set the widget invisible, that means:
base class of top level items, the only item which needs to store the final canvases to draw on.
Definition: window.hpp:61
std::size_t i
Definition: function.cpp:968
static std::string _(const char *str)
Definition: gettext.hpp:93
This file contains the window object, this object is a top level container which has the event manage...
bool available()
Returns whether we were compiled with support for desktop notifications.
static void set_pref_and_button(const std::string &id, bool value, window &window)
static void revert_to_default_pref_values(window &window)
REGISTER_DIALOG(editor_edit_unit)
static void setup_item(const std::string &item, window &window)
static toggle_button * setup_pref_toggle_button(const std::string &id, bool def, window &window)
void connect_signal_mouse_left_click(dispatcher &dispatcher, const signal &signal)
Connects a signal handler for a left mouse button click.
Definition: dispatcher.cpp:177
std::pair< std::string, unsigned > item
Definition: help_impl.hpp:412
const std::vector< std::string > items
bool get_def_pref_lobby(const std::string &id)
bool get_def_pref_sound(const std::string &id)
bool get_def_pref_notif(const std::string &id)
void set(const std::string &key, bool value)
Definition: general.cpp:165
std::string get(const std::string &key)
Definition: general.cpp:213
#define b