summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/lancard
Side-by-side diff
Diffstat (limited to 'noncore/settings/networksettings2/lancard') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/lancard/config.in4
-rw-r--r--noncore/settings/networksettings2/lancard/lancard.pro18
-rw-r--r--noncore/settings/networksettings2/lancard/lancardGUI.ui129
-rw-r--r--noncore/settings/networksettings2/lancard/lancard_NN.cpp60
-rw-r--r--noncore/settings/networksettings2/lancard/lancard_NN.h44
-rw-r--r--noncore/settings/networksettings2/lancard/lancard_NNI.cpp44
-rw-r--r--noncore/settings/networksettings2/lancard/lancard_NNI.h43
-rw-r--r--noncore/settings/networksettings2/lancard/lancarddata.h13
-rw-r--r--noncore/settings/networksettings2/lancard/lancardedit.cpp95
-rw-r--r--noncore/settings/networksettings2/lancard/lancardedit.h16
-rw-r--r--noncore/settings/networksettings2/lancard/lancardrun.cpp158
-rw-r--r--noncore/settings/networksettings2/lancard/lancardrun.h38
12 files changed, 662 insertions, 0 deletions
diff --git a/noncore/settings/networksettings2/lancard/config.in b/noncore/settings/networksettings2/lancard/config.in
new file mode 100644
index 0000000..d190f6e
--- a/dev/null
+++ b/noncore/settings/networksettings2/lancard/config.in
@@ -0,0 +1,4 @@
+ config NS2LANCARD
+ boolean "opie-networksettings2plugin-lancard (regular wired lan card)"
+ default "n" if NS2
+ depends ( LIBQPE || LIBQPE-X11 ) && LIBOPIE && NS2 && NS2CORE
diff --git a/noncore/settings/networksettings2/lancard/lancard.pro b/noncore/settings/networksettings2/lancard/lancard.pro
new file mode 100644
index 0000000..f188d2b
--- a/dev/null
+++ b/noncore/settings/networksettings2/lancard/lancard.pro
@@ -0,0 +1,18 @@
+TEMPLATE = lib
+CONFIG += qt warn_on release
+DESTDIR = $(OPIEDIR)/plugins/networksettings2
+HEADERS = lancard_NN.h \
+ lancard_NNI.h \
+ lancardedit.h
+SOURCES = lancard_NN.cpp \
+ lancard_NNI.cpp \
+ lancardedit.cpp \
+ lancardrun.cpp
+INCLUDEPATH += $(OPIEDIR)/include ../ ../networksettings2
+DEPENDPATH += $(OPIEDIR)/include ../ ../networksettings2
+LIBS += -lqpe
+INTERFACES = lancardGUI.ui
+TARGET = lancard
+VERSION = 1.0.0
+
+include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/settings/networksettings2/lancard/lancardGUI.ui b/noncore/settings/networksettings2/lancard/lancardGUI.ui
new file mode 100644
index 0000000..8d94816
--- a/dev/null
+++ b/noncore/settings/networksettings2/lancard/lancardGUI.ui
@@ -0,0 +1,129 @@
+<!DOCTYPE UI><UI>
+<class>LanCardGUI</class>
+<widget>
+ <class>QWidget</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>Lancard_FRM</cstring>
+ </property>
+ <property stdset="1">
+ <name>geometry</name>
+ <rect>
+ <x>0</x>
+ <y>0</y>
+ <width>362</width>
+ <height>359</height>
+ </rect>
+ </property>
+ <property stdset="1">
+ <name>caption</name>
+ <string>LAN card</string>
+ </property>
+ <property>
+ <name>layoutMargin</name>
+ </property>
+ <property>
+ <name>layoutSpacing</name>
+ </property>
+ <vbox>
+ <property stdset="1">
+ <name>margin</name>
+ <number>2</number>
+ </property>
+ <property stdset="1">
+ <name>spacing</name>
+ <number>2</number>
+ </property>
+ <widget>
+ <class>QCheckBox</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>AnyCard_CB</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>Any available LAN card</string>
+ </property>
+ <property stdset="1">
+ <name>checked</name>
+ <bool>true</bool>
+ </property>
+ </widget>
+ <widget>
+ <class>QGroupBox</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>GroupBox1</cstring>
+ </property>
+ <property stdset="1">
+ <name>enabled</name>
+ <bool>false</bool>
+ </property>
+ <property stdset="1">
+ <name>title</name>
+ <string>Select Card</string>
+ </property>
+ <property>
+ <name>layoutMargin</name>
+ </property>
+ <vbox>
+ <property stdset="1">
+ <name>margin</name>
+ <number>11</number>
+ </property>
+ <property stdset="1">
+ <name>spacing</name>
+ <number>6</number>
+ </property>
+ <widget>
+ <class>QListView</class>
+ <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>
+ <name>clickable</name>
+ <bool>true</bool>
+ </property>
+ <property>
+ <name>resizeable</name>
+ <bool>true</bool>
+ </property>
+ </column>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>LanCards_LV</cstring>
+ </property>
+ <property stdset="1">
+ <name>allColumnsShowFocus</name>
+ <bool>true</bool>
+ </property>
+ </widget>
+ </vbox>
+ </widget>
+ </vbox>
+</widget>
+<connections>
+ <connection>
+ <sender>AnyCard_CB</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>GroupBox1</receiver>
+ <slot>setDisabled(bool)</slot>
+ </connection>
+</connections>
+</UI>
diff --git a/noncore/settings/networksettings2/lancard/lancard_NN.cpp b/noncore/settings/networksettings2/lancard/lancard_NN.cpp
new file mode 100644
index 0000000..a45496d
--- a/dev/null
+++ b/noncore/settings/networksettings2/lancard/lancard_NN.cpp
@@ -0,0 +1,60 @@
+#include "lancard_NN.h"
+#include "lancard_NNI.h"
+
+static const char * LanCardNeeds[] =
+ { 0 };
+
+/**
+ * Constructor, find all of the possible interfaces
+ */
+LanCardNetNode::LanCardNetNode() : ANetNode() {
+}
+
+/**
+ * Delete any interfaces that we own.
+ */
+LanCardNetNode::~LanCardNetNode(){
+}
+
+const QString LanCardNetNode::nodeDescription(){
+ return tr("\
+<p>Sets up a wired regular LAN card.</p>\
+<p>Use this to set up 10/100/1000 MBit LAN cards.</p>\
+"
+);
+}
+
+ANetNodeInstance * LanCardNetNode::createInstance( void ) {
+ return new ALanCard( this );
+}
+
+
+const char ** LanCardNetNode::needs( void ) {
+ return LanCardNeeds;
+}
+
+const char * LanCardNetNode::provides( void ) {
+ return "device";
+}
+
+bool LanCardNetNode::generateProperFilesFor(
+ ANetNodeInstance * ) {
+ return 1;
+}
+
+bool LanCardNetNode::hasDataFor( const QString & ) {
+ return 0;
+}
+
+bool LanCardNetNode::generateDataForCommonFile(
+ SystemFile & ,
+ long ,
+ ANetNodeInstance * ) {
+ return 1;
+}
+
+extern "C" {
+void create_plugin( QList<ANetNode> & PNN ) {
+ PNN.append( new LanCardNetNode() );
+}
+}
diff --git a/noncore/settings/networksettings2/lancard/lancard_NN.h b/noncore/settings/networksettings2/lancard/lancard_NN.h
new file mode 100644
index 0000000..576a6e0
--- a/dev/null
+++ b/noncore/settings/networksettings2/lancard/lancard_NN.h
@@ -0,0 +1,44 @@
+#ifndef LANCARD_NETNODE_H
+#define LANCARD_NETNODE_H
+
+#include "netnode.h"
+
+class ALanCard;
+
+class LanCardNetNode : public ANetNode{
+
+ Q_OBJECT
+
+public:
+
+ LanCardNetNode();
+ virtual ~LanCardNetNode();
+
+ virtual const QString pixmapName()
+ { return "card"; }
+
+ virtual const QString nodeName()
+ { return tr("LAN card"); }
+
+ virtual const QString nodeDescription() ;
+
+ virtual ANetNodeInstance * createInstance( void );
+
+ virtual const char ** needs( void );
+ virtual const char * provides( void );
+
+ virtual bool generateProperFilesFor( ANetNodeInstance * NNI );
+ virtual bool hasDataFor( const QString & S );
+ virtual bool generateDataForCommonFile(
+ SystemFile & SF, long DevNr, ANetNodeInstance * NNI );
+
+private:
+
+};
+
+extern "C"
+{
+ void create_plugin( QList<ANetNode> & PNN );
+};
+
+#endif
diff --git a/noncore/settings/networksettings2/lancard/lancard_NNI.cpp b/noncore/settings/networksettings2/lancard/lancard_NNI.cpp
new file mode 100644
index 0000000..9595e2e
--- a/dev/null
+++ b/noncore/settings/networksettings2/lancard/lancard_NNI.cpp
@@ -0,0 +1,44 @@
+#include "lancardedit.h"
+#include "lancard_NNI.h"
+#include "lancard_NN.h"
+
+ALanCard::ALanCard( LanCardNetNode * PNN ) : ANetNodeInstance( PNN ) {
+
+ Data.AnyLanCard = 1;
+ Data.HWAddresses.clear();
+
+ GUI = 0;
+ RT = 0;
+}
+
+void ALanCard::setSpecificAttribute( QString & A, QString & V ) {
+ if( A == "matchanycard" ) {
+ Data.AnyLanCard = (V == "yes" );
+ } else if( A == "match" ) {
+ Data.HWAddresses.append( V );
+ }
+}
+
+void ALanCard::saveSpecificAttribute( QTextStream & TS) {
+ TS << "matchanycard=" <<
+ ((Data.AnyLanCard) ? "yes" : "no") << endl;
+ for( QStringList::Iterator it = Data.HWAddresses.begin();
+ it != Data.HWAddresses.end(); ++it ) {
+ TS << "match=" << quote( *it ) << endl;
+ }
+}
+
+QWidget * ALanCard::edit( QWidget * parent ) {
+ GUI = new LanCardEdit( parent );
+ GUI->showData( Data );
+ return GUI;
+}
+
+QString ALanCard::acceptable( void ) {
+ return ( GUI ) ? GUI->acceptable( ) : QString();
+}
+
+void ALanCard::commit( void ) {
+ if( GUI && GUI->commit( Data ) )
+ setModified( 1 );
+}
diff --git a/noncore/settings/networksettings2/lancard/lancard_NNI.h b/noncore/settings/networksettings2/lancard/lancard_NNI.h
new file mode 100644
index 0000000..8fc8868
--- a/dev/null
+++ b/noncore/settings/networksettings2/lancard/lancard_NNI.h
@@ -0,0 +1,43 @@
+#ifndef LANCARD_H
+#define LANCARD_H
+
+#include <netnode.h>
+#include "lancarddata.h"
+#include "lancardrun.h"
+
+class LanCardNetNode;
+class LanCardEdit;
+
+class ALanCard : public ANetNodeInstance {
+
+public :
+
+ ALanCard( LanCardNetNode * PNN );
+
+ QWidget * edit( QWidget * parent );
+ QString acceptable( void );
+ void commit( void );
+
+ RuntimeInfo * runtime( void )
+ { if( RT == 0 )
+ RT = new LanCardRun( this, Data );
+ return RT;
+ }
+
+ virtual void * data( void )
+ { return (void *)&Data; }
+
+protected :
+
+ virtual void setSpecificAttribute( QString & Attr, QString & Value );
+ virtual void saveSpecificAttribute( QTextStream & TS );
+
+private :
+
+ LanCardEdit * GUI;
+ LanCardData Data;
+ LanCardRun * RT;
+
+};
+
+#endif
diff --git a/noncore/settings/networksettings2/lancard/lancarddata.h b/noncore/settings/networksettings2/lancard/lancarddata.h
new file mode 100644
index 0000000..c76767f
--- a/dev/null
+++ b/noncore/settings/networksettings2/lancard/lancarddata.h
@@ -0,0 +1,13 @@
+#ifndef LANCARD_DATA_H
+#define LANCARD_DATA_H
+
+#include <qstringlist.h>
+#include <qstring.h>
+
+typedef struct LanCardData {
+ bool AnyLanCard;
+ QStringList HWAddresses;
+
+} LanCardData_t;
+
+#endif
diff --git a/noncore/settings/networksettings2/lancard/lancardedit.cpp b/noncore/settings/networksettings2/lancard/lancardedit.cpp
new file mode 100644
index 0000000..fa7f6dc
--- a/dev/null
+++ b/noncore/settings/networksettings2/lancard/lancardedit.cpp
@@ -0,0 +1,95 @@
+#include <GUIUtils.h>
+#include <resources.h>
+#include <qlistview.h>
+#include <qcheckbox.h>
+#include <qheader.h>
+#include <qregexp.h>
+#include "lancardedit.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
+ int idx;
+ QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild();
+ while( CLI ) {
+ idx = Data.HWAddresses.findIndex(CLI->text(1));
+ if( CLI->isOn() ) {
+ if( idx < 0 ) {
+ // should be in list
+ Data.HWAddresses.append( CLI->text(1) );
+ SM = 1;
+ }
+ } else {
+ // should not be in list
+ if( idx >= 0 ) {
+ Data.HWAddresses.remove( Data.HWAddresses.at(idx) );
+ SM = 1;
+ }
+ }
+ CLI = (QCheckListItem *)CLI->nextSibling();
+ }
+ }
+ return SM || ContainedObsoleteMAC ;
+}
+
+void LanCardEdit::showData( LanCardData & Data ) {
+ AnyCard_CB->setChecked( Data.AnyLanCard );
+
+ QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild();
+
+ 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
+ break;
+ CLI = (QCheckListItem *)CLI->nextSibling();
+ }
+ if( CLI == 0 ) {
+ // address not found -> remove
+ ContainedObsoleteMAC = 1;
+ Data.HWAddresses.remove( it );
+ } else {
+ ++ it;
+ }
+ }
+
+ // set checks
+ while( CLI ) {
+ CLI->setOn( Data.HWAddresses.findIndex(CLI->text(1)) >= 0 );
+ CLI = (QCheckListItem *)CLI->nextSibling();
+ }
+}
diff --git a/noncore/settings/networksettings2/lancard/lancardedit.h b/noncore/settings/networksettings2/lancard/lancardedit.h
new file mode 100644
index 0000000..8def789
--- a/dev/null
+++ b/noncore/settings/networksettings2/lancard/lancardedit.h
@@ -0,0 +1,16 @@
+#include "lancarddata.h"
+#include "lancardGUI.h"
+
+class LanCardEdit : public LanCardGUI {
+
+public :
+
+ LanCardEdit( QWidget * parent );
+ QString acceptable( void );
+ bool commit( LanCardData & Data );
+ void showData( LanCardData & Data );
+
+private :
+
+ bool ContainedObsoleteMAC;
+};
diff --git a/noncore/settings/networksettings2/lancard/lancardrun.cpp b/noncore/settings/networksettings2/lancard/lancardrun.cpp
new file mode 100644
index 0000000..b3b592b
--- a/dev/null
+++ b/noncore/settings/networksettings2/lancard/lancardrun.cpp
@@ -0,0 +1,158 @@
+#include <qfile.h>
+#include <qtextstream.h>
+#include <resources.h>
+#include "lancardrun.h"
+
+void LanCardRun::detectState( NodeCollection * NC ) {
+
+ // unavailable : no card found
+ // available : card found and assigned to us or free
+ // up : card found and assigned to us and up
+
+ QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number());
+ System & Sys = NSResources->system();
+ InterfaceInfo * Run;
+
+ QFile F( S );
+
+ if( F.open( IO_ReadOnly ) ) {
+ // could open file -> read interface and assign
+ QString X;
+ QTextStream TS(&F);
+ X = TS.readLine();
+ // find interface
+ if( handlesInterface( X ) ) {
+ for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
+ It.current();
+ ++It ) {
+ Run = It.current();
+ if( X == Run->Name ) {
+ Run->assignNode( netNode() );
+ assignInterface( Run );
+ NC->setCurrentState( IsUp );
+ return;
+ }
+ }
+ }
+ }
+
+ // we are certainly not UP
+ assignInterface( 0 );
+
+ // find possible interface
+ for( QDictIterator<InterfaceInfo> It(Sys.interfaces());
+ It.current();
+ ++It ) {
+ Run = It.current();
+ if( handlesInterface( Run->Name ) &&
+ Run->CardType == ARPHRD_ETHER &&
+ ! Run->IsUp
+ ) {
+ // proper type, and Not UP -> free
+ NC->setCurrentState( Off );
+ return;
+ }
+ }
+ // no free found
+
+ NC->setCurrentState( Unavailable );
+
+}
+
+bool LanCardRun::setState( NodeCollection * NC, Action_t A ) {
+
+ // we only handle activate and deactivate
+ switch( A ) {
+ case Activate :
+ {
+ if( NC->currentState() != Off ) {
+ return 0;
+ }
+ InterfaceInfo * N = getInterface();
+ if( ! N ) {
+ // no interface available
+ NC->setCurrentState( Unavailable );
+ return 0;
+ }
+ // because we were OFF the interface
+ // we get back is NOT assigned
+ N->assignNode( netNode() );
+ assignInterface( N );
+ NC->setCurrentState( Available );
+ return 1;
+ }
+ case Deactivate :
+ if( NC->currentState() == IsUp ) {
+ // bring down first
+ if( ! connection()->setState( Down ) )
+ // could not ...
+ return 0;
+ }
+ if( NC->currentState() != Available ) {
+ return 1;
+ }
+ assignedInterface()->assignNode( 0 ); // release
+ assignInterface( 0 );
+ NC->setCurrentState( Off );
+ return 1;
+ default :
+ // FT
+ break;
+ }
+ return 0;
+}
+
+bool LanCardRun::canSetState( State_t Curr, Action_t A ) {
+ // we only handle up down activate and deactivate
+ switch( A ) {
+ case Activate :
+ { // at least available
+ if( Curr == Available ) {
+ return 1;
+ }
+ // or we can make one available
+ InterfaceInfo * N = getInterface();
+ if( ! N || N->assignedNode() != 0 ) {
+ // non available or assigned
+ return 0;
+ }
+ return 1;
+ }
+ case Deactivate :
+ return ( Curr >= Available );
+ default :
+ // FT
+ break;
+ }
+ return 0;
+}
+
+// get interface that is free or assigned to us
+InterfaceInfo * LanCardRun::getInterface( void ) {
+
+ System & S = NSResources->system();
+ InterfaceInfo * best = 0, * Run;
+
+ for( QDictIterator<InterfaceInfo> It(S.interfaces());
+ It.current();
+ ++It ) {
+ Run = It.current();
+ if( handlesInterface( Run->Name ) &&
+ Run->CardType == ARPHRD_ETHER
+ ) {
+ // this is a LAN card
+ if( Run->assignedNode() == netNode() ) {
+ // assigned to us
+ return Run;
+ } else if( Run->assignedNode() == 0 ) {
+ // free
+ best = Run;
+ }
+ }
+ }
+ return best; // can be 0
+}
+
+bool LanCardRun::handlesInterface( const QString & S ) {
+ return Pat.match( S ) >= 0;
+}
diff --git a/noncore/settings/networksettings2/lancard/lancardrun.h b/noncore/settings/networksettings2/lancard/lancardrun.h
new file mode 100644
index 0000000..5f004e0
--- a/dev/null
+++ b/noncore/settings/networksettings2/lancard/lancardrun.h
@@ -0,0 +1,38 @@
+#ifndef LANCARDRUN_H
+#define LANCARDRUN_H
+
+#include <asdevice.h>
+#include <qregexp.h>
+#include "lancarddata.h"
+
+class LanCardRun : public AsDevice {
+
+public :
+
+ LanCardRun( ANetNodeInstance * NNI,
+ LanCardData & Data ) : AsDevice( NNI ),
+ Pat( "eth[0-9]" )
+ { }
+
+ virtual long count( void )
+ { return 2; }
+ virtual QString genNic( long nr )
+ { QString S; return S.sprintf( "eth%ld", nr ); }
+ virtual AsDevice * device( void )
+ { return asDevice(); }
+
+protected :
+
+ void detectState( NodeCollection * NC );
+ bool setState( NodeCollection * NC, Action_t A );
+ bool canSetState( State_t Curr, Action_t A );
+
+ bool handlesInterface( const QString & I );
+
+private :
+
+ InterfaceInfo * getInterface( void );
+ QRegExp Pat;
+
+};
+#endif