⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setip_form.cpp.bak

📁 在S3C2410上基于Qt的设置IP程序
💻 BAK
字号:
/****************************************************************************** Form implementation generated from reading ui file 'setip_form.ui'**** Created: Mon May 29 18:24:22 2006**      by:  The User Interface Compiler (uic)**** WARNING! All changes made in this file will be lost!****************************************************************************/#include "setip_form.h"#include <qlabel.h>#include <qlineedit.h>#include <qpushbutton.h>#include <qradiobutton.h>#include <qlayout.h>#include <qvariant.h>#include <qtooltip.h>#include <qwhatsthis.h>#define Run(al1, al2, al3, al4) { char *arglist[4];  arglist[0]=al1; arglist[1]=al2; arglist[2]=al3; arglist[3]=al4; if(execute(arglist))    return 1; }int execute(char *arglist[]){  int pid,exitstatus;  char buf[100];    pid =fork();  switch (pid) {    case -1:     perror("fork failed");      return 1;    case 0:      execvp(arglist[0],arglist);      perror("execvp failed");      return 1;    default:      while( wait(&exitstatus)!=pid)        ;     printf("child exited with status %d,%d\n",exitstatus>>8,exitstatus&0377);     if ((exitstatus>>8)){          QMessageBox::information(this,"execute error","execute error!");	  return 1;       }   }   return 0; }  static int check_net(){   int ch;   char buf[128];   FILE *fd;    if((fd=fopen("/proc/net/dev","r"))==NULL)	    {	       printf(0,"打不开文件/proc/net/dev");	       return 1;	       }   while(!feof(fd)){     fgets(buf,128,fd);     if (strstr(buf,"eth0:")!=NULL)     {        printf("net on.");	return 0;      }   }    printf("net off.");    return 1;}int open_net(){   int ch;   char *arglist[4], buf[20];   int fd;   TERM_clearscreen();      if(check_net()==0)   { 	  TERM_displayxy(5,2,NORMALDISPLAY,"网络已经打开,按任意键退出。\r\n");             TERM_getkey(KEEPWAITING);          return 0;   }   	   memset(buf,'\0',20);   if((fd=open("/mnt/a/etc/mc2005IP",O_RDWR|O_CREAT))==-1){        TERM_display(0,"cannot open /mnt/a/etc/mc2005IP");	return -1;	}   read(fd,buf,20);   TERM_displayxy(5,2,NORMALDISPLAY,"请输入IP地址,回车确认:");    int i=strlen(buf);   while(1)    {                    TERM_displayxy(0,3,NORMALDISPLAY,"                               ");	    TERM_displayxy(5,3,NORMALDISPLAY,buf);	    ch=TERM_getkey(KEEPWAITING);	    if(ch==KEY_ENTER)	    {	      if(check_ip(buf))	      {	        TERM_displayxy(5,3,NORMALDISPLAY,"输入IP地址错误,请重输 ");		ch=TERM_getkey(KEEPWAITING);	        continue;	      }	      else	        break;	    }	    if ((ch==KEY_BACKSPACE)&&(i>0)){	        i--;		buf[i]=0;		}	    else if (isdigit(ch) || ch=='.'){              buf[i]=ch;	      buf[i+1]=0;	      i++;	      }      }      lseek(fd,(off_t)0,0);      int n=write(fd,buf,strlen(buf)+1);      close(fd);      Run ("mc2005_pp","ETHER","ON",NULL);      sleep(5);      Run("insmod","/lib/modules/2.6.12-rc4/at91_ether.ko",NULL,NULL);      Run("/sbin/ifconfig","eth0",buf,NULL);      TERM_displayxy(5,12,NORMALDISPLAY,"网络启动成功,按任意键退出。\r\n");         while(TERM_getkey(2)==-1);      return 0;}int close_net(){   char *arglist[4];      TERM_clearscreen();   if(check_net())   { 	  TERM_displayxy(5,2,NORMALDISPLAY,"网络没有打开,按任意键退出。\r\n");             TERM_getkey(KEEPWAITING);          return 0;   }   TERM_displayxy(5,4,NORMALDISPLAY,"正在关闭以太网......\r\n");    Run ("/sbin/ifconfig","eth0","down",NULL);   Run ("rmmod","at91_ether",NULL,NULL);   Run ("mc2005_pp","ETHER","OFF",NULL);   TERM_displayxy(5,6,NORMALDISPLAY,"网络关闭成功,按任意键退出。\r\n");      TERM_getkey(KEEPWAITING);   return 0;}/*  *  Constructs a setip_form which is a child of 'parent', with the  *  name 'name' and widget flags set to 'f'  * *  The dialog will by default be modeless, unless you set 'modal' to *  TRUE to construct a modal dialog. */  setip_form::setip_form( QWidget* parent,  const char* name, bool modal, WFlags fl )    : QDialog( parent, name, modal, fl ){    if ( !name )	setName( "setip_form" );    resize( 289, 161 );     setBaseSize( QSize( 320, 240 ) );    setCaption( tr( "Set IP" ) );    OK_Button = new QPushButton( this, "OK_Button" );    OK_Button->setGeometry( QRect( 10, 110, 80, 30 ) );     OK_Button->setText( tr( "OK" ) );    Cancel_Button = new QPushButton( this, "Cancel_Button" );    Cancel_Button->setGeometry( QRect( 200, 110, 80, 30 ) );     Cancel_Button->setText( tr( "Cancel" ) );    LineEdit1 = new QLineEdit( this, "LineEdit1" );    LineEdit1->setGeometry( QRect( 160, 30, 120, 22 ) );     LineEdit1->setText( tr( "192.168.0.113" ) );    IP_Label1 = new QLabel( this, "IP_Label1" );    IP_Label1->setGeometry( QRect( 140, 30, 20, 21 ) );     IP_Label1->setText( tr( "IP " ) );    RadioButton1 = new QRadioButton( this, "RadioButton1" );    RadioButton1->setGeometry( QRect( 10, 30, 100, 21 ) );     RadioButton1->setText( tr( "Ethernet On" ) );    RadioButton2 = new QRadioButton( this, "RadioButton2" );    RadioButton2->setGeometry( QRect( 10, 60, 100, 21 ) );     RadioButton2->setText( tr( "Ethernet Off" ) );        // signals and slots connections    connect( Cancel_Button, SIGNAL( clicked() ), this, SLOT( accept() ) );    connect( OK_Button, SIGNAL( clicked() ), this, SLOT( ok_slot() ) );}/*   *  Destroys the object and frees any allocated resources */setip_form::~setip_form(){    // no need to delete child widgets, Qt does it all for us}void setip_form::ok_slot(){    qWarning( "setip_form::ok_slot(): Not implemented yet!" );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -