| 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_model.h" | 5 #include "chrome/browser/chromeos/login/language_switch_model.h" |
| 6 | 6 |
| 7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" | 8 #include "app/resource_bundle.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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 GtkRequisition box_size; | 74 GtkRequisition box_size; |
| 75 gtk_widget_size_request(menu_->GetNativeMenu(), &box_size); | 75 gtk_widget_size_request(menu_->GetNativeMenu(), &box_size); |
| 76 return box_size.width; | 76 return box_size.width; |
| 77 } | 77 } |
| 78 | 78 |
| 79 void LanguageSwitchModel::SetFirstLevelMenuWidth(int width) { | 79 void LanguageSwitchModel::SetFirstLevelMenuWidth(int width) { |
| 80 DCHECK(menu_ != NULL); | 80 DCHECK(menu_ != NULL); |
| 81 gtk_widget_set_size_request(menu_->GetNativeMenu(), width, -1); | 81 gtk_widget_set_size_request(menu_->GetNativeMenu(), width, -1); |
| 82 } | 82 } |
| 83 | 83 |
| 84 // static |
| 85 void LanguageSwitchModel::SwitchLanguage(const std::string& locale) { |
| 86 // Save new locale. |
| 87 DCHECK(g_browser_process); |
| 88 PrefService* prefs = g_browser_process->local_state(); |
| 89 prefs->SetString(prefs::kApplicationLocale, UTF8ToWide(locale)); |
| 90 prefs->SavePersistentPrefs(); |
| 91 |
| 92 // Switch the locale. |
| 93 ResourceBundle::ReloadSharedInstance(UTF8ToWide(locale)); |
| 94 |
| 95 // The following line does not seem to affect locale anyhow. Maybe in future.. |
| 96 g_browser_process->SetApplicationLocale(locale); |
| 97 } |
| 98 |
| 84 //////////////////////////////////////////////////////////////////////////////// | 99 //////////////////////////////////////////////////////////////////////////////// |
| 85 // views::ViewMenuDelegate implementation. | 100 // views::ViewMenuDelegate implementation. |
| 86 | 101 |
| 87 void LanguageSwitchModel::RunMenu(views::View* source, const gfx::Point& pt) { | 102 void LanguageSwitchModel::RunMenu(views::View* source, const gfx::Point& pt) { |
| 88 DCHECK(menu_ != NULL); | 103 DCHECK(menu_ != NULL); |
| 89 gfx::Point point(pt); | 104 gfx::Point point(pt); |
| 90 point.Offset(delta_x_, delta_y_); | 105 point.Offset(delta_x_, delta_y_); |
| 91 menu_->RunMenuAt(point, views::Menu2::ALIGN_TOPRIGHT); | 106 menu_->RunMenuAt(point, views::Menu2::ALIGN_TOPRIGHT); |
| 92 } | 107 } |
| 93 | 108 |
| (...skipping 15 matching lines...) Expand all Loading... |
| 109 | 124 |
| 110 void LanguageSwitchModel::ExecuteCommand(int command_id) { | 125 void LanguageSwitchModel::ExecuteCommand(int command_id) { |
| 111 const std::string locale = language_list_->GetLocaleFromIndex(command_id); | 126 const std::string locale = language_list_->GetLocaleFromIndex(command_id); |
| 112 SwitchLanguage(locale); | 127 SwitchLanguage(locale); |
| 113 InitLanguageMenu(); | 128 InitLanguageMenu(); |
| 114 | 129 |
| 115 // Update all view hierarchies that the locale has changed. | 130 // Update all view hierarchies that the locale has changed. |
| 116 views::Widget::NotifyLocaleChanged(); | 131 views::Widget::NotifyLocaleChanged(); |
| 117 } | 132 } |
| 118 | 133 |
| 119 //////////////////////////////////////////////////////////////////////////////// | |
| 120 // Private implementation. | |
| 121 | |
| 122 // static | |
| 123 void LanguageSwitchModel::SwitchLanguage(const std::string& locale) { | |
| 124 // Save new locale. | |
| 125 DCHECK(g_browser_process); | |
| 126 PrefService* prefs = g_browser_process->local_state(); | |
| 127 prefs->SetString(prefs::kApplicationLocale, UTF8ToWide(locale)); | |
| 128 prefs->SavePersistentPrefs(); | |
| 129 | |
| 130 // Switch the locale. | |
| 131 ResourceBundle::ReloadSharedInstance(UTF8ToWide(locale)); | |
| 132 | |
| 133 // The following line does not seem to affect locale anyhow. Maybe in future.. | |
| 134 g_browser_process->SetApplicationLocale(locale); | |
| 135 } | |
| 136 | |
| 137 } // namespace chromeos | 134 } // namespace chromeos |
| OLD | NEW |