Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Side by Side Diff: ash/system/bluetooth/tray_bluetooth.cc

Issue 12385064: Introduce 'connecting' field to bluetooth device info for system tray (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | ash/system/tray/system_tray_delegate.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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(
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
257 HoverHighlightView* container = new HoverHighlightView(this); 265 HoverHighlightView* container = new HoverHighlightView(this);
258 container->AddLabel( 266 container->AddLabel(
259 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BLUETOOTH_ADD_DEVICE), 267 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BLUETOOTH_ADD_DEVICE),
260 gfx::Font::NORMAL); 268 gfx::Font::NORMAL);
261 container->SetEnabled(delegate->GetBluetoothAvailable()); 269 container->SetEnabled(delegate->GetBluetoothAvailable());
262 AddChildView(container); 270 AddChildView(container);
263 add_device_ = container; 271 add_device_ = container;
264 } 272 }
265 273
266 // Returns true if the device with |device_id| is found in |device_list|, 274 // 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|. 275 // and the display_name of the device will be returned in |display_name| if
276 // it's not NULL.
268 bool FoundDevice(const std::string& device_id, 277 bool FoundDevice(const std::string& device_id,
269 const BluetoothDeviceList& device_list, 278 const BluetoothDeviceList& device_list,
270 base::string16* display_name) { 279 base::string16* display_name) {
271 for (size_t i = 0; i < device_list.size(); ++i) { 280 for (size_t i = 0; i < device_list.size(); ++i) {
272 if (device_list[i].address == device_id) { 281 if (device_list[i].address == device_id) {
273 *display_name = device_list[i].display_name; 282 if (display_name)
283 *display_name = device_list[i].display_name;
274 return true; 284 return true;
275 } 285 }
276 } 286 }
277 return false; 287 return false;
278 } 288 }
279 289
280 // Updates UI of the clicked bluetooth device to show it is being connected 290 // 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. 291 // or disconnected if such an operation is going to be performed underway.
282 void UpdateClickedDevice(std::string device_id, views::View* item_container) { 292 void UpdateClickedDevice(std::string device_id, views::View* item_container) {
283 base::string16 display_name; 293 base::string16 display_name;
(...skipping 24 matching lines...) Expand all
308 if (!delegate->GetBluetoothEnabled()) 318 if (!delegate->GetBluetoothEnabled())
309 delegate->ToggleBluetooth(); 319 delegate->ToggleBluetooth();
310 delegate->AddBluetoothDevice(); 320 delegate->AddBluetoothDevice();
311 } else if (sender == enable_bluetooth_) { 321 } else if (sender == enable_bluetooth_) {
312 delegate->ToggleBluetooth(); 322 delegate->ToggleBluetooth();
313 } else { 323 } else {
314 if (!delegate->GetBluetoothEnabled()) 324 if (!delegate->GetBluetoothEnabled())
315 return; 325 return;
316 std::map<views::View*, std::string>::iterator find; 326 std::map<views::View*, std::string>::iterator find;
317 find = device_map_.find(sender); 327 find = device_map_.find(sender);
318 if (find != device_map_.end()) { 328 if (find == device_map_.end())
319 std::string device_id = find->second; 329 return;
320 UpdateClickedDevice(device_id, sender); 330 std::string device_id = find->second;
321 delegate->ToggleBluetoothConnection(device_id); 331 if (FoundDevice(device_id, connecting_devices_, NULL))
322 } 332 return;
333 UpdateClickedDevice(device_id, sender);
334 delegate->ToggleBluetoothConnection(device_id);
323 } 335 }
324 } 336 }
325 337
326 // Overridden from ButtonListener. 338 // Overridden from ButtonListener.
327 virtual void ButtonPressed(views::Button* sender, 339 virtual void ButtonPressed(views::Button* sender,
328 const ui::Event& event) OVERRIDE { 340 const ui::Event& event) OVERRIDE {
329 ash::SystemTrayDelegate* delegate = 341 ash::SystemTrayDelegate* delegate =
330 ash::Shell::GetInstance()->system_tray_delegate(); 342 ash::Shell::GetInstance()->system_tray_delegate();
331 if (sender == toggle_bluetooth_) 343 if (sender == toggle_bluetooth_)
332 delegate->ToggleBluetooth(); 344 delegate->ToggleBluetooth();
333 else 345 else
334 NOTREACHED(); 346 NOTREACHED();
335 } 347 }
336 348
337 user::LoginStatus login_; 349 user::LoginStatus login_;
338 350
339 std::map<views::View*, std::string> device_map_; 351 std::map<views::View*, std::string> device_map_;
340 views::View* add_device_; 352 views::View* add_device_;
341 ThrobberView* throbber_; 353 ThrobberView* throbber_;
342 TrayPopupHeaderButton* toggle_bluetooth_; 354 TrayPopupHeaderButton* toggle_bluetooth_;
343 HoverHighlightView* enable_bluetooth_; 355 HoverHighlightView* enable_bluetooth_;
344 BluetoothDeviceList connected_devices_; 356 BluetoothDeviceList connected_devices_;
357 BluetoothDeviceList connecting_devices_;
345 BluetoothDeviceList paired_not_connected_devices_; 358 BluetoothDeviceList paired_not_connected_devices_;
346 BluetoothDeviceList discovered_not_paired_devices_; 359 BluetoothDeviceList discovered_not_paired_devices_;
347 bool bluetooth_discovering_; 360 bool bluetooth_discovering_;
348 361
349 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); 362 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView);
350 }; 363 };
351 364
352 } // namespace tray 365 } // namespace tray
353 366
354 TrayBluetooth::TrayBluetooth(SystemTray* system_tray) 367 TrayBluetooth::TrayBluetooth(SystemTray* system_tray)
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
403 } 416 }
404 417
405 void TrayBluetooth::OnBluetoothDiscoveringChanged() { 418 void TrayBluetooth::OnBluetoothDiscoveringChanged() {
406 if (!detailed_) 419 if (!detailed_)
407 return; 420 return;
408 detailed_->Update(); 421 detailed_->Update();
409 } 422 }
410 423
411 } // namespace internal 424 } // namespace internal
412 } // namespace ash 425 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/system/tray/system_tray_delegate.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698