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