Diffstat (limited to 'noncore/settings/networksettings2/networksettings.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/networksettings.cpp | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/noncore/settings/networksettings2/networksettings.cpp b/noncore/settings/networksettings2/networksettings.cpp index b36c7a0..6ee4106 100644 --- a/noncore/settings/networksettings2/networksettings.cpp +++ b/noncore/settings/networksettings2/networksettings.cpp | |||
@@ -1,7 +1,8 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <unistd.h> | ||
2 | 3 | ||
3 | #include <qpe/qpeapplication.h> | 4 | #include <qpe/qpeapplication.h> |
4 | #include <qlistbox.h> | 5 | #include <qlistbox.h> |
5 | #include <qgroupbox.h> | 6 | #include <qgroupbox.h> |
6 | #include <qtimer.h> | 7 | #include <qtimer.h> |
7 | #include <qlistbox.h> | 8 | #include <qlistbox.h> |
@@ -58,12 +59,16 @@ NetworkSettings::NetworkSettings( QWidget *parent, | |||
58 | 59 | ||
59 | // if no profiles -> auto popup editing | 60 | // if no profiles -> auto popup editing |
60 | if( NSResources->connections().count() == 0 ) { | 61 | if( NSResources->connections().count() == 0 ) { |
61 | QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); | 62 | QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); |
62 | } | 63 | } |
63 | 64 | ||
65 | connect( &(NSResources->system()), | ||
66 | SIGNAL( lineFromCommand(const QString &) ), | ||
67 | this, SLOT( SLOT_CmdMessage(const QString &) ) ); | ||
68 | |||
64 | UpdateTimer->start( 5000 ); | 69 | UpdateTimer->start( 5000 ); |
65 | connect( UpdateTimer, SIGNAL( timeout() ), | 70 | connect( UpdateTimer, SIGNAL( timeout() ), |
66 | this, SLOT( SLOT_RefreshStates() ) ); | 71 | this, SLOT( SLOT_RefreshStates() ) ); |
67 | 72 | ||
68 | /* Add QCopChannel */ | 73 | /* Add QCopChannel */ |
69 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), | 74 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), |
@@ -88,12 +93,18 @@ NetworkSettings::~NetworkSettings() { | |||
88 | QMessageBox::warning( | 93 | QMessageBox::warning( |
89 | 0, | 94 | 0, |
90 | tr( "Saving setup" ), S ); | 95 | tr( "Saving setup" ), S ); |
91 | } | 96 | } |
92 | } | 97 | } |
93 | 98 | ||
99 | void NetworkSettings::SLOT_CmdMessage( const QString & S ) { | ||
100 | Messages_LB->insertItem( S ); | ||
101 | Messages_LB->setCurrentItem( Messages_LB->count()-1 ); | ||
102 | Messages_LB->ensureCurrentVisible(); | ||
103 | } | ||
104 | |||
94 | void NetworkSettings::SLOT_RefreshStates( void ) { | 105 | void NetworkSettings::SLOT_RefreshStates( void ) { |
95 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember | 106 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember |
96 | 107 | ||
97 | if( LBI ) { | 108 | if( LBI ) { |
98 | NodeCollection * NC; | 109 | NodeCollection * NC; |
99 | NSResources->system().probeInterfaces(); | 110 | NSResources->system().probeInterfaces(); |
@@ -131,12 +142,15 @@ void NetworkSettings::SLOT_RefreshStates( void ) { | |||
131 | } | 142 | } |
132 | if( ci >= 0 ) | 143 | if( ci >= 0 ) |
133 | Profiles_LB->setCurrentItem( ci ); | 144 | Profiles_LB->setCurrentItem( ci ); |
134 | */ | 145 | */ |
135 | } | 146 | } |
136 | 147 | ||
148 | void NetworkSettings::SLOT_NoLongerBusy( void ) { | ||
149 | NSResources->busy( FALSE ); | ||
150 | } | ||
137 | void NetworkSettings::SLOT_AddNode( void ) { | 151 | void NetworkSettings::SLOT_AddNode( void ) { |
138 | SLOT_EditNode( 0 ); | 152 | SLOT_EditNode( 0 ); |
139 | } | 153 | } |
140 | 154 | ||
141 | void NetworkSettings::SLOT_DeleteNode( void ) { | 155 | void NetworkSettings::SLOT_DeleteNode( void ) { |
142 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 156 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
@@ -169,12 +183,14 @@ void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { | |||
169 | EC.setConnection( NC ); | 183 | EC.setConnection( NC ); |
170 | } | 184 | } |
171 | 185 | ||
172 | EC.showMaximized(); | 186 | EC.showMaximized(); |
173 | // disable refresh timer | 187 | // disable refresh timer |
174 | UpdateTimer->stop(); | 188 | UpdateTimer->stop(); |
189 | NSResources->busy( TRUE ); | ||
190 | QTimer::singleShot( 1000, this, SLOT( SLOT_NoLongerBusy() )); | ||
175 | // we need to retry | 191 | // we need to retry |
176 | while( 1 ) { | 192 | while( 1 ) { |
177 | if( EC.exec() == QDialog::Accepted ) { | 193 | if( EC.exec() == QDialog::Accepted ) { |
178 | // toplevel item -> store | 194 | // toplevel item -> store |
179 | NodeCollection * NC = EC.connection(); | 195 | NodeCollection * NC = EC.connection(); |
180 | if( NC->isModified() ) { | 196 | if( NC->isModified() ) { |
@@ -203,13 +219,13 @@ void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { | |||
203 | Profiles_LB->index( LBI ) | 219 | Profiles_LB->index( LBI ) |
204 | ); | 220 | ); |
205 | } else { | 221 | } else { |
206 | // new item | 222 | // new item |
207 | int ci = Profiles_LB->count(); | 223 | int ci = Profiles_LB->count(); |
208 | NSResources->addConnection( NC ); | 224 | NSResources->addConnection( NC ); |
209 | NC->setNumber( NC->maxConnectionNumber()+1 ); | 225 | NC->setNumber( NSResources->assignConnectionNumber() ); |
210 | Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); | 226 | Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); |
211 | Profiles_LB->setSelected( ci, TRUE ); | 227 | Profiles_LB->setSelected( ci, TRUE ); |
212 | } | 228 | } |
213 | updateProfileState( LBI ); | 229 | updateProfileState( LBI ); |
214 | } | 230 | } |
215 | } else { | 231 | } else { |
@@ -254,37 +270,42 @@ void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { | |||
254 | break; | 270 | break; |
255 | case Off : | 271 | case Off : |
256 | DisabledOn = 0; | 272 | DisabledOn = 0; |
257 | break; | 273 | break; |
258 | case Available : | 274 | case Available : |
259 | OnOn = 1; | 275 | OnOn = 1; |
276 | Connect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) ); | ||
260 | DisabledOn = 0; | 277 | DisabledOn = 0; |
261 | break; | 278 | break; |
262 | case IsUp : | 279 | case IsUp : |
263 | OnOn = ConnectOn = 1; | 280 | OnOn = ConnectOn = 1; |
281 | Connect_TB->setPixmap( NSResources->getPixmap( "connected" ) ); | ||
264 | DisabledOn = 0; | 282 | DisabledOn = 0; |
265 | break; | 283 | break; |
266 | } | 284 | } |
267 | 285 | ||
286 | if( ! OnOn ) { | ||
287 | Connect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) ); | ||
288 | } | ||
289 | |||
268 | // set button state | 290 | // set button state |
269 | Enable_TB->setEnabled( EnabledPossible ); | 291 | Enable_TB->setEnabled( EnabledPossible ); |
270 | On_TB->setEnabled( OnPossible ); | 292 | On_TB->setEnabled( OnPossible ); |
271 | Connect_TB->setEnabled( ConnectPossible ); | 293 | Connect_TB->setEnabled( ConnectPossible ); |
272 | 294 | ||
273 | Enable_TB->setOn( DisabledOn ); | 295 | Enable_TB->setOn( DisabledOn ); |
274 | On_TB->setOn( OnOn ); | 296 | On_TB->setOn( OnOn ); |
275 | Connect_TB->setOn( ConnectOn ); | 297 | Connect_TB->setOn( ConnectOn ); |
276 | 298 | ||
277 | if( NC->description().isEmpty() ) { | 299 | if( NC->description().isEmpty() ) { |
278 | Description_LBL->setText( tr( "No description" ) ); | 300 | Description_LBL->setText( tr( "<<No description>>" ) ); |
279 | } else { | 301 | } else { |
280 | Description_LBL->setText( NC->description() ); | 302 | Description_LBL->setText( NC->description() ); |
281 | } | 303 | } |
282 | 304 | ||
283 | Profile_GB->setTitle( LBI->text() ); | 305 | Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() ); |
284 | State_LBL->setText( NC->stateName() ); | ||
285 | } | 306 | } |
286 | 307 | ||
287 | void NetworkSettings::SLOT_CheckState( void ) { | 308 | void NetworkSettings::SLOT_CheckState( void ) { |
288 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 309 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
289 | if ( ! LBI ) | 310 | if ( ! LBI ) |
290 | return; | 311 | return; |
@@ -411,21 +432,26 @@ void NetworkSettings::SLOT_Connect( void ) { | |||
411 | } | 432 | } |
412 | 433 | ||
413 | // we do not update the GUI but wait for the REAL upping of the device | 434 | // we do not update the GUI but wait for the REAL upping of the device |
414 | } | 435 | } |
415 | 436 | ||
416 | void NetworkSettings::SLOT_Disconnect( void ) { | 437 | void NetworkSettings::SLOT_Disconnect( void ) { |
438 | QString S; | ||
417 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 439 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
418 | 440 | ||
419 | if ( ! LBI ) | 441 | if ( ! LBI ) |
420 | return; | 442 | return; |
421 | 443 | ||
422 | NodeCollection * NC = | 444 | NodeCollection * NC = |
423 | NSResources->findConnection( LBI->text() ); | 445 | NSResources->findConnection( LBI->text() ); |
424 | 446 | ||
447 | Log(( "Force interface %s down\n", NC->name().latin1() )); | ||
425 | NC->setState( Down, 1 ); | 448 | NC->setState( Down, 1 ); |
449 | // remove 'up' file to make sure | ||
450 | S.sprintf( "/tmp/Profile-%d.up", NC->number() ); | ||
451 | unlink( S.latin1() ); | ||
426 | } | 452 | } |
427 | 453 | ||
428 | void NetworkSettings::SLOT_ToMessages( void ) { | 454 | void NetworkSettings::SLOT_ToMessages( void ) { |
429 | Profile_GB->hide(); | 455 | Profile_GB->hide(); |
430 | Messages_GB->show(); | 456 | Messages_GB->show(); |
431 | } | 457 | } |