spek-preferences-dialog.cc (3526B)
1 #include "spek-platform.h" 2 #include "spek-preferences.h" 3 4 #include "spek-preferences-dialog.h" 5 6 // List all languages with a decent (e.g. 80%) number of translated 7 // strings. Don't translate language names. Keep the first line intact. 8 static const char *available_languages[] = 9 { 10 "", "", 11 "ca", "Català", 12 "cs", "Čeština", 13 "da", "Dansk", 14 "de", "Deutsch", 15 "el", "Ελληνικά", 16 "en", "English", 17 "eo", "Esperanto", 18 "es", "Español", 19 "fi", "Suomi", 20 "fr", "Français", 21 "gl", "Galego", 22 "it", "Italiano", 23 "ja", "日本語", 24 "lv", "Latviešu", 25 "nb", "Norsk (bokmål)", 26 "nl", "Nederlands", 27 "pl", "Polski", 28 "pt_BR", "Português brasileiro", 29 "ru", "Русский", 30 "sk", "Slovenčina", 31 "sr@latin", "Srpski", 32 "sv", "Svenska", 33 "tr", "Türkçe", 34 "uk", "Українська", 35 "vi", "Tiếng Việt", 36 "zh_CN", "中文(简体)", 37 "zh_TW", "中文(台灣)", 38 NULL 39 }; 40 41 #define ID_LANGUAGE (wxID_HIGHEST + 1) 42 #define ID_CHECK (wxID_HIGHEST + 2) 43 44 BEGIN_EVENT_TABLE(SpekPreferencesDialog, wxDialog) 45 EVT_CHOICE(ID_LANGUAGE, SpekPreferencesDialog::on_language) 46 EVT_CHECKBOX(ID_CHECK, SpekPreferencesDialog::on_check) 47 END_EVENT_TABLE() 48 49 SpekPreferencesDialog::SpekPreferencesDialog(wxWindow *parent) : 50 wxDialog(parent, -1, _("Preferences")) 51 { 52 for (int i = 0; available_languages[i]; ++i) { 53 this->languages.Add(wxString::FromUTF8(available_languages[i])); 54 } 55 this->languages[1] = _("(system default)"); 56 57 wxSizer *sizer = new wxBoxSizer(wxVERTICAL); 58 wxSizer *inner_sizer = new wxBoxSizer(wxVERTICAL); 59 sizer->Add(inner_sizer, 1, wxALL, 12); 60 61 // TRANSLATORS: The name of a section in the Preferences dialog. 62 wxStaticText *general_label = new wxStaticText(this, -1, _("General")); 63 wxFont font = general_label->GetFont(); 64 font.SetWeight(wxFONTWEIGHT_BOLD); 65 general_label->SetFont(font); 66 inner_sizer->Add(general_label); 67 68 if (spek_platform_can_change_language()) { 69 wxSizer *language_sizer = new wxBoxSizer(wxHORIZONTAL); 70 inner_sizer->Add(language_sizer, 0, wxLEFT | wxTOP, 12); 71 wxStaticText *language_label = new wxStaticText(this, -1, _("Language:")); 72 language_sizer->Add(language_label, 0, wxALIGN_CENTER_VERTICAL); 73 74 wxChoice *language_choice = new wxChoice(this, ID_LANGUAGE); 75 language_sizer->Add(language_choice, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 12); 76 int active_index = 0; 77 wxString active_language = SpekPreferences::get().get_language(); 78 for (unsigned int i = 0; i < this->languages.GetCount(); i += 2) { 79 language_choice->Append(this->languages[i + 1]); 80 if (this->languages[i] == active_language) { 81 active_index = i / 2; 82 } 83 } 84 language_choice->SetSelection(active_index); 85 } 86 87 wxCheckBox *check_update = new wxCheckBox(this, ID_CHECK, _("Check for &updates")); 88 inner_sizer->Add(check_update, 0 ,wxLEFT | wxTOP, 12); 89 check_update->SetValue(SpekPreferences::get().get_check_update()); 90 91 sizer->Add(CreateButtonSizer(wxOK), 0, wxALIGN_RIGHT | wxBOTTOM | wxRIGHT, 12); 92 sizer->SetSizeHints(this); 93 SetSizer(sizer); 94 } 95 96 void SpekPreferencesDialog::on_language(wxCommandEvent& event) 97 { 98 SpekPreferences::get().set_language(this->languages[event.GetSelection() * 2]); 99 } 100 101 void SpekPreferencesDialog::on_check(wxCommandEvent& event) 102 { 103 SpekPreferences::get().set_check_update(event.IsChecked()); 104 }