OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "chrome/browser/chromeos/dom_ui/system_options_handler.h" |
| 6 |
| 7 #include "app/l10n_util.h" |
| 8 #include "app/resource_bundle.h" |
| 9 #include "base/basictypes.h" |
| 10 #include "base/callback.h" |
| 11 #include "base/i18n/time_formatting.h" |
| 12 #include "base/stl_util-inl.h" |
| 13 #include "base/time.h" |
| 14 #include "base/utf_string_conversions.h" |
| 15 #include "base/values.h" |
| 16 #include "chrome/common/notification_service.h" |
| 17 #include "grit/browser_resources.h" |
| 18 #include "grit/chromium_strings.h" |
| 19 #include "grit/generated_resources.h" |
| 20 #include "grit/locale_settings.h" |
| 21 #include "grit/theme_resources.h" |
| 22 |
| 23 static const char* kTimeZonesUtf8[] = { |
| 24 "Pacific/Samoa", |
| 25 "US/Hawaii", |
| 26 "US/Alaska", |
| 27 "US/Pacific", |
| 28 "US/Mountain", |
| 29 "US/Central", |
| 30 "US/Eastern", |
| 31 "America/Santiago", |
| 32 "America/Sao_Paulo", |
| 33 "Atlantic/South_Georgia", |
| 34 "Atlantic/Cape_Verde", |
| 35 "Europe/London", |
| 36 "Europe/Rome", |
| 37 "Europe/Helsinki", |
| 38 "Europe/Moscow", |
| 39 "Asia/Dubai", |
| 40 "Asia/Karachi", |
| 41 "Asia/Dhaka", |
| 42 "Asia/Bangkok", |
| 43 "Asia/Hong_Kong", |
| 44 "Asia/Tokyo", |
| 45 "Australia/Sydney", |
| 46 "Asia/Magadan", |
| 47 "Pacific/Auckland" }; |
| 48 |
| 49 SystemOptionsHandler::SystemOptionsHandler() { |
| 50 // TODO(chocobo): For now, add all the GMT timezones. |
| 51 // We may eventually want to use icu::TimeZone::createEnumeration() |
| 52 // to list all the timezones and pick the ones we want to show. |
| 53 // NOTE: This currently does not handle daylight savings properly |
| 54 // b/c this is just a manually selected list of timezones that |
| 55 // happen to span the GMT-11 to GMT+12 Today. When daylight savings |
| 56 // kick in, this list might have more than one timezone in the same |
| 57 // GMT bucket. |
| 58 for (size_t i = 0; i < arraysize(kTimeZonesUtf8); i++) { |
| 59 timezones_.push_back(icu::TimeZone::createTimeZone( |
| 60 icu::UnicodeString::fromUTF8(kTimeZonesUtf8[i]))); |
| 61 } |
| 62 } |
| 63 |
| 64 SystemOptionsHandler::~SystemOptionsHandler() { |
| 65 STLDeleteElements(&timezones_); |
| 66 } |
| 67 |
| 68 void SystemOptionsHandler::GetLocalizedValues( |
| 69 DictionaryValue* localized_strings) { |
| 70 DCHECK(localized_strings); |
| 71 // System page - ChromeOS |
| 72 localized_strings->SetString(L"datetime_title", |
| 73 l10n_util::GetString(IDS_OPTIONS_SETTINGS_SECTION_TITLE_DATETIME)); |
| 74 localized_strings->SetString(L"timezone", |
| 75 l10n_util::GetString(IDS_OPTIONS_SETTINGS_TIMEZONE_DESCRIPTION)); |
| 76 |
| 77 localized_strings->SetString(L"touchpad", |
| 78 l10n_util::GetString(IDS_OPTIONS_SETTINGS_SECTION_TITLE_TOUCHPAD)); |
| 79 localized_strings->SetString(L"enable_tap_to_click", |
| 80 l10n_util::GetString( |
| 81 IDS_OPTIONS_SETTINGS_TAP_TO_CLICK_ENABLED_DESCRIPTION)); |
| 82 localized_strings->SetString(L"enable_vert_edge_scroll", |
| 83 l10n_util::GetString( |
| 84 IDS_OPTIONS_SETTINGS_VERT_EDGE_SCROLL_ENABLED_DESCRIPTION)); |
| 85 localized_strings->SetString(L"sensitivity", |
| 86 l10n_util::GetString(IDS_OPTIONS_SETTINGS_SENSITIVITY_DESCRIPTION)); |
| 87 localized_strings->SetString(L"speed_factor", |
| 88 l10n_util::GetString(IDS_OPTIONS_SETTINGS_SPEED_FACTOR_DESCRIPTION)); |
| 89 |
| 90 localized_strings->SetString(L"language", |
| 91 l10n_util::GetString(IDS_OPTIONS_SETTINGS_SECTION_TITLE_LANGUAGE)); |
| 92 localized_strings->SetString(L"language_customize", |
| 93 l10n_util::GetString(IDS_OPTIONS_SETTINGS_LANGUAGES_CUSTOMIZE)); |
| 94 |
| 95 localized_strings->SetString(L"accessibility_title", |
| 96 l10n_util::GetString(IDS_OPTIONS_SETTINGS_SECTION_TITLE_ACCESSIBILITY)); |
| 97 localized_strings->SetString(L"accessibility", |
| 98 l10n_util::GetString(IDS_OPTIONS_SETTINGS_ACCESSIBILITY_DESCRIPTION)); |
| 99 |
| 100 localized_strings->Set(L"timezoneMap", GetTimezoneMap()); |
| 101 } |
| 102 |
| 103 DictionaryValue* SystemOptionsHandler::GetTimezoneMap() { |
| 104 DictionaryValue* timezoneMap = new DictionaryValue(); |
| 105 for (std::vector<icu::TimeZone*>::iterator iter = timezones_.begin(); |
| 106 iter != timezones_.end(); ++iter) { |
| 107 const icu::TimeZone* timezone = *iter; |
| 108 timezoneMap->SetString(GetTimezoneID(timezone).c_str(), |
| 109 GetTimezoneName(timezone)); |
| 110 } |
| 111 return timezoneMap; |
| 112 } |
| 113 |
| 114 std::string SystemOptionsHandler::GetTimezoneName( |
| 115 const icu::TimeZone* timezone) { |
| 116 DCHECK(timezone); |
| 117 icu::UnicodeString name; |
| 118 timezone->getDisplayName(name); |
| 119 std::string output; |
| 120 UTF16ToUTF8(name.getBuffer(), name.length(), &output); |
| 121 int hour_offset = timezone->getRawOffset() / 3600000; |
| 122 const char* format; |
| 123 if (hour_offset == 0) |
| 124 format = "(GMT) "; |
| 125 else |
| 126 format = "(GMT%+d) "; |
| 127 |
| 128 return StringPrintf(format, hour_offset) + output; |
| 129 } |
| 130 |
| 131 std::wstring SystemOptionsHandler::GetTimezoneID( |
| 132 const icu::TimeZone* timezone) { |
| 133 DCHECK(timezone); |
| 134 icu::UnicodeString id; |
| 135 timezone->getID(id); |
| 136 std::wstring output; |
| 137 UTF16ToWide(id.getBuffer(), id.length(), &output); |
| 138 return output; |
| 139 } |
OLD | NEW |