• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #ifndef ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_LIST_DETAILED_VIEW_H
6 #define ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_LIST_DETAILED_VIEW_H
7 
8 #include <map>
9 #include <string>
10 #include <vector>
11 
12 #include "ash/system/chromeos/network/network_detailed_view.h"
13 #include "ash/system/chromeos/network/network_icon.h"
14 #include "ash/system/chromeos/network/network_icon_animation_observer.h"
15 #include "ash/system/tray/view_click_listener.h"
16 #include "ash/system/user/login_status.h"
17 #include "base/memory/scoped_vector.h"
18 #include "base/memory/weak_ptr.h"
19 #include "ui/views/controls/button/button.h"
20 
21 namespace chromeos {
22 class NetworkTypePattern;
23 }
24 
25 namespace views {
26 class BubbleDelegateView;
27 }
28 
29 namespace ash {
30 
31 class SystemTrayItem;
32 
33 namespace internal {
34 
35 class HoverHighlightView;
36 class TrayPopupLabelButton;
37 
38 namespace tray {
39 
40 struct NetworkInfo;
41 
42 class NetworkStateListDetailedView
43     : public NetworkDetailedView,
44       public views::ButtonListener,
45       public ViewClickListener,
46       public network_icon::AnimationObserver,
47       public base::SupportsWeakPtr<NetworkStateListDetailedView> {
48  public:
49   enum ListType {
50     LIST_TYPE_NETWORK,
51     LIST_TYPE_DEBUG_PREFERRED,
52     LIST_TYPE_VPN
53   };
54 
55   NetworkStateListDetailedView(SystemTrayItem* owner,
56                                ListType list_type,
57                                user::LoginStatus login);
58   virtual ~NetworkStateListDetailedView();
59 
60   // Overridden from NetworkDetailedView:
61   virtual void Init() OVERRIDE;
62   virtual DetailedViewType GetViewType() const OVERRIDE;
63   virtual void ManagerChanged() OVERRIDE;
64   virtual void NetworkListChanged() OVERRIDE;
65   virtual void NetworkServiceChanged(
66       const chromeos::NetworkState* network) OVERRIDE;
67 
68   // network_icon::AnimationObserver overrides
69   virtual void NetworkIconChanged() OVERRIDE;
70 
71  protected:
72   // Overridden from ButtonListener.
73   virtual void ButtonPressed(views::Button* sender,
74                              const ui::Event& event) OVERRIDE;
75 
76   // Overridden from ViewClickListener.
77   virtual void OnViewClicked(views::View* sender) OVERRIDE;
78 
79  private:
80   class InfoBubble;
81 
82   typedef std::map<views::View*, std::string> NetworkMap;
83   typedef std::map<std::string, HoverHighlightView*> ServicePathMap;
84 
85   // Create UI components.
86   void CreateHeaderEntry();
87   void CreateHeaderButtons();
88   void CreateNetworkExtra();
89 
90   // Update UI components.
91   void UpdateHeaderButtons();
92   void UpdateTechnologyButton(TrayPopupHeaderButton* button,
93                               const chromeos::NetworkTypePattern& technology);
94 
95   void UpdateNetworks(
96       const chromeos::NetworkStateHandler::NetworkStateList& networks);
97   void UpdatePreferred(
98       const chromeos::NetworkStateHandler::FavoriteStateList& favorites);
99   void UpdateNetworkList();
100   bool CreateOrUpdateInfoLabel(
101       int index, const base::string16& text, views::Label** label);
102   bool UpdateNetworkChild(int index, const NetworkInfo* info);
103   bool OrderChild(views::View* view, int index);
104   bool UpdateNetworkListEntries(std::set<std::string>* new_service_paths);
105   void UpdateNetworkExtra();
106 
107   // Adds a settings entry when logged in, and an entry for changing proxy
108   // settings otherwise.
109   void CreateSettingsEntry();
110 
111   // Create and manage the network info bubble.
112   void ToggleInfoBubble();
113   bool ResetInfoBubble();
114   void OnInfoBubbleDestroyed();
115   views::View* CreateNetworkInfoView();
116 
117   // Periodically request a network scan.
118   void CallRequestScan();
119 
120   // Handle toggile mobile action
121   void ToggleMobile();
122 
123   // Type of list (all networks or vpn)
124   ListType list_type_;
125 
126   // Track login state.
127   user::LoginStatus login_;
128 
129   // A map of child views to their network service path.
130   NetworkMap network_map_;
131 
132   // A map of network service paths to their view.
133   ServicePathMap service_path_map_;
134 
135   // An owned list of network info.
136   ScopedVector<NetworkInfo> network_list_;
137 
138   // Child views.
139   TrayPopupHeaderButton* info_icon_;
140   TrayPopupHeaderButton* button_wifi_;
141   TrayPopupHeaderButton* button_mobile_;
142   TrayPopupLabelButton* other_wifi_;
143   TrayPopupLabelButton* turn_on_wifi_;
144   TrayPopupLabelButton* other_mobile_;
145   TrayPopupLabelButton* other_vpn_;
146   TrayPopupLabelButton* toggle_debug_preferred_networks_;
147   TrayPopupLabelButton* settings_;
148   TrayPopupLabelButton* proxy_settings_;
149   views::Label* scanning_view_;
150   views::Label* no_wifi_networks_view_;
151   views::Label* no_cellular_networks_view_;
152 
153   // A small bubble for displaying network info.
154   views::BubbleDelegateView* info_bubble_;
155 
156   DISALLOW_COPY_AND_ASSIGN(NetworkStateListDetailedView);
157 };
158 
159 }  // namespace tray
160 }  // namespace internal
161 }  // namespace ash
162 
163 #endif  // ASH_SYSTEM_CHROMEOS_NETWORK_NETWORK_STATE_LIST_DETAILED_VIEW
164