| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "ash/system/bluetooth/tray_bluetooth.h" |
| 6 |
| 7 #include "ash/shell.h" |
| 8 #include "ash/system/tray/system_tray.h" |
| 9 #include "ash/system/tray/system_tray_delegate.h" |
| 10 #include "ash/system/tray/tray_constants.h" |
| 11 #include "ash/system/tray/tray_item_more.h" |
| 12 #include "ash/system/tray/tray_utils.h" |
| 13 #include "grit/ash_strings.h" |
| 14 #include "grit/ui_resources.h" |
| 15 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/gfx/image/image.h" |
| 17 #include "ui/views/controls/image_view.h" |
| 18 #include "ui/views/controls/label.h" |
| 19 #include "ui/views/layout/box_layout.h" |
| 20 |
| 21 namespace ash { |
| 22 namespace internal { |
| 23 |
| 24 namespace tray { |
| 25 |
| 26 class BluetoothDefaultView : public TrayItemMore { |
| 27 public: |
| 28 explicit BluetoothDefaultView(SystemTrayItem* owner) |
| 29 : TrayItemMore(owner) { |
| 30 SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal, |
| 31 kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingBetweenItems)); |
| 32 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 33 |
| 34 views::ImageView* icon = new views::ImageView; |
| 35 icon->SetImage(bundle.GetImageNamed( |
| 36 IDR_AURA_UBER_TRAY_BLUETOOTH_LARGE).ToSkBitmap()); |
| 37 AddChildView(icon); |
| 38 |
| 39 // TODO(sad): Use the correct label depending on the status. |
| 40 label_ = new views::Label; |
| 41 AddChildView(label_); |
| 42 UpdateLabel(); |
| 43 |
| 44 AddMore(); |
| 45 } |
| 46 |
| 47 virtual ~BluetoothDefaultView() {} |
| 48 |
| 49 void UpdateLabel() { |
| 50 ash::SystemTrayDelegate* delegate = |
| 51 ash::Shell::GetInstance()->tray_delegate(); |
| 52 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 53 label_->SetText(rb.GetLocalizedString(delegate->GetBluetoothEnabled() ? |
| 54 IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTED : |
| 55 IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED)); |
| 56 } |
| 57 |
| 58 private: |
| 59 views::Label* label_; |
| 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView); |
| 62 }; |
| 63 |
| 64 class BluetoothDetailedView : public views::View, |
| 65 public ViewClickListener { |
| 66 public: |
| 67 BluetoothDetailedView() |
| 68 : header_(NULL), |
| 69 add_device_(NULL), |
| 70 toggle_bluetooth_(NULL) { |
| 71 SetLayoutManager(new views::BoxLayout( |
| 72 views::BoxLayout::kVertical, 1, 1, 1)); |
| 73 set_background(views::Background::CreateSolidBackground(kBackgroundColor)); |
| 74 Update(); |
| 75 } |
| 76 |
| 77 virtual ~BluetoothDetailedView() {} |
| 78 |
| 79 void Update() { |
| 80 RemoveAllChildViews(true); |
| 81 |
| 82 header_ = NULL; |
| 83 add_device_ = NULL; |
| 84 toggle_bluetooth_ = NULL; |
| 85 |
| 86 AppendHeaderEntry(); |
| 87 AppendDeviceList(); |
| 88 AppendSettingsEntries(); |
| 89 |
| 90 Layout(); |
| 91 } |
| 92 |
| 93 private: |
| 94 void AppendHeaderEntry() { |
| 95 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 96 HoverHighlightView* container = new HoverHighlightView(this); |
| 97 container->SetLayoutManager(new |
| 98 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3, 5)); |
| 99 views::ImageView* back = new FixedWidthImageView; |
| 100 back->SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_LESS).ToSkBitmap()); |
| 101 container->AddChildView(back); |
| 102 views::Label* header = new views::Label(rb.GetLocalizedString( |
| 103 IDS_ASH_STATUS_TRAY_BLUETOOTH)); |
| 104 header->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 105 header->SetFont(header->font().DeriveFont(4)); |
| 106 container->AddChildView(header); |
| 107 AddChildView(container); |
| 108 header_ = container; |
| 109 } |
| 110 |
| 111 void AppendDeviceList() { |
| 112 } |
| 113 |
| 114 void AppendSettingsEntries() { |
| 115 ash::SystemTrayDelegate* delegate = |
| 116 ash::Shell::GetInstance()->tray_delegate(); |
| 117 HoverHighlightView* container = new HoverHighlightView(this); |
| 118 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 119 container->AddLabel(rb.GetLocalizedString( |
| 120 delegate->GetBluetoothEnabled() ? |
| 121 IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH : |
| 122 IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH)); |
| 123 AddChildView(container); |
| 124 toggle_bluetooth_ = container; |
| 125 |
| 126 container = new HoverHighlightView(this); |
| 127 container->AddLabel(rb.GetLocalizedString( |
| 128 IDS_ASH_STATUS_TRAY_BLUETOOTH_ADD_DEVICE)); |
| 129 AddChildView(container); |
| 130 add_device_ = container; |
| 131 } |
| 132 |
| 133 // Overridden from ViewClickListener. |
| 134 virtual void ClickedOn(views::View* sender) OVERRIDE { |
| 135 ash::SystemTrayDelegate* delegate = |
| 136 ash::Shell::GetInstance()->tray_delegate(); |
| 137 if (sender == header_) { |
| 138 Shell::GetInstance()->tray()->ShowDefaultView(); |
| 139 } else if (sender == toggle_bluetooth_) { |
| 140 delegate->ToggleBluetooth(); |
| 141 } else if (sender == add_device_) { |
| 142 delegate->AddBluetoothDevice(); |
| 143 } else { |
| 144 } |
| 145 } |
| 146 |
| 147 views::View* header_; |
| 148 views::View* add_device_; |
| 149 views::View* toggle_bluetooth_; |
| 150 views::View* settings_; |
| 151 |
| 152 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); |
| 153 }; |
| 154 |
| 155 } // namespace tray |
| 156 |
| 157 TrayBluetooth::TrayBluetooth() |
| 158 : TrayImageItem(IDR_AURA_UBER_TRAY_BLUETOOTH_SMALL) { |
| 159 } |
| 160 |
| 161 TrayBluetooth::~TrayBluetooth() { |
| 162 } |
| 163 |
| 164 bool TrayBluetooth::InitialVisibility() { |
| 165 // Hide at startup. If bluetooth is enabled, the tray-delegate will send a |
| 166 // notification, and this will be made visible again. |
| 167 return false; |
| 168 } |
| 169 |
| 170 views::View* TrayBluetooth::CreateDefaultView(user::LoginStatus status) { |
| 171 if (!Shell::GetInstance()->tray_delegate()->GetBluetoothAvailable()) |
| 172 return NULL; |
| 173 default_.reset(new tray::BluetoothDefaultView(this)); |
| 174 return default_.get(); |
| 175 } |
| 176 |
| 177 views::View* TrayBluetooth::CreateDetailedView(user::LoginStatus status) { |
| 178 if (!Shell::GetInstance()->tray_delegate()->GetBluetoothAvailable()) |
| 179 return NULL; |
| 180 detailed_.reset(new tray::BluetoothDetailedView); |
| 181 return detailed_.get(); |
| 182 } |
| 183 |
| 184 void TrayBluetooth::DestroyDefaultView() { |
| 185 default_.reset(); |
| 186 } |
| 187 |
| 188 void TrayBluetooth::DestroyDetailedView() { |
| 189 detailed_.reset(); |
| 190 } |
| 191 |
| 192 void TrayBluetooth::OnBluetoothRefresh() { |
| 193 BluetoothDeviceList list = |
| 194 Shell::GetInstance()->tray_delegate()->GetAvailableBluetoothDevices(); |
| 195 for (size_t i = 0; i < list.size(); ++i) { |
| 196 LOG(ERROR) << "Bluetooth device: \n" |
| 197 << " address: " << list[i].address << "\n" |
| 198 << " name: " << list[i].display_name << "\n" |
| 199 << " connected: " << list[i].connected; |
| 200 } |
| 201 image_view()->SetVisible(list.size()); |
| 202 if (default_.get()) |
| 203 default_->UpdateLabel(); |
| 204 if (detailed_.get()) |
| 205 detailed_->Update(); |
| 206 } |
| 207 |
| 208 } // namespace internal |
| 209 } // namespace ash |
| OLD | NEW |