network_config_view.cc revision 72a454cd3513ac24fbdd0e0cb9ad70b86a99b801
1// Copyright (c) 2011 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 "base/string_util.h" 10#include "base/utf_string_conversions.h" 11#include "chrome/browser/chromeos/options/wifi_config_view.h" 12#include "grit/chromium_strings.h" 13#include "grit/generated_resources.h" 14#include "grit/locale_settings.h" 15#include "ui/base/l10n/l10n_util.h" 16#include "views/layout/grid_layout.h" 17#include "views/layout/layout_constants.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 42 GTK_WINDOW(static_cast<const WidgetGtk*>(GetWidget())->GetNativeView()); 43} 44 45std::wstring NetworkConfigView::GetDialogButtonLabel( 46 MessageBoxFlags::DialogButton button) const { 47 if (button == MessageBoxFlags::DIALOGBUTTON_OK) 48 return UTF16ToWide(l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_CONNECT)); 49 return std::wstring(); 50} 51 52bool NetworkConfigView::IsDialogButtonEnabled( 53 MessageBoxFlags::DialogButton button) const { 54 // Disable connect button if cannot login. 55 if (button == MessageBoxFlags::DIALOGBUTTON_OK) 56 return wificonfig_view_->can_login(); 57 return true; 58} 59 60bool NetworkConfigView::Cancel() { 61 if (delegate_) 62 delegate_->OnDialogCancelled(); 63 wificonfig_view_->Cancel(); 64 return true; 65} 66 67bool NetworkConfigView::Accept() { 68 bool result = wificonfig_view_->Login(); 69 if (result && delegate_) 70 delegate_->OnDialogAccepted(); 71 return result; 72} 73 74std::wstring NetworkConfigView::GetWindowTitle() const { 75 return title_; 76} 77 78void NetworkConfigView::Layout() { 79 wificonfig_view_->SetBounds(0, 0, width(), height()); 80} 81 82gfx::Size NetworkConfigView::GetPreferredSize() { 83 // TODO(chocobo): Once UI is finalized, create locale settings. 84 gfx::Size result(views::Window::GetLocalizedContentsSize( 85 IDS_IMPORT_DIALOG_WIDTH_CHARS, 86 IDS_IMPORT_DIALOG_HEIGHT_LINES)); 87 result.set_height(wificonfig_view_->GetPreferredSize().height()); 88 return result; 89} 90 91void NetworkConfigView::ViewHierarchyChanged( 92 bool is_add, views::View* parent, views::View* child) { 93 // Can't init before we're inserted into a Container, because we require 94 // a HWND to parent native child controls to. 95 if (is_add && child == this) 96 AddChildView(wificonfig_view_); 97} 98 99} // namespace chromeos 100