-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 74 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntp.h | 7 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntpbase.ui | 109 |
3 files changed, 156 insertions, 34 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index 52fc6be..364609d 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp | |||
@@ -1,6 +1,7 @@ | |||
1 | #include "ntp.h" | 1 | #include "ntp.h" |
2 | #include <qpushbutton.h> | 2 | #include <qpushbutton.h> |
3 | #include <qregexp.h> | 3 | #include <qregexp.h> |
4 | #include <qtimer.h> | ||
4 | #include <qtable.h> | 5 | #include <qtable.h> |
5 | #include <qlabel.h> | 6 | #include <qlabel.h> |
6 | #include <qsocket.h> | 7 | #include <qsocket.h> |
@@ -23,19 +24,36 @@ | |||
23 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | 24 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) |
24 | : SetDateTime( parent, name, fl ) | 25 | : SetDateTime( parent, name, fl ) |
25 | { | 26 | { |
27 | |||
28 | Config ntpSrvs("/etc/ntpservers",Config::File); | ||
29 | ntpSrvs.setGroup("servers"); | ||
30 | int srvCount = ntpSrvs.readNumEntry("count", 0 ); | ||
31 | for (int i = 0; i < srvCount; i++) | ||
32 | { | ||
33 | ntpSrvs.setGroup(QString::number(i)); | ||
34 | ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); | ||
35 | } | ||
36 | if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); | ||
37 | |||
26 | Config cfg("ntp",Config::User); | 38 | Config cfg("ntp",Config::User); |
27 | cfg.setGroup("settings"); | 39 | cfg.setGroup("settings"); |
28 | // _maxOffset = cfg.readNumEntry("maxOffset",5); | 40 | // _maxOffset = cfg.readNumEntry("maxOffset",5); |
29 | // _minLookupDiff = cfg.readNumEntry("minLookupDiff",10); | 41 | // _minLookupDiff = cfg.readNumEntry("minLookupDiff",10); |
30 | SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",60) ); | 42 | SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) ); |
31 | SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",60) ); | 43 | SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) ); |
32 | LineEditNtpSrv->setText( cfg.readEntry("ntpServer", tr("time.fu-berlin.de")) ); | 44 | ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); |
45 | |||
46 | ntpTimer = new QTimer(this); | ||
47 | ntpTimer->start(SpinBoxNtpDelay->value()*100); | ||
48 | |||
33 | ntpProcess = new OProcess( ); | 49 | ntpProcess = new OProcess( ); |
50 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), | ||
51 | SLOT(slotNtpDelayChanged(int)) ); | ||
34 | 52 | ||
35 | QSocket *ntpSock = new QSocket( this ); | 53 | ntpSock = new QSocket( this ); |
36 | ntpSock->connectToHost( LineEditNtpSrv->text() ,123); | ||
37 | connect( ntpSock, SIGNAL( error(int) ), | 54 | connect( ntpSock, SIGNAL( error(int) ), |
38 | SLOT(slotCheckNtp(int)) ); | 55 | SLOT(slotCheckNtp(int)) ); |
56 | slotProbeNtpServer(); | ||
39 | 57 | ||
40 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), | 58 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), |
41 | this, SLOT(getNtpOutput(OProcess*,char*,int))); | 59 | this, SLOT(getNtpOutput(OProcess*,char*,int))); |
@@ -43,16 +61,26 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | |||
43 | this, SLOT(ntpFinished(OProcess*))); | 61 | this, SLOT(ntpFinished(OProcess*))); |
44 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); | 62 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); |
45 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); | 63 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); |
64 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); | ||
46 | slotCheckNtp(-1); | 65 | slotCheckNtp(-1); |
47 | // slotRunNtp(); | ||
48 | readLookups(); | 66 | readLookups(); |
49 | } | 67 | } |
50 | 68 | ||
51 | Ntp::~Ntp() | 69 | Ntp::~Ntp() |
52 | { | 70 | { |
71 | delete ntpProcess; | ||
72 | Config ntpSrvs("/etc/ntpservers",Config::File); | ||
73 | ntpSrvs.setGroup("servers"); | ||
74 | int srvCount = ComboNtpSrv->count(); | ||
75 | ntpSrvs.writeEntry("count", srvCount); | ||
76 | for (int i = 0; i < srvCount; i++) | ||
77 | { | ||
78 | ntpSrvs.setGroup(QString::number(i)); | ||
79 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); | ||
80 | } | ||
53 | Config cfg("ntp",Config::User); | 81 | Config cfg("ntp",Config::User); |
54 | cfg.setGroup("settings"); | 82 | cfg.setGroup("settings"); |
55 | cfg.writeEntry("ntpServer", LineEditNtpSrv->text()); | 83 | cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); |
56 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); | 84 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); |
57 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); | 85 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); |
58 | } | 86 | } |
@@ -79,8 +107,9 @@ void Ntp::slotRunNtp() | |||
79 | } | 107 | } |
80 | } | 108 | } |
81 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); | 109 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); |
110 | MultiLineEditntpOutPut->append( "\n"+tr("Running:")+"\nntpdate "+ ComboNtpSrv->currentText()+"\n"); | ||
82 | ntpProcess->clearArguments(); | 111 | ntpProcess->clearArguments(); |
83 | *ntpProcess << "ntpdate" << LineEditNtpSrv->text(); | 112 | *ntpProcess << "ntpdate" << ComboNtpSrv->currentText(); |
84 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); | 113 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); |
85 | if ( !ret ) { | 114 | if ( !ret ) { |
86 | qDebug("Error while executing ntp"); | 115 | qDebug("Error while executing ntp"); |
@@ -190,6 +219,7 @@ void Ntp::preditctTime() | |||
190 | setenv( "TZ", tz->currentZone(), 1 ); | 219 | setenv( "TZ", tz->currentZone(), 1 ); |
191 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 220 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
192 | int corr = int((now - lastTime) * _shiftPerSec); | 221 | int corr = int((now - lastTime) * _shiftPerSec); |
222 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); | ||
193 | predictedTime = QDateTime::currentDateTime().addSecs(corr); | 223 | predictedTime = QDateTime::currentDateTime().addSecs(corr); |
194 | TextLabelPredTime->setText(predictedTime.toString()); | 224 | TextLabelPredTime->setText(predictedTime.toString()); |
195 | TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); | 225 | TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); |
@@ -208,9 +238,35 @@ void Ntp::slotCheckNtp(int i) | |||
208 | TextLabelMainPredTime->hide(); | 238 | TextLabelMainPredTime->hide(); |
209 | ButtonSetTime->setText( tr("Get time from network") ); | 239 | ButtonSetTime->setText( tr("Get time from network") ); |
210 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); | 240 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); |
241 | Config cfg("ntp",Config::User); | ||
242 | cfg.setGroup("lookups"); | ||
243 | int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); | ||
244 | if ( lookupDiff > SpinBoxNtpDelay->value()*60 ) | ||
245 | { | ||
246 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); | ||
247 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); | ||
248 | }else{ | ||
249 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); | ||
250 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | ||
251 | } | ||
211 | }else{ | 252 | }else{ |
212 | preditctTime(); | 253 | preditctTime(); |
213 | ButtonSetTime->setText( tr("Set predicted time") ); | 254 | ButtonSetTime->setText( tr("Set predicted time") ); |
214 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); | 255 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); |
215 | }; | 256 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
257 | } | ||
258 | } | ||
259 | |||
260 | void Ntp::slotProbeNtpServer() | ||
261 | { | ||
262 | Config cfg("ntp",Config::User); | ||
263 | cfg.setGroup("lookups"); | ||
264 | int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); | ||
265 | if ( lookupDiff > SpinBoxNtpDelay->value()*60 ) | ||
266 | ntpSock->connectToHost( ComboNtpSrv->currentText() ,123); | ||
267 | } | ||
268 | |||
269 | void Ntp::slotNtpDelayChanged(int delay) | ||
270 | { | ||
271 | ntpTimer->changeInterval( delay*100 ); | ||
216 | } | 272 | } |
diff --git a/noncore/settings/netsystemtime/ntp.h b/noncore/settings/netsystemtime/ntp.h index 284ae27..7cc309f 100644 --- a/noncore/settings/netsystemtime/ntp.h +++ b/noncore/settings/netsystemtime/ntp.h | |||
@@ -5,7 +5,8 @@ | |||
5 | 5 | ||
6 | class OProcess; | 6 | class OProcess; |
7 | class QString; | 7 | class QString; |
8 | 8 | class QTimer; | |
9 | class QSocket; | ||
9 | 10 | ||
10 | class Ntp : public SetDateTime | 11 | class Ntp : public SetDateTime |
11 | { | 12 | { |
@@ -23,6 +24,8 @@ private: | |||
23 | QString _ntpOutput; | 24 | QString _ntpOutput; |
24 | float _shiftPerSec; | 25 | float _shiftPerSec; |
25 | OProcess *ntpProcess; | 26 | OProcess *ntpProcess; |
27 | QTimer *ntpTimer; | ||
28 | QSocket *ntpSock; | ||
26 | 29 | ||
27 | float getTimeShift(); | 30 | float getTimeShift(); |
28 | void readLookups(); | 31 | void readLookups(); |
@@ -33,6 +36,8 @@ private slots: | |||
33 | void preditctTime(); | 36 | void preditctTime(); |
34 | void slotCheckNtp(int); | 37 | void slotCheckNtp(int); |
35 | void setPredictTime(); | 38 | void setPredictTime(); |
39 | void slotProbeNtpServer(); | ||
40 | void slotNtpDelayChanged(int); | ||
36 | }; | 41 | }; |
37 | 42 | ||
38 | #endif | 43 | #endif |
diff --git a/noncore/settings/netsystemtime/ntpbase.ui b/noncore/settings/netsystemtime/ntpbase.ui index 8d32849..4e10fd2 100644 --- a/noncore/settings/netsystemtime/ntpbase.ui +++ b/noncore/settings/netsystemtime/ntpbase.ui | |||
@@ -11,8 +11,8 @@ | |||
11 | <rect> | 11 | <rect> |
12 | <x>0</x> | 12 | <x>0</x> |
13 | <y>0</y> | 13 | <y>0</y> |
14 | <width>330</width> | 14 | <width>331</width> |
15 | <height>419</height> | 15 | <height>426</height> |
16 | </rect> | 16 | </rect> |
17 | </property> | 17 | </property> |
18 | <property stdset="1"> | 18 | <property stdset="1"> |
@@ -109,7 +109,7 @@ | |||
109 | </property> | 109 | </property> |
110 | <property stdset="1"> | 110 | <property stdset="1"> |
111 | <name>text</name> | 111 | <name>text</name> |
112 | <string>get time from network</string> | 112 | <string>Get time from network</string> |
113 | </property> | 113 | </property> |
114 | </widget> | 114 | </widget> |
115 | <widget row="0" column="0" > | 115 | <widget row="0" column="0" > |
@@ -287,11 +287,11 @@ | |||
287 | <grid> | 287 | <grid> |
288 | <property stdset="1"> | 288 | <property stdset="1"> |
289 | <name>margin</name> | 289 | <name>margin</name> |
290 | <number>2</number> | 290 | <number>5</number> |
291 | </property> | 291 | </property> |
292 | <property stdset="1"> | 292 | <property stdset="1"> |
293 | <name>spacing</name> | 293 | <name>spacing</name> |
294 | <number>2</number> | 294 | <number>6</number> |
295 | </property> | 295 | </property> |
296 | <widget row="0" column="0" > | 296 | <widget row="0" column="0" > |
297 | <class>QTable</class> | 297 | <class>QTable</class> |
@@ -308,22 +308,11 @@ | |||
308 | <number>2</number> | 308 | <number>2</number> |
309 | </property> | 309 | </property> |
310 | </widget> | 310 | </widget> |
311 | <widget row="2" column="0" > | ||
312 | <class>QPushButton</class> | ||
313 | <property stdset="1"> | ||
314 | <name>name</name> | ||
315 | <cstring>PushButtonPredict</cstring> | ||
316 | </property> | ||
317 | <property stdset="1"> | ||
318 | <name>text</name> | ||
319 | <string>predict time</string> | ||
320 | </property> | ||
321 | </widget> | ||
322 | <widget row="1" column="0" > | 311 | <widget row="1" column="0" > |
323 | <class>QLayoutWidget</class> | 312 | <class>QLayoutWidget</class> |
324 | <property stdset="1"> | 313 | <property stdset="1"> |
325 | <name>name</name> | 314 | <name>name</name> |
326 | <cstring>Layout5</cstring> | 315 | <cstring>Layout9</cstring> |
327 | </property> | 316 | </property> |
328 | <grid> | 317 | <grid> |
329 | <property stdset="1"> | 318 | <property stdset="1"> |
@@ -345,17 +334,39 @@ | |||
345 | <string>nan</string> | 334 | <string>nan</string> |
346 | </property> | 335 | </property> |
347 | </widget> | 336 | </widget> |
337 | <widget row="1" column="0" > | ||
338 | <class>QLabel</class> | ||
339 | <property stdset="1"> | ||
340 | <name>name</name> | ||
341 | <cstring>TextLabel4</cstring> | ||
342 | </property> | ||
343 | <property stdset="1"> | ||
344 | <name>text</name> | ||
345 | <string>Esimated Shift:</string> | ||
346 | </property> | ||
347 | </widget> | ||
348 | <widget row="1" column="1" > | 348 | <widget row="1" column="1" > |
349 | <class>QLabel</class> | 349 | <class>QLabel</class> |
350 | <property stdset="1"> | 350 | <property stdset="1"> |
351 | <name>name</name> | 351 | <name>name</name> |
352 | <cstring>TextLabelPredTime</cstring> | 352 | <cstring>TextLabelEstimatedShift</cstring> |
353 | </property> | 353 | </property> |
354 | <property stdset="1"> | 354 | <property stdset="1"> |
355 | <name>text</name> | 355 | <name>text</name> |
356 | <string>nan</string> | 356 | <string>nan</string> |
357 | </property> | 357 | </property> |
358 | </widget> | 358 | </widget> |
359 | <widget row="2" column="0" > | ||
360 | <class>QLabel</class> | ||
361 | <property stdset="1"> | ||
362 | <name>name</name> | ||
363 | <cstring>TextLabel3_2</cstring> | ||
364 | </property> | ||
365 | <property stdset="1"> | ||
366 | <name>text</name> | ||
367 | <string>Predicted Time:</string> | ||
368 | </property> | ||
369 | </widget> | ||
359 | <widget row="0" column="0" > | 370 | <widget row="0" column="0" > |
360 | <class>QLabel</class> | 371 | <class>QLabel</class> |
361 | <property stdset="1"> | 372 | <property stdset="1"> |
@@ -367,19 +378,58 @@ | |||
367 | <string>Mean shift:</string> | 378 | <string>Mean shift:</string> |
368 | </property> | 379 | </property> |
369 | </widget> | 380 | </widget> |
370 | <widget row="1" column="0" > | 381 | <widget row="2" column="1" > |
371 | <class>QLabel</class> | 382 | <class>QLabel</class> |
372 | <property stdset="1"> | 383 | <property stdset="1"> |
373 | <name>name</name> | 384 | <name>name</name> |
374 | <cstring>TextLabel3_2</cstring> | 385 | <cstring>TextLabelPredTime</cstring> |
375 | </property> | 386 | </property> |
376 | <property stdset="1"> | 387 | <property stdset="1"> |
377 | <name>text</name> | 388 | <name>text</name> |
378 | <string>Pred. Time:</string> | 389 | <string>nan</string> |
379 | </property> | 390 | </property> |
380 | </widget> | 391 | </widget> |
381 | </grid> | 392 | </grid> |
382 | </widget> | 393 | </widget> |
394 | <widget row="2" column="0" > | ||
395 | <class>QLayoutWidget</class> | ||
396 | <property stdset="1"> | ||
397 | <name>name</name> | ||
398 | <cstring>Layout11</cstring> | ||
399 | </property> | ||
400 | <hbox> | ||
401 | <property stdset="1"> | ||
402 | <name>margin</name> | ||
403 | <number>0</number> | ||
404 | </property> | ||
405 | <property stdset="1"> | ||
406 | <name>spacing</name> | ||
407 | <number>6</number> | ||
408 | </property> | ||
409 | <widget> | ||
410 | <class>QPushButton</class> | ||
411 | <property stdset="1"> | ||
412 | <name>name</name> | ||
413 | <cstring>PushButtonSetPredTime</cstring> | ||
414 | </property> | ||
415 | <property stdset="1"> | ||
416 | <name>text</name> | ||
417 | <string>Set predicted time</string> | ||
418 | </property> | ||
419 | </widget> | ||
420 | <widget> | ||
421 | <class>QPushButton</class> | ||
422 | <property stdset="1"> | ||
423 | <name>name</name> | ||
424 | <cstring>PushButtonPredict</cstring> | ||
425 | </property> | ||
426 | <property stdset="1"> | ||
427 | <name>text</name> | ||
428 | <string>Predict time</string> | ||
429 | </property> | ||
430 | </widget> | ||
431 | </hbox> | ||
432 | </widget> | ||
383 | </grid> | 433 | </grid> |
384 | </widget> | 434 | </widget> |
385 | <widget> | 435 | <widget> |
@@ -486,10 +536,14 @@ | |||
486 | </property> | 536 | </property> |
487 | </widget> | 537 | </widget> |
488 | <widget row="0" column="1" > | 538 | <widget row="0" column="1" > |
489 | <class>QLineEdit</class> | 539 | <class>QComboBox</class> |
490 | <property stdset="1"> | 540 | <property stdset="1"> |
491 | <name>name</name> | 541 | <name>name</name> |
492 | <cstring>LineEditNtpSrv</cstring> | 542 | <cstring>ComboNtpSrv</cstring> |
543 | </property> | ||
544 | <property stdset="1"> | ||
545 | <name>editable</name> | ||
546 | <bool>true</bool> | ||
493 | </property> | 547 | </property> |
494 | </widget> | 548 | </widget> |
495 | </grid> | 549 | </grid> |
@@ -609,6 +663,13 @@ | |||
609 | <cstring>TextLabel1_2_2</cstring> | 663 | <cstring>TextLabel1_2_2</cstring> |
610 | </property> | 664 | </property> |
611 | <property stdset="1"> | 665 | <property stdset="1"> |
666 | <name>sizePolicy</name> | ||
667 | <sizepolicy> | ||
668 | <hsizetype>1</hsizetype> | ||
669 | <vsizetype>1</vsizetype> | ||
670 | </sizepolicy> | ||
671 | </property> | ||
672 | <property stdset="1"> | ||
612 | <name>text</name> | 673 | <name>text</name> |
613 | <string>Wait for</string> | 674 | <string>Wait for</string> |
614 | </property> | 675 | </property> |
@@ -632,7 +693,7 @@ | |||
632 | </property> | 693 | </property> |
633 | <property stdset="1"> | 694 | <property stdset="1"> |
634 | <name>text</name> | 695 | <name>text</name> |
635 | <string>NTP syncronises the clock with the network</string> | 696 | <string>NTP tries to syncronises the clock with the network.</string> |
636 | </property> | 697 | </property> |
637 | <property stdset="1"> | 698 | <property stdset="1"> |
638 | <name>alignment</name> | 699 | <name>alignment</name> |