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_views.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 |
| 75 BluetoothDeviceList list; |
| 76 Shell::GetInstance()->tray_delegate()->GetAvailableBluetoothDevices(&list); |
| 77 Update(list); |
| 78 } |
| 79 |
| 80 virtual ~BluetoothDetailedView() {} |
| 81 |
| 82 void Update(BluetoothDeviceList& list) { |
| 83 RemoveAllChildViews(true); |
| 84 |
| 85 header_ = NULL; |
| 86 add_device_ = NULL; |
| 87 toggle_bluetooth_ = NULL; |
| 88 |
| 89 AppendHeaderEntry(); |
| 90 AppendDeviceList(); |
| 91 AppendSettingsEntries(); |
| 92 |
| 93 Layout(); |
| 94 } |
| 95 |
| 96 private: |
| 97 void AppendHeaderEntry() { |
| 98 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 99 HoverHighlightView* container = new HoverHighlightView(this); |
| 100 container->SetLayoutManager(new |
| 101 views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3, 5)); |
| 102 views::ImageView* back = new FixedWidthImageView; |
| 103 back->SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_LESS).ToSkBitmap()); |
| 104 container->AddChildView(back); |
| 105 views::Label* header = new views::Label(rb.GetLocalizedString( |
| 106 IDS_ASH_STATUS_TRAY_BLUETOOTH)); |
| 107 header->SetHorizontalAlignment(views::Label::ALIGN_LEFT); |
| 108 header->SetFont(header->font().DeriveFont(4)); |
| 109 container->AddChildView(header); |
| 110 AddChildView(container); |
| 111 header_ = container; |
| 112 } |
| 113 |
| 114 void AppendDeviceList() { |
| 115 } |
| 116 |
| 117 void AppendSettingsEntries() { |
| 118 ash::SystemTrayDelegate* delegate = |
| 119 ash::Shell::GetInstance()->tray_delegate(); |
| 120 HoverHighlightView* container = new HoverHighlightView(this); |
| 121 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 122 container->AddLabel(rb.GetLocalizedString( |
| 123 delegate->GetBluetoothEnabled() ? |
| 124 IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH : |
| 125 IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH)); |
| 126 AddChildView(container); |
| 127 toggle_bluetooth_ = container; |
| 128 |
| 129 container = new HoverHighlightView(this); |
| 130 container->AddLabel(rb.GetLocalizedString( |
| 131 IDS_ASH_STATUS_TRAY_BLUETOOTH_ADD_DEVICE)); |
| 132 AddChildView(container); |
| 133 add_device_ = container; |
| 134 } |
| 135 |
| 136 // Overridden from ViewClickListener. |
| 137 virtual void ClickedOn(views::View* sender) OVERRIDE { |
| 138 ash::SystemTrayDelegate* delegate = |
| 139 ash::Shell::GetInstance()->tray_delegate(); |
| 140 if (sender == header_) { |
| 141 Shell::GetInstance()->tray()->ShowDefaultView(); |
| 142 } else if (sender == toggle_bluetooth_) { |
| 143 delegate->ToggleBluetooth(); |
| 144 } else if (sender == add_device_) { |
| 145 delegate->AddBluetoothDevice(); |
| 146 } else { |
| 147 // TODO: Connect/disconnect from the device list. |
| 148 } |
| 149 } |
| 150 |
| 151 views::View* header_; |
| 152 views::View* add_device_; |
| 153 views::View* toggle_bluetooth_; |
| 154 views::View* settings_; |
| 155 |
| 156 DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); |
| 157 }; |
| 158 |
| 159 } // namespace tray |
| 160 |
| 161 TrayBluetooth::TrayBluetooth() |
| 162 : TrayImageItem(IDR_AURA_UBER_TRAY_BLUETOOTH_SMALL) { |
| 163 } |
| 164 |
| 165 TrayBluetooth::~TrayBluetooth() { |
| 166 } |
| 167 |
| 168 bool TrayBluetooth::GetInitialVisibility() { |
| 169 // Hide at startup. If bluetooth is enabled, the tray-delegate will send a |
| 170 // notification, and this will be made visible again. |
| 171 return false; |
| 172 } |
| 173 |
| 174 views::View* TrayBluetooth::CreateDefaultView(user::LoginStatus status) { |
| 175 if (!Shell::GetInstance()->tray_delegate()->GetBluetoothAvailable()) |
| 176 return NULL; |
| 177 default_.reset(new tray::BluetoothDefaultView(this)); |
| 178 return default_.get(); |
| 179 } |
| 180 |
| 181 views::View* TrayBluetooth::CreateDetailedView(user::LoginStatus status) { |
| 182 if (!Shell::GetInstance()->tray_delegate()->GetBluetoothAvailable()) |
| 183 return NULL; |
| 184 detailed_.reset(new tray::BluetoothDetailedView); |
| 185 return detailed_.get(); |
| 186 } |
| 187 |
| 188 void TrayBluetooth::DestroyDefaultView() { |
| 189 default_.reset(); |
| 190 } |
| 191 |
| 192 void TrayBluetooth::DestroyDetailedView() { |
| 193 detailed_.reset(); |
| 194 } |
| 195 |
| 196 void TrayBluetooth::OnBluetoothRefresh() { |
| 197 BluetoothDeviceList list; |
| 198 Shell::GetInstance()->tray_delegate()->GetAvailableBluetoothDevices(&list); |
| 199 if (default_.get()) |
| 200 default_->UpdateLabel(); |
| 201 if (detailed_.get()) |
| 202 detailed_->Update(list); |
| 203 } |
| 204 |
| 205 } // namespace internal |
| 206 } // namespace ash |
OLD | NEW |