network_config_view.cc 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#include "chrome/browser/chromeos/options/network_config_view.h" 6 7#include <algorithm> 8 9#include "app/l10n_util.h" 10#include "base/string_util.h" 11#include "base/utf_string_conversions.h" 12#include "chrome/browser/chromeos/options/wifi_config_view.h" 13#include "grit/chromium_strings.h" 14#include "grit/generated_resources.h" 15#include "grit/locale_settings.h" 16#include "views/grid_layout.h" 17#include "views/standard_layout.h" 18#include "views/widget/widget_gtk.h" 19#include "views/window/window.h" 20 21using views::WidgetGtk; 22 23namespace chromeos { 24 25NetworkConfigView::NetworkConfigView(const WifiNetwork* wifi) 26 : browser_mode_(true), 27 title_(ASCIIToWide(wifi->name())), 28 wificonfig_view_(new WifiConfigView(this, wifi)), 29 delegate_(NULL) { 30} 31 32NetworkConfigView::NetworkConfigView() 33 : browser_mode_(true), 34 title_(UTF16ToWide( 35 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_OTHER_NETWORKS))), 36 wificonfig_view_(new WifiConfigView(this)), 37 delegate_(NULL) { 38} 39 40gfx::NativeWindow NetworkConfigView::GetNativeWindow() const { 41 return GTK_WINDOW(static_cast<WidgetGtk*>(GetWidget())->GetNativeView()); 42} 43 44std::wstring NetworkConfigView::GetDialogButtonLabel( 45 MessageBoxFlags::DialogButton button) const { 46 if (button == MessageBoxFlags::DIALOGBUTTON_OK) 47 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_CONNECT)); 48 return std::wstring(); 49} 50 51bool NetworkConfigView::IsDialogButtonEnabled( 52 MessageBoxFlags::DialogButton button) const { 53 // Disable connect button if cannot login. 54 if (button == MessageBoxFlags::DIALOGBUTTON_OK) 55 return wificonfig_view_->can_login(); 56 return true; 57} 58 59bool NetworkConfigView::Cancel() { 60 if (delegate_) 61 delegate_->OnDialogCancelled(); 62 wificonfig_view_->Cancel(); 63 return true; 64} 65 66bool NetworkConfigView::Accept() { 67 bool result = wificonfig_view_->Login(); 68 if (result && delegate_) 69 delegate_->OnDialogAccepted(); 70 return result; 71} 72 73std::wstring NetworkConfigView::GetWindowTitle() const { 74 return title_; 75} 76 77void NetworkConfigView::Layout() { 78 wificonfig_view_->SetBounds(0, 0, width(), height()); 79} 80 81gfx::Size NetworkConfigView::GetPreferredSize() { 82 // TODO(chocobo): Once UI is finalized, create locale settings. 83 gfx::Size result(views::Window::GetLocalizedContentsSize( 84 IDS_IMPORT_DIALOG_WIDTH_CHARS, 85 IDS_IMPORT_DIALOG_HEIGHT_LINES)); 86 result.set_height(wificonfig_view_->GetPreferredSize().height()); 87 return result; 88} 89 90void NetworkConfigView::ViewHierarchyChanged( 91 bool is_add, views::View* parent, views::View* child) { 92 // Can't init before we're inserted into a Container, because we require 93 // a HWND to parent native child controls to. 94 if (is_add && child == this) 95 AddChildView(wificonfig_view_); 96} 97 98} // namespace chromeos 99