summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/lancard
authorwimpie <wimpie>2004-04-07 00:09:37 (UTC)
committer wimpie <wimpie>2004-04-07 00:09:37 (UTC)
commitb93d9e0c4384be0a6f40be257ba791004388400b (patch) (side-by-side diff)
tree2ca0e41dc8c99e1af3ce2f0305d458f76d10db45 /noncore/settings/networksettings2/lancard
parent1b7aaf904fa70c16eee03155bd826e921798cc22 (diff)
downloadopie-b93d9e0c4384be0a6f40be257ba791004388400b.zip
opie-b93d9e0c4384be0a6f40be257ba791004388400b.tar.gz
opie-b93d9e0c4384be0a6f40be257ba791004388400b.tar.bz2
MANY changes ... lancards should be OK now
Diffstat (limited to 'noncore/settings/networksettings2/lancard') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/lancard/lancardGUI.ui92
-rw-r--r--noncore/settings/networksettings2/lancard/lancard_NN.cpp11
-rw-r--r--noncore/settings/networksettings2/lancard/lancard_NN.h8
-rw-r--r--noncore/settings/networksettings2/lancard/lancard_NNI.cpp2
-rw-r--r--noncore/settings/networksettings2/lancard/lancardedit.cpp195
-rw-r--r--noncore/settings/networksettings2/lancard/lancardedit.h12
-rw-r--r--noncore/settings/networksettings2/lancard/lancardrun.cpp34
-rw-r--r--noncore/settings/networksettings2/lancard/lancardrun.h6
8 files changed, 290 insertions, 70 deletions
diff --git a/noncore/settings/networksettings2/lancard/lancardGUI.ui b/noncore/settings/networksettings2/lancard/lancardGUI.ui
index 8d94816..c407175 100644
--- a/noncore/settings/networksettings2/lancard/lancardGUI.ui
+++ b/noncore/settings/networksettings2/lancard/lancardGUI.ui
@@ -11,7 +11,7 @@
<rect>
<x>0</x>
<y>0</y>
- <width>362</width>
+ <width>354</width>
<height>359</height>
</rect>
</property>
@@ -69,7 +69,7 @@
<vbox>
<property stdset="1">
<name>margin</name>
- <number>11</number>
+ <number>5</number>
</property>
<property stdset="1">
<name>spacing</name>
@@ -80,20 +80,6 @@
<column>
<property>
<name>text</name>
- <string>Name</string>
- </property>
- <property>
- <name>clickable</name>
- <bool>true</bool>
- </property>
- <property>
- <name>resizeable</name>
- <bool>true</bool>
- </property>
- </column>
- <column>
- <property>
- <name>text</name>
<string>MACAddress</string>
</property>
<property>
@@ -114,6 +100,66 @@
<bool>true</bool>
</property>
</widget>
+ <widget>
+ <class>QLayoutWidget</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>Layout2</cstring>
+ </property>
+ <hbox>
+ <property stdset="1">
+ <name>margin</name>
+ <number>0</number>
+ </property>
+ <property stdset="1">
+ <name>spacing</name>
+ <number>6</number>
+ </property>
+ <widget>
+ <class>QPushButton</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>RemoveUnknown_BUT</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>Remove Unknown</string>
+ </property>
+ </widget>
+ <spacer>
+ <property>
+ <name>name</name>
+ <cstring>Spacer1</cstring>
+ </property>
+ <property stdset="1">
+ <name>orientation</name>
+ <enum>Horizontal</enum>
+ </property>
+ <property stdset="1">
+ <name>sizeType</name>
+ <enum>Expanding</enum>
+ </property>
+ <property>
+ <name>sizeHint</name>
+ <size>
+ <width>20</width>
+ <height>20</height>
+ </size>
+ </property>
+ </spacer>
+ <widget>
+ <class>QPushButton</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>RescanCards_BUT</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>Rescan</string>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
</vbox>
</widget>
</vbox>
@@ -125,5 +171,19 @@
<receiver>GroupBox1</receiver>
<slot>setDisabled(bool)</slot>
</connection>
+ <connection>
+ <sender>RescanCards_BUT</sender>
+ <signal>clicked()</signal>
+ <receiver>Lancard_FRM</receiver>
+ <slot>SLOT_ScanCards()</slot>
+ </connection>
+ <connection>
+ <sender>RemoveUnknown_BUT</sender>
+ <signal>clicked()</signal>
+ <receiver>Lancard_FRM</receiver>
+ <slot>SLOT_RemoveUnknown()</slot>
+ </connection>
+ <slot access="public">SLOT_ScanCards()</slot>
+ <slot access="public">SLOT_RemoveUnknown()</slot>
</connections>
</UI>
diff --git a/noncore/settings/networksettings2/lancard/lancard_NN.cpp b/noncore/settings/networksettings2/lancard/lancard_NN.cpp
index ba1c1f8..a4afab1 100644
--- a/noncore/settings/networksettings2/lancard/lancard_NN.cpp
+++ b/noncore/settings/networksettings2/lancard/lancard_NN.cpp
@@ -7,7 +7,7 @@ static const char * LanCardNeeds[] =
/**
* Constructor, find all of the possible interfaces
*/
-LanCardNetNode::LanCardNetNode() : ANetNode() {
+LanCardNetNode::LanCardNetNode() : ANetNode(tr("LAN card")), NICMACAddresses() {
InstanceCount = 2;
}
@@ -69,6 +69,8 @@ QString LanCardNetNode::genNic( long nr ) {
void LanCardNetNode::setSpecificAttribute( QString & A, QString & V ) {
if( A == "interfacecount" ) {
InstanceCount = V.toLong();
+ } else if ( A == "macaddress" ) {
+ NICMACAddresses.append( V );
}
}
@@ -76,6 +78,13 @@ void LanCardNetNode::saveSpecificAttribute( QTextStream & TS) {
TS << "interfacecount="
<< InstanceCount
<< endl;
+ for( QStringList::Iterator it = NICMACAddresses.begin();
+ it != NICMACAddresses.end();
+ ++it ) {
+ TS << "macaddress="
+ << (*it)
+ << endl;
+ }
}
extern "C" {
diff --git a/noncore/settings/networksettings2/lancard/lancard_NN.h b/noncore/settings/networksettings2/lancard/lancard_NN.h
index 5f2b25d..d58823c 100644
--- a/noncore/settings/networksettings2/lancard/lancard_NN.h
+++ b/noncore/settings/networksettings2/lancard/lancard_NN.h
@@ -1,6 +1,7 @@
#ifndef LANCARD_NETNODE_H
#define LANCARD_NETNODE_H
+#include <qstringlist.h>
#include "netnode.h"
class ALanCard;
@@ -17,9 +18,6 @@ public:
virtual const QString pixmapName()
{ return "Devices/card"; }
- virtual const QString nodeName()
- { return tr("LAN card"); }
-
virtual const QString nodeDescription() ;
virtual ANetNodeInstance * createInstance( void );
@@ -36,6 +34,8 @@ public:
{ return InstanceCount; }
virtual QString genNic( long );
+ virtual QStringList & addressesOfNIC( void )
+ { return NICMACAddresses; }
private:
@@ -45,6 +45,8 @@ private:
// number of interfaces for this device
long InstanceCount;
+ QStringList NICMACAddresses;
+
};
extern "C"
diff --git a/noncore/settings/networksettings2/lancard/lancard_NNI.cpp b/noncore/settings/networksettings2/lancard/lancard_NNI.cpp
index 5962d52..99c033e 100644
--- a/noncore/settings/networksettings2/lancard/lancard_NNI.cpp
+++ b/noncore/settings/networksettings2/lancard/lancard_NNI.cpp
@@ -30,7 +30,7 @@ void ALanCard::saveSpecificAttribute( QTextStream & TS) {
QWidget * ALanCard::edit( QWidget * parent ) {
GUI = new LanCardEdit( parent );
- GUI->showData( Data );
+ GUI->showData( this );
return GUI;
}
diff --git a/noncore/settings/networksettings2/lancard/lancardedit.cpp b/noncore/settings/networksettings2/lancard/lancardedit.cpp
index fa7f6dc..ffe9bf6 100644
--- a/noncore/settings/networksettings2/lancard/lancardedit.cpp
+++ b/noncore/settings/networksettings2/lancard/lancardedit.cpp
@@ -1,95 +1,208 @@
#include <GUIUtils.h>
#include <resources.h>
+#include <qarray.h>
#include <qlistview.h>
#include <qcheckbox.h>
#include <qheader.h>
#include <qregexp.h>
+
#include "lancardedit.h"
+#include "lancard_NN.h"
+#include "lancard_NNI.h"
LanCardEdit::LanCardEdit( QWidget * Parent ) : LanCardGUI( Parent ){
- System & S = NSResources->system();
- QRegExp R( "eth[0-9]" );
- QCheckListItem * CLI;
-
LanCards_LV->header()->hide();
- // populate with all lancards in system
- for( QDictIterator<InterfaceInfo> It(S.interfaces());
- It.current();
- ++It ) {
- if( R.match( It.current()->Name ) >= 0 &&
- It.current()->CardType == ARPHRD_ETHER
- ) {
- CLI = new QCheckListItem( LanCards_LV, It.current()->Name,
- QCheckListItem::CheckBox );
- CLI->setText( 1, It.current()->MACAddress );
- }
- }
}
QString LanCardEdit::acceptable( void ) {
return QString();
}
-
bool LanCardEdit::commit( LanCardData & Data ) {
bool SM = 0;
CBM( Data.AnyLanCard, AnyCard_CB, SM );
if( ! Data.AnyLanCard ) {
- // collect set of lancards that match
+ // take copy for orig list
+ QStringList NewList( Data.HWAddresses );
+
+ // update HWAddresses to new state
+ // remove item also from NewList
int idx;
QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild();
while( CLI ) {
- idx = Data.HWAddresses.findIndex(CLI->text(1));
+ idx = Data.HWAddresses.findIndex(CLI->text(0));
if( CLI->isOn() ) {
if( idx < 0 ) {
// should be in list
- Data.HWAddresses.append( CLI->text(1) );
+ Data.HWAddresses.append( CLI->text(0) );
SM = 1;
}
} else {
// should not be in list
if( idx >= 0 ) {
- Data.HWAddresses.remove( Data.HWAddresses.at(idx) );
+ NewList.remove( CLI->text(0) );
+ Data.HWAddresses.remove( CLI->text(0) );
SM = 1;
}
}
CLI = (QCheckListItem *)CLI->nextSibling();
}
+
+ // if newlist still contains items. it were items
+ // that were checked but no longer are present in the system
+ SM |= ( NewList.count() > 0 ) ;
}
- return SM || ContainedObsoleteMAC ;
+ return SM;
}
-void LanCardEdit::showData( LanCardData & Data ) {
+void LanCardEdit::showData( ALanCard * LC ) {
+ NNI = LC;
+ LanCardData & Data = *((LanCardData *)LC->data());
+
AnyCard_CB->setChecked( Data.AnyLanCard );
+ // load all cards
+ populateList();
+
+ // set checks
QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild();
+ while( CLI ) {
+ CLI->setOn( Data.HWAddresses.findIndex(CLI->text(0)) >= 0 );
+ CLI = (QCheckListItem *)CLI->nextSibling();
+ }
+}
- ContainedObsoleteMAC = 0;
- // remove obsolete address
- for( QStringList::Iterator it=Data.HWAddresses.begin();
- it != Data.HWAddresses.end();
- ) {
- CLI = (QCheckListItem *)LanCards_LV->firstChild();
- while( CLI ) {
- if( CLI->text(1) == (*it) )
- // still valid
+// load all known cards in list
+void LanCardEdit::populateList( void ) {
+ LanCardNetNode *NN = (LanCardNetNode *)NNI->nodeClass();
+ QCheckListItem * CLI;
+ bool Found;
+
+ LanCards_LV->clear();
+
+ for( QStringList::Iterator it = NN->addressesOfNIC().begin();
+ it != NN->addressesOfNIC().end();
+ ++it ) {
+ CLI = new QCheckListItem( LanCards_LV, (*it), QCheckListItem::CheckBox );
+
+ // check interfaces and see if this card is present
+ Found = 0;
+ for( QDictIterator<InterfaceInfo> NIt(NSResources->system().interfaces());
+ NIt.current();
+ ++NIt ) {
+ if( NIt.current()->MACAddress == (*it) ) {
+ Found = 1;
break;
- CLI = (QCheckListItem *)CLI->nextSibling();
+ }
}
- if( CLI == 0 ) {
- // address not found -> remove
- ContainedObsoleteMAC = 1;
- Data.HWAddresses.remove( it );
- } else {
- ++ it;
+
+ CLI->setPixmap( 0, NSResources->getPixmap(
+ (Found) ? "add" : "remove" ) );
+ }
+}
+
+// rescan system for new cards
+void LanCardEdit::SLOT_ScanCards( void ) {
+ LanCardNetNode *NN = (LanCardNetNode *)NNI->nodeClass();
+
+ // add any NIC that is new and matches our interfacename
+ System & S = NSResources->system();
+ QRegExp R( "eth[0-9]" );
+ // populate with all lancards in system
+ for( QDictIterator<InterfaceInfo> It(S.interfaces());
+ It.current();
+ ++It ) {
+ fprintf( stderr, "TEST %s %s\n",
+ It.current()->Name.latin1(),
+ It.current()->MACAddress.latin1() );
+ if( R.match( It.current()->Name ) >= 0 &&
+ ( It.current()->CardType == ARPHRD_ETHER
+#ifdef ARPHRD_IEEE1394
+ || It.current()->CardType == ARPHRD_IEEE1394
+#endif
+ )
+ ) {
+ // old item ?
+ QCheckListItem * CLI =
+ (QCheckListItem *)LanCards_LV->firstChild();
+ while( CLI ) {
+ if( CLI->text(0) == It.current()->MACAddress ) {
+ break;
+ }
+ CLI = (QCheckListItem *)CLI->nextSibling();
+ }
+
+ if( ! CLI ) {
+ // new item
+ CLI = new QCheckListItem( LanCards_LV,
+ It.current()->MACAddress,
+ QCheckListItem::CheckBox );
+ }
+
+ // mark present
+ CLI->setPixmap( 0, NSResources->getPixmap(
+ "add" ) );
+
+ if( NN->addressesOfNIC().findIndex( It.current()->MACAddress) < 0 ) {
+ // new
+ NN->addressesOfNIC().append( It.current()->MACAddress );
+ }
}
}
- // set checks
+}
+
+// remove all cards that are not present -> flagged with 'remove'
+// and unchecked
+void LanCardEdit::SLOT_RemoveUnknown( void ) {
+ QArray<QCheckListItem *> AllItems;
+
+ LanCardNetNode *NN = (LanCardNetNode *)NNI->nodeClass();
+
+ QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild();
while( CLI ) {
- CLI->setOn( Data.HWAddresses.findIndex(CLI->text(1)) >= 0 );
+ AllItems.resize( AllItems.size()+1 );
+ AllItems[ AllItems.size()-1 ] = CLI;
CLI = (QCheckListItem *)CLI->nextSibling();
}
+
+ // force update of system
+ System & S = NSResources->system();
+ S.probeInterfaces();
+
+ // add any NIC that is new and matches our interfacename
+ QRegExp R( "eth[0-9]" );
+
+
+ for( QDictIterator<InterfaceInfo> It(S.interfaces());
+ It.current();
+ ++It ) {
+ if( R.match( It.current()->Name ) >= 0 &&
+ ( It.current()->CardType == ARPHRD_ETHER
+#ifdef ARPHRD_IEEE1394
+ || It.current()->CardType == ARPHRD_IEEE1394
+#endif
+ )
+ ) {
+
+ for ( unsigned i = 0; i< AllItems.size(); i++ ) {
+ if( AllItems[i] &&
+ AllItems[i]->text(0) == It.current()->MACAddress ) {
+ AllItems[i] = 0;
+ break;
+ }
+ }
+ }
+ }
+
+ // AllItems now contains all cards NOT present
+ // remove all items non null and not ON
+ for ( unsigned i = 0; i< AllItems.size(); i++ ) {
+ if( AllItems[i] && ! AllItems[i]->isOn() ) {
+ NN->addressesOfNIC().remove( AllItems[i]->text(0) );
+ delete AllItems[i];
+ }
+ }
}
diff --git a/noncore/settings/networksettings2/lancard/lancardedit.h b/noncore/settings/networksettings2/lancard/lancardedit.h
index 8def789..282db1f 100644
--- a/noncore/settings/networksettings2/lancard/lancardedit.h
+++ b/noncore/settings/networksettings2/lancard/lancardedit.h
@@ -1,6 +1,8 @@
#include "lancarddata.h"
#include "lancardGUI.h"
+class ALanCard;
+
class LanCardEdit : public LanCardGUI {
public :
@@ -8,9 +10,15 @@ public :
LanCardEdit( QWidget * parent );
QString acceptable( void );
bool commit( LanCardData & Data );
- void showData( LanCardData & Data );
+ void showData( ALanCard * NNI );
+
+public slots :
+
+ void SLOT_ScanCards( void );
+ void SLOT_RemoveUnknown( void );
private :
- bool ContainedObsoleteMAC;
+ void populateList( void );
+ ALanCard * NNI;
};
diff --git a/noncore/settings/networksettings2/lancard/lancardrun.cpp b/noncore/settings/networksettings2/lancard/lancardrun.cpp
index 951756d..2e4fc43 100644
--- a/noncore/settings/networksettings2/lancard/lancardrun.cpp
+++ b/noncore/settings/networksettings2/lancard/lancardrun.cpp
@@ -1,5 +1,6 @@
#include <qfile.h>
#include <qtextstream.h>
+#include <qstringlist.h>
#include <resources.h>
#include "lancardrun.h"
@@ -53,8 +54,12 @@ void LanCardRun::detectState( NodeCollection * NC ) {
It.current();
++It ) {
Run = It.current();
- if( handlesInterface( Run->Name ) &&
- Run->CardType == ARPHRD_ETHER &&
+ if( handlesInterface( *Run ) &&
+ ( Run->CardType == ARPHRD_ETHER
+#ifdef ARPHRD_IEEE1394
+ || Run->CardType == ARPHRD_IEEE1394
+#endif
+ ) &&
! Run->IsUp
) {
// proper type, and Not UP -> free
@@ -145,8 +150,12 @@ InterfaceInfo * LanCardRun::getInterface( void ) {
It.current();
++It ) {
Run = It.current();
- if( handlesInterface( Run->Name ) &&
- Run->CardType == ARPHRD_ETHER
+ if( handlesInterface( *Run ) &&
+ ( Run->CardType == ARPHRD_ETHER
+#ifdef ARPHRD_IEEE1394
+ || Run->CardType == ARPHRD_IEEE1394
+#endif
+ )
) {
// this is a LAN card
if( Run->assignedNode() == netNode() ) {
@@ -162,5 +171,22 @@ InterfaceInfo * LanCardRun::getInterface( void ) {
}
bool LanCardRun::handlesInterface( const QString & S ) {
+ InterfaceInfo * II;
+ II = NSResources->system().interface( S );
+ if( ( II = NSResources->system().interface( S ) ) ) {
+ return handlesInterface( *II );
+ }
return Pat.match( S ) >= 0;
}
+
+bool LanCardRun::handlesInterface( const InterfaceInfo & II ) {
+ if( Pat.match( II.Name ) < 0 )
+ return 0;
+
+ if( Data->AnyLanCard ) {
+ return 1;
+ }
+
+ // must also match hardware address
+ return ( Data->HWAddresses.findIndex( II.MACAddress ) >= 0 );
+}
diff --git a/noncore/settings/networksettings2/lancard/lancardrun.h b/noncore/settings/networksettings2/lancard/lancardrun.h
index 499b417..e8a535a 100644
--- a/noncore/settings/networksettings2/lancard/lancardrun.h
+++ b/noncore/settings/networksettings2/lancard/lancardrun.h
@@ -10,9 +10,9 @@ class LanCardRun : public AsDevice {
public :
LanCardRun( ANetNodeInstance * NNI,
- LanCardData & Data ) : AsDevice( NNI ),
+ LanCardData & D ) : AsDevice( NNI ),
Pat( "eth[0-9]" )
- { }
+ { Data = &D; }
virtual AsDevice * device( void )
{ return (AsDevice *)this; }
@@ -27,11 +27,13 @@ protected :
bool canSetState( State_t Curr, Action_t A );
bool handlesInterface( const QString & I );
+ bool handlesInterface( const InterfaceInfo & II );
private :
InterfaceInfo * getInterface( void );
QRegExp Pat;
+ LanCardData * Data;
};
#endif