summaryrefslogtreecommitdiff
path: root/noncore/settings/netsystemtime/ntp.cpp
Side-by-side diff
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
@@ -39,14 +39,12 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
cfg.setGroup("settings");
SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) );
SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) );
ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) );
ntpTimer = new QTimer(this);
- processTimer = new QTimer(this);
- ntpTimer->start(SpinBoxNtpDelay->value()*1000*60);
ntpProcess = new OProcess( );
connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ),
SLOT(slotNtpDelayChanged(int)) );
ntpSock = new QSocket( this );
@@ -112,14 +110,12 @@ void Ntp::slotRunNtp()
case QMessageBox::Cancel: return;
default: return;
}
}
TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() );
- connect( processTimer, SIGNAL( timeout() ), SLOT(slotTimeoutNtpProcess()) );
- processTimer->start(2*1000*60, true);
ntpProcess->clearArguments();
*ntpProcess << "ntpdate" << getNtpServer();
bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
if ( !ret ) {
qDebug("Error while executing ntpdate");
@@ -139,22 +135,22 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
}
lineStrOld = lineStr;
}
void Ntp::ntpFinished(OProcess *p)
{
- if (!p->normalExit())
+ qDebug("p->exitStatus() %i",p->exitStatus());
+ if (p->exitStatus()!=0 || !p->normalExit())
{
slotProbeNtpServer();
return;
}
- processTimer->stop();
Config cfg("ntp",Config::User);
cfg.setGroup("lookups");
int lastLookup = cfg.readNumEntry("time",0);
- int lookupCount = cfg.readNumEntry("count",-1);
+ int lookupCount = cfg.readNumEntry("count",0);
int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
cfg.writeEntry("time", time);
cfg.setGroup("correction");
cfg.writeEntry("time", time);
float timeShift = getTimeShift();
@@ -191,20 +187,20 @@ float Ntp::getTimeShift()
}
void Ntp::readLookups()
{
Config cfg("ntp",Config::User);
cfg.setGroup("lookups");
- int lookupCount = cfg.readNumEntry("count",-1);
+ int lookupCount = cfg.readNumEntry("count",0);
float last, shift, shiftPerSec;
qDebug("lookupCount = %i",lookupCount);
TableLookups->setNumCols( 3 );
TableLookups->setNumRows( lookupCount);
- TableLookups->horizontalHeader()->setLabel(1,"secsSinceLast");
- TableLookups->horizontalHeader()->setLabel(2,"timeShift");
- TableLookups->horizontalHeader()->setLabel(0,"shift/s");
+ TableLookups->horizontalHeader()->setLabel(1,tr("last [h]"));
+ TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]"));
+ TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]"));
int cw = 50;//TableLookups->width()/4;
qDebug("column width %i",cw);
TableLookups->setColumnWidth( 0, cw+30 );
TableLookups->setColumnWidth( 1, cw );
TableLookups->setColumnWidth( 2, cw );
TableLookups->sortColumn(0, false, true );
@@ -215,15 +211,15 @@ void Ntp::readLookups()
last = cfg.readEntry("secsSinceLast",0).toFloat();
shift = QString(cfg.readEntry("timeShift",0)).toFloat();
// qDebug("%i last %f",i,last);
// qDebug("%i shift %f",i,shift);
shiftPerSec = shift / last;
_shiftPerSec += shiftPerSec;
- TableLookups->setText( i,0,QString::number(shiftPerSec));
+ TableLookups->setText( i,0,QString::number(shiftPerSec*60));
TableLookups->setText( i,2,QString::number(shift));
- TableLookups->setText( i,1,QString::number(last));
+ TableLookups->setText( i,1,QString::number(last/60));
}
_shiftPerSec /= lookupCount+1;
TextLabelShift->setText(QString::number(_shiftPerSec)+tr(" seconds"));
}
void Ntp::preditctTime()
@@ -270,12 +266,13 @@ void Ntp::slotCheckNtp(int i)
connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
}
}
void Ntp::slotProbeNtpServer()
{
+ qDebug("Ntp::slotProbeNtpServer()");
ntpSock->connectToHost( getNtpServer() ,123);
}
void Ntp::slotNtpDelayChanged(int delay)
{
ntpTimer->changeInterval( delay*1000*60 );
@@ -284,11 +281,6 @@ void Ntp::slotNtpDelayChanged(int delay)
void Ntp::ntpOutPut(QString out)
{
MultiLineEditntpOutPut->append(out);
MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE);
}
-void Ntp::slotTimeoutNtpProcess()
-{
- ntpProcess->kill();
- slotProbeNtpServer();
-}