summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/net/networksetup/TODO2
-rw-r--r--noncore/net/networksetup/interface.cpp77
-rw-r--r--noncore/net/networksetup/interface.h31
-rw-r--r--noncore/net/networksetup/interfaceadvanced.ui11
-rw-r--r--noncore/net/networksetup/interfaceinformationimp.cpp51
-rw-r--r--noncore/net/networksetup/interfaceinformationimp.h6
-rw-r--r--noncore/net/networksetup/mainwindowimp.cpp43
-rw-r--r--noncore/net/networksetup/wlan/wlanmodule.cpp4
-rw-r--r--noncore/settings/networksettings/TODO2
-rw-r--r--noncore/settings/networksettings/interface.cpp77
-rw-r--r--noncore/settings/networksettings/interface.h31
-rw-r--r--noncore/settings/networksettings/interfaceadvanced.ui11
-rw-r--r--noncore/settings/networksettings/interfaceinformationimp.cpp51
-rw-r--r--noncore/settings/networksettings/interfaceinformationimp.h6
-rw-r--r--noncore/settings/networksettings/mainwindowimp.cpp43
-rw-r--r--noncore/settings/networksettings/wlan/wlanmodule.cpp4
16 files changed, 258 insertions, 192 deletions
diff --git a/noncore/net/networksetup/TODO b/noncore/net/networksetup/TODO
index 7386646..c8e2989 100644
--- a/noncore/net/networksetup/TODO
+++ b/noncore/net/networksetup/TODO
@@ -1,8 +1,10 @@
+Write a class that parses /proc and not ifconfig
+
[ ] Wlanmodule needs to check if an interface supports wireless
extensions.
[x] When you set options in wlanmodule, hit OK, it exits all of
networksetup, doesnt bring you back to the main screen.
[x] Wlanmodule isnt writing out wireless.opts
[ ] Need a means of bringing an interface up and down (calling
out ifup/ifdown) from the gui.
-Ben- Click information, then click up or down... :-D
diff --git a/noncore/net/networksetup/interface.cpp b/noncore/net/networksetup/interface.cpp
index 1f32093..1e01da4 100644
--- a/noncore/net/networksetup/interface.cpp
+++ b/noncore/net/networksetup/interface.cpp
@@ -1,188 +1,231 @@
#include "interface.h"
#include <qdatetime.h>
#include <qfile.h>
#include <qdir.h>
#include <qfileinfo.h>
#include <qtextstream.h>
#define IFCONFIG "/sbin/ifconfig"
#define HDCP_INFO_DIR "/etc/dhcpc"
#include <stdio.h>
#include <stdlib.h>
-Interface::Interface(QString name, bool newSatus): status(newSatus), attached(false), interfaceName(name), hardareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){
+Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), status(newSatus), attached(false), hardareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){
refresh();
}
/**
+ * Set status
+ * @param newStatus - the new status
+ * emit updateInterface
+ */
+void Interface::setStatus(bool newStatus){
+ if(status != newStatus){
+ status = newStatus;
+ refresh();
+ }
+};
+
+/**
+ * Set if attached or not (802.11 card pulled out for example)
+ * @param isAttached - if attached
+ * emit updateInterface
+ */
+void Interface::setAttached(bool isAttached){
+ attached = isAttached;
+ emit(updateInterface(this));
+};
+
+/**
+ * Set Hardware name
+ * @param name - the new name
+ * emit updateInterface
+ */
+void Interface::setHardwareName(QString name){
+ hardareName = name;
+ emit(updateInterface(this));
+};
+
+/**
+ * Set Module owner
+ * @param owner - the new owner
+ * emit updateInterface
+ */
+void Interface::setModuleOwner(Module *owner){
+ moduleOwner = owner;
+ emit(updateInterface(this));
+};
+
+
+/**
* Try to start the interface.
- * @return bool true if successfull.
*/
-bool Interface::start(){
+void Interface::start(){
// check to see if we are already running.
- if(status)
- return false;
+ if(true == status)
+ return;
int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1());
+ // See if it was successfull...
if(ret != 0)
- return false;
+ return;
status = true;
refresh();
- return true;
}
/**
* Try to stop the interface.
- * @return bool true if successfull.
*/
-bool Interface::stop(){
+void Interface::stop(){
// check to see if we are already stopped.
- if(status == false)
- return false;
+ if(false == status)
+ return;
int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1());
if(ret != 0)
- return false;
+ return;
status = true;
refresh();
- return true;
}
+
/**
* Try to restart the interface.
- * @return bool true if successfull.
*/
-bool Interface::restart(){
- return (stop() && start());
+void Interface::restart(){
+ stop();
+ start();
}
/**
* Try to refresh the information about the interface.
* First call ifconfig, then check the dhcp-info file
* @return bool true if successfull.
*/
bool Interface::refresh(){
// See if we are up.
if(status == false){
macAddress = "";
ip = "0.0.0.0";
subnetMask = "0.0.0.0";
broadcast = "";
dhcp = false;
dhcpServerIp = "";
leaseObtained = "";
leaseExpires = "";
+ emit(updateInterface(this));
return true;
}
QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName);
int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(interfaceName).arg(fileName).latin1());
if(ret != 0){
qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1());
return false;
}
QFile file(fileName);
if (!file.open(IO_ReadOnly)){
qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
return false;
}
// Set to the defaults
macAddress = "";
ip = "0.0.0.0";
subnetMask = "0.0.0.0";
broadcast = "";
QTextStream stream( &file );
QString line;
while ( !stream.eof() ) {
line = stream.readLine();
if(line.contains("HWaddr")){
int mac = line.find("HWaddr");
macAddress = line.mid(mac+7, line.length());
}
if(line.contains("inet addr")){
int ipl = line.find("inet addr");
int space = line.find(" ", ipl+10);
ip = line.mid(ipl+10, space-ipl-10);
}
if(line.contains("Mask")){
int mask = line.find("Mask");
subnetMask = line.mid(mask+5, line.length());
}
if(line.contains("Bcast")){
int mask = line.find("Bcast");
int space = line.find(" ", mask+6);
broadcast = line.mid(mask+6, space-mask-6);
}
}
file.close();
QFile::remove(fileName);
// DHCP TESTING
// reset DHCP info
dhcpServerIp = "";
leaseObtained = "";
leaseExpires = "";
dhcp = false;
QString dhcpDirectory(HDCP_INFO_DIR);
QDir d(dhcpDirectory);
if(!d.exists(dhcpDirectory))
dhcpDirectory = "/var/run";
// See if we have
QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName));
// If there is no DHCP information then exit now with no errors.
if(!QFile::exists(dhcpFile)){
+ emit(updateInterface(this));
return true;
}
file.setName(dhcpFile);
if (!file.open(IO_ReadOnly)){
qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
return false;
}
// leaseTime and renewalTime and used if pid and deamon exe can be accessed.
int leaseTime = 0;
int renewalTime = 0;
stream.setDevice( &file );
while ( !stream.eof() ) {
line = stream.readLine();
if(line.contains("DHCPSIADDR="))
dhcpServerIp = line.mid(11, line.length());
if(line.contains("LEASETIME="))
leaseTime = line.mid(10, line.length()).toInt();
if(line.contains("RENEWALTIME="))
renewalTime = line.mid(12, line.length()).toInt();
}
file.close();
//qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1());
//qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1());
// Get the pid of the deamond
dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(interfaceName));
file.setName(dhcpFile);
if (!file.open(IO_ReadOnly)){
qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
return false;
}
int pid = -1;
stream.setDevice( &file );
while ( !stream.eof() ) {
line = stream.readLine();
pid = line.toInt();
}
file.close();
if( pid == -1){
qDebug("Interface: Could not get pid of dhcpc deamon.");
return false;
}
@@ -190,53 +233,55 @@ bool Interface::refresh(){
fileName = (QString("/proc/%1/stat").arg(pid));
file.setName(fileName);
stream.setDevice( &file );
if (!file.open(IO_ReadOnly)){
qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
return false;
}
while ( !stream.eof() ) {
line = stream.readLine();
}
file.close();
long time = 0;
// Grab the start time
// pid com state ppid pgrp session tty_nr tpgid flags
sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u "
// minflt cminflt majflt cmajflt utime stime cutime cstime priority
"%*u %*u %*u %*u %*u %*u %*d %*d %*d "
// nice 0 itrealvalue starttime
"%*d %*d %*d %lu", (long*) &time);
time = time/100;
QDateTime datetime(QDateTime::currentDateTime());
// Get the uptime of the computer.
QFile f("/proc/uptime");
if ( f.open(IO_ReadOnly) ) { // file opened successfully
QTextStream t( &f ); // use a text stream
int sec = 0;
t >> sec;
datetime = datetime.addSecs((-1*sec));
f.close();
}
else{
qDebug("Interface: Can't open /proc/uptime to retrive uptime.");
return false;
}
datetime = datetime.addSecs(time);
//qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1());
// Calculate the start and renew times
leaseObtained = datetime.toString();
// Calculate the start and renew times
datetime = datetime.addSecs(leaseTime);
leaseExpires = datetime.toString();
dhcp = true;
+
+ emit(updateInterface(this));
return true;
}
// interface.cpp
diff --git a/noncore/net/networksetup/interface.h b/noncore/net/networksetup/interface.h
index 1406e99..980171a 100644
--- a/noncore/net/networksetup/interface.h
+++ b/noncore/net/networksetup/interface.h
@@ -1,67 +1,72 @@
#ifndef INTERFACE_H
#define INTERFACE_H
#include <qstring.h>
+#include <qobject.h>
class Module;
-class Interface {
+class Interface : public QObject{
+ Q_OBJECT
+signals:
+ void updateInterface(Interface *i);
+
public:
- Interface(QString name = "unknown", bool status = false);
+ Interface(QObject * parent=0, const char * name= "unknown", bool status = false);
virtual ~Interface(){};
+ virtual QString getInterfaceName(){ QString n(this->name()); return n; };
+
virtual bool getStatus(){ return status; };
- virtual void setStatus(bool newSatus){ status = newSatus; refresh(); };
+ virtual void setStatus(bool newStatus);
virtual bool isAttached(){ return attached; };
- virtual void setAttached(bool isAttached=false){ attached = isAttached; };
-
- virtual QString getInterfaceName(){ return interfaceName; };
- virtual void setInterfaceName(QString name="unknown"){ interfaceName = name; };
+ virtual void setAttached(bool isAttached=false);
virtual QString getHardwareName(){ return hardareName; };
- virtual void setHardwareName(QString name="Unknown"){ hardareName = name; };
+ virtual void setHardwareName(QString name="Unknown");
virtual Module* getModuleOwner(){ return moduleOwner; };
- virtual void setModuleOwner(Module *owner=NULL){ moduleOwner = owner; };
+ virtual void setModuleOwner(Module *owner=NULL);
// inet information.
QString getMacAddress(){ return macAddress; };
QString getIp(){ return ip; };
QString getSubnetMask(){ return subnetMask; };
QString getBroadcast(){ return broadcast; };
bool isDhcp(){ return dhcp; };
QString getDhcpServerIp(){ return dhcpServerIp; };
QString getLeaseObtained(){ return leaseObtained; };
QString getLeaseExpires(){ return leaseExpires; };
-
+
+public slots:
bool refresh();
- bool start();
- bool stop();
- bool restart();
+ void start();
+ void stop();
+ void restart();
private:
// Interface information
bool status;
bool attached;
QString interfaceName;
QString hardareName;
Module *moduleOwner;
// Network information
QString macAddress;
QString ip;
QString broadcast;
QString subnetMask;
bool dhcp;
QString dhcpServerIp;
QString leaseObtained;
QString leaseExpires;
};
#endif
// interface.h
diff --git a/noncore/net/networksetup/interfaceadvanced.ui b/noncore/net/networksetup/interfaceadvanced.ui
index 7520abe..efe67b0 100644
--- a/noncore/net/networksetup/interfaceadvanced.ui
+++ b/noncore/net/networksetup/interfaceadvanced.ui
@@ -1,66 +1,73 @@
<!DOCTYPE UI><UI>
<class>InterfaceAdvanced</class>
<widget>
<class>QWidget</class>
<property stdset="1">
<name>name</name>
<cstring>InterfaceAdvanced</cstring>
</property>
<property stdset="1">
<name>geometry</name>
<rect>
<x>0</x>
<y>0</y>
- <width>188</width>
- <height>277</height>
+ <width>214</width>
+ <height>286</height>
</rect>
</property>
<property stdset="1">
+ <name>maximumSize</name>
+ <size>
+ <width>320</width>
+ <height>32767</height>
+ </size>
+ </property>
+ <property stdset="1">
<name>caption</name>
<string>Advanced Interface Information</string>
</property>
<grid>
<property stdset="1">
<name>margin</name>
<number>11</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget row="1" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>TextLabel1</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>MAC Address</string>
</property>
</widget>
<widget row="0" column="1" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>interfaceName</cstring>
</property>
<property stdset="1">
<name>frameShape</name>
<enum>Panel</enum>
</property>
<property stdset="1">
<name>frameShadow</name>
<enum>Sunken</enum>
</property>
<property stdset="1">
<name>text</name>
<string>eth0</string>
</property>
</widget>
<widget row="2" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>TextLabel3</cstring>
</property>
diff --git a/noncore/net/networksetup/interfaceinformationimp.cpp b/noncore/net/networksetup/interfaceinformationimp.cpp
index e37e0f8..59a6400 100644
--- a/noncore/net/networksetup/interfaceinformationimp.cpp
+++ b/noncore/net/networksetup/interfaceinformationimp.cpp
@@ -1,94 +1,67 @@
#include "interfaceinformationimp.h"
#include "interfaceadvanced.h"
#include <qpushbutton.h>
#include <qlabel.h>
#include <assert.h>
/**
* Constructor for the InterfaceInformationImp class. This class pretty much
* just display's information about the interface that is passed to it.
*/
InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){
assert(i);
interface = i;
- updateInterface();
- connect(startButton, SIGNAL(clicked()), this, SLOT(start()));
- connect(stopButton, SIGNAL(clicked()), this, SLOT(stop()));
- connect(restartButton, SIGNAL(clicked()), this, SLOT(restart()));
- connect(refreshButton, SIGNAL(clicked()), this, SLOT(refresh()));
+ connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
+ updateInterface(interface);
+ connect(startButton, SIGNAL(clicked()), interface, SLOT(start()));
+ connect(stopButton, SIGNAL(clicked()), interface, SLOT(stop()));
+ connect(restartButton, SIGNAL(clicked()), interface, SLOT(restart()));
+ connect(refreshButton, SIGNAL(clicked()), interface, SLOT(refresh()));
connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced()));
}
-void InterfaceInformationImp::updateInterface(){
+/**
+ * Update the interface information and buttons.
+ * @param Intarface *i the interface to update (should be the one we already
+ * know about).
+ */
+void InterfaceInformationImp::updateInterface(Interface *i){
if(interface->getStatus()){
startButton->setEnabled(false);
stopButton->setEnabled(true);
restartButton->setEnabled(true);
}
else{
startButton->setEnabled(true);
stopButton->setEnabled(false);
restartButton->setEnabled(false);
}
macAddressLabel->setText(interface->getMacAddress());
ipAddressLabel->setText(interface->getIp());
subnetMaskLabel->setText(interface->getSubnetMask());
broadcastLabel->setText(interface->getBroadcast());
}
/**
- * Start the interface. Update the information if successfull
- */
-void InterfaceInformationImp::start(){
- if(interface->start()){
- updateInterface();
- }
-}
-
-/**
- * Stop the interface.
- */
-void InterfaceInformationImp::stop(){
- if(interface->stop()){
- updateInterface();
- }
-}
-
-/***
- * Tell the interface to refresh its information.
- **/
-void InterfaceInformationImp::refresh(){
- if(interface->refresh())
- updateInterface();
-}
-
-void InterfaceInformationImp::restart(){
- if(interface->restart()){
- updateInterface();
- }
-}
-
-
-/**
* Create the advanced widget. Fill it with the current interface's information.
* Display it.
*/
void InterfaceInformationImp::advanced(){
InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced");
a->interfaceName->setText(interface->getInterfaceName());
a->macAddressLabel->setText(interface->getMacAddress());
a->ipAddressLabel->setText(interface->getIp());
a->subnetMaskLabel->setText(interface->getSubnetMask());
a->broadcastLabel->setText(interface->getBroadcast());
a->dhcpServerLabel->setText(interface->getDhcpServerIp());
a->leaseObtainedLabel->setText(interface->getLeaseObtained());
a->leaseExpiresLabel->setText(interface->getLeaseExpires());
a->showMaximized();
a->show();
}
// infoimp.cpp
diff --git a/noncore/net/networksetup/interfaceinformationimp.h b/noncore/net/networksetup/interfaceinformationimp.h
index c8a478e..42213cc 100644
--- a/noncore/net/networksetup/interfaceinformationimp.h
+++ b/noncore/net/networksetup/interfaceinformationimp.h
@@ -1,31 +1,27 @@
#ifndef INTERFACEINFORMATIONIMP_H
#define INTERFACEINFORMATIONIMP_H
#include "interfaceinformation.h"
#include "interface.h"
class InterfaceInformationImp : public InterfaceInformation {
Q_OBJECT
public:
InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0);
~InterfaceInformationImp(){};
private slots:
- void start();
- void stop();
- void refresh();
- void restart();
void advanced();
+ void updateInterface(Interface *i);
private:
Interface *interface;
- void updateInterface();
};
#endif
// addserviceimp.h
diff --git a/noncore/net/networksetup/mainwindowimp.cpp b/noncore/net/networksetup/mainwindowimp.cpp
index b46362f..117bac1 100644
--- a/noncore/net/networksetup/mainwindowimp.cpp
+++ b/noncore/net/networksetup/mainwindowimp.cpp
@@ -259,188 +259,191 @@ void MainWindowImp::informationClicked(){
}
InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true);
information->showMaximized();
information->show();
}
/**
* Aquire the list of active interfaces from ifconfig
* Call ifconfig and ifconfig -a
*/
void MainWindowImp::getInterfaceList(){
KShellProcess *processAll = new KShellProcess();
*processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL;
connect(processAll, SIGNAL(processExited(KProcess *)),
this, SLOT(jobDone(KProcess *)));
threads.insert(processAll, TEMP_ALL);
KShellProcess *process = new KShellProcess();
*process << "/sbin/ifconfig" << " > " TEMP_UP;
connect(process, SIGNAL(processExited(KProcess *)),
this, SLOT(jobDone(KProcess *)));
threads.insert(process, TEMP_UP);
processAll->start(KShellProcess::NotifyOnExit);
process->start(KShellProcess::NotifyOnExit);
}
void MainWindowImp::jobDone(KProcess *process){
QString fileName = threads[process];
threads.remove(process);
delete process;
QFile file(fileName);
if (!file.open(IO_ReadOnly)){
qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1());
return;
}
QTextStream stream( &file );
QString line;
while ( !stream.eof() ) {
line = stream.readLine();
int space = line.find(" ");
if(space > 1){
// We have found an interface
QString interfaceName = line.mid(0, space);
Interface *i;
+ // We have found an interface
+ //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1());
// See if we already have it
if(interfaceNames.find(interfaceName) == interfaceNames.end()){
if(fileName == TEMP_ALL)
- i = new Interface(interfaceName, false);
+ i = new Interface(this, interfaceName, false);
else
- i = new Interface(interfaceName, true);
+ i = new Interface(this, interfaceName, true);
+ i->setAttached(true);
+
+ QString hardName = "Ethernet";
+ int hardwareName = line.find("Link encap:");
+ int macAddress = line.find("HWaddr");
+ if(macAddress == -1)
+ macAddress = line.length();
+ if(hardwareName != -1)
+ i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName()));
+
+ interfaceNames.insert(i->getInterfaceName(), i);
+ updateInterface(i);
+ connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
}
+ // It was an interface we already had.
else{
i = interfaceNames[interfaceName];
if(fileName != TEMP_ALL)
i->setStatus(true);
}
-
- i->setAttached(true);
- i->setInterfaceName(interfaceName);
-
- QString hardName = "Ethernet";
- int hardwareName = line.find("Link encap:");
- int macAddress = line.find("HWaddr");
- if(macAddress == -1)
- macAddress = line.length();
- if(hardwareName != -1)
- i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName()));
- // We have found an interface
- //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1());
- interfaceNames.insert(i->getInterfaceName(), i);
- updateInterface(i);
}
}
file.close();
QFile::remove(fileName);
if(threads.count() == 0){
Interfaces i;
QStringList list = i.getInterfaceList();
QMap<QString, Interface*>::Iterator it;
for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) {
bool found = false;
for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){
if(it.key() == (*ni))
found = true;
}
if(!found){
- Interface *i = new Interface(*ni, false);
+ Interface *i = new Interface(this, *ni, false);
i->setAttached(false);
i->setHardwareName(QString("Disconnected (%1)").arg(*ni));
- i->setInterfaceName(*ni);
interfaceNames.insert(i->getInterfaceName(), i);
updateInterface(i);
+ connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
}
}
}
}
/**
* Update this interface. If no QListViewItem exists create one.
* @param Interface* pointer to the interface that needs to be updated.
*/
void MainWindowImp::updateInterface(Interface *i){
if(!advancedUserMode){
if(i->getInterfaceName() == "lo")
return;
}
QListViewItem *item = NULL;
// Find the interface, making it if needed.
if(items.find(i) == items.end()){
item = new QListViewItem(connectionList, "", "", "");
// See if you can't find a module owner for this interface
QMap<Module*, QLibrary*>::Iterator it;
for( it = libraries.begin(); it != libraries.end(); ++it ){
if(it.key()->isOwner(i))
i->setModuleOwner(it.key());
}
items.insert(i, item);
interfaceItems.insert(item, i);
}
else
item = items[i];
// Update the icons and information
item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
QString typeName = "lan";
if(i->getHardwareName().contains("Local Loopback"))
typeName = "lo";
if(i->getInterfaceName().contains("irda"))
typeName = "irda";
if(i->getInterfaceName().contains("wlan"))
typeName = "wlan";
-
+ if(i->getInterfaceName().contains("usb"))
+ typeName = "usb";
+
if(!i->isAttached())
typeName = "connect_no";
// Actually try to use the Module
if(i->getModuleOwner() != NULL)
typeName = i->getModuleOwner()->getPixmapName(i);
item->setPixmap(1, (Resource::loadPixmap(typeName)));
item->setText(2, i->getHardwareName());
item->setText(3, (i->getStatus()) ? i->getIp() : QString(""));
}
void MainWindowImp::newProfileChanged(const QString& newText){
if(newText.length() > 0)
newProfileButton->setEnabled(true);
else
newProfileButton->setEnabled(false);
}
/**
* Adds a new profile to the list of profiles.
* Don't add profiles that already exists.
* Appends to the list and QStringList
*/
void MainWindowImp::addProfile(){
QString newProfileName = newProfile->text();
if(profiles.grep(newProfileName).count() > 0){
QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok");
return;
}
profiles.append(newProfileName);
profilesList->insertItem(newProfileName);
}
/**
* Removes the currently selected profile in the combo.
* Doesn't delete if there are less then 2 profiles.
*/
void MainWindowImp::removeProfile(){
if(profilesList->count() <= 1){
QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok");
return;
}
QString profileToRemove = profilesList->currentText();
if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){
profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
profilesList->clear();
for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
profilesList->insertItem((*it));
diff --git a/noncore/net/networksetup/wlan/wlanmodule.cpp b/noncore/net/networksetup/wlan/wlanmodule.cpp
index 98d2eb6..f0394b4 100644
--- a/noncore/net/networksetup/wlan/wlanmodule.cpp
+++ b/noncore/net/networksetup/wlan/wlanmodule.cpp
@@ -1,76 +1,78 @@
#include "wlanmodule.h"
#include <qpe/config.h>
#include "wlanimp.h"
/**
* Constructor, find all of the possible interfaces
*/
WLANModule::WLANModule() : Module() {
// get output from iwconfig
}
/**
* get the icon name for this device.
* @param Interface* can be used in determining the icon.
* @return QString the icon name (minus .png, .gif etc)
*/
QString WLANModule::getPixmapName(Interface* ){
return "wlan";
}
/**
* Check to see if the interface i is owned by this module.
* @param Interface* interface to check against
* @return bool true if i is owned by this module, false otherwise.
*/
bool WLANModule::isOwner(Interface *i){
- if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0")
+ if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){
+ i->setHardwareName(QString("802.11b (%1)").arg(i->getInterfaceName()));
return true;
+ }
return false;
}
/**
* Create, set tabWiget and return the WLANConfigure Module
* @param tabWidget a pointer to the tab widget that this configure has.
* @return QWidget* pointer to the tab widget in this modules configure.
*/
QWidget *WLANModule::configure(QTabWidget **tabWidget){
Config *cfg = new Config("wireless");
WLANImp *wlanconfig = new WLANImp(*cfg);
(*tabWidget) = wlanconfig->tabWidget;
return wlanconfig;
}
/**
* Create, set tabWiget and return the Information Module
* @param tabWidget a pointer to the tab widget that this information has.
* @return QWidget* pointer to the tab widget in this modules info.
*/
QWidget *WLANModule::information(QTabWidget **tabWidget){
return NULL;
}
/**
* Get all active (up or down) interfaces
* @return QList<Interface> A list of interfaces that exsist that havn't
* been called by isOwner()
*/
QList<Interface> WLANModule::getInterfaces(){
return list;
}
/**
* Attempt to add a new interface as defined by name
* @param name the name of the type of interface that should be created given
* by possibleNewInterfaces();
* @return Interface* NULL if it was unable to be created.
*/
Interface *WLANModule::addNewInterface(QString ){
// We can't add a 802.11 interface, either the hardware will be there
// or it wont.
return NULL;
}
/**
* Attempts to remove the interface, doesn't delete i
* @return bool true if successfull, false otherwise.
diff --git a/noncore/settings/networksettings/TODO b/noncore/settings/networksettings/TODO
index 7386646..c8e2989 100644
--- a/noncore/settings/networksettings/TODO
+++ b/noncore/settings/networksettings/TODO
@@ -1,8 +1,10 @@
+Write a class that parses /proc and not ifconfig
+
[ ] Wlanmodule needs to check if an interface supports wireless
extensions.
[x] When you set options in wlanmodule, hit OK, it exits all of
networksetup, doesnt bring you back to the main screen.
[x] Wlanmodule isnt writing out wireless.opts
[ ] Need a means of bringing an interface up and down (calling
out ifup/ifdown) from the gui.
-Ben- Click information, then click up or down... :-D
diff --git a/noncore/settings/networksettings/interface.cpp b/noncore/settings/networksettings/interface.cpp
index 1f32093..1e01da4 100644
--- a/noncore/settings/networksettings/interface.cpp
+++ b/noncore/settings/networksettings/interface.cpp
@@ -1,188 +1,231 @@
#include "interface.h"
#include <qdatetime.h>
#include <qfile.h>
#include <qdir.h>
#include <qfileinfo.h>
#include <qtextstream.h>
#define IFCONFIG "/sbin/ifconfig"
#define HDCP_INFO_DIR "/etc/dhcpc"
#include <stdio.h>
#include <stdlib.h>
-Interface::Interface(QString name, bool newSatus): status(newSatus), attached(false), interfaceName(name), hardareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){
+Interface::Interface(QObject * parent, const char * name, bool newSatus): QObject(parent, name), status(newSatus), attached(false), hardareName("Unknown"), moduleOwner(NULL), macAddress(""), ip("0.0.0.0"), broadcast(""), subnetMask("0.0.0.0"), dhcp(false){
refresh();
}
/**
+ * Set status
+ * @param newStatus - the new status
+ * emit updateInterface
+ */
+void Interface::setStatus(bool newStatus){
+ if(status != newStatus){
+ status = newStatus;
+ refresh();
+ }
+};
+
+/**
+ * Set if attached or not (802.11 card pulled out for example)
+ * @param isAttached - if attached
+ * emit updateInterface
+ */
+void Interface::setAttached(bool isAttached){
+ attached = isAttached;
+ emit(updateInterface(this));
+};
+
+/**
+ * Set Hardware name
+ * @param name - the new name
+ * emit updateInterface
+ */
+void Interface::setHardwareName(QString name){
+ hardareName = name;
+ emit(updateInterface(this));
+};
+
+/**
+ * Set Module owner
+ * @param owner - the new owner
+ * emit updateInterface
+ */
+void Interface::setModuleOwner(Module *owner){
+ moduleOwner = owner;
+ emit(updateInterface(this));
+};
+
+
+/**
* Try to start the interface.
- * @return bool true if successfull.
*/
-bool Interface::start(){
+void Interface::start(){
// check to see if we are already running.
- if(status)
- return false;
+ if(true == status)
+ return;
int ret = system(QString("%1 %2 up").arg(IFCONFIG).arg(interfaceName).latin1());
+ // See if it was successfull...
if(ret != 0)
- return false;
+ return;
status = true;
refresh();
- return true;
}
/**
* Try to stop the interface.
- * @return bool true if successfull.
*/
-bool Interface::stop(){
+void Interface::stop(){
// check to see if we are already stopped.
- if(status == false)
- return false;
+ if(false == status)
+ return;
int ret = system(QString("%1 %2 down").arg(IFCONFIG).arg(interfaceName).latin1());
if(ret != 0)
- return false;
+ return;
status = true;
refresh();
- return true;
}
+
/**
* Try to restart the interface.
- * @return bool true if successfull.
*/
-bool Interface::restart(){
- return (stop() && start());
+void Interface::restart(){
+ stop();
+ start();
}
/**
* Try to refresh the information about the interface.
* First call ifconfig, then check the dhcp-info file
* @return bool true if successfull.
*/
bool Interface::refresh(){
// See if we are up.
if(status == false){
macAddress = "";
ip = "0.0.0.0";
subnetMask = "0.0.0.0";
broadcast = "";
dhcp = false;
dhcpServerIp = "";
leaseObtained = "";
leaseExpires = "";
+ emit(updateInterface(this));
return true;
}
QString fileName = QString("/tmp/%1_ifconfig_info").arg(interfaceName);
int ret = system(QString("%1 %2 > %3").arg(IFCONFIG).arg(interfaceName).arg(fileName).latin1());
if(ret != 0){
qDebug(QString("Interface: Ifconfig return value: %1, is not 0").arg(ret).latin1());
return false;
}
QFile file(fileName);
if (!file.open(IO_ReadOnly)){
qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
return false;
}
// Set to the defaults
macAddress = "";
ip = "0.0.0.0";
subnetMask = "0.0.0.0";
broadcast = "";
QTextStream stream( &file );
QString line;
while ( !stream.eof() ) {
line = stream.readLine();
if(line.contains("HWaddr")){
int mac = line.find("HWaddr");
macAddress = line.mid(mac+7, line.length());
}
if(line.contains("inet addr")){
int ipl = line.find("inet addr");
int space = line.find(" ", ipl+10);
ip = line.mid(ipl+10, space-ipl-10);
}
if(line.contains("Mask")){
int mask = line.find("Mask");
subnetMask = line.mid(mask+5, line.length());
}
if(line.contains("Bcast")){
int mask = line.find("Bcast");
int space = line.find(" ", mask+6);
broadcast = line.mid(mask+6, space-mask-6);
}
}
file.close();
QFile::remove(fileName);
// DHCP TESTING
// reset DHCP info
dhcpServerIp = "";
leaseObtained = "";
leaseExpires = "";
dhcp = false;
QString dhcpDirectory(HDCP_INFO_DIR);
QDir d(dhcpDirectory);
if(!d.exists(dhcpDirectory))
dhcpDirectory = "/var/run";
// See if we have
QString dhcpFile(QString(dhcpDirectory+"/dhcpcd-%1.info").arg(interfaceName));
// If there is no DHCP information then exit now with no errors.
if(!QFile::exists(dhcpFile)){
+ emit(updateInterface(this));
return true;
}
file.setName(dhcpFile);
if (!file.open(IO_ReadOnly)){
qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
return false;
}
// leaseTime and renewalTime and used if pid and deamon exe can be accessed.
int leaseTime = 0;
int renewalTime = 0;
stream.setDevice( &file );
while ( !stream.eof() ) {
line = stream.readLine();
if(line.contains("DHCPSIADDR="))
dhcpServerIp = line.mid(11, line.length());
if(line.contains("LEASETIME="))
leaseTime = line.mid(10, line.length()).toInt();
if(line.contains("RENEWALTIME="))
renewalTime = line.mid(12, line.length()).toInt();
}
file.close();
//qDebug(QString("Interface: leaseTime: %1").arg(leaseTime).latin1());
//qDebug(QString("Interface: renewalTime: %1").arg(renewalTime).latin1());
// Get the pid of the deamond
dhcpFile = (QString(dhcpDirectory+"/dhcpcd-%1.pid").arg(interfaceName));
file.setName(dhcpFile);
if (!file.open(IO_ReadOnly)){
qDebug(QString("Interface: Can't open file: %1").arg(dhcpFile).latin1());
return false;
}
int pid = -1;
stream.setDevice( &file );
while ( !stream.eof() ) {
line = stream.readLine();
pid = line.toInt();
}
file.close();
if( pid == -1){
qDebug("Interface: Could not get pid of dhcpc deamon.");
return false;
}
@@ -190,53 +233,55 @@ bool Interface::refresh(){
fileName = (QString("/proc/%1/stat").arg(pid));
file.setName(fileName);
stream.setDevice( &file );
if (!file.open(IO_ReadOnly)){
qDebug(QString("Interface: Can't open file: %1").arg(fileName).latin1());
return false;
}
while ( !stream.eof() ) {
line = stream.readLine();
}
file.close();
long time = 0;
// Grab the start time
// pid com state ppid pgrp session tty_nr tpgid flags
sscanf(line.latin1(), "%*d %*s %*c %*d %*d %*d %*d %*d %*u "
// minflt cminflt majflt cmajflt utime stime cutime cstime priority
"%*u %*u %*u %*u %*u %*u %*d %*d %*d "
// nice 0 itrealvalue starttime
"%*d %*d %*d %lu", (long*) &time);
time = time/100;
QDateTime datetime(QDateTime::currentDateTime());
// Get the uptime of the computer.
QFile f("/proc/uptime");
if ( f.open(IO_ReadOnly) ) { // file opened successfully
QTextStream t( &f ); // use a text stream
int sec = 0;
t >> sec;
datetime = datetime.addSecs((-1*sec));
f.close();
}
else{
qDebug("Interface: Can't open /proc/uptime to retrive uptime.");
return false;
}
datetime = datetime.addSecs(time);
//qDebug(QString("Interface: %1 %2").arg(datetime.toString()).arg(pid).latin1());
// Calculate the start and renew times
leaseObtained = datetime.toString();
// Calculate the start and renew times
datetime = datetime.addSecs(leaseTime);
leaseExpires = datetime.toString();
dhcp = true;
+
+ emit(updateInterface(this));
return true;
}
// interface.cpp
diff --git a/noncore/settings/networksettings/interface.h b/noncore/settings/networksettings/interface.h
index 1406e99..980171a 100644
--- a/noncore/settings/networksettings/interface.h
+++ b/noncore/settings/networksettings/interface.h
@@ -1,67 +1,72 @@
#ifndef INTERFACE_H
#define INTERFACE_H
#include <qstring.h>
+#include <qobject.h>
class Module;
-class Interface {
+class Interface : public QObject{
+ Q_OBJECT
+signals:
+ void updateInterface(Interface *i);
+
public:
- Interface(QString name = "unknown", bool status = false);
+ Interface(QObject * parent=0, const char * name= "unknown", bool status = false);
virtual ~Interface(){};
+ virtual QString getInterfaceName(){ QString n(this->name()); return n; };
+
virtual bool getStatus(){ return status; };
- virtual void setStatus(bool newSatus){ status = newSatus; refresh(); };
+ virtual void setStatus(bool newStatus);
virtual bool isAttached(){ return attached; };
- virtual void setAttached(bool isAttached=false){ attached = isAttached; };
-
- virtual QString getInterfaceName(){ return interfaceName; };
- virtual void setInterfaceName(QString name="unknown"){ interfaceName = name; };
+ virtual void setAttached(bool isAttached=false);
virtual QString getHardwareName(){ return hardareName; };
- virtual void setHardwareName(QString name="Unknown"){ hardareName = name; };
+ virtual void setHardwareName(QString name="Unknown");
virtual Module* getModuleOwner(){ return moduleOwner; };
- virtual void setModuleOwner(Module *owner=NULL){ moduleOwner = owner; };
+ virtual void setModuleOwner(Module *owner=NULL);
// inet information.
QString getMacAddress(){ return macAddress; };
QString getIp(){ return ip; };
QString getSubnetMask(){ return subnetMask; };
QString getBroadcast(){ return broadcast; };
bool isDhcp(){ return dhcp; };
QString getDhcpServerIp(){ return dhcpServerIp; };
QString getLeaseObtained(){ return leaseObtained; };
QString getLeaseExpires(){ return leaseExpires; };
-
+
+public slots:
bool refresh();
- bool start();
- bool stop();
- bool restart();
+ void start();
+ void stop();
+ void restart();
private:
// Interface information
bool status;
bool attached;
QString interfaceName;
QString hardareName;
Module *moduleOwner;
// Network information
QString macAddress;
QString ip;
QString broadcast;
QString subnetMask;
bool dhcp;
QString dhcpServerIp;
QString leaseObtained;
QString leaseExpires;
};
#endif
// interface.h
diff --git a/noncore/settings/networksettings/interfaceadvanced.ui b/noncore/settings/networksettings/interfaceadvanced.ui
index 7520abe..efe67b0 100644
--- a/noncore/settings/networksettings/interfaceadvanced.ui
+++ b/noncore/settings/networksettings/interfaceadvanced.ui
@@ -1,66 +1,73 @@
<!DOCTYPE UI><UI>
<class>InterfaceAdvanced</class>
<widget>
<class>QWidget</class>
<property stdset="1">
<name>name</name>
<cstring>InterfaceAdvanced</cstring>
</property>
<property stdset="1">
<name>geometry</name>
<rect>
<x>0</x>
<y>0</y>
- <width>188</width>
- <height>277</height>
+ <width>214</width>
+ <height>286</height>
</rect>
</property>
<property stdset="1">
+ <name>maximumSize</name>
+ <size>
+ <width>320</width>
+ <height>32767</height>
+ </size>
+ </property>
+ <property stdset="1">
<name>caption</name>
<string>Advanced Interface Information</string>
</property>
<grid>
<property stdset="1">
<name>margin</name>
<number>11</number>
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget row="1" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>TextLabel1</cstring>
</property>
<property stdset="1">
<name>text</name>
<string>MAC Address</string>
</property>
</widget>
<widget row="0" column="1" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>interfaceName</cstring>
</property>
<property stdset="1">
<name>frameShape</name>
<enum>Panel</enum>
</property>
<property stdset="1">
<name>frameShadow</name>
<enum>Sunken</enum>
</property>
<property stdset="1">
<name>text</name>
<string>eth0</string>
</property>
</widget>
<widget row="2" column="0" >
<class>QLabel</class>
<property stdset="1">
<name>name</name>
<cstring>TextLabel3</cstring>
</property>
diff --git a/noncore/settings/networksettings/interfaceinformationimp.cpp b/noncore/settings/networksettings/interfaceinformationimp.cpp
index e37e0f8..59a6400 100644
--- a/noncore/settings/networksettings/interfaceinformationimp.cpp
+++ b/noncore/settings/networksettings/interfaceinformationimp.cpp
@@ -1,94 +1,67 @@
#include "interfaceinformationimp.h"
#include "interfaceadvanced.h"
#include <qpushbutton.h>
#include <qlabel.h>
#include <assert.h>
/**
* Constructor for the InterfaceInformationImp class. This class pretty much
* just display's information about the interface that is passed to it.
*/
InterfaceInformationImp::InterfaceInformationImp(QWidget *parent, const char *name, Interface *i, WFlags f):InterfaceInformation(parent, name, f){
assert(i);
interface = i;
- updateInterface();
- connect(startButton, SIGNAL(clicked()), this, SLOT(start()));
- connect(stopButton, SIGNAL(clicked()), this, SLOT(stop()));
- connect(restartButton, SIGNAL(clicked()), this, SLOT(restart()));
- connect(refreshButton, SIGNAL(clicked()), this, SLOT(refresh()));
+ connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
+ updateInterface(interface);
+ connect(startButton, SIGNAL(clicked()), interface, SLOT(start()));
+ connect(stopButton, SIGNAL(clicked()), interface, SLOT(stop()));
+ connect(restartButton, SIGNAL(clicked()), interface, SLOT(restart()));
+ connect(refreshButton, SIGNAL(clicked()), interface, SLOT(refresh()));
connect(advancedButton, SIGNAL(clicked()), this, SLOT(advanced()));
}
-void InterfaceInformationImp::updateInterface(){
+/**
+ * Update the interface information and buttons.
+ * @param Intarface *i the interface to update (should be the one we already
+ * know about).
+ */
+void InterfaceInformationImp::updateInterface(Interface *i){
if(interface->getStatus()){
startButton->setEnabled(false);
stopButton->setEnabled(true);
restartButton->setEnabled(true);
}
else{
startButton->setEnabled(true);
stopButton->setEnabled(false);
restartButton->setEnabled(false);
}
macAddressLabel->setText(interface->getMacAddress());
ipAddressLabel->setText(interface->getIp());
subnetMaskLabel->setText(interface->getSubnetMask());
broadcastLabel->setText(interface->getBroadcast());
}
/**
- * Start the interface. Update the information if successfull
- */
-void InterfaceInformationImp::start(){
- if(interface->start()){
- updateInterface();
- }
-}
-
-/**
- * Stop the interface.
- */
-void InterfaceInformationImp::stop(){
- if(interface->stop()){
- updateInterface();
- }
-}
-
-/***
- * Tell the interface to refresh its information.
- **/
-void InterfaceInformationImp::refresh(){
- if(interface->refresh())
- updateInterface();
-}
-
-void InterfaceInformationImp::restart(){
- if(interface->restart()){
- updateInterface();
- }
-}
-
-
-/**
* Create the advanced widget. Fill it with the current interface's information.
* Display it.
*/
void InterfaceInformationImp::advanced(){
InterfaceAdvanced *a = new InterfaceAdvanced(0, "InterfaceAdvanced");
a->interfaceName->setText(interface->getInterfaceName());
a->macAddressLabel->setText(interface->getMacAddress());
a->ipAddressLabel->setText(interface->getIp());
a->subnetMaskLabel->setText(interface->getSubnetMask());
a->broadcastLabel->setText(interface->getBroadcast());
a->dhcpServerLabel->setText(interface->getDhcpServerIp());
a->leaseObtainedLabel->setText(interface->getLeaseObtained());
a->leaseExpiresLabel->setText(interface->getLeaseExpires());
a->showMaximized();
a->show();
}
// infoimp.cpp
diff --git a/noncore/settings/networksettings/interfaceinformationimp.h b/noncore/settings/networksettings/interfaceinformationimp.h
index c8a478e..42213cc 100644
--- a/noncore/settings/networksettings/interfaceinformationimp.h
+++ b/noncore/settings/networksettings/interfaceinformationimp.h
@@ -1,31 +1,27 @@
#ifndef INTERFACEINFORMATIONIMP_H
#define INTERFACEINFORMATIONIMP_H
#include "interfaceinformation.h"
#include "interface.h"
class InterfaceInformationImp : public InterfaceInformation {
Q_OBJECT
public:
InterfaceInformationImp(QWidget *parent=0, const char *name=0, Interface *i=0, WFlags f=0);
~InterfaceInformationImp(){};
private slots:
- void start();
- void stop();
- void refresh();
- void restart();
void advanced();
+ void updateInterface(Interface *i);
private:
Interface *interface;
- void updateInterface();
};
#endif
// addserviceimp.h
diff --git a/noncore/settings/networksettings/mainwindowimp.cpp b/noncore/settings/networksettings/mainwindowimp.cpp
index b46362f..117bac1 100644
--- a/noncore/settings/networksettings/mainwindowimp.cpp
+++ b/noncore/settings/networksettings/mainwindowimp.cpp
@@ -259,188 +259,191 @@ void MainWindowImp::informationClicked(){
}
InterfaceInformationImp *information = new InterfaceInformationImp(0, "InterfaceSetupImp", i, true);
information->showMaximized();
information->show();
}
/**
* Aquire the list of active interfaces from ifconfig
* Call ifconfig and ifconfig -a
*/
void MainWindowImp::getInterfaceList(){
KShellProcess *processAll = new KShellProcess();
*processAll << "/sbin/ifconfig" << "-a" << " > " TEMP_ALL;
connect(processAll, SIGNAL(processExited(KProcess *)),
this, SLOT(jobDone(KProcess *)));
threads.insert(processAll, TEMP_ALL);
KShellProcess *process = new KShellProcess();
*process << "/sbin/ifconfig" << " > " TEMP_UP;
connect(process, SIGNAL(processExited(KProcess *)),
this, SLOT(jobDone(KProcess *)));
threads.insert(process, TEMP_UP);
processAll->start(KShellProcess::NotifyOnExit);
process->start(KShellProcess::NotifyOnExit);
}
void MainWindowImp::jobDone(KProcess *process){
QString fileName = threads[process];
threads.remove(process);
delete process;
QFile file(fileName);
if (!file.open(IO_ReadOnly)){
qDebug(QString("MainWindowImp: Can't open file: %1").arg(fileName).latin1());
return;
}
QTextStream stream( &file );
QString line;
while ( !stream.eof() ) {
line = stream.readLine();
int space = line.find(" ");
if(space > 1){
// We have found an interface
QString interfaceName = line.mid(0, space);
Interface *i;
+ // We have found an interface
+ //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1());
// See if we already have it
if(interfaceNames.find(interfaceName) == interfaceNames.end()){
if(fileName == TEMP_ALL)
- i = new Interface(interfaceName, false);
+ i = new Interface(this, interfaceName, false);
else
- i = new Interface(interfaceName, true);
+ i = new Interface(this, interfaceName, true);
+ i->setAttached(true);
+
+ QString hardName = "Ethernet";
+ int hardwareName = line.find("Link encap:");
+ int macAddress = line.find("HWaddr");
+ if(macAddress == -1)
+ macAddress = line.length();
+ if(hardwareName != -1)
+ i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName()));
+
+ interfaceNames.insert(i->getInterfaceName(), i);
+ updateInterface(i);
+ connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
}
+ // It was an interface we already had.
else{
i = interfaceNames[interfaceName];
if(fileName != TEMP_ALL)
i->setStatus(true);
}
-
- i->setAttached(true);
- i->setInterfaceName(interfaceName);
-
- QString hardName = "Ethernet";
- int hardwareName = line.find("Link encap:");
- int macAddress = line.find("HWaddr");
- if(macAddress == -1)
- macAddress = line.length();
- if(hardwareName != -1)
- i->setHardwareName(line.mid(hardwareName+11, macAddress-(hardwareName+11)) + QString(" (%1)").arg(i->getInterfaceName()));
- // We have found an interface
- //qDebug(QString("MainWindowImp: Found Interface: %1").arg(line).latin1());
- interfaceNames.insert(i->getInterfaceName(), i);
- updateInterface(i);
}
}
file.close();
QFile::remove(fileName);
if(threads.count() == 0){
Interfaces i;
QStringList list = i.getInterfaceList();
QMap<QString, Interface*>::Iterator it;
for ( QStringList::Iterator ni = list.begin(); ni != list.end(); ++ni ) {
bool found = false;
for( it = interfaceNames.begin(); it != interfaceNames.end(); ++it ){
if(it.key() == (*ni))
found = true;
}
if(!found){
- Interface *i = new Interface(*ni, false);
+ Interface *i = new Interface(this, *ni, false);
i->setAttached(false);
i->setHardwareName(QString("Disconnected (%1)").arg(*ni));
- i->setInterfaceName(*ni);
interfaceNames.insert(i->getInterfaceName(), i);
updateInterface(i);
+ connect(i, SIGNAL(updateInterface(Interface *)), this, SLOT(updateInterface(Interface *)));
}
}
}
}
/**
* Update this interface. If no QListViewItem exists create one.
* @param Interface* pointer to the interface that needs to be updated.
*/
void MainWindowImp::updateInterface(Interface *i){
if(!advancedUserMode){
if(i->getInterfaceName() == "lo")
return;
}
QListViewItem *item = NULL;
// Find the interface, making it if needed.
if(items.find(i) == items.end()){
item = new QListViewItem(connectionList, "", "", "");
// See if you can't find a module owner for this interface
QMap<Module*, QLibrary*>::Iterator it;
for( it = libraries.begin(); it != libraries.end(); ++it ){
if(it.key()->isOwner(i))
i->setModuleOwner(it.key());
}
items.insert(i, item);
interfaceItems.insert(item, i);
}
else
item = items[i];
// Update the icons and information
item->setPixmap(0, (Resource::loadPixmap(i->getStatus() ? "up": "down")));
QString typeName = "lan";
if(i->getHardwareName().contains("Local Loopback"))
typeName = "lo";
if(i->getInterfaceName().contains("irda"))
typeName = "irda";
if(i->getInterfaceName().contains("wlan"))
typeName = "wlan";
-
+ if(i->getInterfaceName().contains("usb"))
+ typeName = "usb";
+
if(!i->isAttached())
typeName = "connect_no";
// Actually try to use the Module
if(i->getModuleOwner() != NULL)
typeName = i->getModuleOwner()->getPixmapName(i);
item->setPixmap(1, (Resource::loadPixmap(typeName)));
item->setText(2, i->getHardwareName());
item->setText(3, (i->getStatus()) ? i->getIp() : QString(""));
}
void MainWindowImp::newProfileChanged(const QString& newText){
if(newText.length() > 0)
newProfileButton->setEnabled(true);
else
newProfileButton->setEnabled(false);
}
/**
* Adds a new profile to the list of profiles.
* Don't add profiles that already exists.
* Appends to the list and QStringList
*/
void MainWindowImp::addProfile(){
QString newProfileName = newProfile->text();
if(profiles.grep(newProfileName).count() > 0){
QMessageBox::information(this, "Can't Add","Profile already exists.", "Ok");
return;
}
profiles.append(newProfileName);
profilesList->insertItem(newProfileName);
}
/**
* Removes the currently selected profile in the combo.
* Doesn't delete if there are less then 2 profiles.
*/
void MainWindowImp::removeProfile(){
if(profilesList->count() <= 1){
QMessageBox::information(this, "Can't remove anything.","Need One Profile.", "Ok");
return;
}
QString profileToRemove = profilesList->currentText();
if(QMessageBox::information(this, "Question",QString("Remove profile: %1").arg(profileToRemove), QMessageBox::Ok, QMessageBox::Cancel) == QMessageBox::Ok){
profiles = QStringList::split(" ", profiles.join(" ").replace(QRegExp(profileToRemove), ""));
profilesList->clear();
for ( QStringList::Iterator it = profiles.begin(); it != profiles.end(); ++it)
profilesList->insertItem((*it));
diff --git a/noncore/settings/networksettings/wlan/wlanmodule.cpp b/noncore/settings/networksettings/wlan/wlanmodule.cpp
index 98d2eb6..f0394b4 100644
--- a/noncore/settings/networksettings/wlan/wlanmodule.cpp
+++ b/noncore/settings/networksettings/wlan/wlanmodule.cpp
@@ -1,76 +1,78 @@
#include "wlanmodule.h"
#include <qpe/config.h>
#include "wlanimp.h"
/**
* Constructor, find all of the possible interfaces
*/
WLANModule::WLANModule() : Module() {
// get output from iwconfig
}
/**
* get the icon name for this device.
* @param Interface* can be used in determining the icon.
* @return QString the icon name (minus .png, .gif etc)
*/
QString WLANModule::getPixmapName(Interface* ){
return "wlan";
}
/**
* Check to see if the interface i is owned by this module.
* @param Interface* interface to check against
* @return bool true if i is owned by this module, false otherwise.
*/
bool WLANModule::isOwner(Interface *i){
- if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0")
+ if(i->getInterfaceName() == "eth0" || i->getInterfaceName() == "wlan0"){
+ i->setHardwareName(QString("802.11b (%1)").arg(i->getInterfaceName()));
return true;
+ }
return false;
}
/**
* Create, set tabWiget and return the WLANConfigure Module
* @param tabWidget a pointer to the tab widget that this configure has.
* @return QWidget* pointer to the tab widget in this modules configure.
*/
QWidget *WLANModule::configure(QTabWidget **tabWidget){
Config *cfg = new Config("wireless");
WLANImp *wlanconfig = new WLANImp(*cfg);
(*tabWidget) = wlanconfig->tabWidget;
return wlanconfig;
}
/**
* Create, set tabWiget and return the Information Module
* @param tabWidget a pointer to the tab widget that this information has.
* @return QWidget* pointer to the tab widget in this modules info.
*/
QWidget *WLANModule::information(QTabWidget **tabWidget){
return NULL;
}
/**
* Get all active (up or down) interfaces
* @return QList<Interface> A list of interfaces that exsist that havn't
* been called by isOwner()
*/
QList<Interface> WLANModule::getInterfaces(){
return list;
}
/**
* Attempt to add a new interface as defined by name
* @param name the name of the type of interface that should be created given
* by possibleNewInterfaces();
* @return Interface* NULL if it was unable to be created.
*/
Interface *WLANModule::addNewInterface(QString ){
// We can't add a 802.11 interface, either the hardware will be there
// or it wont.
return NULL;
}
/**
* Attempts to remove the interface, doesn't delete i
* @return bool true if successfull, false otherwise.