-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 3 |
1 files changed, 1 insertions, 2 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index bcbf7a1..b2f5332 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp | |||
@@ -205,78 +205,77 @@ void Ntp::readLookups() | |||
205 | { | 205 | { |
206 | cfg.setGroup("lookup_"+QString::number(i)); | 206 | cfg.setGroup("lookup_"+QString::number(i)); |
207 | last = cfg.readEntry("secsSinceLast",0).toFloat(); | 207 | last = cfg.readEntry("secsSinceLast",0).toFloat(); |
208 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); | 208 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); |
209 | // qDebug("%i last %f",i,last); | 209 | // qDebug("%i last %f",i,last); |
210 | // qDebug("%i shift %f",i,shift); | 210 | // qDebug("%i shift %f",i,shift); |
211 | shiftPerSec = shift / last; | 211 | shiftPerSec = shift / last; |
212 | _shiftPerSec += shiftPerSec; | 212 | _shiftPerSec += shiftPerSec; |
213 | TableLookups->setText( i,0,QString::number(shiftPerSec)); | 213 | TableLookups->setText( i,0,QString::number(shiftPerSec)); |
214 | TableLookups->setText( i,2,QString::number(shift)); | 214 | TableLookups->setText( i,2,QString::number(shift)); |
215 | TableLookups->setText( i,1,QString::number(last)); | 215 | TableLookups->setText( i,1,QString::number(last)); |
216 | } | 216 | } |
217 | _shiftPerSec /= lookupCount+1; | 217 | _shiftPerSec /= lookupCount+1; |
218 | TextLabelShift->setText(QString::number(_shiftPerSec)+tr(" seconds")); | 218 | TextLabelShift->setText(QString::number(_shiftPerSec)+tr(" seconds")); |
219 | } | 219 | } |
220 | 220 | ||
221 | void Ntp::preditctTime() | 221 | void Ntp::preditctTime() |
222 | { | 222 | { |
223 | Config cfg("ntp",Config::User); | 223 | Config cfg("ntp",Config::User); |
224 | cfg.setGroup("lookups"); | 224 | cfg.setGroup("lookups"); |
225 | int lastTime = cfg.readNumEntry("time",0); | 225 | int lastTime = cfg.readNumEntry("time",0); |
226 | setenv( "TZ", tz->currentZone(), 1 ); | 226 | setenv( "TZ", tz->currentZone(), 1 ); |
227 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 227 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
228 | int corr = int((now - lastTime) * _shiftPerSec); | 228 | int corr = int((now - lastTime) * _shiftPerSec); |
229 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); | 229 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); |
230 | predictedTime = QDateTime::currentDateTime().addSecs(corr); | 230 | predictedTime = QDateTime::currentDateTime().addSecs(corr); |
231 | TextLabelPredTime->setText(predictedTime.toString()); | 231 | TextLabelPredTime->setText(predictedTime.toString()); |
232 | TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); | 232 | TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); |
233 | } | 233 | } |
234 | 234 | ||
235 | void Ntp::setPredictTime() | 235 | void Ntp::setPredictTime() |
236 | { | 236 | { |
237 | preditctTime(); | 237 | preditctTime(); |
238 | setTime( predictedTime ); | 238 | setTime( predictedTime ); |
239 | } | 239 | } |
240 | 240 | ||
241 | void Ntp::slotCheckNtp(int i) | 241 | void Ntp::slotCheckNtp(int i) |
242 | { | 242 | { |
243 | if (i == 0) | 243 | if (i == 0) |
244 | { | 244 | { |
245 | TextLabelMainPredTime->hide(); | 245 | TextLabelMainPredTime->hide(); |
246 | ButtonSetTime->setText( tr("Get time from network") ); | 246 | ButtonSetTime->setText( tr("Get time from network") ); |
247 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); | 247 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); |
248 | if ( ntpDelayElapsed() ) | 248 | if ( ntpDelayElapsed() ) |
249 | { | 249 | { |
250 | slotRunNtp(); | 250 | slotRunNtp(); |
251 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); | 251 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); |
252 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); | 252 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); |
253 | }else{ | 253 | }else{ |
254 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); | 254 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); |
255 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 255 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
256 | } | 256 | } |
257 | }else{ | 257 | }else{ |
258 | preditctTime(); | 258 | preditctTime(); |
259 | ButtonSetTime->setText( tr("Set predicted time") ); | 259 | ButtonSetTime->setText( tr("Set predicted time") ); |
260 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); | 260 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); |
261 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); | 261 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); |
262 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 262 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
263 | } | 263 | } |
264 | //ntpTimer->start(SpinBoxNtpDelay->value()*1000*60); | 264 | //ntpTimer->start(SpinBoxNtpDelay->value()*1000*60); |
265 | } | 265 | } |
266 | 266 | ||
267 | void Ntp::slotProbeNtpServer() | 267 | void Ntp::slotProbeNtpServer() |
268 | { | 268 | { |
269 | if ( ntpDelayElapsed() ) | 269 | ntpSock->connectToHost( getNtpServer() ,123); |
270 | ntpSock->connectToHost( getNtpServer() ,123); | ||
271 | } | 270 | } |
272 | 271 | ||
273 | void Ntp::slotNtpDelayChanged(int delay) | 272 | void Ntp::slotNtpDelayChanged(int delay) |
274 | { | 273 | { |
275 | ntpTimer->changeInterval( delay*1000*60 ); | 274 | ntpTimer->changeInterval( delay*1000*60 ); |
276 | } | 275 | } |
277 | 276 | ||
278 | void Ntp::ntpOutPut(QString out) | 277 | void Ntp::ntpOutPut(QString out) |
279 | { | 278 | { |
280 | MultiLineEditntpOutPut->append(out); | 279 | MultiLineEditntpOutPut->append(out); |
281 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); | 280 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); |
282 | } | 281 | } |