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.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 @@
3#include <qregexp.h> 3#include <qregexp.h>
4#include <qtimer.h>
4#include <qtable.h> 5#include <qtable.h>
@@ -25,2 +26,13 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
25{ 26{
27
28 Config ntpSrvs("/etc/ntpservers",Config::File);
29 ntpSrvs.setGroup("servers");
30 int srvCount = ntpSrvs.readNumEntry("count", 0 );
31 for (int i = 0; i < srvCount; i++)
32 {
33 ntpSrvs.setGroup(QString::number(i));
34 ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") );
35 }
36 if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de"));
37
26 Config cfg("ntp",Config::User); 38 Config cfg("ntp",Config::User);
@@ -29,11 +41,17 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
29// _minLookupDiff = cfg.readNumEntry("minLookupDiff",10); 41// _minLookupDiff = cfg.readNumEntry("minLookupDiff",10);
30 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",60) ); 42 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) );
31 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",60) ); 43 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) );
32 LineEditNtpSrv->setText( cfg.readEntry("ntpServer", tr("time.fu-berlin.de")) ); 44 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) );
45
46 ntpTimer = new QTimer(this);
47 ntpTimer->start(SpinBoxNtpDelay->value()*100);
48
33 ntpProcess = new OProcess( ); 49 ntpProcess = new OProcess( );
50 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ),
51 SLOT(slotNtpDelayChanged(int)) );
34 52
35 QSocket *ntpSock = new QSocket( this ); 53 ntpSock = new QSocket( this );
36 ntpSock->connectToHost( LineEditNtpSrv->text() ,123);
37 connect( ntpSock, SIGNAL( error(int) ), 54 connect( ntpSock, SIGNAL( error(int) ),
38 SLOT(slotCheckNtp(int)) ); 55 SLOT(slotCheckNtp(int)) );
56 slotProbeNtpServer();
39 57
@@ -45,4 +63,4 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
45 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); 63 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime()));
64 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime()));
46 slotCheckNtp(-1); 65 slotCheckNtp(-1);
47// slotRunNtp();
48 readLookups(); 66 readLookups();
@@ -52,5 +70,15 @@ Ntp::~Ntp()
52{ 70{
71 delete ntpProcess;
72 Config ntpSrvs("/etc/ntpservers",Config::File);
73 ntpSrvs.setGroup("servers");
74 int srvCount = ComboNtpSrv->count();
75 ntpSrvs.writeEntry("count", srvCount);
76 for (int i = 0; i < srvCount; i++)
77 {
78 ntpSrvs.setGroup(QString::number(i));
79 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) );
80 }
53 Config cfg("ntp",Config::User); 81 Config cfg("ntp",Config::User);
54 cfg.setGroup("settings"); 82 cfg.setGroup("settings");
55 cfg.writeEntry("ntpServer", LineEditNtpSrv->text()); 83 cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem());
56 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); 84 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() );
@@ -81,4 +109,5 @@ void Ntp::slotRunNtp()
81 TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); 109 TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
110 MultiLineEditntpOutPut->append( "\n"+tr("Running:")+"\nntpdate "+ ComboNtpSrv->currentText()+"\n");
82 ntpProcess->clearArguments(); 111 ntpProcess->clearArguments();
83 *ntpProcess << "ntpdate" << LineEditNtpSrv->text(); 112 *ntpProcess << "ntpdate" << ComboNtpSrv->currentText();
84 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); 113 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
@@ -192,2 +221,3 @@ void Ntp::preditctTime()
192 int corr = int((now - lastTime) * _shiftPerSec); 221 int corr = int((now - lastTime) * _shiftPerSec);
222 TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds"));
193 predictedTime = QDateTime::currentDateTime().addSecs(corr); 223 predictedTime = QDateTime::currentDateTime().addSecs(corr);
@@ -210,2 +240,13 @@ void Ntp::slotCheckNtp(int i)
210 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); 240 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) );
241 Config cfg("ntp",Config::User);
242 cfg.setGroup("lookups");
243 int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
244 if ( lookupDiff > SpinBoxNtpDelay->value()*60 )
245 {
246 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) );
247 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) );
248 }else{
249 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) );
250 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
251 }
211 }else{ 252 }else{
@@ -214,3 +255,18 @@ void Ntp::slotCheckNtp(int i)
214 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); 255 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) );
215 }; 256 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
257 }
258}
259
260void Ntp::slotProbeNtpServer()
261{
262 Config cfg("ntp",Config::User);
263 cfg.setGroup("lookups");
264 int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
265 if ( lookupDiff > SpinBoxNtpDelay->value()*60 )
266 ntpSock->connectToHost( ComboNtpSrv->currentText() ,123);
267}
268
269void Ntp::slotNtpDelayChanged(int delay)
270{
271 ntpTimer->changeInterval( delay*100 );
216} 272}