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

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

Issue 11748023: M26 new bluetooth UI. List all bluetooth devices in detailed view and automatically discover all BT… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 11 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/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
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) {
sadrul 2013/01/07 20:39:03 No braces needed
jennyz 2013/01/07 20:57:12 Done.
188 AddScrollSeparator();
189 }
190 AppendSameTypeDevicesToScrollList(
191 discovered_not_paired_devices_, false, false, bluetooth_enabled);
151 192
152 // Show user Bluetooth state if there is no bluetooth devices in list. 193 // Show user Bluetooth state if there is no bluetooth devices in list.
153 if (connected_devices_.size() == 0 && 194 if (device_map_.size() == 0) {
154 paired_not_connected_devices_.size() == 0) { 195 if (blueooth_available && bluetooth_enabled) {
155 ash::SystemTrayDelegate* delegate = 196 AddScrollListItem(
156 ash::Shell::GetInstance()->system_tray_delegate(); 197 l10n_util::GetStringUTF16(
157 int message_id; 198 IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING),
158 if (delegate->GetBluetoothAvailable() && 199 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 } 200 }
167 } 201 }
202
203 scroll_content()->SizeToPreferredSize();
204 static_cast<views::View*>(scroller())->Layout();
168 } 205 }
169 206
170 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list, 207 void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list,
171 bool bold, 208 bool bold,
172 bool checked, 209 bool checked,
173 bool enabled) { 210 bool enabled) {
174 for (size_t i = 0; i < list.size(); ++i) { 211 for (size_t i = 0; i < list.size(); ++i) {
175 HoverHighlightView* container = AddScrollListItem( 212 HoverHighlightView* container = AddScrollListItem(
176 list[i].display_name, 213 list[i].display_name,
177 bold? gfx::Font::BOLD : gfx::Font::NORMAL, 214 bold? gfx::Font::BOLD : gfx::Font::NORMAL,
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 virtual void ClickedOn(views::View* sender) OVERRIDE { 254 virtual void ClickedOn(views::View* sender) OVERRIDE {
218 ash::SystemTrayDelegate* delegate = 255 ash::SystemTrayDelegate* delegate =
219 ash::Shell::GetInstance()->system_tray_delegate(); 256 ash::Shell::GetInstance()->system_tray_delegate();
220 if (sender == footer()->content()) { 257 if (sender == footer()->content()) {
221 owner()->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); 258 owner()->system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING);
222 } else if (sender == add_device_) { 259 } else if (sender == add_device_) {
223 if (!delegate->GetBluetoothEnabled()) 260 if (!delegate->GetBluetoothEnabled())
224 delegate->ToggleBluetooth(); 261 delegate->ToggleBluetooth();
225 delegate->AddBluetoothDevice(); 262 delegate->AddBluetoothDevice();
226 } else if (sender == enable_bluetooth_) { 263 } else if (sender == enable_bluetooth_) {
227 delegate->ToggleBluetooth(); 264 delegate->ToggleBluetooth();
228 } else { 265 } else {
229 std::map<views::View*, std::string>::iterator find; 266 std::map<views::View*, std::string>::iterator find;
230 find = device_map_.find(sender); 267 find = device_map_.find(sender);
231 if (find != device_map_.end()) { 268 if (find != device_map_.end()) {
232 std::string device_id = find->second; 269 std::string device_id = find->second;
233 delegate->ToggleBluetoothConnection(device_id); 270 delegate->ToggleBluetoothConnection(device_id);
234 } 271 }
235 } 272 }
236 } 273 }
237 274
238 // Overridden from ButtonListener. 275 // Overridden from ButtonListener.
239 virtual void ButtonPressed(views::Button* sender, 276 virtual void ButtonPressed(views::Button* sender,
240 const ui::Event& event) OVERRIDE { 277 const ui::Event& event) OVERRIDE {
241 ash::SystemTrayDelegate* delegate = 278 ash::SystemTrayDelegate* delegate =
242 ash::Shell::GetInstance()->system_tray_delegate(); 279 ash::Shell::GetInstance()->system_tray_delegate();
243 if (sender == toggle_bluetooth_) 280 if (sender == toggle_bluetooth_)
244 delegate->ToggleBluetooth(); 281 delegate->ToggleBluetooth();
245 else 282 else
246 NOTREACHED(); 283 NOTREACHED();
247 } 284 }
248 285
249 user::LoginStatus login_; 286 user::LoginStatus login_;
250 287
251 std::map<views::View*, std::string> device_map_; 288 std::map<views::View*, std::string> device_map_;
252 views::View* add_device_; 289 views::View* add_device_;
253 TrayPopupHeaderButton* toggle_bluetooth_; 290 TrayPopupHeaderButton* toggle_bluetooth_;
254 HoverHighlightView* enable_bluetooth_; 291 HoverHighlightView* enable_bluetooth_;
255 BluetoothDeviceList connected_devices_; 292 BluetoothDeviceList connected_devices_;
256 BluetoothDeviceList paired_not_connected_devices_; 293 BluetoothDeviceList paired_not_connected_devices_;
294 BluetoothDeviceList discovered_not_paired_devices_;
295 bool bluetooth_discovering_;
257 296
258 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); 297 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView);
259 }; 298 };
260 299
261 } // namespace tray 300 } // namespace tray
262 301
263 TrayBluetooth::TrayBluetooth(SystemTray* system_tray) 302 TrayBluetooth::TrayBluetooth(SystemTray* system_tray)
264 : SystemTrayItem(system_tray), 303 : SystemTrayItem(system_tray),
265 default_(NULL), 304 default_(NULL),
266 detailed_(NULL) { 305 detailed_(NULL) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 } 350 }
312 351
313 void TrayBluetooth::OnBluetoothDiscoveringChanged() { 352 void TrayBluetooth::OnBluetoothDiscoveringChanged() {
314 if (!detailed_) 353 if (!detailed_)
315 return; 354 return;
316 detailed_->Update(); 355 detailed_->Update();
317 } 356 }
318 357
319 } // namespace internal 358 } // namespace internal
320 } // namespace ash 359 } // 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