summaryrefslogtreecommitdiff
path: root/noncore/settings/networksettings2/networksettings.cpp
Unidiff
Diffstat (limited to 'noncore/settings/networksettings2/networksettings.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/networksettings2/networksettings.cpp277
1 files changed, 161 insertions, 116 deletions
diff --git a/noncore/settings/networksettings2/networksettings.cpp b/noncore/settings/networksettings2/networksettings.cpp
index ce0eabc..a0d4c7c 100644
--- a/noncore/settings/networksettings2/networksettings.cpp
+++ b/noncore/settings/networksettings2/networksettings.cpp
@@ -2,8 +2,12 @@
2#include <unistd.h> 2#include <unistd.h>
3#include <errno.h> 3#include <errno.h>
4 4
5#include <opie2/odebug.h>
6#include <opie2/oledbox.h>
7
5#include <qpe/qpeapplication.h> 8#include <qpe/qpeapplication.h>
6#include <qlistbox.h> 9#include <qlistbox.h>
10#include <qlayout.h>
7#include <qgroupbox.h> 11#include <qgroupbox.h>
8#include <qtimer.h> 12#include <qtimer.h>
9#include <qlistbox.h> 13#include <qlistbox.h>
@@ -15,7 +19,6 @@
15#include <qtoolbutton.h> 19#include <qtoolbutton.h>
16#include <qevent.h> 20#include <qevent.h>
17 21
18#include <asdevice.h>
19#include "networksettings.h" 22#include "networksettings.h"
20#include "netnode.h" 23#include "netnode.h"
21#include "editconnection.h" 24#include "editconnection.h"
@@ -31,13 +34,24 @@ NetworkSettings::NetworkSettings( QWidget *parent,
31 Add_TB->setPixmap( NSResources->getPixmap( "add" ) ); 34 Add_TB->setPixmap( NSResources->getPixmap( "add" ) );
32 Delete_TB->setPixmap( NSResources->getPixmap( "remove" ) ); 35 Delete_TB->setPixmap( NSResources->getPixmap( "remove" ) );
33 CheckState_TB->setPixmap( NSResources->getPixmap( "check" ) ); 36 CheckState_TB->setPixmap( NSResources->getPixmap( "check" ) );
34 Enable_TB->setPixmap( NSResources->getPixmap( "disabled" ) );
35 GenConfig_TB->setPixmap( NSResources->getPixmap( "configure" ) ); 37 GenConfig_TB->setPixmap( NSResources->getPixmap( "configure" ) );
36 38
37 Connect_TB->setPixmap( NSResources->getPixmap( "connected" ) ); 39 Disable_TB->setPixmap( NSResources->getPixmap( "disabled" ) );
38 Disconnect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) ); 40 Up_TB->setPixmap( NSResources->getPixmap( "more" ) );
41 Down_TB->setPixmap( NSResources->getPixmap( "less" ) );
42
43 QVBoxLayout* V = new QVBoxLayout( LED_Frm );
44 QHBoxLayout * H = new QHBoxLayout( 0 );
45 V->addStretch(1);
46 V->addLayout( H );
47 Leds[0] = new OLedBox( red, LED_Frm );
48 H->addWidget( Leds[0], 0, Qt::AlignVCenter );
49 Leds[1] = new OLedBox( red, LED_Frm );
50 H->addWidget( Leds[1], 0, Qt::AlignVCenter );
51 Leds[2] = new OLedBox( red, LED_Frm );
52 H->addWidget( Leds[2], 0, Qt::AlignVCenter );
53 V->addStretch(1);
39 54
40 On_TB->setPixmap( NSResources->getPixmap( "off" ) );
41 55
42 SLOT_ToProfile(); 56 SLOT_ToProfile();
43 57
@@ -72,7 +86,15 @@ NetworkSettings::NetworkSettings( QWidget *parent,
72 } 86 }
73 87
74 connect( &(NSResources->system()), 88 connect( &(NSResources->system()),
75 SIGNAL( lineFromCommand(const QString &) ), 89 SIGNAL( stdoutLine(const QString &) ),
90 this, SLOT( SLOT_CmdMessage(const QString &) ) );
91
92 connect( &(NSResources->system()),
93 SIGNAL( stderrLine(const QString &) ),
94 this, SLOT( SLOT_CmdMessage(const QString &) ) );
95
96 connect( &(NSResources->system()),
97 SIGNAL( processEvent(const QString &) ),
76 this, SLOT( SLOT_CmdMessage(const QString &) ) ); 98 this, SLOT( SLOT_CmdMessage(const QString &) ) );
77 99
78 UpdateTimer->start( 5000 ); 100 UpdateTimer->start( 5000 );
@@ -87,9 +109,13 @@ NetworkSettings::NetworkSettings( QWidget *parent,
87NetworkSettings::~NetworkSettings() { 109NetworkSettings::~NetworkSettings() {
88 QString S; 110 QString S;
89 111
90 if( isModified() ) { 112 owarn << "Dispose NS" << oendl;
113 if( NSD.isModified() ) {
114 owarn << "Modified" << oendl;
91 S = NSD.saveSettings(); 115 S = NSD.saveSettings();
92 if( ! S.isEmpty() ) { 116 if( ! S.isEmpty() ) {
117 S.insert( 0, "<p>" );
118 S.append( "</p>" );
93 // problem saving 119 // problem saving
94 QMessageBox::warning( 120 QMessageBox::warning(
95 0, 121 0,
@@ -97,6 +123,7 @@ NetworkSettings::~NetworkSettings() {
97 } 123 }
98 124
99 SLOT_GenerateConfig(); 125 SLOT_GenerateConfig();
126 NSD.setModified( 0 );
100 } 127 }
101 128
102} 129}
@@ -167,14 +194,13 @@ void NetworkSettings::SLOT_DeleteNode( void ) {
167 1, 0 ) == 1 ) { 194 1, 0 ) == 1 ) {
168 NSResources->removeConnection( LBI->text() ); 195 NSResources->removeConnection( LBI->text() );
169 delete LBI; 196 delete LBI;
170 setModified( 1 ); 197 NSD.setModified( 1 );
171 } 198 }
172} 199}
173 200
174void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { 201void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) {
175 QString OldName = ""; 202 QString OldName = "";
176 203
177 printf( "------------------ Edit NOde\n" );
178 EditConnection EC( this ); 204 EditConnection EC( this );
179 205
180 if( LBI ) { 206 if( LBI ) {
@@ -196,7 +222,6 @@ void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) {
196 // toplevel item -> store 222 // toplevel item -> store
197 NodeCollection * NC = EC.connection(); 223 NodeCollection * NC = EC.connection();
198 if( NC->isModified() ) { 224 if( NC->isModified() ) {
199 setModified( 1 );
200 if( LBI ) { 225 if( LBI ) {
201 if( NC->name() != OldName ) { 226 if( NC->name() != OldName ) {
202 // find if new name is free 227 // find if new name is free
@@ -249,62 +274,55 @@ void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) {
249 274
250 NodeCollection * NC = NSResources->findConnection( LBI->text() ); 275 NodeCollection * NC = NSResources->findConnection( LBI->text() );
251 276
252 // is button possible 277 if( NC->description().isEmpty() ) {
253 bool EnabledPossible, OnPossible, ConnectPossible; 278 Description_LBL->setText( tr( "<<No description>>" ) );
254 // is button On or Off 279 } else {
255 bool DisabledOn, OnOn, ConnectOn; 280 Description_LBL->setText( NC->description() );
281 }
282
283 Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() );
256 284
257 EnabledPossible = OnPossible = ConnectPossible = 1; 285 bool FrmActive = 1;
258 DisabledOn = 1; 286 bool IsEnabled = 1;
259 OnOn = ConnectOn = 0; 287 int leds = 0;
260 288
289 owarn << "State " << NC->state() << oendl;
261 switch( NC->state() ) { 290 switch( NC->state() ) {
262 case Unknown : 291 case Disabled : // no further work
263 // cannot occur here 292 IsEnabled = 0;
293 FrmActive = 0;
294 owarn << "LEds " << leds << oendl;
264 break; 295 break;
296 case Unknown :
265 case Unchecked : 297 case Unchecked :
266 case Unavailable : 298 case Unavailable :
267 // cannot do anything but recheck 299 FrmActive = 0;
268 EnabledPossible = OnPossible = ConnectPossible = 0;
269 break;
270 case Disabled :
271 OnPossible = ConnectPossible = 0;
272 break; 300 break;
273 case Off : 301 case Off :
274 DisabledOn = 0; 302 leds = 1;
275 break; 303 break;
276 case Available : 304 case Available :
277 OnOn = 1; 305 leds = 2;
278 Connect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) );
279 DisabledOn = 0;
280 break; 306 break;
281 case IsUp : 307 case IsUp :
282 OnOn = ConnectOn = 1; 308 leds = 3;
283 Connect_TB->setPixmap( NSResources->getPixmap( "connected" ) );
284 DisabledOn = 0;
285 break; 309 break;
286 } 310 }
287 311
288 if( ! OnOn ) { 312 Disable_TB->setOn( ! IsEnabled );
289 Connect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) ); 313 LED_Frm->setEnabled( FrmActive );
290 }
291
292 // set button state
293 Enable_TB->setEnabled( EnabledPossible );
294 On_TB->setEnabled( OnPossible );
295 Connect_TB->setEnabled( ConnectPossible );
296
297 Enable_TB->setOn( DisabledOn );
298 On_TB->setOn( OnOn );
299 Connect_TB->setOn( ConnectOn );
300 314
301 if( NC->description().isEmpty() ) { 315 for( int i = 0 ; i < leds; i ++ ) {
302 Description_LBL->setText( tr( "<<No description>>" ) ); 316 Leds[i]->setColor( red );
303 } else { 317 Leds[i]->setOn( true );
304 Description_LBL->setText( NC->description() ); 318 }
319 for( int i = leds ; i < 3; i ++ ) {
320 Leds[i]->setColor( red );
321 Leds[i]->setOn( false );
305 } 322 }
306 323
307 Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() ); 324 Up_TB->setEnabled( leds < 3 && leds != 0 );
325 Down_TB->setEnabled( leds > 0 );
308} 326}
309 327
310void NetworkSettings::SLOT_CheckState( void ) { 328void NetworkSettings::SLOT_CheckState( void ) {
@@ -321,42 +339,49 @@ void NetworkSettings::updateProfileState( QListBoxItem * LBI ) {
321} 339}
322 340
323void NetworkSettings::SLOT_GenerateConfig( void ) { 341void NetworkSettings::SLOT_GenerateConfig( void ) {
324 NSD.regenerate(); 342 QString S = NSD.generateSettings();
343 if( ! S.isEmpty() ) {
344 S.insert( 0, "<p>" );
345 S.append( "</p>" );
346 QMessageBox::warning(
347 0,
348 tr( "Generate config" ),
349 S);
350 }
325} 351}
326 352
327void NetworkSettings::SLOT_Enable( void ) { 353void NetworkSettings::SLOT_Disable( bool T ) {
328 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); 354 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
329 QString Msg; 355 QString Msg;
356
330 if ( ! LBI ) 357 if ( ! LBI )
331 return; 358 return;
332 359
333 NodeCollection * NC = 360 NodeCollection * NC = NSResources->findConnection( LBI->text() );
334 NSResources->findConnection( LBI->text() );
335
336 bool rv;
337 switch( NC->state() ) {
338 case Disabled :
339 Msg = tr( "Cannot enable profile" );
340 rv = NC->setState( Enable );
341 break;
342 default :
343 Msg = tr( "Cannot disable profile" );
344 rv = NC->setState( Disable );
345 break;
346 }
347 361
348 if( ! rv ) { 362 owarn << "Prepare to disable" << oendl;
363 Msg = NC->setState( (T) ? Disable : Enable );
364 if( ! Msg.isEmpty() ) {
365 Msg.insert( 0, "<p>" );
366 Msg.append( "</p>" );
349 QMessageBox::warning( 367 QMessageBox::warning(
350 0, 368 0,
351 tr( "Activating profile" ), 369 tr( "Activating profile" ),
352 Msg ); 370 Msg );
353 return; 371 return;
354 } 372 }
373
374 // reload new state
375 NC->state( true );
355 updateProfileState( LBI ); 376 updateProfileState( LBI );
356} 377}
357 378
358void NetworkSettings::SLOT_On( void ) { 379void NetworkSettings::SLOT_Up( void ) {
380 // bring more up
381
359 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); 382 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
383 QString Msg;
384 int led = -1;
360 385
361 if ( ! LBI ) 386 if ( ! LBI )
362 return; 387 return;
@@ -364,33 +389,55 @@ void NetworkSettings::SLOT_On( void ) {
364 NodeCollection * NC = 389 NodeCollection * NC =
365 NSResources->findConnection( LBI->text() ); 390 NSResources->findConnection( LBI->text() );
366 391
367 bool rv;
368 switch( NC->state() ) { 392 switch( NC->state() ) {
369 case Off : 393 case Disabled : // cannot modify this state
370 // activate interface 394 case Unknown : // cannot modify this state
371 rv = NC->setState( Activate ); 395 case Unchecked : // cannot modify this state
396 case Unavailable : // cannot modify this state
397 case IsUp : // highest UP state
398 return;
399 case Off : // -> activate
400 led = 1;
401 Down_TB->setEnabled( true );
402 Log(( "Activate interface %s\n", NC->name().latin1() ));
403 Msg = NC->setState( Activate );
372 break; 404 break;
373 case Available : // deactivate 405 case Available : // -> up
374 case IsUp : // deactivate (will also bring down if needed) 406 led = 2;
375 rv = NC->setState( Deactivate ); 407 Log(( "Bring up interface %s\n", NC->name().latin1() ));
408 Msg = NC->setState( Up );
409 if( Msg.isEmpty() ) {
410 Up_TB->setEnabled( false );
411 }
376 break; 412 break;
377 default : 413 }
378 // others no change
379 return;
380 }
381 414
382 if( ! rv ) { 415 if( ! Msg.isEmpty() ) {
416 Msg.insert( 0, "<p>" );
417 Msg.append( "</p>" );
383 QMessageBox::warning( 418 QMessageBox::warning(
384 0, 419 0,
385 tr( "Activating profile" ), 420 tr( "Increase availability" ),
386 tr( "Cannot enable profile" ) ); 421 Msg );
387 return; 422 return;
388 } 423 }
424
389 updateProfileState( LBI ); 425 updateProfileState( LBI );
426
427 // set color of led we should change
428 if( led > 0 ) {
429 Leds[led]->setColor( blue );
430 Leds[led]->setOn( true );
431 }
432
390} 433}
391 434
392void NetworkSettings::SLOT_Connect( void ) { 435void NetworkSettings::SLOT_Down( void ) {
436 // bring more down
437
393 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); 438 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
439 int led = -1;
440 QString Msg;
394 441
395 if ( ! LBI ) 442 if ( ! LBI )
396 return; 443 return;
@@ -398,59 +445,57 @@ void NetworkSettings::SLOT_Connect( void ) {
398 NodeCollection * NC = 445 NodeCollection * NC =
399 NSResources->findConnection( LBI->text() ); 446 NSResources->findConnection( LBI->text() );
400 447
401 bool rv = 1 ;
402 switch( NC->state() ) { 448 switch( NC->state() ) {
403 case IsUp : 449 case Disabled : // cannot modify this state
404 // down interface 450 case Unknown : // cannot modify this state
405 rv = NC->setState( Down ); 451 case Unchecked : // cannot modify this state
406 break; 452 case Unavailable : // cannot modify this state
407 case Available : 453 case Off : // highest DOWN state
408 // up interface
409 rv = NC->setState( Up );
410 break; 454 break;
411 case Off : 455 case Available : // -> down
412 // activate and bring up 456 led = 0;
413 rv = ( NC->setState( Activate ) && 457 Log(( "Deactivate interface %s\n", NC->name().latin1() ));
414 NC->setState( Up ) ); 458 Msg = NC->setState( Deactivate );
459 Down_TB->setEnabled( false );
415 break; 460 break;
416 default : 461 case IsUp : // highest UP state
417 // others no change 462 led = 1;
463 Up_TB->setEnabled( true );
464 Log(( "Bring down interface %s\n", NC->name().latin1() ));
465 Msg = NC->setState( Down, 1 );
466 if( Msg.isEmpty() ) {
467 // remove 'up' file to make sure
468 unlink ( QString().sprintf( "/tmp/Profile-%d.up", NC->number() ).latin1() );;
469 }
418 break; 470 break;
419 } 471 }
420 472
421 if( ! rv ) { 473 if( ! Msg.isEmpty() ) {
474 Msg.insert( 0, "<p>" );
475 Msg.append( "</p>" );
422 QMessageBox::warning( 476 QMessageBox::warning(
423 0, 477 0,
424 tr( "Activating profile" ), 478 tr( "Decrease availability" ),
425 tr( "Cannot enable profile" ) ); 479 Msg );
426 }
427
428 // we do not update the GUI but wait for the REAL upping of the device
429}
430
431void NetworkSettings::SLOT_Disconnect( void ) {
432 QString S;
433 QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() );
434
435 if ( ! LBI )
436 return; 480 return;
481 }
437 482
438 NodeCollection * NC = 483 updateProfileState( LBI );
439 NSResources->findConnection( LBI->text() );
440 484
441 Log(( "Force interface %s down\n", NC->name().latin1() )); 485 // set color of led we should change
442 NC->setState( Down, 1 ); 486 if( led >= 0 ) {
443 // remove 'up' file to make sure 487 Leds[led]->setColor( blue );
444 S.sprintf( "/tmp/Profile-%d.up", NC->number() ); 488 }
445 unlink( S.latin1() );
446} 489}
447 490
448void NetworkSettings::SLOT_ToMessages( void ) { 491void NetworkSettings::SLOT_ToMessages( void ) {
492 Profiles_LB->hide();
449 Profile_GB->hide(); 493 Profile_GB->hide();
450 Messages_GB->show(); 494 Messages_GB->show();
451} 495}
452 496
453void NetworkSettings::SLOT_ToProfile( void ) { 497void NetworkSettings::SLOT_ToProfile( void ) {
498 Profiles_LB->show();
454 Profile_GB->show(); 499 Profile_GB->show();
455 Messages_GB->hide(); 500 Messages_GB->hide();
456} 501}