summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/mainwindow.cpp6
1 files changed, 0 insertions, 6 deletions
diff --git a/noncore/settings/netsystemtime/mainwindow.cpp b/noncore/settings/netsystemtime/mainwindow.cpp
index 85a46b7..2d240ba 100644
--- a/noncore/settings/netsystemtime/mainwindow.cpp
+++ b/noncore/settings/netsystemtime/mainwindow.cpp
@@ -1,364 +1,358 @@
1/* 1/*
2                This file is part of the OPIE Project 2                This file is part of the OPIE Project
3 =. 3 =.
4             .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?> 4             .=l. Copyright (c) 2002 OPIE team <opie@handhelds.org?>
5           .>+-= 5           .>+-=
6 _;:,     .>    :=|. This file is free software; you can 6 _;:,     .>    :=|. This file is free software; you can
7.> <`_,   >  .   <= redistribute it and/or modify it under 7.> <`_,   >  .   <= redistribute it and/or modify it under
8:`=1 )Y*s>-.--   : the terms of the GNU General Public 8:`=1 )Y*s>-.--   : the terms of the GNU General Public
9.="- .-=="i,     .._ License as published by the Free Software 9.="- .-=="i,     .._ License as published by the Free Software
10 - .   .-<_>     .<> Foundation; either version 2 of the License, 10 - .   .-<_>     .<> Foundation; either version 2 of the License,
11     ._= =}       : or (at your option) any later version. 11     ._= =}       : or (at your option) any later version.
12    .%`+i>       _;_. 12    .%`+i>       _;_.
13    .i_,=:_.      -<s. This file is distributed in the hope that 13    .i_,=:_.      -<s. This file is distributed in the hope that
14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY; 14     +  .  -:.       = it will be useful, but WITHOUT ANY WARRANTY;
15    : ..    .:,     . . . without even the implied warranty of 15    : ..    .:,     . . . without even the implied warranty of
16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A 16    =_        +     =;=|` MERCHANTABILITY or FITNESS FOR A
17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General 17  _.=:.       :    :=>`: PARTICULAR PURPOSE. See the GNU General
18..}^=.=       =       ; Public License for more details. 18..}^=.=       =       ; Public License for more details.
19++=   -.     .`     .: 19++=   -.     .`     .:
20 :     =  ...= . :.=- You should have received a copy of the GNU 20 :     =  ...= . :.=- You should have received a copy of the GNU
21 -.   .:....=;==+<; General Public License along with this file; 21 -.   .:....=;==+<; General Public License along with this file;
22  -_. . .   )=.  = see the file COPYING. If not, write to the 22  -_. . .   )=.  = see the file COPYING. If not, write to the
23    --        :-=` Free Software Foundation, Inc., 23    --        :-=` Free Software Foundation, Inc.,
24 59 Temple Place - Suite 330, 24 59 Temple Place - Suite 330,
25 Boston, MA 02111-1307, USA. 25 Boston, MA 02111-1307, USA.
26 26
27*/ 27*/
28 28
29#include "mainwindow.h" 29#include "mainwindow.h"
30#include "timetabwidget.h" 30#include "timetabwidget.h"
31#include "formattabwidget.h" 31#include "formattabwidget.h"
32#include "settingstabwidget.h" 32#include "settingstabwidget.h"
33#include "ntptabwidget.h" 33#include "ntptabwidget.h"
34#include "predicttabwidget.h" 34#include "predicttabwidget.h"
35 35
36#include <opie/oprocess.h> 36#include <opie/oprocess.h>
37#include <opie/otabwidget.h> 37#include <opie/otabwidget.h>
38 38
39#include <qpe/config.h> 39#include <qpe/config.h>
40#include <qpe/datebookdb.h> 40#include <qpe/datebookdb.h>
41#include <qpe/qpeapplication.h> 41#include <qpe/qpeapplication.h>
42 42
43#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) 43#if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP)
44#include <qpe/qcopenvelope_qws.h> 44#include <qpe/qcopenvelope_qws.h>
45#endif 45#endif
46 46
47#include <qlayout.h> 47#include <qlayout.h>
48#include <qmessagebox.h> 48#include <qmessagebox.h>
49#include <qsocket.h> 49#include <qsocket.h>
50#include <qstring.h> 50#include <qstring.h>
51#include <qtimer.h> 51#include <qtimer.h>
52 52
53MainWindow::MainWindow() 53MainWindow::MainWindow()
54 : QDialog( 0x0, 0x0, TRUE, 0 ) 54 : QDialog( 0x0, 0x0, TRUE, 0 )
55{ 55{
56 setCaption( tr( "SystemTime" ) ); 56 setCaption( tr( "SystemTime" ) );
57 57
58 QVBoxLayout *layout = new QVBoxLayout( this ); 58 QVBoxLayout *layout = new QVBoxLayout( this );
59 layout->setMargin( 2 ); 59 layout->setMargin( 2 );
60 layout->setSpacing( 4 ); 60 layout->setSpacing( 4 );
61 61
62 // Create main tabbed control 62 // Create main tabbed control
63 mainWidget = new OTabWidget( this ); 63 mainWidget = new OTabWidget( this );
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 // Create QCOP channel 82 // Create QCOP channel
83 QCopChannel *channel = new QCopChannel( "QPE/Application/netsystemtime", this ); 83 QCopChannel *channel = new QCopChannel( "QPE/Application/netsystemtime", this );
84 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 84 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
85 this, SLOT(slotQCopReceive(const QCString&, const QByteArray&)) ); 85 this, SLOT(slotQCopReceive(const QCString&, const QByteArray&)) );
86 86
87 // Create NTP socket 87 // Create NTP socket
88 ntpSock = new QSocket( this ); 88 ntpSock = new QSocket( this );
89 connect( ntpSock, SIGNAL(error(int)),SLOT(slotCheckNtp(int)) ); 89 connect( ntpSock, SIGNAL(error(int)),SLOT(slotCheckNtp(int)) );
90 slotProbeNTPServer(); 90 slotProbeNTPServer();
91 91
92 // Create timer for automatic time lookups 92 // Create timer for automatic time lookups
93 ntpTimer = new QTimer( this ); 93 ntpTimer = new QTimer( this );
94 94
95 // Connect everything together 95 // Connect everything together
96 connect( timeTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) ); 96 connect( timeTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) );
97 connect( timeTab, SIGNAL(tzChanged(const QString &)), predictTab, SLOT(slotTZChanged(const QString &)) ); 97 connect( timeTab, SIGNAL(tzChanged(const QString &)), predictTab, SLOT(slotTZChanged(const QString &)) );
98 connect( timeTab, SIGNAL(getPredictedTime()), predictTab, SLOT(slotSetPredictedTime()) ); 98 connect( timeTab, SIGNAL(getPredictedTime()), predictTab, SLOT(slotSetPredictedTime()) );
99 connect( formatTab, SIGNAL(show12HourTime(int)), timeTab, SLOT(slotUse12HourTime( int )) ); 99 connect( formatTab, SIGNAL(show12HourTime(int)), timeTab, SLOT(slotUse12HourTime( int )) );
100 connect( formatTab, SIGNAL(dateFormatChanged(const DateFormat &)), 100 connect( formatTab, SIGNAL(dateFormatChanged(const DateFormat &)),
101 timeTab, SLOT(slotDateFormatChanged(const DateFormat &)) ); 101 timeTab, SLOT(slotDateFormatChanged(const DateFormat &)) );
102 connect( formatTab, SIGNAL(weekStartChanged(int)), timeTab, SLOT(slotWeekStartChanged(int)) ); 102 connect( formatTab, SIGNAL(weekStartChanged(int)), timeTab, SLOT(slotWeekStartChanged(int)) );
103 connect( settingsTab, SIGNAL(ntpDelayChanged(int)), this, SLOT(slotNTPDelayChanged(int)) ); 103 connect( settingsTab, SIGNAL(ntpDelayChanged(int)), this, SLOT(slotNTPDelayChanged(int)) );
104 connect( settingsTab, SIGNAL(displayNTPTab(bool)), this, SLOT(slotDisplayNTPTab(bool)) ); 104 connect( settingsTab, SIGNAL(displayNTPTab(bool)), this, SLOT(slotDisplayNTPTab(bool)) );
105 connect( settingsTab, SIGNAL(displayPredictTab(bool)), this, SLOT(slotDisplayPredictTab(bool)) ); 105 connect( settingsTab, SIGNAL(displayPredictTab(bool)), this, SLOT(slotDisplayPredictTab(bool)) );
106 connect( predictTab, SIGNAL(setTime(const QDateTime &)), this, SLOT(slotSetTime(const QDateTime &)) ); 106 connect( predictTab, SIGNAL(setTime(const QDateTime &)), this, SLOT(slotSetTime(const QDateTime &)) );
107 107
108 // Do initial time server check 108 // Do initial time server check
109 slotNTPDelayChanged( config.readNumEntry( "ntpRefreshFreq", 1440 ) ); 109 slotNTPDelayChanged( config.readNumEntry( "ntpRefreshFreq", 1440 ) );
110 slotCheckNtp( -1 ); 110 slotCheckNtp( -1 );
111 111
112 // Display app 112 // Display app
113 showMaximized(); 113 showMaximized();
114} 114}
115 115
116MainWindow::~MainWindow() 116MainWindow::~MainWindow()
117{ 117{
118 if ( ntpProcess ) 118 if ( ntpProcess )
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 " );
168 msg.append( QString::number( ntpDelay ) );
169 msg.append( tr( " minutes, but only " ) );
170 msg.append( QString::number( _lookupDiff / 60 ) );
171 msg.append( tr(" minutes elapsed since last lookup.<br>Continue?") );
172
173 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 ) );
174 168
175 switch ( 169 switch (
176 QMessageBox::warning( this, tr( "Continue?" ), msg, QMessageBox::Yes, QMessageBox::No ) 170 QMessageBox::warning( this, tr( "Continue?" ), msg, QMessageBox::Yes, QMessageBox::No )
177 ) 171 )
178 { 172 {
179 case QMessageBox::Yes: break; 173 case QMessageBox::Yes: break;
180 case QMessageBox::No: return; 174 case QMessageBox::No: return;
181 default: return; 175 default: return;
182 } 176 }
183 } 177 }
184 178
185 QString srv = settingsTab->ntpServer(); 179 QString srv = settingsTab->ntpServer();
186 180
187 // Send information to time server tab if enabled 181 // Send information to time server tab if enabled
188 if ( ntpTabEnabled ) 182 if ( ntpTabEnabled )
189 { 183 {
190 ntpTab->setStartTime( QDateTime::currentDateTime().toString() ); 184 ntpTab->setStartTime( QDateTime::currentDateTime().toString() );
191 QString output = tr( "Running:\nntpdate " ); 185 QString output = tr( "Running:\nntpdate " );
192 output.append( srv ); 186 output.append( srv );
193 ntpTab->addNtpOutput( output ); 187 ntpTab->addNtpOutput( output );
194 } 188 }
195 189
196 if ( !ntpProcess ) 190 if ( !ntpProcess )
197 { 191 {
198 ntpProcess = new OProcess(); 192 ntpProcess = new OProcess();
199 connect( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), 193 connect( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)),
200 this, SLOT(slotNtpOutput(OProcess*,char*,int)) ); 194 this, SLOT(slotNtpOutput(OProcess*,char*,int)) );
201 connect( ntpProcess, SIGNAL(processExited(OProcess*)), 195 connect( ntpProcess, SIGNAL(processExited(OProcess*)),
202 this, SLOT(slotNtpFinished(OProcess*)) ); 196 this, SLOT(slotNtpFinished(OProcess*)) );
203 } 197 }
204 198
205 else 199 else
206 ntpProcess->clearArguments(); 200 ntpProcess->clearArguments();
207 201
208 *ntpProcess << "ntpdate" << srv; 202 *ntpProcess << "ntpdate" << srv;
209 bool ret = ntpProcess->start( OProcess::NotifyOnExit, OProcess::AllOutput ); 203 bool ret = ntpProcess->start( OProcess::NotifyOnExit, OProcess::AllOutput );
210 if ( !ret ) 204 if ( !ret )
211 { 205 {
212 QMessageBox::critical( this, tr( "Error" ), tr( "Error while getting time from network." ) ); 206 QMessageBox::critical( this, tr( "Error" ), tr( "Error while getting time from network." ) );
213 if ( ntpTabEnabled ) 207 if ( ntpTabEnabled )
214 ntpTab->addNtpOutput( tr( "Error while executing ntpdate" ) ); 208 ntpTab->addNtpOutput( tr( "Error while executing ntpdate" ) );
215 } 209 }
216} 210}
217 211
218bool MainWindow::ntpDelayElapsed() 212bool MainWindow::ntpDelayElapsed()
219{ 213{
220 // Determine if time elapsed is greater than time delay 214 // Determine if time elapsed is greater than time delay
221 Config config( "ntp" ); 215 Config config( "ntp" );
222 config.setGroup( "lookups" ); 216 config.setGroup( "lookups" );
223 _lookupDiff = TimeConversion::toUTC( QDateTime::currentDateTime() ) - config.readNumEntry( "time", 0 ); 217 _lookupDiff = TimeConversion::toUTC( QDateTime::currentDateTime() ) - config.readNumEntry( "time", 0 );
224 if ( _lookupDiff < 0 ) 218 if ( _lookupDiff < 0 )
225 return true; 219 return true;
226 return ( _lookupDiff - ( ntpDelay * 60) ) > 0; 220 return ( _lookupDiff - ( ntpDelay * 60) ) > 0;
227} 221}
228 222
229void MainWindow::slotSetTime( const QDateTime &dt ) 223void MainWindow::slotSetTime( const QDateTime &dt )
230{ 224{
231 timeTab->setDateTime( dt ); 225 timeTab->setDateTime( dt );
232} 226}
233 227
234void MainWindow::slotQCopReceive( const QCString &msg, const QByteArray & ) 228void MainWindow::slotQCopReceive( const QCString &msg, const QByteArray & )
235{ 229{
236 if ( msg == "ntpLookup(QString)" ) 230 if ( msg == "ntpLookup(QString)" )
237 { 231 {
238 ntpInteractive = false; 232 ntpInteractive = false;
239 runNTP(); 233 runNTP();
240 } 234 }
241 if ( msg == "setPredictedTime(QString)" ) 235 if ( msg == "setPredictedTime(QString)" )
242 { 236 {
243 //setPredictTime(); 237 //setPredictTime();
244 } 238 }
245} 239}
246 240
247void MainWindow::slotDisplayNTPTab( bool display ) 241void MainWindow::slotDisplayNTPTab( bool display )
248{ 242{
249 ntpTabEnabled = display; 243 ntpTabEnabled = display;
250 244
251 // Create widget if it hasn't needed 245 // Create widget if it hasn't needed
252 if ( display && !ntpTab ) 246 if ( display && !ntpTab )
253 { 247 {
254 ntpTab = new NTPTabWidget( mainWidget ); 248 ntpTab = new NTPTabWidget( mainWidget );
255 connect( ntpTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) ); 249 connect( ntpTab, SIGNAL(getNTPTime()), this, SLOT(slotGetNTPTime()) );
256 } 250 }
257 251
258 // Display/hide tab 252 // Display/hide tab
259 display ? mainWidget->addTab( ntpTab, "netsystemtime/ntptab", tr( "Time Server" ) ) 253 display ? mainWidget->addTab( ntpTab, "netsystemtime/ntptab", tr( "Time Server" ) )
260 : mainWidget->removePage( ntpTab ); 254 : mainWidget->removePage( ntpTab );
261} 255}
262 256
263void MainWindow::slotDisplayPredictTab( bool display ) 257void MainWindow::slotDisplayPredictTab( bool display )
264{ 258{
265 predictTabEnabled = display; 259 predictTabEnabled = display;
266 260
267 // Create widget if it hasn't needed 261 // Create widget if it hasn't needed
268 if ( display && !predictTab ) 262 if ( display && !predictTab )
269 { 263 {
270 } 264 }
271 // Display/hide tab 265 // Display/hide tab
272 display ? mainWidget->addTab( predictTab, "netsystemtime/predicttab", tr( "Predict" ) ) 266 display ? mainWidget->addTab( predictTab, "netsystemtime/predicttab", tr( "Predict" ) )
273 : mainWidget->removePage( predictTab ); 267 : mainWidget->removePage( predictTab );
274} 268}
275 269
276void MainWindow::slotGetNTPTime() 270void MainWindow::slotGetNTPTime()
277{ 271{
278 ntpInteractive = TRUE; 272 ntpInteractive = TRUE;
279 runNTP(); 273 runNTP();
280} 274}
281 275
282void MainWindow::slotTimerGetNTPTime() 276void MainWindow::slotTimerGetNTPTime()
283{ 277{
284 ntpInteractive = FALSE; 278 ntpInteractive = FALSE;
285 runNTP(); 279 runNTP();
286} 280}
287 281
288void MainWindow::slotProbeNTPServer() 282void MainWindow::slotProbeNTPServer()
289{ 283{
290 ntpSock->connectToHost( settingsTab->ntpServer(), 123 ); 284 ntpSock->connectToHost( settingsTab->ntpServer(), 123 );
291} 285}
292 286
293void MainWindow::slotNtpOutput( OProcess *, char *buffer, int buflen ) 287void MainWindow::slotNtpOutput( OProcess *, char *buffer, int buflen )
294{ 288{
295 QString output = QString( buffer ).left( buflen ); 289 QString output = QString( buffer ).left( buflen );
296 ntpOutput.append( output ); 290 ntpOutput.append( output );
297 291
298 if ( ntpTabEnabled ) 292 if ( ntpTabEnabled )
299 ntpTab->addNtpOutput( output ); 293 ntpTab->addNtpOutput( output );
300} 294}
301 295
302void MainWindow::slotNtpFinished( OProcess *p ) 296void MainWindow::slotNtpFinished( OProcess *p )
303{ 297{
304 QString output; 298 QString output;
305 QDateTime dt = QDateTime::currentDateTime(); 299 QDateTime dt = QDateTime::currentDateTime();
306 300
307 // Verify run was successful 301 // Verify run was successful
308 if ( p->exitStatus() != 0 || !p->normalExit() ) 302 if ( p->exitStatus() != 0 || !p->normalExit() )
309 { 303 {
310 if ( isVisible() && ntpInteractive ) 304 if ( isVisible() && ntpInteractive )
311 { 305 {
312 output = tr( "Error while getting time from\n server: " ); 306 output = tr( "Error while getting time from\n server: " );
313 output.append( settingsTab->ntpServer() ); 307 output.append( settingsTab->ntpServer() );
314 QMessageBox::critical(this, tr( "Error" ), output ); 308 QMessageBox::critical(this, tr( "Error" ), output );
315 } 309 }
316 // slotCheckNtp(-1); 310 // slotCheckNtp(-1);
317 return; 311 return;
318 } 312 }
319 313
320 // Set controls on time tab to new time value 314 // Set controls on time tab to new time value
321 timeTab->setDateTime( dt ); 315 timeTab->setDateTime( dt );
322 316
323 // Write out lookup information 317 // Write out lookup information
324 Config config( "ntp" ); 318 Config config( "ntp" );
325 config.setGroup( "lookups" ); 319 config.setGroup( "lookups" );
326 int lastLookup = config.readNumEntry( "time", 0 ); 320 int lastLookup = config.readNumEntry( "time", 0 );
327 int lookupCount = config.readNumEntry( "count", 0 ); 321 int lookupCount = config.readNumEntry( "count", 0 );
328 bool lastNtp = config.readBoolEntry( "lastNtp", FALSE ); 322 bool lastNtp = config.readBoolEntry( "lastNtp", FALSE );
329 int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); 323 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
330 config.writeEntry( "time", time ); 324 config.writeEntry( "time", time );
331 325
332 // Calculate new time/time shift 326 // Calculate new time/time shift
333 QString _offset = "offset"; 327 QString _offset = "offset";
334 QString _sec = "sec"; 328 QString _sec = "sec";
335 QRegExp _reOffset = QRegExp( _offset ); 329 QRegExp _reOffset = QRegExp( _offset );
336 QRegExp _reEndOffset = QRegExp( _sec ); 330 QRegExp _reEndOffset = QRegExp( _sec );
337 int posOffset = _reOffset.match( ntpOutput ); 331 int posOffset = _reOffset.match( ntpOutput );
338 int posEndOffset = _reEndOffset.match( ntpOutput, posOffset ); 332 int posEndOffset = _reEndOffset.match( ntpOutput, posOffset );
339 posOffset += _offset.length() + 1; 333 posOffset += _offset.length() + 1;
340 QString diff = ntpOutput.mid( posOffset, posEndOffset - posOffset - 1 ); 334 QString diff = ntpOutput.mid( posOffset, posEndOffset - posOffset - 1 );
341 335
342 float timeShift = diff.toFloat(); 336 float timeShift = diff.toFloat();
343 if ( timeShift == 0.0 ) 337 if ( timeShift == 0.0 )
344 return; 338 return;
345 int secsSinceLast = time - lastLookup; 339 int secsSinceLast = time - lastLookup;
346 output = tr( "%1 seconds").arg(QString::number( timeShift )); 340 output = tr( "%1 seconds").arg(QString::number( timeShift ));
347 341
348 // Display information on time server tab 342 // Display information on time server tab
349 if ( ntpTabEnabled ) 343 if ( ntpTabEnabled )
350 { 344 {
351 ntpTab->setTimeShift( output ); 345 ntpTab->setTimeShift( output );
352 ntpTab->setNewTime( dt.toString() ); 346 ntpTab->setNewTime( dt.toString() );
353 } 347 }
354 348
355 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60 * ntpDelay ) 349 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60 * ntpDelay )
356 { 350 {
357 QString grpname = QString( "lookup_" ).append( QString::number( lookupCount ) ); 351 QString grpname = QString( "lookup_" ).append( QString::number( lookupCount ) );
358 config.setGroup( grpname ); 352 config.setGroup( grpname );
359 lookupCount++; 353 lookupCount++;
360 predictTab->setShiftPerSec( timeShift / secsSinceLast ); 354 predictTab->setShiftPerSec( timeShift / secsSinceLast );
361 config.writeEntry( "secsSinceLast", secsSinceLast ); 355 config.writeEntry( "secsSinceLast", secsSinceLast );
362 config.writeEntry( "timeShift", QString::number( timeShift ) ); 356 config.writeEntry( "timeShift", QString::number( timeShift ) );
363 config.setGroup( "lookups" ); 357 config.setGroup( "lookups" );
364 config.writeEntry( "count", lookupCount ); 358 config.writeEntry( "count", lookupCount );