| 1 | /*************************************************************************** |
| 2 | * Copyright (C) 2006-2008 by Guy Rutenberg * |
| 3 | * [email protected] * |
| 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 | * * |
| 10 | * This program is distributed in the hope that it will be useful, * |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 13 | * GNU General Public License for more details. * |
| 14 | * * |
| 15 | * You should have received a copy of the GNU General Public License * |
| 16 | * along with this program; if not, write to the * |
| 17 | * Free Software Foundation, Inc., * |
| 18 | * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * |
| 19 | ***************************************************************************/ |
| 20 | |
| 21 | #include "settings_dialog.h" |
| 22 | #include "icon32.xpm" |
| 23 | |
| 24 | using namespace settings_dialog; |
| 25 | |
| 26 | SettingsDialog::SettingsDialog(wxWindow* parent, configuration::Configuration* config): |
| 27 | wxDialog(parent, wxID_ANY, wxT("Settings Dialog"), wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE) |
| 28 | { |
| 29 | |
| 30 | SetIcon(wxIcon(icon32_xpm)); |
| 31 | |
| 32 | m_config = config; |
| 33 | |
| 34 | connectEventTable(); |
| 35 | createControls(); |
| 36 | loadSettings(); |
| 37 | doLayout(); |
| 38 | } |
| 39 | |
| 40 | void SettingsDialog::createControls() |
| 41 | { |
| 42 | // note that child windows are automatically deleted by wxWidgets, so |
| 43 | // need to delete them manually |
| 44 | animate_checkbox = new wxCheckBox(this, wxID_ANY, wxT("Dice animation")); |
| 45 | subtotal_checkbox = new wxCheckBox(this, wxID_ANY, wxT("Calculate sub-total score for the upper and lower sections")); |
| 46 | score_hints_checkbox = new wxCheckBox(this, wxID_ANY, wxT("Display score hints.")); |
| 47 | horizontal_checkbox = new wxCheckBox(this, wxID_ANY, wxT("Enable horizontal layout for user interface.")); |
| 48 | } |
| 49 | |
| 50 | |
| 51 | void SettingsDialog::connectEventTable() |
| 52 | { |
| 53 | Connect(wxID_OK, wxEVT_COMMAND_BUTTON_CLICKED, wxCommandEventHandler(SettingsDialog::onOK)); |
| 54 | } |
| 55 | |
| 56 | void SettingsDialog::doLayout() |
| 57 | { |
| 58 | wxBoxSizer* top_sizer = new wxBoxSizer(wxVERTICAL); |
| 59 | wxStaticBoxSizer* settings_sizer = new wxStaticBoxSizer( new wxStaticBox( this, wxID_ANY, wxT("General Settings") ), wxVERTICAL); |
| 60 | |
| 61 | settings_sizer->Add(animate_checkbox,0,wxALL,5); |
| 62 | settings_sizer->Add(subtotal_checkbox,0,wxALL,5); |
| 63 | settings_sizer->Add(score_hints_checkbox,0,wxALL,5); |
| 64 | settings_sizer->Add(horizontal_checkbox,0,wxALL,5); |
| 65 | |
| 66 | top_sizer->Add(settings_sizer,0,wxALL,5); |
| 67 | |
| 68 | top_sizer->Add(CreateButtonSizer(wxOK|wxCANCEL), 1, wxBOTTOM, 10); |
| 69 | |
| 70 | SetAutoLayout(true); |
| 71 | SetSizer(top_sizer); |
| 72 | |
| 73 | top_sizer->Fit(this); |
| 74 | top_sizer->SetSizeHints(this); |
| 75 | |
| 76 | Layout(); |
| 77 | } |
| 78 | |
| 79 | void SettingsDialog::loadSettings() |
| 80 | { |
| 81 | animate_checkbox->SetValue(m_config->get("dice-animation")=="True"); |
| 82 | subtotal_checkbox->SetValue(m_config->get("calculate-subtotal")=="True"); |
| 83 | score_hints_checkbox->SetValue(m_config->get("score-hints")=="True"); |
| 84 | horizontal_checkbox->SetValue(m_config->get("horizontal-layout")=="True"); |
| 85 | |
| 86 | } |
| 87 | void SettingsDialog::onOK(wxCommandEvent& event) |
| 88 | { |
| 89 | m_config->set("dice-animation",animate_checkbox->GetValue()?"True":"False"); |
| 90 | m_config->set("calculate-subtotal",subtotal_checkbox->GetValue()?"True":"False"); |
| 91 | m_config->set("score-hints",score_hints_checkbox->GetValue()?"True":"False"); |
| 92 | m_config->set("horizontal-layout",horizontal_checkbox->GetValue()?"True":"False"); |
| 93 | |
| 94 | m_config->save(); |
| 95 | |
| 96 | event.Skip(); |
| 97 | } |