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/options/cellular_config_view.h" | 5 #include "chrome/browser/chromeos/options/cellular_config_view.h" |
6 | 6 |
7 #include "app/l10n_util.h" | 7 #include "app/l10n_util.h" |
8 #include "base/i18n/time_formatting.h" | 8 #include "base/i18n/time_formatting.h" |
9 #include "base/time.h" | 9 #include "base/time.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
(...skipping 22 matching lines...) Expand all Loading... |
33 | 33 |
34 int64 purchased_data; | 34 int64 purchased_data; |
35 base::TimeDelta purchased_time; | 35 base::TimeDelta purchased_time; |
36 | 36 |
37 int64 remaining_data; | 37 int64 remaining_data; |
38 base::TimeDelta remaining_time; | 38 base::TimeDelta remaining_time; |
39 }; | 39 }; |
40 | 40 |
41 // TODO(xiyuan): Get real data from libcros when it's ready. | 41 // TODO(xiyuan): Get real data from libcros when it's ready. |
42 // Get plan details at the time being called. | 42 // Get plan details at the time being called. |
43 void GetPlanDetails(const chromeos::CellularNetwork& cellular, | 43 void GetPlanDetails(const chromeos::CellularNetwork* cellular, |
44 PlanDetails* details) { | 44 PlanDetails* details) { |
45 // Free 5M 30day plan. | 45 // Free 5M 30day plan. |
46 details->last_purchase_type = UNKNOWN; | 46 details->last_purchase_type = UNKNOWN; |
47 details->last_purchase_time = base::Time::Now(); | 47 details->last_purchase_time = base::Time::Now(); |
48 details->purchased_data = 5 * 1024 * 1024; | 48 details->purchased_data = 5 * 1024 * 1024; |
49 details->purchased_time = base::TimeDelta::FromDays(30); | 49 details->purchased_time = base::TimeDelta::FromDays(30); |
50 details->remaining_data = 2 * 1024 * 1024; | 50 details->remaining_data = 2 * 1024 * 1024; |
51 details->remaining_time = base::TimeDelta::FromDays(29); | 51 details->remaining_time = base::TimeDelta::FromDays(29); |
52 } | 52 } |
53 | 53 |
54 } // namespace | 54 } // namespace |
55 | 55 |
56 namespace chromeos { | 56 namespace chromeos { |
57 | 57 |
58 CellularConfigView::CellularConfigView(NetworkConfigView* parent, | 58 CellularConfigView::CellularConfigView(NetworkConfigView* parent, |
59 const CellularNetwork& cellular) | 59 const CellularNetwork* cellular) |
60 : parent_(parent), | 60 : parent_(parent), |
61 cellular_(cellular), | 61 cellular_(new CellularNetwork(*cellular)), |
62 purchase_info_(NULL), | 62 purchase_info_(NULL), |
63 purchase_more_button_(NULL), | 63 purchase_more_button_(NULL), |
64 remaining_data_info_(NULL), | 64 remaining_data_info_(NULL), |
65 expiration_info_(NULL), | 65 expiration_info_(NULL), |
66 show_notification_checkbox_(NULL), | 66 show_notification_checkbox_(NULL), |
67 autoconnect_checkbox_(NULL), | 67 autoconnect_checkbox_(NULL), |
68 customer_support_link_(NULL) { | 68 customer_support_link_(NULL) { |
69 Init(); | 69 Init(); |
70 } | 70 } |
71 | 71 |
| 72 CellularConfigView::~CellularConfigView() { |
| 73 } |
| 74 |
72 void CellularConfigView::ButtonPressed(views::Button* button, | 75 void CellularConfigView::ButtonPressed(views::Button* button, |
73 const views::Event& event) { | 76 const views::Event& event) { |
74 if (button == purchase_more_button_) { | 77 if (button == purchase_more_button_) { |
75 // TODO(xiyuan): Purchase more... | 78 // TODO(xiyuan): Purchase more... |
76 } | 79 } |
77 } | 80 } |
78 | 81 |
79 void CellularConfigView::LinkActivated(views::Link* source, int event_flags) { | 82 void CellularConfigView::LinkActivated(views::Link* source, int event_flags) { |
80 if (source == customer_support_link_) { | 83 if (source == customer_support_link_) { |
81 // TODO(xiyuan): Find out where to go. | 84 // TODO(xiyuan): Find out where to go. |
82 } | 85 } |
83 } | 86 } |
84 | 87 |
85 bool CellularConfigView::Save() { | 88 bool CellularConfigView::Save() { |
86 // Save auto-connect here. | 89 // Save auto-connect here. |
87 bool auto_connect = autoconnect_checkbox_->checked(); | 90 bool auto_connect = autoconnect_checkbox_->checked(); |
88 if (auto_connect != cellular_.auto_connect()) { | 91 if (auto_connect != cellular_->auto_connect()) { |
89 cellular_.set_auto_connect(auto_connect); | 92 cellular_->set_auto_connect(auto_connect); |
90 CrosLibrary::Get()->GetNetworkLibrary()->SaveCellularNetwork(cellular_); | 93 CrosLibrary::Get()->GetNetworkLibrary()->SaveCellularNetwork( |
| 94 cellular_.get()); |
91 } | 95 } |
92 return true; | 96 return true; |
93 } | 97 } |
94 | 98 |
95 void CellularConfigView::Init() { | 99 void CellularConfigView::Init() { |
96 views::GridLayout* layout = CreatePanelGridLayout(this); | 100 views::GridLayout* layout = CreatePanelGridLayout(this); |
97 SetLayoutManager(layout); | 101 SetLayoutManager(layout); |
98 | 102 |
99 purchase_info_ = new views::Label(); | 103 purchase_info_ = new views::Label(); |
100 purchase_more_button_ = new views::NativeButton(this, l10n_util::GetString( | 104 purchase_more_button_ = new views::NativeButton(this, l10n_util::GetString( |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
150 | 154 |
151 layout->StartRow(0, kColumnSetId); | 155 layout->StartRow(0, kColumnSetId); |
152 layout->AddView(customer_support_link_, 3, 1, | 156 layout->AddView(customer_support_link_, 3, 1, |
153 views::GridLayout::LEADING, views::GridLayout::TRAILING); | 157 views::GridLayout::LEADING, views::GridLayout::TRAILING); |
154 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); | 158 layout->AddPaddingRow(0, kRelatedControlVerticalSpacing); |
155 | 159 |
156 Update(); | 160 Update(); |
157 } | 161 } |
158 | 162 |
159 void CellularConfigView::Update() { | 163 void CellularConfigView::Update() { |
160 autoconnect_checkbox_->SetChecked(cellular_.auto_connect()); | 164 autoconnect_checkbox_->SetChecked(cellular_->auto_connect()); |
161 | 165 |
162 PlanDetails details; | 166 PlanDetails details; |
163 GetPlanDetails(cellular_, &details); | 167 GetPlanDetails(cellular_.get(), &details); |
164 | 168 |
165 switch (details.last_purchase_type) { | 169 switch (details.last_purchase_type) { |
166 case NO_PURCHASE: | 170 case NO_PURCHASE: |
167 purchase_info_->SetText(l10n_util::GetStringF( | 171 purchase_info_->SetText(l10n_util::GetStringF( |
168 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_RECEIVED_FREE_DATA, | 172 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_RECEIVED_FREE_DATA, |
169 UTF16ToWide(FormatBytes(details.purchased_data, | 173 UTF16ToWide(FormatBytes(details.purchased_data, |
170 GetByteDisplayUnits(details.purchased_data), | 174 GetByteDisplayUnits(details.purchased_data), |
171 true)), | 175 true)), |
172 base::TimeFormatFriendlyDate(details.last_purchase_time))); | 176 base::TimeFormatFriendlyDate(details.last_purchase_time))); |
173 remaining_data_info_->SetText( | 177 remaining_data_info_->SetText( |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 } | 218 } |
215 default: | 219 default: |
216 NOTREACHED() << "Unknown mobile plan purchase type."; | 220 NOTREACHED() << "Unknown mobile plan purchase type."; |
217 break; | 221 break; |
218 } | 222 } |
219 | 223 |
220 Layout(); | 224 Layout(); |
221 } | 225 } |
222 | 226 |
223 } // namespace chromeos | 227 } // namespace chromeos |
OLD | NEW |