Diffstat (limited to 'noncore/settings/networksettings2/networksettings.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/networksettings.cpp | 86 |
1 files changed, 49 insertions, 37 deletions
diff --git a/noncore/settings/networksettings2/networksettings.cpp b/noncore/settings/networksettings2/networksettings.cpp index e1110e2..c3e6572 100644 --- a/noncore/settings/networksettings2/networksettings.cpp +++ b/noncore/settings/networksettings2/networksettings.cpp | |||
@@ -159,54 +159,72 @@ void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { | |||
159 | if( LBI ) { | 159 | if( LBI ) { |
160 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); | 160 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
161 | if( ! NC ) { | 161 | if( ! NC ) { |
162 | return; | 162 | return; |
163 | } | 163 | } |
164 | OldName = NC->name(); | 164 | OldName = NC->name(); |
165 | EC.setConnection( NC ); | 165 | EC.setConnection( NC ); |
166 | } | 166 | } |
167 | 167 | ||
168 | EC.showMaximized(); | 168 | EC.showMaximized(); |
169 | // disable refresh timer | 169 | // disable refresh timer |
170 | UpdateTimer->stop(); | 170 | UpdateTimer->stop(); |
171 | if( EC.exec() == QDialog::Accepted ) { | 171 | // we need to retry |
172 | // toplevel item -> store | 172 | while( 1 ) { |
173 | NodeCollection * NC = EC.connection(); | 173 | if( EC.exec() == QDialog::Accepted ) { |
174 | if( NC->isModified() ) { | 174 | // toplevel item -> store |
175 | setModified( 1 ); | 175 | NodeCollection * NC = EC.connection(); |
176 | if( NC->isModified() ) { | ||
177 | setModified( 1 ); | ||
178 | if( LBI ) { | ||
179 | if( NC->name() != OldName ) { | ||
180 | // find if new name is free | ||
181 | NodeCollection * LCN = NSResources->findConnection( | ||
182 | NC->name() ); | ||
183 | if( LCN ) { | ||
184 | QMessageBox::warning( | ||
185 | 0, | ||
186 | tr( "Generating system configuration" ), | ||
187 | tr( "Name %1 already exists" ).arg(NC->name()) | ||
188 | ); | ||
189 | continue; // restart exec | ||
190 | } // else new name | ||
191 | // new name -> remove item | ||
192 | NSResources->removeConnection( OldName ); | ||
193 | NSResources->addConnection( NC ); | ||
194 | } // else not changed | ||
195 | |||
196 | // must add it here since change will trigger event | ||
197 | Profiles_LB->changeItem( NC->devicePixmap(), | ||
198 | NC->name(), | ||
199 | Profiles_LB->index( LBI ) | ||
200 | ); | ||
201 | } else { | ||
202 | // new item | ||
203 | int ci = Profiles_LB->count(); | ||
204 | NSResources->addConnection( NC ); | ||
205 | NC->setNumber( NC->maxConnectionNumber()+1 ); | ||
206 | Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); | ||
207 | Profiles_LB->setSelected( ci, TRUE ); | ||
208 | } | ||
209 | updateProfileState( LBI ); | ||
210 | } | ||
211 | } else { | ||
212 | // cancelled : reset connection | ||
176 | if( LBI ) { | 213 | if( LBI ) { |
177 | // new name -> remove item | 214 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
178 | NSResources->removeConnection( OldName ); | 215 | NC->reassign(); |
179 | // must add it here since change will trigger event | ||
180 | NSResources->addConnection( NC ); | ||
181 | Profiles_LB->changeItem( NC->devicePixmap(), | ||
182 | NC->name(), | ||
183 | Profiles_LB->index( LBI ) | ||
184 | ); | ||
185 | } else { | ||
186 | // new item | ||
187 | int ci = Profiles_LB->count(); | ||
188 | NSResources->addConnection( NC ); | ||
189 | NC->setNumber( NC->maxConnectionNumber()+1 ); | ||
190 | Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); | ||
191 | Profiles_LB->setSelected( ci, TRUE ); | ||
192 | } | 216 | } |
193 | updateProfileState( LBI ); | ||
194 | } | ||
195 | } else { | ||
196 | // cancelled : reset connection | ||
197 | if( LBI ) { | ||
198 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); | ||
199 | NC->reassign(); | ||
200 | } | 217 | } |
218 | break; | ||
201 | } | 219 | } |
202 | // reenable | 220 | // reenable |
203 | UpdateTimer->start( 5000 ); | 221 | UpdateTimer->start( 5000 ); |
204 | } | 222 | } |
205 | 223 | ||
206 | void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { | 224 | void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { |
207 | if( LBI == 0 ) | 225 | if( LBI == 0 ) |
208 | return; | 226 | return; |
209 | 227 | ||
210 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); | 228 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
211 | 229 | ||
212 | // is button possible | 230 | // is button possible |
@@ -324,83 +342,77 @@ void NetworkSettings::SLOT_On( void ) { | |||
324 | if ( ! LBI ) | 342 | if ( ! LBI ) |
325 | return; | 343 | return; |
326 | 344 | ||
327 | NodeCollection * NC = | 345 | NodeCollection * NC = |
328 | NSResources->findConnection( LBI->text() ); | 346 | NSResources->findConnection( LBI->text() ); |
329 | 347 | ||
330 | bool rv; | 348 | bool rv; |
331 | switch( NC->state() ) { | 349 | switch( NC->state() ) { |
332 | case Off : | 350 | case Off : |
333 | // activate interface | 351 | // activate interface |
334 | rv = NC->setState( Activate ); | 352 | rv = NC->setState( Activate ); |
335 | break; | 353 | break; |
336 | case Available : | 354 | case Available : // deactivate |
337 | // deactivate | 355 | case IsUp : // deactivate (will also bring down if needed) |
338 | rv = NC->setState( Deactivate ); | 356 | rv = NC->setState( Deactivate ); |
339 | break; | 357 | break; |
340 | case IsUp : | ||
341 | // bring down and deactivate | ||
342 | rv = ( NC->setState( Down ) && | ||
343 | NC->setState( Deactivate ) ); | ||
344 | break; | ||
345 | default : | 358 | default : |
346 | // others no change | 359 | // others no change |
347 | return; | 360 | return; |
348 | } | 361 | } |
349 | 362 | ||
350 | if( ! rv ) { | 363 | if( ! rv ) { |
351 | QMessageBox::warning( | 364 | QMessageBox::warning( |
352 | 0, | 365 | 0, |
353 | tr( "Activating profile" ), | 366 | tr( "Activating profile" ), |
354 | tr( "Cannot enable profile" ) ); | 367 | tr( "Cannot enable profile" ) ); |
355 | return; | 368 | return; |
356 | } | 369 | } |
357 | updateProfileState( LBI ); | 370 | updateProfileState( LBI ); |
358 | } | 371 | } |
359 | 372 | ||
360 | void NetworkSettings::SLOT_Connect( void ) { | 373 | void NetworkSettings::SLOT_Connect( void ) { |
361 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 374 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
362 | 375 | ||
363 | if ( ! LBI ) | 376 | if ( ! LBI ) |
364 | return; | 377 | return; |
365 | 378 | ||
366 | NodeCollection * NC = | 379 | NodeCollection * NC = |
367 | NSResources->findConnection( LBI->text() ); | 380 | NSResources->findConnection( LBI->text() ); |
368 | 381 | ||
369 | bool rv; | 382 | bool rv = 1 ; |
370 | switch( NC->state() ) { | 383 | switch( NC->state() ) { |
371 | case IsUp : | 384 | case IsUp : |
372 | // down interface | 385 | // down interface |
373 | rv = NC->setState( Down ); | 386 | rv = NC->setState( Down ); |
374 | break; | 387 | break; |
375 | case Available : | 388 | case Available : |
376 | // up interface | 389 | // up interface |
377 | rv = NC->setState( Up ); | 390 | rv = NC->setState( Up ); |
378 | break; | 391 | break; |
379 | case Off : | 392 | case Off : |
380 | // activate and bring up | 393 | // activate and bring up |
381 | rv = ( NC->setState( Activate ) && | 394 | rv = ( NC->setState( Activate ) && |
382 | NC->setState( Up ) ); | 395 | NC->setState( Up ) ); |
383 | break; | 396 | break; |
384 | default : | 397 | default : |
385 | // others no change | 398 | // others no change |
386 | return; | 399 | break; |
387 | } | 400 | } |
388 | 401 | ||
389 | if( ! rv ) { | 402 | if( ! rv ) { |
390 | QMessageBox::warning( | 403 | QMessageBox::warning( |
391 | 0, | 404 | 0, |
392 | tr( "Activating profile" ), | 405 | tr( "Activating profile" ), |
393 | tr( "Cannot enable profile" ) ); | 406 | tr( "Cannot enable profile" ) ); |
394 | return; | ||
395 | } | 407 | } |
396 | 408 | ||
397 | // we do not update the GUI but wait for the REAL upping of the device | 409 | // we do not update the GUI but wait for the REAL upping of the device |
398 | } | 410 | } |
399 | 411 | ||
400 | void NetworkSettings::SLOT_QCopMessage(const QCString &msg, const QByteArray &data) { | 412 | void NetworkSettings::SLOT_QCopMessage(const QCString &msg, const QByteArray &data) { |
401 | QDataStream stream( data, IO_ReadOnly ); | 413 | QDataStream stream( data, IO_ReadOnly ); |
402 | 414 | ||
403 | if( msg == "raise" ) { | 415 | if( msg == "raise" ) { |
404 | raise(); | 416 | raise(); |
405 | return; | 417 | return; |
406 | } /* if ( msg == "someMessage(int,int,int)" ) { | 418 | } /* if ( msg == "someMessage(int,int,int)" ) { |