From 9bf86676ad1834390945e8f84ab754ff2d6e9a87 Mon Sep 17 00:00:00 2001 From: DarkWyrm Date: Tue, 7 Feb 2006 01:38:02 +0000 Subject: [PATCH] Serious refactoring of app code. Updating files to style guidelines Separated classes into their own files Lots of other things, but still nowhere near finished git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@16265 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/preferences/network/BackupWindow.cpp | 177 +++++++ src/preferences/network/BackupWindow.h | 31 ++ src/preferences/network/ConfigData.cpp | 488 +++++++++++++++++++ src/preferences/network/ConfigData.h | 55 +++ src/preferences/network/InterfaceWin.cpp | 157 ++++++ src/preferences/network/InterfaceWin.h | 43 ++ src/preferences/network/Jamfile | 10 +- src/preferences/network/LoginInfo.cpp | 78 +++ src/preferences/network/LoginInfo.h | 30 ++ src/preferences/network/NetListView.cpp | 64 +++ src/preferences/network/NetListView.h | 32 ++ src/preferences/network/Network.cpp | 568 +--------------------- src/preferences/network/Network.h | 182 +------ src/preferences/network/NetworkWindow.cpp | 565 +++++++++++++++++++++ src/preferences/network/NetworkWindow.h | 91 ++++ src/preferences/network/funcs.cpp | 301 ------------ 16 files changed, 1839 insertions(+), 1033 deletions(-) create mode 100644 src/preferences/network/BackupWindow.cpp create mode 100644 src/preferences/network/BackupWindow.h create mode 100644 src/preferences/network/ConfigData.cpp create mode 100644 src/preferences/network/ConfigData.h create mode 100644 src/preferences/network/InterfaceWin.cpp create mode 100644 src/preferences/network/InterfaceWin.h create mode 100644 src/preferences/network/LoginInfo.cpp create mode 100644 src/preferences/network/LoginInfo.h create mode 100644 src/preferences/network/NetListView.cpp create mode 100644 src/preferences/network/NetListView.h create mode 100644 src/preferences/network/NetworkWindow.cpp create mode 100644 src/preferences/network/NetworkWindow.h delete mode 100644 src/preferences/network/funcs.cpp diff --git a/src/preferences/network/BackupWindow.cpp b/src/preferences/network/BackupWindow.cpp new file mode 100644 index 0000000000..c494f67228 --- /dev/null +++ b/src/preferences/network/BackupWindow.cpp @@ -0,0 +1,177 @@ +#include +#include +#include +#include "BackupWindow.h" +#include "NetworkWindow.h" +#include "NetListView.h" +#include "ConfigData.h" + +BackupWin::BackupWin(const BRect &frame) + : BWindow(frame,"Backup Win",B_MODAL_WINDOW, + B_NOT_ANCHORED_ON_ACTIVATE | B_NOT_RESIZABLE,B_CURRENT_WORKSPACE) +{ + BRect r(Bounds()); + + BView *view=new BView(Bounds(),"Backup",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); + view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + AddChild(view); + + fDone=new BButton(BRect(0,0,1,1),"Done","Done",new BMessage(kSaveBackup_M)); + fDone->ResizeToPreferred(); + fDone->MoveTo(r.right - 5 - fDone->Bounds().Width(), + r.bottom - 5 - fDone->Bounds().Height()); + + fCancel=new BButton(BRect(100,50,190,70),"Cancel","Cancel", + new BMessage(kCancel_bak_M)); + fCancel->ResizeToPreferred(); + fCancel->MoveTo(fDone->Frame().left - 5 - fCancel->Frame().Width(), + fDone->Frame().top); + + fName=new BTextControl(BRect(5,5,r.right - 10,40),"Backup As","Backup As:", + NULL,new BMessage(),B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); + float w,h; + fName->GetPreferredSize(&w,&h); + fName->ResizeTo(r.right - 10, h); + fName->MoveTo(5, 5 + (fCancel->Frame().top-h-10)/2); + fName->SetDivider(fName->StringWidth("Backup As:")+10); + + view->AddChild(fName); + view->AddChild(fCancel); + view->AddChild(fDone); + fDone->MakeDefault(true); + fName->MakeFocus(true); +} + +void +BackupWin::MessageReceived(BMessage *message) +{ + switch (message->what) { + + case kCancel_bak_M: { + PostMessage(B_QUIT_REQUESTED); + break; + } + case kSaveBackup_M: { + + if (strlen(fName->Text()) > 0) { + SaveBackup(fName->Text()); //Writes the new config file + fParentWindow->Lock(); + fParentWindow->LoadConfigEntries(); //Update the list + fParentWindow->fConfigurationsList->SelectionChanged(); //Update the buttons + fParentWindow->Unlock(); + Quit(); + } + else { + BAlert *alert = new BAlert("Backup Info Alert","You must specify a name.","OK"); + alert->Go(); + } + break; + } + } +} + +void +BackupWin::SaveBackup(const char *bak_name) +{ +/* + // GLOBAL: section + BString DNS_DOMAIN = "\n\tDNS_DOMAIN = "; + DNS_DOMAIN << fParentWindow->fDomain->Text(); + BString HOSTNAME = "\n\tHOSTNAME = "; + HOSTNAME << fParentWindow->fHost->Text(); + BString USERNAME = "\n\tUSERNAME = "; + USERNAME << fParentWindow->flogin_info_S[0]; + BString PROTOCOLS = "\n\tPROTOCOLS = ";//where to get that info ?? + BString PASSWORD = "\n\tPASSWORD = "; + PASSWORD << fParentWindow->flogin_info_S[1]; + BString FTP_ENABLED = "\n\tFTP_ENABLED = "; + if (fParentWindow->fFTPServer->Value() == 0) + FTP_ENABLED << 0; + else FTP_ENABLED << 1; + BString IP_FORWARD = "\n\tIP_FORWARD = "; + if (fParentWindow->fIPForwarding->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 (fParentWindow->fTelnetServer->Value() == 0) + TELNETD_ENABLED << 0; + else TELNETD_ENABLED << 1; + BString DNS_PRIMARY = "\n\tDNS_PRIMARY = "; + DNS_PRIMARY << fParentWindow->fPrimaryDNS->Text(); + BString DNS_SECONDARY = "\n\tDNS_SECONDARY = "; + DNS_SECONDARY << fParentWindow->fSecondaryDNS->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 = fParentWindow->fInterfacesList->CountItems(); + + // Each interface has 8 fields + BString fields[numb][8]; + + for(int i=0;i (fParentWindow->fInterfacesList->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 this stuff + BString path; + path = "/boot/home/config/settings/network"; + + // This SaveBackup() function is used for backups(so a network. file) + // and for the "Save" button which uses the network file as the backup file. + if (bak_name != NULL) + path << "." << bak_name; + else { + BEntry entry(path.String()); + 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;i +#include +#include +#include + +class NetworkWindow; + +// The window that appears when you press the 'Backup' button +class BackupWin : public BWindow +{ +public: + BackupWin(const BRect &frame); + + BTextControl *fName; + BButton *fCancel; + BButton *fDone; + + NetworkWindow *fParentWindow; + + void SaveBackup(const char *name=NULL); + virtual void MessageReceived(BMessage *message); + + static const int32 kSaveBackup_M = 'fbam' ; + static const int32 kCancel_bak_M = 'cbam' ; +}; + +#endif + diff --git a/src/preferences/network/ConfigData.cpp b/src/preferences/network/ConfigData.cpp new file mode 100644 index 0000000000..2f1cc270c1 --- /dev/null +++ b/src/preferences/network/ConfigData.cpp @@ -0,0 +1,488 @@ +#include "ConfigData.h" +#include + +InterfaceData::InterfaceData(const char *name) + : + fConfig(""), + fPath(""), + fType("ETHERNET"), + fIPAddress("192.168.0.2"), + fNetMask("255.255.255.0"), + fGateway("192.168.0.1"), + fPrettyName(""), + fName(name), + fEnabled(true), + fDHCP(false) +{ +} + +ConfigData::ConfigData(void) + : fDomainName(""), + fHostname(""), + fPrimaryDNS(""), + fSecondaryDNS(""), + fFTPServer(false), + fTelnetServer(false), + fUsername(""), + fPassword(""), + fProtocols(""), + fAppleTalk(false), + fIPForwarding(false), + fUseDNS(true), + fInterfaceList(0) +{ +} + +ConfigData::~ConfigData(void) +{ + EmptyInterfaces(); +} + +void +ConfigData::EmptyInterfaces(void) +{ + for(int32 i=0; i file) + // and for the "Save" button which uses the network file as the backup file. + if(filename) + path << "." << filename; + + BFile file(path.String(),B_READ_WRITE | B_CREATE_FILE | B_ERASE_FILE); + if(file.InitCheck()!=B_OK) + { + printf("DEBUG: Couldn't create network settings file %s\n",path.String()); + return; + } + + file.Write(filedata.String(),filedata.Length()); + + file.Unset(); +} + +status_t +LoadBackup(const char *pathname, ConfigData &data) +{ + // 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 + + // This function being used when pressing "Revert" so first we need to + // empty things before setting the new values + ConfigData empty; + data.EmptyInterfaces(); + data = empty; + + // Read in the data from the file + + BString pathstring = "/boot/home/config/settings/network"; + if(pathname) + pathstring << "." << pathname; + + BFile file(pathstring.String(),B_READ_ONLY); + if(file.InitCheck()!=B_OK) + return file.InitCheck(); + + off_t filesize; + file.GetSize(&filesize); + + if(filesize < 1) + return B_ERROR; + + char *filestr = new char[filesize + 1]; + + filestr[filesize + 1] = 0; + file.Read(filestr, filesize); + file.Unset(); + + char *start=NULL, *end=NULL; + + // This is a little bit more flexible (and slower) implementation than may be necessary. We do use a small + // string hack to avoid unnecessary copying + start = strstr(filestr,"HOSTNAME = "); + if(start) { + + end = strstr(start,"\n"); + if(end) { + + *end='\0'; + data.fHostname = start; + *end='\n'; + } + } + + start = strstr(filestr,"USERNAME = "); + if(start) { + + end = strchr(start,'\n'); + if(end) { + + *end='\0'; + data.fUsername = start + 11; + *end='\n'; + } + } + + start = strstr(filestr,"HOSTNAME = "); + if(start) { + + end = strchr(start,'\n'); + if(end) { + + *end='\0'; + data.fHostname = start + 11; + *end='\n'; + } + } + + start = strstr(filestr,"PROTOCOLS = "); + if(start) { + + end = strchr(start,'\n'); + if(end) { + + *end='\0'; + data.fProtocols = start + 12; + *end='\n'; + } + } + + start = strstr(filestr,"PASSWORD = "); + if(start) { + + end = strchr(start,'\n'); + if(end) { + + *end='\0'; + data.fPassword = start + 11; + *end='\n'; + } + } + + start = strstr(filestr,"FTP_ENABLED = "); + if(start) { + + end = strchr(start,'\n'); + if(end) { + + *end='\0'; + start += 14; + data.fFTPServer = (strcmp(start,"1")==0)?true:false; + *end='\n'; + } + } + + start = strstr(filestr,"IP_FORWARD = "); + if(start) { + + end = strchr(start,'\n'); + if(end) { + + *end='\0'; + start += 13; + data.fIPForwarding = (strcmp(start,"1")==0)?true:false; + *end='\n'; + } + } + + start = strstr(filestr,"DNS_ENABLED = "); + if(start) { + + end = strchr(start,'\n'); + if(end) { + + *end='\0'; + start += 14; + data.fUseDNS = (strcmp(start,"1")==0)?true:false; + *end='\n'; + } + } + + start = strstr(filestr,"TELNETD_ENABLED = "); + if(start) { + + end = strchr(start,'\n'); + if(end) { + + *end='\0'; + start += 18; + data.fTelnetServer = (strcmp(start,"1")==0)?true:false; + *end='\n'; + } + } + + start = strstr(filestr,"DNS_DOMAIN = "); + if(start) { + + end = strchr(start,'\n'); + if(end) { + + *end='\0'; + data.fDomainName = start + 13; + *end='\n'; + } + } + + start = strstr(filestr,"DNS_PRIMARY = "); + if(start) { + + end = strchr(start,'\n'); + if(end) { + + *end='\0'; + data.fPrimaryDNS = start + 14; + *end='\n'; + } + } + + start = strstr(filestr,"DNS_SECONDARY = "); + if(start) { + + end = strchr(start,'\n'); + if(end) { + + *end='\0'; + data.fSecondaryDNS = start + 16; + *end='\n'; + } + } + + // TODO: What should we do with the ROUTER setting if there are more then one card and both + // specify settings? + +/* + start = strstr(filestr,"ROUTER = "); + if(start) { + + end = strchr(start,'\n'); + if(end) { + + *end='\0'; + data.fGateway = start + 9; + *end='\n'; + } + } + + start = strstr(filestr,"VERSION = "); + if(start) { + + end = strchr(start,'\n'); + if(end) { + + *end='\0'; + data.fVersion = start + 9; + *end='\n'; + } + } +*/ + + start = strstr(filestr,"INTERFACES = "); + if(start) { + + end = strchr(start,'\n'); + if(end) { + + *end='\0'; + BString interfaces = start + 13; + *end='\n'; + + // Now that we have them, lets find the names of all the interfaces present + int32 startpos=0,endpos=0; + while(endpos>=0) + { + endpos = interfaces.FindFirst(" ",startpos); + + BString name = interfaces.String() + startpos; + + if(endpos>=0) + name.Truncate(endpos); + + data.fInterfaceList.AddItem(new InterfaceData(name.String())); + + startpos = endpos+1; + } + } + } + + // OK. Now we've gotten through the GLOBAL section. All that's left is to read each interface section + for(int32 i=0; ifName.String()); + searchstr << ":"; + + char *istart = strstr(filestr,searchstr.String()); + if(!istart) + continue; + + istart = strchr(istart,'\n') + 1; + + BString istring = istart; + int32 istringend = istring.FindFirst("interface"); + if(istringend>=0) + istring.Truncate(istringend); + + // OK. At this point, we should have in istring all the data for the interface + int32 datastart=0,dataend=0; + datastart = istring.FindFirst("DEVICECONFIG = "); + if(datastart>=0) + { + idata->fConfig = istring.String() + datastart; + dataend = idata->fConfig.FindFirst("\n"); + if(dataend>=0) + idata->fConfig.Truncate(dataend); + + idata->fConfig = BString(idata->fConfig.String() + 15); + } + + datastart = istring.FindFirst("DEVICELINK = "); + if(datastart>=0) + { + idata->fPath = istring.String() + datastart; + dataend = idata->fPath.FindFirst("\n"); + if(dataend>=0) + idata->fPath.Truncate(dataend); + + idata->fPath = BString(idata->fPath.String() + 13); + } + + datastart = istring.FindFirst("DEVICETYPE = "); + if(datastart>=0) + { + idata->fType = istring.String() + datastart; + dataend = idata->fType.FindFirst("\n"); + if(dataend>=0) + idata->fType.Truncate(dataend); + + idata->fType = BString(idata->fType.String() + 13); + } + + datastart = istring.FindFirst("IPADDRESS = "); + if(datastart>=0) + { + idata->fIPAddress = istring.String() + datastart; + dataend = idata->fIPAddress.FindFirst("\n"); + if(dataend>=0) + idata->fIPAddress.Truncate(dataend); + + idata->fIPAddress = BString(idata->fIPAddress.String() + 12); + } + + datastart = istring.FindFirst("NETMASK = "); + if(datastart>=0) + { + idata->fNetMask = istring.String() + datastart; + dataend = idata->fNetMask.FindFirst("\n"); + if(dataend>=0) + idata->fNetMask.Truncate(dataend); + + idata->fNetMask = BString(idata->fNetMask.String() + 10); + } + + datastart = istring.FindFirst("PRETTYNAME = "); + if(datastart>=0) + { + idata->fPrettyName = istring.String() + datastart; + dataend = idata->fPrettyName.FindFirst("\n"); + if(dataend>=0) + idata->fPrettyName.Truncate(dataend); + + idata->fPrettyName = BString(idata->fPrettyName.String() + 13); + } + + datastart = istring.FindFirst("ENABLED = "); + if(datastart>=0) + { + BString str = istring.String() + datastart; + dataend = str.FindFirst("\n"); + if(dataend>=0) + str.Truncate(dataend); + + idata->fEnabled = (strcmp(str.String() + 10,"1")==0); + } + + datastart = istring.FindFirst("DHCP = "); + if(datastart>=0) + { + BString str = istring.String() + datastart; + dataend = str.FindFirst("\n"); + if(dataend>=0) + str.Truncate(dataend); + + idata->fDHCP = (strcmp(str.String() + 7,"1")==0); + } + + } + + + return B_OK; +} diff --git a/src/preferences/network/ConfigData.h b/src/preferences/network/ConfigData.h new file mode 100644 index 0000000000..2605db65c2 --- /dev/null +++ b/src/preferences/network/ConfigData.h @@ -0,0 +1,55 @@ +#ifndef CONFIG_DATA_H +#define CONFIG_DATA_H + +#include +#include +#include + +class InterfaceData +{ +public: + InterfaceData(const char *name); + + BString fConfig; + BString fPath; + BString fType; + BString fIPAddress; + BString fNetMask; + BString fGateway; + BString fPrettyName; + BString fName; + + bool fEnabled; + bool fDHCP; +}; + +class ConfigData +{ +public: + ConfigData(void); + ~ConfigData(void); + void EmptyInterfaces(void); + + BString fDomainName; + BString fHostname; + BString fPrimaryDNS; + BString fSecondaryDNS; + + bool fFTPServer; + bool fTelnetServer; + + BString fUsername; + BString fPassword; + BString fProtocols; + + bool fAppleTalk; + bool fIPForwarding; + bool fUseDNS; + + BList fInterfaceList; +}; + +void SaveBackup(const char *filename, ConfigData &data); +status_t LoadBackup(const char *pathname, ConfigData &data); + +#endif diff --git a/src/preferences/network/InterfaceWin.cpp b/src/preferences/network/InterfaceWin.cpp new file mode 100644 index 0000000000..09cd3dc19a --- /dev/null +++ b/src/preferences/network/InterfaceWin.cpp @@ -0,0 +1,157 @@ +#include +#include "InterfaceWin.h" +#include "NetListView.h" + +InterfaceWin::InterfaceWin(const BRect &frame, const InterfaceData &data) + : BWindow(frame,"Interface Win",B_MODAL_WINDOW, + B_NOT_ANCHORED_ON_ACTIVATE | B_NOT_RESIZABLE,B_CURRENT_WORKSPACE), + fData(data.fName.String()) +{ + AddShortcut('W',B_COMMAND_KEY,new BMessage(B_QUIT_REQUESTED)); + AddShortcut('Q',B_COMMAND_KEY,new BMessage(B_QUIT_REQUESTED)); + + BRect r(Bounds()); + + fData=data; + BView *view=new BView(r,"Interface_View",B_FOLLOW_ALL,B_WILL_DRAW); + view->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + AddChild(view); + + float width,height; + + fName=new BStringView(BRect(5,5,6,6),"Interface_Name",data.fPrettyName.String()); + fName->GetPreferredSize(&width,&height); + fName->ResizeTo(width,height); + view->AddChild(fName); + + // There is a serious possibility that the name of the interface may be + // longer than the current width of the window, especially at larger font + // settings. If this is the case, we will end up resizing the window to fit it + // all + float maxwidth = MAX(width, r.right); + + float ypos = 5 + height + 20; + fEnabled=new BCheckBox(BRect(5,ypos,6,ypos + 1), + "Enabled","Interface enabled", + new BMessage(kSOMETHING_HAS_CHANGED), + B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); + fEnabled->GetPreferredSize(&width,&height); + fEnabled->ResizeTo(width,height); + view->AddChild(fEnabled); + + ypos += height + 10; + fDHCP=new BRadioButton(BRect(5,ypos,6,ypos+1),"DHCP", + "Obtain settings automatically", + new BMessage(kSOMETHING_HAS_CHANGED)); + fDHCP->GetPreferredSize(&width,&height); + fDHCP->ResizeTo(width,height); + view->AddChild(fDHCP); + + ypos += height + 1; + fManual=new BRadioButton(BRect(5,ypos,6,ypos+1),"Manual","Specify settings", + new BMessage(kSOMETHING_HAS_CHANGED)); + fManual->GetPreferredSize(&width,&height); + fManual->ResizeTo(width,height); + view->AddChild(fManual); + + ypos += height + 10; + + fIPAddress=new BTextControl(BRect(10,10,6,6),"IP address","IP address:",NULL, + new BMessage(kSOMETHING_HAS_CHANGED), + B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); + fIPAddress->GetPreferredSize(&width,&height); + width = r.right - 15; + + fNetMask=new BTextControl(BRect(10,20 + height,width - 5,15 + (height*2)), + "Subnet mask","Subnet mask:",NULL, + new BMessage(kSOMETHING_HAS_CHANGED), + B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); + + fGateway=new BTextControl(BRect(10,30 + (height*2),width - 5,25 + (height*3)), + "Gateway","Gateway:",NULL, + new BMessage(kSOMETHING_HAS_CHANGED), + B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); + + fBox=new BBox(BRect(5,ypos,r.right - 5, ypos + fGateway->Frame().bottom + 10), + "IP",B_FOLLOW_LEFT_RIGHT | B_FOLLOW_TOP); + view->AddChild(fBox); + + fBox->AddChild(fIPAddress); + fBox->AddChild(fNetMask); + fBox->AddChild(fGateway); + + // We have to place the ResizeTo() call down here because in R5, these calls + // apparently don't do anything unless attached to a window. Grrr.... + fIPAddress->ResizeTo(width - 15, height); + + float dividersize = fIPAddress->StringWidth("Subnet mask:") + 10; + fIPAddress->SetDivider(dividersize); + fNetMask->SetDivider(dividersize); + fGateway->SetDivider(dividersize); + + fIPAddress->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); + fNetMask->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); + fGateway->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); + + + ypos = fBox->Frame().bottom + 10; + + // TODO: Finish the Configure code + fConfig=new BButton(BRect(5,ypos,6,ypos+1),"Config","Configure", NULL); + fConfig->GetPreferredSize(&width,&height); + fConfig->ResizeTo(width,height); + view->AddChild(fConfig); + + + fDone=new BButton(BRect(0,0,1,1),"Done","Done", new BMessage(kDone_inter_M), + B_FOLLOW_RIGHT | B_FOLLOW_TOP); + + fDone->ResizeToPreferred(); + fDone->MoveTo(r.right - 5 - fDone->Bounds().right,ypos); + + fCancel=new BButton(BRect(0,0,1,1),"Cancel","Cancel", + new BMessage(B_QUIT_REQUESTED), B_FOLLOW_RIGHT | B_FOLLOW_TOP); + + fCancel->ResizeToPreferred(); + fCancel->MoveTo(fDone->Frame().left - 10 - fCancel->Bounds().right,ypos); + view->AddChild(fCancel); + view->AddChild(fDone); + fDone->MakeDefault(true); + + ypos += height + 10; + if(r.bottom < ypos || r.right < maxwidth) + ResizeTo( MAX(r.right,maxwidth), MAX(ypos, r.bottom) ); +} + +void InterfaceWin::MessageReceived(BMessage *message) +{ + switch(message->what){ + + case kDone_inter_M:{ + if (fChanged==true){ + fParentWindow->PostMessage(fParentWindow->kSOMETHING_HAS_CHANGED_M); + + NetListItem *item=dynamic_cast (fParentWindow->fInterfacesList->ItemAt(fParentWindow->fInterfacesList->CurrentSelection())); + + item->fIPADDRESS=fIPAddress->Text(); + item->fNETMASK =fNetMask->Text(); + + if (fEnabled->Value()==0) + item->fENABLED =0; + else + item->fENABLED =1; + + if (fDHCP->Value()==0) + item->fDHCP=0; + else + item->fDHCP=1; + } + Quit(); + break; + } + case kSOMETHING_HAS_CHANGED:{ + fChanged=true; + break; + } + } +} diff --git a/src/preferences/network/InterfaceWin.h b/src/preferences/network/InterfaceWin.h new file mode 100644 index 0000000000..9a9a349964 --- /dev/null +++ b/src/preferences/network/InterfaceWin.h @@ -0,0 +1,43 @@ +#ifndef INTERFACE_WIN_H +#define INTERFACE_WIN_H + +#include +#include +#include +#include +#include + +#include "ConfigData.h" +#include "NetworkWindow.h" + +// This is the window that appears when you press the 'Settings' button. +class InterfaceWin : public BWindow +{ +public: + InterfaceWin(const BRect &frame, const InterfaceData &data); + + BStringView *fName; + BCheckBox *fEnabled; + BRadioButton *fDHCP; + BRadioButton *fManual; + BButton *fConfig; + BButton *fCancel; + BButton *fDone; + BBox *fBox; + BTextControl *fIPAddress; + BTextControl *fNetMask; + BTextControl *fGateway; + + NetworkWindow *fParentWindow; + + InterfaceData fData; + bool fChanged; + + 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' ; +}; + +#endif diff --git a/src/preferences/network/Jamfile b/src/preferences/network/Jamfile index 1216f66663..da94446ab1 100644 --- a/src/preferences/network/Jamfile +++ b/src/preferences/network/Jamfile @@ -4,7 +4,15 @@ SetSubDirSupportedPlatformsBeOSCompatible ; AddResources Network : Network.rdef ; -Preference Network : Network.cpp funcs.cpp ; +Preference Network : + BackupWindow.cpp + ConfigData.cpp + InterfaceWin.cpp + LoginInfo.cpp + NetListView.cpp + Network.cpp + NetworkWindow.cpp + ; LinkAgainst Network : be root ; diff --git a/src/preferences/network/LoginInfo.cpp b/src/preferences/network/LoginInfo.cpp new file mode 100644 index 0000000000..36d7d6f006 --- /dev/null +++ b/src/preferences/network/LoginInfo.cpp @@ -0,0 +1,78 @@ +#include "LoginInfo.h" +#include +#include +#include +#include +#include "NetworkWindow.h" + +LoginInfo::LoginInfo(void) + :BWindow(BRect(410,200,710,335),"Login Info",B_MODAL_WINDOW,B_NOT_ANCHORED_ON_ACTIVATE + | B_NOT_RESIZABLE,B_CURRENT_WORKSPACE) +{ + fView=new BView(Bounds(),"Login_Info_View",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); + fName=new BTextControl(BRect(10,10,290,30),"User_Name", + "User Name",NULL,new BMessage()); + fPassword=new BTextControl(BRect(10,40,290,60),"Password", + "Password",NULL,new BMessage()); + fPassword->TextView()->HideTyping(true); + fConfirm=new BTextControl(BRect(10,70,290,90),"Confirm Password", + "Confirm Password",NULL,new BMessage()); + fConfirm->TextView()->HideTyping(true); + fCancel=new BButton(BRect(100,100,190,120),"Cancel","Cancel", + new BMessage(kLogin_Info_Cancel_M)); + fDone=new BButton(BRect(200,100,290,120),"Done","Done", + new BMessage(kLogin_Info_Done_M)); + + fDone->MakeDefault(true); + fView->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + fView->AddChild(fName); + fView->AddChild(fPassword); + fView->AddChild(fConfirm); + fView->AddChild(fCancel); + fView->AddChild(fDone); + + AddChild(fView); +} + +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 = fName->Text(); + const char *login_info_password_S = fPassword ->Text(); + const char *login_info_confirm_S = fConfirm ->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) { + + fParentWindow->flogin_info_S[0] = login_info_name_S; + fParentWindow->flogin_info_S[1] = login_info_password_S; + fParentWindow->PostMessage(fParentWindow->kSOMETHING_HAS_CHANGED_M); + Quit(); + } + else { + BAlert *alert = new BAlert("Login Info Alert", + "Passwords don't match. Please try again","OK"); + 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; + } + } +} diff --git a/src/preferences/network/LoginInfo.h b/src/preferences/network/LoginInfo.h new file mode 100644 index 0000000000..34f4c8860f --- /dev/null +++ b/src/preferences/network/LoginInfo.h @@ -0,0 +1,30 @@ +#ifndef LOGIN_INFO_H +#define LOGIN_INFO_H + +#include +#include +#include +class NetworkWindow; + +// This is the window that appears when you press the 'Login Info' button +class LoginInfo : public BWindow +{ +public: + LoginInfo(void); + + BView *fView; + BTextControl *fName; + BTextControl *fPassword; + BTextControl *fConfirm; + BButton *fCancel; + BButton *fDone; + + NetworkWindow *fParentWindow; + + virtual void MessageReceived(BMessage *message); + + static const int32 kLogin_Info_Cancel_M = 'licm'; + static const int32 kLogin_Info_Done_M = 'lidn'; +}; + +#endif diff --git a/src/preferences/network/NetListView.cpp b/src/preferences/network/NetListView.cpp new file mode 100644 index 0000000000..baa5eb191a --- /dev/null +++ b/src/preferences/network/NetListView.cpp @@ -0,0 +1,64 @@ +#include +#include "NetListView.h" + +// The NetListView only exists to override the SelectionChanged() function below +NetListView::NetListView(BRect frame,const char *name) : BListView(frame, name) +{ +} + +// 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) { + + // There are 2 lists that are instances of this class, so we have to see in which list you are clicking + if (strcmp(parent->Name(),"Interfaces_Scroller") == 0) { + + 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 { + + // There are 2 lists that are instances of this class, so we have to see in which list you are clicking + if (strcmp(parent->Name(),"Interfaces_Scroller") == 0) { + + 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); + } + } + +} + +NetListItem::NetListItem(const char *text) + : BStringItem(text), + fData(text) +{ +} diff --git a/src/preferences/network/NetListView.h b/src/preferences/network/NetListView.h new file mode 100644 index 0000000000..d7e1ea114b --- /dev/null +++ b/src/preferences/network/NetListView.h @@ -0,0 +1,32 @@ +#ifndef NETLISTVIEW_H +#define NETLISTVIEW_H + +#include +#include +#include +#include "ConfigData.h" + +class NetListView : public BListView +{ +public: + NetListView(BRect frame,const char *name); + + virtual void SelectionChanged(void); +}; + + +class NetListItem : public BStringItem +{ +public: + NetListItem(const char *text); + + InterfaceData fData; + + BString fIPADDRESS; + BString fNETMASK; + BString fPRETTYNAME; + int fENABLED; + int fDHCP; +}; + +#endif diff --git a/src/preferences/network/Network.cpp b/src/preferences/network/Network.cpp index dfb26b7c26..c721b032d7 100644 --- a/src/preferences/network/Network.cpp +++ b/src/preferences/network/Network.cpp @@ -10,11 +10,24 @@ #include #include "Network.h" +#include "NetworkWindow.h" -#define NETWORK_WINDOW_RIGHT 435 -#define NETWORK_WINDOW_BOTTOM 309 +class Network : public BApplication +{ + public: + Network(); + + NetworkWindow *fwindow; +}; -#define B_GREY 216,216,216 +Network::Network() : BApplication("application/x-vnd.OBOS-Network") +{ + fwindow = new NetworkWindow(); + fwindow ->Show(); + + fwindow ->LoadConfigEntries(); + fwindow ->GetEverything(); +} int main() { @@ -22,552 +35,3 @@ int main() 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(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) -{ - // if(!Network_settings) - // { ... - BScreen screen; - - BRect screenframe = screen.Frame(); - float screenx, screeny; - screenx = ((screenframe.right + 1) / 2) - (NETWORK_WINDOW_RIGHT / 2) - 1; - screeny = ((screenframe.bottom + 1) / 2) - (NETWORK_WINDOW_BOTTOM / 2) - 1; - MoveTo(screenx, screeny); - // } - // else - // { - // ... - // } - - BRect bounds = Bounds(); - fview = new BView(bounds,"View",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); - - frestart = new BButton(BRect(11,274,122,298),"Restart_Networking","Restart Networking",new BMessage(kRestart_Networking_M)); - frevert = new BButton(BRect(145,274,220,298),"Revert","Revert",new BMessage(kRevert_M)); - fsave = new BButton(BRect(349,274,424,297),"Save","Save",new BMessage(kSave_M)); - fsave->MakeDefault(true); - fsave->SetEnabled(false); - frevert->SetEnabled(false); - - bounds.bottom = Bounds().Height(); - bounds.top += 10; - bounds.right = Bounds().Width(); - ftabview = new BTabView(bounds,"tab_view", B_WIDTH_FROM_WIDEST); - - 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.top -= 10; - bounds.bottom -= 209; - bounds.left += 11; - bounds.right -= 12; - fnames = new BBox(bounds,"Names",B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_FRAME_EVENTS); - - fdomain = new BTextControl(BRect(15,19,195,50),"Domain_Name","Domain name:",NULL,new BMessage(kSOMETHING_HAS_CHANGED_M)); - fhost = new BTextControl(BRect(15,49,195,90),"Host_Name","Host name:",NULL,new BMessage(kSOMETHING_HAS_CHANGED_M)); - fprimary_dns = new BTextControl(BRect(209,19,399,45),"Primary_DNS","Primary DNS:",NULL,new BMessage(kSOMETHING_HAS_CHANGED_M)); - fsecondary_dns = new BTextControl(BRect(209,49,399,90),"Secondary_DNS","Secondary DNS:",NULL,new BMessage(kSOMETHING_HAS_CHANGED_M)); - - bounds.top = bounds.bottom + 12; - bounds.bottom = 208; - finterfaces = new BBox(bounds,"Network_Interfaces",B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_FRAME_EVENTS); - - fsettings = new BButton(BRect(325,16,400,37),"Settings","Settings...",new BMessage(kSettings_M)); - fclear = new BButton(BRect(325,45,400,67),"Clear","Clear",new BMessage(kClear_M)); - fcustom = new BButton(BRect(325,83,400,107),"Custom","Custom...",new BMessage(kCustom_M)); - //fsettings ->SetEnabled(false); - //fclear ->SetEnabled(false); - - bounds = finterfaces->Bounds(); - bounds.InsetBy(20,20); - bounds.top ++; - bounds.bottom += 6; - bounds.right -= 94; - bounds.left -= 5; - finterfaces_list = new NetListView(bounds,"Interfaces_List"); - BScrollView *interfaces_scroller = new BScrollView("Interfaces_Scroller",finterfaces_list, B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, 0, 1, B_FANCY_BORDER); - - 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); - - BBox *hr = new BBox(BRect(1,261,Bounds().Width()-1,262), "horizontal_rule"); - BBox *vr = new BBox(BRect(133, 274, 134, 299), "vertical_rule"); - - fdomain->SetDivider(70); - fdomain->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); - fhost->SetDivider(70); - fhost->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); - fprimary_dns->SetDivider(80); - fprimary_dns->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); - fsecondary_dns->SetDivider(80); - fsecondary_dns->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); - - fnames ->SetLabel("Names"); - finterfaces ->SetLabel("Network Interfaces"); - fconfigurations ->SetLabel("Configurations"); - fidentity_view ->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - fservices_view ->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - ftabview ->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - fview ->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); - -//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(interfaces_scroller); - finterfaces ->AddChild(fsettings); - finterfaces ->AddChild(fclear); - finterfaces ->AddChild(fcustom); - 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); - fview ->AddChild(hr); - fview ->AddChild(vr); - 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:{ - // Don't Save - break; - } - case 1:{ - // Cancel - return false; - break; - } - case 2:{ - // Save - BackupWin *sav = new BackupWin(); - sav->fparent_window = dynamic_cast (fview->Window()); - sav->Flatten_bak(); - sav->Quit(); - break; - } - default: - break; - } - } - 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/preferences/network/Network.h b/src/preferences/network/Network.h index fd42f04486..0f56f4eaa7 100644 --- a/src/preferences/network/Network.h +++ b/src/preferences/network/Network.h @@ -1,19 +1,11 @@ +#ifndef _NETWORK_H_ +#define _NETWORK_H_ + #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 @@ -30,172 +22,4 @@ */ -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 diff --git a/src/preferences/network/NetworkWindow.cpp b/src/preferences/network/NetworkWindow.cpp new file mode 100644 index 0000000000..25a8dd992a --- /dev/null +++ b/src/preferences/network/NetworkWindow.cpp @@ -0,0 +1,565 @@ +#include "NetworkWindow.h" +#include "NetListView.h" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "InterfaceWin.h" +#include "BackupWindow.h" +#include "LoginInfo.h" + +#define NETWORK_WINDOW_RIGHT 435 +#define NETWORK_WINDOW_BOTTOM 309 + +class RestartWindow : public BWindow +{ +public: + RestartWindow(); + + BView *fView; + BStringView *fRestarting; + BStringView *fWhatsHappening; +}; + + +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(ui_color(B_PANEL_BACKGROUND_COLOR)); + + 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); +} + +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) +{ + // if(!Network_settings) + // { ... + BScreen screen; + + BRect screenframe = screen.Frame(); + float screenx, screeny; + screenx = ((screenframe.right + 1) / 2) - (NETWORK_WINDOW_RIGHT / 2) - 1; + screeny = ((screenframe.bottom + 1) / 2) - (NETWORK_WINDOW_BOTTOM / 2) - 1; + MoveTo(screenx, screeny); + // } + // else + // { + // ... + // } + + BRect bounds = Bounds(); + fView = new BView(bounds,"View",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); + + fRestart = new BButton(BRect(11,274,122,298),"Restart_Networking","Restart Networking",new BMessage(kRestart_Networking_M)); + fRevert = new BButton(BRect(145,274,220,298),"Revert","Revert",new BMessage(kRevert_M)); + fSave = new BButton(BRect(349,274,424,297),"Save","Save",new BMessage(kSave_M)); + fSave->MakeDefault(true); + fSave->SetEnabled(false); + fRevert->SetEnabled(false); + + bounds.bottom = Bounds().Height(); + bounds.top += 10; + bounds.right = Bounds().Width(); + fTabView = new BTabView(bounds,"tab_view", B_WIDTH_FROM_WIDEST); + + fIdentity = new BTab(); + bounds.bottom -= fTabView->TabHeight(); + fIdentityView = new BView(bounds,"Identity",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); + fServicesView = new BView(bounds,"Services",B_FOLLOW_ALL_SIDES,B_WILL_DRAW); + + bounds.top -= 10; + bounds.bottom -= 209; + bounds.left += 11; + bounds.right -= 12; + fNames = new BBox(bounds,"Names",B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_FRAME_EVENTS); + + fDomain = new BTextControl(BRect(15,19,195,50),"Domain_Name","Domain name:",NULL,new BMessage(kSOMETHING_HAS_CHANGED_M)); + fHost = new BTextControl(BRect(15,49,195,90),"Host_Name","Host name:",NULL,new BMessage(kSOMETHING_HAS_CHANGED_M)); + fPrimaryDNS = new BTextControl(BRect(209,19,399,45),"Primary_DNS","Primary DNS:",NULL,new BMessage(kSOMETHING_HAS_CHANGED_M)); + fSecondaryDNS = new BTextControl(BRect(209,49,399,90),"Secondary_DNS","Secondary DNS:",NULL,new BMessage(kSOMETHING_HAS_CHANGED_M)); + + bounds.top = bounds.bottom + 12; + bounds.bottom = 208; + fInterfaces = new BBox(bounds,"Network_Interfaces",B_FOLLOW_LEFT | B_FOLLOW_TOP,B_WILL_DRAW | B_FRAME_EVENTS); + + fSettings = new BButton(BRect(325,16,400,37),"Settings","Settings...",new BMessage(kSettings_M)); + fClear = new BButton(BRect(325,45,400,67),"Clear","Clear",new BMessage(kClear_M)); + fCustom = new BButton(BRect(325,83,400,107),"Custom","Custom...",new BMessage(kCustom_M)); + //fSettings ->SetEnabled(false); + //fClear ->SetEnabled(false); + + bounds = fInterfaces->Bounds(); + bounds.InsetBy(20,20); + bounds.top ++; + bounds.bottom += 6; + bounds.right -= 94; + bounds.left -= 5; + fInterfacesList = new NetListView(bounds,"Interfaces_List"); + BScrollView *interfaces_scroller = new BScrollView("Interfaces_Scroller",fInterfacesList, B_FOLLOW_LEFT | B_FOLLOW_TOP, 0, 0, 1, B_FANCY_BORDER); + + fServices = new BTab(); + fFTPServer = new BCheckBox(BRect(10,20,120,40),"FTP_Server","FTP Server",new BMessage(kSOMETHING_HAS_CHANGED_M)); + fTelnetServer = new BCheckBox(BRect(10,50,120,70),"Telnet_Server","Telnet Server",new BMessage(kSOMETHING_HAS_CHANGED_M)); + fAppleTalk = new BCheckBox(BRect(10,110,120,130),"Apple_Talk","Apple Talk",new BMessage(kSOMETHING_HAS_CHANGED_M)); + fIPForwarding = new BCheckBox(BRect(10,140,120,160),"IP_Forwarding","IP Forwarding",new BMessage(kSOMETHING_HAS_CHANGED_M)); + fLoginInfo = 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; + fConfigurationsList = new NetListView(bounds,"Configurations_List"); + BScrollView *configurations_scroller = new BScrollView("Configurations_Scroller",fConfigurationsList); + + 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); + + BBox *hr = new BBox(BRect(1,261,Bounds().Width()-1,262), "horizontal_rule"); + BBox *vr = new BBox(BRect(133, 274, 134, 299), "vertical_rule"); + + fDomain->SetDivider(70); + fDomain->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); + fHost->SetDivider(70); + fHost->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); + fPrimaryDNS->SetDivider(80); + fPrimaryDNS->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); + fSecondaryDNS->SetDivider(80); + fSecondaryDNS->SetAlignment(B_ALIGN_RIGHT,B_ALIGN_LEFT); + + fNames ->SetLabel("Names"); + fInterfaces ->SetLabel("Network Interfaces"); + fConfigurations ->SetLabel("Configurations"); + fIdentityView ->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + fServicesView ->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + fTabView ->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + fView ->SetViewColor(ui_color(B_PANEL_BACKGROUND_COLOR)); + + // Casts an AddEverything + fTabView->AddTab(fIdentityView,fIdentity); + fTabView->AddTab(fServicesView,fServices); + + fNames->AddChild(fDomain); + fNames->AddChild(fHost); + fNames->AddChild(fPrimaryDNS); + fNames->AddChild(fSecondaryDNS); + + fInterfaces->AddChild(interfaces_scroller); + fInterfaces->AddChild(fSettings); + fInterfaces->AddChild(fClear); + fInterfaces->AddChild(fCustom); + + fIdentityView->AddChild(fNames); + fIdentityView->AddChild(fInterfaces); + + fServicesView->AddChild(fFTPServer); + fServicesView->AddChild(fTelnetServer); + fServicesView->AddChild(fIPForwarding); + fServicesView->AddChild(fAppleTalk); + fServicesView->AddChild(fLoginInfo); + fServicesView->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); + fView->AddChild(hr); + fView->AddChild(vr); + 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(Bounds()); + bak->fParentWindow = dynamic_cast (fView->Window()); + bak->SaveBackup(); + bak->Quit(); + fRevert->SetEnabled(false); + fSave->SetEnabled(false); + break; + } + case kSettings_M:{ + + BRect r(Frame()); + r.right = r.left + 325; + r.bottom = r.top + 225; + + NetListItem *selection = dynamic_cast (fInterfacesList->ItemAt(fInterfacesList->CurrentSelection())); + if(!selection) + break; + + InterfaceWin *win = new InterfaceWin(r,selection->fData); + r=win->Frame(); + win->MoveBy((Frame().Width()-r.Width())/2, + (Frame().Height()-r.Height())/2); + + win->fParentWindow = dynamic_cast (fView->Window()); + + if (selection->fData.fEnabled) + win->fEnabled->SetValue(1); + + if (selection->fData.fDHCP) + win->fDHCP->SetValue(1); + else + win->fManual->SetValue(1); + + win->fName->SetText(selection->fData.fPrettyName.String()); + win->fIPAddress->SetText(selection->fData.fIPAddress.String()); + win->fNetMask->SetText(selection->fData.fNetMask.String()); + + win->fChanged = false; + + win->fIPAddress->SetTarget(win); + win->fNetMask->SetTarget(win); + win->fGateway->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->fParentWindow = dynamic_cast (fView->Window()); + login_info_pop->fName->SetText(fusername.String()); + login_info_pop->fName->MakeFocus(); + login_info_pop->Show(); + break; + } + case kBackup_M:{ + + BRect r(Frame()); + r.right = r.left + 260; + r.bottom = r.top + 77; + r.OffsetBy( (Frame().Width()-260)/2, (Frame().Height()-77)/2); + BackupWin *backup_pop = new BackupWin(r); + backup_pop->fParentWindow = dynamic_cast (fView->Window()); + backup_pop->Show(); + break; + } + case kRestore_M:{ + BStringItem *string_item = dynamic_cast (fConfigurationsList->ItemAt(fConfigurationsList->CurrentSelection())); + GetEverything(string_item->Text()); + PostMessage(kSOMETHING_HAS_CHANGED_M); + break; + } + case kDelete_M:{ + DeleteConfigFile(); + LoadConfigEntries(); + fConfigurationsList->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:{ + // Don't Save + break; + } + case 1:{ + // Cancel + return false; + break; + } + case 2:{ + // Save + BackupWin *sav = new BackupWin(Bounds()); + sav->fParentWindow = dynamic_cast (fView->Window()); + sav->SaveBackup(); + sav->Quit(); + break; + } + default: + break; + } + } + be_app->PostMessage(B_QUIT_REQUESTED); + return true; +} + +void NetworkWindow::DeleteConfigFile() +{ + BAlert *alert = new BAlert("Alert","Really delete networking configuration?", + "Delete","Cancel"); + int32 result = alert->Go(); + if (result == 0) { + + BStringItem *item = dynamic_cast (fConfigurationsList->ItemAt(fConfigurationsList->CurrentSelection())); + + BString path; + path = "/boot/home/config/settings/network."; + path << item->Text(); + + BEntry entry(path.String()); + entry.Remove(); + } +} + +void NetworkWindow::LoadConfigEntries() +{ + fConfigurationsList->MakeEmpty(); + + BDirectory settings("/boot/home/config/settings/"); + BEntry entry; + + if (settings.InitCheck() == B_OK) { + + while (settings.GetNextEntry(&entry) == B_OK) { + + // All the config files start with "network." so we only compare the + // first 8 characters + char buffer[9]; + entry.GetName(buffer); + buffer[8]='\0'; + + if (strcmp(buffer,"network.") == 0) { + + BString string; + char name[B_FILE_NAME_LENGTH]; + entry.GetName(name); + string << name; + string = string.Remove(0,8); + + BStringItem *item = new BStringItem(string.String()); + fConfigurationsList->AddItem(item); + + } + } + } +} + +void NetworkWindow::GetEverything(const char *bakname) +{ +/* +// 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 exist.\n" + "It should be located at/boot/home/config/settings/network ","OK"); + alert->Go(); + } + else { + // This function being used when pressing "Revert" so first we need to + // empty things before setting the new values + Lock(); + fInterfacesList->MakeEmpty(); + fFTPServer ->SetValue(0); + fTelnetServer ->SetValue(0); + fAppleTalk ->SetValue(0); + fIPForwarding ->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()); + fPrimaryDNS ->SetText(GLOBAL[9].String()); + fSecondaryDNS ->SetText(GLOBAL[10].String()); + + if (GLOBAL[5]== "1") fFTPServer->SetValue(1); //Now the BCheckBoxes + if (GLOBAL[6]== "1") fIPForwarding->SetValue(1); + if (GLOBAL[8]== "1") fTelnetServer->SetValue(1); + + for (i=0;i<(unsigned)number_of_interfaces;i++){ //Now the interfaces list + BString string = INTERFACES[i][3]; + string<<"->"<"<<"State(Not implemented yet)"; + NetListItem *item = new NetListItem(string.String()); + + item->fData.fIPAddress = INTERFACES[i][3]; + item->fData.fNetMask = INTERFACES[i][4]; + item->fData.fPrettyName = INTERFACES[i][5]; + item->fData.fEnabled = atoi(INTERFACES[i][6].String()); + item->fData.fDHCP = atoi(INTERFACES[i][7].String()); + + fInterfacesList->AddItem(item); + } + fInterfacesList->Select(0L); + + Unlock(); + +//And save some of them + fusername = GLOBAL[2]; + } +*/ +} diff --git a/src/preferences/network/NetworkWindow.h b/src/preferences/network/NetworkWindow.h new file mode 100644 index 0000000000..c2514cf4b3 --- /dev/null +++ b/src/preferences/network/NetworkWindow.h @@ -0,0 +1,91 @@ +#ifndef NETWORK_WINDOW_H +#define NETWORK_WINDOW_H + +#include +#include +#include +#include +#include +#include +#include +#include "ConfigData.h" + +class NetListView; + +class NetworkWindow : public BWindow +{ +public: + NetworkWindow(); + + BView *fView; + BTabView *fTabView; + + BButton *fRestart; + BButton *fRevert; + BButton *fSave; + + BTab *fIdentity; + BView *fIdentityView; + + BBox *fNames; + BTextControl *fDomain; + BTextControl *fHost; + BTextControl *fPrimaryDNS; + BTextControl *fSecondaryDNS; + + BBox *fInterfaces; + NetListView *fInterfacesList; + BButton *fSettings; + BButton *fClear; + BButton *fCustom; + + BTab *fServices; + BView *fServicesView; + BCheckBox *fFTPServer; + BCheckBox *fTelnetServer; + BCheckBox *fAppleTalk; + BCheckBox *fIPForwarding; + BButton *fLoginInfo; + + BBox *fConfigurations; + NetListView *fConfigurationsList; + 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 + info 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 DeleteConfigFile(); + void LoadConfigEntries(); + 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. + ConfigData fData; +}; + +#endif diff --git a/src/preferences/network/funcs.cpp b/src/preferences/network/funcs.cpp deleted file mode 100644 index 5ea27a7392..0000000000 --- a/src/preferences/network/funcs.cpp +++ /dev/null @@ -1,301 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#include "Network.h" - -#define B_GREY 216,216,216 - - -void BackupWin::Flatten_bak(const char *bak_name) -{ -/*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) -{ -//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<(unsigned)number_of_interfaces;i++){ //Now the interfaces list - BString string = INTERFACES[i][3]; - string<<"->"<"<<"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]; - } -}