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