network_menu_button.h revision 4a5e2dc747d50c653511c68ccb2cfbfb740bd5a7
1// Copyright (c) 2006-2008 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#ifndef CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_BUTTON_H_
6#define CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_BUTTON_H_
7#pragma once
8
9#include <string>
10
11#include "app/throb_animation.h"
12#include "base/timer.h"
13#include "chrome/browser/chromeos/cros/network_library.h"
14#include "chrome/browser/chromeos/status/network_menu.h"
15#include "chrome/browser/chromeos/status/status_area_button.h"
16
17namespace gfx {
18class Canvas;
19}
20
21namespace chromeos {
22
23class StatusAreaHost;
24
25// The network menu button in the status area.
26// This class will handle getting the wifi networks and populating the menu.
27// It will also handle the status icon changing and connecting to another
28// wifi/cellular network.
29//
30// The network menu looks like this:
31//
32// <icon>  Ethernet
33// <icon>  Wifi Network A
34// <icon>  Wifi Network B
35// <icon>  Wifi Network C
36// <icon>  Cellular Network A
37// <icon>  Cellular Network B
38// <icon>  Cellular Network C
39// <icon>  Other...
40// --------------------------------
41//         Disable Wifi
42//         Disable Celluar
43// --------------------------------
44//         <IP Address>
45//         Network settings...
46//
47// <icon> will show the strength of the wifi/cellular networks.
48// The label will be BOLD if the network is currently connected.
49class NetworkMenuButton : public StatusAreaButton,
50                          public NetworkMenu,
51                          public NetworkLibrary::NetworkManagerObserver,
52                          public NetworkLibrary::NetworkObserver,
53                          public NetworkLibrary::CellularDataPlanObserver {
54 public:
55  explicit NetworkMenuButton(StatusAreaHost* host);
56  virtual ~NetworkMenuButton();
57
58  // AnimationDelegate implementation.
59  virtual void AnimationProgressed(const Animation* animation);
60
61  // NetworkLibrary::NetworkManagerObserver implementation.
62  virtual void OnNetworkManagerChanged(NetworkLibrary* cros);
63  // NetworkLibrary::NetworkObserver implementation.
64  virtual void OnNetworkChanged(NetworkLibrary* cros, const Network* network);
65  // NetworkLibrary::CellularDataPlanObserver implementation.
66  virtual void OnCellularDataPlanChanged(NetworkLibrary* cros);
67
68  // Sets the badge icon.
69  void SetBadge(const SkBitmap& badge) { badge_ = badge; }
70  SkBitmap badge() const { return badge_; }
71
72 protected:
73  // StatusAreaButton implementation.
74  virtual void DrawIcon(gfx::Canvas* canvas);
75
76  // NetworkMenu implementation:
77  virtual bool IsBrowserMode() const;
78  virtual gfx::NativeWindow GetNativeWindow() const;
79  virtual void OpenButtonOptions();
80  virtual bool ShouldOpenButtonOptions() const;
81
82 private:
83  void SetNetworkIcon(const Network* network);
84  void SetNetworkBadge(NetworkLibrary* cros, const Network* network);
85
86  // Called when the active network has possibly changed. This will remove
87  // old network observer and add a network observer for the active network.
88  void RefreshNetworkObserver(NetworkLibrary* cros);
89
90  // The status area host,
91  StatusAreaHost* host_;
92
93  // A badge icon displayed on top of the icon.
94  SkBitmap badge_;
95
96  // The throb animation that does the wifi connecting animation.
97  ThrobAnimation animation_connecting_;
98
99  // The duration of the icon throbbing in milliseconds.
100  static const int kThrobDuration;
101
102  // If any network is currently active, this is the service path of the one
103  // whose status is displayed in the network menu button.
104  std::string active_network_;
105
106  DISALLOW_COPY_AND_ASSIGN(NetworkMenuButton);
107};
108
109}  // namespace chromeos
110
111#endif  // CHROME_BROWSER_CHROMEOS_STATUS_NETWORK_MENU_BUTTON_H_
112