[PC-BSD Commits] r2071 - pcbsd/trunk/wificonfig

svn at pcbsd.org svn at pcbsd.org
Mon Jun 9 11:20:31 PDT 2008


Author: tim
Date: 2008-06-09 11:20:31 -0700 (Mon, 09 Jun 2008)
New Revision: 2071

Modified:
   pcbsd/trunk/wificonfig/wificonfig.pro
   pcbsd/trunk/wificonfig/wificonfigwidgetbase.ui
   pcbsd/trunk/wificonfig/wificonfigwidgetbase.ui.h
Log:
Refactored wificonfig to make use of libpcbsd

Modified: pcbsd/trunk/wificonfig/wificonfig.pro
===================================================================
--- pcbsd/trunk/wificonfig/wificonfig.pro	2008-06-09 17:57:17 UTC (rev 2070)
+++ pcbsd/trunk/wificonfig/wificonfig.pro	2008-06-09 18:20:31 UTC (rev 2071)
@@ -3,8 +3,10 @@
 
 CONFIG	+= qt warn_on release
 
-LIBS	+= -lkdeui
+LIBS	+= -lkdeui -lpcbsd
 
+INCLUDEPATH	+= /PCBSD/includes
+
 SOURCES	+= main.cpp
 
 FORMS	= wificonfigwidgetbase.ui \

Modified: pcbsd/trunk/wificonfig/wificonfigwidgetbase.ui
===================================================================
--- pcbsd/trunk/wificonfig/wificonfigwidgetbase.ui	2008-06-09 17:57:17 UTC (rev 2070)
+++ pcbsd/trunk/wificonfig/wificonfigwidgetbase.ui	2008-06-09 18:20:31 UTC (rev 2071)
@@ -1009,6 +1009,9 @@
     <include location="local" impldecl="in declaration">qdesktopwidget.h</include>
     <include location="local" impldecl="in declaration">qapplication.h</include>
     <include location="local" impldecl="in declaration">qprocess.h</include>
+    <include location="global" impldecl="in declaration">qregexp.h</include>
+    <include location="global" impldecl="in declaration">netif.h</include>
+    <include location="global" impldecl="in declaration">utils.h</include>
     <include location="local" impldecl="in implementation">wificonfigwidgetbase.ui.h</include>
 </includes>
 <variables>

Modified: pcbsd/trunk/wificonfig/wificonfigwidgetbase.ui.h
===================================================================
--- pcbsd/trunk/wificonfig/wificonfigwidgetbase.ui.h	2008-06-09 17:57:17 UTC (rev 2070)
+++ pcbsd/trunk/wificonfig/wificonfigwidgetbase.ui.h	2008-06-09 18:20:31 UTC (rev 2071)
@@ -672,165 +672,66 @@
 
 QString wificonfigWidgetBase::getNetmaskForIdent( QString ident )
 {
-int num;
-    QString RealIP, tmp;
-    
-	QString command = "ifconfig " +ident + " | grep \"netmask\"";
-	QString inputLine = getLineFromCommandOutput(command);
-	QString net= "";
-	
-	if (inputLine != "" && inputLine.find("netmask ") != -1){
-		
-		net = inputLine.remove(0, inputLine.find("netmask ") + 8);
-		net.truncate(net.find(" "));
-		
-		num = net.mid(2, 2).toInt(0, 16);
-		tmp.setNum(num);
-		RealIP = tmp;
-		
-		num = net.mid(4, 2).toInt(0, 16);
-		tmp.setNum(num);
-		RealIP = RealIP + "." + tmp ;
-		
-		num = net.mid(6, 2).toInt(0, 16);
-		tmp.setNum(num);
-		RealIP = RealIP + "." + tmp ;
-		
-		num = net.mid(8, 2).toInt(0, 16);
-		tmp.setNum(num);
-		RealIP = RealIP + "." + tmp ;
-		
-		//QMessageBox::information( this, "Application name",  "IP: " + RealIP );
-		
-	}
-	
-	return RealIP;
-
+   NetworkInterface ifr(ident);
+   return ifr.netmaskAsString();
 }
 
 
 QString wificonfigWidgetBase::getOutErrorsForIdent( QString ident )
 {
-         QString command = "netstat -n -I " +ident + " | grep \"Link\"";
-	QString inputLine = getLineFromCommandOutput(command);
-	QString packets = "";
-	
-	if (inputLine != "" && inputLine.find("Link") != -1){
-		inputLine = inputLine.simplifyWhiteSpace();
-		packets = inputLine.section(' ', 7, 7 );
-	}
-	
-	return packets;    
+   NetworkInterface ifr(ident);
+   return QString::number(ifr.errorsRx());
 }
 
 
 QString wificonfigWidgetBase::getOutPacketsForIdent( QString ident )
 {
-        QString command = "netstat -n -I " +ident + " | grep \"Link\"";
-	QString inputLine = getLineFromCommandOutput(command);
-	QString packets = "";
-	
-	if (inputLine != "" && inputLine.find("Link") != -1){
-		inputLine = inputLine.simplifyWhiteSpace();
-		packets = inputLine.section(' ', 6, 6 );
-	}
-	
-	return packets;
+   NetworkInterface ifr(ident);
+   return QString::number(ifr.packetsRx());
 }
 
 
 QString wificonfigWidgetBase::getInErrorsForIdent( QString ident )
 {
-        QString command = "netstat -n -I " +ident + " | grep \"Link\"";
-	QString inputLine = getLineFromCommandOutput(command);
-	QString packets = "";
-	
-	if (inputLine != "" && inputLine.find("Link") != -1){
-		inputLine = inputLine.simplifyWhiteSpace();
-		packets = inputLine.section(' ', 5, 5 );
-	}
-	
-	return packets;
+   NetworkInterface ifr(ident);
+   return QString::number(ifr.errorsTx());
 }
 
 
 QString wificonfigWidgetBase::getInPacketsForIdent( QString ident )
 {
-        QString command = "netstat -n -I " +ident + " | grep \"Link\"";
-	QString inputLine = getLineFromCommandOutput(command);
-	QString packets = "";
-	
-	if (inputLine != "" && inputLine.find("Link") != -1){
-		inputLine = inputLine.simplifyWhiteSpace();
-		packets = inputLine.section(' ', 4, 4 );
-	}
-	
-	return packets;
+   NetworkInterface ifr(ident);
+   return QString::number(ifr.packetsTx());
 }
 
 
 QString wificonfigWidgetBase::getStatusForIdent( QString ident )
 {
-    	QString command = "ifconfig " +ident + " | grep \"status\"";
-	QString inputLine = getLineFromCommandOutput(command);
-	QString status = "";
-	
-	if (inputLine != "" && inputLine.find("status") != -1){
-		
-		status = inputLine.remove(0, inputLine.find(" ") + 1);
-		status.truncate(inputLine.find("\n") );
-	
-	}
-	
-	return status;
+   NetworkInterface ifr(ident);
+   return ifr.mediaStatusAsString();
 }
 
 
 QString wificonfigWidgetBase::getMacForIdent( QString ident )
 {
-    	QString command = "ifconfig " +ident + " | grep \"ether\"";
-	QString inputLine = getLineFromCommandOutput(command);
-	QString ether = "";
-	
-	if (inputLine != "" && inputLine.find("ether") != -1){
-		
-		ether = inputLine.remove(0, inputLine.find(" ") + 1);
-	
-	}
-	
-	return ether;
+   NetworkInterface ifr(ident);
+   return ifr.macAsString();
 }
 
 
 QString wificonfigWidgetBase::getIpForIdent( QString ident )
 {
-	QString command = "ifconfig " +ident + " | grep \"inet \"";
-	QString inputLine = getLineFromCommandOutput(command);
-	QString ip= "";
-	
-	if (inputLine != "" && inputLine.find("inet ") != -1){
-		
-		ip = inputLine.remove(0, inputLine.find("inet ") + 5);
-		ip.truncate(ip.find(" "));
-		
-		
-	}
-	
-	return ip;
+   NetworkInterface ifr(ident);
+   return ifr.ipAsString();
 }
 
 
 QString wificonfigWidgetBase::getNameForIdent( QString ident )
 {
-	QString command = "dmesg | grep " + ident;
-	QString inputLine = getLineFromCommandOutput(command);
-	QString name = "";
-	
-	inputLine = inputLine.remove (0, inputLine.find("<") + 1);
-	inputLine.truncate(inputLine.find(">"));
-	name = inputLine;
-	
-	return name;	
+   uint pos = ident.find(QRegExp("[0-9]+$"));
+   QString devNum = ident.mid(pos);
+   ident.truncate(pos);
+   return Utils::sysctl("dev." + ident + "." + devNum + ".%desc");
 }
 
 



More information about the Commits mailing list