Diffstat (limited to 'noncore/settings/networksettings2/lancard') (more/less context) (ignore whitespace changes)
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 | |||
@@ -2,25 +2,25 @@ | |||
2 | <class>LanCardGUI</class> | 2 | <class>LanCardGUI</class> |
3 | <widget> | 3 | <widget> |
4 | <class>QWidget</class> | 4 | <class>QWidget</class> |
5 | <property stdset="1"> | 5 | <property stdset="1"> |
6 | <name>name</name> | 6 | <name>name</name> |
7 | <cstring>Lancard_FRM</cstring> | 7 | <cstring>Lancard_FRM</cstring> |
8 | </property> | 8 | </property> |
9 | <property stdset="1"> | 9 | <property stdset="1"> |
10 | <name>geometry</name> | 10 | <name>geometry</name> |
11 | <rect> | 11 | <rect> |
12 | <x>0</x> | 12 | <x>0</x> |
13 | <y>0</y> | 13 | <y>0</y> |
14 | <width>362</width> | 14 | <width>354</width> |
15 | <height>359</height> | 15 | <height>359</height> |
16 | </rect> | 16 | </rect> |
17 | </property> | 17 | </property> |
18 | <property stdset="1"> | 18 | <property stdset="1"> |
19 | <name>caption</name> | 19 | <name>caption</name> |
20 | <string>LAN card</string> | 20 | <string>LAN card</string> |
21 | </property> | 21 | </property> |
22 | <property> | 22 | <property> |
23 | <name>layoutMargin</name> | 23 | <name>layoutMargin</name> |
24 | </property> | 24 | </property> |
25 | <property> | 25 | <property> |
26 | <name>layoutSpacing</name> | 26 | <name>layoutSpacing</name> |
@@ -60,70 +60,130 @@ | |||
60 | <bool>false</bool> | 60 | <bool>false</bool> |
61 | </property> | 61 | </property> |
62 | <property stdset="1"> | 62 | <property stdset="1"> |
63 | <name>title</name> | 63 | <name>title</name> |
64 | <string>Select Card</string> | 64 | <string>Select Card</string> |
65 | </property> | 65 | </property> |
66 | <property> | 66 | <property> |
67 | <name>layoutMargin</name> | 67 | <name>layoutMargin</name> |
68 | </property> | 68 | </property> |
69 | <vbox> | 69 | <vbox> |
70 | <property stdset="1"> | 70 | <property stdset="1"> |
71 | <name>margin</name> | 71 | <name>margin</name> |
72 | <number>11</number> | 72 | <number>5</number> |
73 | </property> | 73 | </property> |
74 | <property stdset="1"> | 74 | <property stdset="1"> |
75 | <name>spacing</name> | 75 | <name>spacing</name> |
76 | <number>6</number> | 76 | <number>6</number> |
77 | </property> | 77 | </property> |
78 | <widget> | 78 | <widget> |
79 | <class>QListView</class> | 79 | <class>QListView</class> |
80 | <column> | 80 | <column> |
81 | <property> | 81 | <property> |
82 | <name>text</name> | 82 | <name>text</name> |
83 | <string>Name</string> | ||
84 | </property> | ||
85 | <property> | ||
86 | <name>clickable</name> | ||
87 | <bool>true</bool> | ||
88 | </property> | ||
89 | <property> | ||
90 | <name>resizeable</name> | ||
91 | <bool>true</bool> | ||
92 | </property> | ||
93 | </column> | ||
94 | <column> | ||
95 | <property> | ||
96 | <name>text</name> | ||
97 | <string>MACAddress</string> | 83 | <string>MACAddress</string> |
98 | </property> | 84 | </property> |
99 | <property> | 85 | <property> |
100 | <name>clickable</name> | 86 | <name>clickable</name> |
101 | <bool>true</bool> | 87 | <bool>true</bool> |
102 | </property> | 88 | </property> |
103 | <property> | 89 | <property> |
104 | <name>resizeable</name> | 90 | <name>resizeable</name> |
105 | <bool>true</bool> | 91 | <bool>true</bool> |
106 | </property> | 92 | </property> |
107 | </column> | 93 | </column> |
108 | <property stdset="1"> | 94 | <property stdset="1"> |
109 | <name>name</name> | 95 | <name>name</name> |
110 | <cstring>LanCards_LV</cstring> | 96 | <cstring>LanCards_LV</cstring> |
111 | </property> | 97 | </property> |
112 | <property stdset="1"> | 98 | <property stdset="1"> |
113 | <name>allColumnsShowFocus</name> | 99 | <name>allColumnsShowFocus</name> |
114 | <bool>true</bool> | 100 | <bool>true</bool> |
115 | </property> | 101 | </property> |
116 | </widget> | 102 | </widget> |
103 | <widget> | ||
104 | <class>QLayoutWidget</class> | ||
105 | <property stdset="1"> | ||
106 | <name>name</name> | ||
107 | <cstring>Layout2</cstring> | ||
108 | </property> | ||
109 | <hbox> | ||
110 | <property stdset="1"> | ||
111 | <name>margin</name> | ||
112 | <number>0</number> | ||
113 | </property> | ||
114 | <property stdset="1"> | ||
115 | <name>spacing</name> | ||
116 | <number>6</number> | ||
117 | </property> | ||
118 | <widget> | ||
119 | <class>QPushButton</class> | ||
120 | <property stdset="1"> | ||
121 | <name>name</name> | ||
122 | <cstring>RemoveUnknown_BUT</cstring> | ||
123 | </property> | ||
124 | <property stdset="1"> | ||
125 | <name>text</name> | ||
126 | <string>Remove Unknown</string> | ||
127 | </property> | ||
128 | </widget> | ||
129 | <spacer> | ||
130 | <property> | ||
131 | <name>name</name> | ||
132 | <cstring>Spacer1</cstring> | ||
133 | </property> | ||
134 | <property stdset="1"> | ||
135 | <name>orientation</name> | ||
136 | <enum>Horizontal</enum> | ||
137 | </property> | ||
138 | <property stdset="1"> | ||
139 | <name>sizeType</name> | ||
140 | <enum>Expanding</enum> | ||
141 | </property> | ||
142 | <property> | ||
143 | <name>sizeHint</name> | ||
144 | <size> | ||
145 | <width>20</width> | ||
146 | <height>20</height> | ||
147 | </size> | ||
148 | </property> | ||
149 | </spacer> | ||
150 | <widget> | ||
151 | <class>QPushButton</class> | ||
152 | <property stdset="1"> | ||
153 | <name>name</name> | ||
154 | <cstring>RescanCards_BUT</cstring> | ||
155 | </property> | ||
156 | <property stdset="1"> | ||
157 | <name>text</name> | ||
158 | <string>Rescan</string> | ||
159 | </property> | ||
160 | </widget> | ||
161 | </hbox> | ||
162 | </widget> | ||
117 | </vbox> | 163 | </vbox> |
118 | </widget> | 164 | </widget> |
119 | </vbox> | 165 | </vbox> |
120 | </widget> | 166 | </widget> |
121 | <connections> | 167 | <connections> |
122 | <connection> | 168 | <connection> |
123 | <sender>AnyCard_CB</sender> | 169 | <sender>AnyCard_CB</sender> |
124 | <signal>toggled(bool)</signal> | 170 | <signal>toggled(bool)</signal> |
125 | <receiver>GroupBox1</receiver> | 171 | <receiver>GroupBox1</receiver> |
126 | <slot>setDisabled(bool)</slot> | 172 | <slot>setDisabled(bool)</slot> |
127 | </connection> | 173 | </connection> |
174 | <connection> | ||
175 | <sender>RescanCards_BUT</sender> | ||
176 | <signal>clicked()</signal> | ||
177 | <receiver>Lancard_FRM</receiver> | ||
178 | <slot>SLOT_ScanCards()</slot> | ||
179 | </connection> | ||
180 | <connection> | ||
181 | <sender>RemoveUnknown_BUT</sender> | ||
182 | <signal>clicked()</signal> | ||
183 | <receiver>Lancard_FRM</receiver> | ||
184 | <slot>SLOT_RemoveUnknown()</slot> | ||
185 | </connection> | ||
186 | <slot access="public">SLOT_ScanCards()</slot> | ||
187 | <slot access="public">SLOT_RemoveUnknown()</slot> | ||
128 | </connections> | 188 | </connections> |
129 | </UI> | 189 | </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 | |||
@@ -1,22 +1,22 @@ | |||
1 | #include "lancard_NN.h" | 1 | #include "lancard_NN.h" |
2 | #include "lancard_NNI.h" | 2 | #include "lancard_NNI.h" |
3 | 3 | ||
4 | static const char * LanCardNeeds[] = | 4 | static const char * LanCardNeeds[] = |
5 | { 0 }; | 5 | { 0 }; |
6 | 6 | ||
7 | /** | 7 | /** |
8 | * Constructor, find all of the possible interfaces | 8 | * Constructor, find all of the possible interfaces |
9 | */ | 9 | */ |
10 | LanCardNetNode::LanCardNetNode() : ANetNode() { | 10 | LanCardNetNode::LanCardNetNode() : ANetNode(tr("LAN card")), NICMACAddresses() { |
11 | InstanceCount = 2; | 11 | InstanceCount = 2; |
12 | } | 12 | } |
13 | 13 | ||
14 | /** | 14 | /** |
15 | * Delete any interfaces that we own. | 15 | * Delete any interfaces that we own. |
16 | */ | 16 | */ |
17 | LanCardNetNode::~LanCardNetNode(){ | 17 | LanCardNetNode::~LanCardNetNode(){ |
18 | } | 18 | } |
19 | 19 | ||
20 | const QString LanCardNetNode::nodeDescription(){ | 20 | const QString LanCardNetNode::nodeDescription(){ |
21 | return tr("\ | 21 | return tr("\ |
22 | <p>Sets up a wired regular LAN card.</p>\ | 22 | <p>Sets up a wired regular LAN card.</p>\ |
@@ -60,26 +60,35 @@ bool LanCardNetNode::generateDeviceDataForCommonFile( | |||
60 | } | 60 | } |
61 | return 0; | 61 | return 0; |
62 | } | 62 | } |
63 | 63 | ||
64 | QString LanCardNetNode::genNic( long nr ) { | 64 | QString LanCardNetNode::genNic( long nr ) { |
65 | QString S; | 65 | QString S; |
66 | return S.sprintf( "eth%ld", nr ); | 66 | return S.sprintf( "eth%ld", nr ); |
67 | } | 67 | } |
68 | 68 | ||
69 | void LanCardNetNode::setSpecificAttribute( QString & A, QString & V ) { | 69 | void LanCardNetNode::setSpecificAttribute( QString & A, QString & V ) { |
70 | if( A == "interfacecount" ) { | 70 | if( A == "interfacecount" ) { |
71 | InstanceCount = V.toLong(); | 71 | InstanceCount = V.toLong(); |
72 | } else if ( A == "macaddress" ) { | ||
73 | NICMACAddresses.append( V ); | ||
72 | } | 74 | } |
73 | } | 75 | } |
74 | 76 | ||
75 | void LanCardNetNode::saveSpecificAttribute( QTextStream & TS) { | 77 | void LanCardNetNode::saveSpecificAttribute( QTextStream & TS) { |
76 | TS << "interfacecount=" | 78 | TS << "interfacecount=" |
77 | << InstanceCount | 79 | << InstanceCount |
78 | << endl; | 80 | << endl; |
81 | for( QStringList::Iterator it = NICMACAddresses.begin(); | ||
82 | it != NICMACAddresses.end(); | ||
83 | ++it ) { | ||
84 | TS << "macaddress=" | ||
85 | << (*it) | ||
86 | << endl; | ||
87 | } | ||
79 | } | 88 | } |
80 | 89 | ||
81 | extern "C" { | 90 | extern "C" { |
82 | void create_plugin( QList<ANetNode> & PNN ) { | 91 | void create_plugin( QList<ANetNode> & PNN ) { |
83 | PNN.append( new LanCardNetNode() ); | 92 | PNN.append( new LanCardNetNode() ); |
84 | } | 93 | } |
85 | } | 94 | } |
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,55 +1,57 @@ | |||
1 | #ifndef LANCARD_NETNODE_H | 1 | #ifndef LANCARD_NETNODE_H |
2 | #define LANCARD_NETNODE_H | 2 | #define LANCARD_NETNODE_H |
3 | 3 | ||
4 | #include <qstringlist.h> | ||
4 | #include "netnode.h" | 5 | #include "netnode.h" |
5 | 6 | ||
6 | class ALanCard; | 7 | class ALanCard; |
7 | 8 | ||
8 | class LanCardNetNode : public ANetNode{ | 9 | class LanCardNetNode : public ANetNode{ |
9 | 10 | ||
10 | Q_OBJECT | 11 | Q_OBJECT |
11 | 12 | ||
12 | public: | 13 | public: |
13 | 14 | ||
14 | LanCardNetNode(); | 15 | LanCardNetNode(); |
15 | virtual ~LanCardNetNode(); | 16 | virtual ~LanCardNetNode(); |
16 | 17 | ||
17 | virtual const QString pixmapName() | 18 | virtual const QString pixmapName() |
18 | { return "Devices/card"; } | 19 | { return "Devices/card"; } |
19 | 20 | ||
20 | virtual const QString nodeName() | ||
21 | { return tr("LAN card"); } | ||
22 | |||
23 | virtual const QString nodeDescription() ; | 21 | virtual const QString nodeDescription() ; |
24 | 22 | ||
25 | virtual ANetNodeInstance * createInstance( void ); | 23 | virtual ANetNodeInstance * createInstance( void ); |
26 | 24 | ||
27 | virtual const char ** needs( void ); | 25 | virtual const char ** needs( void ); |
28 | virtual const char * provides( void ); | 26 | virtual const char * provides( void ); |
29 | 27 | ||
30 | virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); | 28 | virtual bool generateProperFilesFor( ANetNodeInstance * NNI ); |
31 | virtual bool hasDataFor( const QString & S ); | 29 | virtual bool hasDataFor( const QString & S ); |
32 | virtual bool generateDeviceDataForCommonFile( | 30 | virtual bool generateDeviceDataForCommonFile( |
33 | SystemFile & SF, long DevNr ); | 31 | SystemFile & SF, long DevNr ); |
34 | 32 | ||
35 | virtual long instanceCount( void ) | 33 | virtual long instanceCount( void ) |
36 | { return InstanceCount; } | 34 | { return InstanceCount; } |
37 | 35 | ||
38 | virtual QString genNic( long ); | 36 | virtual QString genNic( long ); |
37 | virtual QStringList & addressesOfNIC( void ) | ||
38 | { return NICMACAddresses; } | ||
39 | 39 | ||
40 | private: | 40 | private: |
41 | 41 | ||
42 | virtual void setSpecificAttribute( QString & Attr, QString & Value ); | 42 | virtual void setSpecificAttribute( QString & Attr, QString & Value ); |
43 | virtual void saveSpecificAttribute( QTextStream & TS ); | 43 | virtual void saveSpecificAttribute( QTextStream & TS ); |
44 | 44 | ||
45 | // number of interfaces for this device | 45 | // number of interfaces for this device |
46 | long InstanceCount; | 46 | long InstanceCount; |
47 | 47 | ||
48 | QStringList NICMACAddresses; | ||
49 | |||
48 | }; | 50 | }; |
49 | 51 | ||
50 | extern "C" | 52 | extern "C" |
51 | { | 53 | { |
52 | void create_plugin( QList<ANetNode> & PNN ); | 54 | void create_plugin( QList<ANetNode> & PNN ); |
53 | }; | 55 | }; |
54 | 56 | ||
55 | #endif | 57 | #endif |
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 | |||
@@ -21,25 +21,25 @@ void ALanCard::setSpecificAttribute( QString & A, QString & V ) { | |||
21 | 21 | ||
22 | void ALanCard::saveSpecificAttribute( QTextStream & TS) { | 22 | void ALanCard::saveSpecificAttribute( QTextStream & TS) { |
23 | TS << "matchanycard=" << | 23 | TS << "matchanycard=" << |
24 | ((Data.AnyLanCard) ? "yes" : "no") << endl; | 24 | ((Data.AnyLanCard) ? "yes" : "no") << endl; |
25 | for( QStringList::Iterator it = Data.HWAddresses.begin(); | 25 | for( QStringList::Iterator it = Data.HWAddresses.begin(); |
26 | it != Data.HWAddresses.end(); ++it ) { | 26 | it != Data.HWAddresses.end(); ++it ) { |
27 | TS << "match=" << quote( *it ) << endl; | 27 | TS << "match=" << quote( *it ) << endl; |
28 | } | 28 | } |
29 | } | 29 | } |
30 | 30 | ||
31 | QWidget * ALanCard::edit( QWidget * parent ) { | 31 | QWidget * ALanCard::edit( QWidget * parent ) { |
32 | GUI = new LanCardEdit( parent ); | 32 | GUI = new LanCardEdit( parent ); |
33 | GUI->showData( Data ); | 33 | GUI->showData( this ); |
34 | return GUI; | 34 | return GUI; |
35 | } | 35 | } |
36 | 36 | ||
37 | QString ALanCard::acceptable( void ) { | 37 | QString ALanCard::acceptable( void ) { |
38 | return ( GUI ) ? GUI->acceptable( ) : QString(); | 38 | return ( GUI ) ? GUI->acceptable( ) : QString(); |
39 | } | 39 | } |
40 | 40 | ||
41 | void ALanCard::commit( void ) { | 41 | void ALanCard::commit( void ) { |
42 | if( GUI && GUI->commit( Data ) ) | 42 | if( GUI && GUI->commit( Data ) ) |
43 | setModified( 1 ); | 43 | setModified( 1 ); |
44 | } | 44 | } |
45 | 45 | ||
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 @@ | |||
1 | #include <GUIUtils.h> | 1 | #include <GUIUtils.h> |
2 | #include <resources.h> | 2 | #include <resources.h> |
3 | #include <qarray.h> | ||
3 | #include <qlistview.h> | 4 | #include <qlistview.h> |
4 | #include <qcheckbox.h> | 5 | #include <qcheckbox.h> |
5 | #include <qheader.h> | 6 | #include <qheader.h> |
6 | #include <qregexp.h> | 7 | #include <qregexp.h> |
8 | |||
7 | #include "lancardedit.h" | 9 | #include "lancardedit.h" |
10 | #include "lancard_NN.h" | ||
11 | #include "lancard_NNI.h" | ||
8 | 12 | ||
9 | LanCardEdit::LanCardEdit( QWidget * Parent ) : LanCardGUI( Parent ){ | 13 | LanCardEdit::LanCardEdit( QWidget * Parent ) : LanCardGUI( Parent ){ |
10 | System & S = NSResources->system(); | ||
11 | QRegExp R( "eth[0-9]" ); | ||
12 | QCheckListItem * CLI; | ||
13 | |||
14 | LanCards_LV->header()->hide(); | 14 | LanCards_LV->header()->hide(); |
15 | 15 | ||
16 | // populate with all lancards in system | ||
17 | for( QDictIterator<InterfaceInfo> It(S.interfaces()); | ||
18 | It.current(); | ||
19 | ++It ) { | ||
20 | if( R.match( It.current()->Name ) >= 0 && | ||
21 | It.current()->CardType == ARPHRD_ETHER | ||
22 | ) { | ||
23 | CLI = new QCheckListItem( LanCards_LV, It.current()->Name, | ||
24 | QCheckListItem::CheckBox ); | ||
25 | CLI->setText( 1, It.current()->MACAddress ); | ||
26 | } | ||
27 | } | ||
28 | } | 16 | } |
29 | 17 | ||
30 | QString LanCardEdit::acceptable( void ) { | 18 | QString LanCardEdit::acceptable( void ) { |
31 | return QString(); | 19 | return QString(); |
32 | } | 20 | } |
33 | 21 | ||
34 | |||
35 | bool LanCardEdit::commit( LanCardData & Data ) { | 22 | bool LanCardEdit::commit( LanCardData & Data ) { |
36 | bool SM = 0; | 23 | bool SM = 0; |
37 | CBM( Data.AnyLanCard, AnyCard_CB, SM ); | 24 | CBM( Data.AnyLanCard, AnyCard_CB, SM ); |
38 | 25 | ||
39 | if( ! Data.AnyLanCard ) { | 26 | if( ! Data.AnyLanCard ) { |
40 | // collect set of lancards that match | 27 | // take copy for orig list |
28 | QStringList NewList( Data.HWAddresses ); | ||
29 | |||
30 | // update HWAddresses to new state | ||
31 | // remove item also from NewList | ||
41 | int idx; | 32 | int idx; |
42 | QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild(); | 33 | QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild(); |
43 | while( CLI ) { | 34 | while( CLI ) { |
44 | idx = Data.HWAddresses.findIndex(CLI->text(1)); | 35 | idx = Data.HWAddresses.findIndex(CLI->text(0)); |
45 | if( CLI->isOn() ) { | 36 | if( CLI->isOn() ) { |
46 | if( idx < 0 ) { | 37 | if( idx < 0 ) { |
47 | // should be in list | 38 | // should be in list |
48 | Data.HWAddresses.append( CLI->text(1) ); | 39 | Data.HWAddresses.append( CLI->text(0) ); |
49 | SM = 1; | 40 | SM = 1; |
50 | } | 41 | } |
51 | } else { | 42 | } else { |
52 | // should not be in list | 43 | // should not be in list |
53 | if( idx >= 0 ) { | 44 | if( idx >= 0 ) { |
54 | Data.HWAddresses.remove( Data.HWAddresses.at(idx) ); | 45 | NewList.remove( CLI->text(0) ); |
46 | Data.HWAddresses.remove( CLI->text(0) ); | ||
55 | SM = 1; | 47 | SM = 1; |
56 | } | 48 | } |
57 | } | 49 | } |
58 | CLI = (QCheckListItem *)CLI->nextSibling(); | 50 | CLI = (QCheckListItem *)CLI->nextSibling(); |
59 | } | 51 | } |
52 | |||
53 | // if newlist still contains items. it were items | ||
54 | // that were checked but no longer are present in the system | ||
55 | SM |= ( NewList.count() > 0 ) ; | ||
60 | } | 56 | } |
61 | return SM || ContainedObsoleteMAC ; | 57 | return SM; |
62 | } | 58 | } |
63 | 59 | ||
64 | void LanCardEdit::showData( LanCardData & Data ) { | 60 | void LanCardEdit::showData( ALanCard * LC ) { |
61 | NNI = LC; | ||
62 | LanCardData & Data = *((LanCardData *)LC->data()); | ||
63 | |||
65 | AnyCard_CB->setChecked( Data.AnyLanCard ); | 64 | AnyCard_CB->setChecked( Data.AnyLanCard ); |
66 | 65 | ||
66 | // load all cards | ||
67 | populateList(); | ||
68 | |||
69 | // set checks | ||
67 | QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild(); | 70 | QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild(); |
71 | while( CLI ) { | ||
72 | CLI->setOn( Data.HWAddresses.findIndex(CLI->text(0)) >= 0 ); | ||
73 | CLI = (QCheckListItem *)CLI->nextSibling(); | ||
74 | } | ||
75 | } | ||
68 | 76 | ||
69 | ContainedObsoleteMAC = 0; | 77 | // load all known cards in list |
70 | // remove obsolete address | 78 | void LanCardEdit::populateList( void ) { |
71 | for( QStringList::Iterator it=Data.HWAddresses.begin(); | 79 | LanCardNetNode *NN = (LanCardNetNode *)NNI->nodeClass(); |
72 | it != Data.HWAddresses.end(); | 80 | QCheckListItem * CLI; |
73 | ) { | 81 | bool Found; |
74 | CLI = (QCheckListItem *)LanCards_LV->firstChild(); | 82 | |
75 | while( CLI ) { | 83 | LanCards_LV->clear(); |
76 | if( CLI->text(1) == (*it) ) | 84 | |
77 | // still valid | 85 | for( QStringList::Iterator it = NN->addressesOfNIC().begin(); |
86 | it != NN->addressesOfNIC().end(); | ||
87 | ++it ) { | ||
88 | CLI = new QCheckListItem( LanCards_LV, (*it), QCheckListItem::CheckBox ); | ||
89 | |||
90 | // check interfaces and see if this card is present | ||
91 | Found = 0; | ||
92 | for( QDictIterator<InterfaceInfo> NIt(NSResources->system().interfaces()); | ||
93 | NIt.current(); | ||
94 | ++NIt ) { | ||
95 | if( NIt.current()->MACAddress == (*it) ) { | ||
96 | Found = 1; | ||
78 | break; | 97 | break; |
79 | CLI = (QCheckListItem *)CLI->nextSibling(); | 98 | } |
80 | } | 99 | } |
81 | if( CLI == 0 ) { | 100 | |
82 | // address not found -> remove | 101 | CLI->setPixmap( 0, NSResources->getPixmap( |
83 | ContainedObsoleteMAC = 1; | 102 | (Found) ? "add" : "remove" ) ); |
84 | Data.HWAddresses.remove( it ); | 103 | } |
85 | } else { | 104 | } |
86 | ++ it; | 105 | |
106 | // rescan system for new cards | ||
107 | void LanCardEdit::SLOT_ScanCards( void ) { | ||
108 | LanCardNetNode *NN = (LanCardNetNode *)NNI->nodeClass(); | ||
109 | |||
110 | // add any NIC that is new and matches our interfacename | ||
111 | System & S = NSResources->system(); | ||
112 | QRegExp R( "eth[0-9]" ); | ||
113 | // populate with all lancards in system | ||
114 | for( QDictIterator<InterfaceInfo> It(S.interfaces()); | ||
115 | It.current(); | ||
116 | ++It ) { | ||
117 | fprintf( stderr, "TEST %s %s\n", | ||
118 | It.current()->Name.latin1(), | ||
119 | It.current()->MACAddress.latin1() ); | ||
120 | if( R.match( It.current()->Name ) >= 0 && | ||
121 | ( It.current()->CardType == ARPHRD_ETHER | ||
122 | #ifdef ARPHRD_IEEE1394 | ||
123 | || It.current()->CardType == ARPHRD_IEEE1394 | ||
124 | #endif | ||
125 | ) | ||
126 | ) { | ||
127 | // old item ? | ||
128 | QCheckListItem * CLI = | ||
129 | (QCheckListItem *)LanCards_LV->firstChild(); | ||
130 | while( CLI ) { | ||
131 | if( CLI->text(0) == It.current()->MACAddress ) { | ||
132 | break; | ||
133 | } | ||
134 | CLI = (QCheckListItem *)CLI->nextSibling(); | ||
135 | } | ||
136 | |||
137 | if( ! CLI ) { | ||
138 | // new item | ||
139 | CLI = new QCheckListItem( LanCards_LV, | ||
140 | It.current()->MACAddress, | ||
141 | QCheckListItem::CheckBox ); | ||
142 | } | ||
143 | |||
144 | // mark present | ||
145 | CLI->setPixmap( 0, NSResources->getPixmap( | ||
146 | "add" ) ); | ||
147 | |||
148 | if( NN->addressesOfNIC().findIndex( It.current()->MACAddress) < 0 ) { | ||
149 | // new | ||
150 | NN->addressesOfNIC().append( It.current()->MACAddress ); | ||
151 | } | ||
87 | } | 152 | } |
88 | } | 153 | } |
89 | 154 | ||
90 | // set checks | 155 | } |
156 | |||
157 | // remove all cards that are not present -> flagged with 'remove' | ||
158 | // and unchecked | ||
159 | void LanCardEdit::SLOT_RemoveUnknown( void ) { | ||
160 | QArray<QCheckListItem *> AllItems; | ||
161 | |||
162 | LanCardNetNode *NN = (LanCardNetNode *)NNI->nodeClass(); | ||
163 | |||
164 | QCheckListItem * CLI = (QCheckListItem *)LanCards_LV->firstChild(); | ||
91 | while( CLI ) { | 165 | while( CLI ) { |
92 | CLI->setOn( Data.HWAddresses.findIndex(CLI->text(1)) >= 0 ); | 166 | AllItems.resize( AllItems.size()+1 ); |
167 | AllItems[ AllItems.size()-1 ] = CLI; | ||
93 | CLI = (QCheckListItem *)CLI->nextSibling(); | 168 | CLI = (QCheckListItem *)CLI->nextSibling(); |
94 | } | 169 | } |
170 | |||
171 | // force update of system | ||
172 | System & S = NSResources->system(); | ||
173 | S.probeInterfaces(); | ||
174 | |||
175 | // add any NIC that is new and matches our interfacename | ||
176 | QRegExp R( "eth[0-9]" ); | ||
177 | |||
178 | |||
179 | for( QDictIterator<InterfaceInfo> It(S.interfaces()); | ||
180 | It.current(); | ||
181 | ++It ) { | ||
182 | if( R.match( It.current()->Name ) >= 0 && | ||
183 | ( It.current()->CardType == ARPHRD_ETHER | ||
184 | #ifdef ARPHRD_IEEE1394 | ||
185 | || It.current()->CardType == ARPHRD_IEEE1394 | ||
186 | #endif | ||
187 | ) | ||
188 | ) { | ||
189 | |||
190 | for ( unsigned i = 0; i< AllItems.size(); i++ ) { | ||
191 | if( AllItems[i] && | ||
192 | AllItems[i]->text(0) == It.current()->MACAddress ) { | ||
193 | AllItems[i] = 0; | ||
194 | break; | ||
195 | } | ||
196 | } | ||
197 | } | ||
198 | } | ||
199 | |||
200 | // AllItems now contains all cards NOT present | ||
201 | // remove all items non null and not ON | ||
202 | for ( unsigned i = 0; i< AllItems.size(); i++ ) { | ||
203 | if( AllItems[i] && ! AllItems[i]->isOn() ) { | ||
204 | NN->addressesOfNIC().remove( AllItems[i]->text(0) ); | ||
205 | delete AllItems[i]; | ||
206 | } | ||
207 | } | ||
95 | } | 208 | } |
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,16 +1,24 @@ | |||
1 | #include "lancarddata.h" | 1 | #include "lancarddata.h" |
2 | #include "lancardGUI.h" | 2 | #include "lancardGUI.h" |
3 | 3 | ||
4 | class ALanCard; | ||
5 | |||
4 | class LanCardEdit : public LanCardGUI { | 6 | class LanCardEdit : public LanCardGUI { |
5 | 7 | ||
6 | public : | 8 | public : |
7 | 9 | ||
8 | LanCardEdit( QWidget * parent ); | 10 | LanCardEdit( QWidget * parent ); |
9 | QString acceptable( void ); | 11 | QString acceptable( void ); |
10 | bool commit( LanCardData & Data ); | 12 | bool commit( LanCardData & Data ); |
11 | void showData( LanCardData & Data ); | 13 | void showData( ALanCard * NNI ); |
14 | |||
15 | public slots : | ||
16 | |||
17 | void SLOT_ScanCards( void ); | ||
18 | void SLOT_RemoveUnknown( void ); | ||
12 | 19 | ||
13 | private : | 20 | private : |
14 | 21 | ||
15 | bool ContainedObsoleteMAC; | 22 | void populateList( void ); |
23 | ALanCard * NNI; | ||
16 | }; | 24 | }; |
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,14 +1,15 @@ | |||
1 | #include <qfile.h> | 1 | #include <qfile.h> |
2 | #include <qtextstream.h> | 2 | #include <qtextstream.h> |
3 | #include <qstringlist.h> | ||
3 | #include <resources.h> | 4 | #include <resources.h> |
4 | #include "lancardrun.h" | 5 | #include "lancardrun.h" |
5 | 6 | ||
6 | void LanCardRun::detectState( NodeCollection * NC ) { | 7 | void LanCardRun::detectState( NodeCollection * NC ) { |
7 | 8 | ||
8 | // unavailable : no card found | 9 | // unavailable : no card found |
9 | // available : card found and assigned to us or free | 10 | // available : card found and assigned to us or free |
10 | // up : card found and assigned to us and up | 11 | // up : card found and assigned to us and up |
11 | 12 | ||
12 | QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); | 13 | QString S = QString( "/tmp/profile-%1.up" ).arg(NC->number()); |
13 | System & Sys = NSResources->system(); | 14 | System & Sys = NSResources->system(); |
14 | InterfaceInfo * Run; | 15 | InterfaceInfo * Run; |
@@ -44,26 +45,30 @@ void LanCardRun::detectState( NodeCollection * NC ) { | |||
44 | return; | 45 | return; |
45 | } // else interface is up but NOT us -> some other profile | 46 | } // else interface is up but NOT us -> some other profile |
46 | } | 47 | } |
47 | 48 | ||
48 | // nothing (valid) assigned to us | 49 | // nothing (valid) assigned to us |
49 | assignInterface( 0 ); | 50 | assignInterface( 0 ); |
50 | 51 | ||
51 | // find possible interface | 52 | // find possible interface |
52 | for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); | 53 | for( QDictIterator<InterfaceInfo> It(Sys.interfaces()); |
53 | It.current(); | 54 | It.current(); |
54 | ++It ) { | 55 | ++It ) { |
55 | Run = It.current(); | 56 | Run = It.current(); |
56 | if( handlesInterface( Run->Name ) && | 57 | if( handlesInterface( *Run ) && |
57 | Run->CardType == ARPHRD_ETHER && | 58 | ( Run->CardType == ARPHRD_ETHER |
59 | #ifdef ARPHRD_IEEE1394 | ||
60 | || Run->CardType == ARPHRD_IEEE1394 | ||
61 | #endif | ||
62 | ) && | ||
58 | ! Run->IsUp | 63 | ! Run->IsUp |
59 | ) { | 64 | ) { |
60 | // proper type, and Not UP -> free | 65 | // proper type, and Not UP -> free |
61 | NC->setCurrentState( Off ); | 66 | NC->setCurrentState( Off ); |
62 | return; | 67 | return; |
63 | } | 68 | } |
64 | } | 69 | } |
65 | // no free found | 70 | // no free found |
66 | 71 | ||
67 | NC->setCurrentState( Unavailable ); | 72 | NC->setCurrentState( Unavailable ); |
68 | 73 | ||
69 | } | 74 | } |
@@ -136,31 +141,52 @@ bool LanCardRun::canSetState( State_t Curr, Action_t A ) { | |||
136 | } | 141 | } |
137 | 142 | ||
138 | // get interface that is free or assigned to us | 143 | // get interface that is free or assigned to us |
139 | InterfaceInfo * LanCardRun::getInterface( void ) { | 144 | InterfaceInfo * LanCardRun::getInterface( void ) { |
140 | 145 | ||
141 | System & S = NSResources->system(); | 146 | System & S = NSResources->system(); |
142 | InterfaceInfo * best = 0, * Run; | 147 | InterfaceInfo * best = 0, * Run; |
143 | 148 | ||
144 | for( QDictIterator<InterfaceInfo> It(S.interfaces()); | 149 | for( QDictIterator<InterfaceInfo> It(S.interfaces()); |
145 | It.current(); | 150 | It.current(); |
146 | ++It ) { | 151 | ++It ) { |
147 | Run = It.current(); | 152 | Run = It.current(); |
148 | if( handlesInterface( Run->Name ) && | 153 | if( handlesInterface( *Run ) && |
149 | Run->CardType == ARPHRD_ETHER | 154 | ( Run->CardType == ARPHRD_ETHER |
155 | #ifdef ARPHRD_IEEE1394 | ||
156 | || Run->CardType == ARPHRD_IEEE1394 | ||
157 | #endif | ||
158 | ) | ||
150 | ) { | 159 | ) { |
151 | // this is a LAN card | 160 | // this is a LAN card |
152 | if( Run->assignedNode() == netNode() ) { | 161 | if( Run->assignedNode() == netNode() ) { |
153 | // assigned to us | 162 | // assigned to us |
154 | return Run; | 163 | return Run; |
155 | } else if( Run->assignedNode() == 0 ) { | 164 | } else if( Run->assignedNode() == 0 ) { |
156 | // free | 165 | // free |
157 | best = Run; | 166 | best = Run; |
158 | } | 167 | } |
159 | } | 168 | } |
160 | } | 169 | } |
161 | return best; // can be 0 | 170 | return best; // can be 0 |
162 | } | 171 | } |
163 | 172 | ||
164 | bool LanCardRun::handlesInterface( const QString & S ) { | 173 | bool LanCardRun::handlesInterface( const QString & S ) { |
174 | InterfaceInfo * II; | ||
175 | II = NSResources->system().interface( S ); | ||
176 | if( ( II = NSResources->system().interface( S ) ) ) { | ||
177 | return handlesInterface( *II ); | ||
178 | } | ||
165 | return Pat.match( S ) >= 0; | 179 | return Pat.match( S ) >= 0; |
166 | } | 180 | } |
181 | |||
182 | bool LanCardRun::handlesInterface( const InterfaceInfo & II ) { | ||
183 | if( Pat.match( II.Name ) < 0 ) | ||
184 | return 0; | ||
185 | |||
186 | if( Data->AnyLanCard ) { | ||
187 | return 1; | ||
188 | } | ||
189 | |||
190 | // must also match hardware address | ||
191 | return ( Data->HWAddresses.findIndex( II.MACAddress ) >= 0 ); | ||
192 | } | ||
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 | |||
@@ -1,37 +1,39 @@ | |||
1 | #ifndef LANCARDRUN_H | 1 | #ifndef LANCARDRUN_H |
2 | #define LANCARDRUN_H | 2 | #define LANCARDRUN_H |
3 | 3 | ||
4 | #include <asdevice.h> | 4 | #include <asdevice.h> |
5 | #include <qregexp.h> | 5 | #include <qregexp.h> |
6 | #include "lancarddata.h" | 6 | #include "lancarddata.h" |
7 | 7 | ||
8 | class LanCardRun : public AsDevice { | 8 | class LanCardRun : public AsDevice { |
9 | 9 | ||
10 | public : | 10 | public : |
11 | 11 | ||
12 | LanCardRun( ANetNodeInstance * NNI, | 12 | LanCardRun( ANetNodeInstance * NNI, |
13 | LanCardData & Data ) : AsDevice( NNI ), | 13 | LanCardData & D ) : AsDevice( NNI ), |
14 | Pat( "eth[0-9]" ) | 14 | Pat( "eth[0-9]" ) |
15 | { } | 15 | { Data = &D; } |
16 | 16 | ||
17 | virtual AsDevice * device( void ) | 17 | virtual AsDevice * device( void ) |
18 | { return (AsDevice *)this; } | 18 | { return (AsDevice *)this; } |
19 | 19 | ||
20 | virtual AsDevice * asDevice( void ) | 20 | virtual AsDevice * asDevice( void ) |
21 | { return (AsDevice *)this; } | 21 | { return (AsDevice *)this; } |
22 | 22 | ||
23 | protected : | 23 | protected : |
24 | 24 | ||
25 | void detectState( NodeCollection * NC ); | 25 | void detectState( NodeCollection * NC ); |
26 | bool setState( NodeCollection * NC, Action_t A ); | 26 | bool setState( NodeCollection * NC, Action_t A ); |
27 | bool canSetState( State_t Curr, Action_t A ); | 27 | bool canSetState( State_t Curr, Action_t A ); |
28 | 28 | ||
29 | bool handlesInterface( const QString & I ); | 29 | bool handlesInterface( const QString & I ); |
30 | bool handlesInterface( const InterfaceInfo & II ); | ||
30 | 31 | ||
31 | private : | 32 | private : |
32 | 33 | ||
33 | InterfaceInfo * getInterface( void ); | 34 | InterfaceInfo * getInterface( void ); |
34 | QRegExp Pat; | 35 | QRegExp Pat; |
36 | LanCardData * Data; | ||
35 | 37 | ||
36 | }; | 38 | }; |
37 | #endif | 39 | #endif |