OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/login/network_screen.h" | 5 #include "chrome/browser/chromeos/login/network_screen.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "chrome/browser/chromeos/cros/cros_library.h" | 10 #include "chrome/browser/chromeos/cros/cros_library.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 NetworkScreen::~NetworkScreen() { | 30 NetworkScreen::~NetworkScreen() { |
31 UnsubscribeNetworkNotification(); | 31 UnsubscribeNetworkNotification(); |
32 } | 32 } |
33 | 33 |
34 //////////////////////////////////////////////////////////////////////////////// | 34 //////////////////////////////////////////////////////////////////////////////// |
35 // ComboboxModel implementation: | 35 // ComboboxModel implementation: |
36 | 36 |
37 int NetworkScreen::GetItemCount() { | 37 int NetworkScreen::GetItemCount() { |
38 // Item with index = 0 is either "no networks are available" or | 38 // Item with index = 0 is either "no networks are available" or |
39 // "no selection". | 39 // "no selection". |
40 return static_cast<int>(networks_.GetNetworkCount()) + 1; | 40 return networks_.size() + 1; |
41 } | 41 } |
42 | 42 |
43 std::wstring NetworkScreen::GetItemAt(int index) { | 43 std::wstring NetworkScreen::GetItemAt(int index) { |
44 if (index == 0) { | 44 if (index == 0) { |
45 return networks_.IsEmpty() ? | 45 return networks_.empty() ? |
46 l10n_util::GetString(IDS_STATUSBAR_NO_NETWORKS_MESSAGE) : | 46 l10n_util::GetString(IDS_STATUSBAR_NO_NETWORKS_MESSAGE) : |
47 l10n_util::GetString(IDS_NETWORK_SELECTION_NONE); | 47 l10n_util::GetString(IDS_NETWORK_SELECTION_NONE); |
48 } | 48 } |
49 NetworkList::NetworkItem* network = | 49 NetworkList::NetworkItem* network = |
50 networks_.GetNetworkAt(index - 1); | 50 networks_.GetNetworkAt(index - 1); |
51 return network ? UTF16ToWide(network->label) : std::wstring(); | 51 return network ? UTF16ToWide(network->label) : std::wstring(); |
52 } | 52 } |
53 | 53 |
54 //////////////////////////////////////////////////////////////////////////////// | 54 //////////////////////////////////////////////////////////////////////////////// |
55 // views::Combobox::Listener implementation: | 55 // views::Combobox::Listener implementation: |
56 | 56 |
57 void NetworkScreen::ItemChanged(views::Combobox* sender, | 57 void NetworkScreen::ItemChanged(views::Combobox* sender, |
58 int prev_index, | 58 int prev_index, |
59 int new_index) { | 59 int new_index) { |
60 if (new_index == prev_index || new_index < 0 || prev_index < 0) | 60 if (new_index == prev_index || new_index < 0 || prev_index < 0) |
61 return; | 61 return; |
62 | 62 |
63 // First item is a text, not a network. | 63 // First item is a text, not a network. |
64 if (new_index == 0) { | 64 if (new_index == 0) { |
65 view()->SetSelectedNetworkItem(prev_index); | 65 view()->SetSelectedNetworkItem(prev_index); |
66 return; | 66 return; |
67 } | 67 } |
68 | 68 |
69 if (networks_.IsEmpty()) | 69 if (networks_.empty()) |
70 return; | 70 return; |
71 | 71 |
72 const NetworkList::NetworkItem* network = | 72 const NetworkList::NetworkItem* network = |
73 networks_.GetNetworkAt(new_index - 1); | 73 networks_.GetNetworkAt(new_index - 1); |
74 MessageLoop::current()->PostTask(FROM_HERE, task_factory_.NewRunnableMethod( | 74 MessageLoop::current()->PostTask(FROM_HERE, task_factory_.NewRunnableMethod( |
75 &NetworkScreen::ConnectToNetwork, network->network_type, network->label)); | 75 &NetworkScreen::ConnectToNetwork, network->network_type, network->label)); |
76 } | 76 } |
77 | 77 |
78 /////////////////////////////////////////////////////////////////////////////// | 78 /////////////////////////////////////////////////////////////////////////////// |
79 // views::ButtonListener implementation: | 79 // views::ButtonListener implementation: |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 const string16& id) { | 214 const string16& id) { |
215 int index = networks_.GetNetworkIndexById(type, id); | 215 int index = networks_.GetNetworkIndexById(type, id); |
216 if (index >= 0) { | 216 if (index >= 0) { |
217 view()->SetSelectedNetworkItem(index + 1); | 217 view()->SetSelectedNetworkItem(index + 1); |
218 } else { | 218 } else { |
219 view()->SetSelectedNetworkItem(0); | 219 view()->SetSelectedNetworkItem(0); |
220 } | 220 } |
221 } | 221 } |
222 | 222 |
223 } // namespace chromeos | 223 } // namespace chromeos |
OLD | NEW |