1 // Copyright (C) 2008, 2009 Ben Asselstine
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.
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.
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
21 #include <sigc++/functors/mem_fun.h>
23 #include "main-preferences-dialog.h"
25 #include "glade-helpers.h"
26 #include "image-helpers.h"
27 #include "ucompose.hpp"
29 #include "Configuration.h"
33 MainPreferencesDialog::MainPreferencesDialog()
35 Glib::RefPtr<Gtk::Builder> xml
36 = Gtk::Builder::create_from_file(get_glade_path()
37 + "/main-preferences-dialog.ui");
39 xml->get_widget("dialog", dialog);
41 window_closed.connect(sigc::mem_fun(dialog, &Gtk::Dialog::hide));
43 xml->get_widget("show_turn_popup_checkbutton", show_turn_popup_checkbutton);
44 xml->get_widget("commentator_checkbutton", commentator_checkbutton);
45 xml->get_widget("show_decorated_windows_checkbutton", show_decorated_windows_checkbutton);
46 xml->get_widget("play_music_checkbutton", play_music_checkbutton);
47 xml->get_widget("music_volume_scale", music_volume_scale);
48 xml->get_widget("music_volume_hbox", music_volume_hbox);
49 show_turn_popup_checkbutton->signal_toggled().connect(
50 sigc::mem_fun(this, &MainPreferencesDialog::on_show_turn_popup_toggled));
51 commentator_checkbutton->signal_toggled().connect(
52 sigc::mem_fun(this, &MainPreferencesDialog::on_show_commentator_toggled));
53 show_decorated_windows_checkbutton->signal_toggled().connect(
54 sigc::mem_fun(this, &MainPreferencesDialog::on_show_decorated_windows_toggled));
55 play_music_checkbutton->signal_toggled().connect(
56 sigc::mem_fun(this, &MainPreferencesDialog::on_play_music_toggled));
57 music_volume_scale->signal_value_changed().connect(
58 sigc::mem_fun(this, &MainPreferencesDialog::on_music_volume_changed));
60 show_turn_popup_checkbutton->set_active(Configuration::s_showNextPlayer);
61 commentator_checkbutton->set_active(Configuration::s_displayCommentator);
62 show_decorated_windows_checkbutton->set_active(!Configuration::s_decorated);
63 play_music_checkbutton->set_active(Configuration::s_musicenable);
64 music_volume_hbox->set_sensitive(Configuration::s_musicenable);
65 music_volume_scale->set_value(Configuration::s_musicvolume * 100.0 / 128);
69 MainPreferencesDialog::~MainPreferencesDialog()
73 void MainPreferencesDialog::set_parent_window(Gtk::Window &parent)
75 dialog->set_transient_for(parent);
76 //dialog->set_position(Gtk::WIN_POS_CENTER_ON_PARENT);
79 void MainPreferencesDialog::hide()
84 void MainPreferencesDialog::run()
89 Configuration::saveConfigurationFile(Configuration::configuration_file_path);
93 void MainPreferencesDialog::on_show_turn_popup_toggled()
95 Configuration::s_showNextPlayer = show_turn_popup_checkbutton->get_active();
98 void MainPreferencesDialog::on_show_decorated_windows_toggled()
100 Configuration::s_decorated = !show_decorated_windows_checkbutton->get_active();
103 void MainPreferencesDialog::on_play_music_toggled()
105 bool play_music = play_music_checkbutton->get_active();
107 Configuration::s_musicenable = play_music;
111 Sound::getInstance()->enableBackground();
115 Sound::getInstance()->haltMusic();
116 Sound::getInstance()->disableBackground();
118 music_volume_hbox->set_sensitive(Configuration::s_musicenable);
121 void MainPreferencesDialog::on_music_volume_changed()
123 int volume = int(music_volume_scale->get_value() / 100 * 128);
126 Mix_VolumeMusic(volume);
129 Configuration::s_musicvolume = volume;
132 void MainPreferencesDialog::on_show_commentator_toggled()
134 Configuration::s_displayCommentator = commentator_checkbutton->get_active();