OLD | NEW |
---|---|
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/login/language_switch_menu.h" | 5 #include "chrome/browser/chromeos/login/language_switch_menu.h" |
6 | 6 |
7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
60 line, WideToUTF16(language_list_->GetLanguageNameAt(line))); | 60 line, WideToUTF16(language_list_->GetLanguageNameAt(line))); |
61 } | 61 } |
62 | 62 |
63 // Initialize menu here so it appears fast when called. | 63 // Initialize menu here so it appears fast when called. |
64 menu_.reset(new views::Menu2(&menu_model_)); | 64 menu_.reset(new views::Menu2(&menu_model_)); |
65 } | 65 } |
66 | 66 |
67 std::wstring LanguageSwitchMenu::GetCurrentLocaleName() const { | 67 std::wstring LanguageSwitchMenu::GetCurrentLocaleName() const { |
68 DCHECK(g_browser_process); | 68 DCHECK(g_browser_process); |
69 const std::string locale = g_browser_process->GetApplicationLocale(); | 69 const std::string locale = g_browser_process->GetApplicationLocale(); |
70 return language_list_->GetLanguageNameAt( | 70 int index = language_list_->GetIndexFromLocale(locale); |
71 language_list_->GetIndexFromLocale(locale)); | 71 CHECK_NE(index, -1) << "Unknown locale: " << locale; |
Peter Kasting
2010/12/21 18:35:58
Nit: (expected, actual)
glotov
2010/12/21 20:33:34
Done.
| |
72 return language_list_->GetLanguageNameAt(index); | |
72 }; | 73 }; |
73 | 74 |
74 void LanguageSwitchMenu::SetFirstLevelMenuWidth(int width) { | 75 void LanguageSwitchMenu::SetFirstLevelMenuWidth(int width) { |
75 DCHECK(menu_ != NULL); | 76 DCHECK(menu_ != NULL); |
76 menu_->SetMinimumWidth(width); | 77 menu_->SetMinimumWidth(width); |
77 } | 78 } |
78 | 79 |
79 // static | 80 // static |
80 void LanguageSwitchMenu::SwitchLanguage(const std::string& locale) { | 81 void LanguageSwitchMenu::SwitchLanguage(const std::string& locale) { |
81 DCHECK(g_browser_process); | 82 DCHECK(g_browser_process); |
82 if (g_browser_process->GetApplicationLocale() == locale) { | 83 if (g_browser_process->GetApplicationLocale() == locale) { |
83 return; | 84 return; |
84 } | 85 } |
85 // Save new locale. | 86 // Save new locale. |
86 PrefService* prefs = g_browser_process->local_state(); | 87 PrefService* prefs = g_browser_process->local_state(); |
87 // TODO(markusheintz): If the preference is managed and can not be changed by | 88 // TODO(markusheintz): If the preference is managed and can not be changed by |
88 // the user, changing the language should be disabled in the UI. | 89 // the user, changing the language should be disabled in the UI. |
89 // TODO(markusheintz): Change the if condition to prefs->IsUserModifiable() | 90 // TODO(markusheintz): Change the if condition to prefs->IsUserModifiable() |
90 // once Mattias landed his pending patch. | 91 // once Mattias landed his pending patch. |
91 if (!prefs->IsManagedPreference(prefs::kApplicationLocale)) { | 92 if (!prefs->IsManagedPreference(prefs::kApplicationLocale)) { |
92 prefs->SetString(prefs::kApplicationLocale, locale); | 93 prefs->SetString(prefs::kApplicationLocale, locale); |
93 prefs->SavePersistentPrefs(); | 94 prefs->SavePersistentPrefs(); |
94 | 95 |
95 // Switch the locale. | 96 // Switch the locale. |
96 ResourceBundle::ReloadSharedInstance(locale); | 97 const std::string res = ResourceBundle::ReloadSharedInstance(locale); |
Peter Kasting
2010/12/21 18:35:58
Nit: Same nits
glotov
2010/12/21 20:33:34
Done.
| |
98 CHECK(!res.empty()) << "Locale could not be found for " << locale; | |
97 | 99 |
98 // Enable the keyboard layouts that are necessary for the new locale. | 100 // Enable the keyboard layouts that are necessary for the new locale. |
99 input_method::EnableInputMethods( | 101 input_method::EnableInputMethods( |
100 locale, input_method::kKeyboardLayoutsOnly, | 102 locale, input_method::kKeyboardLayoutsOnly, |
101 CrosLibrary::Get()->GetKeyboardLibrary()-> | 103 CrosLibrary::Get()->GetKeyboardLibrary()-> |
102 GetHardwareKeyboardLayoutName()); | 104 GetHardwareKeyboardLayoutName()); |
103 | 105 |
104 // The following line does not seem to affect locale anyhow. Maybe in | 106 // The following line does not seem to affect locale anyhow. Maybe in |
105 // future.. | 107 // future.. |
106 g_browser_process->SetApplicationLocale(locale); | 108 g_browser_process->SetApplicationLocale(locale); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
145 void LanguageSwitchMenu::ExecuteCommand(int command_id) { | 147 void LanguageSwitchMenu::ExecuteCommand(int command_id) { |
146 const std::string locale = language_list_->GetLocaleFromIndex(command_id); | 148 const std::string locale = language_list_->GetLocaleFromIndex(command_id); |
147 SwitchLanguage(locale); | 149 SwitchLanguage(locale); |
148 InitLanguageMenu(); | 150 InitLanguageMenu(); |
149 | 151 |
150 // Update all view hierarchies that the locale has changed. | 152 // Update all view hierarchies that the locale has changed. |
151 views::Widget::NotifyLocaleChanged(); | 153 views::Widget::NotifyLocaleChanged(); |
152 } | 154 } |
153 | 155 |
154 } // namespace chromeos | 156 } // namespace chromeos |
OLD | NEW |