Diffstat (limited to 'noncore/settings/networksettings2/lancard/lancardedit.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/lancard/lancardedit.cpp | 195 |
1 files changed, 154 insertions, 41 deletions
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 | } |