-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 21 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntp.h | 3 |
2 files changed, 19 insertions, 5 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index b2f5332..6a5c062 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp | |||
@@ -36,15 +36,14 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | |||
36 | if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); | 36 | if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); |
37 | 37 | ||
38 | Config cfg("ntp",Config::User); | 38 | Config cfg("ntp",Config::User); |
39 | cfg.setGroup("settings"); | 39 | cfg.setGroup("settings"); |
40 | // _maxOffset = cfg.readNumEntry("maxOffset",5); | ||
41 | // _minLookupDiff = cfg.readNumEntry("minLookupDiff",10); | ||
42 | SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) ); | 40 | SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) ); |
43 | SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) ); | 41 | SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) ); |
44 | ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); | 42 | ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); |
45 | 43 | ||
46 | ntpTimer = new QTimer(this); | 44 | ntpTimer = new QTimer(this); |
45 | processTimer = new QTimer(this); | ||
47 | ntpTimer->start(SpinBoxNtpDelay->value()*1000*60); | 46 | ntpTimer->start(SpinBoxNtpDelay->value()*1000*60); |
48 | 47 | ||
49 | ntpProcess = new OProcess( ); | 48 | ntpProcess = new OProcess( ); |
50 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), | 49 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), |
@@ -115,8 +114,11 @@ void Ntp::slotRunNtp() | |||
115 | } | 114 | } |
116 | } | 115 | } |
117 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); | 116 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); |
118 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); | 117 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); |
118 | connect( processTimer, SIGNAL( timeout() ), SLOT(slotTimeoutNtpProcess()) ); | ||
119 | processTimer->start(2*1000*60, true); | ||
120 | |||
119 | ntpProcess->clearArguments(); | 121 | ntpProcess->clearArguments(); |
120 | *ntpProcess << "ntpdate" << getNtpServer(); | 122 | *ntpProcess << "ntpdate" << getNtpServer(); |
121 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); | 123 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); |
122 | if ( !ret ) { | 124 | if ( !ret ) { |
@@ -137,10 +139,16 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) | |||
137 | } | 139 | } |
138 | lineStrOld = lineStr; | 140 | lineStrOld = lineStr; |
139 | } | 141 | } |
140 | 142 | ||
141 | void Ntp::ntpFinished(OProcess*) | 143 | void Ntp::ntpFinished(OProcess *p) |
142 | { | 144 | { |
145 | if (!p->normalExit()) | ||
146 | { | ||
147 | slotProbeNtpServer(); | ||
148 | return; | ||
149 | } | ||
150 | processTimer->stop(); | ||
143 | Config cfg("ntp",Config::User); | 151 | Config cfg("ntp",Config::User); |
144 | cfg.setGroup("lookups"); | 152 | cfg.setGroup("lookups"); |
145 | int lastLookup = cfg.readNumEntry("time",0); | 153 | int lastLookup = cfg.readNumEntry("time",0); |
146 | int lookupCount = cfg.readNumEntry("count",-1); | 154 | int lookupCount = cfg.readNumEntry("count",-1); |
@@ -260,9 +268,8 @@ void Ntp::slotCheckNtp(int i) | |||
260 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); | 268 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); |
261 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); | 269 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); |
262 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 270 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
263 | } | 271 | } |
264 | //ntpTimer->start(SpinBoxNtpDelay->value()*1000*60); | ||
265 | } | 272 | } |
266 | 273 | ||
267 | void Ntp::slotProbeNtpServer() | 274 | void Ntp::slotProbeNtpServer() |
268 | { | 275 | { |
@@ -278,4 +285,10 @@ void Ntp::ntpOutPut(QString out) | |||
278 | { | 285 | { |
279 | MultiLineEditntpOutPut->append(out); | 286 | MultiLineEditntpOutPut->append(out); |
280 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); | 287 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); |
281 | } | 288 | } |
289 | |||
290 | void Ntp::slotTimeoutNtpProcess() | ||
291 | { | ||
292 | ntpProcess->kill(); | ||
293 | slotProbeNtpServer(); | ||
294 | } | ||
diff --git a/noncore/settings/netsystemtime/ntp.h b/noncore/settings/netsystemtime/ntp.h index c78dc55..d166973 100644 --- a/noncore/settings/netsystemtime/ntp.h +++ b/noncore/settings/netsystemtime/ntp.h | |||
@@ -24,9 +24,9 @@ private: | |||
24 | QString _ntpOutput; | 24 | QString _ntpOutput; |
25 | float _shiftPerSec; | 25 | float _shiftPerSec; |
26 | int _lookupDiff; | 26 | int _lookupDiff; |
27 | OProcess *ntpProcess; | 27 | OProcess *ntpProcess; |
28 | QTimer *ntpTimer; | 28 | QTimer *ntpTimer, *processTimer; |
29 | QSocket *ntpSock; | 29 | QSocket *ntpSock; |
30 | 30 | ||
31 | float getTimeShift(); | 31 | float getTimeShift(); |
32 | void readLookups(); | 32 | void readLookups(); |
@@ -41,7 +41,8 @@ private slots: | |||
41 | void slotCheckNtp(int); | 41 | void slotCheckNtp(int); |
42 | void setPredictTime(); | 42 | void setPredictTime(); |
43 | void slotProbeNtpServer(); | 43 | void slotProbeNtpServer(); |
44 | void slotNtpDelayChanged(int); | 44 | void slotNtpDelayChanged(int); |
45 | void slotTimeoutNtpProcess(); | ||
45 | }; | 46 | }; |
46 | 47 | ||
47 | #endif | 48 | #endif |