spek

Acoustic spectrum analyser
git clone http://git.hanabi.in/repos/spek.git
Log | Files | Refs | README

commit dc7ce9a4c27b572cd90fea71401fbf42330be463
parent 1ff2597fdbe183cc32aeeed2718e0598c9fe3d55
Author: Alexander Kojevnikov <alexander@kojevnikov.com>
Date:   Sun, 26 Aug 2012 18:39:41 -0700

Preferences dialogue

Diffstat:
Msrc/Makefile.am | 2++
Asrc/spek-preferences-dialog.cc | 113+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Asrc/spek-preferences-dialog.hh | 38++++++++++++++++++++++++++++++++++++++
Dsrc/spek-preferences-dialog.vala | 110-------------------------------------------------------------------------------
Msrc/spek-window.cc | 3+++
Dsrc/spek-window.vala | 31-------------------------------
6 files changed, 156 insertions(+), 141 deletions(-)

diff --git a/src/Makefile.am b/src/Makefile.am @@ -15,6 +15,8 @@ spek_SOURCES = \ spek-pipeline.h \ spek-platform.cc \ spek-platform.hh \ + spek-preferences-dialog.cc \ + spek-preferences-dialog.hh \ spek-preferences.cc \ spek-preferences.hh \ spek-ruler.cc \ diff --git a/src/spek-preferences-dialog.cc b/src/spek-preferences-dialog.cc @@ -0,0 +1,113 @@ +/* spek-preferences-dialog.cc + * + * Copyright (C) 2011-2012 Alexander Kojevnikov <alexander@kojevnikov.com> + * + * Spek is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Spek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Spek. If not, see <http://www.gnu.org/licenses/>. + */ + +#include "spek-preferences.hh" + +#include "spek-preferences-dialog.hh" + +// List all languages with a decent (e.g. 80%) number of translated +// strings. Don't translate language names. Keep the first line intact. +static const char *available_languages[] = +{ + "", "", + "cs", "Čeština", + "de", "Deutsch", + "en", "English", + "eo", "Esperanto", + "es", "Español", + "fr", "Français", + "it", "Italiano", + "ja", "日本語", + "nl", "Nederlands", + "pl", "Polski", + "pt_BR", "Português brasileiro", + "ru", "Русский", + "sv", "Svenska", + "uk", "Українська", + "zh_CN", "中文(简体)", + "zh_TW", "中文(台灣)", + NULL +}; + +#ifndef wxCLOSE +// wxWidgets 2.8 doesn't have wxCLOSE, replace with wxOK for now. +#define wxCLOSE wxOK +#endif + +#define ID_LANGUAGE (wxID_HIGHEST + 1) +#define ID_CHECK (wxID_HIGHEST + 2) + +BEGIN_EVENT_TABLE(SpekPreferencesDialog, wxDialog) + EVT_CHOICE(ID_LANGUAGE, SpekPreferencesDialog::on_language) + EVT_CHECKBOX(ID_CHECK, SpekPreferencesDialog::on_check) +END_EVENT_TABLE() + +SpekPreferencesDialog::SpekPreferencesDialog(wxWindow *parent) : + wxDialog(parent, -1, _("Preferences")) +{ + for (int i = 0; available_languages[i]; ++i) { + this->languages.Add(wxString::FromUTF8(available_languages[i])); + } + this->languages[1] = _("(system default)"); + + wxSizer *sizer = new wxBoxSizer(wxVERTICAL); + wxSizer *inner_sizer = new wxBoxSizer(wxVERTICAL); + sizer->Add(inner_sizer, 1, wxALL, 12); + + // TRANSLATORS: The name of a section in the Preferences dialog. + wxStaticText *general_label = new wxStaticText(this, -1, _("General")); + wxFont font = general_label->GetFont(); + font.SetWeight(wxFONTWEIGHT_BOLD); + general_label->SetFont(font); + inner_sizer->Add(general_label); + + wxSizer *language_sizer = new wxBoxSizer(wxHORIZONTAL); + inner_sizer->Add(language_sizer, 0, wxLEFT | wxTOP, 12); + wxStaticText *language_label = new wxStaticText(this, -1, _("Language:")); + language_sizer->Add(language_label, 0, wxALIGN_CENTER_VERTICAL); + + wxChoice *language_choice = new wxChoice(this, ID_LANGUAGE); + language_sizer->Add(language_choice, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 12); + int active_index = 0; + wxString active_language = SpekPreferences::get().get_language(); + for (int i = 0; i < this->languages.GetCount(); i += 2) { + language_choice->Append(this->languages[i + 1]); + if (this->languages[i] == active_language) { + active_index = i / 2; + } + } + language_choice->SetSelection(active_index); + + wxCheckBox *check_update = new wxCheckBox(this, ID_CHECK, _("Check for &updates")); + inner_sizer->Add(check_update, 0 ,wxLEFT | wxTOP, 12); + check_update->SetValue(SpekPreferences::get().get_check_update()); + + sizer->Add(CreateButtonSizer(wxCLOSE), 0, wxALIGN_RIGHT | wxBOTTOM | wxRIGHT, 12); + sizer->SetSizeHints(this); + SetSizer(sizer); +} + +void SpekPreferencesDialog::on_language(wxCommandEvent& event) +{ + SpekPreferences::get().set_language(this->languages[event.GetSelection() * 2]); +} + +void SpekPreferencesDialog::on_check(wxCommandEvent& event) +{ + SpekPreferences::get().set_check_update(event.IsChecked()); +} diff --git a/src/spek-preferences-dialog.hh b/src/spek-preferences-dialog.hh @@ -0,0 +1,38 @@ +/* spek-preferences-dialog.hh + * + * Copyright (C) 2011-2012 Alexander Kojevnikov <alexander@kojevnikov.com> + * + * Spek is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * Spek is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with Spek. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef SPEK_PREFERENCES_DIALOG_HH_ +#define SPEK_PREFERENCES_DIALOG_HH_ + +#include <wx/wx.h> + +class SpekPreferencesDialog : public wxDialog +{ +public: + SpekPreferencesDialog(wxWindow *parent); + +private: + void on_language(wxCommandEvent& event); + void on_check(wxCommandEvent& event); + + wxArrayString languages; + + DECLARE_EVENT_TABLE() +}; + +#endif diff --git a/src/spek-preferences-dialog.vala b/src/spek-preferences-dialog.vala @@ -1,109 +0,0 @@ -/* spek-preferences-dialog.vala - * - * Copyright (C) 2011 Alexander Kojevnikov <alexander@kojevnikov.com> - * - * Spek is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Spek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Spek. If not, see <http://www.gnu.org/licenses/>. - */ - -using Gtk; - -namespace Spek { - public class PreferencesDialog : Gtk.Dialog { - // List all languages with a decent (e.g. 80%) number of translated - // strings. Don't translate language names. Keep the first line intact. - private static string[,] languages = { - {"", null}, - {"cs", "Čeština"}, - {"de", "Deutsch"}, - {"en", "English"}, - {"eo", "Esperanto"}, - {"es", "Español"}, - {"fr", "Français"}, - {"it", "Italiano"}, - {"ja", "日本語"}, - {"nl", "Nederlands"}, - {"pl", "Polski"}, - {"pt_BR", "Português brasileiro"}, - {"ru", "Русский"}, - {"sv", "Svenska"}, - {"uk", "Українська"}, - {"zh_CN", "中文(简体)"}, - {"zh_TW", "中文(台灣)"} - }; - - public PreferencesDialog () { - title = _("Preferences"); - modal = true; - resizable = false; - window_position = WindowPosition.CENTER_ON_PARENT; - languages[0,1] = _("(system default)"); - - var alignment = new Alignment (0.5f, 0.5f, 1f, 1f); - alignment.set_padding (12, 12, 12, 12); - var box = new VBox (false, 0); - - var general_box = new VBox (false, 6); - // TRANSLATORS: The name of a section in the Preferences dialog. - var general_label = new Label (_("General")); - var attributes = new Pango.AttrList (); - attributes.insert (Pango.attr_weight_new (Pango.Weight.BOLD)); - general_label.attributes = attributes; - general_label.xalign = 0; - general_box.pack_start (general_label, false, false, 0); - var general_alignment = new Alignment (0.5f, 0.5f, 1f, 1f); - general_alignment.left_padding = 12; - var general_subbox = new VBox (false, 6); - var language_box = new HBox (false, 12); - var language_label = new Label.with_mnemonic (_("_Language:")); - language_box.pack_start (language_label, false, false, 0); - var language_combo = new ComboBox.text (); - int active_language = 0; - var prefs = Preferences.instance; - for (int i = 0; i < languages.length[0]; i++) { - language_combo.append_text (languages[i,1]); - if (languages[i,0] == prefs.language) { - active_language = i; - } - } - language_combo.active = active_language; - language_combo.changed.connect ( - () => prefs.language = languages[language_combo.active,0]); - language_label.mnemonic_widget = language_combo; - language_box.pack_start (language_combo, false, false, 0); - general_subbox.pack_start(language_box, false, false, 0); - var check_update = new CheckButton.with_mnemonic (_("Check for _updates")); - check_update.active = prefs.check_update; - check_update.toggled.connect ( - () => prefs.check_update = check_update.active); - general_subbox.pack_start (check_update, false, false, 0); - general_alignment.add (general_subbox); - general_box.pack_start (general_alignment, false, false, 0); - - box.pack_start (general_box, false, false, 0); - alignment.add (box); - var vbox = (VBox) get_content_area (); - vbox.pack_start (alignment, false, false, 0); - vbox.show_all (); - - add_button (Stock.CLOSE, ResponseType.CLOSE); - set_default_response (ResponseType.CLOSE); - response.connect (on_response); - } - - private void on_response (Dialog dialog, int response_id) { - Preferences.instance.save (); - destroy (); - } - } -} -\ No newline at end of file diff --git a/src/spek-window.cc b/src/spek-window.cc @@ -25,6 +25,7 @@ #include <wx/protocol/http.h> #include <wx/sstream.h> +#include "spek-preferences-dialog.hh" #include "spek-preferences.hh" #include "spek-spectrogram.hh" @@ -282,6 +283,8 @@ void SpekWindow::on_exit(wxCommandEvent& event) void SpekWindow::on_preferences(wxCommandEvent& event) { + SpekPreferencesDialog dlg(this); + dlg.ShowModal(); } void SpekWindow::on_about(wxCommandEvent& event) diff --git a/src/spek-window.vala b/src/spek-window.vala @@ -1,31 +0,0 @@ -/* spek-window.vala - * - * Copyright (C) 2010-2011 Alexander Kojevnikov <alexander@kojevnikov.com> - * - * Spek is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Spek is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Spek. If not, see <http://www.gnu.org/licenses/>. - */ - -using Gdk; -using Gtk; - -namespace Spek { - public class Window : Gtk.Window { - - private void on_edit_preferences () { - var dlg = new PreferencesDialog (); - dlg.transient_for = this; - dlg.run (); - } - } -}