1 #include <Alert.h> 2 #include <image.h> 3 #include <Font.h> 4 #include <Messenger.h> 5 #include <OS.h> 6 #include <Roster.h> 7 #include <Screen.h> 8 #include <ScrollView.h> 9 #include <stdio.h> 10 #include <stdlib.h> 11 12 #include "Network.h" 13 14 #define NETWORK_WINDOW_RIGHT 435 15 #define NETWORK_WINDOW_BOTTOM 309 16 17 #define B_GREY 216,216,216 18 19 int main() 20 { 21 Network app; 22 app.Run(); 23 return B_NO_ERROR; 24 } 25 26 Network::Network() : BApplication("application/x-vnd.OBOS-Network") 27 { 28 fwindow = new NetworkWindow(); 29 fwindow ->Show(); 30 31 fwindow ->Get_Configs_List(); 32 fwindow ->GetEverything(); 33 } 34 35 NetworkWindow::NetworkWindow() : BWindow(BRect(0, 0, NETWORK_WINDOW_RIGHT, NETWORK_WINDOW_BOTTOM),"Network",B_TITLED_WINDOW,B_NOT_ANCHORED_ON_ACTIVATE | B_NOT_ZOOMABLE | B_NOT_RESIZABLE,B_CURRENT_WORKSPACE) 36 { 37 // if(!Network_settings) 38 // { ... 39 BScreen screen; 40 41 BRect screenframe = screen.Frame(); 42 float screenx, screeny; 43 screenx = ((screenframe.right + 1) / 2) - (NETWORK_WINDOW_RIGHT / 2) - 1; 44 screeny = ((screenframe.bottom + 1) / 2) - (NETWORK_WINDOW_BOTTOM / 2) - 1; 45 MoveTo(screenx, screeny); 46 // } 47 // else 48 // { 49 // ... 50 // } 51 52 BRect bounds = Bounds(); 53 fview = new BView(bounds,"View",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); 54 55 frestart = new BButton(BRect(11,274,122,298),"Restart_Networking","Restart Networking",new BMessage(kRestart_Networking_M)); 56 frevert = new BButton(BRect(145,274,220,298),"Revert","Revert",new BMessage(kRevert_M)); 57 fsave = new BButton(BRect(349,274,424,297),"Save","Save",new BMessage(kSave_M)); 58 fsave->MakeDefault(true); 59 fsave->SetEnabled(false); 60 frevert->SetEnabled(false); 61 62 bounds.bottom = Bounds().Height(); 63 bounds.top += 10; 64 bounds.right = Bounds().Width(); 65 ftabview = new BTabView(bounds,"tab_view", B_WIDTH_FROM_WIDEST); 66 67 fidentity = new BTab(); 68 bounds.bottom -= ftabview->TabHeight(); 69 fidentity_view = new BView(bounds,"Identity",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); 70 fservices_view = new BView(bounds,"Services",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); 71 72 bounds.top -= 10; 73 bounds.bottom -= 209; 74 bounds.left += 11; 75 bounds.right -= 12; 76 fnames = new BBox(bounds,"Names",B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_FRAME_EVENTS); 77 78 fdomain = new BTextControl(BRect(15,19,195,50),"Domain_Name","Domain name:",NULL,new BMessage(kSOMETHING_HAS_CHANGED_M)); 79 fhost = new BTextControl(BRect(15,49,195,90),"Host_Name","Host name:",NULL,new BMessage(kSOMETHING_HAS_CHANGED_M)); 80 fprimary_dns = new BTextControl(BRect(209,19,399,45),"Primary_DNS","Primary DNS:",NULL,new BMessage(kSOMETHING_HAS_CHANGED_M)); 81 fsecondary_dns = new BTextControl(BRect(209,49,399,90),"Secondary_DNS","Secondary DNS:",NULL,new BMessage(kSOMETHING_HAS_CHANGED_M)); 82 83 bounds.top = bounds.bottom + 12; 84 bounds.bottom = 208; 85 finterfaces = new BBox(bounds,"Network_Interfaces",B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_FRAME_EVENTS); 86 87 fsettings = new BButton(BRect(325,16,400,37),"Settings","Settings...",new BMessage(kSettings_M)); 88 fclear = new BButton(BRect(325,45,400,67),"Clear","Clear",new BMessage(kClear_M)); 89 fcustom = new BButton(BRect(325,83,400,107),"Custom","Custom...",new BMessage(kCustom_M)); 90 //fsettings ->SetEnabled(false); 91 //fclear ->SetEnabled(false); 92 93 bounds = finterfaces->Bounds(); 94 bounds.InsetBy(20,20); 95 bounds.top ++; 96 bounds.bottom += 6; 97 bounds.right -= 94; 98 bounds.left -= 5; 99 finterfaces_list = new NetListView(bounds,"Interfaces_List"); 100 BScrollView *interfaces_scroller = new BScrollView("Interfaces_Scroller",finterfaces_list, B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, 0, 1, B_FANCY_BORDER); 101 102 fservices = new BTab(); 103 fftp_server = new BCheckBox(BRect(10,20,120,40),"FTP_Server","FTP Server",new BMessage(kSOMETHING_HAS_CHANGED_M)); 104 ftelnet_server = new BCheckBox(BRect(10,50,120,70),"Telnet_Server","Telnet Server",new BMessage(kSOMETHING_HAS_CHANGED_M)); 105 fapple_talk = new BCheckBox(BRect(10,110,120,130),"Apple_Talk","Apple Talk",new BMessage(kSOMETHING_HAS_CHANGED_M)); 106 fip_forwarding = new BCheckBox(BRect(10,140,120,160),"IP_Forwarding","IP Forwarding",new BMessage(kSOMETHING_HAS_CHANGED_M)); 107 flogin_info = new BButton(BRect(10,80,120,100),"Login_Info","Login Info...",new BMessage(kLogin_Info_M)); 108 109 fconfigurations = new BBox(BRect(200,10,460,210),"Configurations",B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_FRAME_EVENTS); 110 111 bounds = fconfigurations->Bounds(); 112 bounds.InsetBy(20,20); 113 bounds.right -= 80; 114 fconfigurations_list = new NetListView(bounds,"Configurations_List"); 115 BScrollView *configurations_scroller = new BScrollView("Configurations_Scroller",fconfigurations_list); 116 117 fbackup = new BButton(BRect(170,17,250,37),"Backup","Backup",new BMessage(kBackup_M)); 118 frestore = new BButton(BRect(170,47,250,67),"Restore","Restore",new BMessage(kRestore_M)); 119 fremove = new BButton(BRect(170,87,250,107),"Delete","Delete",new BMessage(kDelete_M)); 120 frestore->SetEnabled(false); 121 fremove->SetEnabled(false); 122 123 BBox *hr = new BBox(BRect(1,261,Bounds().Width()-1,262), "horizontal_rule"); 124 BBox *vr = new BBox(BRect(133, 274, 134, 299), "vertical_rule"); 125 126 fdomain->SetDivider(70); 127 fdomain->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); 128 fhost->SetDivider(70); 129 fhost->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); 130 fprimary_dns->SetDivider(80); 131 fprimary_dns->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); 132 fsecondary_dns->SetDivider(80); 133 fsecondary_dns->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); 134 135 fnames ->SetLabel("Names"); 136 finterfaces ->SetLabel("Network Interfaces"); 137 fconfigurations ->SetLabel("Configurations"); 138 fidentity_view ->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 139 fservices_view ->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 140 ftabview ->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 141 fview ->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); 142 143 //Casts an AddEverything 144 ftabview ->AddTab(fidentity_view,fidentity); 145 ftabview ->AddTab(fservices_view,fservices); 146 147 fnames ->AddChild(fdomain); 148 fnames ->AddChild(fhost); 149 fnames ->AddChild(fprimary_dns); 150 fnames ->AddChild(fsecondary_dns); 151 finterfaces ->AddChild(interfaces_scroller); 152 finterfaces ->AddChild(fsettings); 153 finterfaces ->AddChild(fclear); 154 finterfaces ->AddChild(fcustom); 155 fidentity_view ->AddChild(fnames); 156 fidentity_view ->AddChild(finterfaces); 157 fservices_view ->AddChild(fftp_server); 158 fservices_view ->AddChild(ftelnet_server); 159 fservices_view ->AddChild(flogin_info); 160 fservices_view ->AddChild(fapple_talk); 161 fservices_view ->AddChild(fip_forwarding); 162 fservices_view ->AddChild(fconfigurations); 163 fconfigurations ->AddChild(configurations_scroller); 164 fconfigurations ->AddChild(fbackup); 165 fconfigurations ->AddChild(frestore); 166 fconfigurations ->AddChild(fremove); 167 fview ->AddChild(ftabview); 168 fview ->AddChild(frestart); 169 fview ->AddChild(frevert); 170 fview ->AddChild(fsave); 171 fview ->AddChild(hr); 172 fview ->AddChild(vr); 173 AddChild(fview); 174 } 175 176 void NetworkWindow::MessageReceived(BMessage *message) 177 { 178 switch (message->what){ 179 case kRestart_Networking_M:{ 180 181 RestartWindow *restartWindow = new RestartWindow(); 182 restartWindow->Show(); 183 184 BMessenger messenger("application/x-vnd.Be-NETS"); 185 if (messenger.IsValid() == true) 186 messenger.SendMessage(B_QUIT_REQUESTED); 187 188 const char **arg_v; 189 int32 argc; 190 thread_id thread; 191 status_t return_value; 192 193 argc = 1; 194 arg_v = (const char **)malloc(sizeof(char *) * (argc + 1)); 195 196 arg_v[0] = strdup("/boot/beos/system/servers/net_server"); 197 arg_v[1] = NULL; 198 199 thread = load_image(argc,arg_v,(const char **)environ); 200 201 while (--argc >= 0) 202 free((void *)arg_v[argc]); 203 free (arg_v); 204 205 return_value = resume_thread(thread); 206 207 restartWindow->Quit(); 208 break; 209 } 210 case kRevert_M:{ 211 GetEverything(); 212 frevert->SetEnabled(false); 213 fsave->SetEnabled(false); 214 break; 215 } 216 case kSave_M:{ 217 BackupWin *bak = new BackupWin(); 218 bak->fparent_window = dynamic_cast <NetworkWindow *> (fview->Window()); 219 bak->Flatten_bak(); 220 bak->Quit(); 221 frevert->SetEnabled(false); 222 fsave->SetEnabled(false); 223 break; 224 } 225 case kSettings_M:{ 226 InterfaceWin *win = new InterfaceWin(); 227 228 win->fparent_window = dynamic_cast <NetworkWindow *> (fview->Window()); 229 230 NetListItem *selection = dynamic_cast <NetListItem *> (finterfaces_list->ItemAt(finterfaces_list->CurrentSelection())); 231 232 if (selection->fENABLED == 1) 233 win->finter_enabled->SetValue(1); 234 if (selection->fDHCP == 1) 235 win->finter_dhcp->SetValue(1); 236 else 237 win->finter_manual->SetValue(1); 238 239 win->finter_name->SetText((selection->fPRETTYNAME).String()); 240 win->finter_ip->SetText((selection->fIPADDRESS).String()); 241 win->finter_mask->SetText((selection->fNETMASK).String()); 242 243 win->fhas_something_changed = false; 244 245 win->finter_ip->SetTarget(win); 246 win->finter_mask->SetTarget(win); 247 win->finter_gateway->SetTarget(win); 248 249 win->Show(); 250 break; 251 } 252 case kClear_M:{ 253 break; 254 } 255 case kCustom_M:{ 256 break; 257 } 258 case kLogin_Info_M:{ 259 LoginInfo *login_info_pop = new LoginInfo(); 260 login_info_pop->fparent_window = dynamic_cast <NetworkWindow *> (fview->Window()); 261 login_info_pop->flogin_info_name->SetText(fusername.String()); 262 login_info_pop->flogin_info_name->MakeFocus(); 263 login_info_pop->Show(); 264 break; 265 } 266 case kBackup_M:{ 267 BackupWin *backup_pop = new BackupWin(); 268 backup_pop->fparent_window = dynamic_cast <NetworkWindow *> (fview->Window()); 269 backup_pop->fbak_name->MakeFocus(); 270 backup_pop->Show(); 271 break; 272 } 273 case kRestore_M:{ 274 BStringItem *string_item = dynamic_cast <BStringItem *> (fconfigurations_list->ItemAt(fconfigurations_list->CurrentSelection())); 275 GetEverything(string_item->Text()); 276 PostMessage(kSOMETHING_HAS_CHANGED_M); 277 break; 278 } 279 case kDelete_M:{ 280 Remove_Config_File(); 281 Get_Configs_List(); 282 fconfigurations_list->SelectionChanged(); 283 break; 284 } 285 case kSOMETHING_HAS_CHANGED_M:{ 286 frevert->SetEnabled(true); 287 fsave->SetEnabled(true); 288 break; 289 } 290 } 291 } 292 293 bool NetworkWindow::QuitRequested() 294 { 295 if (fsave->IsEnabled() == true){ 296 BAlert *alert = new BAlert("Save Info Alert","Save changes before quitting ?","Don't Save","Cancel","Save",B_WIDTH_FROM_WIDEST,B_INFO_ALERT); 297 int32 result = alert->Go(); 298 switch (result){ 299 case 0:{ 300 // Don't Save 301 break; 302 } 303 case 1:{ 304 // Cancel 305 return false; 306 break; 307 } 308 case 2:{ 309 // Save 310 BackupWin *sav = new BackupWin(); 311 sav->fparent_window = dynamic_cast <NetworkWindow *> (fview->Window()); 312 sav->Flatten_bak(); 313 sav->Quit(); 314 break; 315 } 316 default: 317 break; 318 } 319 } 320 be_app->PostMessage(B_QUIT_REQUESTED); 321 return true; 322 } 323 324 LoginInfo::LoginInfo() : BWindow(BRect(410,200,710,335),"Login Info",B_MODAL_WINDOW,B_NOT_ANCHORED_ON_ACTIVATE | B_NOT_RESIZABLE,B_CURRENT_WORKSPACE) 325 { 326 flogin_info_view = new BView(Bounds(),"Login_Info_View",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); 327 328 flogin_info_name = new BTextControl(BRect(10,10,290,30),"User_Name","User Name",NULL,new BMessage()); 329 flogin_info_password = new BTextControl(BRect(10,40,290,60),"Password","Password",NULL,new BMessage()); 330 flogin_info_confirm = new BTextControl(BRect(10,70,290,90),"Confirm Password","Confirm Password",NULL,new BMessage()); 331 flogin_info_cancel = new BButton(BRect(100,100,190,120),"Cancel","Cancel",new BMessage(kLogin_Info_Cancel_M)); 332 flogin_info_done = new BButton(BRect(200,100,290,120),"Done","Done",new BMessage(kLogin_Info_Done_M)); 333 334 flogin_info_done->MakeDefault(true); 335 flogin_info_view->SetViewColor(B_GREY); 336 flogin_info_view->AddChild(flogin_info_name); 337 flogin_info_view->AddChild(flogin_info_password); 338 flogin_info_view->AddChild(flogin_info_confirm); 339 flogin_info_view->AddChild(flogin_info_cancel); 340 flogin_info_view->AddChild(flogin_info_done); 341 342 AddChild(flogin_info_view); 343 } 344 345 void LoginInfo::MessageReceived(BMessage *message) 346 { 347 switch (message->what) 348 { 349 case kLogin_Info_Cancel_M: 350 { 351 Quit(); 352 break; 353 } 354 case kLogin_Info_Done_M: 355 { 356 const char *login_info_name_S = flogin_info_name ->Text(); 357 const char *login_info_password_S = flogin_info_password ->Text(); 358 const char *login_info_confirm_S = flogin_info_confirm ->Text(); 359 360 if (strlen(login_info_name_S) > 0 361 && strlen(login_info_password_S) > 0 362 && strlen(login_info_confirm_S) > 0 ){ 363 if (strcmp(login_info_password_S,login_info_confirm_S) == 0){ 364 fparent_window->flogin_info_S[0] = login_info_name_S; 365 fparent_window->flogin_info_S[1] = login_info_password_S; 366 fparent_window->PostMessage(fparent_window->kSOMETHING_HAS_CHANGED_M); 367 Quit(); 368 } 369 else{ 370 BAlert *alert = new BAlert("Login Info Alert","Youd didn't enter twice the same password","Oups...",NULL,NULL,B_WIDTH_FROM_WIDEST,B_INFO_ALERT); 371 alert->Go(); 372 } 373 374 } 375 else{ 376 BAlert *alert = new BAlert("Login Info Alert","You didn't fill all the fields","Oups...",NULL,NULL,B_WIDTH_FROM_WIDEST,B_INFO_ALERT); 377 alert->Go(); 378 } 379 break; 380 } 381 } 382 } 383 384 BackupWin::BackupWin() : BWindow(BRect(410,200,710,285),"Backup Win",B_MODAL_WINDOW,B_NOT_ANCHORED_ON_ACTIVATE | B_NOT_RESIZABLE,B_CURRENT_WORKSPACE) 385 { 386 fbakview = new BView(Bounds(),"Backup",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); 387 fbak_name = new BTextControl(BRect(10,20,290,40),"Backup As","Backup As:",NULL,new BMessage()); 388 fbak_cancel = new BButton(BRect(100,50,190,70),"Cancel","Cancel",new BMessage(kCancel_bak_M)); 389 fbak_done = new BButton(BRect(200,50,290,70),"Done","Done",new BMessage(kFlatten_bak_M)); 390 391 fbakview->SetViewColor(B_GREY); 392 fbak_done->MakeDefault(true); 393 394 fbakview->AddChild(fbak_name); 395 fbakview->AddChild(fbak_cancel); 396 fbakview->AddChild(fbak_done); 397 398 AddChild(fbakview); 399 } 400 401 void BackupWin::MessageReceived(BMessage *message) 402 { 403 switch (message->what){ 404 case kCancel_bak_M:{ 405 Quit(); 406 break; 407 } 408 case kFlatten_bak_M:{ 409 const char *bak_name_S = fbak_name->Text(); 410 411 if (strlen(bak_name_S) > 0){ 412 Flatten_bak(bak_name_S); //Writes the new config file 413 fparent_window->Lock(); 414 fparent_window->Get_Configs_List(); //Update the list 415 fparent_window->fconfigurations_list->SelectionChanged(); //Update the buttons 416 fparent_window->Unlock(); 417 Quit(); 418 } 419 else{ 420 BAlert *alert = new BAlert("Backup Info Alert","You must sprcify a name","Oups...",NULL,NULL,B_WIDTH_FROM_WIDEST,B_INFO_ALERT); 421 alert->Go(); 422 } 423 break; 424 } 425 } 426 } 427 428 NetListView::NetListView(BRect frame,const char *name) : BListView(frame, name) 429 {} //The NetListView only exists to override the SelectionChanged() function below 430 431 //Buttons are enabled or not depending on the selection in the list 432 //so each time you click in the list, this method is called to update the buttons 433 void NetListView::SelectionChanged(void) 434 { 435 int32 index = CurrentSelection(); 436 437 BView *parent = Parent(); 438 439 if (index >= 0){ 440 if (strcmp(parent->Name(),"Interfaces_Scroller") == 0) //There are 2 lists that are instances of this class, 441 { //so we have to see in which list you are clicking 442 BButton *settings = dynamic_cast <BButton *> ((parent->Parent())->FindView("Settings")); 443 BButton *clear = dynamic_cast <BButton *> ((parent->Parent())->FindView("Clear")); 444 445 settings ->SetEnabled(true); 446 clear ->SetEnabled(true); 447 } 448 else if (strcmp(parent->Name(),"Configurations_Scroller") == 0){ 449 BButton *restore = dynamic_cast <BButton *> ((parent->Parent())->FindView("Restore")); 450 BButton *remove = dynamic_cast <BButton *> ((parent->Parent())->FindView("Delete")); 451 452 restore ->SetEnabled(true); 453 remove ->SetEnabled(true); 454 } 455 } 456 else{ 457 if (strcmp(parent->Name(),"Interfaces_Scroller") == 0) //There are 2 lists that are instances of this class, 458 { //so we have to see in which list you are clicking 459 BButton *settings = dynamic_cast <BButton *> ((parent->Parent())->FindView("Settings")); 460 BButton *clear = dynamic_cast <BButton *> ((parent->Parent())->FindView("Clear")); 461 462 settings ->SetEnabled(false); 463 clear ->SetEnabled(false); 464 } 465 else if (strcmp(parent->Name(),"Configurations_Scroller") == 0){ 466 BButton *restore = dynamic_cast <BButton *> ((parent->Parent())->FindView("Restore")); 467 BButton *remove = dynamic_cast <BButton *> ((parent->Parent())->FindView("Delete")); 468 469 restore ->SetEnabled(false); 470 remove ->SetEnabled(false); 471 } 472 } 473 474 } 475 476 RestartWindow::RestartWindow() : BWindow(BRect(400,300,650,350),"Restart Networking",B_MODAL_WINDOW,B_NOT_ANCHORED_ON_ACTIVATE | B_NOT_RESIZABLE,B_CURRENT_WORKSPACE) 477 { 478 fview = new BView(Bounds(),"Restart_View",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); 479 480 fview->SetViewColor(B_GREY); 481 482 frestarting = new BStringView(BRect(60,5,200,25),"Restarting_Text_1","Restarting Networking"); 483 fwhatshappening = new BStringView(BRect(60,30,200,50),"Restarting_Text_2","Please Wait..."); 484 485 BFont font(be_bold_font); 486 487 frestarting->SetFont(&font); 488 fwhatshappening->SetFont(&font); 489 490 fview->AddChild(frestarting); 491 fview->AddChild(fwhatshappening); 492 493 AddChild(fview); 494 } 495 496 NetListItem::NetListItem(const char *text) : BStringItem(text) 497 {} 498 499 InterfaceWin::InterfaceWin():BWindow(BRect(410,350,720,600),"Interface Win",B_MODAL_WINDOW,B_NOT_ANCHORED_ON_ACTIVATE | B_NOT_RESIZABLE,B_CURRENT_WORKSPACE) 500 { 501 BRect rect = Bounds(); 502 finterview = new BView(rect,"Interface_View",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); 503 finter_name = new BStringView(BRect(10,10,290,20),"Interface_Name",NULL); 504 finter_enabled= new BCheckBox(BRect(10,30,190,40),"Enabled","Interface enabled",new BMessage(kSOMETHING_HAS_CHANGED)); 505 finter_dhcp = new BRadioButton(BRect(10,50,290,60),"DHCP","Obtain settings automatically (DHCP)",new BMessage(kSOMETHING_HAS_CHANGED)); 506 finter_manual = new BRadioButton(BRect(10,70,290,80),"Manual","Specify settings",new BMessage(kSOMETHING_HAS_CHANGED)); 507 finter_config = new BButton(BRect(10,220,100,230),"Config","Config...",new BMessage()); 508 finter_cancel = new BButton(BRect(145,220,215,230),"Cancel","Cancel",new BMessage(kCancel_inter_M)); 509 finter_done = new BButton(BRect(225,220,295,230),"Done","Done",new BMessage(kDone_inter_M)); 510 rect.InsetBy(5,5); 511 rect.top+=95; 512 rect.bottom-=35; 513 finter_box = new BBox(rect,"IP",B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_FRAME_EVENTS); 514 finter_ip = new BTextControl(BRect(10,15,290,35),"IP address","IP address:",NULL,new BMessage(kSOMETHING_HAS_CHANGED)); 515 finter_mask = new BTextControl(BRect(10,45,290,65),"Subnet mask","Subnet mask:",NULL,new BMessage(kSOMETHING_HAS_CHANGED)); 516 finter_gateway = new BTextControl(BRect(10,75,290,95),"Gateway","Gateway:",NULL,new BMessage(kSOMETHING_HAS_CHANGED)); 517 518 finterview->SetViewColor(B_GREY); 519 finter_done->MakeDefault(true); 520 521 finter_box->AddChild(finter_ip); 522 finter_box->AddChild(finter_mask); 523 finter_box->AddChild(finter_gateway); 524 525 finterview->AddChild(finter_name); 526 finterview->AddChild(finter_enabled); 527 finterview->AddChild(finter_dhcp); 528 finterview->AddChild(finter_manual); 529 finterview->AddChild(finter_config); 530 finterview->AddChild(finter_cancel); 531 finterview->AddChild(finter_done); 532 finterview->AddChild(finter_box); 533 534 AddChild(finterview); 535 } 536 537 void InterfaceWin::MessageReceived(BMessage *message) 538 { 539 switch(message->what){ 540 case kCancel_inter_M:{ 541 Quit(); 542 break; 543 } 544 case kDone_inter_M:{ 545 if (fhas_something_changed == true){ 546 fparent_window->PostMessage(fparent_window->kSOMETHING_HAS_CHANGED_M); 547 548 NetListItem *item = dynamic_cast <NetListItem *> (fparent_window->finterfaces_list->ItemAt(fparent_window->finterfaces_list->CurrentSelection())); 549 550 item->fIPADDRESS = finter_ip->Text(); 551 item->fNETMASK = finter_mask->Text(); 552 553 if (finter_enabled->Value() == 0) 554 item->fENABLED = 0; 555 else 556 item->fENABLED = 1; 557 558 if (finter_dhcp->Value() == 0) 559 item->fDHCP = 0; 560 else 561 item->fDHCP = 1; 562 } 563 Quit(); 564 break; 565 } 566 case kSOMETHING_HAS_CHANGED:{ 567 fhas_something_changed = true; 568 break; 569 } 570 } 571 } 572 573 574