Diffstat (limited to 'noncore/settings/networksettings2/networksettings.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/networksettings.cpp | 101 |
1 files changed, 49 insertions, 52 deletions
diff --git a/noncore/settings/networksettings2/networksettings.cpp b/noncore/settings/networksettings2/networksettings.cpp index f72fa8e..e1110e2 100644 --- a/noncore/settings/networksettings2/networksettings.cpp +++ b/noncore/settings/networksettings2/networksettings.cpp | |||
@@ -1,10 +1,10 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | 2 | ||
3 | #include <qpe/qpeapplication.h> | 3 | #include <qpe/qpeapplication.h> |
4 | #include <qiconset.h> | 4 | #include <qlistbox.h> |
5 | #include <qgroupbox.h> | 5 | #include <qgroupbox.h> |
6 | #include <qtimer.h> | 6 | #include <qtimer.h> |
7 | #include <qlistbox.h> | 7 | #include <qlistbox.h> |
8 | #include <qmessagebox.h> | 8 | #include <qmessagebox.h> |
9 | #include <qlabel.h> | 9 | #include <qlabel.h> |
10 | #include <qiconview.h> | 10 | #include <qiconview.h> |
@@ -32,30 +32,27 @@ NetworkSettings::NetworkSettings( QWidget *parent, | |||
32 | 32 | ||
33 | Connect_TB->setPixmap( NSResources->getPixmap( "connected" ) ); | 33 | Connect_TB->setPixmap( NSResources->getPixmap( "connected" ) ); |
34 | 34 | ||
35 | On_TB->setPixmap( NSResources->getPixmap( "off" ) ); | 35 | On_TB->setPixmap( NSResources->getPixmap( "off" ) ); |
36 | 36 | ||
37 | // populate main Listbox | 37 | // populate main Listbox |
38 | Profiles_IV->clear(); | 38 | Profiles_LB->clear(); |
39 | { Name2Connection_t & M = NSResources->connections(); | 39 | { Name2Connection_t & M = NSResources->connections(); |
40 | NodeCollection * NC; | 40 | NodeCollection * NC; |
41 | QIconViewItem * IVI; | ||
42 | |||
43 | // for all connections | 41 | // for all connections |
44 | for( QDictIterator<NodeCollection> it(M); | 42 | for( QDictIterator<NodeCollection> it(M); |
45 | it.current(); | 43 | it.current(); |
46 | ++it ) { | 44 | ++it ) { |
47 | NC = it.current(); | 45 | NC = it.current(); |
48 | IVI = new QIconViewItem( Profiles_IV, | 46 | Profiles_LB->insertItem( NC->devicePixmap(), |
49 | NC->name(), | 47 | NC->name() ); |
50 | NC->devicePixmap() ); | ||
51 | } | 48 | } |
52 | } | 49 | } |
53 | 50 | ||
54 | if( Profiles_IV->count() ) { | 51 | if( Profiles_LB->count() ) { |
55 | Profiles_IV->setSelected( Profiles_IV->firstItem(), TRUE ); | 52 | Profiles_LB->setSelected( 0, TRUE ); |
56 | } | 53 | } |
57 | 54 | ||
58 | // if no profiles -> auto popup editing | 55 | // if no profiles -> auto popup editing |
59 | if( NSResources->connections().count() == 0 ) { | 56 | if( NSResources->connections().count() == 0 ) { |
60 | QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); | 57 | QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); |
61 | } | 58 | } |
@@ -88,24 +85,24 @@ NetworkSettings::~NetworkSettings() { | |||
88 | 0, | 85 | 0, |
89 | tr( "Saving setup" ), S ); | 86 | tr( "Saving setup" ), S ); |
90 | } | 87 | } |
91 | } | 88 | } |
92 | 89 | ||
93 | void NetworkSettings::SLOT_RefreshStates( void ) { | 90 | void NetworkSettings::SLOT_RefreshStates( void ) { |
94 | QIconViewItem * IVI = Profiles_IV->currentItem(); // remeber | 91 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember |
95 | 92 | ||
96 | if( IVI ) { | 93 | if( LBI ) { |
97 | NodeCollection * NC; | 94 | NodeCollection * NC; |
98 | NSResources->system().probeInterfaces(); | 95 | NSResources->system().probeInterfaces(); |
99 | // update current selection only | 96 | // update current selection only |
100 | NC = NSResources->findConnection( IVI->text() ); | 97 | NC = NSResources->findConnection( LBI->text() ); |
101 | if( NC ) { | 98 | if( NC ) { |
102 | State_t OldS = NC->state(); | 99 | State_t OldS = NC->state(); |
103 | State_t NewS = NC->state(1); | 100 | State_t NewS = NC->state(1); |
104 | if( OldS != NewS ) { | 101 | if( OldS != NewS ) { |
105 | updateProfileState( IVI ); | 102 | updateProfileState( LBI ); |
106 | } | 103 | } |
107 | } | 104 | } |
108 | } | 105 | } |
109 | 106 | ||
110 | 107 | ||
111 | /* -> LATER !! | 108 | /* -> LATER !! |
@@ -135,35 +132,35 @@ void NetworkSettings::SLOT_RefreshStates( void ) { | |||
135 | 132 | ||
136 | void NetworkSettings::SLOT_AddNode( void ) { | 133 | void NetworkSettings::SLOT_AddNode( void ) { |
137 | SLOT_EditNode( 0 ); | 134 | SLOT_EditNode( 0 ); |
138 | } | 135 | } |
139 | 136 | ||
140 | void NetworkSettings::SLOT_DeleteNode( void ) { | 137 | void NetworkSettings::SLOT_DeleteNode( void ) { |
141 | QIconViewItem * IVI = Profiles_IV->currentItem(); | 138 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
142 | 139 | ||
143 | if ( ! IVI ) | 140 | if ( ! LBI ) |
144 | return; | 141 | return; |
145 | 142 | ||
146 | if( QMessageBox::warning( | 143 | if( QMessageBox::warning( |
147 | 0, | 144 | 0, |
148 | tr( "Removing profile" ), | 145 | tr( "Removing profile" ), |
149 | tr( "Remove selected profile ?" ), | 146 | tr( "Remove selected profile ?" ), |
150 | 1, 0 ) == 1 ) { | 147 | 1, 0 ) == 1 ) { |
151 | NSResources->removeConnection( IVI->text() ); | 148 | NSResources->removeConnection( LBI->text() ); |
152 | delete IVI; | 149 | delete LBI; |
153 | setModified( 1 ); | 150 | setModified( 1 ); |
154 | NSD.forceGeneration(1); | 151 | NSD.forceGeneration(1); |
155 | } | 152 | } |
156 | } | 153 | } |
157 | 154 | ||
158 | void NetworkSettings::SLOT_EditNode( QIconViewItem * IVI ) { | 155 | void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { |
159 | QString OldName = ""; | 156 | QString OldName = ""; |
160 | EditConnection EC( this ); | 157 | EditConnection EC( this ); |
161 | 158 | ||
162 | if( IVI ) { | 159 | if( LBI ) { |
163 | NodeCollection * NC = NSResources->findConnection( IVI->text() ); | 160 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
164 | if( ! NC ) { | 161 | if( ! NC ) { |
165 | return; | 162 | return; |
166 | } | 163 | } |
167 | OldName = NC->name(); | 164 | OldName = NC->name(); |
168 | EC.setConnection( NC ); | 165 | EC.setConnection( NC ); |
169 | } | 166 | } |
@@ -173,47 +170,47 @@ void NetworkSettings::SLOT_EditNode( QIconViewItem * IVI ) { | |||
173 | UpdateTimer->stop(); | 170 | UpdateTimer->stop(); |
174 | if( EC.exec() == QDialog::Accepted ) { | 171 | if( EC.exec() == QDialog::Accepted ) { |
175 | // toplevel item -> store | 172 | // toplevel item -> store |
176 | NodeCollection * NC = EC.connection(); | 173 | NodeCollection * NC = EC.connection(); |
177 | if( NC->isModified() ) { | 174 | if( NC->isModified() ) { |
178 | setModified( 1 ); | 175 | setModified( 1 ); |
179 | if( IVI ) { | 176 | if( LBI ) { |
180 | // new name -> remove item | 177 | // new name -> remove item |
181 | NSResources->removeConnection( OldName ); | 178 | NSResources->removeConnection( OldName ); |
182 | // must add it here since change will trigger event | 179 | // must add it here since change will trigger event |
183 | NSResources->addConnection( NC ); | 180 | NSResources->addConnection( NC ); |
184 | IVI->setText( NC->name() ); | 181 | Profiles_LB->changeItem( NC->devicePixmap(), |
185 | IVI->setPixmap( NC->devicePixmap() ); | 182 | NC->name(), |
183 | Profiles_LB->index( LBI ) | ||
184 | ); | ||
186 | } else { | 185 | } else { |
187 | // new item | 186 | // new item |
187 | int ci = Profiles_LB->count(); | ||
188 | NSResources->addConnection( NC ); | 188 | NSResources->addConnection( NC ); |
189 | NC->setNumber( NC->maxConnectionNumber()+1 ); | 189 | NC->setNumber( NC->maxConnectionNumber()+1 ); |
190 | IVI = new QIconViewItem( Profiles_IV, | 190 | Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); |
191 | NC->name(), | 191 | Profiles_LB->setSelected( ci, TRUE ); |
192 | NC->devicePixmap() | ||
193 | ); | ||
194 | Profiles_IV->setSelected( IVI, TRUE ); | ||
195 | } | 192 | } |
196 | updateProfileState( IVI ); | 193 | updateProfileState( LBI ); |
197 | } | 194 | } |
198 | } else { | 195 | } else { |
199 | // cancelled : reset connection | 196 | // cancelled : reset connection |
200 | if( IVI ) { | 197 | if( LBI ) { |
201 | NodeCollection * NC = NSResources->findConnection( IVI->text() ); | 198 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
202 | NC->reassign(); | 199 | NC->reassign(); |
203 | } | 200 | } |
204 | } | 201 | } |
205 | // reenable | 202 | // reenable |
206 | UpdateTimer->start( 5000 ); | 203 | UpdateTimer->start( 5000 ); |
207 | } | 204 | } |
208 | 205 | ||
209 | void NetworkSettings::SLOT_ShowNode( QIconViewItem * IVI ) { | 206 | void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { |
210 | if( IVI == 0 ) | 207 | if( LBI == 0 ) |
211 | return; | 208 | return; |
212 | 209 | ||
213 | NodeCollection * NC = NSResources->findConnection( IVI->text() ); | 210 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
214 | 211 | ||
215 | // is button possible | 212 | // is button possible |
216 | bool EnabledPossible, OnPossible, ConnectPossible; | 213 | bool EnabledPossible, OnPossible, ConnectPossible; |
217 | // is button On or Off | 214 | // is button On or Off |
218 | bool DisabledOn, OnOn, ConnectOn; | 215 | bool DisabledOn, OnOn, ConnectOn; |
219 | 216 | ||
@@ -258,26 +255,26 @@ void NetworkSettings::SLOT_ShowNode( QIconViewItem * IVI ) { | |||
258 | if( NC->description().isEmpty() ) { | 255 | if( NC->description().isEmpty() ) { |
259 | Description_LBL->setText( tr( "No description" ) ); | 256 | Description_LBL->setText( tr( "No description" ) ); |
260 | } else { | 257 | } else { |
261 | Description_LBL->setText( NC->description() ); | 258 | Description_LBL->setText( NC->description() ); |
262 | } | 259 | } |
263 | 260 | ||
264 | CurProfile_GB->setTitle( IVI->text() ); | 261 | CurProfile_GB->setTitle( LBI->text() ); |
265 | State_LBL->setText( NC->stateName() ); | 262 | State_LBL->setText( NC->stateName() ); |
266 | } | 263 | } |
267 | 264 | ||
268 | void NetworkSettings::SLOT_CheckState( void ) { | 265 | void NetworkSettings::SLOT_CheckState( void ) { |
269 | QIconViewItem * IVI = Profiles_IV->currentItem(); | 266 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
270 | if ( ! IVI ) | 267 | if ( ! LBI ) |
271 | return; | 268 | return; |
272 | updateProfileState( IVI ); | 269 | updateProfileState( LBI ); |
273 | } | 270 | } |
274 | 271 | ||
275 | void NetworkSettings::updateProfileState( QIconViewItem * IVI ) { | 272 | void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { |
276 | if( IVI == Profiles_IV->currentItem() ) { | 273 | if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) { |
277 | SLOT_ShowNode( IVI ); | 274 | SLOT_ShowNode( LBI ); |
278 | } | 275 | } |
279 | } | 276 | } |
280 | 277 | ||
281 | void NetworkSettings::SLOT_GenerateConfig( void ) { | 278 | void NetworkSettings::SLOT_GenerateConfig( void ) { |
282 | QString S = NSD.generateSettings( TRUE ); | 279 | QString S = NSD.generateSettings( TRUE ); |
283 | 280 | ||
@@ -288,19 +285,19 @@ void NetworkSettings::SLOT_GenerateConfig( void ) { | |||
288 | S | 285 | S |
289 | ); | 286 | ); |
290 | } | 287 | } |
291 | } | 288 | } |
292 | 289 | ||
293 | void NetworkSettings::SLOT_Enable( void ) { | 290 | void NetworkSettings::SLOT_Enable( void ) { |
294 | QIconViewItem * IVI = Profiles_IV->currentItem(); | 291 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
295 | QString Msg; | 292 | QString Msg; |
296 | if ( ! IVI ) | 293 | if ( ! LBI ) |
297 | return; | 294 | return; |
298 | 295 | ||
299 | NodeCollection * NC = | 296 | NodeCollection * NC = |
300 | NSResources->findConnection( IVI->text() ); | 297 | NSResources->findConnection( LBI->text() ); |
301 | 298 | ||
302 | bool rv; | 299 | bool rv; |
303 | switch( NC->state() ) { | 300 | switch( NC->state() ) { |
304 | case Disabled : | 301 | case Disabled : |
305 | Msg = tr( "Cannot enable profile" ); | 302 | Msg = tr( "Cannot enable profile" ); |
306 | rv = NC->setState( Enable ); | 303 | rv = NC->setState( Enable ); |
@@ -315,23 +312,23 @@ void NetworkSettings::SLOT_Enable( void ) { | |||
315 | QMessageBox::warning( | 312 | QMessageBox::warning( |
316 | 0, | 313 | 0, |
317 | tr( "Activating profile" ), | 314 | tr( "Activating profile" ), |
318 | Msg ); | 315 | Msg ); |
319 | return; | 316 | return; |
320 | } | 317 | } |
321 | updateProfileState( IVI ); | 318 | updateProfileState( LBI ); |
322 | } | 319 | } |
323 | 320 | ||
324 | void NetworkSettings::SLOT_On( void ) { | 321 | void NetworkSettings::SLOT_On( void ) { |
325 | QIconViewItem * IVI = Profiles_IV->currentItem(); | 322 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
326 | 323 | ||
327 | if ( ! IVI ) | 324 | if ( ! LBI ) |
328 | return; | 325 | return; |
329 | 326 | ||
330 | NodeCollection * NC = | 327 | NodeCollection * NC = |
331 | NSResources->findConnection( IVI->text() ); | 328 | NSResources->findConnection( LBI->text() ); |
332 | 329 | ||
333 | bool rv; | 330 | bool rv; |
334 | switch( NC->state() ) { | 331 | switch( NC->state() ) { |
335 | case Off : | 332 | case Off : |
336 | // activate interface | 333 | // activate interface |
337 | rv = NC->setState( Activate ); | 334 | rv = NC->setState( Activate ); |
@@ -354,23 +351,23 @@ void NetworkSettings::SLOT_On( void ) { | |||
354 | QMessageBox::warning( | 351 | QMessageBox::warning( |
355 | 0, | 352 | 0, |
356 | tr( "Activating profile" ), | 353 | tr( "Activating profile" ), |
357 | tr( "Cannot enable profile" ) ); | 354 | tr( "Cannot enable profile" ) ); |
358 | return; | 355 | return; |
359 | } | 356 | } |
360 | updateProfileState( IVI ); | 357 | updateProfileState( LBI ); |
361 | } | 358 | } |
362 | 359 | ||
363 | void NetworkSettings::SLOT_Connect( void ) { | 360 | void NetworkSettings::SLOT_Connect( void ) { |
364 | QIconViewItem * IVI = Profiles_IV->currentItem(); | 361 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
365 | 362 | ||
366 | if ( ! IVI ) | 363 | if ( ! LBI ) |
367 | return; | 364 | return; |
368 | 365 | ||
369 | NodeCollection * NC = | 366 | NodeCollection * NC = |
370 | NSResources->findConnection( IVI->text() ); | 367 | NSResources->findConnection( LBI->text() ); |
371 | 368 | ||
372 | bool rv; | 369 | bool rv; |
373 | switch( NC->state() ) { | 370 | switch( NC->state() ) { |
374 | case IsUp : | 371 | case IsUp : |
375 | // down interface | 372 | // down interface |
376 | rv = NC->setState( Down ); | 373 | rv = NC->setState( Down ); |