wifi_config_view.h revision 3f50c38dc070f4bb515c1b64450dae14f316474e
1// Copyright (c) 2010 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_OPTIONS_WIFI_CONFIG_VIEW_H_
6#define CHROME_BROWSER_CHROMEOS_OPTIONS_WIFI_CONFIG_VIEW_H_
7#pragma once
8
9#include <string>
10
11#include "app/combobox_model.h"
12#include "base/gtest_prod_util.h"
13#include "base/string16.h"
14#include "chrome/browser/chromeos/cros/network_library.h"
15#include "chrome/browser/shell_dialogs.h"
16#include "views/controls/button/button.h"
17#include "views/controls/button/checkbox.h"
18#include "views/controls/button/image_button.h"
19#include "views/controls/button/native_button.h"
20#include "views/controls/combobox/combobox.h"
21#include "views/controls/textfield/textfield.h"
22#include "views/view.h"
23
24class FilePath;
25
26namespace chromeos {
27
28class NetworkConfigView;
29
30// A dialog box for showing a password textfield.
31class WifiConfigView : public views::View,
32                       public views::Textfield::Controller,
33                       public views::ButtonListener,
34                       public views::Combobox::Listener,
35                       public SelectFileDialog::Listener {
36 public:
37  WifiConfigView(NetworkConfigView* parent, const WifiNetwork* wifi);
38  explicit WifiConfigView(NetworkConfigView* parent);
39  virtual ~WifiConfigView();
40
41  // views::Textfield::Controller methods.
42  virtual void ContentsChanged(views::Textfield* sender,
43                               const string16& new_contents);
44  virtual bool HandleKeyEvent(views::Textfield* sender,
45                              const views::KeyEvent& key_event);
46
47  // views::ButtonListener
48  virtual void ButtonPressed(views::Button* sender, const views::Event& event);
49
50  // views::Combobox::Listener
51  virtual void ItemChanged(views::Combobox* combo_box,
52                           int prev_index, int new_index);
53
54  // SelectFileDialog::Listener implementation.
55  virtual void FileSelected(const FilePath& path, int index, void* params);
56
57  // Login to network. Returns false if the dialog should remain open.
58  virtual bool Login();
59
60  // Save network information.
61  virtual bool Save();
62
63  // Cancel the dialog.
64  virtual void Cancel();
65
66  // Get the typed in ssid.
67  const std::string GetSSID() const;
68  // Get the typed in passphrase.
69  const std::string GetPassphrase() const;
70
71  // Returns true if the textfields are non-empty and we can login.
72  bool can_login() const { return can_login_; }
73
74 private:
75  class SecurityComboboxModel : public ComboboxModel {
76   public:
77    SecurityComboboxModel() {}
78    virtual ~SecurityComboboxModel() {}
79    virtual int GetItemCount();
80    virtual string16 GetItemAt(int index);
81   private:
82    DISALLOW_COPY_AND_ASSIGN(SecurityComboboxModel);
83  };
84
85  // Initializes UI.
86  void Init();
87
88  // Updates state of the Login button.
89  void UpdateCanLogin();
90
91  // Updates the error text label.
92  void UpdateErrorLabel(bool failed);
93
94  NetworkConfigView* parent_;
95
96  // Whether or not we can log in. This gets recalculated when textfield
97  // contents change.
98  bool can_login_;
99
100  scoped_ptr<WifiNetwork> wifi_;
101
102  views::Textfield* ssid_textfield_;
103  views::Textfield* identity_textfield_;
104  views::NativeButton* certificate_browse_button_;
105  scoped_refptr<SelectFileDialog> select_file_dialog_;
106  std::string certificate_path_;
107  views::Combobox* security_combobox_;
108  views::Textfield* passphrase_textfield_;
109  views::ImageButton* passphrase_visible_button_;
110  views::Label* error_label_;
111
112  DISALLOW_COPY_AND_ASSIGN(WifiConfigView);
113};
114
115}  // namespace chromeos
116
117#endif  // CHROME_BROWSER_CHROMEOS_OPTIONS_WIFI_CONFIG_VIEW_H_
118