summaryrefslogtreecommitdiff
Side-by-side diff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp28
-rw-r--r--noncore/settings/netsystemtime/ntp.h3
-rw-r--r--noncore/settings/netsystemtime/ntpbase.ui8
3 files changed, 18 insertions, 21 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
@@ -33,26 +33,24 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
ntpSrvs.setGroup(QString::number(i));
ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") );
}
if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de"));
Config cfg("ntp",Config::User);
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 );
connect( ntpSock, SIGNAL( error(int) ),
SLOT(slotCheckNtp(int)) );
slotProbeNtpServer();
connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)),
this, SLOT(getNtpOutput(OProcess*,char*,int)));
@@ -106,26 +104,24 @@ void Ntp::slotRunNtp()
tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+
QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+
"<br>"+tr("Rerun NTP?"),
QMessageBox::Ok,QMessageBox::Cancel)
) {
case QMessageBox::Ok: break;
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");
ntpOutPut( tr("Error while executing ntpdate"));
}
}
void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
{
@@ -133,34 +129,34 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
lineStr = buffer;
lineStr=lineStr.left(buflen);
if (lineStr!=lineStrOld)
{
ntpOutPut(lineStr);
_ntpOutput += lineStr;
}
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();
if (timeShift == 0.0) return;
int secsSinceLast = time - lastLookup;
TextLabelNewTime->setText(QDateTime::currentDateTime().toString());
TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds"));
if ( lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value())
{
@@ -185,51 +181,51 @@ float Ntp::getTimeShift()
int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset );
posOffset += _offset.length() + 1;
QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1);
qDebug("%s", _ntpOutput.latin1());
qDebug("diff = >%s<",diff.latin1());
return diff.toFloat();
}
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 );
// TableLookups->setSorting( true );
for (int i=0; i < lookupCount; i++)
{
cfg.setGroup("lookup_"+QString::number(i));
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()
{
Config cfg("ntp",Config::User);
cfg.setGroup("lookups");
int lastTime = cfg.readNumEntry("time",0);
setenv( "TZ", tz->currentZone(), 1 );
int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
@@ -264,31 +260,27 @@ void Ntp::slotCheckNtp(int i)
}
}else{
preditctTime();
ButtonSetTime->setText( tr("Set predicted time") );
if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer());
connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) );
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 );
}
void Ntp::ntpOutPut(QString out)
{
MultiLineEditntpOutPut->append(out);
MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE);
}
-void Ntp::slotTimeoutNtpProcess()
-{
- ntpProcess->kill();
- slotProbeNtpServer();
-}
diff --git a/noncore/settings/netsystemtime/ntp.h b/noncore/settings/netsystemtime/ntp.h
index d166973..c78dc55 100644
--- a/noncore/settings/netsystemtime/ntp.h
+++ b/noncore/settings/netsystemtime/ntp.h
@@ -16,33 +16,32 @@ public:
Ntp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
~Ntp();
protected:
QDateTime predictedTime;
private:
QString _ntpOutput;
float _shiftPerSec;
int _lookupDiff;
OProcess *ntpProcess;
- QTimer *ntpTimer, *processTimer;
+ QTimer *ntpTimer;
QSocket *ntpSock;
float getTimeShift();
void readLookups();
void ntpOutPut(QString);
bool ntpDelayElapsed();
QString getNtpServer();
private slots:
void slotRunNtp();
void getNtpOutput(OProcess *proc, char *buffer, int buflen);
void ntpFinished(OProcess*);
void preditctTime();
void slotCheckNtp(int);
void setPredictTime();
void slotProbeNtpServer();
void slotNtpDelayChanged(int);
- void slotTimeoutNtpProcess();
};
#endif
diff --git a/noncore/settings/netsystemtime/ntpbase.ui b/noncore/settings/netsystemtime/ntpbase.ui
index a83dc93..f5e9371 100644
--- a/noncore/settings/netsystemtime/ntpbase.ui
+++ b/noncore/settings/netsystemtime/ntpbase.ui
@@ -2,25 +2,25 @@
<class>NtpBase</class>
<widget>
<class>QWidget</class>
<property stdset="1">
<name>name</name>
<cstring>NtpBase</cstring>
</property>
<property stdset="1">
<name>geometry</name>
<rect>
<x>0</x>
<y>0</y>
- <width>328</width>
+ <width>324</width>
<height>411</height>
</rect>
</property>
<property stdset="1">
<name>caption</name>
<string>Network Time</string>
</property>
<property>
<name>layoutMargin</name>
</property>
<property>
<name>layoutSpacing</name>
@@ -291,24 +291,30 @@
</property>
<property stdset="1">
<name>spacing</name>
<number>6</number>
</property>
<widget row="0" column="0" >
<class>QTable</class>
<property stdset="1">
<name>name</name>
<cstring>TableLookups</cstring>
</property>
<property stdset="1">
+ <name>font</name>
+ <font>
+ <pointsize>8</pointsize>
+ </font>
+ </property>
+ <property stdset="1">
<name>numRows</name>
<number>2</number>
</property>
<property stdset="1">
<name>numCols</name>
<number>2</number>
</property>
</widget>
<widget row="1" column="0" >
<class>QLayoutWidget</class>
<property stdset="1">
<name>name</name>