summaryrefslogtreecommitdiffstats
path: root/chrome/browser
diff options
context:
space:
mode:
authorxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-26 21:39:59 +0000
committerxiyuan@chromium.org <xiyuan@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-08-26 21:39:59 +0000
commit3e21c5f17af3e104a40356321843f1cf8aa1428d (patch)
tree32407c743a976bf354e40006a10620fbd41b079e /chrome/browser
parent38caec4325a29e257bfac9ac1d55d305b82380fe (diff)
downloadchromium_src-3e21c5f17af3e104a40356321843f1cf8aa1428d.zip
chromium_src-3e21c5f17af3e104a40356321843f1cf8aa1428d.tar.gz
chromium_src-3e21c5f17af3e104a40356321843f1cf8aa1428d.tar.bz2
Implement 3G network settings dialog per chromium-os:5609.
BUG=chromium-os:5609 TEST=none. Hold until flipflam supports are implemented. Review URL: http://codereview.chromium.org/3112035 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@57584 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser')
-rw-r--r--chrome/browser/chromeos/options/cellular_config_view.cc181
-rw-r--r--chrome/browser/chromeos/options/cellular_config_view.h28
-rw-r--r--chrome/browser/chromeos/options/network_config_view.cc2
3 files changed, 192 insertions, 19 deletions
diff --git a/chrome/browser/chromeos/options/cellular_config_view.cc b/chrome/browser/chromeos/options/cellular_config_view.cc
index db3d837..6807bff 100644
--- a/chrome/browser/chromeos/options/cellular_config_view.cc
+++ b/chrome/browser/chromeos/options/cellular_config_view.cc
@@ -5,24 +5,82 @@
#include "chrome/browser/chromeos/options/cellular_config_view.h"
#include "app/l10n_util.h"
+#include "base/i18n/time_formatting.h"
+#include "base/time.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/chromeos/cros/cros_library.h"
#include "chrome/browser/chromeos/options/network_config_view.h"
+#include "chrome/common/time_format.h"
#include "grit/generated_resources.h"
+#include "views/controls/button/checkbox.h"
+#include "views/controls/button/native_button.h"
#include "views/controls/label.h"
#include "views/grid_layout.h"
#include "views/standard_layout.h"
+namespace {
+
+enum PlanPurchaseType {
+ NO_PURCHASE, // No purchase happened.
+ PURCHASED_DATA, // Purchased limited data plan.
+ PURCHASED_UNLIMITED_DATA // Purchased unlimited data plan.
+};
+
+struct PlanDetails {
+ PlanPurchaseType last_purchase_type;
+ base::Time last_purchase_time;
+
+ int64 purchased_data;
+ base::TimeDelta purchased_time;
+
+ int64 remaining_data;
+ base::TimeDelta remaining_time;
+};
+
+// TODO(xiyuan): Get real data from libcros when it's ready.
+// Get plan details at the time being called.
+void GetPlanDetails(const chromeos::CellularNetwork& cellular,
+ PlanDetails* details) {
+ // Free 5M 30day plan.
+ details->last_purchase_type = NO_PURCHASE;
+ details->last_purchase_time = base::Time::Now();
+ details->purchased_data = 5 * 1024 * 1024;
+ details->purchased_time = base::TimeDelta::FromDays(30);
+ details->remaining_data = 2 * 1024 * 1024;
+ details->remaining_time = base::TimeDelta::FromDays(29);
+}
+
+} // namespace
+
namespace chromeos {
CellularConfigView::CellularConfigView(NetworkConfigView* parent,
const CellularNetwork& cellular)
: parent_(parent),
cellular_(cellular),
- autoconnect_checkbox_(NULL) {
+ purchase_info_(NULL),
+ purchase_more_button_(NULL),
+ remaining_data_info_(NULL),
+ expiration_info_(NULL),
+ show_notification_checkbox_(NULL),
+ autoconnect_checkbox_(NULL),
+ customer_support_link_(NULL) {
Init();
}
+void CellularConfigView::ButtonPressed(views::Button* button,
+ const views::Event& event) {
+ if (button == purchase_more_button_) {
+ // TODO(xiyuan): Purchase more...
+ }
+}
+
+void CellularConfigView::LinkActivated(views::Link* source, int event_flags) {
+ if (source == customer_support_link_) {
+ // TODO(xiyuan): Find out where to go.
+ }
+}
+
bool CellularConfigView::Save() {
// Save auto-connect here.
bool auto_connect = autoconnect_checkbox_->checked();
@@ -37,28 +95,119 @@ void CellularConfigView::Init() {
views::GridLayout* layout = CreatePanelGridLayout(this);
SetLayoutManager(layout);
- int column_view_set_id = 0;
- views::ColumnSet* column_set = layout->AddColumnSet(column_view_set_id);
+ purchase_info_ = new views::Label();
+ purchase_more_button_ = new views::NativeButton(this, l10n_util::GetString(
+ IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PURCHASE_MORE));
+ views::Label* data_remaining_label = new views::Label(l10n_util::GetString(
+ IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_DATA_REMAINING));
+ remaining_data_info_ = new views::Label();
+ views::Label* expires_label = new views::Label(l10n_util::GetString(
+ IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_EXPIRES));
+ expiration_info_ = new views::Label();
+ show_notification_checkbox_ = new views::Checkbox(l10n_util::GetString(
+ IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SHOW_MOBILE_NOTIFICATION));
+ autoconnect_checkbox_ = new views::Checkbox(l10n_util::GetString(
+ IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_AUTO_CONNECT));
+ customer_support_link_ = new views::Link(l10n_util::GetString(
+ IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CUSTOMER_SUPPORT));
+
+ data_remaining_label->SetFont(data_remaining_label->font().DeriveFont(0,
+ gfx::Font::BOLD));
+ expires_label->SetFont(data_remaining_label->font());
+
+ const int kColumnSetId = 0;
+ views::ColumnSet* column_set = layout->AddColumnSet(kColumnSetId);
+ column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,
+ views::GridLayout::USE_PREF, 0, 0);
column_set->AddColumn(views::GridLayout::LEADING, views::GridLayout::FILL, 1,
views::GridLayout::USE_PREF, 0, 0);
- column_set->AddColumn(views::GridLayout::FILL, views::GridLayout::FILL, 1,
+ column_set->AddColumn(views::GridLayout::TRAILING, views::GridLayout::FILL, 1,
views::GridLayout::USE_PREF, 0, 0);
- layout->StartRow(0, column_view_set_id);
- layout->AddView(new views::Label(l10n_util::GetString(
- IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_ID)));
- views::Label* label = new views::Label(ASCIIToWide(cellular_.name()));
- label->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
- layout->AddView(label);
+ layout->StartRow(0, kColumnSetId);
+ layout->AddView(purchase_info_, 2, 1);
+ layout->AddView(purchase_more_button_);
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
- // Autoconnect checkbox
- autoconnect_checkbox_ = new views::Checkbox(
- l10n_util::GetString(IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_AUTO_CONNECT));
- autoconnect_checkbox_->SetChecked(cellular_.auto_connect());
- layout->StartRow(0, column_view_set_id);
- layout->AddView(autoconnect_checkbox_, 2, 1);
+ layout->StartRow(0, kColumnSetId);
+ layout->AddView(data_remaining_label);
+ layout->AddView(remaining_data_info_, 2, 1);
+ layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
+
+ layout->StartRow(0, kColumnSetId);
+ layout->AddView(expires_label);
+ layout->AddView(expiration_info_, 2, 1);
+ layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
+
+ layout->StartRow(0, kColumnSetId);
+ layout->AddView(show_notification_checkbox_, 3, 1);
+ layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
+
+ layout->StartRow(0, kColumnSetId);
+ layout->AddView(autoconnect_checkbox_, 3, 1);
+ layout->AddPaddingRow(0, kUnrelatedControlVerticalSpacing);
+
+ layout->StartRow(0, kColumnSetId);
+ layout->AddView(customer_support_link_, 3, 1,
+ views::GridLayout::LEADING, views::GridLayout::TRAILING);
layout->AddPaddingRow(0, kRelatedControlVerticalSpacing);
+
+ Update();
+}
+
+void CellularConfigView::Update() {
+ autoconnect_checkbox_->SetChecked(cellular_.auto_connect());
+
+ PlanDetails details;
+ GetPlanDetails(cellular_, &details);
+
+ switch (details.last_purchase_type) {
+ case NO_PURCHASE:
+ purchase_info_->SetText(l10n_util::GetStringF(
+ IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_RECEIVED_FREE_DATA,
+ UTF16ToWide(FormatBytes(details.purchased_data,
+ GetByteDisplayUnits(details.purchased_data),
+ true)),
+ base::TimeFormatFriendlyDate(details.last_purchase_time)));
+ remaining_data_info_->SetText(
+ UTF16ToWide(FormatBytes(details.remaining_data,
+ GetByteDisplayUnits(details.remaining_data),
+ true)));
+ expiration_info_->SetText(UTF16ToWide(
+ TimeFormat::TimeRemaining(details.remaining_time)));
+ break;
+ case PURCHASED_DATA:
+ purchase_info_->SetText(l10n_util::GetStringF(
+ IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PURCHASE_DATA,
+ UTF16ToWide(FormatBytes(details.purchased_data,
+ GetByteDisplayUnits(details.purchased_data),
+ true)),
+ base::TimeFormatFriendlyDate(details.last_purchase_time)));
+ remaining_data_info_->SetText(
+ UTF16ToWide(FormatBytes(details.remaining_data,
+ GetByteDisplayUnits(details.remaining_data),
+ true)));
+ expiration_info_->SetText(UTF16ToWide(
+ TimeFormat::TimeRemaining(details.remaining_time)));
+ break;
+ case PURCHASED_UNLIMITED_DATA:
+ purchase_info_->SetText(l10n_util::GetStringF(
+ IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PURCHASE_UNLIMITED_DATA,
+ UTF16ToWide(FormatBytes(details.purchased_data,
+ GetByteDisplayUnits(details.purchased_data),
+ true)),
+ base::TimeFormatFriendlyDate(details.last_purchase_time)));
+ remaining_data_info_->SetText(l10n_util::GetString(
+ IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_UNLIMITED));
+ expiration_info_->SetText(UTF16ToWide(
+ TimeFormat::TimeRemaining(details.remaining_time)));
+ break;
+ default:
+ NOTREACHED() << "Unknown mobile plan purchase type.";
+ break;
+ }
+
+ Layout();
}
} // namespace chromeos
diff --git a/chrome/browser/chromeos/options/cellular_config_view.h b/chrome/browser/chromeos/options/cellular_config_view.h
index 7887330..9120c6d 100644
--- a/chrome/browser/chromeos/options/cellular_config_view.h
+++ b/chrome/browser/chromeos/options/cellular_config_view.h
@@ -7,21 +7,36 @@
#pragma once
#include "chrome/browser/chromeos/cros/network_library.h"
-#include "views/controls/button/checkbox.h"
+#include "views/controls/button/button.h"
+#include "views/controls/link.h"
#include "views/view.h"
+namespace views {
+class Checkbox;
+class Label;
+class NativeButton;
+} // namespace views
+
namespace chromeos {
class NetworkConfigView;
// A dialog box for showing a password textfield.
-class CellularConfigView : public views::View {
+class CellularConfigView : public views::View,
+ public views::ButtonListener,
+ public views::LinkController {
public:
CellularConfigView(NetworkConfigView* parent,
const CellularNetwork& cellular);
explicit CellularConfigView(NetworkConfigView* parent);
virtual ~CellularConfigView() {}
+ // views::ButtonListener implementation.
+ virtual void ButtonPressed(views::Button* button, const views::Event& event);
+
+ // views::LinkController implementation.
+ virtual void LinkActivated(views::Link* source, int event_flags);
+
// Save network information.
virtual bool Save();
@@ -30,11 +45,20 @@ class CellularConfigView : public views::View {
// Initializes UI.
void Init();
+ // Updates UI.
+ void Update();
+
NetworkConfigView* parent_;
CellularNetwork cellular_;
+ views::Label* purchase_info_;
+ views::NativeButton* purchase_more_button_;
+ views::Label* remaining_data_info_;
+ views::Label* expiration_info_;
+ views::Checkbox* show_notification_checkbox_;
views::Checkbox* autoconnect_checkbox_;
+ views::Link* customer_support_link_;
DISALLOW_COPY_AND_ASSIGN(CellularConfigView);
};
diff --git a/chrome/browser/chromeos/options/network_config_view.cc b/chrome/browser/chromeos/options/network_config_view.cc
index 9919433..d18006e 100644
--- a/chrome/browser/chromeos/options/network_config_view.cc
+++ b/chrome/browser/chromeos/options/network_config_view.cc
@@ -179,7 +179,7 @@ void NetworkConfigView::Init() {
if (flags_ & FLAG_CELLULAR) {
cellularconfig_view_ = new CellularConfigView(this, cellular_);
tabs_->AddTab(
- l10n_util::GetString(IDS_OPTIONS_SETTINGS_SECTION_TITLE_NETWORK_CONFIG),
+ l10n_util::GetString(IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USAGE),
cellularconfig_view_);
}
if (flags_ & FLAG_WIFI) {