Diffstat (limited to 'noncore/settings/networksettings2/networksettings.cpp') (more/less context) (show 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,13 +1,14 @@ | |||
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> |
8 | #include <qmessagebox.h> | 9 | #include <qmessagebox.h> |
9 | #include <qlabel.h> | 10 | #include <qlabel.h> |
10 | #include <qiconview.h> | 11 | #include <qiconview.h> |
11 | #include <qtimer.h> | 12 | #include <qtimer.h> |
12 | #include <qpe/qpeapplication.h> | 13 | #include <qpe/qpeapplication.h> |
13 | #include <qtoolbutton.h> | 14 | #include <qtoolbutton.h> |
@@ -52,24 +53,28 @@ NetworkSettings::NetworkSettings( QWidget *parent, | |||
52 | } | 53 | } |
53 | } | 54 | } |
54 | 55 | ||
55 | if( Profiles_LB->count() ) { | 56 | if( Profiles_LB->count() ) { |
56 | Profiles_LB->setSelected( 0, TRUE ); | 57 | Profiles_LB->setSelected( 0, TRUE ); |
57 | } | 58 | } |
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&)), |
70 | this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) ); | 75 | this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) ); |
71 | } | 76 | } |
72 | 77 | ||
73 | NetworkSettings::~NetworkSettings() { | 78 | NetworkSettings::~NetworkSettings() { |
74 | QString S; | 79 | QString S; |
75 | 80 | ||
@@ -82,24 +87,30 @@ NetworkSettings::~NetworkSettings() { | |||
82 | ); | 87 | ); |
83 | } | 88 | } |
84 | 89 | ||
85 | S = NSD.saveSettings(); | 90 | S = NSD.saveSettings(); |
86 | if( ! S.isEmpty() ) { | 91 | if( ! S.isEmpty() ) { |
87 | // problem saving | 92 | // problem saving |
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(); |
100 | // update current selection only | 111 | // update current selection only |
101 | NC = NSResources->findConnection( LBI->text() ); | 112 | NC = NSResources->findConnection( LBI->text() ); |
102 | if( NC ) { | 113 | if( NC ) { |
103 | State_t OldS = NC->state(); | 114 | State_t OldS = NC->state(); |
104 | State_t NewS = NC->state(1); | 115 | State_t NewS = NC->state(1); |
105 | if( OldS != NewS ) { | 116 | if( OldS != NewS ) { |
@@ -125,24 +136,27 @@ void NetworkSettings::SLOT_RefreshStates( void ) { | |||
125 | i ); | 136 | i ); |
126 | if( is ) { | 137 | if( is ) { |
127 | Profiles_LB->setSelected( i, TRUE ); | 138 | Profiles_LB->setSelected( i, TRUE ); |
128 | } | 139 | } |
129 | } | 140 | } |
130 | } | 141 | } |
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() ); |
143 | 157 | ||
144 | if ( ! LBI ) | 158 | if ( ! LBI ) |
145 | return; | 159 | return; |
146 | 160 | ||
147 | if( QMessageBox::warning( | 161 | if( QMessageBox::warning( |
148 | 0, | 162 | 0, |
@@ -163,24 +177,26 @@ void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { | |||
163 | if( LBI ) { | 177 | if( LBI ) { |
164 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); | 178 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
165 | if( ! NC ) { | 179 | if( ! NC ) { |
166 | return; | 180 | return; |
167 | } | 181 | } |
168 | OldName = NC->name(); | 182 | OldName = NC->name(); |
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() ) { |
181 | setModified( 1 ); | 197 | setModified( 1 ); |
182 | if( LBI ) { | 198 | if( LBI ) { |
183 | if( NC->name() != OldName ) { | 199 | if( NC->name() != OldName ) { |
184 | // find if new name is free | 200 | // find if new name is free |
185 | NodeCollection * LCN = NSResources->findConnection( | 201 | NodeCollection * LCN = NSResources->findConnection( |
186 | NC->name() ); | 202 | NC->name() ); |
@@ -197,25 +213,25 @@ void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { | |||
197 | NSResources->addConnection( NC ); | 213 | NSResources->addConnection( NC ); |
198 | } // else not changed | 214 | } // else not changed |
199 | 215 | ||
200 | // must add it here since change will trigger event | 216 | // must add it here since change will trigger event |
201 | Profiles_LB->changeItem( NC->devicePixmap(), | 217 | Profiles_LB->changeItem( NC->devicePixmap(), |
202 | NC->name(), | 218 | NC->name(), |
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 { |
216 | // cancelled : reset connection | 232 | // cancelled : reset connection |
217 | if( LBI ) { | 233 | if( LBI ) { |
218 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); | 234 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
219 | NC->reassign(); | 235 | NC->reassign(); |
220 | } | 236 | } |
221 | } | 237 | } |
@@ -248,49 +264,54 @@ void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { | |||
248 | case Unavailable : | 264 | case Unavailable : |
249 | // cannot do anything but recheck | 265 | // cannot do anything but recheck |
250 | EnabledPossible = OnPossible = ConnectPossible = 0; | 266 | EnabledPossible = OnPossible = ConnectPossible = 0; |
251 | break; | 267 | break; |
252 | case Disabled : | 268 | case Disabled : |
253 | OnPossible = ConnectPossible = 0; | 269 | OnPossible = ConnectPossible = 0; |
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; |
291 | updateProfileState( LBI ); | 312 | updateProfileState( LBI ); |
292 | } | 313 | } |
293 | 314 | ||
294 | void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { | 315 | void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { |
295 | if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) { | 316 | if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) { |
296 | SLOT_ShowNode( LBI ); | 317 | SLOT_ShowNode( LBI ); |
@@ -405,33 +426,38 @@ void NetworkSettings::SLOT_Connect( void ) { | |||
405 | 426 | ||
406 | if( ! rv ) { | 427 | if( ! rv ) { |
407 | QMessageBox::warning( | 428 | QMessageBox::warning( |
408 | 0, | 429 | 0, |
409 | tr( "Activating profile" ), | 430 | tr( "Activating profile" ), |
410 | tr( "Cannot enable profile" ) ); | 431 | tr( "Cannot enable profile" ) ); |
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 | } |
432 | 458 | ||
433 | void NetworkSettings::SLOT_ToProfile( void ) { | 459 | void NetworkSettings::SLOT_ToProfile( void ) { |
434 | Profile_GB->show(); | 460 | Profile_GB->show(); |
435 | Messages_GB->hide(); | 461 | Messages_GB->hide(); |
436 | } | 462 | } |
437 | 463 | ||