OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ui/idle_logout_dialog_view.h" | 5 #include "chrome/browser/chromeos/ui/idle_logout_dialog_view.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/bind_helpers.h" | 9 #include "base/bind_helpers.h" |
10 #include "base/time.h" | 10 #include "base/time.h" |
11 #include "base/string_number_conversions.h" | 11 #include "base/string_number_conversions.h" |
12 #include "base/utf_string_conversions.h" | |
13 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" | 12 #include "chrome/browser/chromeos/kiosk_mode/kiosk_mode_settings.h" |
14 #include "chrome/browser/ui/browser_list.h" | 13 #include "chrome/browser/ui/browser_list.h" |
15 #include "chromeos/dbus/dbus_thread_manager.h" | 14 #include "chromeos/dbus/dbus_thread_manager.h" |
16 #include "chromeos/dbus/session_manager_client.h" | 15 #include "chromeos/dbus/session_manager_client.h" |
17 #include "grit/browser_resources.h" | 16 #include "grit/browser_resources.h" |
18 #include "grit/generated_resources.h" | 17 #include "grit/generated_resources.h" |
19 #include "ui/base/l10n/l10n_util.h" | 18 #include "ui/base/l10n/l10n_util.h" |
20 #include "ui/base/resource/resource_bundle.h" | 19 #include "ui/base/resource/resource_bundle.h" |
21 #include "ui/views/controls/label.h" | 20 #include "ui/views/controls/label.h" |
22 #include "ui/views/layout/grid_layout.h" | 21 #include "ui/views/layout/grid_layout.h" |
23 #include "ui/views/layout/layout_constants.h" | 22 #include "ui/views/layout/layout_constants.h" |
24 #include "ui/views/widget/widget.h" | 23 #include "ui/views/widget/widget.h" |
25 | 24 |
26 namespace { | 25 namespace { |
27 | 26 |
28 // Global singleton instance of our dialog class. | 27 // Global singleton instance of our dialog class. |
29 chromeos::IdleLogoutDialogView* g_instance = NULL; | 28 chromeos::IdleLogoutDialogView* g_instance = NULL; |
30 | 29 |
31 const int kIdleLogoutDialogMaxWidth = 300; | 30 const int kIdleLogoutDialogMaxWidth = 400; |
32 const int kCountdownUpdateIntervalMs = 1000; | 31 const int kCountdownUpdateIntervalMs = 1000; |
33 | 32 |
34 } // namespace | 33 } // namespace |
35 | 34 |
36 namespace chromeos { | 35 namespace chromeos { |
37 | 36 |
38 IdleLogoutSettingsProvider* IdleLogoutDialogView::provider_ = NULL; | 37 IdleLogoutSettingsProvider* IdleLogoutDialogView::provider_ = NULL; |
39 | 38 |
40 //////////////////////////////////////////////////////////////////////////////// | 39 //////////////////////////////////////////////////////////////////////////////// |
41 // IdleLogoutSettingsProvider public methods | 40 // IdleLogoutSettingsProvider public methods |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 } | 92 } |
94 | 93 |
95 views::View* IdleLogoutDialogView::GetContentsView() { | 94 views::View* IdleLogoutDialogView::GetContentsView() { |
96 return this; | 95 return this; |
97 } | 96 } |
98 | 97 |
99 //////////////////////////////////////////////////////////////////////////////// | 98 //////////////////////////////////////////////////////////////////////////////// |
100 // IdleLogoutDialog private methods | 99 // IdleLogoutDialog private methods |
101 IdleLogoutDialogView::IdleLogoutDialogView() | 100 IdleLogoutDialogView::IdleLogoutDialogView() |
102 : restart_label_(NULL), | 101 : restart_label_(NULL), |
| 102 warning_label_(NULL), |
103 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { | 103 weak_ptr_factory_(ALLOW_THIS_IN_INITIALIZER_LIST(this)) { |
104 if (!IdleLogoutDialogView::provider_) | 104 if (!IdleLogoutDialogView::provider_) |
105 IdleLogoutDialogView::provider_ = new IdleLogoutSettingsProvider(); | 105 IdleLogoutDialogView::provider_ = new IdleLogoutSettingsProvider(); |
106 } | 106 } |
107 | 107 |
108 IdleLogoutDialogView::~IdleLogoutDialogView() { | 108 IdleLogoutDialogView::~IdleLogoutDialogView() { |
109 if (this == g_instance) | 109 if (this == g_instance) |
110 g_instance = NULL; | 110 g_instance = NULL; |
111 } | 111 } |
112 | 112 |
113 void IdleLogoutDialogView::InitAndShow() { | 113 void IdleLogoutDialogView::InitAndShow() { |
114 KioskModeSettings* settings = | 114 KioskModeSettings* settings = |
115 IdleLogoutDialogView::provider_->GetKioskModeSettings(); | 115 IdleLogoutDialogView::provider_->GetKioskModeSettings(); |
116 if (!settings->is_initialized()) { | 116 if (!settings->is_initialized()) { |
117 settings->Initialize(base::Bind(&IdleLogoutDialogView::InitAndShow, | 117 settings->Initialize(base::Bind(&IdleLogoutDialogView::InitAndShow, |
118 weak_ptr_factory_.GetWeakPtr())); | 118 weak_ptr_factory_.GetWeakPtr())); |
119 return; | 119 return; |
120 } | 120 } |
121 | 121 |
122 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 122 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
123 | 123 |
| 124 warning_label_ = new views::Label( |
| 125 l10n_util::GetStringUTF16(IDS_IDLE_LOGOUT_WARNING)); |
| 126 warning_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 127 warning_label_->SetMultiLine(true); |
| 128 warning_label_->SetFont(rb.GetFont(ui::ResourceBundle::BaseFont)); |
| 129 warning_label_->SizeToFit(kIdleLogoutDialogMaxWidth); |
| 130 |
124 restart_label_ = new views::Label(); | 131 restart_label_ = new views::Label(); |
125 restart_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); | 132 restart_label_->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
126 restart_label_->SetMultiLine(true); | 133 restart_label_->SetFont(rb.GetFont(ui::ResourceBundle::BoldFont)); |
127 restart_label_->SetFont(rb.GetFont(ui::ResourceBundle::BaseFont)); | |
128 | 134 |
129 views::GridLayout* layout = views::GridLayout::CreatePanel(this); | 135 views::GridLayout* layout = views::GridLayout::CreatePanel(this); |
130 SetLayoutManager(layout); | 136 SetLayoutManager(layout); |
131 | 137 |
132 views::ColumnSet* column_set = layout->AddColumnSet(0); | 138 views::ColumnSet* column_set = layout->AddColumnSet(0); |
133 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1, | 139 column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::CENTER, 1, |
134 views::GridLayout::FIXED, kIdleLogoutDialogMaxWidth, 0); | 140 views::GridLayout::USE_PREF, 0, 0); |
135 layout->StartRow(0, 0); | 141 layout->StartRow(0, 0); |
136 layout->AddPaddingRow(0, views::kRelatedControlHorizontalSpacing); | 142 layout->AddView(warning_label_); |
| 143 layout->AddPaddingRow(0, views::kUnrelatedControlVerticalSpacing); |
137 layout->StartRow(0, 0); | 144 layout->StartRow(0, 0); |
138 layout->AddView(restart_label_); | 145 layout->AddView(restart_label_); |
139 layout->AddPaddingRow(0, views::kRelatedControlHorizontalSpacing); | |
140 | 146 |
141 // We're initialized, show the dialog. | 147 // We're initialized, can safely show the dialog now. |
142 Show(); | 148 Show(); |
143 } | 149 } |
144 | 150 |
145 void IdleLogoutDialogView::Show() { | 151 void IdleLogoutDialogView::Show() { |
146 KioskModeSettings* settings = | 152 KioskModeSettings* settings = |
147 IdleLogoutDialogView::provider_->GetKioskModeSettings(); | 153 IdleLogoutDialogView::provider_->GetKioskModeSettings(); |
148 | 154 |
149 // Setup the countdown label before showing. | 155 // Setup the countdown label before showing. |
150 countdown_end_time_ = base::Time::Now() + | 156 countdown_end_time_ = base::Time::Now() + |
151 settings->GetIdleLogoutWarningDuration(); | 157 settings->GetIdleLogoutWarningDuration(); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
211 return g_instance; | 217 return g_instance; |
212 } | 218 } |
213 | 219 |
214 // static | 220 // static |
215 void IdleLogoutDialogView::set_settings_provider( | 221 void IdleLogoutDialogView::set_settings_provider( |
216 IdleLogoutSettingsProvider* provider) { | 222 IdleLogoutSettingsProvider* provider) { |
217 provider_ = provider; | 223 provider_ = provider; |
218 } | 224 } |
219 | 225 |
220 } // namespace chromeos | 226 } // namespace chromeos |
OLD | NEW |