Commit 56dbdd01 authored by stevenjb@google.com's avatar stevenjb@google.com

Add TrayLocale for locale change notifications.

TBR=ben for ash/ string changes
BUG=124726
TEST=On a device wuth ash-notify enabled in about:flags, change the locale and re-login. Notification should appear. Revert should revert the change after re-login. If ignored, the notification should appear again after re-login. Closing the notification should clear it.

Review URL: https://chromiumcodereview.appspot.com/10391177

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@137700 0039d316-1c4b-4281-b951-d872f2087c98
parent 89019d6a
......@@ -132,6 +132,8 @@
'system/ime/ime_observer.h',
'system/ime/tray_ime.cc',
'system/ime/tray_ime.h',
'system/locale/tray_locale.cc',
'system/locale/tray_locale.h',
'system/network/network_observer.h',
'system/network/tray_network.cc',
'system/network/tray_network.h',
......
......@@ -243,6 +243,12 @@ This file contains the strings for ash.
<message name="IDS_ASH_STATUS_TRAY_SMS_NUMBER" desc="Sender for SMS messagees in the system tray.">
SMS from <ph name="PHONE_NUMBER">$1<ex>08700 776655</ex></ph>
</message>
<message name="IDS_ASH_STATUS_TRAY_LOCALE_CHANGE_MESSAGE" desc="The message used for locale change notifications in the system tray.">
The language has changed from "<ph name="FROM_LOCALE">$1<ex>Italian</ex></ph>" to "<ph name="TO_LOCALE">$2<ex>English (United States)</ex></ph>" after syncing your settings.
</message>
<message name="IDS_ASH_STATUS_TRAY_LOCALE_REVERT_MESSAGE" desc="Link to revert a change.">
Change back to "<ph name="FROM_LOCALE">$1<ex>Italian</ex></ph>" (requires restart)
</message>
<message name="IDS_ASH_STATUS_TRAY_AIRPLANE_MODE" desc="The label used in the network dialog to turn on airplane mode.">
Airplane mode
</message>
......
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_LOCALE_LOCALE_OBSERVER_H_
#define ASH_SYSTEM_LOCALE_LOCALE_OBSERVER_H_
#pragma once
#include "ash/ash_export.h"
namespace ash {
class ASH_EXPORT LocaleObserver {
public:
class Delegate {
public:
virtual ~Delegate() {}
virtual void AcceptLocaleChange() = 0;
virtual void RevertLocaleChange() = 0;
};
virtual ~LocaleObserver() {}
virtual void OnLocaleChanged(Delegate* delegate,
const std::string& cur_locale,
const std::string& from_locale,
const std::string& to_locale) = 0;
};
} // namespace ash
#endif // ASH_SYSTEM_LOCALE_LOCALE_OBSERVER_H_
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ash/system/locale/tray_locale.h"
#include "ash/system/tray/tray_views.h"
#include "base/string16.h"
#include "grit/ash_strings.h"
#include "grit/ui_resources.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/views/view.h"
#include "ui/views/controls/label.h"
#include "ui/views/controls/link.h"
#include "ui/views/controls/link_listener.h"
namespace ash {
namespace internal {
namespace tray {
class LocaleNotificationView : public TrayNotificationView,
public views::LinkListener {
public:
LocaleNotificationView(TrayLocale* tray,
LocaleObserver::Delegate* delegate,
const std::string& cur_locale,
const std::string& from_locale,
const std::string& to_locale)
: tray_(tray),
delegate_(delegate) {
string16 from = l10n_util::GetDisplayNameForLocale(
from_locale, cur_locale, true);
string16 to = l10n_util::GetDisplayNameForLocale(
to_locale, cur_locale, true);
views::View* container = new views::View;
views::Label* message = new views::Label(
l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_LOCALE_CHANGE_MESSAGE, from, to));
container->AddChildView(message);
views::Link* revert = new views::Link(
l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_LOCALE_REVERT_MESSAGE, from));
container->AddChildView(revert);
InitView(container);
}
// Overridden from views::LinkListener.
virtual void LinkClicked(views::Link* source, int event_flags) OVERRIDE {
if (delegate_)
delegate_->RevertLocaleChange();
}
// Overridden from TrayNotificationView.
virtual void OnClose() OVERRIDE {
if (delegate_)
delegate_->AcceptLocaleChange();
tray_->HideNotificationView();
}
private:
TrayLocale* tray_;
LocaleObserver::Delegate* delegate_;
DISALLOW_COPY_AND_ASSIGN(LocaleNotificationView);
};
} // namespace tray
TrayLocale::TrayLocale()
: TrayImageItem(IDR_AURA_UBER_TRAY_LOCALE),
notification_(NULL),
delegate_(NULL) {
}
TrayLocale::~TrayLocale() {
}
bool TrayLocale::GetInitialVisibility() {
return notification_ != NULL;
}
views::View* TrayLocale::CreateNotificationView(user::LoginStatus status) {
if (!delegate_)
return NULL;
CHECK(notification_ == NULL);
notification_ = new tray::LocaleNotificationView(
this, delegate_, cur_locale_, from_locale_, to_locale_);
return notification_;
}
void TrayLocale::DestroyNotificationView() {
notification_ = NULL;
}
void TrayLocale::OnLocaleChanged(LocaleObserver::Delegate* delegate,
const std::string& cur_locale,
const std::string& from_locale,
const std::string& to_locale) {
if (notification_)
HideNotificationView();
delegate_ = delegate;
cur_locale_ = cur_locale;
from_locale_ = from_locale;
to_locale_ = to_locale;
ShowNotificationView();
}
} // namespace internal
} // namespace ash
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_LOCALE_TRAY_LOCALE_H_
#define ASH_SYSTEM_LOCALE_TRAY_LOCALE_H_
#pragma once
#include <string>
#include "ash/system/locale/locale_observer.h"
#include "ash/system/tray/tray_image_item.h"
namespace ash {
namespace internal {
namespace tray {
class LocaleNotificationView;
}
class TrayLocale : public TrayImageItem,
public LocaleObserver {
public:
TrayLocale();
virtual ~TrayLocale();
private:
// Overridden from TrayImageItem.
virtual bool GetInitialVisibility() OVERRIDE;
virtual views::View* CreateNotificationView(
user::LoginStatus status) OVERRIDE;
virtual void DestroyNotificationView() OVERRIDE;
// Overridden from LocaleObserver.
virtual void OnLocaleChanged(LocaleObserver::Delegate* delegate,
const std::string& cur_locale,
const std::string& from_locale,
const std::string& to_locale) OVERRIDE;
tray::LocaleNotificationView* notification_;
LocaleObserver::Delegate* delegate_;
std::string cur_locale_;
std::string from_locale_;
std::string to_locale_;
DISALLOW_COPY_AND_ASSIGN(TrayLocale);
};
} // namespace internal
} // namespace ash
#endif // ASH_SYSTEM_LOCALE_TRAY_LOCALE_H_
......@@ -13,6 +13,7 @@
#include "ash/system/date/tray_date.h"
#include "ash/system/drive/tray_drive.h"
#include "ash/system/ime/tray_ime.h"
#include "ash/system/locale/tray_locale.h"
#include "ash/system/network/tray_network.h"
#include "ash/system/network/tray_sms.h"
#include "ash/system/power/power_status_observer.h"
......@@ -162,6 +163,7 @@ SystemTray::SystemTray()
clock_observer_(NULL),
drive_observer_(NULL),
ime_observer_(NULL),
locale_observer_(NULL),
network_observer_(NULL),
power_status_observer_(NULL),
update_observer_(NULL),
......@@ -214,6 +216,7 @@ void SystemTray::CreateItems() {
internal::TrayCapsLock* tray_caps_lock = new internal::TrayCapsLock;
internal::TrayDrive* tray_drive = new internal::TrayDrive;
internal::TrayIME* tray_ime = new internal::TrayIME;
internal::TrayLocale* tray_locale = new internal::TrayLocale;
internal::TrayUpdate* tray_update = new internal::TrayUpdate;
accessibility_observer_ = tray_accessibility;
......@@ -224,6 +227,7 @@ void SystemTray::CreateItems() {
clock_observer_ = tray_date;
drive_observer_ = tray_drive;
ime_observer_ = tray_ime;
locale_observer_ = tray_locale;
network_observer_ = tray_network;
power_status_observer_ = tray_power;
update_observer_ = tray_update;
......@@ -236,6 +240,7 @@ void SystemTray::CreateItems() {
AddTrayItem(tray_sms);
AddTrayItem(tray_drive);
AddTrayItem(tray_ime);
AddTrayItem(tray_locale);
AddTrayItem(tray_volume);
AddTrayItem(tray_brightness);
AddTrayItem(tray_update);
......
......@@ -29,6 +29,7 @@ class CapsLockObserver;
class ClockObserver;
class DriveObserver;
class IMEObserver;
class LocaleObserver;
class NetworkObserver;
class PowerStatusObserver;
class UpdateObserver;
......@@ -129,6 +130,9 @@ class ASH_EXPORT SystemTray : public internal::ActionableView,
IMEObserver* ime_observer() const {
return ime_observer_;
}
LocaleObserver* locale_observer() const {
return locale_observer_;
}
NetworkObserver* network_observer() const {
return network_observer_;
}
......@@ -215,6 +219,7 @@ class ASH_EXPORT SystemTray : public internal::ActionableView,
ClockObserver* clock_observer_;
DriveObserver* drive_observer_;
IMEObserver* ime_observer_;
LocaleObserver* locale_observer_;
NetworkObserver* network_observer_;
PowerStatusObserver* power_status_observer_;
UpdateObserver* update_observer_;
......
......@@ -4,7 +4,11 @@
#include "chrome/browser/chromeos/locale_change_guard.h"
#include "ash/ash_switches.h"
#include "ash/shell.h"
#include "ash/system/tray/system_tray.h"
#include "base/bind.h"
#include "base/command_line.h"
#include "base/utf_string_conversions.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/browser_process.h"
......@@ -60,7 +64,7 @@ void LocaleChangeGuard::OnLogin() {
content::NotificationService::AllBrowserContextsAndSources());
}
void LocaleChangeGuard::RevertLocaleChange(const ListValue* list) {
void LocaleChangeGuard::RevertLocaleChange() {
if (note_ == NULL ||
profile_ == NULL ||
from_locale_.empty() ||
......@@ -80,6 +84,10 @@ void LocaleChangeGuard::RevertLocaleChange(const ListValue* list) {
browser->ExecuteCommand(IDC_EXIT);
}
void LocaleChangeGuard::RevertLocaleChangeCallback(const ListValue* list) {
RevertLocaleChange();
}
void LocaleChangeGuard::Observe(int type,
const content::NotificationSource& source,
const content::NotificationDetails& details) {
......@@ -162,6 +170,13 @@ void LocaleChangeGuard::Check() {
"Showing locale change notification in current (not previous) language";
PrepareChangingLocale(from_locale, to_locale);
}
if (CommandLine::ForCurrentProcess()->HasSwitch(ash::switches::kAshNotify)) {
ash::Shell::GetInstance()->tray()->locale_observer()->OnLocaleChanged(
this, cur_locale, from_locale_, to_locale_);
return;
}
note_.reset(new chromeos::SystemNotification(
profile_,
new Delegate(this),
......@@ -169,7 +184,7 @@ void LocaleChangeGuard::Check() {
title_text_));
note_->Show(
message_text_, revert_link_text_,
base::Bind(&LocaleChangeGuard::RevertLocaleChange,
base::Bind(&LocaleChangeGuard::RevertLocaleChangeCallback,
AsWeakPtr()),
true, // urgent
false); // non-sticky
......
// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
......@@ -8,6 +8,7 @@
#include <string>
#include "ash/system/locale/locale_observer.h"
#include "base/compiler_specific.h"
#include "base/lazy_instance.h"
#include "base/memory/scoped_ptr.h"
......@@ -29,11 +30,16 @@ namespace chromeos {
// (based on synchronized user preference). If so: shows notification that
// allows user to revert change.
class LocaleChangeGuard : public content::NotificationObserver,
public ash::LocaleObserver::Delegate,
public base::SupportsWeakPtr<LocaleChangeGuard> {
public:
explicit LocaleChangeGuard(Profile* profile);
virtual ~LocaleChangeGuard();
// ash::LocaleChangeDelegate implementation.
virtual void AcceptLocaleChange() OVERRIDE;
virtual void RevertLocaleChange() OVERRIDE;
// Called just before changing locale.
void PrepareChangingLocale(
const std::string& from_locale, const std::string& to_locale);
......@@ -44,8 +50,7 @@ class LocaleChangeGuard : public content::NotificationObserver,
private:
class Delegate;
void RevertLocaleChange(const base::ListValue* list);
void AcceptLocaleChange();
void RevertLocaleChangeCallback(const base::ListValue* list);
void Check();
// content::NotificationObserver implementation.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment