network_config_view.cc revision 21d179b334e59e9a3bfcaed4c4430bef1bc5759d
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_(l10n_util::GetString(IDS_OPTIONS_SETTINGS_OTHER_NETWORKS)), 35 wificonfig_view_(new WifiConfigView(this)), 36 delegate_(NULL) { 37} 38 39gfx::NativeWindow NetworkConfigView::GetNativeWindow() const { 40 return GTK_WINDOW(static_cast<WidgetGtk*>(GetWidget())->GetNativeView()); 41} 42 43std::wstring NetworkConfigView::GetDialogButtonLabel( 44 MessageBoxFlags::DialogButton button) const { 45 if (button == MessageBoxFlags::DIALOGBUTTON_OK) 46 return l10n_util::GetString(IDS_OPTIONS_SETTINGS_CONNECT); 47 return std::wstring(); 48} 49 50bool NetworkConfigView::IsDialogButtonEnabled( 51 MessageBoxFlags::DialogButton button) const { 52 // Disable connect button if cannot login. 53 if (button == MessageBoxFlags::DIALOGBUTTON_OK) 54 return wificonfig_view_->can_login(); 55 return true; 56} 57 58bool NetworkConfigView::Cancel() { 59 if (delegate_) 60 delegate_->OnDialogCancelled(); 61 wificonfig_view_->Cancel(); 62 return true; 63} 64 65bool NetworkConfigView::Accept() { 66 bool result = wificonfig_view_->Login(); 67 if (result && delegate_) 68 delegate_->OnDialogAccepted(); 69 return result; 70} 71 72std::wstring NetworkConfigView::GetWindowTitle() const { 73 return title_; 74} 75 76void NetworkConfigView::Layout() { 77 wificonfig_view_->SetBounds(0, 0, width(), height()); 78} 79 80gfx::Size NetworkConfigView::GetPreferredSize() { 81 // TODO(chocobo): Once UI is finalized, create locale settings. 82 gfx::Size result(views::Window::GetLocalizedContentsSize( 83 IDS_IMPORT_DIALOG_WIDTH_CHARS, 84 IDS_IMPORT_DIALOG_HEIGHT_LINES)); 85 result.set_height(wificonfig_view_->GetPreferredSize().height()); 86 return result; 87} 88 89void NetworkConfigView::ViewHierarchyChanged( 90 bool is_add, views::View* parent, views::View* child) { 91 // Can't init before we're inserted into a Container, because we require 92 // a HWND to parent native child controls to. 93 if (is_add && child == this) 94 AddChildView(wificonfig_view_); 95} 96 97} // namespace chromeos 98