📄 networkpanel.cpp
字号:
#include "NetworkPanel.h"#include "ConfigFrame.h"BEGIN_EVENT_TABLE(NetworkPanel, wxPanel) EVT_PAINT(NetworkPanel::OnPaint) EVT_BUTTON(ID_Button_SetNetWork, NetworkPanel::OnButtonSetNetWork) EVT_BUTTON(ID_Button_Back, NetworkPanel::OnButtonBack)END_EVENT_TABLE()NetworkPanel::NetworkPanel(wxWindow *parent, const wxPoint& point, const wxSize& size, long style) : wxPanel(parent, -1,point,size,style, _("")){ pStaticBox = new wxStaticBox(this,-1,_("网络"),wxPoint(300,200),wxSize(400,200)); pTxt1 = new wxStaticText(this,-1,_("IP地址"),wxPoint(350,235),wxSize(90,25),wxALIGN_RIGHT); pEdit1 = new wxTextCtrl(this,-1,_(""),wxPoint(450,235),wxSize(150,25)); pTxt2 = new wxStaticText(this,-1,_("子网掩码"),wxPoint(350,265),wxSize(90,25),wxALIGN_RIGHT); pEdit2 = new wxTextCtrl(this,-1,_(""),wxPoint(450,265),wxSize(150,25)); pTxt3 = new wxStaticText(this,-1,_("网关"),wxPoint(350,295),wxSize(90,25),wxALIGN_RIGHT); pEdit3 = new wxTextCtrl(this,-1,_(""),wxPoint(450,295),wxSize(150,25)); pTxt4 = new wxStaticText(this,-1,_("DNS"),wxPoint(350,325),wxSize(90,25),wxALIGN_RIGHT); pEdit4 = new wxTextCtrl(this,-1,_(""),wxPoint(450,325),wxSize(150,25)); pButtonSetNetWork = new wxButton(this,ID_Button_SetNetWork,_("保存设置"),wxPoint(450,420),wxSize(100,30)); pButtonBack = new wxButton(this,ID_Button_Back,_("返回"),wxPoint(600,450),wxSize(100,35)); pButtonBack->Show(0); ReInitNetWorkInfo(); pEdit1->SetValue(strAddr); pEdit2->SetValue(strMask); pEdit3->SetValue(strGateway); pEdit4->SetValue(strDNS);}void NetworkPanel::OnPaint(wxPaintEvent& event){}NetworkPanel::~NetworkPanel(){}void NetworkPanel::ReInitNetWorkInfo(){ strAddr = _(""); strMask = _(""); strGateway = _(""); strDNS = _(""); wxString str; // 打开配置文件 wxFileInputStream ConfigInStream(_("/etc/sysconfig/network-scripts/ifcfg-eth0")); if(!ConfigInStream.Ok())//检查配置文件是否存在 { return; } // 建立到配置文件的连接,同时指定转换为UTF8格式 wxFileConfig config(ConfigInStream, wxConvUTF8); if(!config.Read(_("IPADDR"),&strAddr)) { strAddr = _(""); } if(!config.Read(_("NETMASK"),&strMask)) { strMask = _(""); } if(!config.Read(_("GATEWAY"),&strGateway)) { strGateway = _(""); } // 打开配置文件 wxTextFile file(_("/etc/resolv.conf")); if(!file.Open()) { return; } for ( str = file.GetFirstLine(); !file.Eof(); str = file.GetNextLine()) { if(str.SubString(0,9) == _("nameserver") && str.Length() > 10) { str = str.SubString(10,str.Length()); str.Trim(true); str.Trim(false); strDNS = str; break; } }}void NetworkPanel::OnButtonSetNetWork(wxCommandEvent& event){ strAddr = pEdit1->GetValue(); strMask = pEdit2->GetValue(); strGateway = pEdit3->GetValue(); strDNS = pEdit4->GetValue(); // 打开配置文件 wxFileInputStream ConfigInStream(_("/etc/sysconfig/network-scripts/ifcfg-eth0")); if(!ConfigInStream.Ok())//检查配置文件是否存在 { return; } // 建立到配置文件的连接,同时指定转换为UTF8格式 wxFileConfig config(ConfigInStream, wxConvUTF8); if(!config.Write(_("IPADDR"),&strAddr)) { } if(!config.Write(_("NETMASK"),&strMask)) { } if(!config.Write(_("GATEWAY"),&strGateway)) { } // 打开配置文件 wxTextFile file(_("/etc/resolv.conf")); if(!file.Open()) { return; } file.Clear(); file.AddLine(_("nameserver ")+strDNS); file.Write(); file.Close(); system("service network restart"); system("mount /dev/hda1 /mnt"); system("cp -f /etc/sysconfig/network-scripts/ifcfg-eth0 /mnt/network/"); system("cp /etc/resolv.conf /mnt/network/"); system("umount /mnt");}void NetworkPanel::OnButtonBack(wxCommandEvent& event){ ConfigFrame* pMainFrame = (ConfigFrame*)(this->GetParent()->GetParent()->GetParent()); pMainFrame->ShowListPage();}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -