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/fixed_sized_scroll_view.h" | 8 #include "ash/system/tray/fixed_sized_scroll_view.h" |
9 #include "ash/system/tray/hover_highlight_view.h" | 9 #include "ash/system/tray/hover_highlight_view.h" |
10 #include "ash/system/tray/system_tray.h" | 10 #include "ash/system/tray/system_tray.h" |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
121 ash::Shell::GetInstance()->system_tray_delegate(); | 121 ash::Shell::GetInstance()->system_tray_delegate(); |
122 if (delegate && bluetooth_discovering_) { | 122 if (delegate && bluetooth_discovering_) { |
123 bluetooth_discovering_ = false; | 123 bluetooth_discovering_ = false; |
124 delegate->BluetoothStopDiscovering(); | 124 delegate->BluetoothStopDiscovering(); |
125 throbber_->Stop(); | 125 throbber_->Stop(); |
126 } | 126 } |
127 } | 127 } |
128 | 128 |
129 void UpdateBlueToothDeviceList() { | 129 void UpdateBlueToothDeviceList() { |
130 connected_devices_.clear(); | 130 connected_devices_.clear(); |
131 connecting_devices_.clear(); | |
131 paired_not_connected_devices_.clear(); | 132 paired_not_connected_devices_.clear(); |
132 discovered_not_paired_devices_.clear(); | 133 discovered_not_paired_devices_.clear(); |
133 BluetoothDeviceList list; | 134 BluetoothDeviceList list; |
134 Shell::GetInstance()->system_tray_delegate()-> | 135 Shell::GetInstance()->system_tray_delegate()-> |
135 GetAvailableBluetoothDevices(&list); | 136 GetAvailableBluetoothDevices(&list); |
136 for (size_t i = 0; i < list.size(); ++i) { | 137 for (size_t i = 0; i < list.size(); ++i) { |
137 if (list[i].connected) | 138 if (list[i].connecting) { |
139 list[i].display_name = l10n_util::GetStringFUTF16( | |
140 IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTING, list[i].display_name); | |
141 connecting_devices_.push_back(list[i]); | |
142 } else if (list[i].connected) { | |
138 connected_devices_.push_back(list[i]); | 143 connected_devices_.push_back(list[i]); |
139 else if (list[i].paired) | 144 } else if (list[i].paired) { |
140 paired_not_connected_devices_.push_back(list[i]); | 145 paired_not_connected_devices_.push_back(list[i]); |
141 else | 146 } else { |
142 discovered_not_paired_devices_.push_back(list[i]); | 147 discovered_not_paired_devices_.push_back(list[i]); |
148 } | |
143 } | 149 } |
144 } | 150 } |
145 | 151 |
146 void AppendHeaderEntry() { | 152 void AppendHeaderEntry() { |
147 CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this); | 153 CreateSpecialRow(IDS_ASH_STATUS_TRAY_BLUETOOTH, this); |
148 | 154 |
149 if (login_ == user::LOGGED_IN_LOCKED) | 155 if (login_ == user::LOGGED_IN_LOCKED) |
150 return; | 156 return; |
151 | 157 |
152 throbber_ = new ThrobberView; | 158 throbber_ = new ThrobberView; |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
192 toggle_bluetooth_) { | 198 toggle_bluetooth_) { |
193 enable_bluetooth_ = | 199 enable_bluetooth_ = |
194 AddScrollListItem( | 200 AddScrollListItem( |
195 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH), | 201 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH), |
196 gfx::Font::NORMAL, false, true); | 202 gfx::Font::NORMAL, false, true); |
197 } | 203 } |
198 | 204 |
199 AppendSameTypeDevicesToScrollList( | 205 AppendSameTypeDevicesToScrollList( |
200 connected_devices_, true, true, bluetooth_enabled); | 206 connected_devices_, true, true, bluetooth_enabled); |
201 AppendSameTypeDevicesToScrollList( | 207 AppendSameTypeDevicesToScrollList( |
208 connecting_devices_, true, false, bluetooth_enabled); | |
209 AppendSameTypeDevicesToScrollList( | |
202 paired_not_connected_devices_, false, false, bluetooth_enabled); | 210 paired_not_connected_devices_, false, false, bluetooth_enabled); |
203 if (discovered_not_paired_devices_.size() > 0) | 211 if (discovered_not_paired_devices_.size() > 0) |
204 AddScrollSeparator(); | 212 AddScrollSeparator(); |
205 AppendSameTypeDevicesToScrollList( | 213 AppendSameTypeDevicesToScrollList( |
206 discovered_not_paired_devices_, false, false, bluetooth_enabled); | 214 discovered_not_paired_devices_, false, false, bluetooth_enabled); |
207 | 215 |
208 // Show user Bluetooth state if there is no bluetooth devices in list. | 216 // Show user Bluetooth state if there is no bluetooth devices in list. |
209 if (device_map_.size() == 0) { | 217 if (device_map_.size() == 0) { |
210 if (blueooth_available && bluetooth_enabled) { | 218 if (blueooth_available && bluetooth_enabled) { |
211 AddScrollListItem( | 219 AddScrollListItem( |
212 l10n_util::GetStringUTF16( | 220 l10n_util::GetStringUTF16( |
213 IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING), | 221 IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING), |
214 gfx::Font::NORMAL, false, true); | 222 gfx::Font::NORMAL, false, true); |
215 } | 223 } |
216 } | 224 } |
217 | 225 |
218 scroll_content()->SizeToPreferredSize(); | 226 scroll_content()->SizeToPreferredSize(); |
219 static_cast<views::View*>(scroller())->Layout(); | 227 static_cast<views::View*>(scroller())->Layout(); |
220 } | 228 } |
221 | 229 |
222 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list, | 230 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list, |
223 bool bold, | 231 bool bold, |
224 bool checked, | 232 bool checked, |
225 bool enabled) { | 233 bool enabled) { |
226 for (size_t i = 0; i < list.size(); ++i) { | 234 for (size_t i = 0; i < list.size(); ++i) { |
235 string16 display_name = list[i].display_name; | |
jennyz
2013/04/15 18:47:17
nit, you don't need to use this variable display_n
Jun Mukai
2013/04/15 21:09:45
Done.
| |
227 HoverHighlightView* container = AddScrollListItem( | 236 HoverHighlightView* container = AddScrollListItem( |
228 list[i].display_name, | 237 display_name, |
229 bold? gfx::Font::BOLD : gfx::Font::NORMAL, | 238 bold? gfx::Font::BOLD : gfx::Font::NORMAL, |
230 checked, enabled); | 239 checked, enabled); |
231 device_map_[container] = list[i].address; | 240 device_map_[container] = list[i].address; |
232 } | 241 } |
233 } | 242 } |
234 | 243 |
235 HoverHighlightView* AddScrollListItem(const base::string16& text, | 244 HoverHighlightView* AddScrollListItem(const base::string16& text, |
236 gfx::Font::FontStyle style, | 245 gfx::Font::FontStyle style, |
237 bool checked, | 246 bool checked, |
238 bool enabled) { | 247 bool enabled) { |
(...skipping 18 matching lines...) Expand all Loading... | |
257 HoverHighlightView* container = new HoverHighlightView(this); | 266 HoverHighlightView* container = new HoverHighlightView(this); |
258 container->AddLabel( | 267 container->AddLabel( |
259 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BLUETOOTH_ADD_DEVICE), | 268 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BLUETOOTH_ADD_DEVICE), |
260 gfx::Font::NORMAL); | 269 gfx::Font::NORMAL); |
261 container->SetEnabled(delegate->GetBluetoothAvailable()); | 270 container->SetEnabled(delegate->GetBluetoothAvailable()); |
262 AddChildView(container); | 271 AddChildView(container); |
263 add_device_ = container; | 272 add_device_ = container; |
264 } | 273 } |
265 | 274 |
266 // Returns true if the device with |device_id| is found in |device_list|, | 275 // Returns true if the device with |device_id| is found in |device_list|, |
267 // and the display_name of the device will be returned in |display_name|. | 276 // and the display_name of the device will be returned in |display_name| if |
277 // it's not NULL. | |
268 bool FoundDevice(const std::string& device_id, | 278 bool FoundDevice(const std::string& device_id, |
269 const BluetoothDeviceList& device_list, | 279 const BluetoothDeviceList& device_list, |
270 base::string16* display_name) { | 280 base::string16* display_name) { |
271 for (size_t i = 0; i < device_list.size(); ++i) { | 281 for (size_t i = 0; i < device_list.size(); ++i) { |
272 if (device_list[i].address == device_id) { | 282 if (device_list[i].address == device_id) { |
273 *display_name = device_list[i].display_name; | 283 if (display_name) |
284 *display_name = device_list[i].display_name; | |
274 return true; | 285 return true; |
275 } | 286 } |
276 } | 287 } |
277 return false; | 288 return false; |
278 } | 289 } |
279 | 290 |
280 // Updates UI of the clicked bluetooth device to show it is being connected | 291 // Updates UI of the clicked bluetooth device to show it is being connected |
281 // or disconnected if such an operation is going to be performed underway. | 292 // or disconnected if such an operation is going to be performed underway. |
282 void UpdateClickedDevice(std::string device_id, views::View* item_container) { | 293 void UpdateClickedDevice(std::string device_id, views::View* item_container) { |
283 base::string16 display_name; | 294 base::string16 display_name; |
(...skipping 24 matching lines...) Expand all Loading... | |
308 if (!delegate->GetBluetoothEnabled()) | 319 if (!delegate->GetBluetoothEnabled()) |
309 delegate->ToggleBluetooth(); | 320 delegate->ToggleBluetooth(); |
310 delegate->AddBluetoothDevice(); | 321 delegate->AddBluetoothDevice(); |
311 } else if (sender == enable_bluetooth_) { | 322 } else if (sender == enable_bluetooth_) { |
312 delegate->ToggleBluetooth(); | 323 delegate->ToggleBluetooth(); |
313 } else { | 324 } else { |
314 if (!delegate->GetBluetoothEnabled()) | 325 if (!delegate->GetBluetoothEnabled()) |
315 return; | 326 return; |
316 std::map<views::View*, std::string>::iterator find; | 327 std::map<views::View*, std::string>::iterator find; |
317 find = device_map_.find(sender); | 328 find = device_map_.find(sender); |
318 if (find != device_map_.end()) { | 329 if (find == device_map_.end()) |
319 std::string device_id = find->second; | 330 return; |
320 UpdateClickedDevice(device_id, sender); | 331 std::string device_id = find->second; |
321 delegate->ToggleBluetoothConnection(device_id); | 332 if (FoundDevice(device_id, connecting_devices_, NULL)) |
322 } | 333 return; |
334 UpdateClickedDevice(device_id, sender); | |
335 delegate->ToggleBluetoothConnection(device_id); | |
323 } | 336 } |
324 } | 337 } |
325 | 338 |
326 // Overridden from ButtonListener. | 339 // Overridden from ButtonListener. |
327 virtual void ButtonPressed(views::Button* sender, | 340 virtual void ButtonPressed(views::Button* sender, |
328 const ui::Event& event) OVERRIDE { | 341 const ui::Event& event) OVERRIDE { |
329 ash::SystemTrayDelegate* delegate = | 342 ash::SystemTrayDelegate* delegate = |
330 ash::Shell::GetInstance()->system_tray_delegate(); | 343 ash::Shell::GetInstance()->system_tray_delegate(); |
331 if (sender == toggle_bluetooth_) | 344 if (sender == toggle_bluetooth_) |
332 delegate->ToggleBluetooth(); | 345 delegate->ToggleBluetooth(); |
333 else | 346 else |
334 NOTREACHED(); | 347 NOTREACHED(); |
335 } | 348 } |
336 | 349 |
337 user::LoginStatus login_; | 350 user::LoginStatus login_; |
338 | 351 |
339 std::map<views::View*, std::string> device_map_; | 352 std::map<views::View*, std::string> device_map_; |
340 views::View* add_device_; | 353 views::View* add_device_; |
341 ThrobberView* throbber_; | 354 ThrobberView* throbber_; |
342 TrayPopupHeaderButton* toggle_bluetooth_; | 355 TrayPopupHeaderButton* toggle_bluetooth_; |
343 HoverHighlightView* enable_bluetooth_; | 356 HoverHighlightView* enable_bluetooth_; |
344 BluetoothDeviceList connected_devices_; | 357 BluetoothDeviceList connected_devices_; |
358 BluetoothDeviceList connecting_devices_; | |
345 BluetoothDeviceList paired_not_connected_devices_; | 359 BluetoothDeviceList paired_not_connected_devices_; |
346 BluetoothDeviceList discovered_not_paired_devices_; | 360 BluetoothDeviceList discovered_not_paired_devices_; |
347 bool bluetooth_discovering_; | 361 bool bluetooth_discovering_; |
348 | 362 |
349 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); | 363 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); |
350 }; | 364 }; |
351 | 365 |
352 } // namespace tray | 366 } // namespace tray |
353 | 367 |
354 TrayBluetooth::TrayBluetooth(SystemTray* system_tray) | 368 TrayBluetooth::TrayBluetooth(SystemTray* system_tray) |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
403 } | 417 } |
404 | 418 |
405 void TrayBluetooth::OnBluetoothDiscoveringChanged() { | 419 void TrayBluetooth::OnBluetoothDiscoveringChanged() { |
406 if (!detailed_) | 420 if (!detailed_) |
407 return; | 421 return; |
408 detailed_->Update(); | 422 detailed_->Update(); |
409 } | 423 } |
410 | 424 |
411 } // namespace internal | 425 } // namespace internal |
412 } // namespace ash | 426 } // namespace ash |
OLD | NEW |