author | wimpie <wimpie> | 2005-01-12 00:29:48 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2005-01-12 00:29:48 (UTC) |
commit | a846a0be197d3a6ff7f8c76a3ba322db0da7d058 (patch) (unidiff) | |
tree | 0db1eccb73b0756ff49029dcfa71ff1a3699cab0 | |
parent | 4b1d4fc9f4170ec22d196dd352cae5d9c1ecb232 (diff) | |
download | opie-a846a0be197d3a6ff7f8c76a3ba322db0da7d058.zip opie-a846a0be197d3a6ff7f8c76a3ba322db0da7d058.tar.gz opie-a846a0be197d3a6ff7f8c76a3ba322db0da7d058.tar.bz2 |
Fixed Crash in editing new profiles
-rw-r--r-- | noncore/settings/networksettings2/editconnection.cpp | 17 | ||||
-rw-r--r-- | noncore/settings/networksettings2/nsdata.cpp | 2 |
2 files changed, 14 insertions, 5 deletions
diff --git a/noncore/settings/networksettings2/editconnection.cpp b/noncore/settings/networksettings2/editconnection.cpp index 6ab2dd6..bda9d7e 100644 --- a/noncore/settings/networksettings2/editconnection.cpp +++ b/noncore/settings/networksettings2/editconnection.cpp | |||
@@ -1,631 +1,640 @@ | |||
1 | #include <opie2/odebug.h> | 1 | #include <opie2/odebug.h> |
2 | #include <qlistview.h> | 2 | #include <qlistview.h> |
3 | #include <qwidgetstack.h> | 3 | #include <qwidgetstack.h> |
4 | #include <qframe.h> | 4 | #include <qframe.h> |
5 | #include <qcombobox.h> | 5 | #include <qcombobox.h> |
6 | #include <qtabwidget.h> | 6 | #include <qtabwidget.h> |
7 | #include <qmessagebox.h> | 7 | #include <qmessagebox.h> |
8 | #include <qpushbutton.h> | 8 | #include <qpushbutton.h> |
9 | #include <qlineedit.h> | 9 | #include <qlineedit.h> |
10 | #include <qheader.h> | 10 | #include <qheader.h> |
11 | #include <qpainter.h> | 11 | #include <qpainter.h> |
12 | #include <qcheckbox.h> | 12 | #include <qcheckbox.h> |
13 | #include <qlabel.h> | 13 | #include <qlabel.h> |
14 | 14 | ||
15 | #include "editconnection.h" | 15 | #include "editconnection.h" |
16 | #include "resources.h" | 16 | #include "resources.h" |
17 | #include "netnode.h" | 17 | #include "netnode.h" |
18 | 18 | ||
19 | // | 19 | // |
20 | // | 20 | // |
21 | // THESE TO GIVE BETTER FEEDBACK ABOUT DISABLED ITEMS | 21 | // THESE TO GIVE BETTER FEEDBACK ABOUT DISABLED ITEMS |
22 | // | 22 | // |
23 | // | 23 | // |
24 | 24 | ||
25 | class MyQCheckListItem : public QCheckListItem | 25 | class MyQCheckListItem : public QCheckListItem |
26 | { | 26 | { |
27 | public: | 27 | public: |
28 | MyQCheckListItem( QListView *parent, const QString & S, Type T ) : | 28 | MyQCheckListItem( QListView *parent, const QString & S, Type T ) : |
29 | QCheckListItem( parent, S, T ) { } | 29 | QCheckListItem( parent, S, T ) { } |
30 | MyQCheckListItem( QCheckListItem *parent, const QString & S, Type T ) : | 30 | MyQCheckListItem( QCheckListItem *parent, const QString & S, Type T ) : |
31 | QCheckListItem( parent, S, T ) { } | 31 | QCheckListItem( parent, S, T ) { } |
32 | MyQCheckListItem( QListViewItem *parent, const QString & S, Type T ) : | 32 | MyQCheckListItem( QListViewItem *parent, const QString & S, Type T ) : |
33 | QCheckListItem( parent, S, T ) { } | 33 | QCheckListItem( parent, S, T ) { } |
34 | 34 | ||
35 | MyQCheckListItem( QListView *parent, const QString & S ) : | 35 | MyQCheckListItem( QListView *parent, const QString & S ) : |
36 | QCheckListItem( parent, S, QCheckListItem::Controller ) { } | 36 | QCheckListItem( parent, S, QCheckListItem::Controller ) { } |
37 | MyQCheckListItem( QCheckListItem *parent, const QString & S ) : | 37 | MyQCheckListItem( QCheckListItem *parent, const QString & S ) : |
38 | QCheckListItem( parent, S, QCheckListItem::Controller ) { } | 38 | QCheckListItem( parent, S, QCheckListItem::Controller ) { } |
39 | MyQCheckListItem( QListViewItem *parent, const QString & S ) : | 39 | MyQCheckListItem( QListViewItem *parent, const QString & S ) : |
40 | QCheckListItem( parent, S, QCheckListItem::Controller ) { } | 40 | QCheckListItem( parent, S, QCheckListItem::Controller ) { } |
41 | 41 | ||
42 | virtual void paintCell( QPainter *p, const QColorGroup &cg, | 42 | virtual void paintCell( QPainter *p, const QColorGroup &cg, |
43 | int column, int width, int alignment ); | 43 | int column, int width, int alignment ); |
44 | 44 | ||
45 | }; | 45 | }; |
46 | 46 | ||
47 | void MyQCheckListItem::paintCell( QPainter *p, const QColorGroup &cg, | 47 | void MyQCheckListItem::paintCell( QPainter *p, const QColorGroup &cg, |
48 | int column, int width, int alignment ) | 48 | int column, int width, int alignment ) |
49 | { | 49 | { |
50 | QColorGroup _cg( cg ); | 50 | QColorGroup _cg( cg ); |
51 | QColor c = _cg.text(); | 51 | QColor c = _cg.text(); |
52 | if ( ! isSelectable() ) | 52 | if ( ! isSelectable() ) |
53 | _cg.setColor( QColorGroup::Text, Qt::lightGray ); | 53 | _cg.setColor( QColorGroup::Text, Qt::lightGray ); |
54 | QCheckListItem::paintCell( p, _cg, column, width, alignment ); | 54 | QCheckListItem::paintCell( p, _cg, column, width, alignment ); |
55 | _cg.setColor( QColorGroup::Text, c ); | 55 | _cg.setColor( QColorGroup::Text, c ); |
56 | } | 56 | } |
57 | 57 | ||
58 | class MyQListViewItem : public QListViewItem | 58 | class MyQListViewItem : public QListViewItem |
59 | { | 59 | { |
60 | public: | 60 | public: |
61 | MyQListViewItem( QListView *parent, const QString & S ) : | 61 | MyQListViewItem( QListView *parent, const QString & S ) : |
62 | QListViewItem( parent, S ) { } | 62 | QListViewItem( parent, S ) { } |
63 | MyQListViewItem( QListViewItem *parent, const QString & S ) : | 63 | MyQListViewItem( QListViewItem *parent, const QString & S ) : |
64 | QListViewItem( parent, S ) { } | 64 | QListViewItem( parent, S ) { } |
65 | 65 | ||
66 | virtual void paintCell( QPainter *p, const QColorGroup &cg, | 66 | virtual void paintCell( QPainter *p, const QColorGroup &cg, |
67 | int column, int width, int alignment ); | 67 | int column, int width, int alignment ); |
68 | 68 | ||
69 | }; | 69 | }; |
70 | 70 | ||
71 | void MyQListViewItem::paintCell( QPainter *p, const QColorGroup &cg, | 71 | void MyQListViewItem::paintCell( QPainter *p, const QColorGroup &cg, |
72 | int column, int width, int alignment ) | 72 | int column, int width, int alignment ) |
73 | { | 73 | { |
74 | QColorGroup _cg( cg ); | 74 | QColorGroup _cg( cg ); |
75 | QColor c = _cg.text(); | 75 | QColor c = _cg.text(); |
76 | if ( ! isSelectable() ) | 76 | if ( ! isSelectable() ) |
77 | _cg.setColor( QColorGroup::Text, Qt::lightGray ); | 77 | _cg.setColor( QColorGroup::Text, Qt::lightGray ); |
78 | QListViewItem::paintCell( p, _cg, column, width, alignment ); | 78 | QListViewItem::paintCell( p, _cg, column, width, alignment ); |
79 | _cg.setColor( QColorGroup::Text, c ); | 79 | _cg.setColor( QColorGroup::Text, c ); |
80 | } | 80 | } |
81 | 81 | ||
82 | // | 82 | // |
83 | // | 83 | // |
84 | // REAL GUI | 84 | // REAL GUI |
85 | // | 85 | // |
86 | // | 86 | // |
87 | 87 | ||
88 | bool EditNetworkSetup::AutoCollapse = 1; | 88 | bool EditNetworkSetup::AutoCollapse = 1; |
89 | 89 | ||
90 | EditNetworkSetup::EditNetworkSetup( QWidget* parent ) : | 90 | EditNetworkSetup::EditNetworkSetup( QWidget* parent ) : |
91 | EditNetworkSetupGUI( parent, 0, TRUE ), TmpCollection() { | 91 | EditNetworkSetupGUI( parent, 0, TRUE ), TmpCollection() { |
92 | 92 | ||
93 | Tab_TB->setTabEnabled( Setup_FRM, FALSE ); | 93 | Tab_TB->setTabEnabled( Setup_FRM, FALSE ); |
94 | Setup_FRM->setEnabled( FALSE ); | 94 | Setup_FRM->setEnabled( FALSE ); |
95 | 95 | ||
96 | TmpIsValid = 0; | 96 | TmpIsValid = 0; |
97 | SelectedNodes = 0; | 97 | SelectedNodes = 0; |
98 | 98 | ||
99 | AutoCollapse_CB->setChecked( AutoCollapse ); | 99 | AutoCollapse_CB->setChecked( AutoCollapse ); |
100 | 100 | ||
101 | Mapping = new QPtrDict<ANetNode>; | 101 | Mapping = new QPtrDict<ANetNode>; |
102 | Mapping->setAutoDelete( FALSE ); | 102 | Mapping->setAutoDelete( FALSE ); |
103 | Nodes_LV->header()->hide(); | 103 | Nodes_LV->header()->hide(); |
104 | // popluate tree with all NetNodes | 104 | // popluate tree with all NetNodes |
105 | buildFullTree(); | 105 | buildFullTree(); |
106 | } | 106 | } |
107 | 107 | ||
108 | NetworkSetup * EditNetworkSetup::getTmpCollection( void ) { | 108 | NetworkSetup * EditNetworkSetup::getTmpCollection( void ) { |
109 | 109 | ||
110 | if( TmpIsValid ) | 110 | if( TmpIsValid ) |
111 | // content is stil OK | 111 | // content is stil OK |
112 | return &(TmpCollection); | 112 | return &(TmpCollection); |
113 | 113 | ||
114 | // reset collection -> delete all NEW NetNodes | 114 | // reset collection -> delete all NEW NetNodes |
115 | for( QListIterator<ANetNodeInstance> it(TmpCollection); | 115 | for( QListIterator<ANetNodeInstance> it(TmpCollection); |
116 | it.current(); | 116 | it.current(); |
117 | ++it ) { | 117 | ++it ) { |
118 | if( it.current()->isNew() ) { | 118 | if( it.current()->isNew() ) { |
119 | delete it.current(); | 119 | delete it.current(); |
120 | } | 120 | } |
121 | } | 121 | } |
122 | 122 | ||
123 | TmpCollection.clear(); | 123 | TmpCollection.clear(); |
124 | TmpCollection.copyFrom( *SelectedNodes ); | 124 | if( SelectedNodes ) { |
125 | // initialize like original | ||
126 | TmpCollection.copyFrom( *SelectedNodes ); | ||
127 | } | ||
125 | 128 | ||
126 | // update content | 129 | // update content |
127 | QListViewItem * it = Nodes_LV->firstChild(); | 130 | QListViewItem * it = Nodes_LV->firstChild(); |
128 | ANetNode * NN; | 131 | ANetNode * NN; |
129 | 132 | ||
130 | // start iter (if there is a collection) | 133 | // start iter (if there is a collection) |
131 | /* | 134 | /* |
132 | 135 | ||
133 | a node collection is sorted from the toplevel | 136 | a node collection is sorted from the toplevel |
134 | node to the deepest node | 137 | node to the deepest node |
135 | 138 | ||
136 | */ | 139 | */ |
137 | ANetNodeInstance * NNI = | 140 | ANetNodeInstance * NNI = |
138 | (SelectedNodes) ? SelectedNodes->first() : 0 ; | 141 | (SelectedNodes) ? SelectedNodes->first() : 0 ; |
139 | 142 | ||
140 | TmpCollection.setModified( 0 ); | 143 | TmpCollection.setModified( 0 ); |
141 | 144 | ||
142 | // the listview always starts with the toplevel | 145 | // the listview always starts with the toplevel |
143 | // hierarchy. This is always a controller item | 146 | // hierarchy. This is always a controller item |
144 | while ( it ) { | 147 | while ( it ) { |
145 | NN = (*Mapping)[it]; | 148 | NN = (*Mapping)[it]; |
146 | if( NN == 0 ) { | 149 | if( NN == 0 ) { |
147 | // this item is a controller -> | 150 | // this item is a controller -> |
148 | // has radio items as children -> | 151 | // has radio items as children -> |
149 | // find selected one | 152 | // find selected one |
150 | it = it->firstChild(); | 153 | it = it->firstChild(); |
151 | while( it ) { | 154 | while( it ) { |
152 | if( ((QCheckListItem *)it)->isOn() ) { | 155 | if( ((QCheckListItem *)it)->isOn() ) { |
153 | // this radio is selected -> go deeper | 156 | // this radio is selected -> go deeper |
154 | break; | 157 | break; |
155 | } | 158 | } |
156 | it = it->nextSibling(); | 159 | it = it->nextSibling(); |
157 | } | 160 | } |
158 | 161 | ||
159 | if( ! it ) { | 162 | if( ! it ) { |
160 | TmpIsValid = 0; | 163 | TmpIsValid = 0; |
161 | return 0; | 164 | return 0; |
162 | } | 165 | } |
163 | 166 | ||
164 | // it now contains selected radio | 167 | // it now contains selected radio |
165 | NN = (*Mapping)[it]; | 168 | NN = (*Mapping)[it]; |
166 | } | 169 | } |
167 | 170 | ||
168 | // NN here contains the netnode of the | 171 | // NN here contains the netnode of the |
169 | // current item -> this node needs to | 172 | // current item -> this node needs to |
170 | // be stored in the collection | 173 | // be stored in the collection |
171 | if( NNI == 0 || | 174 | if( NNI == 0 || |
172 | it->text(0) != NNI->nodeClass()->name() ) { | 175 | it->text(0) != NNI->nodeClass()->name() ) { |
173 | // new item not in previous collection | 176 | // new item not in previous collection |
174 | ANetNodeInstance * NNI = NN->createInstance(); | 177 | ANetNodeInstance * NNI = NN->createInstance(); |
175 | NNI->initialize(); | 178 | NNI->initialize(); |
176 | // this node type not in collection | 179 | // this node type not in collection |
177 | TmpCollection.append( NNI ); | 180 | TmpCollection.append( NNI ); |
178 | // master collection changed because new item in it | 181 | // master collection changed because new item in it |
179 | TmpCollection.setModified( 1 ); | 182 | TmpCollection.setModified( 1 ); |
180 | // no more valid items in old list | 183 | // no more valid items in old list |
181 | NNI = 0; | 184 | NNI = 0; |
182 | } else { | 185 | } else { |
183 | // already in list -> copy pointer | 186 | // already in list -> copy pointer |
184 | TmpCollection.append( NNI ); | 187 | TmpCollection.append( NNI ); |
185 | NNI = SelectedNodes->next(); | 188 | NNI = SelectedNodes->next(); |
186 | } | 189 | } |
187 | 190 | ||
188 | // go deeper to next level | 191 | // go deeper to next level |
189 | // this level is can be a new controller | 192 | // this level is can be a new controller |
190 | // or an item | 193 | // or an item |
191 | it = it->firstChild(); | 194 | it = it->firstChild(); |
192 | } | 195 | } |
193 | 196 | ||
194 | TmpIsValid = 1; | 197 | TmpIsValid = 1; |
195 | return &(TmpCollection); | 198 | return &(TmpCollection); |
196 | } | 199 | } |
197 | 200 | ||
198 | // pass a NetworkSetup NetworkSetup to be edited | 201 | // pass a NetworkSetup NetworkSetup to be edited |
199 | void EditNetworkSetup::setNetworkSetup( NetworkSetup * NC ) { | 202 | void EditNetworkSetup::setNetworkSetup( NetworkSetup * NC ) { |
200 | ANetNodeInstance * NNI; | 203 | ANetNodeInstance * NNI; |
201 | ANetNode * NN; | 204 | ANetNode * NN; |
202 | 205 | ||
203 | SelectedNodes = NC; | 206 | SelectedNodes = NC; |
204 | Name_LE->setText( NC->name() ); | 207 | Name_LE->setText( NC->name() ); |
205 | NNI = NC->first(); | 208 | NNI = NC->first(); |
206 | 209 | ||
207 | // show configure tabl | 210 | // show configure tabl |
208 | Tab_TB->setCurrentPage( 1 ); | 211 | Tab_TB->setCurrentPage( 1 ); |
209 | 212 | ||
210 | // valid colledction | 213 | // valid colledction |
211 | Tab_TB->setTabEnabled( Setup_FRM, FALSE ); | 214 | Tab_TB->setTabEnabled( Setup_FRM, FALSE ); |
212 | Setup_FRM->setEnabled( FALSE ); | 215 | Setup_FRM->setEnabled( FALSE ); |
213 | 216 | ||
214 | // select items in collection | 217 | // select items in collection |
215 | QListViewItem * it = Nodes_LV->firstChild(); | 218 | QListViewItem * it = Nodes_LV->firstChild(); |
216 | bool Found; | 219 | bool Found; |
217 | 220 | ||
218 | TmpIsValid = 0; | 221 | TmpIsValid = 0; |
219 | 222 | ||
220 | while ( it ) { | 223 | while ( it ) { |
221 | NN = (*Mapping)[it]; | 224 | NN = (*Mapping)[it]; |
222 | if( NN == 0 ) { | 225 | if( NN == 0 ) { |
223 | // this item is a controller -> | 226 | // this item is a controller -> |
224 | // has radio items as children -> | 227 | // has radio items as children -> |
225 | // find selected one | 228 | // find selected one |
226 | it = it->firstChild(); | 229 | it = it->firstChild(); |
227 | Found = 0; | 230 | Found = 0; |
228 | while( it ) { | 231 | while( it ) { |
229 | if( NNI && it->text(0) == NNI->nodeClass()->name() ) { | 232 | if( NNI && it->text(0) == NNI->nodeClass()->name() ) { |
230 | // this radio is part of the collection | 233 | // this radio is part of the collection |
231 | ((QCheckListItem *)it)->setOn( 1 ); | 234 | ((QCheckListItem *)it)->setOn( 1 ); |
232 | updateGUI( it, NNI->nodeClass() ); | 235 | updateGUI( it, NNI->nodeClass() ); |
233 | // check its children | 236 | // check its children |
234 | Found = 1; | 237 | Found = 1; |
235 | it = it->firstChild(); | 238 | it = it->firstChild(); |
236 | NNI = SelectedNodes->next(); | 239 | NNI = SelectedNodes->next(); |
237 | // do not bother to check other items | 240 | // do not bother to check other items |
238 | break; | 241 | break; |
239 | } | 242 | } |
240 | it = it->nextSibling(); | 243 | it = it->nextSibling(); |
241 | } | 244 | } |
242 | 245 | ||
243 | if( ! Found ) { | 246 | if( ! Found ) { |
244 | // this means that this level is NOT present in collection | 247 | // this means that this level is NOT present in collection |
245 | // probably INCOMPATIBEL collection OR Missing plugin | 248 | // probably INCOMPATIBEL collection OR Missing plugin |
246 | QMessageBox::warning( | 249 | QMessageBox::warning( |
247 | 0, | 250 | 0, |
248 | tr( "Error presentig NetworkSetup" ), | 251 | tr( "Error presentig NetworkSetup" ), |
249 | tr( "<p>Old NetworkSetup or missing plugin \"<i>%1</i>\"</p>" ). | 252 | tr( "<p>Old NetworkSetup or missing plugin \"<i>%1</i>\"</p>" ). |
250 | arg(NNI->nodeClass()->name()) ); | 253 | arg(NNI->nodeClass()->name()) ); |
251 | return; | 254 | return; |
252 | } | 255 | } |
253 | 256 | ||
254 | // it now contains selected radio | 257 | // it now contains selected radio |
255 | NN = (*Mapping)[it]; | 258 | NN = (*Mapping)[it]; |
256 | } else { | 259 | } else { |
257 | // automatic selection | 260 | // automatic selection |
258 | if( NNI == 0 || it->text(0) != NNI->nodeClass()->name() ) { | 261 | if( NNI == 0 || it->text(0) != NNI->nodeClass()->name() ) { |
259 | // should exist and be the same | 262 | // should exist and be the same |
260 | if( NNI ) { | 263 | if( NNI ) { |
261 | QMessageBox::warning( | 264 | QMessageBox::warning( |
262 | 0, | 265 | 0, |
263 | tr( "Error presentig NetworkSetup" ), | 266 | tr( "Error presentig NetworkSetup" ), |
264 | tr( "<p>Old NetworkSetup or missing plugin \"<i>%1</i>\"</p>" ). | 267 | tr( "<p>Old NetworkSetup or missing plugin \"<i>%1</i>\"</p>" ). |
265 | arg(NNI->nodeClass()->name()) ); | 268 | arg(NNI->nodeClass()->name()) ); |
266 | } else { | 269 | } else { |
267 | QMessageBox::warning( | 270 | QMessageBox::warning( |
268 | 0, | 271 | 0, |
269 | tr( "Error presentig NetworkSetup" ), | 272 | tr( "Error presentig NetworkSetup" ), |
270 | tr( "<p>Missing NetworkSetup\"<i>%1</i>\"</p>" ). | 273 | tr( "<p>Missing NetworkSetup\"<i>%1</i>\"</p>" ). |
271 | arg(it->text(0)) ); | 274 | arg(it->text(0)) ); |
272 | } | 275 | } |
273 | return; | 276 | return; |
274 | } | 277 | } |
275 | it = it->firstChild(); | 278 | it = it->firstChild(); |
276 | } | 279 | } |
277 | } | 280 | } |
278 | } | 281 | } |
279 | 282 | ||
280 | // get result of editing (either new OR updated collection | 283 | // get result of editing (either new OR updated collection |
281 | NetworkSetup * EditNetworkSetup::networkSetup( void ) { | 284 | NetworkSetup * EditNetworkSetup::networkSetup( void ) { |
282 | 285 | ||
283 | if( SelectedNodes == 0 ) { | 286 | if( SelectedNodes == 0 ) { |
284 | // new collection | 287 | // new collection |
285 | SelectedNodes = new NetworkSetup; | 288 | SelectedNodes = new NetworkSetup; |
286 | } | 289 | } |
287 | 290 | ||
288 | // clean out old entries | 291 | // clean out old entries |
289 | SelectedNodes->clear(); | 292 | SelectedNodes->clear(); |
290 | 293 | ||
291 | // transfer | 294 | // transfer |
292 | for( QListIterator<ANetNodeInstance> it(TmpCollection); | 295 | for( QListIterator<ANetNodeInstance> it(TmpCollection); |
293 | it.current(); | 296 | it.current(); |
294 | ++it ) { | 297 | ++it ) { |
295 | SelectedNodes->append( it.current() ); | 298 | SelectedNodes->append( it.current() ); |
296 | } | 299 | } |
297 | 300 | ||
298 | if( TmpCollection.isModified() ) | 301 | if( TmpCollection.isModified() ) |
299 | SelectedNodes->setModified( 1 ); | 302 | SelectedNodes->setModified( 1 ); |
300 | 303 | ||
301 | if( SelectedNodes->name() != Name_LE->text() ) { | 304 | if( SelectedNodes->name() != Name_LE->text() ) { |
302 | SelectedNodes->setName( Name_LE->text() ); | 305 | SelectedNodes->setName( Name_LE->text() ); |
303 | SelectedNodes->setModified( 1 ); | 306 | SelectedNodes->setModified( 1 ); |
304 | } | 307 | } |
305 | 308 | ||
306 | return SelectedNodes; | 309 | return SelectedNodes; |
307 | } | 310 | } |
308 | 311 | ||
309 | // Build device tree -> start | 312 | // Build device tree -> start |
310 | void EditNetworkSetup::buildFullTree( void ) { | 313 | void EditNetworkSetup::buildFullTree( void ) { |
311 | ANetNode * NN; | 314 | ANetNode * NN; |
312 | 315 | ||
313 | // toplevel item | 316 | // toplevel item |
314 | MyQCheckListItem * TheTop = new MyQCheckListItem( | 317 | MyQCheckListItem * TheTop = new MyQCheckListItem( |
315 | Nodes_LV, | 318 | Nodes_LV, |
316 | NSResources->netNode2Name("fullsetup"), | 319 | NSResources->netNode2Name("fullsetup"), |
317 | QCheckListItem::Controller ); | 320 | QCheckListItem::Controller ); |
318 | TheTop->setOpen( TRUE ); | 321 | TheTop->setOpen( TRUE ); |
319 | Description_LBL->setText( | 322 | Description_LBL->setText( |
320 | NSResources->netNode2Description( "fullsetup" ) ); | 323 | NSResources->netNode2Description( "fullsetup" ) ); |
321 | Nodes_LV->setSelected( TheTop, TRUE ); | 324 | Nodes_LV->setSelected( TheTop, TRUE ); |
322 | 325 | ||
323 | // find all Nodes that are toplevel nodes -> ie provide | 326 | // find all Nodes that are toplevel nodes -> ie provide |
324 | // TCP/IP NetworkSetup | 327 | // TCP/IP NetworkSetup |
325 | for( QDictIterator<ANetNode> Iter(NSResources->netNodes()); | 328 | for( QDictIterator<ANetNode> Iter(NSResources->netNodes()); |
326 | Iter.current(); | 329 | Iter.current(); |
327 | ++Iter ) { | 330 | ++Iter ) { |
328 | NN = Iter.current(); | 331 | NN = Iter.current(); |
329 | 332 | ||
330 | if( ! NN->isToplevel() ) { | 333 | if( ! NN->isToplevel() ) { |
331 | continue; | 334 | continue; |
332 | } | 335 | } |
333 | 336 | ||
334 | MyQCheckListItem * it = new MyQCheckListItem( TheTop, | 337 | MyQCheckListItem * it = new MyQCheckListItem( TheTop, |
335 | NN->name(), | 338 | NN->name(), |
336 | QCheckListItem::RadioButton ); | 339 | QCheckListItem::RadioButton ); |
337 | it->setPixmap( 0, | 340 | it->setPixmap( 0, |
338 | NSResources->getPixmap( NN->pixmapName() ) | 341 | NSResources->getPixmap( NN->pixmapName() ) |
339 | ); | 342 | ); |
340 | // remember that this node maps to this listitem | 343 | // remember that this node maps to this listitem |
341 | Mapping->insert( it, NN ); | 344 | Mapping->insert( it, NN ); |
342 | buildSubTree( it, NN ); | 345 | buildSubTree( it, NN ); |
343 | } | 346 | } |
344 | } | 347 | } |
345 | 348 | ||
346 | // Build device tree -> help function | 349 | // Build device tree -> help function |
347 | void EditNetworkSetup::buildSubTree( QListViewItem * it, ANetNode *NN ) { | 350 | void EditNetworkSetup::buildSubTree( QListViewItem * it, ANetNode *NN ) { |
348 | ANetNode::NetNodeList & NNL = NN->alternatives(); | 351 | ANetNode::NetNodeList & NNL = NN->alternatives(); |
349 | 352 | ||
350 | if( NNL.size() > 1 ) { | 353 | if( NNL.size() > 1 ) { |
351 | // this node has alternatives -> needs radio buttons | 354 | // this node has alternatives -> needs radio buttons |
352 | it = new MyQCheckListItem( | 355 | it = new MyQCheckListItem( |
353 | it, | 356 | it, |
354 | NSResources->netNode2Name(NN->needs()[0]), | 357 | NSResources->netNode2Name(NN->needs()[0]), |
355 | QCheckListItem::Controller ); | 358 | QCheckListItem::Controller ); |
356 | it->setSelectable( FALSE ); | 359 | it->setSelectable( FALSE ); |
357 | } | 360 | } |
358 | 361 | ||
359 | for ( unsigned int i=0; i < NNL.size(); i++ ) { | 362 | for ( unsigned int i=0; i < NNL.size(); i++ ) { |
360 | QListViewItem * CI; | 363 | QListViewItem * CI; |
361 | if( NNL.size() > 1 ) { | 364 | if( NNL.size() > 1 ) { |
362 | // generate radio buttons | 365 | // generate radio buttons |
363 | CI = new MyQCheckListItem( | 366 | CI = new MyQCheckListItem( |
364 | (QCheckListItem *)it, | 367 | (QCheckListItem *)it, |
365 | NNL[i]->name(), QCheckListItem::RadioButton ); | 368 | NNL[i]->name(), QCheckListItem::RadioButton ); |
366 | // remember that this node maps to this listitem | 369 | // remember that this node maps to this listitem |
367 | CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) ); | 370 | CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) ); |
368 | Mapping->insert( CI, NNL[i] ); | 371 | Mapping->insert( CI, NNL[i] ); |
369 | CI->setSelectable( FALSE ); | 372 | CI->setSelectable( FALSE ); |
370 | } else { | 373 | } else { |
371 | // Single item | 374 | // Single item |
372 | CI = new MyQListViewItem( it, NNL[i]->name() ); | 375 | CI = new MyQListViewItem( it, NNL[i]->name() ); |
373 | // remember that this node maps to this listitem | 376 | // remember that this node maps to this listitem |
374 | Mapping->insert( CI, NNL[i] ); | 377 | Mapping->insert( CI, NNL[i] ); |
375 | CI->setSelectable( FALSE ); | 378 | CI->setSelectable( FALSE ); |
376 | CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) ); | 379 | CI->setPixmap( 0, NSResources->getPixmap( NNL[i]->pixmapName() ) ); |
377 | } | 380 | } |
378 | buildSubTree( CI, NNL[i] ); | 381 | buildSubTree( CI, NNL[i] ); |
379 | } | 382 | } |
380 | } | 383 | } |
381 | 384 | ||
382 | // Clicked ok OK button | 385 | // Clicked ok OK button |
383 | void EditNetworkSetup::accept( void ) { | 386 | void EditNetworkSetup::accept( void ) { |
384 | if( ! haveCompleteConfig( 0 ) || Name_LE->text().isEmpty() ) { | 387 | if( ! haveCompleteConfig( 0 ) || Name_LE->text().isEmpty() ) { |
385 | QMessageBox::warning( | 388 | QMessageBox::warning( |
386 | 0, | 389 | 0, |
387 | tr( "Closing NetworkSetup Setup" ), | 390 | tr( "Closing NetworkSetup Setup" ), |
388 | tr( "Definition not complete or no name" ) ); | 391 | tr( "Definition not complete or no name" ) ); |
389 | return; | 392 | return; |
390 | } | 393 | } |
391 | 394 | ||
392 | // check if all devices have acceptable input | 395 | // check if all devices have acceptable input |
393 | getTmpCollection(); | 396 | getTmpCollection(); |
394 | { ANetNodeInstance * NNI; | 397 | { ANetNodeInstance * NNI; |
395 | QString S; | 398 | QString S; |
396 | 399 | ||
397 | for( QListIterator<ANetNodeInstance> it(TmpCollection); | 400 | for( QListIterator<ANetNodeInstance> it(TmpCollection); |
398 | it.current(); | 401 | it.current(); |
399 | ++it ) { | 402 | ++it ) { |
400 | NNI = it.current(); | 403 | NNI = it.current(); |
401 | // widget must show its own problems | 404 | // widget must show its own problems |
402 | S = NNI->acceptable(); | 405 | S = NNI->acceptable(); |
403 | if( ! S.isEmpty() ) { | 406 | if( ! S.isEmpty() ) { |
404 | QMessageBox::warning( | 407 | QMessageBox::warning( |
405 | 0, | 408 | 0, |
406 | tr( "Cannot save" ), | 409 | tr( "Cannot save" ), |
407 | S ); | 410 | S ); |
408 | return; | 411 | return; |
409 | } | 412 | } |
410 | NNI->commit(); | 413 | NNI->commit(); |
411 | 414 | ||
412 | if( NNI->isModified() ) { | 415 | if( NNI->isModified() ) { |
413 | TmpCollection.setModified( 1 ); | 416 | TmpCollection.setModified( 1 ); |
414 | // commit the data | 417 | // commit the data |
415 | } | 418 | } |
416 | } | 419 | } |
417 | } | 420 | } |
418 | 421 | ||
419 | QDialog::accept(); | 422 | QDialog::accept(); |
420 | } | 423 | } |
421 | 424 | ||
422 | // triggered by CB | 425 | // triggered by CB |
423 | void EditNetworkSetup::SLOT_AutoCollapse( bool b ) { | 426 | void EditNetworkSetup::SLOT_AutoCollapse( bool b ) { |
424 | AutoCollapse = b; | 427 | AutoCollapse = b; |
425 | } | 428 | } |
426 | 429 | ||
427 | // clicked on node in tree -> update GUI | 430 | // clicked on node in tree -> update GUI |
428 | void EditNetworkSetup::SLOT_SelectNode( QListViewItem * it ) { | 431 | void EditNetworkSetup::SLOT_SelectNode( QListViewItem * it ) { |
429 | ANetNode * NN; | 432 | ANetNode * NN; |
430 | if( it == 0 || it->depth() == 0 ) { | 433 | if( it == 0 || it->depth() == 0 ) { |
431 | Description_LBL->setText( | 434 | Description_LBL->setText( |
432 | NSResources->netNode2Description( "fullsetup" ) ); | 435 | NSResources->netNode2Description( "fullsetup" ) ); |
433 | // topevel or no selection | 436 | // topevel or no selection |
434 | return; | 437 | return; |
435 | } | 438 | } |
436 | 439 | ||
437 | // store conversion from lvitem to node | 440 | // store conversion from lvitem to node |
438 | NN = (*Mapping)[ it ]; | 441 | NN = (*Mapping)[ it ]; |
439 | 442 | ||
440 | if( ! NN ) { | 443 | if( ! NN ) { |
441 | // intermediate node | 444 | // intermediate node |
442 | NN = (*Mapping)[ it->parent() ]; | 445 | NN = (*Mapping)[ it->parent() ]; |
443 | if( NN ) { | 446 | if( NN ) { |
444 | // figure out type of this node -> produce mesage | 447 | // figure out type of this node -> produce mesage |
445 | Description_LBL->setText( NSResources->netNode2Description( | 448 | Description_LBL->setText( NSResources->netNode2Description( |
446 | NN->needs()[0]) ); | 449 | NN->needs()[0]) ); |
447 | } else { | 450 | } else { |
448 | Description_LBL->setText( "" ); | 451 | Description_LBL->setText( "" ); |
449 | } | 452 | } |
450 | return; | 453 | return; |
451 | } | 454 | } |
452 | 455 | ||
453 | Description_LBL->setText( NN->nodeDescription() ); | 456 | Description_LBL->setText( NN->nodeDescription() ); |
454 | 457 | ||
455 | if( ! it->isSelectable() ) { | 458 | if( ! it->isSelectable() ) { |
456 | return; | 459 | return; |
457 | } | 460 | } |
458 | 461 | ||
459 | if( ! ((QCheckListItem *)it)->isOn() ) { | 462 | ANetNode::NetNodeList & NNL = NN->alternatives(); |
460 | // clicked on line but NOT on Check or Radio item | 463 | |
461 | return; | 464 | if( NNL.size() != 1 ) { |
465 | if( NNL.size() == 0 || | ||
466 | ! ((MyQCheckListItem *)it)->isOn() | ||
467 | ) { | ||
468 | // not clicked on Check or Radio item | ||
469 | return; | ||
470 | } | ||
462 | } | 471 | } |
463 | 472 | ||
464 | // item has really changed -> update | 473 | // item has really changed -> update |
465 | TmpIsValid = 0; | 474 | TmpIsValid = 0; |
466 | updateGUI( it, NN ); | 475 | updateGUI( it, NN ); |
467 | } | 476 | } |
468 | 477 | ||
469 | // cliecked on TAB to go to setup | 478 | // cliecked on TAB to go to setup |
470 | void EditNetworkSetup::SLOT_AlterTab( const QString & S ) { | 479 | void EditNetworkSetup::SLOT_AlterTab( const QString & S ) { |
471 | if( S == tr( "Setup" ) && Setup_FRM->isEnabled() ) { | 480 | if( S == tr( "Setup" ) && Setup_FRM->isEnabled() ) { |
472 | // switched to setup -> update CB and populate ws with | 481 | // switched to setup -> update CB and populate ws with |
473 | // forms for devices | 482 | // forms for devices |
474 | 483 | ||
475 | if( ! TmpIsValid ) { | 484 | if( ! TmpIsValid ) { |
476 | getTmpCollection(); | 485 | getTmpCollection(); |
477 | 486 | ||
478 | // clear CB and Ws | 487 | // clear CB and Ws |
479 | { QWidget * W; | 488 | { QWidget * W; |
480 | int i = 0; | 489 | int i = 0; |
481 | 490 | ||
482 | Devices_CB->clear(); | 491 | Devices_CB->clear(); |
483 | while( ( W = Setup_WS->widget( i ) ) ) { | 492 | while( ( W = Setup_WS->widget( i ) ) ) { |
484 | Setup_WS->removeWidget( W ); | 493 | Setup_WS->removeWidget( W ); |
485 | i ++; | 494 | i ++; |
486 | } | 495 | } |
487 | } | 496 | } |
488 | 497 | ||
489 | // update CB | 498 | // update CB |
490 | // and populate WidgetStack | 499 | // and populate WidgetStack |
491 | { ANetNodeInstance * NNI; | 500 | { ANetNodeInstance * NNI; |
492 | QListIterator<ANetNodeInstance> it(TmpCollection); | 501 | QListIterator<ANetNodeInstance> it(TmpCollection); |
493 | int i = 0; | 502 | int i = 0; |
494 | QWidget * W; | 503 | QWidget * W; |
495 | 504 | ||
496 | for ( ; it.current(); ++it ) { | 505 | for ( ; it.current(); ++it ) { |
497 | NNI = it.current(); | 506 | NNI = it.current(); |
498 | Devices_CB->insertItem( | 507 | Devices_CB->insertItem( |
499 | NSResources->getPixmap( NNI->nodeClass()->pixmapName() ), | 508 | NSResources->getPixmap( NNI->nodeClass()->pixmapName() ), |
500 | NNI->nodeClass()->name() | 509 | NNI->nodeClass()->name() |
501 | ); | 510 | ); |
502 | 511 | ||
503 | // add edit widget | 512 | // add edit widget |
504 | W = NNI->edit( Setup_WS ); | 513 | W = NNI->edit( Setup_WS ); |
505 | if( ! W) { | 514 | if( ! W) { |
506 | W = new QLabel( Setup_WS, | 515 | W = new QLabel( Setup_WS, |
507 | tr("No configuration required")); | 516 | tr("No configuration required")); |
508 | } | 517 | } |
509 | Setup_WS->addWidget( W , i ); | 518 | Setup_WS->addWidget( W , i ); |
510 | i ++; | 519 | i ++; |
511 | } | 520 | } |
512 | } | 521 | } |
513 | Setup_WS->raiseWidget( 0 ); | 522 | Setup_WS->raiseWidget( 0 ); |
514 | } // still valid | 523 | } // still valid |
515 | } | 524 | } |
516 | } | 525 | } |
517 | 526 | ||
518 | // update visual feedback of selection state | 527 | // update visual feedback of selection state |
519 | void EditNetworkSetup::updateGUI( QListViewItem * it, ANetNode * NN ) { | 528 | void EditNetworkSetup::updateGUI( QListViewItem * it, ANetNode * NN ) { |
520 | 529 | ||
521 | bool HCC = haveCompleteConfig( it ); | 530 | bool HCC = haveCompleteConfig( it ); |
522 | Tab_TB->setTabEnabled( Setup_FRM, HCC ); | 531 | Tab_TB->setTabEnabled( Setup_FRM, HCC ); |
523 | Setup_FRM->setEnabled( HCC ); | 532 | Setup_FRM->setEnabled( HCC ); |
524 | 533 | ||
525 | // disable children of all siblings at same level | 534 | // disable children of all siblings at same level |
526 | QListViewItem * Sbl = it->parent()->firstChild(); | 535 | QListViewItem * Sbl = it->parent()->firstChild(); |
527 | while( Sbl ) { | 536 | while( Sbl ) { |
528 | if ( Sbl != it ) { | 537 | if ( Sbl != it ) { |
529 | disableTree( Sbl->firstChild(), FALSE ); | 538 | disableTree( Sbl->firstChild(), FALSE ); |
530 | Sbl->setSelectable( TRUE ); | 539 | Sbl->setSelectable( TRUE ); |
531 | if( AutoCollapse ) | 540 | if( AutoCollapse ) |
532 | Sbl->setOpen( FALSE ); | 541 | Sbl->setOpen( FALSE ); |
533 | } | 542 | } |
534 | Sbl = Sbl->nextSibling(); | 543 | Sbl = Sbl->nextSibling(); |
535 | } | 544 | } |
536 | 545 | ||
537 | // enable selected path (as deep as it goes | 546 | // enable selected path (as deep as it goes |
538 | it->setOpen( TRUE ); | 547 | it->setOpen( TRUE ); |
539 | enablePath( it->firstChild(), | 548 | enablePath( it->firstChild(), |
540 | (it->depth()==1) ? | 549 | (it->depth()==1) ? |
541 | 1 : // toplevel always alternatives | 550 | 1 : // toplevel always alternatives |
542 | (NN->alternatives().size() > 1) ); | 551 | (NN->alternatives().size() > 1) ); |
543 | } | 552 | } |
544 | 553 | ||
545 | void EditNetworkSetup::disableTree( QListViewItem * it, bool Mode ) { | 554 | void EditNetworkSetup::disableTree( QListViewItem * it, bool Mode ) { |
546 | while( it ) { | 555 | while( it ) { |
547 | // disable sbl's chidren | 556 | // disable sbl's chidren |
548 | it->setSelectable( Mode ); | 557 | it->setSelectable( Mode ); |
549 | if( AutoCollapse ) | 558 | if( AutoCollapse ) |
550 | it->setOpen( Mode ); | 559 | it->setOpen( Mode ); |
551 | disableTree( it->firstChild(), Mode ); | 560 | disableTree( it->firstChild(), Mode ); |
552 | it = it->nextSibling(); | 561 | it = it->nextSibling(); |
553 | } | 562 | } |
554 | } | 563 | } |
555 | 564 | ||
556 | // pah : ParentHasAlternatives | 565 | // pah : ParentHasAlternatives |
557 | void EditNetworkSetup::enablePath( QListViewItem * it, bool pha ) { | 566 | void EditNetworkSetup::enablePath( QListViewItem * it, bool pha ) { |
558 | while( it ) { | 567 | while( it ) { |
559 | ANetNode * NN; | 568 | ANetNode * NN; |
560 | NN = (*Mapping)[it]; | 569 | NN = (*Mapping)[it]; |
561 | if( NN ) { | 570 | if( NN ) { |
562 | if( pha ) { | 571 | if( pha ) { |
563 | bool doOn = ((QCheckListItem *)it)->isOn(); | 572 | bool doOn = ((QCheckListItem *)it)->isOn(); |
564 | // we are a checklistitem for sure | 573 | // we are a checklistitem for sure |
565 | it->setSelectable( TRUE ); | 574 | it->setSelectable( TRUE ); |
566 | if( AutoCollapse && ! doOn ) | 575 | if( AutoCollapse && ! doOn ) |
567 | it->setOpen( doOn ); | 576 | it->setOpen( doOn ); |
568 | if( doOn ) { | 577 | if( doOn ) { |
569 | // selected alternative | 578 | // selected alternative |
570 | enablePath( it->firstChild(), | 579 | enablePath( it->firstChild(), |
571 | NN->alternatives().size() > 1); | 580 | NN->alternatives().size() > 1); |
572 | } else { | 581 | } else { |
573 | // non-selected alternative | 582 | // non-selected alternative |
574 | disableTree( it->firstChild(), FALSE); | 583 | disableTree( it->firstChild(), FALSE); |
575 | } | 584 | } |
576 | } else { | 585 | } else { |
577 | // we are single subitem | 586 | // we are single subitem |
578 | it->setSelectable( TRUE ); | 587 | it->setSelectable( TRUE ); |
579 | it->setOpen( TRUE ); | 588 | it->setOpen( TRUE ); |
580 | enablePath( it->firstChild(), | 589 | enablePath( it->firstChild(), |
581 | NN->alternatives().size() > 1); | 590 | NN->alternatives().size() > 1); |
582 | } | 591 | } |
583 | } else { | 592 | } else { |
584 | // controller node | 593 | // controller node |
585 | it->setSelectable( TRUE ); | 594 | it->setSelectable( TRUE ); |
586 | it->setOpen( TRUE ); | 595 | it->setOpen( TRUE ); |
587 | enablePath( it->firstChild(), pha ); | 596 | enablePath( it->firstChild(), pha ); |
588 | } | 597 | } |
589 | it = it->nextSibling(); | 598 | it = it->nextSibling(); |
590 | } | 599 | } |
591 | } | 600 | } |
592 | 601 | ||
593 | // do we have a complete configuration (all needs are provided for ?) | 602 | // do we have a complete configuration (all needs are provided for ?) |
594 | bool EditNetworkSetup::haveCompleteConfig( QListViewItem * it ) { | 603 | bool EditNetworkSetup::haveCompleteConfig( QListViewItem * it ) { |
595 | 604 | ||
596 | // check if all below this level is selected | 605 | // check if all below this level is selected |
597 | it = ( it ) ?it : Nodes_LV->firstChild(); | 606 | it = ( it ) ?it : Nodes_LV->firstChild(); |
598 | ANetNode *NN; | 607 | ANetNode *NN; |
599 | bool Found; | 608 | bool Found; |
600 | 609 | ||
601 | while ( it ) { | 610 | while ( it ) { |
602 | NN = (*Mapping)[it]; | 611 | NN = (*Mapping)[it]; |
603 | if( NN == 0 ) { | 612 | if( NN == 0 ) { |
604 | // this item is a controller -> | 613 | // this item is a controller -> |
605 | // has radio items as children -> | 614 | // has radio items as children -> |
606 | // find selected one | 615 | // find selected one |
607 | it = it->firstChild(); | 616 | it = it->firstChild(); |
608 | Found = 0; | 617 | Found = 0; |
609 | while( it ) { | 618 | while( it ) { |
610 | if( ((QCheckListItem *)it)->isOn() ) { | 619 | if( ((QCheckListItem *)it)->isOn() ) { |
611 | Found = 1; | 620 | Found = 1; |
612 | // go deeper | 621 | // go deeper |
613 | it = it->firstChild(); | 622 | it = it->firstChild(); |
614 | break; | 623 | break; |
615 | } | 624 | } |
616 | it = it->nextSibling(); | 625 | it = it->nextSibling(); |
617 | } | 626 | } |
618 | 627 | ||
619 | if( ! Found ) { | 628 | if( ! Found ) { |
620 | return 0; // no not complete -> a radio should have been chkd | 629 | return 0; // no not complete -> a radio should have been chkd |
621 | } | 630 | } |
622 | 631 | ||
623 | // it now contains selected radio | 632 | // it now contains selected radio |
624 | NN = (*Mapping)[it]; | 633 | NN = (*Mapping)[it]; |
625 | } else { | 634 | } else { |
626 | // automatic selection | 635 | // automatic selection |
627 | it = it->firstChild(); | 636 | it = it->firstChild(); |
628 | } | 637 | } |
629 | } | 638 | } |
630 | return 1; | 639 | return 1; |
631 | } | 640 | } |
diff --git a/noncore/settings/networksettings2/nsdata.cpp b/noncore/settings/networksettings2/nsdata.cpp index b4622fc..835c7c3 100644 --- a/noncore/settings/networksettings2/nsdata.cpp +++ b/noncore/settings/networksettings2/nsdata.cpp | |||
@@ -1,787 +1,787 @@ | |||
1 | #include <stdlib.h> | 1 | #include <stdlib.h> |
2 | #include <opie2/odebug.h> | 2 | #include <opie2/odebug.h> |
3 | #include <qpe/qpeapplication.h> | 3 | #include <qpe/qpeapplication.h> |
4 | #include <qtextstream.h> | 4 | #include <qtextstream.h> |
5 | #include <qdir.h> | 5 | #include <qdir.h> |
6 | #include <qfile.h> | 6 | #include <qfile.h> |
7 | #include <qfileinfo.h> | 7 | #include <qfileinfo.h> |
8 | 8 | ||
9 | #include "nsdata.h" | 9 | #include "nsdata.h" |
10 | #include <netnode.h> | 10 | #include <netnode.h> |
11 | #include <resources.h> | 11 | #include <resources.h> |
12 | 12 | ||
13 | static QString CfgFile; | 13 | static QString CfgFile; |
14 | 14 | ||
15 | NetworkSettingsData::NetworkSettingsData( void ) { | 15 | NetworkSettingsData::NetworkSettingsData( void ) { |
16 | // init global resources structure | 16 | // init global resources structure |
17 | new TheNSResources(); | 17 | new TheNSResources(); |
18 | 18 | ||
19 | if( ! NSResources->userKnown() ) { | 19 | if( ! NSResources->userKnown() ) { |
20 | Log(( "Cannot detect qpe user HOME=\"%s\" USER=\"%s\"\n", | 20 | Log(( "Cannot detect qpe user HOME=\"%s\" USER=\"%s\"\n", |
21 | NSResources->currentUser().HomeDir.latin1(), | 21 | NSResources->currentUser().HomeDir.latin1(), |
22 | NSResources->currentUser().UserName.latin1() )); | 22 | NSResources->currentUser().UserName.latin1() )); |
23 | return; | 23 | return; |
24 | } | 24 | } |
25 | 25 | ||
26 | CfgFile.sprintf( "%s/Settings/NS2.conf", | 26 | CfgFile.sprintf( "%s/Settings/NS2.conf", |
27 | NSResources->currentUser().HomeDir.latin1() ); | 27 | NSResources->currentUser().HomeDir.latin1() ); |
28 | Log(( "Cfg from %s\n", CfgFile.latin1() )); | 28 | Log(( "Cfg from %s\n", CfgFile.latin1() )); |
29 | 29 | ||
30 | // load settings | 30 | // load settings |
31 | loadSettings(); | 31 | loadSettings(); |
32 | 32 | ||
33 | // assign interfaces by scanning /tmp/profile-%s.Up files | 33 | // assign interfaces by scanning /tmp/profile-%s.Up files |
34 | { QDir D( "/tmp" ); | 34 | { QDir D( "/tmp" ); |
35 | QFile * F = new QFile; | 35 | QFile * F = new QFile; |
36 | int profilenr; | 36 | int profilenr; |
37 | QString interfacename; | 37 | QString interfacename; |
38 | QTextStream TS ( F ); | 38 | QTextStream TS ( F ); |
39 | 39 | ||
40 | QStringList SL = D.entryList( "profile-*.up"); | 40 | QStringList SL = D.entryList( "profile-*.up"); |
41 | 41 | ||
42 | Log(( "System reports %d interfaces. Found %d up\n", | 42 | Log(( "System reports %d interfaces. Found %d up\n", |
43 | NSResources->system().interfaces().count(), | 43 | NSResources->system().interfaces().count(), |
44 | SL.count() )); | 44 | SL.count() )); |
45 | 45 | ||
46 | for ( QStringList::Iterator it = SL.begin(); | 46 | for ( QStringList::Iterator it = SL.begin(); |
47 | it != SL.end(); | 47 | it != SL.end(); |
48 | ++it ) { | 48 | ++it ) { |
49 | profilenr = atol( (*it).mid( 8 ).latin1() ); | 49 | profilenr = atol( (*it).mid( 8 ).latin1() ); |
50 | // read the interface store int 'up' | 50 | // read the interface store int 'up' |
51 | F->setName( D.path() + "/" + (*it) ); | 51 | F->setName( D.path() + "/" + (*it) ); |
52 | if( F->open( IO_ReadOnly ) ) { | 52 | if( F->open( IO_ReadOnly ) ) { |
53 | NetworkSetup * NC; | 53 | NetworkSetup * NC; |
54 | interfacename = TS.readLine(); | 54 | interfacename = TS.readLine(); |
55 | F->close(); | 55 | F->close(); |
56 | 56 | ||
57 | Log(( "Assign interface %s to Profile nr %d\n", | 57 | Log(( "Assign interface %s to Profile nr %d\n", |
58 | interfacename.latin1(), profilenr )); | 58 | interfacename.latin1(), profilenr )); |
59 | 59 | ||
60 | NC = NSResources->getNetworkSetup( profilenr ); | 60 | NC = NSResources->getNetworkSetup( profilenr ); |
61 | if( NC ) { | 61 | if( NC ) { |
62 | NC->assignInterface( | 62 | NC->assignInterface( |
63 | NSResources->system().findInterface( interfacename ) ); | 63 | NSResources->system().findInterface( interfacename ) ); |
64 | Log(( "Assign interface %p\n", | 64 | Log(( "Assign interface %p\n", |
65 | NC->assignedInterface() )); | 65 | NC->assignedInterface() )); |
66 | } else { | 66 | } else { |
67 | Log(( "Profile nr %d no longer defined\n", | 67 | Log(( "Profile nr %d no longer defined\n", |
68 | profilenr )); | 68 | profilenr )); |
69 | } | 69 | } |
70 | } | 70 | } |
71 | } | 71 | } |
72 | } | 72 | } |
73 | } | 73 | } |
74 | 74 | ||
75 | // saving is done by caller | 75 | // saving is done by caller |
76 | NetworkSettingsData::~NetworkSettingsData( void ) { | 76 | NetworkSettingsData::~NetworkSettingsData( void ) { |
77 | delete NSResources; | 77 | delete NSResources; |
78 | } | 78 | } |
79 | 79 | ||
80 | void NetworkSettingsData::loadSettings( void ) { | 80 | void NetworkSettingsData::loadSettings( void ) { |
81 | QString Line, S; | 81 | QString Line, S; |
82 | QString Attr, Value; | 82 | QString Attr, Value; |
83 | long idx; | 83 | long idx; |
84 | 84 | ||
85 | QFile F( CfgFile ); | 85 | QFile F( CfgFile ); |
86 | QTextStream TS( &F ); | 86 | QTextStream TS( &F ); |
87 | 87 | ||
88 | ForceModified = 0; | 88 | ForceModified = 0; |
89 | 89 | ||
90 | do { | 90 | do { |
91 | 91 | ||
92 | if( ! F.open(IO_ReadOnly) ) | 92 | if( ! F.open(IO_ReadOnly) ) |
93 | break; | 93 | break; |
94 | 94 | ||
95 | /* load the file -> | 95 | /* load the file -> |
96 | 96 | ||
97 | FORMAT : | 97 | FORMAT : |
98 | 98 | ||
99 | [NETNODETYPE] | 99 | [NETNODETYPE] |
100 | Entries ... | 100 | Entries ... |
101 | <EMPTYLINE> | 101 | <EMPTYLINE> |
102 | [NetworkSetup] | 102 | [NetworkSetup] |
103 | Name=Name | 103 | Name=Name |
104 | Node=Name | 104 | Node=Name |
105 | <EMPTYLINE> | 105 | <EMPTYLINE> |
106 | */ | 106 | */ |
107 | while( ! TS.atEnd() ) { | 107 | while( ! TS.atEnd() ) { |
108 | S = Line = TS.readLine(); | 108 | S = Line = TS.readLine(); |
109 | 109 | ||
110 | if ( S.isEmpty() || S[0] != '[' ) | 110 | if ( S.isEmpty() || S[0] != '[' ) |
111 | continue; | 111 | continue; |
112 | 112 | ||
113 | S = S.mid( 1, S.length()-2 ); | 113 | S = S.mid( 1, S.length()-2 ); |
114 | 114 | ||
115 | if( ! NSResources ) { | 115 | if( ! NSResources ) { |
116 | continue; | 116 | continue; |
117 | } | 117 | } |
118 | 118 | ||
119 | if( S == "NetworkSetup" ) { | 119 | if( S == "NetworkSetup" ) { |
120 | // load NetworkSetups -> collections of nodes | 120 | // load NetworkSetups -> collections of nodes |
121 | bool Dangling; | 121 | bool Dangling; |
122 | NetworkSetup * NC = new NetworkSetup( TS, Dangling ); | 122 | NetworkSetup * NC = new NetworkSetup( TS, Dangling ); |
123 | NSResources->addNetworkSetup( NC, Dangling ); | 123 | NSResources->addNetworkSetup( NC, Dangling ); |
124 | } else { | 124 | } else { |
125 | ANetNode * NN = 0; | 125 | ANetNode * NN = 0; |
126 | ANetNodeInstance* NNI = 0; | 126 | ANetNodeInstance* NNI = 0; |
127 | if( S.startsWith( "nodetype " ) ) { | 127 | if( S.startsWith( "nodetype " ) ) { |
128 | S = S.mid( 9, S.length()-9 ); | 128 | S = S.mid( 9, S.length()-9 ); |
129 | S = deQuote(S); | 129 | S = deQuote(S); |
130 | // try to find netnode | 130 | // try to find netnode |
131 | NN = NSResources->findNetNode( S ); | 131 | NN = NSResources->findNetNode( S ); |
132 | } else { | 132 | } else { |
133 | // try to find instance | 133 | // try to find instance |
134 | NNI = NSResources->createNodeInstance( S ); | 134 | NNI = NSResources->createNodeInstance( S ); |
135 | } | 135 | } |
136 | 136 | ||
137 | if( NN == 0 && NNI == 0 ) { | 137 | if( NN == 0 && NNI == 0 ) { |
138 | LeftOvers.append( Line ); | 138 | LeftOvers.append( Line ); |
139 | do { | 139 | do { |
140 | Line = TS.readLine(); | 140 | Line = TS.readLine(); |
141 | // store even delimiter | 141 | // store even delimiter |
142 | LeftOvers.append( Line ); | 142 | LeftOvers.append( Line ); |
143 | } while ( ! Line.isEmpty() ); | 143 | } while ( ! Line.isEmpty() ); |
144 | 144 | ||
145 | //next section | 145 | //next section |
146 | continue; | 146 | continue; |
147 | } | 147 | } |
148 | 148 | ||
149 | // read entries of this section | 149 | // read entries of this section |
150 | do { | 150 | do { |
151 | S = Line = TS.readLine(); | 151 | S = Line = TS.readLine(); |
152 | 152 | ||
153 | if( S.isEmpty() ) { | 153 | if( S.isEmpty() ) { |
154 | // empty line | 154 | // empty line |
155 | break; | 155 | break; |
156 | } | 156 | } |
157 | idx = S.find( '=' ); | 157 | idx = S.find( '=' ); |
158 | if( idx > 0 ) { | 158 | if( idx > 0 ) { |
159 | Attr = S.left( idx ); | 159 | Attr = S.left( idx ); |
160 | Value = S.mid( idx+1, S.length() ); | 160 | Value = S.mid( idx+1, S.length() ); |
161 | } else { | 161 | } else { |
162 | Value=""; | 162 | Value=""; |
163 | Attr = S; | 163 | Attr = S; |
164 | } | 164 | } |
165 | 165 | ||
166 | Value.stripWhiteSpace(); | 166 | Value.stripWhiteSpace(); |
167 | Attr.stripWhiteSpace(); | 167 | Attr.stripWhiteSpace(); |
168 | Attr.lower(); | 168 | Attr.lower(); |
169 | // dequote Attr | 169 | // dequote Attr |
170 | Value = deQuote(Value); | 170 | Value = deQuote(Value); |
171 | 171 | ||
172 | if( NN ) { | 172 | if( NN ) { |
173 | // set the attribute | 173 | // set the attribute |
174 | NN->setAttribute( Attr, Value ); | 174 | NN->setAttribute( Attr, Value ); |
175 | } else { | 175 | } else { |
176 | // set the attribute | 176 | // set the attribute |
177 | NNI->setAttribute( Attr, Value ); | 177 | NNI->setAttribute( Attr, Value ); |
178 | } | 178 | } |
179 | } while( 1 ); | 179 | } while( 1 ); |
180 | 180 | ||
181 | if( NNI ) { | 181 | if( NNI ) { |
182 | // loading from file -> exists | 182 | // loading from file -> exists |
183 | Log( ( "NodeInstance %s : %p\n", NNI->name(), NNI )); | 183 | Log( ( "NodeInstance %s : %p\n", NNI->name(), NNI )); |
184 | NNI->setNew( FALSE ); | 184 | NNI->setNew( FALSE ); |
185 | NSResources->addNodeInstance( NNI ); | 185 | NSResources->addNodeInstance( NNI ); |
186 | } | 186 | } |
187 | 187 | ||
188 | if( NN ) { | 188 | if( NN ) { |
189 | Log( ( "Node %s : %p\n", NN->name(), NN ) ); | 189 | Log( ( "Node %s : %p\n", NN->name(), NN ) ); |
190 | } | 190 | } |
191 | } | 191 | } |
192 | } | 192 | } |
193 | 193 | ||
194 | } while( 0 ); | 194 | } while( 0 ); |
195 | 195 | ||
196 | } | 196 | } |
197 | 197 | ||
198 | QString NetworkSettingsData::saveSettings( void ) { | 198 | QString NetworkSettingsData::saveSettings( void ) { |
199 | QString ErrS = ""; | 199 | QString ErrS = ""; |
200 | 200 | ||
201 | if( ! isModified() ) | 201 | if( ! isModified() ) |
202 | return ErrS; | 202 | return ErrS; |
203 | 203 | ||
204 | QString S; | 204 | QString S; |
205 | QFile F( CfgFile + ".bup" ); | 205 | QFile F( CfgFile + ".bup" ); |
206 | 206 | ||
207 | Log( ( "Saving settings to %s\n", CfgFile.latin1() )); | 207 | Log( ( "Saving settings to %s\n", CfgFile.latin1() )); |
208 | if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { | 208 | if( ! F.open( IO_WriteOnly | IO_Truncate ) ) { |
209 | ErrS = qApp->translate( "NetworkSettings", | 209 | ErrS = qApp->translate( "NetworkSettings", |
210 | "<p>Could not save setup to \"%1\" !</p>" ). | 210 | "<p>Could not save setup to \"%1\" !</p>" ). |
211 | arg(CfgFile); | 211 | arg(CfgFile); |
212 | // problem | 212 | // problem |
213 | return ErrS; | 213 | return ErrS; |
214 | } | 214 | } |
215 | 215 | ||
216 | QTextStream TS( &F ); | 216 | QTextStream TS( &F ); |
217 | 217 | ||
218 | // save global configs | 218 | // save global configs |
219 | for( QDictIterator<ANetNode> it( NSResources->netNodes() ); | 219 | for( QDictIterator<ANetNode> it( NSResources->netNodes() ); |
220 | it.current(); | 220 | it.current(); |
221 | ++it ) { | 221 | ++it ) { |
222 | TS << "[nodetype " | 222 | TS << "[nodetype " |
223 | << quote( QString( it.current()->name() ) ) | 223 | << quote( QString( it.current()->name() ) ) |
224 | << "]" | 224 | << "]" |
225 | << endl; | 225 | << endl; |
226 | 226 | ||
227 | it.current()->saveAttributes( TS ); | 227 | it.current()->saveAttributes( TS ); |
228 | TS << endl; | 228 | TS << endl; |
229 | } | 229 | } |
230 | 230 | ||
231 | // save leftovers | 231 | // save leftovers |
232 | for ( QStringList::Iterator it = LeftOvers.begin(); | 232 | for ( QStringList::Iterator it = LeftOvers.begin(); |
233 | it != LeftOvers.end(); ++it ) { | 233 | it != LeftOvers.end(); ++it ) { |
234 | TS << (*it) << endl; | 234 | TS << (*it) << endl; |
235 | } | 235 | } |
236 | 236 | ||
237 | // save all netnode instances | 237 | // save all netnode instances |
238 | { ANetNodeInstance * NNI; | 238 | { ANetNodeInstance * NNI; |
239 | for( QDictIterator<ANetNodeInstance> nit( | 239 | for( QDictIterator<ANetNodeInstance> nit( |
240 | NSResources->netNodeInstances()); | 240 | NSResources->netNodeInstances()); |
241 | nit.current(); | 241 | nit.current(); |
242 | ++nit ) { | 242 | ++nit ) { |
243 | // header | 243 | // header |
244 | NNI = nit.current(); | 244 | NNI = nit.current(); |
245 | TS << '[' | 245 | TS << '[' |
246 | << QString(NNI->nodeClass()->name()) | 246 | << QString(NNI->nodeClass()->name()) |
247 | << ']' | 247 | << ']' |
248 | << endl; | 248 | << endl; |
249 | NNI->saveAttributes( TS ); | 249 | NNI->saveAttributes( TS ); |
250 | TS << endl; | 250 | TS << endl; |
251 | } | 251 | } |
252 | } | 252 | } |
253 | 253 | ||
254 | // good NetworkSetups | 254 | // good NetworkSetups |
255 | { Name2NetworkSetup_t & M = NSResources->networkSetups(); | 255 | { Name2NetworkSetup_t & M = NSResources->networkSetups(); |
256 | 256 | ||
257 | // for all NetworkSetups | 257 | // for all NetworkSetups |
258 | for( QDictIterator<NetworkSetup> it(M); | 258 | for( QDictIterator<NetworkSetup> it(M); |
259 | it.current(); | 259 | it.current(); |
260 | ++it ) { | 260 | ++it ) { |
261 | TS << "[NetworkSetup]" << endl; | 261 | TS << "[NetworkSetup]" << endl; |
262 | it.current()->save(TS); | 262 | it.current()->save(TS); |
263 | } | 263 | } |
264 | } | 264 | } |
265 | 265 | ||
266 | // save dangling NetworkSetups | 266 | // save dangling NetworkSetups |
267 | { Name2NetworkSetup_t & M = NSResources->danglingNetworkSetups(); | 267 | { Name2NetworkSetup_t & M = NSResources->danglingNetworkSetups(); |
268 | 268 | ||
269 | // for all NetworkSetups | 269 | // for all NetworkSetups |
270 | for( QDictIterator<NetworkSetup> it(M); | 270 | for( QDictIterator<NetworkSetup> it(M); |
271 | it.current(); | 271 | it.current(); |
272 | ++it ) { | 272 | ++it ) { |
273 | TS << "[NetworkSetup]" << endl; | 273 | TS << "[NetworkSetup]" << endl; |
274 | it.current()->save(TS); | 274 | it.current()->save(TS); |
275 | } | 275 | } |
276 | } | 276 | } |
277 | 277 | ||
278 | QDir D("."); | 278 | QDir D("."); |
279 | D.rename( CfgFile + ".bup", CfgFile ); | 279 | D.rename( CfgFile + ".bup", CfgFile ); |
280 | 280 | ||
281 | // | 281 | // |
282 | // proper files AND system files regenerated | 282 | // proper files AND system files regenerated |
283 | // | 283 | // |
284 | 284 | ||
285 | 285 | ||
286 | for( QDictIterator<NetworkSetup> it(NSResources->networkSetups()); | 286 | for( QDictIterator<NetworkSetup> it(NSResources->networkSetups()); |
287 | it.current(); | 287 | it.current(); |
288 | ++it ) { | 288 | ++it ) { |
289 | it.current()->setModified( 0 ); | 289 | it.current()->setModified( 0 ); |
290 | } | 290 | } |
291 | 291 | ||
292 | return ErrS; | 292 | return ErrS; |
293 | } | 293 | } |
294 | 294 | ||
295 | QString NetworkSettingsData::generateSettings( void ) { | 295 | QString NetworkSettingsData::generateSettings( void ) { |
296 | QString S = ""; | 296 | QString S = ""; |
297 | Name2SystemFile_t & SFM = NSResources->systemFiles(); | 297 | Name2SystemFile_t & SFM = NSResources->systemFiles(); |
298 | Name2NetworkSetup_t & M = NSResources->networkSetups(); | 298 | Name2NetworkSetup_t & M = NSResources->networkSetups(); |
299 | NetworkSetup * NC; | 299 | NetworkSetup * NC; |
300 | ANetNodeInstance * NNI; | 300 | ANetNodeInstance * NNI; |
301 | ANetNodeInstance * FirstWithData; | 301 | ANetNodeInstance * FirstWithData; |
302 | RuntimeInfo * CurDev; | 302 | RuntimeInfo * CurDev; |
303 | ANetNode * NN, * CurDevNN = 0; | 303 | ANetNode * NN, * CurDevNN = 0; |
304 | long NoOfDevs; | 304 | long NoOfDevs; |
305 | long DevCtStart; | 305 | long DevCtStart; |
306 | bool needToGenerate; | 306 | bool needToGenerate; |
307 | 307 | ||
308 | // regenerate system files | 308 | // regenerate system files |
309 | Log( ( "Generating settings from %s\n", CfgFile.latin1() )); | 309 | Log( ( "Generating settings from %s\n", CfgFile.latin1() )); |
310 | 310 | ||
311 | for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); | 311 | for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); |
312 | nnit.current(); | 312 | nnit.current(); |
313 | ++nnit ) { | 313 | ++nnit ) { |
314 | bool FirstItem = 1; | 314 | bool FirstItem = 1; |
315 | bool Generated = 0; | 315 | bool Generated = 0; |
316 | 316 | ||
317 | CurDevNN = nnit.current(); | 317 | CurDevNN = nnit.current(); |
318 | 318 | ||
319 | { QStringList SL; | 319 | { QStringList SL; |
320 | SL = CurDevNN->properFiles(); | 320 | SL = CurDevNN->properFiles(); |
321 | 321 | ||
322 | for ( QStringList::Iterator it = SL.begin(); | 322 | for ( QStringList::Iterator it = SL.begin(); |
323 | it != SL.end(); | 323 | it != SL.end(); |
324 | ++it ) { | 324 | ++it ) { |
325 | 325 | ||
326 | Generated = 0; | 326 | Generated = 0; |
327 | FirstItem = 1; | 327 | FirstItem = 1; |
328 | // iterate over NNI's of this class | 328 | // iterate over NNI's of this class |
329 | for( QDictIterator<ANetNodeInstance> nniit( | 329 | for( QDictIterator<ANetNodeInstance> nniit( |
330 | NSResources->netNodeInstances() ); | 330 | NSResources->netNodeInstances() ); |
331 | nniit.current(); | 331 | nniit.current(); |
332 | ++nniit ) { | 332 | ++nniit ) { |
333 | if( nniit.current()->nodeClass() != CurDevNN ) | 333 | if( nniit.current()->nodeClass() != CurDevNN ) |
334 | // different class | 334 | // different class |
335 | continue; | 335 | continue; |
336 | 336 | ||
337 | // open proper file | 337 | // open proper file |
338 | { SystemFile SF( (*it) ); | 338 | { SystemFile SF( (*it) ); |
339 | 339 | ||
340 | if( ! CurDevNN->openFile( SF, nniit.current()) ) { | 340 | if( ! CurDevNN->openFile( SF, nniit.current()) ) { |
341 | // cannot open | 341 | // cannot open |
342 | S = qApp->translate( "NetworkSettings", | 342 | S = qApp->translate( "NetworkSettings", |
343 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). | 343 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). |
344 | arg( (*it) ).arg( CurDevNN->name() ); | 344 | arg( (*it) ).arg( CurDevNN->name() ); |
345 | return S; | 345 | return S; |
346 | } | 346 | } |
347 | 347 | ||
348 | if( ! SF.open() ) { | 348 | if( ! SF.open() ) { |
349 | S = qApp->translate( "NetworkSettings", | 349 | S = qApp->translate( "NetworkSettings", |
350 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). | 350 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). |
351 | arg( (*it) ).arg( CurDevNN->name() ); | 351 | arg( (*it) ).arg( CurDevNN->name() ); |
352 | return S; | 352 | return S; |
353 | } | 353 | } |
354 | 354 | ||
355 | // preamble on first | 355 | // preamble on first |
356 | if( FirstItem ) { | 356 | if( FirstItem ) { |
357 | if( CurDevNN->generatePreamble( SF ) == 2 ) { | 357 | if( CurDevNN->generatePreamble( SF ) == 2 ) { |
358 | S = qApp->translate( "NetworkSettings", | 358 | S = qApp->translate( "NetworkSettings", |
359 | "<p>Error in section \"preamble\" for proper file \"%1\" and node \"%2\"</p>" ). | 359 | "<p>Error in section \"preamble\" for proper file \"%1\" and node \"%2\"</p>" ). |
360 | arg( (*it) ). | 360 | arg( (*it) ). |
361 | arg( CurDevNN->name() ); | 361 | arg( CurDevNN->name() ); |
362 | return S; | 362 | return S; |
363 | } | 363 | } |
364 | } | 364 | } |
365 | FirstItem = 0; | 365 | FirstItem = 0; |
366 | Generated = 1; | 366 | Generated = 1; |
367 | 367 | ||
368 | // item specific | 368 | // item specific |
369 | if( nniit.current()->generateFile( SF, -1 ) == 2 ) { | 369 | if( nniit.current()->generateFile( SF, -1 ) == 2 ) { |
370 | S = qApp->translate( "NetworkSettings", | 370 | S = qApp->translate( "NetworkSettings", |
371 | "<p>Error in section for node \"%1\" for proper file \"%2\" and node class \"%3\"</p>" ). | 371 | "<p>Error in section for node \"%1\" for proper file \"%2\" and node class \"%3\"</p>" ). |
372 | arg( nniit.current()->name() ). | 372 | arg( nniit.current()->name() ). |
373 | arg( (*it) ). | 373 | arg( (*it) ). |
374 | arg( CurDevNN->name() ); | 374 | arg( CurDevNN->name() ); |
375 | return S; | 375 | return S; |
376 | } | 376 | } |
377 | } | 377 | } |
378 | } | 378 | } |
379 | 379 | ||
380 | if( Generated ) { | 380 | if( Generated ) { |
381 | SystemFile SF( (*it) ); | 381 | SystemFile SF( (*it) ); |
382 | 382 | ||
383 | if( CurDevNN->openFile( SF, 0 ) && | 383 | if( CurDevNN->openFile( SF, 0 ) && |
384 | ! SF.path().isEmpty() | 384 | ! SF.path().isEmpty() |
385 | ) { | 385 | ) { |
386 | 386 | ||
387 | if( ! SF.open() ) { | 387 | if( ! SF.open() ) { |
388 | S = qApp->translate( "NetworkSettings", | 388 | S = qApp->translate( "NetworkSettings", |
389 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). | 389 | "<p>Cannot open proper file \"%1\" for node \"%2\"</p>" ). |
390 | arg( (*it) ).arg( CurDevNN->name() ); | 390 | arg( (*it) ).arg( CurDevNN->name() ); |
391 | return S; | 391 | return S; |
392 | } | 392 | } |
393 | 393 | ||
394 | if( CurDevNN->generatePostamble( SF ) == 2 ) { | 394 | if( CurDevNN->generatePostamble( SF ) == 2 ) { |
395 | S = qApp->translate( "NetworkSettings", | 395 | S = qApp->translate( "NetworkSettings", |
396 | "<p>Error in section \"postamble\" for proper file \"%1\" and node \"%2\"</p>" ). | 396 | "<p>Error in section \"postamble\" for proper file \"%1\" and node \"%2\"</p>" ). |
397 | arg( (*it) ). | 397 | arg( (*it) ). |
398 | arg( CurDevNN->name() ); | 398 | arg( CurDevNN->name() ); |
399 | return S; | 399 | return S; |
400 | } | 400 | } |
401 | } // no postamble | 401 | } // no postamble |
402 | } | 402 | } |
403 | } | 403 | } |
404 | } | 404 | } |
405 | } | 405 | } |
406 | 406 | ||
407 | // | 407 | // |
408 | // generate all registered files | 408 | // generate all registered files |
409 | // | 409 | // |
410 | for( QDictIterator<SystemFile> sfit(SFM); | 410 | for( QDictIterator<SystemFile> sfit(SFM); |
411 | sfit.current(); | 411 | sfit.current(); |
412 | ++sfit ) { | 412 | ++sfit ) { |
413 | SystemFile * SF; | 413 | SystemFile * SF; |
414 | 414 | ||
415 | SF = sfit.current(); | 415 | SF = sfit.current(); |
416 | 416 | ||
417 | // reset all | 417 | // reset all |
418 | for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); | 418 | for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); |
419 | nnit.current(); | 419 | nnit.current(); |
420 | ++nnit ) { | 420 | ++nnit ) { |
421 | nnit.current()->setDone(0); | 421 | nnit.current()->setDone(0); |
422 | } | 422 | } |
423 | 423 | ||
424 | for( QDictIterator<ANetNodeInstance> nniit( | 424 | for( QDictIterator<ANetNodeInstance> nniit( |
425 | NSResources->netNodeInstances() ); | 425 | NSResources->netNodeInstances() ); |
426 | nniit.current(); | 426 | nniit.current(); |
427 | ++nniit ) { | 427 | ++nniit ) { |
428 | nniit.current()->setDone(0); | 428 | nniit.current()->setDone(0); |
429 | } | 429 | } |
430 | 430 | ||
431 | for( QDictIterator<NetworkSetup> ncit(M); | 431 | for( QDictIterator<NetworkSetup> ncit(M); |
432 | ncit.current(); | 432 | ncit.current(); |
433 | ++ncit ) { | 433 | ++ncit ) { |
434 | ncit.current()->setDone(0); | 434 | ncit.current()->setDone(0); |
435 | } | 435 | } |
436 | 436 | ||
437 | Log( ( "Generating system file %s\n", SF->name().latin1() )); | 437 | Log( ( "Generating system file %s\n", SF->name().latin1() )); |
438 | 438 | ||
439 | needToGenerate = 0; | 439 | needToGenerate = 0; |
440 | 440 | ||
441 | // are there netnodes that have instances and need | 441 | // are there netnodes that have instances and need |
442 | // to write data in this system file ? | 442 | // to write data in this system file ? |
443 | for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); | 443 | for( QDictIterator<ANetNode> nnit( NSResources->netNodes() ); |
444 | ! needToGenerate && nnit.current(); | 444 | ! needToGenerate && nnit.current(); |
445 | ++nnit ) { | 445 | ++nnit ) { |
446 | 446 | ||
447 | NN = nnit.current(); | 447 | NN = nnit.current(); |
448 | 448 | ||
449 | if( NN->hasDataForFile( *SF ) ) { | 449 | if( NN->hasDataForFile( *SF ) ) { |
450 | // netnode can have data | 450 | // netnode can have data |
451 | 451 | ||
452 | // are there instances of this node ? | 452 | // are there instances of this node ? |
453 | for( QDictIterator<ANetNodeInstance> nniit( | 453 | for( QDictIterator<ANetNodeInstance> nniit( |
454 | NSResources->netNodeInstances() ); | 454 | NSResources->netNodeInstances() ); |
455 | ! needToGenerate && nniit.current(); | 455 | ! needToGenerate && nniit.current(); |
456 | ++nniit ) { | 456 | ++nniit ) { |
457 | if( nniit.current()->nodeClass() == NN ) { | 457 | if( nniit.current()->nodeClass() == NN ) { |
458 | // yes | 458 | // yes |
459 | Log(("Node %s has data\n", | 459 | Log(("Node %s has data\n", |
460 | nniit.current()->name() )); | 460 | nniit.current()->name() )); |
461 | needToGenerate = 1; | 461 | needToGenerate = 1; |
462 | break; | 462 | break; |
463 | } | 463 | } |
464 | } | 464 | } |
465 | } | 465 | } |
466 | } | 466 | } |
467 | 467 | ||
468 | if( ! needToGenerate ) { | 468 | if( ! needToGenerate ) { |
469 | // no instances found that might need to write data | 469 | // no instances found that might need to write data |
470 | // in this systemfile | 470 | // in this systemfile |
471 | Log(("No nodes for systemfile %s\n", SF->name().latin1() )); | 471 | Log(("No nodes for systemfile %s\n", SF->name().latin1() )); |
472 | continue; | 472 | continue; |
473 | } | 473 | } |
474 | 474 | ||
475 | // ok generate this system file | 475 | // ok generate this system file |
476 | if( ! SF->open() ) { | 476 | if( ! SF->open() ) { |
477 | S = qApp->translate( "NetworkSettings", | 477 | S = qApp->translate( "NetworkSettings", |
478 | "<p>Cannot open system file \"%1\"</p>" ). | 478 | "<p>Cannot open system file \"%1\"</p>" ). |
479 | arg( SF->name() ); | 479 | arg( SF->name() ); |
480 | return S; | 480 | return S; |
481 | } | 481 | } |
482 | 482 | ||
483 | // global presection for this system file | 483 | // global presection for this system file |
484 | if( ! SF->preSection() ) { | 484 | if( ! SF->preSection() ) { |
485 | S = qApp->translate( "NetworkSettings", | 485 | S = qApp->translate( "NetworkSettings", |
486 | "<p>Error in section \"Preamble\" for file \"%1\"</p>" ). | 486 | "<p>Error in section \"Preamble\" for file \"%1\"</p>" ). |
487 | arg( SF->name() ); | 487 | arg( SF->name() ); |
488 | return S; | 488 | return S; |
489 | } | 489 | } |
490 | 490 | ||
491 | // find NetworkSetups that want to write to this file | 491 | // find NetworkSetups that want to write to this file |
492 | for( QDictIterator<NetworkSetup> ncit(M); | 492 | for( QDictIterator<NetworkSetup> ncit(M); |
493 | ncit.current(); | 493 | ncit.current(); |
494 | ++ncit ) { | 494 | ++ncit ) { |
495 | 495 | ||
496 | NC = ncit.current(); | 496 | NC = ncit.current(); |
497 | 497 | ||
498 | if( NC->done() ) { | 498 | if( NC->done() ) { |
499 | // already done | 499 | // already done |
500 | continue; | 500 | continue; |
501 | } | 501 | } |
502 | 502 | ||
503 | if( ! NC->hasDataForFile( *SF ) ) { | 503 | if( ! NC->hasDataForFile( *SF ) ) { |
504 | // no data | 504 | // no data |
505 | continue; | 505 | continue; |
506 | } | 506 | } |
507 | 507 | ||
508 | Log(("Generating %s for NetworkSetup %s\n", | 508 | Log(("Generating %s for NetworkSetup %s\n", |
509 | SF->name().latin1(), NC->name().latin1() )); | 509 | SF->name().latin1(), NC->name().latin1() )); |
510 | // find highest item that wants to write data to this file | 510 | // find highest item that wants to write data to this file |
511 | FirstWithData = NC->firstWithDataForFile( *SF ); | 511 | FirstWithData = NC->firstWithDataForFile( *SF ); |
512 | 512 | ||
513 | // find device on which this NetworkSetup works | 513 | // find device on which this NetworkSetup works |
514 | CurDev = NC->device(); | 514 | CurDev = NC->device(); |
515 | // class of that node | 515 | // class of that node |
516 | CurDevNN = CurDev->netNode()->nodeClass(); | 516 | CurDevNN = CurDev->netNode()->nodeClass(); |
517 | 517 | ||
518 | if( ! FirstWithData->nodeClass()->done() ) { | 518 | if( ! FirstWithData->nodeClass()->done() ) { |
519 | // generate fixed part | 519 | // generate fixed part |
520 | if( ! SF->preDeviceSection( CurDevNN ) ) { | 520 | if( ! SF->preDeviceSection( CurDevNN ) ) { |
521 | S = qApp->translate( "NetworkSettings", | 521 | S = qApp->translate( "NetworkSettings", |
522 | "<p>Error in section \"Pre-Device\" for file \"%1\"</p>" ). | 522 | "<p>Error in section \"Pre-Device\" for file \"%1\"</p>" ). |
523 | arg( SF->name() ); | 523 | arg( SF->name() ); |
524 | return S; | 524 | return S; |
525 | } | 525 | } |
526 | 526 | ||
527 | if( FirstWithData->nodeClass()->generateFile( | 527 | if( FirstWithData->nodeClass()->generateFile( |
528 | *SF, | 528 | *SF, |
529 | FirstWithData, | 529 | FirstWithData, |
530 | -2 ) == 2 ) { | 530 | -2 ) == 2 ) { |
531 | S = qApp->translate( "NetworkSettings", | 531 | S = qApp->translate( "NetworkSettings", |
532 | "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ). | 532 | "<p>Error in section \"Common\" for file \"%1\" and node \"%2\"</p>" ). |
533 | arg( SF->name() ). | 533 | arg( SF->name() ). |
534 | arg( CurDevNN->name() ); | 534 | arg( CurDevNN->name() ); |
535 | return S; | 535 | return S; |
536 | } | 536 | } |
537 | FirstWithData->nodeClass()->setDone( 1 ); | 537 | FirstWithData->nodeClass()->setDone( 1 ); |
538 | Log(( "Systemfile %s for node instance %s is done\n", | 538 | Log(( "Systemfile %s for node instance %s is done\n", |
539 | SF->name().latin1(), | 539 | SF->name().latin1(), |
540 | FirstWithData->name() )); | 540 | FirstWithData->name() )); |
541 | } | 541 | } |
542 | 542 | ||
543 | NoOfDevs = 0; | 543 | NoOfDevs = 0; |
544 | DevCtStart = -1; | 544 | DevCtStart = -1; |
545 | 545 | ||
546 | if( SF->knowsDeviceInstances() ) { | 546 | if( SF->knowsDeviceInstances() ) { |
547 | DevCtStart = 0; | 547 | DevCtStart = 0; |
548 | NoOfDevs = CurDevNN->instanceCount(); | 548 | NoOfDevs = CurDevNN->instanceCount(); |
549 | } | 549 | } |
550 | 550 | ||
551 | if( ! CurDev->netNode()->nodeClass()->done() ) { | 551 | if( ! CurDev->netNode()->nodeClass()->done() ) { |
552 | // first time this device is handled | 552 | // first time this device is handled |
553 | // generate common device specific part | 553 | // generate common device specific part |
554 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { | 554 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { |
555 | 555 | ||
556 | if( FirstWithData->nodeClass()->generateFile( | 556 | if( FirstWithData->nodeClass()->generateFile( |
557 | *SF, CurDev->netNode(), i ) == 2 ) { | 557 | *SF, CurDev->netNode(), i ) == 2 ) { |
558 | S = qApp->translate( "NetworkSettings", | 558 | S = qApp->translate( "NetworkSettings", |
559 | "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ). | 559 | "<p>Error in section \"Device\" for file \"%1\" and node \"%2\"</p>" ). |
560 | arg( SF->name() ). | 560 | arg( SF->name() ). |
561 | arg( CurDevNN->name() ); | 561 | arg( CurDevNN->name() ); |
562 | return S; | 562 | return S; |
563 | } | 563 | } |
564 | } | 564 | } |
565 | CurDev->netNode()->nodeClass()->setDone( 1 ); | 565 | CurDev->netNode()->nodeClass()->setDone( 1 ); |
566 | 566 | ||
567 | Log(( "Systemfile %s for Nodeclass %s is done\n", | 567 | Log(( "Systemfile %s for Nodeclass %s is done\n", |
568 | SF->name().latin1(), | 568 | SF->name().latin1(), |
569 | CurDev->netNode()->nodeClass()->name() | 569 | CurDev->netNode()->nodeClass()->name() |
570 | )); | 570 | )); |
571 | } | 571 | } |
572 | 572 | ||
573 | // generate profile specific info | 573 | // generate profile specific info |
574 | // for all nodeNetworkSetups that work on the same device | 574 | // for all nodeNetworkSetups that work on the same device |
575 | for( QDictIterator<NetworkSetup> ncit2(M); | 575 | for( QDictIterator<NetworkSetup> ncit2(M); |
576 | ncit2.current(); | 576 | ncit2.current(); |
577 | ++ncit2 ) { | 577 | ++ncit2 ) { |
578 | 578 | ||
579 | if( ncit2.current()->device() != CurDev ) { | 579 | if( ncit2.current()->device() != CurDev ) { |
580 | // different device | 580 | // different device |
581 | continue; | 581 | continue; |
582 | } | 582 | } |
583 | 583 | ||
584 | Log(("NetworkSetup %s of family %s\n", | 584 | Log(("NetworkSetup %s of family %s\n", |
585 | ncit2.current()->name().latin1(), | 585 | ncit2.current()->name().latin1(), |
586 | CurDev->name() )); | 586 | CurDev->name() )); |
587 | // generate | 587 | // generate |
588 | NNI = ncit2.current()->firstWithDataForFile( *SF ); | 588 | NNI = ncit2.current()->firstWithDataForFile( *SF ); |
589 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { | 589 | for( int i = DevCtStart; i < NoOfDevs ; i ++ ) { |
590 | if( ! SF->preNodeSection( NNI, i ) ) { | 590 | if( ! SF->preNodeSection( NNI, i ) ) { |
591 | S = qApp->translate( "NetworkSettings", | 591 | S = qApp->translate( "NetworkSettings", |
592 | "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). | 592 | "<p>Error in \"Pre-Node Part\" for file \"%1\" and node \"%2\"</p>" ). |
593 | arg( SF->name() ). | 593 | arg( SF->name() ). |
594 | arg( CurDevNN->name() ); | 594 | arg( CurDevNN->name() ); |
595 | return S; | 595 | return S; |
596 | } | 596 | } |
597 | 597 | ||
598 | switch( NNI->generateFile( *SF, i ) ) { | 598 | switch( NNI->generateFile( *SF, i ) ) { |
599 | case 0 : | 599 | case 0 : |
600 | (*SF) << endl; | 600 | (*SF) << endl; |
601 | break; | 601 | break; |
602 | case 1 : | 602 | case 1 : |
603 | break; | 603 | break; |
604 | case 2 : | 604 | case 2 : |
605 | S = qApp->translate( "NetworkSettings", | 605 | S = qApp->translate( "NetworkSettings", |
606 | "<p>Error in section \"Node\" for file \"%1\" and node \"%2\"</p>" ). | 606 | "<p>Error in section \"Node\" for file \"%1\" and node \"%2\"</p>" ). |
607 | arg( SF->name() ). | 607 | arg( SF->name() ). |
608 | arg( CurDevNN->name() ); | 608 | arg( CurDevNN->name() ); |
609 | return S; | 609 | return S; |
610 | } | 610 | } |
611 | 611 | ||
612 | if( ! SF->postNodeSection( NNI, i ) ) { | 612 | if( ! SF->postNodeSection( NNI, i ) ) { |
613 | S = qApp->translate( "NetworkSettings", | 613 | S = qApp->translate( "NetworkSettings", |
614 | "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). | 614 | "<p>Error in \"Post-Node Part\" for file \"%1\" and node \"%2\"</p>" ). |
615 | arg( SF->name() ). | 615 | arg( SF->name() ). |
616 | arg( CurDevNN->name() ); | 616 | arg( CurDevNN->name() ); |
617 | return S; | 617 | return S; |
618 | } | 618 | } |
619 | } | 619 | } |
620 | 620 | ||
621 | ncit2.current()->setDone( 1 ); | 621 | ncit2.current()->setDone( 1 ); |
622 | 622 | ||
623 | } | 623 | } |
624 | } | 624 | } |
625 | 625 | ||
626 | if( ! SF->postDeviceSection( CurDevNN ) ) { | 626 | if( ! SF->postDeviceSection( CurDevNN ) ) { |
627 | S = qApp->translate( "NetworkSettings", | 627 | S = qApp->translate( "NetworkSettings", |
628 | "<p>Error in section \"Post-Device\" for file \"%1\" and node \"%2\"</p>" ). | 628 | "<p>Error in section \"Post-Device\" for file \"%1\" and node \"%2\"</p>" ). |
629 | arg( SF->name() ). | 629 | arg( SF->name() ). |
630 | arg( CurDevNN->name() ); | 630 | arg( CurDevNN->name() ); |
631 | return S; | 631 | return S; |
632 | } | 632 | } |
633 | 633 | ||
634 | 634 | ||
635 | if( ! SF->postSection() ) { | 635 | if( ! SF->postSection() ) { |
636 | S = qApp->translate( "NetworkSettings", | 636 | S = qApp->translate( "NetworkSettings", |
637 | "<p>Error in section \"Closure\" for file \"%1\"</p>" ). | 637 | "<p>Error in section \"Closure\" for file \"%1\"</p>" ). |
638 | arg( SF->name() ); | 638 | arg( SF->name() ); |
639 | return S; | 639 | return S; |
640 | } | 640 | } |
641 | 641 | ||
642 | // end of file | 642 | // end of file |
643 | SF->close(); | 643 | SF->close(); |
644 | } | 644 | } |
645 | return S; | 645 | return S; |
646 | } | 646 | } |
647 | 647 | ||
648 | QList<NetworkSetup> NetworkSettingsData::collectPossible( | 648 | QList<NetworkSetup> NetworkSettingsData::collectPossible( |
649 | const QString & Interface ) { | 649 | const QString & Interface ) { |
650 | // collect NetworkSetups that can work on top of this interface | 650 | // collect NetworkSetups that can work on top of this interface |
651 | NetworkSetup * NC; | 651 | NetworkSetup * NC; |
652 | QList<NetworkSetup> PossibleNetworkSetups; | 652 | QList<NetworkSetup> PossibleNetworkSetups; |
653 | Name2NetworkSetup_t & M = NSResources->networkSetups(); | 653 | Name2NetworkSetup_t & M = NSResources->networkSetups(); |
654 | 654 | ||
655 | // for all NetworkSetups | 655 | // for all NetworkSetups |
656 | for( QDictIterator<NetworkSetup> it(M); | 656 | for( QDictIterator<NetworkSetup> it(M); |
657 | it.current(); | 657 | it.current(); |
658 | ++it ) { | 658 | ++it ) { |
659 | NC = it.current(); | 659 | NC = it.current(); |
660 | // check if this profile handles the requested interface | 660 | // check if this profile handles the requested interface |
661 | if( NC->handlesInterface( Interface ) && // if different Intf. | 661 | if( NC->handlesInterface( Interface ) && // if different Intf. |
662 | NC->state() != Disabled && // if enabled | 662 | NC->state() != Disabled && // if enabled |
663 | NC->state() != IsUp // if already used | 663 | NC->state() != IsUp // if already used |
664 | ) { | 664 | ) { |
665 | Log( ( "Append %s for %s\n", | 665 | Log( ( "Append %s for %s\n", |
666 | NC->name().latin1(), Interface.latin1() )); | 666 | NC->name().latin1(), Interface.latin1() )); |
667 | PossibleNetworkSetups.append( NC ); | 667 | PossibleNetworkSetups.append( NC ); |
668 | } | 668 | } |
669 | } | 669 | } |
670 | return PossibleNetworkSetups; | 670 | return PossibleNetworkSetups; |
671 | } | 671 | } |
672 | 672 | ||
673 | 673 | ||
674 | /* | 674 | /* |
675 | Called by the system to see if interface can be brought UP | 675 | Called by the system to see if interface can be brought UP |
676 | 676 | ||
677 | if allowed, echo Interface-allowed else Interface-disallowed | 677 | if allowed, echo Interface-allowed else Interface-disallowed |
678 | */ | 678 | */ |
679 | 679 | ||
680 | bool NetworkSettingsData::canStart( const QString & Interface ) { | 680 | bool NetworkSettingsData::canStart( const QString & Interface ) { |
681 | // load situation | 681 | // load situation |
682 | NetworkSetup * NC = 0; | 682 | NetworkSetup * NC = 0; |
683 | QList<NetworkSetup> PossibleNetworkSetups; | 683 | QList<NetworkSetup> PossibleNetworkSetups; |
684 | 684 | ||
685 | PossibleNetworkSetups = collectPossible( Interface ); | 685 | PossibleNetworkSetups = collectPossible( Interface ); |
686 | 686 | ||
687 | Log( ( "for %s : Possiblilies %d\n", | 687 | Log( ( "for %s : Possiblilies %d\n", |
688 | Interface.latin1(), PossibleNetworkSetups.count() )); | 688 | Interface.latin1(), PossibleNetworkSetups.count() )); |
689 | switch( PossibleNetworkSetups.count() ) { | 689 | switch( PossibleNetworkSetups.count() ) { |
690 | case 0 : // no NetworkSetups | 690 | case 0 : // no NetworkSetups |
691 | break; | 691 | break; |
692 | case 1 : // one NetworkSetup | 692 | case 1 : // one NetworkSetup |
693 | NC = PossibleNetworkSetups.first(); | 693 | NC = PossibleNetworkSetups.first(); |
694 | break; | 694 | break; |
695 | default : // need to ask user ? | 695 | default : // need to ask user ? |
696 | return 1; | 696 | return 1; |
697 | } | 697 | } |
698 | 698 | ||
699 | if( NC ) { | 699 | if( NC ) { |
700 | switch( NC->state() ) { | 700 | switch( NC->state() ) { |
701 | case Unchecked : | 701 | case Unchecked : |
702 | case Unknown : | 702 | case Unknown : |
703 | case Unavailable : | 703 | case Unavailable : |
704 | case Disabled : | 704 | case Disabled : |
705 | // this profile does not allow interface to be UP | 705 | // this profile does not allow interface to be UP |
706 | // -> try others | 706 | // -> try others |
707 | break; | 707 | break; |
708 | case Off : | 708 | case Off : |
709 | // try to UP the device | 709 | // try to UP the device |
710 | { QString S= NC->setState( Activate ); | 710 | { QString S= NC->setState( Activate ); |
711 | if( ! S.isEmpty() ) { | 711 | if( ! S.isEmpty() ) { |
712 | // could not bring device Online -> try other alters | 712 | // could not bring device Online -> try other alters |
713 | Log(( "disallow %ld for %s : %s\n", | 713 | Log(( "disallow %ld for %s : %s\n", |
714 | NC->number(), Interface.latin1(), S.latin1() )); | 714 | NC->number(), Interface.latin1(), S.latin1() )); |
715 | break; | 715 | break; |
716 | } | 716 | } |
717 | // interface assigned | 717 | // interface assigned |
718 | } | 718 | } |
719 | // FT | 719 | // FT |
720 | case Available : | 720 | case Available : |
721 | case IsUp : // also called for 'ifdown' | 721 | case IsUp : // also called for 'ifdown' |
722 | // device is ready -> done | 722 | // device is ready -> done |
723 | Log(( "allow %ld for %s\n", NC->number(), Interface.latin1())); | 723 | Log(( "allow %ld for %s\n", NC->number(), Interface.latin1())); |
724 | printf( "A%ld%s\n", NC->number(), Interface.latin1() ); | 724 | printf( "A%d%s\n", NC->number(), Interface.latin1() ); |
725 | return 0; | 725 | return 0; |
726 | } | 726 | } |
727 | } | 727 | } |
728 | 728 | ||
729 | // if we come here no alternatives are possible | 729 | // if we come here no alternatives are possible |
730 | Log(( "disallow %s\n", Interface.latin1())); | 730 | Log(( "disallow %s\n", Interface.latin1())); |
731 | printf( "D-%s\n", Interface.latin1() ); | 731 | printf( "D-%s\n", Interface.latin1() ); |
732 | return 0; | 732 | return 0; |
733 | } | 733 | } |
734 | 734 | ||
735 | bool NetworkSettingsData::isModified( void ) { | 735 | bool NetworkSettingsData::isModified( void ) { |
736 | if( ForceModified ) | 736 | if( ForceModified ) |
737 | return 1; | 737 | return 1; |
738 | 738 | ||
739 | for( QDictIterator<NetworkSetup> it(NSResources->networkSetups()); | 739 | for( QDictIterator<NetworkSetup> it(NSResources->networkSetups()); |
740 | it.current(); | 740 | it.current(); |
741 | ++it ) { | 741 | ++it ) { |
742 | if( it.current()->isModified() ) { | 742 | if( it.current()->isModified() ) { |
743 | return 1; | 743 | return 1; |
744 | } | 744 | } |
745 | } | 745 | } |
746 | return 0; | 746 | return 0; |
747 | } | 747 | } |
748 | 748 | ||
749 | bool NetworkSettingsData::couldBeTriggered( const QString & Interface ) { | 749 | bool NetworkSettingsData::couldBeTriggered( const QString & Interface ) { |
750 | // load situation | 750 | // load situation |
751 | QList<NetworkSetup> PossibleTriggered; | 751 | QList<NetworkSetup> PossibleTriggered; |
752 | 752 | ||
753 | PossibleTriggered = collectTriggered( Interface ); | 753 | PossibleTriggered = collectTriggered( Interface ); |
754 | 754 | ||
755 | Log( ( "for %s : Possiblilies %d\n", | 755 | Log( ( "for %s : Possiblilies %d\n", |
756 | Interface.latin1(), PossibleTriggered.count() )); | 756 | Interface.latin1(), PossibleTriggered.count() )); |
757 | 757 | ||
758 | return ( PossibleTriggered.count() ) ? 1 : 0; | 758 | return ( PossibleTriggered.count() ) ? 1 : 0; |
759 | } | 759 | } |
760 | 760 | ||
761 | QList<NetworkSetup> NetworkSettingsData::collectTriggered( | 761 | QList<NetworkSetup> NetworkSettingsData::collectTriggered( |
762 | const QString & Interface ) { | 762 | const QString & Interface ) { |
763 | 763 | ||
764 | // collect NetworkSetups that could be triggered by this interface | 764 | // collect NetworkSetups that could be triggered by this interface |
765 | NetworkSetup * NC; | 765 | NetworkSetup * NC; |
766 | QList<NetworkSetup> PossibleTriggered; | 766 | QList<NetworkSetup> PossibleTriggered; |
767 | 767 | ||
768 | // for all NetworkSetups | 768 | // for all NetworkSetups |
769 | Name2NetworkSetup_t & M = NSResources->networkSetups(); | 769 | Name2NetworkSetup_t & M = NSResources->networkSetups(); |
770 | 770 | ||
771 | for( QDictIterator<NetworkSetup> it(M); | 771 | for( QDictIterator<NetworkSetup> it(M); |
772 | it.current(); | 772 | it.current(); |
773 | ++it ) { | 773 | ++it ) { |
774 | NC = it.current(); | 774 | NC = it.current(); |
775 | // check if this profile handles the requested interface | 775 | // check if this profile handles the requested interface |
776 | if( NC->triggeredBy( Interface ) && // if different Intf. | 776 | if( NC->triggeredBy( Interface ) && // if different Intf. |
777 | NC->state() != Disabled && // if enabled | 777 | NC->state() != Disabled && // if enabled |
778 | NC->state() != IsUp // if already used | 778 | NC->state() != IsUp // if already used |
779 | ) { | 779 | ) { |
780 | Log( ( "Append %s for %s\n", | 780 | Log( ( "Append %s for %s\n", |
781 | NC->name().latin1(), Interface.latin1() )); | 781 | NC->name().latin1(), Interface.latin1() )); |
782 | PossibleTriggered.append( NC ); | 782 | PossibleTriggered.append( NC ); |
783 | } | 783 | } |
784 | } | 784 | } |
785 | return PossibleTriggered; | 785 | return PossibleTriggered; |
786 | } | 786 | } |
787 | 787 | ||