summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/options/network_config_view.cc
blob: c35be1aa095e15d84adba39f4147862f1abe136a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "chrome/browser/chromeos/options/network_config_view.h"

#include <algorithm>

#include "app/l10n_util.h"
#include "base/string_util.h"
#include "base/utf_string_conversions.h"
#include "chrome/browser/chromeos/options/wifi_config_view.h"
#include "grit/chromium_strings.h"
#include "grit/generated_resources.h"
#include "grit/locale_settings.h"
#include "views/grid_layout.h"
#include "views/standard_layout.h"
#include "views/widget/widget_gtk.h"
#include "views/window/window.h"

using views::WidgetGtk;

namespace chromeos {

NetworkConfigView::NetworkConfigView(const WifiNetwork* wifi)
    : browser_mode_(true),
      title_(ASCIIToWide(wifi->name())),
      wificonfig_view_(new WifiConfigView(this, wifi)),
      delegate_(NULL) {
}

NetworkConfigView::NetworkConfigView()
    : browser_mode_(true),
      title_(l10n_util::GetString(IDS_OPTIONS_SETTINGS_OTHER_NETWORKS)),
      wificonfig_view_(new WifiConfigView(this)),
      delegate_(NULL) {
}

gfx::NativeWindow NetworkConfigView::GetNativeWindow() const {
  return GTK_WINDOW(static_cast<WidgetGtk*>(GetWidget())->GetNativeView());
}

std::wstring NetworkConfigView::GetDialogButtonLabel(
    MessageBoxFlags::DialogButton button) const {
  if (button == MessageBoxFlags::DIALOGBUTTON_OK)
    return l10n_util::GetString(IDS_OPTIONS_SETTINGS_CONNECT);
  return std::wstring();
}

bool NetworkConfigView::IsDialogButtonEnabled(
    MessageBoxFlags::DialogButton button) const {
  // Disable connect button if cannot login.
  if (button == MessageBoxFlags::DIALOGBUTTON_OK)
    return wificonfig_view_->can_login();
  return true;
}

bool NetworkConfigView::Cancel() {
  if (delegate_)
    delegate_->OnDialogCancelled();
  wificonfig_view_->Cancel();
  return true;
}

bool NetworkConfigView::Accept() {
  bool result = wificonfig_view_->Login();
  if (result && delegate_)
    delegate_->OnDialogAccepted();
  return result;
}

std::wstring NetworkConfigView::GetWindowTitle() const {
  return title_;
}

void NetworkConfigView::Layout() {
  wificonfig_view_->SetBounds(0, 0, width(), height());
}

gfx::Size NetworkConfigView::GetPreferredSize() {
  // TODO(chocobo): Once UI is finalized, create locale settings.
  gfx::Size result(views::Window::GetLocalizedContentsSize(
      IDS_IMPORT_DIALOG_WIDTH_CHARS,
      IDS_IMPORT_DIALOG_HEIGHT_LINES));
  result.set_height(wificonfig_view_->GetPreferredSize().height());
  return result;
}

void NetworkConfigView::ViewHierarchyChanged(
    bool is_add, views::View* parent, views::View* child) {
  // Can't init before we're inserted into a Container, because we require
  // a HWND to parent native child controls to.
  if (is_add && child == this)
    AddChildView(wificonfig_view_);
}

}  // namespace chromeos