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.cpp21
1 files changed, 17 insertions, 4 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index b2f5332..6a5c062 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -28,31 +28,30 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
28 Config ntpSrvs("/etc/ntpservers",Config::File); 28 Config ntpSrvs("/etc/ntpservers",Config::File);
29 ntpSrvs.setGroup("servers"); 29 ntpSrvs.setGroup("servers");
30 int srvCount = ntpSrvs.readNumEntry("count", 0 ); 30 int srvCount = ntpSrvs.readNumEntry("count", 0 );
31 for (int i = 0; i < srvCount; i++) 31 for (int i = 0; i < srvCount; i++)
32 { 32 {
33 ntpSrvs.setGroup(QString::number(i)); 33 ntpSrvs.setGroup(QString::number(i));
34 ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); 34 ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") );
35 } 35 }
36 if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); 36 if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de"));
37 37
38 Config cfg("ntp",Config::User); 38 Config cfg("ntp",Config::User);
39 cfg.setGroup("settings"); 39 cfg.setGroup("settings");
40 // _maxOffset = cfg.readNumEntry("maxOffset",5);
41// _minLookupDiff = cfg.readNumEntry("minLookupDiff",10);
42 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) ); 40 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) );
43 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) ); 41 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) );
44 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); 42 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) );
45 43
46 ntpTimer = new QTimer(this); 44 ntpTimer = new QTimer(this);
45 processTimer = new QTimer(this);
47 ntpTimer->start(SpinBoxNtpDelay->value()*1000*60); 46 ntpTimer->start(SpinBoxNtpDelay->value()*1000*60);
48 47
49 ntpProcess = new OProcess( ); 48 ntpProcess = new OProcess( );
50 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), 49 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ),
51 SLOT(slotNtpDelayChanged(int)) ); 50 SLOT(slotNtpDelayChanged(int)) );
52 51
53 ntpSock = new QSocket( this ); 52 ntpSock = new QSocket( this );
54 connect( ntpSock, SIGNAL( error(int) ), 53 connect( ntpSock, SIGNAL( error(int) ),
55 SLOT(slotCheckNtp(int)) ); 54 SLOT(slotCheckNtp(int)) );
56 slotProbeNtpServer(); 55 slotProbeNtpServer();
57 56
58 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), 57 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)),
@@ -107,48 +106,57 @@ void Ntp::slotRunNtp()
107 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ 106 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+
108 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+ 107 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+
109 "<br>"+tr("Rerun NTP?"), 108 "<br>"+tr("Rerun NTP?"),
110 QMessageBox::Ok,QMessageBox::Cancel) 109 QMessageBox::Ok,QMessageBox::Cancel)
111 ) { 110 ) {
112 case QMessageBox::Ok: break; 111 case QMessageBox::Ok: break;
113 case QMessageBox::Cancel: return; 112 case QMessageBox::Cancel: return;
114 default: return; 113 default: return;
115 } 114 }
116 } 115 }
117 TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); 116 TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
118 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); 117 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() );
118 connect( processTimer, SIGNAL( timeout() ), SLOT(slotTimeoutNtpProcess()) );
119 processTimer->start(2*1000*60, true);
120
119 ntpProcess->clearArguments(); 121 ntpProcess->clearArguments();
120 *ntpProcess << "ntpdate" << getNtpServer(); 122 *ntpProcess << "ntpdate" << getNtpServer();
121 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); 123 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
122 if ( !ret ) { 124 if ( !ret ) {
123 qDebug("Error while executing ntpdate"); 125 qDebug("Error while executing ntpdate");
124 ntpOutPut( tr("Error while executing ntpdate")); 126 ntpOutPut( tr("Error while executing ntpdate"));
125 } 127 }
126} 128}
127 129
128void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) 130void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
129{ 131{
130 QString lineStr, lineStrOld; 132 QString lineStr, lineStrOld;
131 lineStr = buffer; 133 lineStr = buffer;
132 lineStr=lineStr.left(buflen); 134 lineStr=lineStr.left(buflen);
133 if (lineStr!=lineStrOld) 135 if (lineStr!=lineStrOld)
134 { 136 {
135 ntpOutPut(lineStr); 137 ntpOutPut(lineStr);
136 _ntpOutput += lineStr; 138 _ntpOutput += lineStr;
137 } 139 }
138 lineStrOld = lineStr; 140 lineStrOld = lineStr;
139} 141}
140 142
141void Ntp::ntpFinished(OProcess*) 143void Ntp::ntpFinished(OProcess *p)
142{ 144{
145 if (!p->normalExit())
146 {
147 slotProbeNtpServer();
148 return;
149 }
150 processTimer->stop();
143 Config cfg("ntp",Config::User); 151 Config cfg("ntp",Config::User);
144 cfg.setGroup("lookups"); 152 cfg.setGroup("lookups");
145 int lastLookup = cfg.readNumEntry("time",0); 153 int lastLookup = cfg.readNumEntry("time",0);
146 int lookupCount = cfg.readNumEntry("count",-1); 154 int lookupCount = cfg.readNumEntry("count",-1);
147 int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); 155 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
148 cfg.writeEntry("time", time); 156 cfg.writeEntry("time", time);
149 cfg.setGroup("correction"); 157 cfg.setGroup("correction");
150 cfg.writeEntry("time", time); 158 cfg.writeEntry("time", time);
151 159
152 float timeShift = getTimeShift(); 160 float timeShift = getTimeShift();
153 if (timeShift == 0.0) return; 161 if (timeShift == 0.0) return;
154 int secsSinceLast = time - lastLookup; 162 int secsSinceLast = time - lastLookup;
@@ -252,30 +260,35 @@ void Ntp::slotCheckNtp(int i)
252 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); 260 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) );
253 }else{ 261 }else{
254 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); 262 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) );
255 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); 263 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
256 } 264 }
257 }else{ 265 }else{
258 preditctTime(); 266 preditctTime();
259 ButtonSetTime->setText( tr("Set predicted time") ); 267 ButtonSetTime->setText( tr("Set predicted time") );
260 if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); 268 if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer());
261 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); 269 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) );
262 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); 270 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
263 } 271 }
264 //ntpTimer->start(SpinBoxNtpDelay->value()*1000*60);
265} 272}
266 273
267void Ntp::slotProbeNtpServer() 274void Ntp::slotProbeNtpServer()
268{ 275{
269 ntpSock->connectToHost( getNtpServer() ,123); 276 ntpSock->connectToHost( getNtpServer() ,123);
270} 277}
271 278
272void Ntp::slotNtpDelayChanged(int delay) 279void Ntp::slotNtpDelayChanged(int delay)
273{ 280{
274 ntpTimer->changeInterval( delay*1000*60 ); 281 ntpTimer->changeInterval( delay*1000*60 );
275} 282}
276 283
277void Ntp::ntpOutPut(QString out) 284void Ntp::ntpOutPut(QString out)
278{ 285{
279 MultiLineEditntpOutPut->append(out); 286 MultiLineEditntpOutPut->append(out);
280 MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); 287 MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE);
281} 288}
289
290void Ntp::slotTimeoutNtpProcess()
291{
292 ntpProcess->kill();
293 slotProbeNtpServer();
294}