author | wimpie <wimpie> | 2005-01-04 01:35:26 (UTC) |
---|---|---|
committer | wimpie <wimpie> | 2005-01-04 01:35:26 (UTC) |
commit | a9c188235c97e07b0eb96b13adbcdfd4bad64767 (patch) (unidiff) | |
tree | 13f6ae5c499dc0c1d1bd4b763a1973a0fa8635cf /noncore/settings/networksettings2/networksettings.cpp | |
parent | 48b6cd5966ec6cc0b968edf10ba1a1ad96ef165f (diff) | |
download | opie-a9c188235c97e07b0eb96b13adbcdfd4bad64767.zip opie-a9c188235c97e07b0eb96b13adbcdfd4bad64767.tar.gz opie-a9c188235c97e07b0eb96b13adbcdfd4bad64767.tar.bz2 |
CONTROL files : changed version string
NS2 many changes and first release of OT2
Diffstat (limited to 'noncore/settings/networksettings2/networksettings.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/networksettings.cpp | 277 |
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 | |||
@@ -1,469 +1,514 @@ | |||
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> | ||
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> |
10 | #include <qmessagebox.h> | 14 | #include <qmessagebox.h> |
11 | #include <qlabel.h> | 15 | #include <qlabel.h> |
12 | #include <qiconview.h> | 16 | #include <qiconview.h> |
13 | #include <qtimer.h> | 17 | #include <qtimer.h> |
14 | #include <qpe/qpeapplication.h> | 18 | #include <qpe/qpeapplication.h> |
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" |
22 | 25 | ||
23 | NetworkSettings::NetworkSettings( QWidget *parent, | 26 | NetworkSettings::NetworkSettings( QWidget *parent, |
24 | const char *name, | 27 | const char *name, |
25 | WFlags fl ) : NetworkSettingsGUI(parent,name,fl), | 28 | WFlags fl ) : NetworkSettingsGUI(parent,name,fl), |
26 | NSD() { | 29 | NSD() { |
27 | 30 | ||
28 | UpdateTimer = new QTimer( this ); | 31 | UpdateTimer = new QTimer( this ); |
29 | 32 | ||
30 | // set pixmaps | 33 | // set pixmaps |
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 | ||
44 | // populate main Listbox | 58 | // populate main Listbox |
45 | Profiles_LB->clear(); | 59 | Profiles_LB->clear(); |
46 | QPEApplication::setStylusOperation( | 60 | QPEApplication::setStylusOperation( |
47 | Profiles_LB->viewport(), QPEApplication::RightOnHold ); | 61 | Profiles_LB->viewport(), QPEApplication::RightOnHold ); |
48 | 62 | ||
49 | connect( Profiles_LB, | 63 | connect( Profiles_LB, |
50 | SIGNAL(rightButtonPressed(QListBoxItem*,const QPoint&)), | 64 | SIGNAL(rightButtonPressed(QListBoxItem*,const QPoint&)), |
51 | this, SLOT(SLOT_EditNode(QListBoxItem*)) ); | 65 | this, SLOT(SLOT_EditNode(QListBoxItem*)) ); |
52 | 66 | ||
53 | { Name2Connection_t & M = NSResources->connections(); | 67 | { Name2Connection_t & M = NSResources->connections(); |
54 | NodeCollection * NC; | 68 | NodeCollection * NC; |
55 | // for all connections | 69 | // for all connections |
56 | for( QDictIterator<NodeCollection> it(M); | 70 | for( QDictIterator<NodeCollection> it(M); |
57 | it.current(); | 71 | it.current(); |
58 | ++it ) { | 72 | ++it ) { |
59 | NC = it.current(); | 73 | NC = it.current(); |
60 | Profiles_LB->insertItem( NC->devicePixmap(), | 74 | Profiles_LB->insertItem( NC->devicePixmap(), |
61 | NC->name() ); | 75 | NC->name() ); |
62 | } | 76 | } |
63 | } | 77 | } |
64 | 78 | ||
65 | if( Profiles_LB->count() ) { | 79 | if( Profiles_LB->count() ) { |
66 | Profiles_LB->setSelected( 0, TRUE ); | 80 | Profiles_LB->setSelected( 0, TRUE ); |
67 | } | 81 | } |
68 | 82 | ||
69 | // if no profiles -> auto popup editing | 83 | // if no profiles -> auto popup editing |
70 | if( NSResources->connections().count() == 0 ) { | 84 | if( NSResources->connections().count() == 0 ) { |
71 | QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); | 85 | QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); |
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 ); |
79 | connect( UpdateTimer, SIGNAL( timeout() ), | 101 | connect( UpdateTimer, SIGNAL( timeout() ), |
80 | this, SLOT( SLOT_RefreshStates() ) ); | 102 | this, SLOT( SLOT_RefreshStates() ) ); |
81 | 103 | ||
82 | /* Add QCopChannel */ | 104 | /* Add QCopChannel */ |
83 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), | 105 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), |
84 | this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) ); | 106 | this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) ); |
85 | } | 107 | } |
86 | 108 | ||
87 | NetworkSettings::~NetworkSettings() { | 109 | NetworkSettings::~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, |
96 | tr( "Saving setup" ), S ); | 122 | tr( "Saving setup" ), S ); |
97 | } | 123 | } |
98 | 124 | ||
99 | SLOT_GenerateConfig(); | 125 | SLOT_GenerateConfig(); |
126 | NSD.setModified( 0 ); | ||
100 | } | 127 | } |
101 | 128 | ||
102 | } | 129 | } |
103 | 130 | ||
104 | void NetworkSettings::SLOT_CmdMessage( const QString & S ) { | 131 | void NetworkSettings::SLOT_CmdMessage( const QString & S ) { |
105 | Messages_LB->insertItem( S ); | 132 | Messages_LB->insertItem( S ); |
106 | Messages_LB->setCurrentItem( Messages_LB->count()-1 ); | 133 | Messages_LB->setCurrentItem( Messages_LB->count()-1 ); |
107 | Messages_LB->ensureCurrentVisible(); | 134 | Messages_LB->ensureCurrentVisible(); |
108 | } | 135 | } |
109 | 136 | ||
110 | void NetworkSettings::SLOT_RefreshStates( void ) { | 137 | void NetworkSettings::SLOT_RefreshStates( void ) { |
111 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember | 138 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember |
112 | 139 | ||
113 | if( LBI ) { | 140 | if( LBI ) { |
114 | NodeCollection * NC; | 141 | NodeCollection * NC; |
115 | NSResources->system().probeInterfaces(); | 142 | NSResources->system().probeInterfaces(); |
116 | // update current selection only | 143 | // update current selection only |
117 | NC = NSResources->findConnection( LBI->text() ); | 144 | NC = NSResources->findConnection( LBI->text() ); |
118 | if( NC ) { | 145 | if( NC ) { |
119 | State_t OldS = NC->state(); | 146 | State_t OldS = NC->state(); |
120 | State_t NewS = NC->state(1); | 147 | State_t NewS = NC->state(1); |
121 | if( OldS != NewS ) { | 148 | if( OldS != NewS ) { |
122 | updateProfileState( LBI ); | 149 | updateProfileState( LBI ); |
123 | } | 150 | } |
124 | } | 151 | } |
125 | } | 152 | } |
126 | 153 | ||
127 | 154 | ||
128 | /* -> LATER !! | 155 | /* -> LATER !! |
129 | bool is; | 156 | bool is; |
130 | NodeCollection * NC; | 157 | NodeCollection * NC; |
131 | 158 | ||
132 | for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) { | 159 | for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) { |
133 | NC = NSResources->findConnection( Profiles_LB->text(i) ); | 160 | NC = NSResources->findConnection( Profiles_LB->text(i) ); |
134 | if( NC ) { | 161 | if( NC ) { |
135 | State_t OldS = NC->state(); | 162 | State_t OldS = NC->state(); |
136 | State_t NewS = NC->state(1); | 163 | State_t NewS = NC->state(1); |
137 | if( OldS != NewS ) { | 164 | if( OldS != NewS ) { |
138 | is = Profiles_LB->isSelected(i); | 165 | is = Profiles_LB->isSelected(i); |
139 | Profiles_LB->changeItem( NC->statePixmap(NewS), | 166 | Profiles_LB->changeItem( NC->statePixmap(NewS), |
140 | NC->name(), | 167 | NC->name(), |
141 | i ); | 168 | i ); |
142 | if( is ) { | 169 | if( is ) { |
143 | Profiles_LB->setSelected( i, TRUE ); | 170 | Profiles_LB->setSelected( i, TRUE ); |
144 | } | 171 | } |
145 | } | 172 | } |
146 | } | 173 | } |
147 | } | 174 | } |
148 | if( ci >= 0 ) | 175 | if( ci >= 0 ) |
149 | Profiles_LB->setCurrentItem( ci ); | 176 | Profiles_LB->setCurrentItem( ci ); |
150 | */ | 177 | */ |
151 | } | 178 | } |
152 | 179 | ||
153 | void NetworkSettings::SLOT_AddNode( void ) { | 180 | void NetworkSettings::SLOT_AddNode( void ) { |
154 | SLOT_EditNode( 0 ); | 181 | SLOT_EditNode( 0 ); |
155 | } | 182 | } |
156 | 183 | ||
157 | void NetworkSettings::SLOT_DeleteNode( void ) { | 184 | void NetworkSettings::SLOT_DeleteNode( void ) { |
158 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 185 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
159 | 186 | ||
160 | if ( ! LBI ) | 187 | if ( ! LBI ) |
161 | return; | 188 | return; |
162 | 189 | ||
163 | if( QMessageBox::warning( | 190 | if( QMessageBox::warning( |
164 | 0, | 191 | 0, |
165 | tr( "Removing profile" ), | 192 | tr( "Removing profile" ), |
166 | tr( "Remove selected profile ?" ), | 193 | tr( "Remove selected profile ?" ), |
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 | ||
174 | void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { | 201 | void 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 ) { |
181 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); | 207 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
182 | if( ! NC ) { | 208 | if( ! NC ) { |
183 | return; | 209 | return; |
184 | } | 210 | } |
185 | OldName = NC->name(); | 211 | OldName = NC->name(); |
186 | EC.setConnection( NC ); | 212 | EC.setConnection( NC ); |
187 | } | 213 | } |
188 | 214 | ||
189 | EC.showMaximized(); | 215 | EC.showMaximized(); |
190 | // disable refresh timer | 216 | // disable refresh timer |
191 | UpdateTimer->stop(); | 217 | UpdateTimer->stop(); |
192 | 218 | ||
193 | // we need to retry | 219 | // we need to retry |
194 | while( 1 ) { | 220 | while( 1 ) { |
195 | if( EC.exec() == QDialog::Accepted ) { | 221 | if( EC.exec() == QDialog::Accepted ) { |
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 |
203 | NodeCollection * LCN = NSResources->findConnection( | 228 | NodeCollection * LCN = NSResources->findConnection( |
204 | NC->name() ); | 229 | NC->name() ); |
205 | if( LCN ) { | 230 | if( LCN ) { |
206 | QMessageBox::warning( | 231 | QMessageBox::warning( |
207 | 0, | 232 | 0, |
208 | tr( "In System Config" ), | 233 | tr( "In System Config" ), |
209 | tr( "Name %1 already exists" ).arg(NC->name()) | 234 | tr( "Name %1 already exists" ).arg(NC->name()) |
210 | ); | 235 | ); |
211 | continue; // restart exec | 236 | continue; // restart exec |
212 | } // else new name | 237 | } // else new name |
213 | // new name -> remove item | 238 | // new name -> remove item |
214 | NSResources->removeConnection( OldName ); | 239 | NSResources->removeConnection( OldName ); |
215 | NSResources->addConnection( NC ); | 240 | NSResources->addConnection( NC ); |
216 | } // else not changed | 241 | } // else not changed |
217 | 242 | ||
218 | // must add it here since change will trigger event | 243 | // must add it here since change will trigger event |
219 | Profiles_LB->changeItem( NC->devicePixmap(), | 244 | Profiles_LB->changeItem( NC->devicePixmap(), |
220 | NC->name(), | 245 | NC->name(), |
221 | Profiles_LB->index( LBI ) | 246 | Profiles_LB->index( LBI ) |
222 | ); | 247 | ); |
223 | } else { | 248 | } else { |
224 | // new item | 249 | // new item |
225 | int ci = Profiles_LB->count(); | 250 | int ci = Profiles_LB->count(); |
226 | NSResources->addConnection( NC ); | 251 | NSResources->addConnection( NC ); |
227 | NC->setNumber( NSResources->assignConnectionNumber() ); | 252 | NC->setNumber( NSResources->assignConnectionNumber() ); |
228 | Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); | 253 | Profiles_LB->insertItem( NC->devicePixmap(), NC->name() ); |
229 | Profiles_LB->setSelected( ci, TRUE ); | 254 | Profiles_LB->setSelected( ci, TRUE ); |
230 | } | 255 | } |
231 | updateProfileState( LBI ); | 256 | updateProfileState( LBI ); |
232 | } | 257 | } |
233 | } else { | 258 | } else { |
234 | // cancelled : reset connection | 259 | // cancelled : reset connection |
235 | if( LBI ) { | 260 | if( LBI ) { |
236 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); | 261 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
237 | NC->reassign(); | 262 | NC->reassign(); |
238 | } | 263 | } |
239 | } | 264 | } |
240 | break; | 265 | break; |
241 | } | 266 | } |
242 | // reenable | 267 | // reenable |
243 | UpdateTimer->start( 5000 ); | 268 | UpdateTimer->start( 5000 ); |
244 | } | 269 | } |
245 | 270 | ||
246 | void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { | 271 | void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { |
247 | if( LBI == 0 ) | 272 | if( LBI == 0 ) |
248 | return; | 273 | return; |
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 | ||
310 | void NetworkSettings::SLOT_CheckState( void ) { | 328 | void NetworkSettings::SLOT_CheckState( void ) { |
311 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 329 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
312 | if ( ! LBI ) | 330 | if ( ! LBI ) |
313 | return; | 331 | return; |
314 | updateProfileState( LBI ); | 332 | updateProfileState( LBI ); |
315 | } | 333 | } |
316 | 334 | ||
317 | void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { | 335 | void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { |
318 | if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) { | 336 | if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) { |
319 | SLOT_ShowNode( LBI ); | 337 | SLOT_ShowNode( LBI ); |
320 | } | 338 | } |
321 | } | 339 | } |
322 | 340 | ||
323 | void NetworkSettings::SLOT_GenerateConfig( void ) { | 341 | void 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 | ||
327 | void NetworkSettings::SLOT_Enable( void ) { | 353 | void 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 | ||
358 | void NetworkSettings::SLOT_On( void ) { | 379 | void 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; |
363 | 388 | ||
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 | ||
392 | void NetworkSettings::SLOT_Connect( void ) { | 435 | void 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; |
397 | 444 | ||
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 | |||
431 | void 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 | ||
448 | void NetworkSettings::SLOT_ToMessages( void ) { | 491 | void 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 | ||
453 | void NetworkSettings::SLOT_ToProfile( void ) { | 497 | void 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 | } |
457 | 502 | ||
458 | void NetworkSettings::SLOT_QCopMessage(const QCString &msg, const QByteArray &data) { | 503 | void NetworkSettings::SLOT_QCopMessage(const QCString &msg, const QByteArray &data) { |
459 | QDataStream stream( data, IO_ReadOnly ); | 504 | QDataStream stream( data, IO_ReadOnly ); |
460 | 505 | ||
461 | if( msg == "raise" ) { | 506 | if( msg == "raise" ) { |
462 | raise(); | 507 | raise(); |
463 | return; | 508 | return; |
464 | } /* if ( msg == "someMessage(int,int,int)" ) { | 509 | } /* if ( msg == "someMessage(int,int,int)" ) { |
465 | int a,b,c; | 510 | int a,b,c; |
466 | stream >> a >> b >> c; | 511 | stream >> a >> b >> c; |
467 | ... | 512 | ... |
468 | } */ | 513 | } */ |
469 | } | 514 | } |