1/* 2 * Copyright 2004-2011 Haiku, Inc. All rights reserved. 3 * Distributed under the terms of the MIT License. 4 * 5 * Authors: 6 * Alexander von Gluck, kallisti5@unixzen.com 7 */ 8 9 10#include "InterfaceWindow.h" 11 12#include <Application.h> 13 14#include <stdio.h> 15 16 17#undef B_TRANSLATION_CONTEXT 18#define B_TRANSLATION_CONTEXT "NetworkSetupWindow" 19 20 21InterfaceWindow::InterfaceWindow(NetworkSettings* settings) 22 : 23 BWindow(BRect(50, 50, 370, 350), "Interface Settings", 24 B_TITLED_WINDOW_LOOK, B_MODAL_APP_WINDOW_FEEL, 25 B_ASYNCHRONOUS_CONTROLS | B_NOT_ZOOMABLE, 26 B_CURRENT_WORKSPACE) 27{ 28 fNetworkSettings = settings; 29 30 fTabView = new BTabView("settings_tabs"); 31 32 fApplyButton = new BButton("save", B_TRANSLATE("Save"), 33 new BMessage(MSG_IP_SAVE)); 34 35 fRevertButton = new BButton("revert", B_TRANSLATE("Revert"), 36 new BMessage(MSG_IP_REVERT)); 37 38 fTabView->SetResizingMode(B_FOLLOW_ALL); 39 // ensure tab container matches window size 40 41 _PopulateTabs(); 42 43 SetLayout(new BGroupLayout(B_VERTICAL)); 44 45 AddChild(BGroupLayoutBuilder(B_VERTICAL, 10) 46 .Add(fTabView) 47 .AddGroup(B_HORIZONTAL, 5) 48 .AddGlue() 49 .Add(fRevertButton) 50 .Add(fApplyButton) 51 .End() 52 .SetInsets(10, 10, 10, 10) 53 ); 54} 55 56 57InterfaceWindow::~InterfaceWindow() 58{ 59} 60 61 62void 63InterfaceWindow::MessageReceived(BMessage* message) 64{ 65 protocols* supportedFamilies = fNetworkSettings->ProtocolVersions(); 66 67 switch (message->what) { 68 case MSG_IP_REVERT: 69 for (int index = 0; index < MAX_PROTOCOLS; index++) 70 { 71 if (supportedFamilies[index].present) { 72 int inet_id = supportedFamilies[index].inet_id; 73 fTabIPView[inet_id]->RevertFields(); 74 } 75 } 76 break; 77 case MSG_IP_SAVE: 78 for (int index = 0; index < MAX_PROTOCOLS; index++) 79 { 80 if (supportedFamilies[index].present) { 81 int inet_id = supportedFamilies[index].inet_id; 82 fTabIPView[inet_id]->SaveFields(); 83 } 84 } 85 this->Quit(); 86 break; 87 default: 88 BWindow::MessageReceived(message); 89 } 90 91} 92 93 94status_t 95InterfaceWindow::_PopulateTabs() 96{ 97 BRect frame = fTabView->Bounds(); 98 protocols* supportedFamilies = fNetworkSettings->ProtocolVersions(); 99 100 BTab* hardwaretab = new BTab; 101 fTabHardwareView = new InterfaceHardwareView(frame, 102 fNetworkSettings); 103 fTabView->AddTab(fTabHardwareView, hardwaretab); 104 105 if (fNetworkSettings->IsEthernet()) 106 hardwaretab->SetLabel("Wired"); 107 else 108 hardwaretab->SetLabel("Wirless"); 109 110 for (int index = 0; index < MAX_PROTOCOLS; index++) 111 { 112 if (supportedFamilies[index].present) { 113 int inet_id = supportedFamilies[index].inet_id; 114 fTabIPView[inet_id] = new InterfaceAddressView(frame, 115 inet_id, fNetworkSettings); 116 BTab* tab = new BTab; 117 fTabView->AddTab(fTabIPView[inet_id], tab); 118 tab->SetLabel(supportedFamilies[index].name); 119 } 120 } 121 122 return B_OK; 123} 124 125 126bool 127InterfaceWindow::QuitRequested() 128{ 129 return true; 130} 131 132