summaryrefslogtreecommitdiff
path: root/noncore/settings
Unidiff
Diffstat (limited to 'noncore/settings') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/mainwindow.cpp29
1 files changed, 16 insertions, 13 deletions
diff --git a/noncore/settings/netsystemtime/mainwindow.cpp b/noncore/settings/netsystemtime/mainwindow.cpp
index 486257f..01d9a98 100644
--- a/noncore/settings/netsystemtime/mainwindow.cpp
+++ b/noncore/settings/netsystemtime/mainwindow.cpp
@@ -64,26 +64,26 @@ MainWindow::MainWindow( QWidget *parent , const char *name, bool modal, WFlags
64 64
65 // Default object pointers to null 65 // Default object pointers to null
66 ntpProcess = 0x0; 66 ntpProcess = 0x0;
67 ntpTab = 0x0; 67 ntpTab = 0x0;
68 68
69 // Add tab widgets 69 // Add tab widgets
70 mainWidget->addTab( timeTab = new TimeTabWidget( mainWidget ), "netsystemtime/DateTime", tr( "Time" ) ); 70 mainWidget->addTab( timeTab = new TimeTabWidget( mainWidget ), "netsystemtime/DateTime", tr( "Time" ) );
71 mainWidget->addTab( formatTab = new FormatTabWidget( mainWidget ), "netsystemtime/formattab", tr( "Format" ) ); 71 mainWidget->addTab( formatTab = new FormatTabWidget( mainWidget ), "netsystemtime/formattab", tr( "Format" ) );
72 mainWidget->addTab( settingsTab = new SettingsTabWidget( mainWidget ), "SettingsIcon", tr( "Settings" ) ); 72 mainWidget->addTab( settingsTab = new SettingsTabWidget( mainWidget ), "SettingsIcon", tr( "Settings" ) );
73 mainWidget->addTab( predictTab = new PredictTabWidget( mainWidget ), "netsystemtime/predicttab", tr( "Predict" ) ); 73 mainWidget->addTab( predictTab = new PredictTabWidget( mainWidget ), "netsystemtime/predicttab", tr( "Predict" ) );
74 Config config( "ntp" ); 74 Config config( "ntp" );
75 config.setGroup( "settings" ); 75 config.setGroup( "settings" );
76 slotDisplayNTPTab( config.readBoolEntry( "displayNtpTab", FALSE ) ); 76 slotDisplayNTPTab( config.readBoolEntry( "displayNtpTab", false ) );
77 slotDisplayPredictTab( config.readBoolEntry( "displayPredictTab", FALSE ) ); 77 slotDisplayPredictTab( config.readBoolEntry( "displayPredictTab", false ) );
78 78
79 mainWidget->setCurrentTab( tr( "Time" ) ); 79 mainWidget->setCurrentTab( tr( "Time" ) );
80 layout->addWidget( mainWidget ); 80 layout->addWidget( mainWidget );
81 81
82 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), 82 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)),
83 this, SLOT(slotQCopReceive(const QCString&,const QByteArray&)) ); 83 this, SLOT(slotQCopReceive(const QCString&,const QByteArray&)) );
84 84
85 85
86 // Create NTP socket 86 // Create NTP socket
87 ntpSock = new QSocket( this ); 87 ntpSock = new QSocket( this );
88 connect( ntpSock, SIGNAL(error(int)),SLOT(slotCheckNtp(int)) ); 88 connect( ntpSock, SIGNAL(error(int)),SLOT(slotCheckNtp(int)) );
89 slotProbeNTPServer(); 89 slotProbeNTPServer();
@@ -119,51 +119,51 @@ MainWindow::~MainWindow()
119 delete ntpProcess; 119 delete ntpProcess;
120} 120}
121 121
122void MainWindow::accept() 122void MainWindow::accept()
123{ 123{
124 // Turn off the screensaver (Note: needs to be encased in { } so that it deconstructs and sends) 124 // Turn off the screensaver (Note: needs to be encased in { } so that it deconstructs and sends)
125 { 125 {
126 QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); 126 QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
127 disableScreenSaver << 0 << 0 << 0; 127 disableScreenSaver << 0 << 0 << 0;
128 } 128 }
129 129
130 // Update the systemtime 130 // Update the systemtime
131 timeTab->saveSettings( TRUE ); 131 timeTab->saveSettings( true );
132 132
133 // Save format options 133 // Save format options
134 formatTab->saveSettings( TRUE ); 134 formatTab->saveSettings( true );
135 135
136 // Save settings options 136 // Save settings options
137 settingsTab->saveSettings(); 137 settingsTab->saveSettings();
138 138
139 // Since time has changed quickly load in the DateBookDB to allow the alarm server to get a better 139 // Since time has changed quickly load in the DateBookDB to allow the alarm server to get a better
140 // grip on itself (example re-trigger alarms for when we travel back in time). 140 // grip on itself (example re-trigger alarms for when we travel back in time).
141 DateBookDB db; 141 DateBookDB db;
142 142
143 // Turn back on the screensaver 143 // Turn back on the screensaver
144 QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); 144 QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
145 enableScreenSaver << -1 << -1 << -1; 145 enableScreenSaver << -1 << -1 << -1;
146 146
147 // Exit app 147 // Exit app
148 qApp->quit(); 148 qApp->quit();
149} 149}
150 150
151void MainWindow::reject() 151void MainWindow::reject()
152{ 152{
153 // Reset time settings 153 // Reset time settings
154 timeTab->saveSettings( FALSE ); 154 timeTab->saveSettings( false );
155 155
156 // Send notifications but do not save settings 156 // Send notifications but do not save settings
157 formatTab->saveSettings( FALSE ); 157 formatTab->saveSettings( false );
158 158
159 // Exit app 159 // Exit app
160 qApp->quit(); 160 qApp->quit();
161} 161}
162 162
163void MainWindow::runNTP() 163void MainWindow::runNTP()
164{ 164{
165 if ( !ntpDelayElapsed() && ntpInteractive ) 165 if ( !ntpDelayElapsed() && ntpInteractive )
166 { 166 {
167 QString msg = tr( "You asked for a delay of %1 minutes, but only %2 minutes elapsed since last lookup.<br>Continue?" ).arg( QString::number( ntpDelay ) ).arg( QString::number( _lookupDiff / 60 ) ); 167 QString msg = tr( "You asked for a delay of %1 minutes, but only %2 minutes elapsed since last lookup.<br>Continue?" ).arg( QString::number( ntpDelay ) ).arg( QString::number( _lookupDiff / 60 ) );
168 168
169 switch ( 169 switch (
@@ -176,53 +176,55 @@ void MainWindow::runNTP()
176 } 176 }
177 } 177 }
178 178
179 QString srv = settingsTab->ntpServer(); 179 QString srv = settingsTab->ntpServer();
180 180
181 // Send information to time server tab if enabled 181 // Send information to time server tab if enabled
182 if ( ntpTabEnabled ) 182 if ( ntpTabEnabled )
183 { 183 {
184 ntpTab->setStartTime( QDateTime::currentDateTime().toString() ); 184 ntpTab->setStartTime( QDateTime::currentDateTime().toString() );
185 QString output = tr( "Running:\nntpdate " ); 185 QString output = tr( "Running:\nntpdate " );
186 output.append( srv ); 186 output.append( srv );
187 ntpTab->addNtpOutput( output ); 187 ntpTab->addNtpOutput( output );
188 ntpTab->setNTPBtnEnabled( false );
188 } 189 }
189 190
190 // Disable set time buttons & change app caption to indicate time update is happening 191 // Disable set time buttons & change app caption to indicate time update is happening
191 ntpTab->setNTPBtnEnabled( false );
192 timeTab->setNTPBtnEnabled( false ); 192 timeTab->setNTPBtnEnabled( false );
193 setCaption( tr( "Retrieving time from network..." ) ); 193 setCaption( tr( "Retrieving time from network..." ) );
194 194
195 if ( !ntpProcess ) 195 if ( !ntpProcess )
196 { 196 {
197 ntpProcess = new OProcess(); 197 ntpProcess = new OProcess();
198 connect( ntpProcess, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)), 198 connect( ntpProcess, SIGNAL(receivedStdout(Opie::Core::OProcess*,char*,int)),
199 this, SLOT(slotNtpOutput(Opie::Core::OProcess*,char*,int)) ); 199 this, SLOT(slotNtpOutput(Opie::Core::OProcess*,char*,int)) );
200 connect( ntpProcess, SIGNAL(processExited(Opie::Core::OProcess*)), 200 connect( ntpProcess, SIGNAL(processExited(Opie::Core::OProcess*)),
201 this, SLOT(slotNtpFinished(Opie::Core::OProcess*)) ); 201 this, SLOT(slotNtpFinished(Opie::Core::OProcess*)) );
202 } 202 }
203 203
204 else 204 else
205 ntpProcess->clearArguments(); 205 ntpProcess->clearArguments();
206 206
207 *ntpProcess << "ntpdate" << srv; 207 *ntpProcess << "ntpdate" << srv;
208 bool ret = ntpProcess->start( OProcess::NotifyOnExit, OProcess::AllOutput ); 208 bool ret = ntpProcess->start( OProcess::NotifyOnExit, OProcess::AllOutput );
209 if ( !ret ) 209 if ( !ret )
210 { 210 {
211 QMessageBox::critical( this, tr( "Error" ), tr( "Error while getting time from network." ) ); 211 QMessageBox::critical( this, tr( "Error" ), tr( "Error while getting time from network." ) );
212 if ( ntpTabEnabled ) 212 if ( ntpTabEnabled )
213 {
213 ntpTab->addNtpOutput( tr( "Error while executing ntpdate" ) ); 214 ntpTab->addNtpOutput( tr( "Error while executing ntpdate" ) );
215 ntpTab->setNTPBtnEnabled( true );
216 }
214 217
215 // Re-enable set time buttons & change app caption to indicate time update is happening 218 // Re-enable set time buttons & change app caption to indicate time update is happening
216 ntpTab->setNTPBtnEnabled( true );
217 timeTab->setNTPBtnEnabled( true ); 219 timeTab->setNTPBtnEnabled( true );
218 setCaption( tr( "SystemTime" ) ); 220 setCaption( tr( "SystemTime" ) );
219 } 221 }
220} 222}
221 223
222bool MainWindow::ntpDelayElapsed() 224bool MainWindow::ntpDelayElapsed()
223{ 225{
224 // Determine if time elapsed is greater than time delay 226 // Determine if time elapsed is greater than time delay
225 Config config( "ntp" ); 227 Config config( "ntp" );
226 config.setGroup( "lookups" ); 228 config.setGroup( "lookups" );
227 _lookupDiff = TimeConversion::toUTC( QDateTime::currentDateTime() ) - config.readNumEntry( "time", 0 ); 229 _lookupDiff = TimeConversion::toUTC( QDateTime::currentDateTime() ) - config.readNumEntry( "time", 0 );
228 if ( _lookupDiff < 0 ) 230 if ( _lookupDiff < 0 )
@@ -270,80 +272,81 @@ void MainWindow::slotDisplayPredictTab( bool display )
270 272
271 // Create widget if it hasn't needed 273 // Create widget if it hasn't needed
272 if ( display && !predictTab ) 274 if ( display && !predictTab )
273 { 275 {
274 } 276 }
275 // Display/hide tab 277 // Display/hide tab
276 display ? mainWidget->addTab( predictTab, "netsystemtime/predicttab", tr( "Predict" ) ) 278 display ? mainWidget->addTab( predictTab, "netsystemtime/predicttab", tr( "Predict" ) )
277 : mainWidget->removePage( predictTab ); 279 : mainWidget->removePage( predictTab );
278} 280}
279 281
280void MainWindow::slotGetNTPTime() 282void MainWindow::slotGetNTPTime()
281{ 283{
282 ntpInteractive = TRUE; 284 ntpInteractive = true;
283 runNTP(); 285 runNTP();
284} 286}
285 287
286void MainWindow::slotTimerGetNTPTime() 288void MainWindow::slotTimerGetNTPTime()
287{ 289{
288 ntpInteractive = FALSE; 290 ntpInteractive = false;
289 runNTP(); 291 runNTP();
290} 292}
291 293
292void MainWindow::slotProbeNTPServer() 294void MainWindow::slotProbeNTPServer()
293{ 295{
294 ntpSock->connectToHost( settingsTab->ntpServer(), 123 ); 296 ntpSock->connectToHost( settingsTab->ntpServer(), 123 );
295} 297}
296 298
297void MainWindow::slotNtpOutput( OProcess *, char *buffer, int buflen ) 299void MainWindow::slotNtpOutput( OProcess *, char *buffer, int buflen )
298{ 300{
299 QString output = QString( buffer ).left( buflen ); 301 QString output = QString( buffer ).left( buflen );
300 ntpOutput.append( output ); 302 ntpOutput.append( output );
301 303
302 if ( ntpTabEnabled ) 304 if ( ntpTabEnabled )
303 ntpTab->addNtpOutput( output ); 305 ntpTab->addNtpOutput( output );
304} 306}
305 307
306void MainWindow::slotNtpFinished( OProcess *p ) 308void MainWindow::slotNtpFinished( OProcess *p )
307{ 309{
308 QString output; 310 QString output;
309 QDateTime dt = QDateTime::currentDateTime(); 311 QDateTime dt = QDateTime::currentDateTime();
310 312
311 // Re-enable set time buttons & change app caption to indicate time update is happening 313 // Re-enable set time buttons & change app caption to indicate time update is happening
312 ntpTab->setNTPBtnEnabled( true ); 314 if ( ntpTabEnabled )
315 ntpTab->setNTPBtnEnabled( true );
313 timeTab->setNTPBtnEnabled( true ); 316 timeTab->setNTPBtnEnabled( true );
314 setCaption( tr( "SystemTime" ) ); 317 setCaption( tr( "SystemTime" ) );
315 318
316 // Verify run was successful 319 // Verify run was successful
317 if ( p->exitStatus() != 0 || !p->normalExit() ) 320 if ( p->exitStatus() != 0 || !p->normalExit() )
318 { 321 {
319 if ( isVisible() && ntpInteractive ) 322 if ( isVisible() && ntpInteractive )
320 { 323 {
321 output = tr( "Error while getting time from\n server: " ); 324 output = tr( "Error while getting time from\n server: " );
322 output.append( settingsTab->ntpServer() ); 325 output.append( settingsTab->ntpServer() );
323 QMessageBox::critical(this, tr( "Error" ), output ); 326 QMessageBox::critical(this, tr( "Error" ), output );
324 } 327 }
325 // slotCheckNtp(-1); 328 // slotCheckNtp(-1);
326 return; 329 return;
327 } 330 }
328 331
329 // Set controls on time tab to new time value 332 // Set controls on time tab to new time value
330 timeTab->setDateTime( dt ); 333 timeTab->setDateTime( dt );
331 334
332 // Write out lookup information 335 // Write out lookup information
333 Config config( "ntp" ); 336 Config config( "ntp" );
334 config.setGroup( "lookups" ); 337 config.setGroup( "lookups" );
335 int lastLookup = config.readNumEntry( "time", 0 ); 338 int lastLookup = config.readNumEntry( "time", 0 );
336 int lookupCount = config.readNumEntry( "count", 0 ); 339 int lookupCount = config.readNumEntry( "count", 0 );
337 bool lastNtp = config.readBoolEntry( "lastNtp", FALSE ); 340 bool lastNtp = config.readBoolEntry( "lastNtp", false );
338 int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); 341 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
339 config.writeEntry( "time", time ); 342 config.writeEntry( "time", time );
340 343
341 // Calculate new time/time shift 344 // Calculate new time/time shift
342 QString _offset = "offset"; 345 QString _offset = "offset";
343 QString _sec = "sec"; 346 QString _sec = "sec";
344 QRegExp _reOffset = QRegExp( _offset ); 347 QRegExp _reOffset = QRegExp( _offset );
345 QRegExp _reEndOffset = QRegExp( _sec ); 348 QRegExp _reEndOffset = QRegExp( _sec );
346 int posOffset = _reOffset.match( ntpOutput ); 349 int posOffset = _reOffset.match( ntpOutput );
347 int posEndOffset = _reEndOffset.match( ntpOutput, posOffset ); 350 int posEndOffset = _reEndOffset.match( ntpOutput, posOffset );
348 posOffset += _offset.length() + 1; 351 posOffset += _offset.length() + 1;
349 QString diff = ntpOutput.mid( posOffset, posEndOffset - posOffset - 1 ); 352 QString diff = ntpOutput.mid( posOffset, posEndOffset - posOffset - 1 );
@@ -362,25 +365,25 @@ void MainWindow::slotNtpFinished( OProcess *p )
362 } 365 }
363 366
364 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60 * ntpDelay ) 367 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60 * ntpDelay )
365 { 368 {
366 QString grpname = QString( "lookup_" ).append( QString::number( lookupCount ) ); 369 QString grpname = QString( "lookup_" ).append( QString::number( lookupCount ) );
367 config.setGroup( grpname ); 370 config.setGroup( grpname );
368 lookupCount++; 371 lookupCount++;
369 predictTab->setShiftPerSec( (int)(timeShift / secsSinceLast) ); 372 predictTab->setShiftPerSec( (int)(timeShift / secsSinceLast) );
370 config.writeEntry( "secsSinceLast", secsSinceLast ); 373 config.writeEntry( "secsSinceLast", secsSinceLast );
371 config.writeEntry( "timeShift", QString::number( timeShift ) ); 374 config.writeEntry( "timeShift", QString::number( timeShift ) );
372 config.setGroup( "lookups" ); 375 config.setGroup( "lookups" );
373 config.writeEntry( "count", lookupCount ); 376 config.writeEntry( "count", lookupCount );
374 config.writeEntry( "lastNtp", TRUE ); 377 config.writeEntry( "lastNtp", true );
375 } 378 }
376} 379}
377 380
378void MainWindow::slotNTPDelayChanged( int delay ) 381void MainWindow::slotNTPDelayChanged( int delay )
379{ 382{
380 ntpTimer->changeInterval( delay * 1000 * 60 ); 383 ntpTimer->changeInterval( delay * 1000 * 60 );
381 ntpDelay = delay; 384 ntpDelay = delay;
382} 385}
383 386
384void MainWindow::slotCheckNtp( int i ) 387void MainWindow::slotCheckNtp( int i )
385{ 388{
386 if ( i == 0 ) 389 if ( i == 0 )