diff --git a/src/prefs/Jamfile b/src/prefs/Jamfile index f07eee7808..22d0cde96a 100644 --- a/src/prefs/Jamfile +++ b/src/prefs/Jamfile @@ -10,6 +10,7 @@ SubInclude OBOS_TOP src prefs keymap ; SubInclude OBOS_TOP src prefs media ; SubInclude OBOS_TOP src prefs menu ; SubInclude OBOS_TOP src prefs mouse ; +SubInclude OBOS_TOP src prefs network ; SubInclude OBOS_TOP src prefs print ; SubInclude OBOS_TOP src prefs screen ; SubInclude OBOS_TOP src prefs screensaver ; diff --git a/src/prefs/keymap/Jamfile b/src/prefs/keymap/Jamfile index 46a87d2cb3..d11a4c203f 100644 --- a/src/prefs/keymap/Jamfile +++ b/src/prefs/keymap/Jamfile @@ -1,6 +1,6 @@ SubDir OBOS_TOP src prefs keymap ; -#AddResources Keymap : <$(SOURCE_GRIST)>Resource.rsrc ; +AddResources Keymap : Keymap.rsrc ; Preference Keymap : main.cpp diff --git a/src/prefs/network/Jamfile b/src/prefs/network/Jamfile new file mode 100644 index 0000000000..cfda4e7d00 --- /dev/null +++ b/src/prefs/network/Jamfile @@ -0,0 +1,7 @@ +SubDir OBOS_TOP src prefs network ; + +AddResources Network : Network.rsrc ; + +Preference Network : Network.cpp funcs.cpp ; + +LinkSharedOSLibs Appearance : be ; diff --git a/src/prefs/network/Network.cpp b/src/prefs/network/Network.cpp new file mode 100644 index 0000000000..622b5c4e01 --- /dev/null +++ b/src/prefs/network/Network.cpp @@ -0,0 +1,542 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "Network.h" + +#define B_GREY 216,216,216 + +int main() +{ + Network app; + app.Run(); + return B_NO_ERROR; +} + +Network::Network() : BApplication("application/x-vnd.OBOS-Network") +{ + fwindow = new NetworkWindow(); + fwindow ->Show(); + + fwindow ->Get_Configs_List(); + fwindow ->GetEverything(); +} + + +NetworkWindow::NetworkWindow() : BWindow(BRect(100,100,600,420),"Network",B_TITLED_WINDOW,B_NOT_ANCHORED_ON_ACTIVATE | B_NOT_ZOOMABLE | B_NOT_RESIZABLE,B_CURRENT_WORKSPACE) +{ + BRect bounds = Bounds(); + fview = new BView(bounds,"View",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); + + frestart = new BButton(BRect(10,285,130,310),"Restart_Networking","Restart Networking",new BMessage(kRestart_Networking_M)); + frevert = new BButton(BRect(150,285,210,310),"Revert","Revert",new BMessage(kRevert_M)); + fsave = new BButton(BRect(400,285,480,310),"Save","Save",new BMessage(kSave_M)); + fsave->MakeDefault(true); + fsave->SetEnabled(false); + frevert->SetEnabled(false); + + bounds.bottom -= 50; + bounds.InsetBy(5,5); + ftabview = new BTabView(bounds,"tab_view"); + + fidentity = new BTab(); + bounds.bottom -= ftabview->TabHeight(); + fidentity_view = new BView(bounds,"Identity",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); + fservices_view = new BView(bounds,"Services",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); + + bounds.bottom -= 160; + bounds.right -= 20; + fnames = new BBox(bounds,"Names",B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_FRAME_EVENTS); + + fdomain = new BTextControl(BRect(10,15,220,45),"Domain_Name","Domain Name:",NULL,new BMessage(kSOMETHING_HAS_CHANGED_M)); + fhost = new BTextControl(BRect(10,50,220,90),"Host_Name","Host Name:",NULL,new BMessage(kSOMETHING_HAS_CHANGED_M)); + fprimary_dns = new BTextControl(BRect(240,15,440,45),"Primary_DNS","Primary DNS:",NULL,new BMessage(kSOMETHING_HAS_CHANGED_M)); + fsecondary_dns = new BTextControl(BRect(240,50,440,90),"Secondary_DNS","Secondary_DNS:",NULL,new BMessage(kSOMETHING_HAS_CHANGED_M)); + + bounds.top = bounds.bottom + 10; + bounds.bottom = 220; + finterfaces = new BBox(bounds,"Network_Interfaces",B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_FRAME_EVENTS); + + fsettings = new BButton(BRect(395,17,460,37),"Settings","Settings",new BMessage(kSettings_M)); + fclear = new BButton(BRect(395,47,460,67),"Clear","Clear",new BMessage(kClear_M)); + fcustom = new BButton(BRect(395,87,460,107),"Add","Add...",new BMessage(kCustom_M)); + fsettings ->SetEnabled(false); + fclear ->SetEnabled(false); + + bounds = finterfaces->Bounds(); + bounds.InsetBy(20,20); + bounds.bottom += 5; + bounds.right -= 70; + finterfaces_list = new NetListView(bounds,"Interfaces_List"); + BScrollView *interfaces_scroller = new BScrollView("Interfaces_Scroller",finterfaces_list); + + fservices = new BTab(); + fftp_server = new BCheckBox(BRect(10,20,120,40),"FTP_Server","FTP Server",new BMessage(kSOMETHING_HAS_CHANGED_M)); + ftelnet_server = new BCheckBox(BRect(10,50,120,70),"Telnet_Server","Telnet Server",new BMessage(kSOMETHING_HAS_CHANGED_M)); + fapple_talk = new BCheckBox(BRect(10,110,120,130),"Apple_Talk","Apple Talk",new BMessage(kSOMETHING_HAS_CHANGED_M)); + fip_forwarding = new BCheckBox(BRect(10,140,120,160),"IP_Forwarding","IP Forwarding",new BMessage(kSOMETHING_HAS_CHANGED_M)); + flogin_info = new BButton(BRect(10,80,120,100),"Login_Info","Login Info...",new BMessage(kLogin_Info_M)); + + fconfigurations = new BBox(BRect(200,10,460,210),"Configurations",B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_FRAME_EVENTS); + + bounds = fconfigurations->Bounds(); + bounds.InsetBy(20,20); + bounds.right -= 80; + fconfigurations_list = new NetListView(bounds,"Configurations_List"); + BScrollView *configurations_scroller = new BScrollView("Configurations_Scroller",fconfigurations_list); + + fbackup = new BButton(BRect(170,17,250,37),"Backup","Backup",new BMessage(kBackup_M)); + frestore = new BButton(BRect(170,47,250,67),"Restore","Restore",new BMessage(kRestore_M)); + fremove = new BButton(BRect(170,87,250,107),"Delete","Delete",new BMessage(kDelete_M)); + frestore->SetEnabled(false); + fremove->SetEnabled(false); + + fdomain->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); + fhost->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); + fprimary_dns->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); + fsecondary_dns->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); + + fnames ->SetLabel("Names"); + finterfaces ->SetLabel("Network Interfaces"); + fconfigurations ->SetLabel("Configurations"); + fidentity_view ->SetViewColor(B_GREY); + fservices_view ->SetViewColor(B_GREY); + ftabview ->SetViewColor(B_GREY); + fview ->SetViewColor(B_GREY); + +//Casts an AddEverything + ftabview ->AddTab(fidentity_view,fidentity); + ftabview ->AddTab(fservices_view,fservices); + + fnames ->AddChild(fdomain); + fnames ->AddChild(fhost); + fnames ->AddChild(fprimary_dns); + fnames ->AddChild(fsecondary_dns); + finterfaces ->AddChild(fsettings); + finterfaces ->AddChild(fclear); + finterfaces ->AddChild(fcustom); + finterfaces ->AddChild(interfaces_scroller); + fidentity_view ->AddChild(fnames); + fidentity_view ->AddChild(finterfaces); + fservices_view ->AddChild(fftp_server); + fservices_view ->AddChild(ftelnet_server); + fservices_view ->AddChild(flogin_info); + fservices_view ->AddChild(fapple_talk); + fservices_view ->AddChild(fip_forwarding); + fservices_view ->AddChild(fconfigurations); + fconfigurations ->AddChild(configurations_scroller); + fconfigurations ->AddChild(fbackup); + fconfigurations ->AddChild(frestore); + fconfigurations ->AddChild(fremove); + fview ->AddChild(ftabview); + fview ->AddChild(frestart); + fview ->AddChild(frevert); + fview ->AddChild(fsave); + AddChild(fview); +} + +void NetworkWindow::MessageReceived(BMessage *message) +{ + switch (message->what){ + case kRestart_Networking_M:{ + + RestartWindow *restartWindow = new RestartWindow(); + restartWindow->Show(); + + BMessenger messenger("application/x-vnd.Be-NETS"); + if (messenger.IsValid() == true) + messenger.SendMessage(B_QUIT_REQUESTED); + + const char **arg_v; + int32 argc; + thread_id thread; + status_t return_value; + + argc = 1; + arg_v = (const char **)malloc(sizeof(char *) * (argc + 1)); + + arg_v[0] = strdup("/boot/beos/system/servers/net_server"); + arg_v[1] = NULL; + + thread = load_image(argc,arg_v,(const char **)environ); + + while (--argc >= 0) + free((void *)arg_v[argc]); + free (arg_v); + + return_value = resume_thread(thread); + + restartWindow->Quit(); + break; + } + case kRevert_M:{ + GetEverything(); + frevert->SetEnabled(false); + fsave->SetEnabled(false); + break; + } + case kSave_M:{ + BackupWin *bak = new BackupWin(); + bak->fparent_window = dynamic_cast (fview->Window()); + bak->Flatten_bak(); + bak->Quit(); + frevert->SetEnabled(false); + fsave->SetEnabled(false); + break; + } + case kSettings_M:{ + InterfaceWin *win = new InterfaceWin(); + + win->fparent_window = dynamic_cast (fview->Window()); + + NetListItem *selection = dynamic_cast (finterfaces_list->ItemAt(finterfaces_list->CurrentSelection())); + + if (selection->fENABLED == 1) + win->finter_enabled->SetValue(1); + if (selection->fDHCP == 1) + win->finter_dhcp->SetValue(1); + else + win->finter_manual->SetValue(1); + + win->finter_name->SetText((selection->fPRETTYNAME).String()); + win->finter_ip->SetText((selection->fIPADDRESS).String()); + win->finter_mask->SetText((selection->fNETMASK).String()); + + win->fhas_something_changed = false; + + win->finter_ip->SetTarget(win); + win->finter_mask->SetTarget(win); + win->finter_gateway->SetTarget(win); + + win->Show(); + break; + } + case kClear_M:{ + break; + } + case kCustom_M:{ + break; + } + case kLogin_Info_M:{ + LoginInfo *login_info_pop = new LoginInfo(); + login_info_pop->fparent_window = dynamic_cast (fview->Window()); + login_info_pop->flogin_info_name->SetText(fusername.String()); + login_info_pop->flogin_info_name->MakeFocus(); + login_info_pop->Show(); + break; + } + case kBackup_M:{ + BackupWin *backup_pop = new BackupWin(); + backup_pop->fparent_window = dynamic_cast (fview->Window()); + backup_pop->fbak_name->MakeFocus(); + backup_pop->Show(); + break; + } + case kRestore_M:{ + BStringItem *string_item = dynamic_cast (fconfigurations_list->ItemAt(fconfigurations_list->CurrentSelection())); + GetEverything(string_item->Text()); + PostMessage(kSOMETHING_HAS_CHANGED_M); + break; + } + case kDelete_M:{ + Remove_Config_File(); + Get_Configs_List(); + fconfigurations_list->SelectionChanged(); + break; + } + case kSOMETHING_HAS_CHANGED_M:{ + frevert->SetEnabled(true); + fsave->SetEnabled(true); + break; + } + } +} + +bool NetworkWindow::QuitRequested() +{ + if (fsave->IsEnabled() == true){ + BAlert *alert = new BAlert("Save Info Alert","Save changes before quitting ?","Don't Save","Cancel","Save",B_WIDTH_FROM_WIDEST,B_INFO_ALERT); + int32 result = alert->Go(); + switch (result){ + case 0:{ + be_app->PostMessage(B_QUIT_REQUESTED); + return true; + break; + } + case 1:{ + return false; + break; + } + case 2:{ + BackupWin *sav = new BackupWin(); + sav->fparent_window = dynamic_cast (fview->Window()); + sav->Flatten_bak(); + sav->Quit(); + be_app->PostMessage(B_QUIT_REQUESTED); + return true; + break; + } + } + } + else { + be_app->PostMessage(B_QUIT_REQUESTED); + return true; + } +} + +LoginInfo::LoginInfo() : BWindow(BRect(410,200,710,335),"Login Info",B_MODAL_WINDOW,B_NOT_ANCHORED_ON_ACTIVATE | B_NOT_RESIZABLE,B_CURRENT_WORKSPACE) +{ + flogin_info_view = new BView(Bounds(),"Login_Info_View",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); + + flogin_info_name = new BTextControl(BRect(10,10,290,30),"User_Name","User Name",NULL,new BMessage()); + flogin_info_password = new BTextControl(BRect(10,40,290,60),"Password","Password",NULL,new BMessage()); + flogin_info_confirm = new BTextControl(BRect(10,70,290,90),"Confirm Password","Confirm Password",NULL,new BMessage()); + flogin_info_cancel = new BButton(BRect(100,100,190,120),"Cancel","Cancel",new BMessage(kLogin_Info_Cancel_M)); + flogin_info_done = new BButton(BRect(200,100,290,120),"Done","Done",new BMessage(kLogin_Info_Done_M)); + + flogin_info_done->MakeDefault(true); + flogin_info_view->SetViewColor(B_GREY); + flogin_info_view->AddChild(flogin_info_name); + flogin_info_view->AddChild(flogin_info_password); + flogin_info_view->AddChild(flogin_info_confirm); + flogin_info_view->AddChild(flogin_info_cancel); + flogin_info_view->AddChild(flogin_info_done); + + AddChild(flogin_info_view); +} + +void LoginInfo::MessageReceived(BMessage *message) +{ + switch (message->what) + { + case kLogin_Info_Cancel_M: + { + Quit(); + break; + } + case kLogin_Info_Done_M: + { + const char *login_info_name_S = flogin_info_name ->Text(); + const char *login_info_password_S = flogin_info_password ->Text(); + const char *login_info_confirm_S = flogin_info_confirm ->Text(); + + if (strlen(login_info_name_S) > 0 + && strlen(login_info_password_S) > 0 + && strlen(login_info_confirm_S) > 0 ){ + if (strcmp(login_info_password_S,login_info_confirm_S) == 0){ + fparent_window->flogin_info_S[0] = login_info_name_S; + fparent_window->flogin_info_S[1] = login_info_password_S; + fparent_window->PostMessage(fparent_window->kSOMETHING_HAS_CHANGED_M); + Quit(); + } + else{ + 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); + alert->Go(); + } + + } + else{ + BAlert *alert = new BAlert("Login Info Alert","You didn't fill all the fields","Oups...",NULL,NULL,B_WIDTH_FROM_WIDEST,B_INFO_ALERT); + alert->Go(); + } + break; + } + } +} + +BackupWin::BackupWin() : BWindow(BRect(410,200,710,285),"Backup Win",B_MODAL_WINDOW,B_NOT_ANCHORED_ON_ACTIVATE | B_NOT_RESIZABLE,B_CURRENT_WORKSPACE) +{ + fbakview = new BView(Bounds(),"Backup",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); + fbak_name = new BTextControl(BRect(10,20,290,40),"Backup As","Backup As:",NULL,new BMessage()); + fbak_cancel = new BButton(BRect(100,50,190,70),"Cancel","Cancel",new BMessage(kCancel_bak_M)); + fbak_done = new BButton(BRect(200,50,290,70),"Done","Done",new BMessage(kFlatten_bak_M)); + + fbakview->SetViewColor(B_GREY); + fbak_done->MakeDefault(true); + + fbakview->AddChild(fbak_name); + fbakview->AddChild(fbak_cancel); + fbakview->AddChild(fbak_done); + + AddChild(fbakview); +} + +void BackupWin::MessageReceived(BMessage *message) +{ + switch (message->what){ + case kCancel_bak_M:{ + Quit(); + break; + } + case kFlatten_bak_M:{ + const char *bak_name_S = fbak_name->Text(); + + if (strlen(bak_name_S) > 0){ + Flatten_bak(bak_name_S); //Writes the new config file + fparent_window->Lock(); + fparent_window->Get_Configs_List(); //Update the list + fparent_window->fconfigurations_list->SelectionChanged(); //Update the buttons + fparent_window->Unlock(); + Quit(); + } + else{ + BAlert *alert = new BAlert("Backup Info Alert","You must sprcify a name","Oups...",NULL,NULL,B_WIDTH_FROM_WIDEST,B_INFO_ALERT); + alert->Go(); + } + break; + } + } +} + +NetListView::NetListView(BRect frame,const char *name) : BListView(frame, name) +{} //The NetListView only exists to override the SelectionChanged() function below + +//Buttons are enabled or not depending on the selection in the list +//so each time you click in the list, this method is called to update the buttons +void NetListView::SelectionChanged(void) +{ + int32 index = CurrentSelection(); + + BView *parent = Parent(); + + if (index >= 0){ + if (strcmp(parent->Name(),"Interfaces_Scroller") == 0) //There are 2 lists that are instances of this class, + { //so we have to see in which list you are clicking + BButton *settings = dynamic_cast ((parent->Parent())->FindView("Settings")); + BButton *clear = dynamic_cast ((parent->Parent())->FindView("Clear")); + + settings ->SetEnabled(true); + clear ->SetEnabled(true); + } + else if (strcmp(parent->Name(),"Configurations_Scroller") == 0){ + BButton *restore = dynamic_cast ((parent->Parent())->FindView("Restore")); + BButton *remove = dynamic_cast ((parent->Parent())->FindView("Delete")); + + restore ->SetEnabled(true); + remove ->SetEnabled(true); + } + } + else{ + if (strcmp(parent->Name(),"Interfaces_Scroller") == 0) //There are 2 lists that are instances of this class, + { //so we have to see in which list you are clicking + BButton *settings = dynamic_cast ((parent->Parent())->FindView("Settings")); + BButton *clear = dynamic_cast ((parent->Parent())->FindView("Clear")); + + settings ->SetEnabled(false); + clear ->SetEnabled(false); + } + else if (strcmp(parent->Name(),"Configurations_Scroller") == 0){ + BButton *restore = dynamic_cast ((parent->Parent())->FindView("Restore")); + BButton *remove = dynamic_cast ((parent->Parent())->FindView("Delete")); + + restore ->SetEnabled(false); + remove ->SetEnabled(false); + } + } + +} + +RestartWindow::RestartWindow() : BWindow(BRect(400,300,650,350),"Restart Networking",B_MODAL_WINDOW,B_NOT_ANCHORED_ON_ACTIVATE | B_NOT_RESIZABLE,B_CURRENT_WORKSPACE) +{ + fview = new BView(Bounds(),"Restart_View",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); + + fview->SetViewColor(B_GREY); + + frestarting = new BStringView(BRect(60,5,200,25),"Restarting_Text_1","Restarting Networking"); + fwhatshappening = new BStringView(BRect(60,30,200,50),"Restarting_Text_2","Please Wait..."); + + BFont font(be_bold_font); + + frestarting->SetFont(&font); + fwhatshappening->SetFont(&font); + + fview->AddChild(frestarting); + fview->AddChild(fwhatshappening); + + AddChild(fview); +} + +NetListItem::NetListItem(const char *text) : BStringItem(text) +{} + +InterfaceWin::InterfaceWin():BWindow(BRect(410,350,720,600),"Interface Win",B_MODAL_WINDOW,B_NOT_ANCHORED_ON_ACTIVATE | B_NOT_RESIZABLE,B_CURRENT_WORKSPACE) +{ + BRect rect = Bounds(); + finterview = new BView(rect,"Interface_View",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); + finter_name = new BStringView(BRect(10,10,290,20),"Interface_Name",NULL); + finter_enabled= new BCheckBox(BRect(10,30,190,40),"Enabled","Interface enabled",new BMessage(kSOMETHING_HAS_CHANGED)); + finter_dhcp = new BRadioButton(BRect(10,50,290,60),"DHCP","Obtain settings automatically (DHCP)",new BMessage(kSOMETHING_HAS_CHANGED)); + finter_manual = new BRadioButton(BRect(10,70,290,80),"Manual","Specify settings",new BMessage(kSOMETHING_HAS_CHANGED)); + finter_config = new BButton(BRect(10,220,100,230),"Config","Config...",new BMessage()); + finter_cancel = new BButton(BRect(145,220,215,230),"Cancel","Cancel",new BMessage(kCancel_inter_M)); + finter_done = new BButton(BRect(225,220,295,230),"Done","Done",new BMessage(kDone_inter_M)); + rect.InsetBy(5,5); + rect.top+=95; + rect.bottom-=35; + finter_box = new BBox(rect,"IP",B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_FRAME_EVENTS); + finter_ip = new BTextControl(BRect(10,15,290,35),"IP address","IP address:",NULL,new BMessage(kSOMETHING_HAS_CHANGED)); + finter_mask = new BTextControl(BRect(10,45,290,65),"Subnet mask","Subnet mask:",NULL,new BMessage(kSOMETHING_HAS_CHANGED)); + finter_gateway = new BTextControl(BRect(10,75,290,95),"Gateway","Gateway:",NULL,new BMessage(kSOMETHING_HAS_CHANGED)); + + finterview->SetViewColor(B_GREY); + finter_done->MakeDefault(true); + + finter_box->AddChild(finter_ip); + finter_box->AddChild(finter_mask); + finter_box->AddChild(finter_gateway); + + finterview->AddChild(finter_name); + finterview->AddChild(finter_enabled); + finterview->AddChild(finter_dhcp); + finterview->AddChild(finter_manual); + finterview->AddChild(finter_config); + finterview->AddChild(finter_cancel); + finterview->AddChild(finter_done); + finterview->AddChild(finter_box); + + AddChild(finterview); +} + +void InterfaceWin::MessageReceived(BMessage *message) +{ + switch(message->what){ + case kCancel_inter_M:{ + Quit(); + break; + } + case kDone_inter_M:{ + if (fhas_something_changed == true){ + fparent_window->PostMessage(fparent_window->kSOMETHING_HAS_CHANGED_M); + + NetListItem *item = dynamic_cast (fparent_window->finterfaces_list->ItemAt(fparent_window->finterfaces_list->CurrentSelection())); + + item->fIPADDRESS = finter_ip->Text(); + item->fNETMASK = finter_mask->Text(); + + if (finter_enabled->Value() == 0) + item->fENABLED = 0; + else + item->fENABLED = 1; + + if (finter_dhcp->Value() == 0) + item->fDHCP = 0; + else + item->fDHCP = 1; + } + Quit(); + break; + } + case kSOMETHING_HAS_CHANGED:{ + fhas_something_changed = true; + break; + } + } +} + + diff --git a/src/prefs/network/Network.h b/src/prefs/network/Network.h new file mode 100644 index 0000000000..e5bace61c3 --- /dev/null +++ b/src/prefs/network/Network.h @@ -0,0 +1,201 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifndef _NETWORK_H_ +#define _NETWORK_H_ +/*General notes: + _ Generates two warnings when compiling which you don't have to care about. + _ The way the net_server is restarted might not be very good as it takes 0.10s + contrarely to Be's original ones that takes few seconds and does many more + things that I don't know yet. Will be improved ASAP.(As soon as I know how + tings are working...) + _ Custom button actually add an interface so I changed his label to "Add" + which make it clearer. + _ Custom/Add button does nothing because of next line. + _ Don't know where to find the "interface types". + _ Clear button does nothing as I couldn't find his utility. + _ Where to find the App's icon ? Ask Creative Design Team ? + _ Is there any "OBOS header" to insert on top of each sheet? +*/ + + +class NetListView : public BListView +{ + public: + NetListView(BRect frame,const char *name); + + virtual void SelectionChanged(void); +}; + + +class NetListItem : public BStringItem +{ + public: + NetListItem(const char *text); + + BString fIPADDRESS; + BString fNETMASK; + BString fPRETTYNAME; + int fENABLED; + int fDHCP; +}; + +class NetworkWindow : public BWindow +{ + public: + NetworkWindow(); +//The whole GUI which is hierarchized to see 'what is attached to what' + BView *fview; + BButton *frestart; + BButton *frevert; + BButton *fsave; + BTabView *ftabview; + BTab *fidentity; + BView *fidentity_view; + BBox *fnames; + BTextControl *fdomain; + BTextControl *fhost; + BTextControl *fprimary_dns; + BTextControl *fsecondary_dns; + BBox *finterfaces; + NetListView *finterfaces_list; + BButton *fsettings; + BButton *fclear; + BButton *fcustom; + BTab *fservices; + BView *fservices_view; + BCheckBox *fftp_server; + BCheckBox *ftelnet_server; + BCheckBox *fapple_talk; + BCheckBox *fip_forwarding; + BButton *flogin_info; + BBox *fconfigurations; + NetListView *fconfigurations_list; + BButton *fbackup; + BButton *frestore; + BButton *fremove; + +//Messages + static const int32 kRestart_Networking_M = 'ranm' ; + static const int32 kRevert_M = 'revm' ; + static const int32 kSave_M = 'savm' ; + static const int32 kSettings_M = 'setm' ; + static const int32 kClear_M = 'clem' ; + static const int32 kCustom_M = 'cusm' ; + static const int32 kLogin_Info_M = 'logm' ; + static const int32 kBackup_M = 'bakm' ; + static const int32 kRestore_M = 'resm' ; + static const int32 kDelete_M = 'delm' ; + + static const int32 kSOMETHING_HAS_CHANGED_M = 'shcm' ; + +/*As this window is the 'main' one and that at startup it gathers up the +infos with the GetEverything() method, some data are kept here and will be passed +to who needs it. */ + BString fusername; + BString flogin_info_S[2]; + + + virtual bool QuitRequested(); + virtual void MessageReceived(BMessage *message); + + //All these are defined in funcs.cpp + void Remove_Config_File(); + void Get_Configs_List(); + void GetEverything(const char *bakname = NULL); //Gets all the infos of the interfaces at startup, display and store them +}; //or get them from a backup file. + +class BackupWin : public BWindow //The window that appears when you press +{ //the 'Backup' button + public: + BackupWin(); + BView *fbakview; + BTextControl *fbak_name; + BButton *fbak_cancel; + BButton *fbak_done; + + NetworkWindow *fparent_window; + + void Flatten_bak(const char *bak_name = NULL); //Writes the backup or used + //when pressing 'save' + virtual void MessageReceived(BMessage *message); + + static const int32 kFlatten_bak_M = 'fbam' ; + static const int32 kCancel_bak_M = 'cbam' ; +}; + +class LoginInfo : public BWindow //The window that appears when you press +{ //the 'Login Info...' button + public: + LoginInfo(); + BView *flogin_info_view; + BTextControl *flogin_info_name; + BTextControl *flogin_info_password; + BTextControl *flogin_info_confirm; + BButton *flogin_info_cancel; + BButton *flogin_info_done; + + NetworkWindow *fparent_window; + + virtual void MessageReceived(BMessage *message); + + static const int32 kLogin_Info_Cancel_M = 'licm' ; + static const int32 kLogin_Info_Done_M = 'lidn' ; +}; + +class InterfaceWin : public BWindow //The window that appears when you press +{ //the 'Settings...' button. + public: + InterfaceWin(); + BView *finterview; + BStringView *finter_name; + BCheckBox *finter_enabled; + BRadioButton *finter_dhcp; + BRadioButton *finter_manual; + BButton *finter_config; + BButton *finter_cancel; + BButton *finter_done; + BBox *finter_box; + BTextControl *finter_ip; + BTextControl *finter_mask; + BTextControl *finter_gateway; + + NetworkWindow *fparent_window; + bool fhas_something_changed; + + virtual void MessageReceived(BMessage *message); + + static const int32 kCancel_inter_M = 'caim' ; + static const int32 kDone_inter_M = 'doim' ; + static const int32 kSOMETHING_HAS_CHANGED = 'sohc' ; +}; + +class RestartWindow : public BWindow +{ + public: + RestartWindow(); + BView *fview; + BStringView *frestarting; + BStringView *fwhatshappening; +}; + +class Network : public BApplication +{ + public: + Network(); + + NetworkWindow *fwindow; +}; + +#endif \ No newline at end of file diff --git a/src/prefs/network/Network.rsrc b/src/prefs/network/Network.rsrc new file mode 100644 index 0000000000..43dd2e7251 Binary files /dev/null and b/src/prefs/network/Network.rsrc differ diff --git a/src/prefs/network/funcs.cpp b/src/prefs/network/funcs.cpp new file mode 100644 index 0000000000..4afe75392e --- /dev/null +++ b/src/prefs/network/funcs.cpp @@ -0,0 +1,300 @@ +#include +#include +#include +#include +#include +#include +#include + +#include "Network.h" + +#define B_GREY 216,216,216 + + +void BackupWin::Flatten_bak(const char *bak_name = NULL) +{ +/*To understand what follows, u'd better open the + /boot/home/config/settings/network textfile */ + +//GLOBAL: + BString DNS_DOMAIN = "\n\tDNS_DOMAIN = "; + DNS_DOMAIN << fparent_window->fdomain->Text(); + BString HOSTNAME = "\n\tHOSTNAME = "; + HOSTNAME << fparent_window->fhost->Text(); + BString USERNAME = "\n\tUSERNAME = "; + USERNAME << fparent_window->flogin_info_S[0]; + BString PROTOCOLS = "\n\tPROTOCOLS = ";/*where to get that info ??*/ + BString PASSWORD = "\n\tPASSWORD = "; + PASSWORD << fparent_window->flogin_info_S[1]; + BString FTP_ENABLED = "\n\tFTP_ENABLED = "; + if (fparent_window->fftp_server->Value() == 0) + FTP_ENABLED << 0; + else FTP_ENABLED << 1; + BString IP_FORWARD = "\n\tIP_FORWARD = "; + if (fparent_window->fip_forwarding->Value() == 0) + IP_FORWARD << 0; + else IP_FORWARD << 1; + BString DNS_ENABLED = "\n\tDNS_ENABLED = ";/*where to get that info ??*/ + BString TELNETD_ENABLED = "\n\tTELNETD_ENABLED = "; + if (fparent_window->ftelnet_server->Value() == 0) + TELNETD_ENABLED << 0; + else TELNETD_ENABLED << 1; + BString DNS_PRIMARY = "\n\tDNS_PRIMARY = "; + DNS_PRIMARY << fparent_window->fprimary_dns->Text(); + BString DNS_SECONDARY = "\n\tDNS_SECONDARY = "; + DNS_SECONDARY << fparent_window->fsecondary_dns->Text(); + BString ROUTER = "\n\tROUTER = ";/*where to get that info ??*/ + BString VERSION = "\n\tVERSION = ";/*where to get that info ??*/ + BString INTERFACES = "\n\tINTERFACES = ";/*Unused but kept for background compatibility*/ + +//Now let's see how many interfaces there are + int32 numb = fparent_window->finterfaces_list->CountItems(); + BString fields[numb][8]; //Each interface has 8 fields + int i; + for (i=0;i (fparent_window->finterfaces_list->ItemAt(i)); + + fields[i][3] << item->fIPADDRESS; + fields[i][4] << item->fNETMASK; + fields[i][5] << item->fPRETTYNAME; + fields[i][6] << item->fENABLED; + fields[i][7] << item->fDHCP; + } + +//Now let's write all these stuffs + BString path; + path = "/boot/home/config/settings/network"; + + if (bak_name != NULL) //This Flatten_bak() function is used + path<<"."< file) + else { //and for the "Save" button which uses the + BEntry entry(path.String()); //network file as the backup file. + entry.Remove(); + } + + FILE *bak_file = fopen(path.String(),"w"); + fprintf(bak_file,"GLOBAL:"); //The "GLOBAL" part + fprintf(bak_file,DNS_DOMAIN.String()); + fprintf(bak_file,HOSTNAME.String()); + fprintf(bak_file,USERNAME.String()); + fprintf(bak_file,PROTOCOLS.String()); + fprintf(bak_file,PASSWORD.String()); + fprintf(bak_file,FTP_ENABLED.String()); + fprintf(bak_file,IP_FORWARD.String()); + fprintf(bak_file,DNS_ENABLED.String()); + fprintf(bak_file,TELNETD_ENABLED.String()); + fprintf(bak_file,DNS_PRIMARY.String()); + fprintf(bak_file,DNS_SECONDARY.String()); + fprintf(bak_file,ROUTER.String()); + fprintf(bak_file,VERSION.String()); + fprintf(bak_file,INTERFACES.String()); + + for (int i=0;iGo(); + if (result == 0){ + BStringItem *item = dynamic_cast (fconfigurations_list->ItemAt(fconfigurations_list->CurrentSelection())); + + BString path; + path = "/boot/home/config/settings/network."; + path<< item->Text(); + + BEntry entry(path.String()); + entry.Remove(); + } +} + +void NetworkWindow::Get_Configs_List() +{ + fconfigurations_list->MakeEmpty(); + + BDirectory settings("/boot/home/config/settings/"); + BEntry entry; + + if (settings.InitCheck() == B_OK){ + while (settings.GetNextEntry(&entry) == B_OK){ + char buffer[9]; //All the config files start with "network." + entry.GetName(buffer); //so we only get the 8 first characters + buffer[8]='\0'; //to compare. + + if (strcmp(buffer,"network.") == 0){ + BString string; + char name[B_FILE_NAME_LENGTH]; + entry.GetName(name); + string<AddItem(item); + } + } + } +} + +void NetworkWindow::GetEverything(const char *bakname = NULL) +{ +//The configuration is saved in the /boot/home/config/settings/network +//text file so the config is static. Maybe we could switch to dynamic by +//directly asking the net_server how things are + + if (bakname == NULL + && BEntry("/boot/home/config/settings/network").Exists() == false){ + BAlert *alert = new BAlert("Network Alert","Your network config file doesn't exists.\n + It should be located at/boot/home/config/settings/network " + ,"Oups...",NULL,NULL,B_WIDTH_FROM_WIDEST,B_INFO_ALERT); + alert->Go(); + } + else { +/*This function being used when pressing "Revert" so first we need to +empty things before setting the new values*/ + Lock(); + finterfaces_list->MakeEmpty(); + fftp_server ->SetValue(0); + ftelnet_server ->SetValue(0); + fapple_talk ->SetValue(0); + fip_forwarding ->SetValue(0); + Unlock(); + + BString path_S = "/boot/home/config/settings/network"; + if (bakname != NULL) path_S<<"."<SetText(GLOBAL[0].String()); //The BTextControls + fhost ->SetText(GLOBAL[1].String()); + fprimary_dns ->SetText(GLOBAL[9].String()); + fsecondary_dns ->SetText(GLOBAL[10].String()); + + if (GLOBAL[5]== "1") fftp_server->SetValue(1); //Now the BCheckBoxes + if (GLOBAL[6]== "1") fip_forwarding->SetValue(1); + if (GLOBAL[8]== "1") ftelnet_server->SetValue(1); + + for (i=0;i"<"<<"State(Not implemented yet)"; + NetListItem *item = new NetListItem(string.String()); + + item->fIPADDRESS = INTERFACES[i][3]; + item->fNETMASK = INTERFACES[i][4]; + item->fPRETTYNAME = INTERFACES[i][5]; + item->fENABLED = atoi(INTERFACES[i][6].String()); + item->fDHCP = atoi(INTERFACES[i][7].String()); + + finterfaces_list->AddItem(item); + } + + Unlock(); + +//And save some of them + fusername = GLOBAL[2]; + } +} \ No newline at end of file diff --git a/src/prefs/screensaver/Jamfile b/src/prefs/screensaver/Jamfile index a67d328fc7..47ccbdfb77 100644 --- a/src/prefs/screensaver/Jamfile +++ b/src/prefs/screensaver/Jamfile @@ -1,5 +1,7 @@ SubDir OBOS_TOP src prefs screensaver ; +AddResources ScreenSaver : ScreenSaver.rsrc ; + local sources = OBOSScreenSaverPreferences.cpp ScreenSaver.cpp