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.cpp74
1 files changed, 65 insertions, 9 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
@@ -3,2 +3,3 @@
#include <qregexp.h>
+#include <qtimer.h>
#include <qtable.h>
@@ -25,2 +26,13 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
{
+
+ Config ntpSrvs("/etc/ntpservers",Config::File);
+ ntpSrvs.setGroup("servers");
+ int srvCount = ntpSrvs.readNumEntry("count", 0 );
+ for (int i = 0; i < srvCount; i++)
+ {
+ 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);
@@ -29,11 +41,17 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
// _minLookupDiff = cfg.readNumEntry("minLookupDiff",10);
- SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",60) );
- SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",60) );
- LineEditNtpSrv->setText( cfg.readEntry("ntpServer", tr("time.fu-berlin.de")) );
+ SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) );
+ SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) );
+ ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) );
+
+ ntpTimer = new QTimer(this);
+ ntpTimer->start(SpinBoxNtpDelay->value()*100);
+
ntpProcess = new OProcess( );
+ connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ),
+ SLOT(slotNtpDelayChanged(int)) );
- QSocket *ntpSock = new QSocket( this );
- ntpSock->connectToHost( LineEditNtpSrv->text() ,123);
+ ntpSock = new QSocket( this );
connect( ntpSock, SIGNAL( error(int) ),
SLOT(slotCheckNtp(int)) );
+ slotProbeNtpServer();
@@ -45,4 +63,4 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime()));
+ connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime()));
slotCheckNtp(-1);
-// slotRunNtp();
readLookups();
@@ -52,5 +70,15 @@ Ntp::~Ntp()
{
+ delete ntpProcess;
+ Config ntpSrvs("/etc/ntpservers",Config::File);
+ ntpSrvs.setGroup("servers");
+ int srvCount = ComboNtpSrv->count();
+ ntpSrvs.writeEntry("count", srvCount);
+ for (int i = 0; i < srvCount; i++)
+ {
+ ntpSrvs.setGroup(QString::number(i));
+ ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) );
+ }
Config cfg("ntp",Config::User);
cfg.setGroup("settings");
- cfg.writeEntry("ntpServer", LineEditNtpSrv->text());
+ cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem());
cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() );
@@ -81,4 +109,5 @@ void Ntp::slotRunNtp()
TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
+ MultiLineEditntpOutPut->append( "\n"+tr("Running:")+"\nntpdate "+ ComboNtpSrv->currentText()+"\n");
ntpProcess->clearArguments();
- *ntpProcess << "ntpdate" << LineEditNtpSrv->text();
+ *ntpProcess << "ntpdate" << ComboNtpSrv->currentText();
bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
@@ -192,2 +221,3 @@ void Ntp::preditctTime()
int corr = int((now - lastTime) * _shiftPerSec);
+ TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds"));
predictedTime = QDateTime::currentDateTime().addSecs(corr);
@@ -210,2 +240,13 @@ void Ntp::slotCheckNtp(int i)
connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) );
+ Config cfg("ntp",Config::User);
+ cfg.setGroup("lookups");
+ int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
+ if ( lookupDiff > SpinBoxNtpDelay->value()*60 )
+ {
+ disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) );
+ connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) );
+ }else{
+ disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) );
+ connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
+ }
}else{
@@ -214,3 +255,18 @@ void Ntp::slotCheckNtp(int i)
connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) );
- };
+ connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
+ }
+}
+
+void Ntp::slotProbeNtpServer()
+{
+ Config cfg("ntp",Config::User);
+ cfg.setGroup("lookups");
+ int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
+ if ( lookupDiff > SpinBoxNtpDelay->value()*60 )
+ ntpSock->connectToHost( ComboNtpSrv->currentText() ,123);
+}
+
+void Ntp::slotNtpDelayChanged(int delay)
+{
+ ntpTimer->changeInterval( delay*100 );
}