1a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 2a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// found in the LICENSE file. 4a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 5a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ash/system/locale/locale_notification_controller.h" 6a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 7a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ash/shell.h" 8424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)#include "ash/system/system_notifier.h" 9a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ash/system/tray/system_tray_notifier.h" 10a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/strings/string16.h" 113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "grit/ash_resources.h" 12a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "grit/ash_strings.h" 13a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h" 143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/base/resource/resource_bundle.h" 15a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ui/message_center/message_center.h" 16a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ui/message_center/notification.h" 17a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ui/message_center/notification_delegate.h" 18a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "ui/message_center/notification_types.h" 19a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 20a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)using message_center::Notification; 21a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 22a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)namespace ash { 23a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)namespace { 24a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 25a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)const char kLocaleChangeNotificationId[] = "chrome://settings/locale"; 26a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 27a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)class LocaleNotificationDelegate : public message_center::NotificationDelegate { 28a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) public: 29a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) explicit LocaleNotificationDelegate(LocaleObserver::Delegate* delegate); 30a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 31a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) protected: 32a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) virtual ~LocaleNotificationDelegate(); 33a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 34a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // message_center::NotificationDelegate overrides: 35a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) virtual void Display() OVERRIDE; 36a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) virtual void Error() OVERRIDE; 37a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) virtual void Close(bool by_user) OVERRIDE; 38a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) virtual bool HasClickedListener() OVERRIDE; 39a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) virtual void Click() OVERRIDE; 40a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) virtual void ButtonClick(int button_index) OVERRIDE; 41a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 42a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) private: 43a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) LocaleObserver::Delegate* delegate_; 44a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 45a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) DISALLOW_COPY_AND_ASSIGN(LocaleNotificationDelegate); 46a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}; 47a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 48a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)LocaleNotificationDelegate::LocaleNotificationDelegate( 49a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) LocaleObserver::Delegate* delegate) 50a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) : delegate_(delegate) { 51a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) DCHECK(delegate_); 52a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 53a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 54a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)LocaleNotificationDelegate::~LocaleNotificationDelegate() { 55a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 56a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 57a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)void LocaleNotificationDelegate::Display() { 58a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 59a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 60a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)void LocaleNotificationDelegate::Error() { 61a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 62a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 63a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)void LocaleNotificationDelegate::Close(bool by_user) { 64a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) delegate_->AcceptLocaleChange(); 65a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 66a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 67a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)bool LocaleNotificationDelegate::HasClickedListener() { 68ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch return true; 69a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 70a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 71a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)void LocaleNotificationDelegate::Click() { 72ba5b9a6411cb1792fd21f0a078d7a25cd1ceec16Ben Murdoch delegate_->AcceptLocaleChange(); 73a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 74a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 75a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)void LocaleNotificationDelegate::ButtonClick(int button_index) { 76a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) DCHECK_EQ(0, button_index); 77a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) delegate_->RevertLocaleChange(); 78a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 79a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 80a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} // namespace 81a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 82a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)LocaleNotificationController::LocaleNotificationController() 83a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) : delegate_(NULL) { 84a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Shell::GetInstance()->system_tray_notifier()->AddLocaleObserver(this); 85a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 86a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 87a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)LocaleNotificationController::~LocaleNotificationController() { 88a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) Shell::GetInstance()->system_tray_notifier()->RemoveLocaleObserver(this); 89a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 90a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 91a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)void LocaleNotificationController::OnLocaleChanged( 92a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) LocaleObserver::Delegate* delegate, 93a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::string& cur_locale, 94a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::string& from_locale, 95a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) const std::string& to_locale) { 96a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) if (!delegate) 97a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) return; 98a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 99a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) base::string16 from = l10n_util::GetDisplayNameForLocale( 100a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) from_locale, cur_locale, true); 101a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) base::string16 to = l10n_util::GetDisplayNameForLocale( 102a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) to_locale, cur_locale, true); 103a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 104a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) message_center::RichNotificationData optional; 105a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) optional.buttons.push_back(message_center::ButtonInfo( 106a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) l10n_util::GetStringFUTF16( 107a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) IDS_ASH_STATUS_TRAY_LOCALE_REVERT_MESSAGE, from))); 108a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) optional.never_timeout = true; 109a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 1103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); 111a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) scoped_ptr<Notification> notification(new Notification( 112a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) message_center::NOTIFICATION_TYPE_SIMPLE, 113a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) kLocaleChangeNotificationId, 1148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) base::string16() /* title */, 115a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) l10n_util::GetStringFUTF16( 116a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) IDS_ASH_STATUS_TRAY_LOCALE_CHANGE_MESSAGE, from, to), 1173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bundle.GetImageNamed(IDR_AURA_UBER_TRAY_LOCALE), 118a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) base::string16() /* display_source */, 119a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) message_center::NotifierId( 120a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) message_center::NotifierId::SYSTEM_COMPONENT, 121a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) system_notifier::kNotifierLocale), 122a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) optional, 123a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) new LocaleNotificationDelegate(delegate))); 124a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) message_center::MessageCenter::Get()->AddNotification(notification.Pass()); 125a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 126a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 127a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} // namespace ash 128