1 // Copyright (C) 2008, 2009, 2014, 2017, 2020 Ben Asselstine
2 //
3 // This program is free software; you can redistribute it and/or modify
4 // it under the terms of the GNU General Public License as published by
5 // the Free Software Foundation; either version 3 of the License, or
6 // (at your option) any later version.
7 //
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU Library General Public License for more details.
12 //
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
16 // 02110-1301, USA.
17
18 #include <config.h>
19
20 #include <gtkmm.h>
21 #include <sigc++/functors/mem_fun.h>
22
23 #include "main-preferences-dialog.h"
24
25 #include "Configuration.h"
26 #include "snd.h"
27
28 #define method(x) sigc::mem_fun(*this, &MainPreferencesDialog::x)
29
MainPreferencesDialog(Gtk::Window & parent)30 MainPreferencesDialog::MainPreferencesDialog(Gtk::Window &parent)
31 : LwDialog(parent, "main-preferences-dialog.ui")
32 {
33 xml->get_widget("commentator_switch", commentator_switch);
34 xml->get_widget("play_music_switch", play_music_switch);
35 xml->get_widget("music_volume_scale", music_volume_scale);
36 commentator_switch->property_active().signal_changed().connect
37 (method(on_show_commentator_toggled));
38 play_music_switch->property_active().signal_changed().connect (method(on_play_music_toggled));
39 music_volume_scale->signal_value_changed().connect
40 (method(on_music_volume_changed));
41
42 commentator_switch->set_active(Configuration::s_displayCommentator);
43 play_music_switch->set_active(Configuration::s_musicenable);
44 music_volume_scale->set_value(Configuration::s_musicvolume * 100.0 / 128);
45 music_volume_scale->set_sensitive(Configuration::s_musicenable);
46 }
47
run()48 void MainPreferencesDialog::run()
49 {
50 dialog->show();
51 dialog->run();
52
53 Configuration::saveConfigurationFile();
54 dialog->hide();
55 }
56
on_play_music_toggled()57 void MainPreferencesDialog::on_play_music_toggled()
58 {
59 Configuration::s_musicenable = play_music_switch->get_active();
60
61 if (play_music_switch->get_active())
62 Snd::getInstance()->play("intro", -1, false);
63 else
64 Snd::getInstance()->halt(false);
65 music_volume_scale->set_sensitive(Configuration::s_musicenable);
66 }
67
on_music_volume_changed()68 void MainPreferencesDialog::on_music_volume_changed()
69 {
70 int volume = int(music_volume_scale->get_value() / 100 * 128);
71
72 Configuration::s_musicvolume = volume;
73 Snd::getInstance()->updateVolume();
74 }
75
on_show_commentator_toggled()76 void MainPreferencesDialog::on_show_commentator_toggled()
77 {
78 Configuration::s_displayCommentator = commentator_switch->get_active();
79 }
80