Diffstat (limited to 'noncore/settings/networksettings2/networksettings.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/networksettings.cpp | 6 |
1 files changed, 1 insertions, 5 deletions
diff --git a/noncore/settings/networksettings2/networksettings.cpp b/noncore/settings/networksettings2/networksettings.cpp index 9680a96..78b6cce 100644 --- a/noncore/settings/networksettings2/networksettings.cpp +++ b/noncore/settings/networksettings2/networksettings.cpp | |||
@@ -1,514 +1,510 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <unistd.h> | 2 | #include <unistd.h> |
3 | #include <errno.h> | 3 | #include <errno.h> |
4 | 4 | ||
5 | #include <opie2/odebug.h> | 5 | #include <opie2/odebug.h> |
6 | #include <opie2/oledbox.h> | 6 | #include <opie2/oledbox.h> |
7 | 7 | ||
8 | #include <qpe/qpeapplication.h> | 8 | #include <qpe/qpeapplication.h> |
9 | #include <qlistbox.h> | 9 | #include <qlistbox.h> |
10 | #include <qlayout.h> | 10 | #include <qlayout.h> |
11 | #include <qgroupbox.h> | 11 | #include <qgroupbox.h> |
12 | #include <qtimer.h> | 12 | #include <qtimer.h> |
13 | #include <qlistbox.h> | 13 | #include <qlistbox.h> |
14 | #include <qmessagebox.h> | 14 | #include <qmessagebox.h> |
15 | #include <qlabel.h> | 15 | #include <qlabel.h> |
16 | #include <qiconview.h> | 16 | #include <qiconview.h> |
17 | #include <qtimer.h> | 17 | #include <qtimer.h> |
18 | #include <qpe/qpeapplication.h> | 18 | #include <qpe/qpeapplication.h> |
19 | #include <qtoolbutton.h> | 19 | #include <qtoolbutton.h> |
20 | #include <qevent.h> | 20 | #include <qevent.h> |
21 | 21 | ||
22 | #include "networksettings.h" | 22 | #include "networksettings.h" |
23 | #include "netnode.h" | 23 | #include "netnode.h" |
24 | #include "editconnection.h" | 24 | #include "editconnection.h" |
25 | 25 | ||
26 | NetworkSettings::NetworkSettings( QWidget *parent, | 26 | NetworkSettings::NetworkSettings( QWidget *parent, |
27 | const char *name, | 27 | const char *name, |
28 | WFlags fl ) : NetworkSettingsGUI(parent,name,fl), | 28 | WFlags fl ) : NetworkSettingsGUI(parent,name,fl), |
29 | NSD() { | 29 | NSD() { |
30 | 30 | ||
31 | UpdateTimer = new QTimer( this ); | 31 | UpdateTimer = new QTimer( this ); |
32 | 32 | ||
33 | // set pixmaps | 33 | // set pixmaps |
34 | Add_TB->setPixmap( NSResources->getPixmap( "add" ) ); | 34 | Add_TB->setPixmap( NSResources->getPixmap( "add" ) ); |
35 | Delete_TB->setPixmap( NSResources->getPixmap( "remove" ) ); | 35 | Delete_TB->setPixmap( NSResources->getPixmap( "remove" ) ); |
36 | CheckState_TB->setPixmap( NSResources->getPixmap( "check" ) ); | 36 | CheckState_TB->setPixmap( NSResources->getPixmap( "check" ) ); |
37 | GenConfig_TB->setPixmap( NSResources->getPixmap( "configure" ) ); | 37 | GenConfig_TB->setPixmap( NSResources->getPixmap( "configure" ) ); |
38 | 38 | ||
39 | Disable_TB->setPixmap( NSResources->getPixmap( "disabled" ) ); | 39 | Disable_TB->setPixmap( NSResources->getPixmap( "disabled" ) ); |
40 | Up_TB->setPixmap( NSResources->getPixmap( "more" ) ); | 40 | Up_TB->setPixmap( NSResources->getPixmap( "more" ) ); |
41 | Down_TB->setPixmap( NSResources->getPixmap( "less" ) ); | 41 | Down_TB->setPixmap( NSResources->getPixmap( "less" ) ); |
42 | 42 | ||
43 | QVBoxLayout* V = new QVBoxLayout( LED_Frm ); | 43 | QVBoxLayout* V = new QVBoxLayout( LED_Frm ); |
44 | QHBoxLayout * H = new QHBoxLayout( 0 ); | 44 | QHBoxLayout * H = new QHBoxLayout( 0 ); |
45 | V->addStretch(1); | 45 | V->addStretch(1); |
46 | V->addLayout( H ); | 46 | V->addLayout( H ); |
47 | Leds[0] = new Opie::Ui::OLedBox( red, LED_Frm ); | 47 | Leds[0] = new Opie::Ui::OLedBox( red, LED_Frm ); |
48 | H->addWidget( Leds[0], 0, Qt::AlignVCenter ); | 48 | H->addWidget( Leds[0], 0, Qt::AlignVCenter ); |
49 | Leds[1] = new Opie::Ui::OLedBox( red, LED_Frm ); | 49 | Leds[1] = new Opie::Ui::OLedBox( red, LED_Frm ); |
50 | H->addWidget( Leds[1], 0, Qt::AlignVCenter ); | 50 | H->addWidget( Leds[1], 0, Qt::AlignVCenter ); |
51 | Leds[2] = new Opie::Ui::OLedBox( red, LED_Frm ); | 51 | Leds[2] = new Opie::Ui::OLedBox( red, LED_Frm ); |
52 | H->addWidget( Leds[2], 0, Qt::AlignVCenter ); | 52 | H->addWidget( Leds[2], 0, Qt::AlignVCenter ); |
53 | V->addStretch(1); | 53 | V->addStretch(1); |
54 | 54 | ||
55 | 55 | ||
56 | SLOT_ToProfile(); | 56 | SLOT_ToProfile(); |
57 | 57 | ||
58 | // populate main Listbox | 58 | // populate main Listbox |
59 | Profiles_LB->clear(); | 59 | Profiles_LB->clear(); |
60 | QPEApplication::setStylusOperation( | 60 | QPEApplication::setStylusOperation( |
61 | Profiles_LB->viewport(), QPEApplication::RightOnHold ); | 61 | Profiles_LB->viewport(), QPEApplication::RightOnHold ); |
62 | 62 | ||
63 | connect( Profiles_LB, | 63 | connect( Profiles_LB, |
64 | SIGNAL(rightButtonPressed(QListBoxItem*,const QPoint&)), | 64 | SIGNAL(rightButtonPressed(QListBoxItem*,const QPoint&)), |
65 | this, SLOT(SLOT_EditNode(QListBoxItem*)) ); | 65 | this, SLOT(SLOT_EditNode(QListBoxItem*)) ); |
66 | 66 | ||
67 | { Name2Connection_t & M = NSResources->connections(); | 67 | { Name2Connection_t & M = NSResources->connections(); |
68 | NodeCollection * NC; | 68 | NodeCollection * NC; |
69 | // for all connections | 69 | // for all connections |
70 | for( QDictIterator<NodeCollection> it(M); | 70 | for( QDictIterator<NodeCollection> it(M); |
71 | it.current(); | 71 | it.current(); |
72 | ++it ) { | 72 | ++it ) { |
73 | NC = it.current(); | 73 | NC = it.current(); |
74 | Profiles_LB->insertItem( NC->devicePixmap(), | 74 | Profiles_LB->insertItem( NC->devicePixmap(), |
75 | NC->name() ); | 75 | NC->name() ); |
76 | } | 76 | } |
77 | } | 77 | } |
78 | 78 | ||
79 | if( Profiles_LB->count() ) { | 79 | if( Profiles_LB->count() ) { |
80 | Profiles_LB->setSelected( 0, TRUE ); | 80 | Profiles_LB->setSelected( 0, TRUE ); |
81 | } | 81 | } |
82 | 82 | ||
83 | // if no profiles -> auto popup editing | 83 | // if no profiles -> auto popup editing |
84 | if( NSResources->connections().count() == 0 ) { | 84 | if( NSResources->connections().count() == 0 ) { |
85 | QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); | 85 | QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); |
86 | } | 86 | } |
87 | 87 | ||
88 | connect( &(NSResources->system()), | 88 | connect( &(NSResources->system()), |
89 | SIGNAL( stdoutLine(const QString &) ), | 89 | SIGNAL( stdoutLine(const QString &) ), |
90 | this, SLOT( SLOT_CmdMessage(const QString &) ) ); | 90 | this, SLOT( SLOT_CmdMessage(const QString &) ) ); |
91 | 91 | ||
92 | connect( &(NSResources->system()), | 92 | connect( &(NSResources->system()), |
93 | SIGNAL( stderrLine(const QString &) ), | 93 | SIGNAL( stderrLine(const QString &) ), |
94 | this, SLOT( SLOT_CmdMessage(const QString &) ) ); | 94 | this, SLOT( SLOT_CmdMessage(const QString &) ) ); |
95 | 95 | ||
96 | connect( &(NSResources->system()), | 96 | connect( &(NSResources->system()), |
97 | SIGNAL( processEvent(const QString &) ), | 97 | SIGNAL( processEvent(const QString &) ), |
98 | this, SLOT( SLOT_CmdMessage(const QString &) ) ); | 98 | this, SLOT( SLOT_CmdMessage(const QString &) ) ); |
99 | 99 | ||
100 | UpdateTimer->start( 5000 ); | 100 | UpdateTimer->start( 5000 ); |
101 | connect( UpdateTimer, SIGNAL( timeout() ), | 101 | connect( UpdateTimer, SIGNAL( timeout() ), |
102 | this, SLOT( SLOT_RefreshStates() ) ); | 102 | this, SLOT( SLOT_RefreshStates() ) ); |
103 | 103 | ||
104 | /* Add QCopChannel */ | 104 | /* Add QCopChannel */ |
105 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), | 105 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), |
106 | this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) ); | 106 | this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) ); |
107 | } | 107 | } |
108 | 108 | ||
109 | NetworkSettings::~NetworkSettings() { | 109 | NetworkSettings::~NetworkSettings() { |
110 | QString S; | 110 | QString S; |
111 | 111 | ||
112 | owarn << "Dispose NS" << oendl; | ||
113 | if( NSD.isModified() ) { | 112 | if( NSD.isModified() ) { |
114 | owarn << "Modified" << oendl; | ||
115 | S = NSD.saveSettings(); | 113 | S = NSD.saveSettings(); |
116 | if( ! S.isEmpty() ) { | 114 | if( ! S.isEmpty() ) { |
117 | S.insert( 0, "<p>" ); | 115 | S.insert( 0, "<p>" ); |
118 | S.append( "</p>" ); | 116 | S.append( "</p>" ); |
119 | // problem saving | 117 | // problem saving |
120 | QMessageBox::warning( | 118 | QMessageBox::warning( |
121 | 0, | 119 | 0, |
122 | tr( "Saving setup" ), S ); | 120 | tr( "Saving setup" ), S ); |
123 | } | 121 | } |
124 | 122 | ||
125 | SLOT_GenerateConfig(); | 123 | SLOT_GenerateConfig(); |
126 | NSD.setModified( 0 ); | 124 | NSD.setModified( 0 ); |
127 | } | 125 | } |
128 | 126 | ||
129 | } | 127 | } |
130 | 128 | ||
131 | void NetworkSettings::SLOT_CmdMessage( const QString & S ) { | 129 | void NetworkSettings::SLOT_CmdMessage( const QString & S ) { |
132 | Messages_LB->insertItem( S ); | 130 | Messages_LB->insertItem( S ); |
133 | Messages_LB->setCurrentItem( Messages_LB->count()-1 ); | 131 | Messages_LB->setCurrentItem( Messages_LB->count()-1 ); |
134 | Messages_LB->ensureCurrentVisible(); | 132 | Messages_LB->ensureCurrentVisible(); |
135 | } | 133 | } |
136 | 134 | ||
137 | void NetworkSettings::SLOT_RefreshStates( void ) { | 135 | void NetworkSettings::SLOT_RefreshStates( void ) { |
138 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember | 136 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember |
139 | 137 | ||
140 | if( LBI ) { | 138 | if( LBI ) { |
141 | NodeCollection * NC; | 139 | NodeCollection * NC; |
142 | NSResources->system().probeInterfaces(); | 140 | NSResources->system().probeInterfaces(); |
143 | // update current selection only | 141 | // update current selection only |
144 | NC = NSResources->findConnection( LBI->text() ); | 142 | NC = NSResources->findConnection( LBI->text() ); |
145 | if( NC ) { | 143 | if( NC ) { |
146 | State_t OldS = NC->state(); | 144 | State_t OldS = NC->state(); |
147 | State_t NewS = NC->state(1); | 145 | State_t NewS = NC->state(1); |
148 | if( OldS != NewS ) { | 146 | if( OldS != NewS ) { |
149 | updateProfileState( LBI ); | 147 | updateProfileState( LBI ); |
150 | } | 148 | } |
151 | } | 149 | } |
152 | } | 150 | } |
153 | 151 | ||
154 | 152 | ||
155 | /* -> LATER !! | 153 | /* -> LATER !! |
156 | bool is; | 154 | bool is; |
157 | NodeCollection * NC; | 155 | NodeCollection * NC; |
158 | 156 | ||
159 | for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) { | 157 | for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) { |
160 | NC = NSResources->findConnection( Profiles_LB->text(i) ); | 158 | NC = NSResources->findConnection( Profiles_LB->text(i) ); |
161 | if( NC ) { | 159 | if( NC ) { |
162 | State_t OldS = NC->state(); | 160 | State_t OldS = NC->state(); |
163 | State_t NewS = NC->state(1); | 161 | State_t NewS = NC->state(1); |
164 | if( OldS != NewS ) { | 162 | if( OldS != NewS ) { |
165 | is = Profiles_LB->isSelected(i); | 163 | is = Profiles_LB->isSelected(i); |
166 | Profiles_LB->changeItem( NC->statePixmap(NewS), | 164 | Profiles_LB->changeItem( NC->statePixmap(NewS), |
167 | NC->name(), | 165 | NC->name(), |
168 | i ); | 166 | i ); |
169 | if( is ) { | 167 | if( is ) { |
170 | Profiles_LB->setSelected( i, TRUE ); | 168 | Profiles_LB->setSelected( i, TRUE ); |
171 | } | 169 | } |
172 | } | 170 | } |
173 | } | 171 | } |
174 | } | 172 | } |
175 | if( ci >= 0 ) | 173 | if( ci >= 0 ) |
176 | Profiles_LB->setCurrentItem( ci ); | 174 | Profiles_LB->setCurrentItem( ci ); |
177 | */ | 175 | */ |
178 | } | 176 | } |
179 | 177 | ||
180 | void NetworkSettings::SLOT_AddNode( void ) { | 178 | void NetworkSettings::SLOT_AddNode( void ) { |
181 | SLOT_EditNode( 0 ); | 179 | SLOT_EditNode( 0 ); |
182 | } | 180 | } |
183 | 181 | ||
184 | void NetworkSettings::SLOT_DeleteNode( void ) { | 182 | void NetworkSettings::SLOT_DeleteNode( void ) { |
185 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 183 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
186 | 184 | ||
187 | if ( ! LBI ) | 185 | if ( ! LBI ) |
188 | return; | 186 | return; |
189 | 187 | ||
190 | if( QMessageBox::warning( | 188 | if( QMessageBox::warning( |
191 | 0, | 189 | 0, |
192 | tr( "Removing profile" ), | 190 | tr( "Removing profile" ), |
193 | tr( "Remove selected profile ?" ), | 191 | tr( "Remove selected profile ?" ), |
194 | 1, 0 ) == 1 ) { | 192 | 1, 0 ) == 1 ) { |
195 | NSResources->removeConnection( LBI->text() ); | 193 | NSResources->removeConnection( LBI->text() ); |
196 | delete LBI; | 194 | delete LBI; |
197 | NSD.setModified( 1 ); | 195 | NSD.setModified( 1 ); |
198 | } | 196 | } |
199 | } | 197 | } |
200 | 198 | ||
201 | void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { | 199 | void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { |
202 | QString OldName = ""; | 200 | QString OldName = ""; |
203 | 201 | ||
204 | EditConnection EC( this ); | 202 | EditConnection EC( this ); |
205 | 203 | ||
206 | if( LBI ) { | 204 | if( LBI ) { |
207 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); | 205 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
208 | if( ! NC ) { | 206 | if( ! NC ) { |
209 | return; | 207 | return; |
210 | } | 208 | } |
211 | OldName = NC->name(); | 209 | OldName = NC->name(); |
212 | EC.setConnection( NC ); | 210 | EC.setConnection( NC ); |
213 | } | 211 | } |
214 | 212 | ||
215 | EC.showMaximized(); | 213 | EC.showMaximized(); |
216 | // disable refresh timer | 214 | // disable refresh timer |
217 | UpdateTimer->stop(); | 215 | UpdateTimer->stop(); |
218 | 216 | ||
219 | // we need to retry | 217 | // we need to retry |
220 | while( 1 ) { | 218 | while( 1 ) { |
221 | if( EC.exec() == QDialog::Accepted ) { | 219 | if( EC.exec() == QDialog::Accepted ) { |
222 | // toplevel item -> store | 220 | // toplevel item -> store |
223 | NodeCollection * NC = EC.connection(); | 221 | NodeCollection * NC = EC.connection(); |
224 | if( NC->isModified() ) { | 222 | if( NC->isModified() ) { |
225 | if( LBI ) { | 223 | if( LBI ) { |
226 | if( NC->name() != OldName ) { | 224 | if( NC->name() != OldName ) { |
227 | // find if new name is free | 225 | // find if new name is free |
228 | NodeCollection * LCN = NSResources->findConnection( | 226 | NodeCollection * LCN = NSResources->findConnection( |
229 | NC->name() ); | 227 | NC->name() ); |
230 | if( LCN ) { | 228 | if( LCN ) { |
231 | QMessageBox::warning( | 229 | QMessageBox::warning( |
232 | 0, | 230 | 0, |
233 | tr( "In System Config" ), | 231 | tr( "In System Config" ), |
234 | tr( "Name %1 already exists" ).arg(NC->name()) | 232 | tr( "Name %1 already exists" ).arg(NC->name()) |
235 | ); | 233 | ); |
236 | continue; // restart exec | 234 | continue; // restart exec |
237 | } // else new name | 235 | } // else new name |
238 | // new name -> remove item | 236 | // new name -> remove item |
239 | NSResources->removeConnection( OldName ); | 237 | NSResources->removeConnection( OldName ); |
240 | NSResources->addConnection( NC, 0 ); | 238 | NSResources->addConnection( NC, 0 ); |
241 | } // else not changed | 239 | } // else not changed |
242 | 240 | ||
243 | // must add it here since change will trigger event | 241 | // must add it here since change will trigger event |
244 | Profiles_LB->changeItem( NC->devicePixmap(), | 242 | Profiles_LB->changeItem( NC->devicePixmap(), |
245 | NC->name(), | 243 | NC->name(), |
246 | Profiles_LB->index( LBI ) | 244 | Profiles_LB->index( LBI ) |
247 | ); | 245 | ); |
248 | } else { | 246 | } else { |
249 | // new item | 247 | // new item |
250 | int ci = Profiles_LB->count(); | 248 | int ci = Profiles_LB->count(); |
251 | NSResources->addConnection( NC, 0 ); | 249 | NSResources->addConnection( NC, 0 ); |
252 | NC->setNumber( NSResources->assignConnectionNumber() ); | 250 | NC->setNumber( NSResources->assignConnectionNumber() ); |
253 | Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); | 251 | Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); |
254 | Profiles_LB->setSelected( ci, TRUE ); | 252 | Profiles_LB->setSelected( ci, TRUE ); |
255 | } | 253 | } |
256 | updateProfileState( LBI ); | 254 | updateProfileState( LBI ); |
257 | } | 255 | } |
258 | } else { | 256 | } else { |
259 | // cancelled : reset connection | 257 | // cancelled : reset connection |
260 | if( LBI ) { | 258 | if( LBI ) { |
261 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); | 259 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
262 | NC->reassign(); | 260 | NC->reassign(); |
263 | } | 261 | } |
264 | } | 262 | } |
265 | break; | 263 | break; |
266 | } | 264 | } |
267 | // reenable | 265 | // reenable |
268 | UpdateTimer->start( 5000 ); | 266 | UpdateTimer->start( 5000 ); |
269 | } | 267 | } |
270 | 268 | ||
271 | void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { | 269 | void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { |
272 | if( LBI == 0 ) | 270 | if( LBI == 0 ) |
273 | return; | 271 | return; |
274 | 272 | ||
275 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); | 273 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
276 | 274 | ||
277 | if( NC->description().isEmpty() ) { | 275 | if( NC->description().isEmpty() ) { |
278 | Description_LBL->setText( tr( "<<No description>>" ) ); | 276 | Description_LBL->setText( tr( "<<No description>>" ) ); |
279 | } else { | 277 | } else { |
280 | Description_LBL->setText( NC->description() ); | 278 | Description_LBL->setText( NC->description() ); |
281 | } | 279 | } |
282 | 280 | ||
283 | Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() ); | 281 | Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() ); |
284 | 282 | ||
285 | bool FrmActive = 1; | 283 | bool FrmActive = 1; |
286 | bool IsEnabled = 1; | 284 | bool IsEnabled = 1; |
287 | int leds = 0; | 285 | int leds = 0; |
288 | 286 | ||
289 | owarn << "State " << NC->state() << oendl; | ||
290 | switch( NC->state() ) { | 287 | switch( NC->state() ) { |
291 | case Disabled : // no further work | 288 | case Disabled : // no further work |
292 | IsEnabled = 0; | 289 | IsEnabled = 0; |
293 | FrmActive = 0; | 290 | FrmActive = 0; |
294 | owarn << "LEds " << leds << oendl; | ||
295 | break; | 291 | break; |
296 | case Unknown : | 292 | case Unknown : |
297 | case Unchecked : | 293 | case Unchecked : |
298 | case Unavailable : | 294 | case Unavailable : |
299 | FrmActive = 0; | 295 | FrmActive = 0; |
300 | break; | 296 | break; |
301 | case Off : | 297 | case Off : |
302 | leds = 1; | 298 | leds = 1; |
303 | break; | 299 | break; |
304 | case Available : | 300 | case Available : |
305 | leds = 2; | 301 | leds = 2; |
306 | break; | 302 | break; |
307 | case IsUp : | 303 | case IsUp : |
308 | leds = 3; | 304 | leds = 3; |
309 | break; | 305 | break; |
310 | } | 306 | } |
311 | 307 | ||
312 | Disable_TB->setOn( ! IsEnabled ); | 308 | Disable_TB->setOn( ! IsEnabled ); |
313 | LED_Frm->setEnabled( FrmActive ); | 309 | LED_Frm->setEnabled( FrmActive ); |
314 | 310 | ||
315 | for( int i = 0 ; i < leds; i ++ ) { | 311 | for( int i = 0 ; i < leds; i ++ ) { |
316 | Leds[i]->setColor( red ); | 312 | Leds[i]->setColor( red ); |
317 | Leds[i]->setOn( true ); | 313 | Leds[i]->setOn( true ); |
318 | } | 314 | } |
319 | for( int i = leds ; i < 3; i ++ ) { | 315 | for( int i = leds ; i < 3; i ++ ) { |
320 | Leds[i]->setColor( red ); | 316 | Leds[i]->setColor( red ); |
321 | Leds[i]->setOn( false ); | 317 | Leds[i]->setOn( false ); |
322 | } | 318 | } |
323 | 319 | ||
324 | Up_TB->setEnabled( leds < 3 && leds != 0 ); | 320 | Up_TB->setEnabled( leds < 3 && leds != 0 ); |
325 | Down_TB->setEnabled( leds > 0 ); | 321 | Down_TB->setEnabled( leds > 0 ); |
326 | } | 322 | } |
327 | 323 | ||
328 | void NetworkSettings::SLOT_CheckState( void ) { | 324 | void NetworkSettings::SLOT_CheckState( void ) { |
329 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 325 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
330 | if ( ! LBI ) | 326 | if ( ! LBI ) |
331 | return; | 327 | return; |
332 | updateProfileState( LBI ); | 328 | updateProfileState( LBI ); |
333 | } | 329 | } |
334 | 330 | ||
335 | void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { | 331 | void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { |
336 | if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) { | 332 | if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) { |
337 | SLOT_ShowNode( LBI ); | 333 | SLOT_ShowNode( LBI ); |
338 | } | 334 | } |
339 | } | 335 | } |
340 | 336 | ||
341 | void NetworkSettings::SLOT_GenerateConfig( void ) { | 337 | void NetworkSettings::SLOT_GenerateConfig( void ) { |
342 | QString S = NSD.generateSettings(); | 338 | QString S = NSD.generateSettings(); |
343 | if( ! S.isEmpty() ) { | 339 | if( ! S.isEmpty() ) { |
344 | S.insert( 0, "<p>" ); | 340 | S.insert( 0, "<p>" ); |
345 | S.append( "</p>" ); | 341 | S.append( "</p>" ); |
346 | QMessageBox::warning( | 342 | QMessageBox::warning( |
347 | 0, | 343 | 0, |
348 | tr( "Generate config" ), | 344 | tr( "Generate config" ), |
349 | S); | 345 | S); |
350 | } | 346 | } |
351 | } | 347 | } |
352 | 348 | ||
353 | void NetworkSettings::SLOT_Disable( bool T ) { | 349 | void NetworkSettings::SLOT_Disable( bool T ) { |
354 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 350 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
355 | QString Msg; | 351 | QString Msg; |
356 | 352 | ||
357 | if ( ! LBI ) | 353 | if ( ! LBI ) |
358 | return; | 354 | return; |
359 | 355 | ||
360 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); | 356 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
361 | 357 | ||
362 | owarn << "Prepare to disable" << oendl; | 358 | Log(( "Prepare to %sable\n", (T) ? "en" : "dis" )); |
363 | Msg = NC->setState( (T) ? Disable : Enable ); | 359 | Msg = NC->setState( (T) ? Disable : Enable ); |
364 | if( ! Msg.isEmpty() ) { | 360 | if( ! Msg.isEmpty() ) { |
365 | Msg.insert( 0, "<p>" ); | 361 | Msg.insert( 0, "<p>" ); |
366 | Msg.append( "</p>" ); | 362 | Msg.append( "</p>" ); |
367 | QMessageBox::warning( | 363 | QMessageBox::warning( |
368 | 0, | 364 | 0, |
369 | tr( "Activating profile" ), | 365 | tr( "Activating profile" ), |
370 | Msg ); | 366 | Msg ); |
371 | return; | 367 | return; |
372 | } | 368 | } |
373 | 369 | ||
374 | // reload new state | 370 | // reload new state |
375 | NC->state( true ); | 371 | NC->state( true ); |
376 | updateProfileState( LBI ); | 372 | updateProfileState( LBI ); |
377 | } | 373 | } |
378 | 374 | ||
379 | void NetworkSettings::SLOT_Up( void ) { | 375 | void NetworkSettings::SLOT_Up( void ) { |
380 | // bring more up | 376 | // bring more up |
381 | 377 | ||
382 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 378 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
383 | QString Msg; | 379 | QString Msg; |
384 | int led = -1; | 380 | int led = -1; |
385 | 381 | ||
386 | if ( ! LBI ) | 382 | if ( ! LBI ) |
387 | return; | 383 | return; |
388 | 384 | ||
389 | NodeCollection * NC = | 385 | NodeCollection * NC = |
390 | NSResources->findConnection( LBI->text() ); | 386 | NSResources->findConnection( LBI->text() ); |
391 | 387 | ||
392 | switch( NC->state() ) { | 388 | switch( NC->state() ) { |
393 | case Disabled : // cannot modify this state | 389 | case Disabled : // cannot modify this state |
394 | case Unknown : // cannot modify this state | 390 | case Unknown : // cannot modify this state |
395 | case Unchecked : // cannot modify this state | 391 | case Unchecked : // cannot modify this state |
396 | case Unavailable : // cannot modify this state | 392 | case Unavailable : // cannot modify this state |
397 | case IsUp : // highest UP state | 393 | case IsUp : // highest UP state |
398 | return; | 394 | return; |
399 | case Off : // -> activate | 395 | case Off : // -> activate |
400 | led = 1; | 396 | led = 1; |
401 | Down_TB->setEnabled( true ); | 397 | Down_TB->setEnabled( true ); |
402 | Log(( "Activate interface %s\n", NC->name().latin1() )); | 398 | Log(( "Activate interface %s\n", NC->name().latin1() )); |
403 | Msg = NC->setState( Activate ); | 399 | Msg = NC->setState( Activate ); |
404 | break; | 400 | break; |
405 | case Available : // -> up | 401 | case Available : // -> up |
406 | led = 2; | 402 | led = 2; |
407 | Log(( "Bring up interface %s\n", NC->name().latin1() )); | 403 | Log(( "Bring up interface %s\n", NC->name().latin1() )); |
408 | Msg = NC->setState( Up ); | 404 | Msg = NC->setState( Up ); |
409 | if( Msg.isEmpty() ) { | 405 | if( Msg.isEmpty() ) { |
410 | Up_TB->setEnabled( false ); | 406 | Up_TB->setEnabled( false ); |
411 | } | 407 | } |
412 | break; | 408 | break; |
413 | } | 409 | } |
414 | 410 | ||
415 | if( ! Msg.isEmpty() ) { | 411 | if( ! Msg.isEmpty() ) { |
416 | Msg.insert( 0, "<p>" ); | 412 | Msg.insert( 0, "<p>" ); |
417 | Msg.append( "</p>" ); | 413 | Msg.append( "</p>" ); |
418 | QMessageBox::warning( | 414 | QMessageBox::warning( |
419 | 0, | 415 | 0, |
420 | tr( "Increase availability" ), | 416 | tr( "Increase availability" ), |
421 | Msg ); | 417 | Msg ); |
422 | return; | 418 | return; |
423 | } | 419 | } |
424 | 420 | ||
425 | updateProfileState( LBI ); | 421 | updateProfileState( LBI ); |
426 | 422 | ||
427 | // set color of led we should change | 423 | // set color of led we should change |
428 | if( led > 0 ) { | 424 | if( led > 0 ) { |
429 | Leds[led]->setColor( blue ); | 425 | Leds[led]->setColor( blue ); |
430 | Leds[led]->setOn( true ); | 426 | Leds[led]->setOn( true ); |
431 | } | 427 | } |
432 | 428 | ||
433 | } | 429 | } |
434 | 430 | ||
435 | void NetworkSettings::SLOT_Down( void ) { | 431 | void NetworkSettings::SLOT_Down( void ) { |
436 | // bring more down | 432 | // bring more down |
437 | 433 | ||
438 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 434 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
439 | int led = -1; | 435 | int led = -1; |
440 | QString Msg; | 436 | QString Msg; |
441 | 437 | ||
442 | if ( ! LBI ) | 438 | if ( ! LBI ) |
443 | return; | 439 | return; |
444 | 440 | ||
445 | NodeCollection * NC = | 441 | NodeCollection * NC = |
446 | NSResources->findConnection( LBI->text() ); | 442 | NSResources->findConnection( LBI->text() ); |
447 | 443 | ||
448 | switch( NC->state() ) { | 444 | switch( NC->state() ) { |
449 | case Disabled : // cannot modify this state | 445 | case Disabled : // cannot modify this state |
450 | case Unknown : // cannot modify this state | 446 | case Unknown : // cannot modify this state |
451 | case Unchecked : // cannot modify this state | 447 | case Unchecked : // cannot modify this state |
452 | case Unavailable : // cannot modify this state | 448 | case Unavailable : // cannot modify this state |
453 | case Off : // highest DOWN state | 449 | case Off : // highest DOWN state |
454 | break; | 450 | break; |
455 | case Available : // -> down | 451 | case Available : // -> down |
456 | led = 0; | 452 | led = 0; |
457 | Log(( "Deactivate interface %s\n", NC->name().latin1() )); | 453 | Log(( "Deactivate interface %s\n", NC->name().latin1() )); |
458 | Msg = NC->setState( Deactivate ); | 454 | Msg = NC->setState( Deactivate ); |
459 | Down_TB->setEnabled( false ); | 455 | Down_TB->setEnabled( false ); |
460 | break; | 456 | break; |
461 | case IsUp : // highest UP state | 457 | case IsUp : // highest UP state |
462 | led = 1; | 458 | led = 1; |
463 | Up_TB->setEnabled( true ); | 459 | Up_TB->setEnabled( true ); |
464 | Log(( "Bring down interface %s\n", NC->name().latin1() )); | 460 | Log(( "Bring down interface %s\n", NC->name().latin1() )); |
465 | Msg = NC->setState( Down, 1 ); | 461 | Msg = NC->setState( Down, 1 ); |
466 | if( Msg.isEmpty() ) { | 462 | if( Msg.isEmpty() ) { |
467 | // remove 'up' file to make sure | 463 | // remove 'up' file to make sure |
468 | unlink ( QString().sprintf( "/tmp/Profile-%d.up", NC->number() ).latin1() );; | 464 | unlink ( QString().sprintf( "/tmp/Profile-%d.up", NC->number() ).latin1() );; |
469 | } | 465 | } |
470 | break; | 466 | break; |
471 | } | 467 | } |
472 | 468 | ||
473 | if( ! Msg.isEmpty() ) { | 469 | if( ! Msg.isEmpty() ) { |
474 | Msg.insert( 0, "<p>" ); | 470 | Msg.insert( 0, "<p>" ); |
475 | Msg.append( "</p>" ); | 471 | Msg.append( "</p>" ); |
476 | QMessageBox::warning( | 472 | QMessageBox::warning( |
477 | 0, | 473 | 0, |
478 | tr( "Decrease availability" ), | 474 | tr( "Decrease availability" ), |
479 | Msg ); | 475 | Msg ); |
480 | return; | 476 | return; |
481 | } | 477 | } |
482 | 478 | ||
483 | updateProfileState( LBI ); | 479 | updateProfileState( LBI ); |
484 | 480 | ||
485 | // set color of led we should change | 481 | // set color of led we should change |
486 | if( led >= 0 ) { | 482 | if( led >= 0 ) { |
487 | Leds[led]->setColor( blue ); | 483 | Leds[led]->setColor( blue ); |
488 | } | 484 | } |
489 | } | 485 | } |
490 | 486 | ||
491 | void NetworkSettings::SLOT_ToMessages( void ) { | 487 | void NetworkSettings::SLOT_ToMessages( void ) { |
492 | Profiles_LB->hide(); | 488 | Profiles_LB->hide(); |
493 | Profile_GB->hide(); | 489 | Profile_GB->hide(); |
494 | Messages_GB->show(); | 490 | Messages_GB->show(); |
495 | } | 491 | } |
496 | 492 | ||
497 | void NetworkSettings::SLOT_ToProfile( void ) { | 493 | void NetworkSettings::SLOT_ToProfile( void ) { |
498 | Profiles_LB->show(); | 494 | Profiles_LB->show(); |
499 | Profile_GB->show(); | 495 | Profile_GB->show(); |
500 | Messages_GB->hide(); | 496 | Messages_GB->hide(); |
501 | } | 497 | } |
502 | 498 | ||
503 | void NetworkSettings::SLOT_QCopMessage(const QCString &msg, const QByteArray &data) { | 499 | void NetworkSettings::SLOT_QCopMessage(const QCString &msg, const QByteArray &data) { |
504 | QDataStream stream( data, IO_ReadOnly ); | 500 | QDataStream stream( data, IO_ReadOnly ); |
505 | 501 | ||
506 | if( msg == "raise" ) { | 502 | if( msg == "raise" ) { |
507 | raise(); | 503 | raise(); |
508 | return; | 504 | return; |
509 | } /* if ( msg == "someMessage(int,int,int)" ) { | 505 | } /* if ( msg == "someMessage(int,int,int)" ) { |
510 | int a,b,c; | 506 | int a,b,c; |
511 | stream >> a >> b >> c; | 507 | stream >> a >> b >> c; |
512 | ... | 508 | ... |
513 | } */ | 509 | } */ |
514 | } | 510 | } |