Diffstat (limited to 'noncore/settings/networksettings2/networksettings.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/networksettings2/networksettings.cpp | 52 |
1 files changed, 23 insertions, 29 deletions
diff --git a/noncore/settings/networksettings2/networksettings.cpp b/noncore/settings/networksettings2/networksettings.cpp index 6ee4106..ce0eabc 100644 --- a/noncore/settings/networksettings2/networksettings.cpp +++ b/noncore/settings/networksettings2/networksettings.cpp | |||
@@ -1,120 +1,125 @@ | |||
1 | #include <stdio.h> | 1 | #include <stdio.h> |
2 | #include <unistd.h> | 2 | #include <unistd.h> |
3 | #include <errno.h> | ||
3 | 4 | ||
4 | #include <qpe/qpeapplication.h> | 5 | #include <qpe/qpeapplication.h> |
5 | #include <qlistbox.h> | 6 | #include <qlistbox.h> |
6 | #include <qgroupbox.h> | 7 | #include <qgroupbox.h> |
7 | #include <qtimer.h> | 8 | #include <qtimer.h> |
8 | #include <qlistbox.h> | 9 | #include <qlistbox.h> |
9 | #include <qmessagebox.h> | 10 | #include <qmessagebox.h> |
10 | #include <qlabel.h> | 11 | #include <qlabel.h> |
11 | #include <qiconview.h> | 12 | #include <qiconview.h> |
12 | #include <qtimer.h> | 13 | #include <qtimer.h> |
13 | #include <qpe/qpeapplication.h> | 14 | #include <qpe/qpeapplication.h> |
14 | #include <qtoolbutton.h> | 15 | #include <qtoolbutton.h> |
16 | #include <qevent.h> | ||
15 | 17 | ||
16 | #include <asdevice.h> | 18 | #include <asdevice.h> |
17 | #include "networksettings.h" | 19 | #include "networksettings.h" |
18 | #include "netnode.h" | 20 | #include "netnode.h" |
19 | #include "editconnection.h" | 21 | #include "editconnection.h" |
20 | 22 | ||
21 | NetworkSettings::NetworkSettings( QWidget *parent, | 23 | NetworkSettings::NetworkSettings( QWidget *parent, |
22 | const char *name, | 24 | const char *name, |
23 | WFlags fl ) : NetworkSettingsGUI(parent,name,fl), | 25 | WFlags fl ) : NetworkSettingsGUI(parent,name,fl), |
24 | NSD() { | 26 | NSD() { |
25 | 27 | ||
26 | UpdateTimer = new QTimer( this ); | 28 | UpdateTimer = new QTimer( this ); |
27 | 29 | ||
28 | // set pixmaps | 30 | // set pixmaps |
29 | Add_TB->setPixmap( NSResources->getPixmap( "add" ) ); | 31 | Add_TB->setPixmap( NSResources->getPixmap( "add" ) ); |
30 | Delete_TB->setPixmap( NSResources->getPixmap( "remove" ) ); | 32 | Delete_TB->setPixmap( NSResources->getPixmap( "remove" ) ); |
31 | CheckState_TB->setPixmap( NSResources->getPixmap( "check" ) ); | 33 | CheckState_TB->setPixmap( NSResources->getPixmap( "check" ) ); |
32 | Enable_TB->setPixmap( NSResources->getPixmap( "disabled" ) ); | 34 | Enable_TB->setPixmap( NSResources->getPixmap( "disabled" ) ); |
33 | GenConfig_TB->setPixmap( NSResources->getPixmap( "configure" ) ); | 35 | GenConfig_TB->setPixmap( NSResources->getPixmap( "configure" ) ); |
34 | 36 | ||
35 | Connect_TB->setPixmap( NSResources->getPixmap( "connected" ) ); | 37 | Connect_TB->setPixmap( NSResources->getPixmap( "connected" ) ); |
36 | Disconnect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) ); | 38 | Disconnect_TB->setPixmap( NSResources->getPixmap( "disconnected" ) ); |
37 | 39 | ||
38 | On_TB->setPixmap( NSResources->getPixmap( "off" ) ); | 40 | On_TB->setPixmap( NSResources->getPixmap( "off" ) ); |
39 | 41 | ||
40 | SLOT_ToProfile(); | 42 | SLOT_ToProfile(); |
41 | 43 | ||
42 | // populate main Listbox | 44 | // populate main Listbox |
43 | Profiles_LB->clear(); | 45 | Profiles_LB->clear(); |
46 | QPEApplication::setStylusOperation( | ||
47 | Profiles_LB->viewport(), QPEApplication::RightOnHold ); | ||
48 | |||
49 | connect( Profiles_LB, | ||
50 | SIGNAL(rightButtonPressed(QListBoxItem*,const QPoint&)), | ||
51 | this, SLOT(SLOT_EditNode(QListBoxItem*)) ); | ||
52 | |||
44 | { Name2Connection_t & M = NSResources->connections(); | 53 | { Name2Connection_t & M = NSResources->connections(); |
45 | NodeCollection * NC; | 54 | NodeCollection * NC; |
46 | // for all connections | 55 | // for all connections |
47 | for( QDictIterator<NodeCollection> it(M); | 56 | for( QDictIterator<NodeCollection> it(M); |
48 | it.current(); | 57 | it.current(); |
49 | ++it ) { | 58 | ++it ) { |
50 | NC = it.current(); | 59 | NC = it.current(); |
51 | Profiles_LB->insertItem( NC->devicePixmap(), | 60 | Profiles_LB->insertItem( NC->devicePixmap(), |
52 | NC->name() ); | 61 | NC->name() ); |
53 | } | 62 | } |
54 | } | 63 | } |
55 | 64 | ||
56 | if( Profiles_LB->count() ) { | 65 | if( Profiles_LB->count() ) { |
57 | Profiles_LB->setSelected( 0, TRUE ); | 66 | Profiles_LB->setSelected( 0, TRUE ); |
58 | } | 67 | } |
59 | 68 | ||
60 | // if no profiles -> auto popup editing | 69 | // if no profiles -> auto popup editing |
61 | if( NSResources->connections().count() == 0 ) { | 70 | if( NSResources->connections().count() == 0 ) { |
62 | QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); | 71 | QTimer::singleShot( 100, this, SLOT(SLOT_AddNode() ) ); |
63 | } | 72 | } |
64 | 73 | ||
65 | connect( &(NSResources->system()), | 74 | connect( &(NSResources->system()), |
66 | SIGNAL( lineFromCommand(const QString &) ), | 75 | SIGNAL( lineFromCommand(const QString &) ), |
67 | this, SLOT( SLOT_CmdMessage(const QString &) ) ); | 76 | this, SLOT( SLOT_CmdMessage(const QString &) ) ); |
68 | 77 | ||
69 | UpdateTimer->start( 5000 ); | 78 | UpdateTimer->start( 5000 ); |
70 | connect( UpdateTimer, SIGNAL( timeout() ), | 79 | connect( UpdateTimer, SIGNAL( timeout() ), |
71 | this, SLOT( SLOT_RefreshStates() ) ); | 80 | this, SLOT( SLOT_RefreshStates() ) ); |
72 | 81 | ||
73 | /* Add QCopChannel */ | 82 | /* Add QCopChannel */ |
74 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), | 83 | connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), |
75 | this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) ); | 84 | this, SLOT(SLOT_QCopMessage(const QCString&,const QByteArray&)) ); |
76 | } | 85 | } |
77 | 86 | ||
78 | NetworkSettings::~NetworkSettings() { | 87 | NetworkSettings::~NetworkSettings() { |
79 | QString S; | 88 | QString S; |
80 | 89 | ||
81 | S = NSD.generateSettings(); | 90 | if( isModified() ) { |
82 | if( ! S.isEmpty() ) { | 91 | S = NSD.saveSettings(); |
83 | QMessageBox::warning( | 92 | if( ! S.isEmpty() ) { |
84 | 0, | 93 | // problem saving |
85 | tr( "In System Config" ), | 94 | QMessageBox::warning( |
86 | S | 95 | 0, |
87 | ); | 96 | tr( "Saving setup" ), S ); |
88 | } | 97 | } |
89 | 98 | ||
90 | S = NSD.saveSettings(); | 99 | SLOT_GenerateConfig(); |
91 | if( ! S.isEmpty() ) { | ||
92 | // problem saving | ||
93 | QMessageBox::warning( | ||
94 | 0, | ||
95 | tr( "Saving setup" ), S ); | ||
96 | } | 100 | } |
101 | |||
97 | } | 102 | } |
98 | 103 | ||
99 | void NetworkSettings::SLOT_CmdMessage( const QString & S ) { | 104 | void NetworkSettings::SLOT_CmdMessage( const QString & S ) { |
100 | Messages_LB->insertItem( S ); | 105 | Messages_LB->insertItem( S ); |
101 | Messages_LB->setCurrentItem( Messages_LB->count()-1 ); | 106 | Messages_LB->setCurrentItem( Messages_LB->count()-1 ); |
102 | Messages_LB->ensureCurrentVisible(); | 107 | Messages_LB->ensureCurrentVisible(); |
103 | } | 108 | } |
104 | 109 | ||
105 | void NetworkSettings::SLOT_RefreshStates( void ) { | 110 | void NetworkSettings::SLOT_RefreshStates( void ) { |
106 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember | 111 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); // remember |
107 | 112 | ||
108 | if( LBI ) { | 113 | if( LBI ) { |
109 | NodeCollection * NC; | 114 | NodeCollection * NC; |
110 | NSResources->system().probeInterfaces(); | 115 | NSResources->system().probeInterfaces(); |
111 | // update current selection only | 116 | // update current selection only |
112 | NC = NSResources->findConnection( LBI->text() ); | 117 | NC = NSResources->findConnection( LBI->text() ); |
113 | if( NC ) { | 118 | if( NC ) { |
114 | State_t OldS = NC->state(); | 119 | State_t OldS = NC->state(); |
115 | State_t NewS = NC->state(1); | 120 | State_t NewS = NC->state(1); |
116 | if( OldS != NewS ) { | 121 | if( OldS != NewS ) { |
117 | updateProfileState( LBI ); | 122 | updateProfileState( LBI ); |
118 | } | 123 | } |
119 | } | 124 | } |
120 | } | 125 | } |
@@ -124,91 +129,88 @@ void NetworkSettings::SLOT_RefreshStates( void ) { | |||
124 | bool is; | 129 | bool is; |
125 | NodeCollection * NC; | 130 | NodeCollection * NC; |
126 | 131 | ||
127 | for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) { | 132 | for( unsigned int i = 0; i < Profiles_LB->count() ; i ++ ) { |
128 | NC = NSResources->findConnection( Profiles_LB->text(i) ); | 133 | NC = NSResources->findConnection( Profiles_LB->text(i) ); |
129 | if( NC ) { | 134 | if( NC ) { |
130 | State_t OldS = NC->state(); | 135 | State_t OldS = NC->state(); |
131 | State_t NewS = NC->state(1); | 136 | State_t NewS = NC->state(1); |
132 | if( OldS != NewS ) { | 137 | if( OldS != NewS ) { |
133 | is = Profiles_LB->isSelected(i); | 138 | is = Profiles_LB->isSelected(i); |
134 | Profiles_LB->changeItem( NC->statePixmap(NewS), | 139 | Profiles_LB->changeItem( NC->statePixmap(NewS), |
135 | NC->name(), | 140 | NC->name(), |
136 | i ); | 141 | i ); |
137 | if( is ) { | 142 | if( is ) { |
138 | Profiles_LB->setSelected( i, TRUE ); | 143 | Profiles_LB->setSelected( i, TRUE ); |
139 | } | 144 | } |
140 | } | 145 | } |
141 | } | 146 | } |
142 | } | 147 | } |
143 | if( ci >= 0 ) | 148 | if( ci >= 0 ) |
144 | Profiles_LB->setCurrentItem( ci ); | 149 | Profiles_LB->setCurrentItem( ci ); |
145 | */ | 150 | */ |
146 | } | 151 | } |
147 | 152 | ||
148 | void NetworkSettings::SLOT_NoLongerBusy( void ) { | ||
149 | NSResources->busy( FALSE ); | ||
150 | } | ||
151 | void NetworkSettings::SLOT_AddNode( void ) { | 153 | void NetworkSettings::SLOT_AddNode( void ) { |
152 | SLOT_EditNode( 0 ); | 154 | SLOT_EditNode( 0 ); |
153 | } | 155 | } |
154 | 156 | ||
155 | void NetworkSettings::SLOT_DeleteNode( void ) { | 157 | void NetworkSettings::SLOT_DeleteNode( void ) { |
156 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 158 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
157 | 159 | ||
158 | if ( ! LBI ) | 160 | if ( ! LBI ) |
159 | return; | 161 | return; |
160 | 162 | ||
161 | if( QMessageBox::warning( | 163 | if( QMessageBox::warning( |
162 | 0, | 164 | 0, |
163 | tr( "Removing profile" ), | 165 | tr( "Removing profile" ), |
164 | tr( "Remove selected profile ?" ), | 166 | tr( "Remove selected profile ?" ), |
165 | 1, 0 ) == 1 ) { | 167 | 1, 0 ) == 1 ) { |
166 | NSResources->removeConnection( LBI->text() ); | 168 | NSResources->removeConnection( LBI->text() ); |
167 | delete LBI; | 169 | delete LBI; |
168 | setModified( 1 ); | 170 | setModified( 1 ); |
169 | NSD.forceGeneration(1); | ||
170 | } | 171 | } |
171 | } | 172 | } |
172 | 173 | ||
173 | void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { | 174 | void NetworkSettings::SLOT_EditNode( QListBoxItem * LBI ) { |
174 | QString OldName = ""; | 175 | QString OldName = ""; |
176 | |||
177 | printf( "------------------ Edit NOde\n" ); | ||
175 | EditConnection EC( this ); | 178 | EditConnection EC( this ); |
176 | 179 | ||
177 | if( LBI ) { | 180 | if( LBI ) { |
178 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); | 181 | NodeCollection * NC = NSResources->findConnection( LBI->text() ); |
179 | if( ! NC ) { | 182 | if( ! NC ) { |
180 | return; | 183 | return; |
181 | } | 184 | } |
182 | OldName = NC->name(); | 185 | OldName = NC->name(); |
183 | EC.setConnection( NC ); | 186 | EC.setConnection( NC ); |
184 | } | 187 | } |
185 | 188 | ||
186 | EC.showMaximized(); | 189 | EC.showMaximized(); |
187 | // disable refresh timer | 190 | // disable refresh timer |
188 | UpdateTimer->stop(); | 191 | UpdateTimer->stop(); |
189 | NSResources->busy( TRUE ); | 192 | |
190 | QTimer::singleShot( 1000, this, SLOT( SLOT_NoLongerBusy() )); | ||
191 | // we need to retry | 193 | // we need to retry |
192 | while( 1 ) { | 194 | while( 1 ) { |
193 | if( EC.exec() == QDialog::Accepted ) { | 195 | if( EC.exec() == QDialog::Accepted ) { |
194 | // toplevel item -> store | 196 | // toplevel item -> store |
195 | NodeCollection * NC = EC.connection(); | 197 | NodeCollection * NC = EC.connection(); |
196 | if( NC->isModified() ) { | 198 | if( NC->isModified() ) { |
197 | setModified( 1 ); | 199 | setModified( 1 ); |
198 | if( LBI ) { | 200 | if( LBI ) { |
199 | if( NC->name() != OldName ) { | 201 | if( NC->name() != OldName ) { |
200 | // find if new name is free | 202 | // find if new name is free |
201 | NodeCollection * LCN = NSResources->findConnection( | 203 | NodeCollection * LCN = NSResources->findConnection( |
202 | NC->name() ); | 204 | NC->name() ); |
203 | if( LCN ) { | 205 | if( LCN ) { |
204 | QMessageBox::warning( | 206 | QMessageBox::warning( |
205 | 0, | 207 | 0, |
206 | tr( "In System Config" ), | 208 | tr( "In System Config" ), |
207 | tr( "Name %1 already exists" ).arg(NC->name()) | 209 | tr( "Name %1 already exists" ).arg(NC->name()) |
208 | ); | 210 | ); |
209 | continue; // restart exec | 211 | continue; // restart exec |
210 | } // else new name | 212 | } // else new name |
211 | // new name -> remove item | 213 | // new name -> remove item |
212 | NSResources->removeConnection( OldName ); | 214 | NSResources->removeConnection( OldName ); |
213 | NSResources->addConnection( NC ); | 215 | NSResources->addConnection( NC ); |
214 | } // else not changed | 216 | } // else not changed |
@@ -298,57 +300,49 @@ void NetworkSettings::SLOT_ShowNode( QListBoxItem * LBI ) { | |||
298 | 300 | ||
299 | if( NC->description().isEmpty() ) { | 301 | if( NC->description().isEmpty() ) { |
300 | Description_LBL->setText( tr( "<<No description>>" ) ); | 302 | Description_LBL->setText( tr( "<<No description>>" ) ); |
301 | } else { | 303 | } else { |
302 | Description_LBL->setText( NC->description() ); | 304 | Description_LBL->setText( NC->description() ); |
303 | } | 305 | } |
304 | 306 | ||
305 | Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() ); | 307 | Profile_GB->setTitle( LBI->text() + " : " + NC->stateName() ); |
306 | } | 308 | } |
307 | 309 | ||
308 | void NetworkSettings::SLOT_CheckState( void ) { | 310 | void NetworkSettings::SLOT_CheckState( void ) { |
309 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 311 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
310 | if ( ! LBI ) | 312 | if ( ! LBI ) |
311 | return; | 313 | return; |
312 | updateProfileState( LBI ); | 314 | updateProfileState( LBI ); |
313 | } | 315 | } |
314 | 316 | ||
315 | void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { | 317 | void NetworkSettings::updateProfileState( QListBoxItem * LBI ) { |
316 | if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) { | 318 | if( LBI == Profiles_LB->item( Profiles_LB->currentItem() ) ) { |
317 | SLOT_ShowNode( LBI ); | 319 | SLOT_ShowNode( LBI ); |
318 | } | 320 | } |
319 | } | 321 | } |
320 | 322 | ||
321 | void NetworkSettings::SLOT_GenerateConfig( void ) { | 323 | void NetworkSettings::SLOT_GenerateConfig( void ) { |
322 | QString S = NSD.generateSettings( TRUE ); | 324 | NSD.regenerate(); |
323 | |||
324 | if( ! S.isEmpty() ) { | ||
325 | QMessageBox::warning( | ||
326 | 0, | ||
327 | tr( "Generating system configuration" ), | ||
328 | S | ||
329 | ); | ||
330 | } | ||
331 | } | 325 | } |
332 | 326 | ||
333 | void NetworkSettings::SLOT_Enable( void ) { | 327 | void NetworkSettings::SLOT_Enable( void ) { |
334 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); | 328 | QListBoxItem * LBI = Profiles_LB->item( Profiles_LB->currentItem() ); |
335 | QString Msg; | 329 | QString Msg; |
336 | if ( ! LBI ) | 330 | if ( ! LBI ) |
337 | return; | 331 | return; |
338 | 332 | ||
339 | NodeCollection * NC = | 333 | NodeCollection * NC = |
340 | NSResources->findConnection( LBI->text() ); | 334 | NSResources->findConnection( LBI->text() ); |
341 | 335 | ||
342 | bool rv; | 336 | bool rv; |
343 | switch( NC->state() ) { | 337 | switch( NC->state() ) { |
344 | case Disabled : | 338 | case Disabled : |
345 | Msg = tr( "Cannot enable profile" ); | 339 | Msg = tr( "Cannot enable profile" ); |
346 | rv = NC->setState( Enable ); | 340 | rv = NC->setState( Enable ); |
347 | break; | 341 | break; |
348 | default : | 342 | default : |
349 | Msg = tr( "Cannot disable profile" ); | 343 | Msg = tr( "Cannot disable profile" ); |
350 | rv = NC->setState( Disable ); | 344 | rv = NC->setState( Disable ); |
351 | break; | 345 | break; |
352 | } | 346 | } |
353 | 347 | ||
354 | if( ! rv ) { | 348 | if( ! rv ) { |