blob: 6ee4aed2bdb0e2216f112c017d9d7bb6030504b0 [file] [log] [blame]
[email protected]2b2820a2011-03-07 22:28:401// Copyright (c) 2011 The Chromium Authors. All rights reserved.
[email protected]fecc1522009-10-15 21:08:292// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/chromeos/preferences.h"
6
[email protected]530cd622011-04-14 15:45:007#include "base/i18n/time_formatting.h"
[email protected]4e5ae20f2010-09-24 04:52:118#include "base/string_split.h"
[email protected]fecc1522009-10-15 21:08:299#include "base/string_util.h"
[email protected]50951432010-03-31 12:12:4210#include "base/utf_string_conversions.h"
[email protected]62c7ef32010-03-23 23:44:2411#include "chrome/browser/chromeos/cros/cros_library.h"
[email protected]291d8b72010-06-21 09:43:1412#include "chrome/browser/chromeos/cros/input_method_library.h"
[email protected]4ccc05e2010-10-06 19:32:1513#include "chrome/browser/chromeos/cros/power_library.h"
[email protected]b4e05f22010-09-08 17:27:4614#include "chrome/browser/chromeos/cros/touchpad_library.h"
[email protected]9199bd52010-07-01 05:04:4115#include "chrome/browser/chromeos/input_method/input_method_util.h"
[email protected]c010f632011-04-01 06:44:3916#include "chrome/browser/chromeos/input_method/xkeyboard.h"
[email protected]26012e22010-12-01 06:44:2717#include "chrome/browser/chromeos/login/login_utils.h"
[email protected]37858e52010-08-26 00:22:0218#include "chrome/browser/prefs/pref_member.h"
19#include "chrome/browser/prefs/pref_service.h"
[email protected]fecc1522009-10-15 21:08:2920#include "chrome/common/pref_names.h"
[email protected]2b2820a2011-03-07 22:28:4021#include "content/common/notification_details.h"
22#include "content/common/notification_source.h"
23#include "content/common/notification_type.h"
[email protected]fecc1522009-10-15 21:08:2924#include "unicode/timezone.h"
25
26namespace chromeos {
27
[email protected]9199bd52010-07-01 05:04:4128static const char kFallbackInputMethodLocale[] = "en-US";
[email protected]4793c942010-09-21 23:17:1729
[email protected]d743a5982010-11-08 17:54:0930Preferences::Preferences() {}
31
32Preferences::~Preferences() {}
[email protected]9199bd52010-07-01 05:04:4133
[email protected]fecc1522009-10-15 21:08:2934// static
35void Preferences::RegisterUserPrefs(PrefService* prefs) {
[email protected]8b80d0d2011-03-07 20:42:3836 prefs->RegisterBooleanPref(prefs::kTapToClickEnabled, false);
[email protected]6ba198f2010-07-02 20:32:0537 prefs->RegisterBooleanPref(prefs::kLabsMediaplayerEnabled, false);
38 prefs->RegisterBooleanPref(prefs::kLabsAdvancedFilesystemEnabled, false);
[email protected]27f20d52010-09-18 00:59:3139 // Check if the accessibility pref is already registered, which can happen
40 // in WizardController::RegisterPrefs. We still want to try to register
41 // the pref here in case of Chrome/Linux with ChromeOS=1.
42 if (prefs->FindPreference(prefs::kAccessibilityEnabled) == NULL) {
43 prefs->RegisterBooleanPref(prefs::kAccessibilityEnabled, false);
44 }
[email protected]b4e05f22010-09-08 17:27:4645 prefs->RegisterIntegerPref(prefs::kTouchpadSensitivity, 3);
[email protected]530cd622011-04-14 15:45:0046 // Set the default based on the hour clock type of the current locale.
47 prefs->RegisterBooleanPref(prefs::kUse24HourClock,
48 base::GetHourClockType() == base::k24HourClock);
[email protected]20ce516d2010-06-18 02:20:0449 prefs->RegisterStringPref(prefs::kLanguageCurrentInputMethod, "");
50 prefs->RegisterStringPref(prefs::kLanguagePreviousInputMethod, "");
[email protected]3b02de292010-05-13 06:05:0551 prefs->RegisterStringPref(prefs::kLanguageHotkeyNextEngineInMenu,
[email protected]b65c5d22010-08-20 02:50:2352 language_prefs::kHotkeyNextEngineInMenu);
[email protected]3b02de292010-05-13 06:05:0553 prefs->RegisterStringPref(prefs::kLanguageHotkeyPreviousEngine,
[email protected]b65c5d22010-08-20 02:50:2354 language_prefs::kHotkeyPreviousEngine);
[email protected]c5d45432010-09-07 08:25:3555 prefs->RegisterStringPref(prefs::kLanguagePreferredLanguages,
56 kFallbackInputMethodLocale);
[email protected]d18893ee2011-02-03 13:14:2357 prefs->RegisterStringPref(
58 prefs::kLanguagePreloadEngines,
[email protected]2779ec22011-02-10 06:31:3559 input_method::GetHardwareInputMethodId());
[email protected]b65c5d22010-08-20 02:50:2360 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) {
61 prefs->RegisterBooleanPref(
62 language_prefs::kChewingBooleanPrefs[i].pref_name,
63 language_prefs::kChewingBooleanPrefs[i].default_pref_value);
[email protected]525dbe22010-06-01 07:05:4364 }
[email protected]b65c5d22010-08-20 02:50:2365 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) {
[email protected]525dbe22010-06-01 07:05:4366 prefs->RegisterStringPref(
[email protected]b65c5d22010-08-20 02:50:2367 language_prefs::kChewingMultipleChoicePrefs[i].pref_name,
68 language_prefs::kChewingMultipleChoicePrefs[i].default_pref_value);
[email protected]525dbe22010-06-01 07:05:4369 }
[email protected]b65c5d22010-08-20 02:50:2370 prefs->RegisterIntegerPref(
71 language_prefs::kChewingHsuSelKeyType.pref_name,
72 language_prefs::kChewingHsuSelKeyType.default_pref_value);
[email protected]7ac5af92010-06-07 01:25:4473
[email protected]b65c5d22010-08-20 02:50:2374 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) {
75 prefs->RegisterIntegerPref(
76 language_prefs::kChewingIntegerPrefs[i].pref_name,
77 language_prefs::kChewingIntegerPrefs[i].default_pref_value);
[email protected]15c53082010-06-03 03:28:2178 }
[email protected]20ce516d2010-06-18 02:20:0479 prefs->RegisterStringPref(
80 prefs::kLanguageHangulKeyboard,
[email protected]b65c5d22010-08-20 02:50:2381 language_prefs::kHangulKeyboardNameIDPairs[0].keyboard_id);
82 prefs->RegisterStringPref(prefs::kLanguageHangulHanjaKeys,
83 language_prefs::kHangulHanjaKeys);
84 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) {
85 prefs->RegisterBooleanPref(
86 language_prefs::kPinyinBooleanPrefs[i].pref_name,
87 language_prefs::kPinyinBooleanPrefs[i].default_pref_value);
[email protected]9040ad22010-04-22 04:29:2888 }
[email protected]b65c5d22010-08-20 02:50:2389 for (size_t i = 0; i < language_prefs::kNumPinyinIntegerPrefs; ++i) {
90 prefs->RegisterIntegerPref(
91 language_prefs::kPinyinIntegerPrefs[i].pref_name,
92 language_prefs::kPinyinIntegerPrefs[i].default_pref_value);
[email protected]6e5c4b82010-05-24 08:18:4493 }
[email protected]b65c5d22010-08-20 02:50:2394 prefs->RegisterIntegerPref(
95 language_prefs::kPinyinDoublePinyinSchema.pref_name,
96 language_prefs::kPinyinDoublePinyinSchema.default_pref_value);
[email protected]7ac5af92010-06-07 01:25:4497
[email protected]b65c5d22010-08-20 02:50:2398 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
99 prefs->RegisterBooleanPref(
100 language_prefs::kMozcBooleanPrefs[i].pref_name,
101 language_prefs::kMozcBooleanPrefs[i].default_pref_value);
[email protected]8a1ace22010-06-10 05:38:25102 }
[email protected]b65c5d22010-08-20 02:50:23103 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
[email protected]7ac5af92010-06-07 01:25:44104 prefs->RegisterStringPref(
[email protected]b65c5d22010-08-20 02:50:23105 language_prefs::kMozcMultipleChoicePrefs[i].pref_name,
106 language_prefs::kMozcMultipleChoicePrefs[i].default_pref_value);
[email protected]9040ad22010-04-22 04:29:28107 }
[email protected]b65c5d22010-08-20 02:50:23108 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
109 prefs->RegisterIntegerPref(
110 language_prefs::kMozcIntegerPrefs[i].pref_name,
111 language_prefs::kMozcIntegerPrefs[i].default_pref_value);
[email protected]54037462010-06-22 02:06:23112 }
[email protected]c010f632011-04-01 06:44:39113 prefs->RegisterIntegerPref(prefs::kLanguageXkbRemapSearchKeyTo,
114 input_method::kSearchKey);
[email protected]b5194dd32010-08-12 10:40:04115 prefs->RegisterIntegerPref(prefs::kLanguageXkbRemapControlKeyTo,
[email protected]c010f632011-04-01 06:44:39116 input_method::kLeftControlKey);
117 prefs->RegisterIntegerPref(prefs::kLanguageXkbRemapAltKeyTo,
118 input_method::kLeftAltKey);
[email protected]a995b392010-08-11 04:38:59119 prefs->RegisterBooleanPref(prefs::kLanguageXkbAutoRepeatEnabled, true);
[email protected]4743dad2010-08-30 01:41:07120 prefs->RegisterIntegerPref(prefs::kLanguageXkbAutoRepeatDelay,
121 language_prefs::kXkbAutoRepeatDelayInMs);
122 prefs->RegisterIntegerPref(prefs::kLanguageXkbAutoRepeatInterval,
123 language_prefs::kXkbAutoRepeatIntervalInMs);
[email protected]4ccc05e2010-10-06 19:32:15124
125 // Screen lock default to off.
126 prefs->RegisterBooleanPref(prefs::kEnableScreenLock, false);
[email protected]ea1eba52010-11-23 18:05:38127
128 // Mobile plan notifications default to on.
129 prefs->RegisterBooleanPref(prefs::kShowPlanNotifications, true);
[email protected]c74fffa2011-04-27 13:32:24130
131 // 3G first-time usage promo will be shown at least once.
132 prefs->RegisterBooleanPref(prefs::kShow3gPromoNotification, true);
[email protected]d6ae9502011-05-05 18:23:09133
134 // Carrier deal notification shown count defaults to 0.
135 prefs->RegisterIntegerPref(prefs::kCarrierDealPromoShown, 0);
[email protected]fecc1522009-10-15 21:08:29136}
137
138void Preferences::Init(PrefService* prefs) {
[email protected]fecc1522009-10-15 21:08:29139 tap_to_click_enabled_.Init(prefs::kTapToClickEnabled, prefs, this);
[email protected]fe23d5a32010-05-28 02:43:04140 accessibility_enabled_.Init(prefs::kAccessibilityEnabled, prefs, this);
[email protected]fecc1522009-10-15 21:08:29141 sensitivity_.Init(prefs::kTouchpadSensitivity, prefs, this);
[email protected]530cd622011-04-14 15:45:00142 use_24hour_clock_.Init(prefs::kUse24HourClock, prefs, this);
[email protected]3b02de292010-05-13 06:05:05143 language_hotkey_next_engine_in_menu_.Init(
144 prefs::kLanguageHotkeyNextEngineInMenu, prefs, this);
145 language_hotkey_previous_engine_.Init(
146 prefs::kLanguageHotkeyPreviousEngine, prefs, this);
[email protected]74b42fc12010-07-20 10:15:41147 language_preferred_languages_.Init(prefs::kLanguagePreferredLanguages,
148 prefs, this);
[email protected]70aa5b32010-04-05 08:30:34149 language_preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, this);
[email protected]b65c5d22010-08-20 02:50:23150 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) {
[email protected]525dbe22010-06-01 07:05:43151 language_chewing_boolean_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23152 language_prefs::kChewingBooleanPrefs[i].pref_name, prefs, this);
[email protected]525dbe22010-06-01 07:05:43153 }
[email protected]b65c5d22010-08-20 02:50:23154 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) {
[email protected]525dbe22010-06-01 07:05:43155 language_chewing_multiple_choice_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23156 language_prefs::kChewingMultipleChoicePrefs[i].pref_name, prefs, this);
[email protected]525dbe22010-06-01 07:05:43157 }
[email protected]7ac5af92010-06-07 01:25:44158 language_chewing_hsu_sel_key_type_.Init(
[email protected]b65c5d22010-08-20 02:50:23159 language_prefs::kChewingHsuSelKeyType.pref_name, prefs, this);
160 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) {
[email protected]15c53082010-06-03 03:28:21161 language_chewing_integer_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23162 language_prefs::kChewingIntegerPrefs[i].pref_name, prefs, this);
[email protected]15c53082010-06-03 03:28:21163 }
[email protected]50951432010-03-31 12:12:42164 language_hangul_keyboard_.Init(prefs::kLanguageHangulKeyboard, prefs, this);
[email protected]6e094092010-07-06 05:52:23165 language_hangul_hanja_keys_.Init(
166 prefs::kLanguageHangulHanjaKeys, prefs, this);
[email protected]b65c5d22010-08-20 02:50:23167 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) {
[email protected]9040ad22010-04-22 04:29:28168 language_pinyin_boolean_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23169 language_prefs::kPinyinBooleanPrefs[i].pref_name, prefs, this);
[email protected]9040ad22010-04-22 04:29:28170 }
[email protected]b65c5d22010-08-20 02:50:23171 for (size_t i = 0; i < language_prefs::kNumPinyinIntegerPrefs; ++i) {
[email protected]9040ad22010-04-22 04:29:28172 language_pinyin_int_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23173 language_prefs::kPinyinIntegerPrefs[i].pref_name, prefs, this);
[email protected]9040ad22010-04-22 04:29:28174 }
[email protected]7ac5af92010-06-07 01:25:44175 language_pinyin_double_pinyin_schema_.Init(
[email protected]b65c5d22010-08-20 02:50:23176 language_prefs::kPinyinDoublePinyinSchema.pref_name, prefs, this);
177 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
[email protected]8a1ace22010-06-10 05:38:25178 language_mozc_boolean_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23179 language_prefs::kMozcBooleanPrefs[i].pref_name, prefs, this);
[email protected]8a1ace22010-06-10 05:38:25180 }
[email protected]b65c5d22010-08-20 02:50:23181 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
[email protected]6e5c4b82010-05-24 08:18:44182 language_mozc_multiple_choice_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23183 language_prefs::kMozcMultipleChoicePrefs[i].pref_name, prefs, this);
[email protected]6e5c4b82010-05-24 08:18:44184 }
[email protected]b65c5d22010-08-20 02:50:23185 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
[email protected]54037462010-06-22 02:06:23186 language_mozc_integer_prefs_[i].Init(
[email protected]b65c5d22010-08-20 02:50:23187 language_prefs::kMozcIntegerPrefs[i].pref_name, prefs, this);
[email protected]54037462010-06-22 02:06:23188 }
[email protected]b5194dd32010-08-12 10:40:04189 language_xkb_remap_search_key_to_.Init(
190 prefs::kLanguageXkbRemapSearchKeyTo, prefs, this);
191 language_xkb_remap_control_key_to_.Init(
192 prefs::kLanguageXkbRemapControlKeyTo, prefs, this);
193 language_xkb_remap_alt_key_to_.Init(
194 prefs::kLanguageXkbRemapAltKeyTo, prefs, this);
[email protected]a995b392010-08-11 04:38:59195 language_xkb_auto_repeat_enabled_.Init(
196 prefs::kLanguageXkbAutoRepeatEnabled, prefs, this);
197 language_xkb_auto_repeat_delay_pref_.Init(
[email protected]4743dad2010-08-30 01:41:07198 prefs::kLanguageXkbAutoRepeatDelay, prefs, this);
[email protected]a995b392010-08-11 04:38:59199 language_xkb_auto_repeat_interval_pref_.Init(
[email protected]4743dad2010-08-30 01:41:07200 prefs::kLanguageXkbAutoRepeatInterval, prefs, this);
[email protected]fecc1522009-10-15 21:08:29201
[email protected]4ccc05e2010-10-06 19:32:15202 enable_screen_lock_.Init(prefs::kEnableScreenLock, prefs, this);
203
[email protected]fecc1522009-10-15 21:08:29204 // Initialize touchpad settings to what's saved in user preferences.
205 NotifyPrefChanged(NULL);
[email protected]26012e22010-12-01 06:44:27206
207 // If a guest is logged in, initialize the prefs as if this is the first
208 // login.
209 if (CommandLine::ForCurrentProcess()->HasSwitch(switches::kGuestSession)) {
210 LoginUtils::Get()->SetFirstLoginPrefs(prefs);
211 }
[email protected]fecc1522009-10-15 21:08:29212}
213
214void Preferences::Observe(NotificationType type,
[email protected]50951432010-03-31 12:12:42215 const NotificationSource& source,
216 const NotificationDetails& details) {
[email protected]fecc1522009-10-15 21:08:29217 if (type == NotificationType::PREF_CHANGED)
[email protected]57ecc4b2010-08-11 03:02:51218 NotifyPrefChanged(Details<std::string>(details).ptr());
[email protected]fecc1522009-10-15 21:08:29219}
220
[email protected]57ecc4b2010-08-11 03:02:51221void Preferences::NotifyPrefChanged(const std::string* pref_name) {
[email protected]3b02de292010-05-13 06:05:05222 if (!pref_name || *pref_name == prefs::kTapToClickEnabled) {
[email protected]b4e05f22010-09-08 17:27:46223 CrosLibrary::Get()->GetTouchpadLibrary()->SetTapToClick(
[email protected]c31b3c722009-10-21 20:01:35224 tap_to_click_enabled_.GetValue());
[email protected]3b02de292010-05-13 06:05:05225 }
[email protected]3b02de292010-05-13 06:05:05226 if (!pref_name || *pref_name == prefs::kTouchpadSensitivity) {
[email protected]b4e05f22010-09-08 17:27:46227 CrosLibrary::Get()->GetTouchpadLibrary()->SetSensitivity(
228 sensitivity_.GetValue());
[email protected]3b02de292010-05-13 06:05:05229 }
[email protected]8be9ff22010-06-08 02:13:54230
231 // We don't handle prefs::kLanguageCurrentInputMethod and PreviousInputMethod
232 // here.
233
[email protected]3b02de292010-05-13 06:05:05234 if (!pref_name || *pref_name == prefs::kLanguageHotkeyNextEngineInMenu) {
[email protected]ddd231e2010-06-29 20:35:19235 SetLanguageConfigStringListAsCSV(
[email protected]b65c5d22010-08-20 02:50:23236 language_prefs::kHotKeySectionName,
237 language_prefs::kNextEngineInMenuConfigName,
[email protected]ddd231e2010-06-29 20:35:19238 language_hotkey_next_engine_in_menu_.GetValue());
[email protected]3b02de292010-05-13 06:05:05239 }
240 if (!pref_name || *pref_name == prefs::kLanguageHotkeyPreviousEngine) {
[email protected]ddd231e2010-06-29 20:35:19241 SetLanguageConfigStringListAsCSV(
[email protected]b65c5d22010-08-20 02:50:23242 language_prefs::kHotKeySectionName,
243 language_prefs::kPreviousEngineConfigName,
[email protected]ddd231e2010-06-29 20:35:19244 language_hotkey_previous_engine_.GetValue());
[email protected]3b02de292010-05-13 06:05:05245 }
[email protected]74b42fc12010-07-20 10:15:41246 if (!pref_name || *pref_name == prefs::kLanguagePreferredLanguages) {
247 // Unlike kLanguagePreloadEngines and some other input method
248 // preferencs, we don't need to send this to ibus-daemon.
249 }
[email protected]a6e90772011-02-09 05:38:54250
251 // Here, we set up the the modifier key mapping. This has to be done
252 // before changing the current keyboard layout, so that the modifier key
253 // preference is properly preserved. For this reason, we should do this
254 // before setting preload engines, that could change the current
255 // keyboard layout as needed.
256 if (!pref_name || (*pref_name == prefs::kLanguageXkbRemapSearchKeyTo ||
257 *pref_name == prefs::kLanguageXkbRemapControlKeyTo ||
258 *pref_name == prefs::kLanguageXkbRemapAltKeyTo)) {
259 UpdateModifierKeyMapping();
260 }
261 if (!pref_name || *pref_name == prefs::kLanguageXkbAutoRepeatEnabled) {
262 const bool enabled = language_xkb_auto_repeat_enabled_.GetValue();
[email protected]c010f632011-04-01 06:44:39263 input_method::SetAutoRepeatEnabled(enabled);
[email protected]a6e90772011-02-09 05:38:54264 }
265 if (!pref_name || ((*pref_name == prefs::kLanguageXkbAutoRepeatDelay) ||
266 (*pref_name == prefs::kLanguageXkbAutoRepeatInterval))) {
267 UpdateAutoRepeatRate();
268 }
269
[email protected]3b02de292010-05-13 06:05:05270 if (!pref_name || *pref_name == prefs::kLanguagePreloadEngines) {
[email protected]b65c5d22010-08-20 02:50:23271 SetLanguageConfigStringListAsCSV(language_prefs::kGeneralSectionName,
272 language_prefs::kPreloadEnginesConfigName,
[email protected]d01bb8072010-04-12 13:00:15273 language_preload_engines_.GetValue());
[email protected]3b02de292010-05-13 06:05:05274 }
[email protected]b65c5d22010-08-20 02:50:23275 for (size_t i = 0; i < language_prefs::kNumChewingBooleanPrefs; ++i) {
276 if (!pref_name ||
277 *pref_name == language_prefs::kChewingBooleanPrefs[i].pref_name) {
278 SetLanguageConfigBoolean(
279 language_prefs::kChewingSectionName,
280 language_prefs::kChewingBooleanPrefs[i].ibus_config_name,
281 language_chewing_boolean_prefs_[i].GetValue());
[email protected]525dbe22010-06-01 07:05:43282 }
283 }
[email protected]b65c5d22010-08-20 02:50:23284 for (size_t i = 0; i < language_prefs::kNumChewingMultipleChoicePrefs; ++i) {
285 if (!pref_name ||
286 *pref_name ==
287 language_prefs::kChewingMultipleChoicePrefs[i].pref_name) {
[email protected]525dbe22010-06-01 07:05:43288 SetLanguageConfigString(
[email protected]b65c5d22010-08-20 02:50:23289 language_prefs::kChewingSectionName,
290 language_prefs::kChewingMultipleChoicePrefs[i].ibus_config_name,
[email protected]525dbe22010-06-01 07:05:43291 language_chewing_multiple_choice_prefs_[i].GetValue());
292 }
293 }
[email protected]b65c5d22010-08-20 02:50:23294 if (!pref_name ||
295 *pref_name == language_prefs::kChewingHsuSelKeyType.pref_name) {
[email protected]7ac5af92010-06-07 01:25:44296 SetLanguageConfigInteger(
[email protected]b65c5d22010-08-20 02:50:23297 language_prefs::kChewingSectionName,
298 language_prefs::kChewingHsuSelKeyType.ibus_config_name,
[email protected]7ac5af92010-06-07 01:25:44299 language_chewing_hsu_sel_key_type_.GetValue());
300 }
[email protected]b65c5d22010-08-20 02:50:23301 for (size_t i = 0; i < language_prefs::kNumChewingIntegerPrefs; ++i) {
302 if (!pref_name ||
303 *pref_name == language_prefs::kChewingIntegerPrefs[i].pref_name) {
304 SetLanguageConfigInteger(
305 language_prefs::kChewingSectionName,
306 language_prefs::kChewingIntegerPrefs[i].ibus_config_name,
307 language_chewing_integer_prefs_[i].GetValue());
[email protected]15c53082010-06-03 03:28:21308 }
309 }
[email protected]b65c5d22010-08-20 02:50:23310 if (!pref_name ||
311 *pref_name == prefs::kLanguageHangulKeyboard) {
312 SetLanguageConfigString(language_prefs::kHangulSectionName,
313 language_prefs::kHangulKeyboardConfigName,
[email protected]50951432010-03-31 12:12:42314 language_hangul_keyboard_.GetValue());
[email protected]3b02de292010-05-13 06:05:05315 }
[email protected]6e094092010-07-06 05:52:23316 if (!pref_name || *pref_name == prefs::kLanguageHangulHanjaKeys) {
[email protected]b65c5d22010-08-20 02:50:23317 SetLanguageConfigString(language_prefs::kHangulSectionName,
318 language_prefs::kHangulHanjaKeysConfigName,
[email protected]6e094092010-07-06 05:52:23319 language_hangul_hanja_keys_.GetValue());
320 }
[email protected]b65c5d22010-08-20 02:50:23321 for (size_t i = 0; i < language_prefs::kNumPinyinBooleanPrefs; ++i) {
322 if (!pref_name ||
323 *pref_name == language_prefs::kPinyinBooleanPrefs[i].pref_name) {
324 SetLanguageConfigBoolean(
325 language_prefs::kPinyinSectionName,
326 language_prefs::kPinyinBooleanPrefs[i].ibus_config_name,
327 language_pinyin_boolean_prefs_[i].GetValue());
[email protected]9040ad22010-04-22 04:29:28328 }
329 }
[email protected]b65c5d22010-08-20 02:50:23330 for (size_t i = 0; i < language_prefs::kNumPinyinIntegerPrefs; ++i) {
331 if (!pref_name ||
332 *pref_name == language_prefs::kPinyinIntegerPrefs[i].pref_name) {
333 SetLanguageConfigInteger(
334 language_prefs::kPinyinSectionName,
335 language_prefs::kPinyinIntegerPrefs[i].ibus_config_name,
336 language_pinyin_int_prefs_[i].GetValue());
[email protected]9040ad22010-04-22 04:29:28337 }
338 }
[email protected]b65c5d22010-08-20 02:50:23339 if (!pref_name ||
340 *pref_name == language_prefs::kPinyinDoublePinyinSchema.pref_name) {
[email protected]7ac5af92010-06-07 01:25:44341 SetLanguageConfigInteger(
[email protected]b65c5d22010-08-20 02:50:23342 language_prefs::kPinyinSectionName,
343 language_prefs::kPinyinDoublePinyinSchema.ibus_config_name,
[email protected]7ac5af92010-06-07 01:25:44344 language_pinyin_double_pinyin_schema_.GetValue());
345 }
[email protected]b65c5d22010-08-20 02:50:23346 for (size_t i = 0; i < language_prefs::kNumMozcBooleanPrefs; ++i) {
347 if (!pref_name ||
348 *pref_name == language_prefs::kMozcBooleanPrefs[i].pref_name) {
349 SetLanguageConfigBoolean(
350 language_prefs::kMozcSectionName,
351 language_prefs::kMozcBooleanPrefs[i].ibus_config_name,
352 language_mozc_boolean_prefs_[i].GetValue());
[email protected]8a1ace22010-06-10 05:38:25353 }
354 }
[email protected]b65c5d22010-08-20 02:50:23355 for (size_t i = 0; i < language_prefs::kNumMozcMultipleChoicePrefs; ++i) {
356 if (!pref_name ||
357 *pref_name == language_prefs::kMozcMultipleChoicePrefs[i].pref_name) {
[email protected]6e5c4b82010-05-24 08:18:44358 SetLanguageConfigString(
[email protected]b65c5d22010-08-20 02:50:23359 language_prefs::kMozcSectionName,
360 language_prefs::kMozcMultipleChoicePrefs[i].ibus_config_name,
[email protected]6e5c4b82010-05-24 08:18:44361 language_mozc_multiple_choice_prefs_[i].GetValue());
362 }
363 }
[email protected]b65c5d22010-08-20 02:50:23364 for (size_t i = 0; i < language_prefs::kNumMozcIntegerPrefs; ++i) {
365 if (!pref_name ||
366 *pref_name == language_prefs::kMozcIntegerPrefs[i].pref_name) {
367 SetLanguageConfigInteger(
368 language_prefs::kMozcSectionName,
369 language_prefs::kMozcIntegerPrefs[i].ibus_config_name,
370 language_mozc_integer_prefs_[i].GetValue());
[email protected]54037462010-06-22 02:06:23371 }
372 }
[email protected]4793c942010-09-21 23:17:17373
[email protected]4ccc05e2010-10-06 19:32:15374 // Init or update power manager config.
375 if (!pref_name || *pref_name == prefs::kEnableScreenLock) {
376 CrosLibrary::Get()->GetPowerLibrary()->EnableScreenLock(
377 enable_screen_lock_.GetValue());
378 }
[email protected]fecc1522009-10-15 21:08:29379}
380
[email protected]70aa5b32010-04-05 08:30:34381void Preferences::SetLanguageConfigBoolean(const char* section,
382 const char* name,
383 bool value) {
384 ImeConfigValue config;
385 config.type = ImeConfigValue::kValueTypeBool;
386 config.bool_value = value;
[email protected]60b07682010-06-17 08:45:28387 CrosLibrary::Get()->GetInputMethodLibrary()->
388 SetImeConfig(section, name, config);
[email protected]70aa5b32010-04-05 08:30:34389}
390
[email protected]9040ad22010-04-22 04:29:28391void Preferences::SetLanguageConfigInteger(const char* section,
392 const char* name,
393 int value) {
394 ImeConfigValue config;
395 config.type = ImeConfigValue::kValueTypeInt;
396 config.int_value = value;
[email protected]60b07682010-06-17 08:45:28397 CrosLibrary::Get()->GetInputMethodLibrary()->
398 SetImeConfig(section, name, config);
[email protected]9040ad22010-04-22 04:29:28399}
400
[email protected]50951432010-03-31 12:12:42401void Preferences::SetLanguageConfigString(const char* section,
402 const char* name,
[email protected]ddd231e2010-06-29 20:35:19403 const std::string& value) {
[email protected]50951432010-03-31 12:12:42404 ImeConfigValue config;
405 config.type = ImeConfigValue::kValueTypeString;
[email protected]ddd231e2010-06-29 20:35:19406 config.string_value = value;
[email protected]60b07682010-06-17 08:45:28407 CrosLibrary::Get()->GetInputMethodLibrary()->
408 SetImeConfig(section, name, config);
[email protected]50951432010-03-31 12:12:42409}
410
[email protected]2c25ddfd2010-04-09 10:35:55411void Preferences::SetLanguageConfigStringList(
412 const char* section,
413 const char* name,
[email protected]ddd231e2010-06-29 20:35:19414 const std::vector<std::string>& values) {
[email protected]2c25ddfd2010-04-09 10:35:55415 ImeConfigValue config;
416 config.type = ImeConfigValue::kValueTypeStringList;
[email protected]ddd231e2010-06-29 20:35:19417 for (size_t i = 0; i < values.size(); ++i)
418 config.string_list_value.push_back(values[i]);
419
[email protected]60b07682010-06-17 08:45:28420 CrosLibrary::Get()->GetInputMethodLibrary()->
421 SetImeConfig(section, name, config);
[email protected]2c25ddfd2010-04-09 10:35:55422}
423
[email protected]d01bb8072010-04-12 13:00:15424void Preferences::SetLanguageConfigStringListAsCSV(const char* section,
425 const char* name,
[email protected]ddd231e2010-06-29 20:35:19426 const std::string& value) {
[email protected]e24c2c92010-10-23 01:39:24427 VLOG(1) << "Setting " << name << " to '" << value << "'";
[email protected]d01bb8072010-04-12 13:00:15428
[email protected]ddd231e2010-06-29 20:35:19429 std::vector<std::string> split_values;
430 if (!value.empty())
[email protected]76eb0242010-10-14 00:35:36431 base::SplitString(value, ',', &split_values);
[email protected]ddd231e2010-06-29 20:35:19432
[email protected]2c25ddfd2010-04-09 10:35:55433 // We should call the cros API even when |value| is empty, to disable default
[email protected]d01bb8072010-04-12 13:00:15434 // config.
435 SetLanguageConfigStringList(section, name, split_values);
[email protected]70aa5b32010-04-05 08:30:34436}
437
[email protected]b5194dd32010-08-12 10:40:04438void Preferences::UpdateModifierKeyMapping() {
439 const int search_remap = language_xkb_remap_search_key_to_.GetValue();
440 const int control_remap = language_xkb_remap_control_key_to_.GetValue();
441 const int alt_remap = language_xkb_remap_alt_key_to_.GetValue();
[email protected]c010f632011-04-01 06:44:39442 if ((search_remap < input_method::kNumModifierKeys) && (search_remap >= 0) &&
443 (control_remap < input_method::kNumModifierKeys) &&
444 (control_remap >= 0) &&
445 (alt_remap < input_method::kNumModifierKeys) && (alt_remap >= 0)) {
446 input_method::ModifierMap modifier_map;
[email protected]b5194dd32010-08-12 10:40:04447 modifier_map.push_back(
[email protected]c010f632011-04-01 06:44:39448 input_method::ModifierKeyPair(
449 input_method::kSearchKey,
450 input_method::ModifierKey(search_remap)));
[email protected]b5194dd32010-08-12 10:40:04451 modifier_map.push_back(
[email protected]c010f632011-04-01 06:44:39452 input_method::ModifierKeyPair(
453 input_method::kLeftControlKey,
454 input_method::ModifierKey(control_remap)));
[email protected]b5194dd32010-08-12 10:40:04455 modifier_map.push_back(
[email protected]c010f632011-04-01 06:44:39456 input_method::ModifierKeyPair(
457 input_method::kLeftAltKey,
458 input_method::ModifierKey(alt_remap)));
459 input_method::RemapModifierKeys(modifier_map);
[email protected]b5194dd32010-08-12 10:40:04460 } else {
461 LOG(ERROR) << "Failed to remap modifier keys. Unexpected value(s): "
462 << search_remap << ", " << control_remap << ", " << alt_remap;
463 }
464}
465
[email protected]a995b392010-08-11 04:38:59466void Preferences::UpdateAutoRepeatRate() {
[email protected]c010f632011-04-01 06:44:39467 input_method::AutoRepeatRate rate;
[email protected]a995b392010-08-11 04:38:59468 rate.initial_delay_in_ms = language_xkb_auto_repeat_delay_pref_.GetValue();
469 rate.repeat_interval_in_ms =
470 language_xkb_auto_repeat_interval_pref_.GetValue();
471 DCHECK(rate.initial_delay_in_ms > 0);
472 DCHECK(rate.repeat_interval_in_ms > 0);
[email protected]c010f632011-04-01 06:44:39473 input_method::SetAutoRepeatRate(rate);
[email protected]a995b392010-08-11 04:38:59474}
475
[email protected]fecc1522009-10-15 21:08:29476} // namespace chromeos