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 "ash/system/bluetooth/tray_bluetooth.h" | 5 #include "ash/system/bluetooth/tray_bluetooth.h" |
6 | 6 |
7 #include "ash/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/system/tray/system_tray.h" | 8 #include "ash/system/tray/system_tray.h" |
9 #include "ash/system/tray/system_tray_delegate.h" | 9 #include "ash/system/tray/system_tray_delegate.h" |
10 #include "ash/system/tray/system_tray_notifier.h" | 10 #include "ash/system/tray/system_tray_notifier.h" |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 | 64 |
65 class BluetoothDetailedView : public TrayDetailsView, | 65 class BluetoothDetailedView : public TrayDetailsView, |
66 public ViewClickListener, | 66 public ViewClickListener, |
67 public views::ButtonListener { | 67 public views::ButtonListener { |
68 public: | 68 public: |
69 BluetoothDetailedView(SystemTrayItem* owner, user::LoginStatus login) | 69 BluetoothDetailedView(SystemTrayItem* owner, user::LoginStatus login) |
70 : TrayDetailsView(owner), | 70 : TrayDetailsView(owner), |
71 login_(login), | 71 login_(login), |
72 add_device_(NULL), | 72 add_device_(NULL), |
73 toggle_bluetooth_(NULL), | 73 toggle_bluetooth_(NULL), |
74 enable_bluetooth_(NULL) { | 74 enable_bluetooth_(NULL), |
| 75 bluetooth_discovering_(false) { |
| 76 CreateItems(); |
75 Update(); | 77 Update(); |
76 } | 78 } |
77 | 79 |
78 virtual ~BluetoothDetailedView() {} | 80 virtual ~BluetoothDetailedView() { |
| 81 // Stop discovering bluetooth devices when exiting BT detailed view. |
| 82 BluetoothSetDiscovering(false); |
| 83 } |
79 | 84 |
80 void Update() { | 85 void Update() { |
| 86 BluetoothSetDiscovering(true); |
81 UpdateBlueToothDeviceList(); | 87 UpdateBlueToothDeviceList(); |
82 | 88 |
83 Reset(); | 89 // Update UI. |
84 | 90 UpdateDeviceScrollList(); |
85 add_device_ = NULL; | 91 UpdateHeaderEntry(); |
86 toggle_bluetooth_ = NULL; | |
87 | |
88 AppendDeviceList(); | |
89 AppendSettingsEntries(); | |
90 AppendHeaderEntry(); | |
91 | |
92 Layout(); | 92 Layout(); |
93 } | 93 } |
94 | 94 |
95 private: | 95 private: |
| 96 void CreateItems() { |
| 97 CreateScrollableList(); |
| 98 AppendSettingsEntries(); |
| 99 AppendHeaderEntry(); |
| 100 } |
| 101 |
| 102 void BluetoothSetDiscovering(bool discovering) { |
| 103 ash::SystemTrayDelegate* delegate = |
| 104 ash::Shell::GetInstance()->system_tray_delegate(); |
| 105 if (discovering) { |
| 106 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); |
| 107 if (!bluetooth_discovering_ && bluetooth_enabled) |
| 108 delegate->BluetoothSetDiscovering(true); |
| 109 bluetooth_discovering_ = bluetooth_enabled; |
| 110 } else { // Stop bluetooth discovering. |
| 111 if (bluetooth_discovering_) { |
| 112 bluetooth_discovering_ = false; |
| 113 delegate->BluetoothSetDiscovering(false); |
| 114 } |
| 115 } |
| 116 } |
| 117 |
96 void UpdateBlueToothDeviceList() { | 118 void UpdateBlueToothDeviceList() { |
97 connected_devices_.clear(); | 119 connected_devices_.clear(); |
98 paired_not_connected_devices_.clear(); | 120 paired_not_connected_devices_.clear(); |
| 121 discovered_not_paired_devices_.clear(); |
99 BluetoothDeviceList list; | 122 BluetoothDeviceList list; |
100 Shell::GetInstance()->system_tray_delegate()-> | 123 Shell::GetInstance()->system_tray_delegate()-> |
101 GetAvailableBluetoothDevices(&list); | 124 GetAvailableBluetoothDevices(&list); |
102 for (size_t i = 0; i < list.size(); ++i) { | 125 for (size_t i = 0; i < list.size(); ++i) { |
103 if (list[i].connected) | 126 if (list[i].connected) |
104 connected_devices_.push_back(list[i]); | 127 connected_devices_.push_back(list[i]); |
105 else | 128 else if (list[i].paired) |
106 paired_not_connected_devices_.push_back(list[i]); | 129 paired_not_connected_devices_.push_back(list[i]); |
| 130 else if (list[i].visible) |
| 131 discovered_not_paired_devices_.push_back(list[i]); |
107 } | 132 } |
108 } | 133 } |
109 | 134 |
110 void AppendHeaderEntry() { | 135 void AppendHeaderEntry() { |
111 CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this); | 136 CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this); |
112 | 137 |
113 if (login_ == user::LOGGED_IN_LOCKED) | 138 if (login_ == user::LOGGED_IN_LOCKED) |
114 return; | 139 return; |
115 | 140 |
116 // Do not allow toggling bluetooth in the lock screen. | 141 // Do not allow toggling bluetooth in the lock screen. |
117 ash::SystemTrayDelegate* delegate = | 142 ash::SystemTrayDelegate* delegate = |
118 ash::Shell::GetInstance()->system_tray_delegate(); | 143 ash::Shell::GetInstance()->system_tray_delegate(); |
119 toggle_bluetooth_ = new TrayPopupHeaderButton(this, | 144 toggle_bluetooth_ = new TrayPopupHeaderButton(this, |
120 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, | 145 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED, |
121 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED, | 146 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED, |
122 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER, | 147 IDR_AURA_UBER_TRAY_BLUETOOTH_ENABLED_HOVER, |
123 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER, | 148 IDR_AURA_UBER_TRAY_BLUETOOTH_DISABLED_HOVER, |
124 IDS_ASH_STATUS_TRAY_BLUETOOTH); | 149 IDS_ASH_STATUS_TRAY_BLUETOOTH); |
125 toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled()); | 150 toggle_bluetooth_->SetToggled(!delegate->GetBluetoothEnabled()); |
126 toggle_bluetooth_->SetTooltipText( | 151 toggle_bluetooth_->SetTooltipText( |
127 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH)); | 152 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH)); |
128 toggle_bluetooth_->SetToggledTooltipText( | 153 toggle_bluetooth_->SetToggledTooltipText( |
129 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH)); | 154 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH)); |
130 footer()->AddButton(toggle_bluetooth_); | 155 footer()->AddButton(toggle_bluetooth_); |
| 156 } |
| 157 |
| 158 void UpdateHeaderEntry() { |
| 159 if (toggle_bluetooth_) { |
| 160 toggle_bluetooth_->SetToggled( |
| 161 !ash::Shell::GetInstance()->system_tray_delegate()-> |
| 162 GetBluetoothEnabled()); |
| 163 } |
131 } | 164 } |
132 | 165 |
133 void AppendDeviceList() { | 166 void UpdateDeviceScrollList() { |
134 device_map_.clear(); | 167 device_map_.clear(); |
135 CreateScrollableList(); | 168 scroll_content()->RemoveAllChildViews(true); |
| 169 enable_bluetooth_ = NULL; |
136 | 170 |
137 ash::SystemTrayDelegate* delegate = | 171 ash::SystemTrayDelegate* delegate = |
138 ash::Shell::GetInstance()->system_tray_delegate(); | 172 ash::Shell::GetInstance()->system_tray_delegate(); |
139 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); | 173 bool bluetooth_enabled = delegate->GetBluetoothEnabled(); |
140 if (delegate->GetBluetoothAvailable() && !bluetooth_enabled) { | 174 bool blueooth_available = delegate->GetBluetoothAvailable(); |
| 175 if (blueooth_available && !bluetooth_enabled && |
| 176 toggle_bluetooth_) { |
141 enable_bluetooth_ = | 177 enable_bluetooth_ = |
142 AddScrollListItem( | 178 AddScrollListItem( |
143 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH), | 179 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH), |
144 gfx::Font::NORMAL, false, true); | 180 gfx::Font::NORMAL, false, true); |
145 } | 181 } |
146 | 182 |
147 AppendSameTypeDevicesToScrollList( | 183 AppendSameTypeDevicesToScrollList( |
148 connected_devices_, true, true, bluetooth_enabled); | 184 connected_devices_, true, true, bluetooth_enabled); |
149 AppendSameTypeDevicesToScrollList( | 185 AppendSameTypeDevicesToScrollList( |
150 paired_not_connected_devices_, false, false, bluetooth_enabled); | 186 paired_not_connected_devices_, false, false, bluetooth_enabled); |
| 187 if (discovered_not_paired_devices_.size() > 0) |
| 188 AddScrollSeparator(); |
| 189 AppendSameTypeDevicesToScrollList( |
| 190 discovered_not_paired_devices_, false, false, bluetooth_enabled); |
151 | 191 |
152 // Show user Bluetooth state if there is no bluetooth devices in list. | 192 // Show user Bluetooth state if there is no bluetooth devices in list. |
153 if (connected_devices_.size() == 0 && | 193 if (device_map_.size() == 0) { |
154 paired_not_connected_devices_.size() == 0) { | 194 if (blueooth_available && bluetooth_enabled) { |
155 ash::SystemTrayDelegate* delegate = | 195 AddScrollListItem( |
156 ash::Shell::GetInstance()->system_tray_delegate(); | 196 l10n_util::GetStringUTF16( |
157 int message_id; | 197 IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING), |
158 if (delegate->GetBluetoothAvailable() && | 198 gfx::Font::NORMAL, false, true); |
159 delegate->GetBluetoothEnabled()) { | |
160 if (delegate->IsBluetoothDiscovering()) | |
161 message_id = IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING; | |
162 else | |
163 message_id = IDS_ASH_STATUS_TRAY_BLUETOOTH_NO_DEVICE; | |
164 AddScrollListItem(l10n_util::GetStringUTF16(message_id), | |
165 gfx::Font::NORMAL, false, true); | |
166 } | 199 } |
167 } | 200 } |
| 201 |
| 202 scroll_content()->SizeToPreferredSize(); |
| 203 static_cast<views::View*>(scroller())->Layout(); |
168 } | 204 } |
169 | 205 |
170 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list, | 206 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list, |
171 bool bold, | 207 bool bold, |
172 bool checked, | 208 bool checked, |
173 bool enabled) { | 209 bool enabled) { |
174 for (size_t i = 0; i < list.size(); ++i) { | 210 for (size_t i = 0; i < list.size(); ++i) { |
175 HoverHighlightView* container = AddScrollListItem( | 211 HoverHighlightView* container = AddScrollListItem( |
176 list[i].display_name, | 212 list[i].display_name, |
177 bold? gfx::Font::BOLD : gfx::Font::NORMAL, | 213 bold? gfx::Font::BOLD : gfx::Font::NORMAL, |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 virtual void ClickedOn(views::View* sender) OVERRIDE { | 253 virtual void ClickedOn(views::View* sender) OVERRIDE { |
218 ash::SystemTrayDelegate* delegate = | 254 ash::SystemTrayDelegate* delegate = |
219 ash::Shell::GetInstance()->system_tray_delegate(); | 255 ash::Shell::GetInstance()->system_tray_delegate(); |
220 if (sender == footer()->content()) { | 256 if (sender == footer()->content()) { |
221 owner()->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); | 257 owner()->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); |
222 } else if (sender == add_device_) { | 258 } else if (sender == add_device_) { |
223 if (!delegate->GetBluetoothEnabled()) | 259 if (!delegate->GetBluetoothEnabled()) |
224 delegate->ToggleBluetooth(); | 260 delegate->ToggleBluetooth(); |
225 delegate->AddBluetoothDevice(); | 261 delegate->AddBluetoothDevice(); |
226 } else if (sender == enable_bluetooth_) { | 262 } else if (sender == enable_bluetooth_) { |
227 delegate->ToggleBluetooth(); | 263 delegate->ToggleBluetooth(); |
228 } else { | 264 } else { |
229 std::map<views::View*, std::string>::iterator find; | 265 std::map<views::View*, std::string>::iterator find; |
230 find = device_map_.find(sender); | 266 find = device_map_.find(sender); |
231 if (find != device_map_.end()) { | 267 if (find != device_map_.end()) { |
232 std::string device_id = find->second; | 268 std::string device_id = find->second; |
233 delegate->ToggleBluetoothConnection(device_id); | 269 delegate->ToggleBluetoothConnection(device_id); |
234 } | 270 } |
235 } | 271 } |
236 } | 272 } |
237 | 273 |
238 // Overridden from ButtonListener. | 274 // Overridden from ButtonListener. |
239 virtual void ButtonPressed(views::Button* sender, | 275 virtual void ButtonPressed(views::Button* sender, |
240 const ui::Event& event) OVERRIDE { | 276 const ui::Event& event) OVERRIDE { |
241 ash::SystemTrayDelegate* delegate = | 277 ash::SystemTrayDelegate* delegate = |
242 ash::Shell::GetInstance()->system_tray_delegate(); | 278 ash::Shell::GetInstance()->system_tray_delegate(); |
243 if (sender == toggle_bluetooth_) | 279 if (sender == toggle_bluetooth_) |
244 delegate->ToggleBluetooth(); | 280 delegate->ToggleBluetooth(); |
245 else | 281 else |
246 NOTREACHED(); | 282 NOTREACHED(); |
247 } | 283 } |
248 | 284 |
249 user::LoginStatus login_; | 285 user::LoginStatus login_; |
250 | 286 |
251 std::map<views::View*, std::string> device_map_; | 287 std::map<views::View*, std::string> device_map_; |
252 views::View* add_device_; | 288 views::View* add_device_; |
253 TrayPopupHeaderButton* toggle_bluetooth_; | 289 TrayPopupHeaderButton* toggle_bluetooth_; |
254 HoverHighlightView* enable_bluetooth_; | 290 HoverHighlightView* enable_bluetooth_; |
255 BluetoothDeviceList connected_devices_; | 291 BluetoothDeviceList connected_devices_; |
256 BluetoothDeviceList paired_not_connected_devices_; | 292 BluetoothDeviceList paired_not_connected_devices_; |
| 293 BluetoothDeviceList discovered_not_paired_devices_; |
| 294 bool bluetooth_discovering_; |
257 | 295 |
258 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); | 296 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); |
259 }; | 297 }; |
260 | 298 |
261 } // namespace tray | 299 } // namespace tray |
262 | 300 |
263 TrayBluetooth::TrayBluetooth(SystemTray* system_tray) | 301 TrayBluetooth::TrayBluetooth(SystemTray* system_tray) |
264 : SystemTrayItem(system_tray), | 302 : SystemTrayItem(system_tray), |
265 default_(NULL), | 303 default_(NULL), |
266 detailed_(NULL) { | 304 detailed_(NULL) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 } | 349 } |
312 | 350 |
313 void TrayBluetooth::OnBluetoothDiscoveringChanged() { | 351 void TrayBluetooth::OnBluetoothDiscoveringChanged() { |
314 if (!detailed_) | 352 if (!detailed_) |
315 return; | 353 return; |
316 detailed_->Update(); | 354 detailed_->Update(); |
317 } | 355 } |
318 | 356 |
319 } // namespace internal | 357 } // namespace internal |
320 } // namespace ash | 358 } // namespace ash |
OLD | NEW |