summaryrefslogtreecommitdiff
path: root/noncore/settings/netsystemtime/ntp.cpp
Unidiff
Diffstat (limited to 'noncore/settings/netsystemtime/ntp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp28
1 files changed, 10 insertions, 18 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index 6a5c062..0abb401 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -42,8 +42,6 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
42 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); 42 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) );
43 43
44 ntpTimer = new QTimer(this); 44 ntpTimer = new QTimer(this);
45 processTimer = new QTimer(this);
46 ntpTimer->start(SpinBoxNtpDelay->value()*1000*60);
47 45
48 ntpProcess = new OProcess( ); 46 ntpProcess = new OProcess( );
49 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), 47 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ),
@@ -115,8 +113,6 @@ void Ntp::slotRunNtp()
115 } 113 }
116 TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); 114 TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
117 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); 115 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() );
118 connect( processTimer, SIGNAL( timeout() ), SLOT(slotTimeoutNtpProcess()) );
119 processTimer->start(2*1000*60, true);
120 116
121 ntpProcess->clearArguments(); 117 ntpProcess->clearArguments();
122 *ntpProcess << "ntpdate" << getNtpServer(); 118 *ntpProcess << "ntpdate" << getNtpServer();
@@ -142,16 +138,16 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
142 138
143void Ntp::ntpFinished(OProcess *p) 139void Ntp::ntpFinished(OProcess *p)
144{ 140{
145 if (!p->normalExit()) 141 qDebug("p->exitStatus() %i",p->exitStatus());
142 if (p->exitStatus()!=0 || !p->normalExit())
146 { 143 {
147 slotProbeNtpServer(); 144 slotProbeNtpServer();
148 return; 145 return;
149 } 146 }
150 processTimer->stop();
151 Config cfg("ntp",Config::User); 147 Config cfg("ntp",Config::User);
152 cfg.setGroup("lookups"); 148 cfg.setGroup("lookups");
153 int lastLookup = cfg.readNumEntry("time",0); 149 int lastLookup = cfg.readNumEntry("time",0);
154 int lookupCount = cfg.readNumEntry("count",-1); 150 int lookupCount = cfg.readNumEntry("count",0);
155 int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); 151 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
156 cfg.writeEntry("time", time); 152 cfg.writeEntry("time", time);
157 cfg.setGroup("correction"); 153 cfg.setGroup("correction");
@@ -194,14 +190,14 @@ void Ntp::readLookups()
194{ 190{
195 Config cfg("ntp",Config::User); 191 Config cfg("ntp",Config::User);
196 cfg.setGroup("lookups"); 192 cfg.setGroup("lookups");
197 int lookupCount = cfg.readNumEntry("count",-1); 193 int lookupCount = cfg.readNumEntry("count",0);
198 float last, shift, shiftPerSec; 194 float last, shift, shiftPerSec;
199 qDebug("lookupCount = %i",lookupCount); 195 qDebug("lookupCount = %i",lookupCount);
200 TableLookups->setNumCols( 3 ); 196 TableLookups->setNumCols( 3 );
201 TableLookups->setNumRows( lookupCount); 197 TableLookups->setNumRows( lookupCount);
202 TableLookups->horizontalHeader()->setLabel(1,"secsSinceLast"); 198 TableLookups->horizontalHeader()->setLabel(1,tr("last [h]"));
203 TableLookups->horizontalHeader()->setLabel(2,"timeShift"); 199 TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]"));
204 TableLookups->horizontalHeader()->setLabel(0,"shift/s"); 200 TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]"));
205 int cw = 50;//TableLookups->width()/4; 201 int cw = 50;//TableLookups->width()/4;
206 qDebug("column width %i",cw); 202 qDebug("column width %i",cw);
207 TableLookups->setColumnWidth( 0, cw+30 ); 203 TableLookups->setColumnWidth( 0, cw+30 );
@@ -218,9 +214,9 @@ void Ntp::readLookups()
218 // qDebug("%i shift %f",i,shift); 214 // qDebug("%i shift %f",i,shift);
219 shiftPerSec = shift / last; 215 shiftPerSec = shift / last;
220 _shiftPerSec += shiftPerSec; 216 _shiftPerSec += shiftPerSec;
221 TableLookups->setText( i,0,QString::number(shiftPerSec)); 217 TableLookups->setText( i,0,QString::number(shiftPerSec*60));
222 TableLookups->setText( i,2,QString::number(shift)); 218 TableLookups->setText( i,2,QString::number(shift));
223 TableLookups->setText( i,1,QString::number(last)); 219 TableLookups->setText( i,1,QString::number(last/60));
224 } 220 }
225 _shiftPerSec /= lookupCount+1; 221 _shiftPerSec /= lookupCount+1;
226 TextLabelShift->setText(QString::number(_shiftPerSec)+tr(" seconds")); 222 TextLabelShift->setText(QString::number(_shiftPerSec)+tr(" seconds"));
@@ -273,6 +269,7 @@ void Ntp::slotCheckNtp(int i)
273 269
274void Ntp::slotProbeNtpServer() 270void Ntp::slotProbeNtpServer()
275{ 271{
272 qDebug("Ntp::slotProbeNtpServer()");
276 ntpSock->connectToHost( getNtpServer() ,123); 273 ntpSock->connectToHost( getNtpServer() ,123);
277} 274}
278 275
@@ -287,8 +284,3 @@ void Ntp::ntpOutPut(QString out)
287 MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); 284 MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE);
288} 285}
289 286
290void Ntp::slotTimeoutNtpProcess()
291{
292 ntpProcess->kill();
293 slotProbeNtpServer();
294}