summaryrefslogtreecommitdiff
authortille <tille>2002-06-27 10:04:37 (UTC)
committer tille <tille>2002-06-27 10:04:37 (UTC)
commit7c3fe018ad8855011c6e0441ed1bef2c09e293f2 (patch) (unidiff)
tree299a1e9ffee7ca35f698165d07e02cb415f0010e
parent596749dc52cc89b5325f9089b79d0b9cc8240682 (diff)
downloadopie-7c3fe018ad8855011c6e0441ed1bef2c09e293f2.zip
opie-7c3fe018ad8855011c6e0441ed1bef2c09e293f2.tar.gz
opie-7c3fe018ad8855011c6e0441ed1bef2c09e293f2.tar.bz2
imp. table
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
@@ -1,294 +1,286 @@
1#include "ntp.h" 1#include "ntp.h"
2#include <qpushbutton.h> 2#include <qpushbutton.h>
3#include <qregexp.h> 3#include <qregexp.h>
4#include <qtimer.h> 4#include <qtimer.h>
5#include <qtable.h> 5#include <qtable.h>
6#include <qlabel.h> 6#include <qlabel.h>
7#include <qsocket.h> 7#include <qsocket.h>
8#include <qlineedit.h> 8#include <qlineedit.h>
9#include <qspinbox.h> 9#include <qspinbox.h>
10#include <qmessagebox.h> 10#include <qmessagebox.h>
11#include <qmultilineedit.h> 11#include <qmultilineedit.h>
12#include <opie/oprocess.h> 12#include <opie/oprocess.h>
13#include <qpe/config.h> 13#include <qpe/config.h>
14#include <qpe/global.h> 14#include <qpe/global.h>
15#include <qpe/timeconversion.h> 15#include <qpe/timeconversion.h>
16#include <qpe/tzselect.h> 16#include <qpe/tzselect.h>
17#include <qpe/timestring.h> 17#include <qpe/timestring.h>
18#include <qpe/qpedialog.h> 18#include <qpe/qpedialog.h>
19#include <sys/time.h> 19#include <sys/time.h>
20#include <time.h> 20#include <time.h>
21#include <stdlib.h> 21#include <stdlib.h>
22 22
23 23
24Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) 24Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
25 : SetDateTime( parent, name, fl ) 25 : SetDateTime( parent, name, fl )
26{ 26{
27 27
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 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) ); 40 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) );
41 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) ); 41 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) );
42 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); 42 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) );
43 43
44 ntpTimer = new QTimer(this); 44 ntpTimer = new QTimer(this);
45 processTimer = new QTimer(this);
46 ntpTimer->start(SpinBoxNtpDelay->value()*1000*60);
47 45
48 ntpProcess = new OProcess( ); 46 ntpProcess = new OProcess( );
49 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), 47 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ),
50 SLOT(slotNtpDelayChanged(int)) ); 48 SLOT(slotNtpDelayChanged(int)) );
51 49
52 ntpSock = new QSocket( this ); 50 ntpSock = new QSocket( this );
53 connect( ntpSock, SIGNAL( error(int) ), 51 connect( ntpSock, SIGNAL( error(int) ),
54 SLOT(slotCheckNtp(int)) ); 52 SLOT(slotCheckNtp(int)) );
55 slotProbeNtpServer(); 53 slotProbeNtpServer();
56 54
57 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), 55 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)),
58 this, SLOT(getNtpOutput(OProcess*,char*,int))); 56 this, SLOT(getNtpOutput(OProcess*,char*,int)));
59 connect ( ntpProcess, SIGNAL(processExited(OProcess*)), 57 connect ( ntpProcess, SIGNAL(processExited(OProcess*)),
60 this, SLOT(ntpFinished(OProcess*))); 58 this, SLOT(ntpFinished(OProcess*)));
61 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); 59 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp()));
62 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); 60 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime()));
63 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); 61 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime()));
64 slotCheckNtp(-1); 62 slotCheckNtp(-1);
65 readLookups(); 63 readLookups();
66} 64}
67 65
68Ntp::~Ntp() 66Ntp::~Ntp()
69{ 67{
70 delete ntpProcess; 68 delete ntpProcess;
71 Config ntpSrvs("/etc/ntpservers",Config::File); 69 Config ntpSrvs("/etc/ntpservers",Config::File);
72 ntpSrvs.setGroup("servers"); 70 ntpSrvs.setGroup("servers");
73 int srvCount = ComboNtpSrv->count(); 71 int srvCount = ComboNtpSrv->count();
74 ntpSrvs.writeEntry("count", srvCount); 72 ntpSrvs.writeEntry("count", srvCount);
75 for (int i = 0; i < srvCount; i++) 73 for (int i = 0; i < srvCount; i++)
76 { 74 {
77 ntpSrvs.setGroup(QString::number(i)); 75 ntpSrvs.setGroup(QString::number(i));
78 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); 76 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) );
79 } 77 }
80 Config cfg("ntp",Config::User); 78 Config cfg("ntp",Config::User);
81 cfg.setGroup("settings"); 79 cfg.setGroup("settings");
82 cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); 80 cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem());
83 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); 81 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() );
84 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); 82 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() );
85} 83}
86 84
87bool Ntp::ntpDelayElapsed() 85bool Ntp::ntpDelayElapsed()
88{ 86{
89 Config cfg("ntp",Config::User); 87 Config cfg("ntp",Config::User);
90 cfg.setGroup("lookups"); 88 cfg.setGroup("lookups");
91 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); 89 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
92 return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60; 90 return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60;
93} 91}
94 92
95QString Ntp::getNtpServer() 93QString Ntp::getNtpServer()
96{ 94{
97 return ComboNtpSrv->currentText(); 95 return ComboNtpSrv->currentText();
98} 96}
99 97
100void Ntp::slotRunNtp() 98void Ntp::slotRunNtp()
101{ 99{
102 if ( !ntpDelayElapsed() ) 100 if ( !ntpDelayElapsed() )
103 { 101 {
104 switch ( 102 switch (
105 QMessageBox::warning(this, tr("Run NTP?"), 103 QMessageBox::warning(this, tr("Run NTP?"),
106 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ 104 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+
107 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+ 105 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+
108 "<br>"+tr("Rerun NTP?"), 106 "<br>"+tr("Rerun NTP?"),
109 QMessageBox::Ok,QMessageBox::Cancel) 107 QMessageBox::Ok,QMessageBox::Cancel)
110 ) { 108 ) {
111 case QMessageBox::Ok: break; 109 case QMessageBox::Ok: break;
112 case QMessageBox::Cancel: return; 110 case QMessageBox::Cancel: return;
113 default: return; 111 default: return;
114 } 112 }
115 } 113 }
116 TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); 114 TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
117 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); 115 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() );
118 connect( processTimer, SIGNAL( timeout() ), SLOT(slotTimeoutNtpProcess()) );
119 processTimer->start(2*1000*60, true);
120 116
121 ntpProcess->clearArguments(); 117 ntpProcess->clearArguments();
122 *ntpProcess << "ntpdate" << getNtpServer(); 118 *ntpProcess << "ntpdate" << getNtpServer();
123 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); 119 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
124 if ( !ret ) { 120 if ( !ret ) {
125 qDebug("Error while executing ntpdate"); 121 qDebug("Error while executing ntpdate");
126 ntpOutPut( tr("Error while executing ntpdate")); 122 ntpOutPut( tr("Error while executing ntpdate"));
127 } 123 }
128} 124}
129 125
130void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) 126void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
131{ 127{
132 QString lineStr, lineStrOld; 128 QString lineStr, lineStrOld;
133 lineStr = buffer; 129 lineStr = buffer;
134 lineStr=lineStr.left(buflen); 130 lineStr=lineStr.left(buflen);
135 if (lineStr!=lineStrOld) 131 if (lineStr!=lineStrOld)
136 { 132 {
137 ntpOutPut(lineStr); 133 ntpOutPut(lineStr);
138 _ntpOutput += lineStr; 134 _ntpOutput += lineStr;
139 } 135 }
140 lineStrOld = lineStr; 136 lineStrOld = lineStr;
141} 137}
142 138
143void Ntp::ntpFinished(OProcess *p) 139void Ntp::ntpFinished(OProcess *p)
144{ 140{
145 if (!p->normalExit()) 141 qDebug("p->exitStatus() %i",p->exitStatus());
142 if (p->exitStatus()!=0 || !p->normalExit())
146 { 143 {
147 slotProbeNtpServer(); 144 slotProbeNtpServer();
148 return; 145 return;
149 } 146 }
150 processTimer->stop();
151 Config cfg("ntp",Config::User); 147 Config cfg("ntp",Config::User);
152 cfg.setGroup("lookups"); 148 cfg.setGroup("lookups");
153 int lastLookup = cfg.readNumEntry("time",0); 149 int lastLookup = cfg.readNumEntry("time",0);
154 int lookupCount = cfg.readNumEntry("count",-1); 150 int lookupCount = cfg.readNumEntry("count",0);
155 int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); 151 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
156 cfg.writeEntry("time", time); 152 cfg.writeEntry("time", time);
157 cfg.setGroup("correction"); 153 cfg.setGroup("correction");
158 cfg.writeEntry("time", time); 154 cfg.writeEntry("time", time);
159 155
160 float timeShift = getTimeShift(); 156 float timeShift = getTimeShift();
161 if (timeShift == 0.0) return; 157 if (timeShift == 0.0) return;
162 int secsSinceLast = time - lastLookup; 158 int secsSinceLast = time - lastLookup;
163 TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); 159 TextLabelNewTime->setText(QDateTime::currentDateTime().toString());
164 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); 160 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds"));
165 if ( lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) 161 if ( lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value())
166 { 162 {
167 lookupCount++; 163 lookupCount++;
168 cfg.writeEntry("count",lookupCount); 164 cfg.writeEntry("count",lookupCount);
169 cfg.setGroup("lookup_"+QString::number(lookupCount)); 165 cfg.setGroup("lookup_"+QString::number(lookupCount));
170 _shiftPerSec = timeShift / secsSinceLast; 166 _shiftPerSec = timeShift / secsSinceLast;
171 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); 167 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec);
172 cfg.writeEntry("secsSinceLast",secsSinceLast); 168 cfg.writeEntry("secsSinceLast",secsSinceLast);
173 cfg.writeEntry("timeShift",QString::number(timeShift)); 169 cfg.writeEntry("timeShift",QString::number(timeShift));
174 } 170 }
175} 171}
176 172
177 173
178float Ntp::getTimeShift() 174float Ntp::getTimeShift()
179{ 175{
180 QString _offset = "offset"; 176 QString _offset = "offset";
181 QString _sec = "sec"; 177 QString _sec = "sec";
182 QRegExp _reOffset = QRegExp(_offset); 178 QRegExp _reOffset = QRegExp(_offset);
183 QRegExp _reEndOffset = QRegExp(_sec); 179 QRegExp _reEndOffset = QRegExp(_sec);
184 int posOffset = _reOffset.match( _ntpOutput ); 180 int posOffset = _reOffset.match( _ntpOutput );
185 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); 181 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset );
186 posOffset += _offset.length() + 1; 182 posOffset += _offset.length() + 1;
187 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); 183 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1);
188 qDebug("%s", _ntpOutput.latin1()); 184 qDebug("%s", _ntpOutput.latin1());
189 qDebug("diff = >%s<",diff.latin1()); 185 qDebug("diff = >%s<",diff.latin1());
190 return diff.toFloat(); 186 return diff.toFloat();
191} 187}
192 188
193void Ntp::readLookups() 189void Ntp::readLookups()
194{ 190{
195 Config cfg("ntp",Config::User); 191 Config cfg("ntp",Config::User);
196 cfg.setGroup("lookups"); 192 cfg.setGroup("lookups");
197 int lookupCount = cfg.readNumEntry("count",-1); 193 int lookupCount = cfg.readNumEntry("count",0);
198 float last, shift, shiftPerSec; 194 float last, shift, shiftPerSec;
199 qDebug("lookupCount = %i",lookupCount); 195 qDebug("lookupCount = %i",lookupCount);
200 TableLookups->setNumCols( 3 ); 196 TableLookups->setNumCols( 3 );
201 TableLookups->setNumRows( lookupCount); 197 TableLookups->setNumRows( lookupCount);
202 TableLookups->horizontalHeader()->setLabel(1,"secsSinceLast"); 198 TableLookups->horizontalHeader()->setLabel(1,tr("last [h]"));
203 TableLookups->horizontalHeader()->setLabel(2,"timeShift"); 199 TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]"));
204 TableLookups->horizontalHeader()->setLabel(0,"shift/s"); 200 TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]"));
205 int cw = 50;//TableLookups->width()/4; 201 int cw = 50;//TableLookups->width()/4;
206 qDebug("column width %i",cw); 202 qDebug("column width %i",cw);
207 TableLookups->setColumnWidth( 0, cw+30 ); 203 TableLookups->setColumnWidth( 0, cw+30 );
208 TableLookups->setColumnWidth( 1, cw ); 204 TableLookups->setColumnWidth( 1, cw );
209 TableLookups->setColumnWidth( 2, cw ); 205 TableLookups->setColumnWidth( 2, cw );
210 TableLookups->sortColumn(0, false, true ); 206 TableLookups->sortColumn(0, false, true );
211 // TableLookups->setSorting( true ); 207 // TableLookups->setSorting( true );
212 for (int i=0; i < lookupCount; i++) 208 for (int i=0; i < lookupCount; i++)
213 { 209 {
214 cfg.setGroup("lookup_"+QString::number(i)); 210 cfg.setGroup("lookup_"+QString::number(i));
215 last = cfg.readEntry("secsSinceLast",0).toFloat(); 211 last = cfg.readEntry("secsSinceLast",0).toFloat();
216 shift = QString(cfg.readEntry("timeShift",0)).toFloat(); 212 shift = QString(cfg.readEntry("timeShift",0)).toFloat();
217 // qDebug("%i last %f",i,last); 213 // qDebug("%i last %f",i,last);
218 // qDebug("%i shift %f",i,shift); 214 // qDebug("%i shift %f",i,shift);
219 shiftPerSec = shift / last; 215 shiftPerSec = shift / last;
220 _shiftPerSec += shiftPerSec; 216 _shiftPerSec += shiftPerSec;
221 TableLookups->setText( i,0,QString::number(shiftPerSec)); 217 TableLookups->setText( i,0,QString::number(shiftPerSec*60));
222 TableLookups->setText( i,2,QString::number(shift)); 218 TableLookups->setText( i,2,QString::number(shift));
223 TableLookups->setText( i,1,QString::number(last)); 219 TableLookups->setText( i,1,QString::number(last/60));
224 } 220 }
225 _shiftPerSec /= lookupCount+1; 221 _shiftPerSec /= lookupCount+1;
226 TextLabelShift->setText(QString::number(_shiftPerSec)+tr(" seconds")); 222 TextLabelShift->setText(QString::number(_shiftPerSec)+tr(" seconds"));
227} 223}
228 224
229void Ntp::preditctTime() 225void Ntp::preditctTime()
230{ 226{
231 Config cfg("ntp",Config::User); 227 Config cfg("ntp",Config::User);
232 cfg.setGroup("lookups"); 228 cfg.setGroup("lookups");
233 int lastTime = cfg.readNumEntry("time",0); 229 int lastTime = cfg.readNumEntry("time",0);
234 setenv( "TZ", tz->currentZone(), 1 ); 230 setenv( "TZ", tz->currentZone(), 1 );
235 int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); 231 int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
236 int corr = int((now - lastTime) * _shiftPerSec); 232 int corr = int((now - lastTime) * _shiftPerSec);
237 TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); 233 TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds"));
238 predictedTime = QDateTime::currentDateTime().addSecs(corr); 234 predictedTime = QDateTime::currentDateTime().addSecs(corr);
239 TextLabelPredTime->setText(predictedTime.toString()); 235 TextLabelPredTime->setText(predictedTime.toString());
240 TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); 236 TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>");
241} 237}
242 238
243void Ntp::setPredictTime() 239void Ntp::setPredictTime()
244{ 240{
245 preditctTime(); 241 preditctTime();
246 setTime( predictedTime ); 242 setTime( predictedTime );
247} 243}
248 244
249void Ntp::slotCheckNtp(int i) 245void Ntp::slotCheckNtp(int i)
250{ 246{
251 if (i == 0) 247 if (i == 0)
252 { 248 {
253 TextLabelMainPredTime->hide(); 249 TextLabelMainPredTime->hide();
254 ButtonSetTime->setText( tr("Get time from network") ); 250 ButtonSetTime->setText( tr("Get time from network") );
255 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); 251 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) );
256 if ( ntpDelayElapsed() ) 252 if ( ntpDelayElapsed() )
257 { 253 {
258 slotRunNtp(); 254 slotRunNtp();
259 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); 255 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) );
260 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); 256 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) );
261 }else{ 257 }else{
262 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); 258 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) );
263 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); 259 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
264 } 260 }
265 }else{ 261 }else{
266 preditctTime(); 262 preditctTime();
267 ButtonSetTime->setText( tr("Set predicted time") ); 263 ButtonSetTime->setText( tr("Set predicted time") );
268 if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); 264 if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer());
269 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); 265 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) );
270 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); 266 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
271 } 267 }
272} 268}
273 269
274void Ntp::slotProbeNtpServer() 270void Ntp::slotProbeNtpServer()
275{ 271{
272 qDebug("Ntp::slotProbeNtpServer()");
276 ntpSock->connectToHost( getNtpServer() ,123); 273 ntpSock->connectToHost( getNtpServer() ,123);
277} 274}
278 275
279void Ntp::slotNtpDelayChanged(int delay) 276void Ntp::slotNtpDelayChanged(int delay)
280{ 277{
281 ntpTimer->changeInterval( delay*1000*60 ); 278 ntpTimer->changeInterval( delay*1000*60 );
282} 279}
283 280
284void Ntp::ntpOutPut(QString out) 281void Ntp::ntpOutPut(QString out)
285{ 282{
286 MultiLineEditntpOutPut->append(out); 283 MultiLineEditntpOutPut->append(out);
287 MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); 284 MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE);
288} 285}
289 286
290void Ntp::slotTimeoutNtpProcess()
291{
292 ntpProcess->kill();
293 slotProbeNtpServer();
294}
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
@@ -1,48 +1,47 @@
1#ifndef NTP_H 1#ifndef NTP_H
2#define NTP_H 2#define NTP_H
3#include "settime.h" 3#include "settime.h"
4#include <qdatetime.h> 4#include <qdatetime.h>
5 5
6class OProcess; 6class OProcess;
7class QString; 7class QString;
8class QTimer; 8class QTimer;
9class QSocket; 9class QSocket;
10 10
11class Ntp : public SetDateTime 11class Ntp : public SetDateTime
12{ 12{
13 Q_OBJECT 13 Q_OBJECT
14 14
15public: 15public:
16 Ntp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); 16 Ntp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 );
17 ~Ntp(); 17 ~Ntp();
18 18
19protected: 19protected:
20 QDateTime predictedTime; 20 QDateTime predictedTime;
21 21
22 22
23private: 23private:
24 QString _ntpOutput; 24 QString _ntpOutput;
25 float _shiftPerSec; 25 float _shiftPerSec;
26 int _lookupDiff; 26 int _lookupDiff;
27 OProcess *ntpProcess; 27 OProcess *ntpProcess;
28 QTimer *ntpTimer, *processTimer; 28 QTimer *ntpTimer;
29 QSocket *ntpSock; 29 QSocket *ntpSock;
30 30
31 float getTimeShift(); 31 float getTimeShift();
32 void readLookups(); 32 void readLookups();
33 void ntpOutPut(QString); 33 void ntpOutPut(QString);
34 bool ntpDelayElapsed(); 34 bool ntpDelayElapsed();
35 QString getNtpServer(); 35 QString getNtpServer();
36private slots: 36private slots:
37 void slotRunNtp(); 37 void slotRunNtp();
38 void getNtpOutput(OProcess *proc, char *buffer, int buflen); 38 void getNtpOutput(OProcess *proc, char *buffer, int buflen);
39 void ntpFinished(OProcess*); 39 void ntpFinished(OProcess*);
40 void preditctTime(); 40 void preditctTime();
41 void slotCheckNtp(int); 41 void slotCheckNtp(int);
42 void setPredictTime(); 42 void setPredictTime();
43 void slotProbeNtpServer(); 43 void slotProbeNtpServer();
44 void slotNtpDelayChanged(int); 44 void slotNtpDelayChanged(int);
45 void slotTimeoutNtpProcess();
46}; 45};
47 46
48#endif 47#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
@@ -1,78 +1,78 @@
1<!DOCTYPE UI><UI> 1<!DOCTYPE UI><UI>
2<class>NtpBase</class> 2<class>NtpBase</class>
3<widget> 3<widget>
4 <class>QWidget</class> 4 <class>QWidget</class>
5 <property stdset="1"> 5 <property stdset="1">
6 <name>name</name> 6 <name>name</name>
7 <cstring>NtpBase</cstring> 7 <cstring>NtpBase</cstring>
8 </property> 8 </property>
9 <property stdset="1"> 9 <property stdset="1">
10 <name>geometry</name> 10 <name>geometry</name>
11 <rect> 11 <rect>
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>328</width> 14 <width>324</width>
15 <height>411</height> 15 <height>411</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
18 <property stdset="1"> 18 <property stdset="1">
19 <name>caption</name> 19 <name>caption</name>
20 <string>Network Time</string> 20 <string>Network Time</string>
21 </property> 21 </property>
22 <property> 22 <property>
23 <name>layoutMargin</name> 23 <name>layoutMargin</name>
24 </property> 24 </property>
25 <property> 25 <property>
26 <name>layoutSpacing</name> 26 <name>layoutSpacing</name>
27 </property> 27 </property>
28 <grid> 28 <grid>
29 <property stdset="1"> 29 <property stdset="1">
30 <name>margin</name> 30 <name>margin</name>
31 <number>2</number> 31 <number>2</number>
32 </property> 32 </property>
33 <property stdset="1"> 33 <property stdset="1">
34 <name>spacing</name> 34 <name>spacing</name>
35 <number>2</number> 35 <number>2</number>
36 </property> 36 </property>
37 <widget row="0" column="0" > 37 <widget row="0" column="0" >
38 <class>QTabWidget</class> 38 <class>QTabWidget</class>
39 <property stdset="1"> 39 <property stdset="1">
40 <name>name</name> 40 <name>name</name>
41 <cstring>TabWidgetMain</cstring> 41 <cstring>TabWidgetMain</cstring>
42 </property> 42 </property>
43 <property> 43 <property>
44 <name>layoutMargin</name> 44 <name>layoutMargin</name>
45 </property> 45 </property>
46 <property> 46 <property>
47 <name>layoutSpacing</name> 47 <name>layoutSpacing</name>
48 </property> 48 </property>
49 <widget> 49 <widget>
50 <class>QWidget</class> 50 <class>QWidget</class>
51 <property stdset="1"> 51 <property stdset="1">
52 <name>name</name> 52 <name>name</name>
53 <cstring>tabMain</cstring> 53 <cstring>tabMain</cstring>
54 </property> 54 </property>
55 <attribute> 55 <attribute>
56 <name>title</name> 56 <name>title</name>
57 <string>Main</string> 57 <string>Main</string>
58 </attribute> 58 </attribute>
59 <grid> 59 <grid>
60 <property stdset="1"> 60 <property stdset="1">
61 <name>margin</name> 61 <name>margin</name>
62 <number>2</number> 62 <number>2</number>
63 </property> 63 </property>
64 <property stdset="1"> 64 <property stdset="1">
65 <name>spacing</name> 65 <name>spacing</name>
66 <number>2</number> 66 <number>2</number>
67 </property> 67 </property>
68 <widget row="0" column="0" > 68 <widget row="0" column="0" >
69 <class>QFrame</class> 69 <class>QFrame</class>
70 <property stdset="1"> 70 <property stdset="1">
71 <name>name</name> 71 <name>name</name>
72 <cstring>FrameSystemTime</cstring> 72 <cstring>FrameSystemTime</cstring>
73 </property> 73 </property>
74 <property stdset="1"> 74 <property stdset="1">
75 <name>frameShape</name> 75 <name>frameShape</name>
76 <enum>StyledPanel</enum> 76 <enum>StyledPanel</enum>
77 </property> 77 </property>
78 <property stdset="1"> 78 <property stdset="1">
@@ -239,128 +239,134 @@
239 <name>sizeType</name> 239 <name>sizeType</name>
240 <enum>Expanding</enum> 240 <enum>Expanding</enum>
241 </property> 241 </property>
242 <property> 242 <property>
243 <name>sizeHint</name> 243 <name>sizeHint</name>
244 <size> 244 <size>
245 <width>20</width> 245 <width>20</width>
246 <height>20</height> 246 <height>20</height>
247 </size> 247 </size>
248 </property> 248 </property>
249 </spacer> 249 </spacer>
250 </vbox> 250 </vbox>
251 </widget> 251 </widget>
252 <widget row="1" column="0" > 252 <widget row="1" column="0" >
253 <class>QMultiLineEdit</class> 253 <class>QMultiLineEdit</class>
254 <property stdset="1"> 254 <property stdset="1">
255 <name>name</name> 255 <name>name</name>
256 <cstring>MultiLineEditntpOutPut</cstring> 256 <cstring>MultiLineEditntpOutPut</cstring>
257 </property> 257 </property>
258 <property stdset="1"> 258 <property stdset="1">
259 <name>font</name> 259 <name>font</name>
260 <font> 260 <font>
261 <pointsize>7</pointsize> 261 <pointsize>7</pointsize>
262 </font> 262 </font>
263 </property> 263 </property>
264 <property stdset="1"> 264 <property stdset="1">
265 <name>wordWrap</name> 265 <name>wordWrap</name>
266 <enum>WidgetWidth</enum> 266 <enum>WidgetWidth</enum>
267 </property> 267 </property>
268 <property stdset="1"> 268 <property stdset="1">
269 <name>text</name> 269 <name>text</name>
270 <string></string> 270 <string></string>
271 </property> 271 </property>
272 </widget> 272 </widget>
273 </grid> 273 </grid>
274 </widget> 274 </widget>
275 </grid> 275 </grid>
276 </widget> 276 </widget>
277 <widget> 277 <widget>
278 <class>QWidget</class> 278 <class>QWidget</class>
279 <property stdset="1"> 279 <property stdset="1">
280 <name>name</name> 280 <name>name</name>
281 <cstring>tab</cstring> 281 <cstring>tab</cstring>
282 </property> 282 </property>
283 <attribute> 283 <attribute>
284 <name>title</name> 284 <name>title</name>
285 <string>Predict</string> 285 <string>Predict</string>
286 </attribute> 286 </attribute>
287 <grid> 287 <grid>
288 <property stdset="1"> 288 <property stdset="1">
289 <name>margin</name> 289 <name>margin</name>
290 <number>5</number> 290 <number>5</number>
291 </property> 291 </property>
292 <property stdset="1"> 292 <property stdset="1">
293 <name>spacing</name> 293 <name>spacing</name>
294 <number>6</number> 294 <number>6</number>
295 </property> 295 </property>
296 <widget row="0" column="0" > 296 <widget row="0" column="0" >
297 <class>QTable</class> 297 <class>QTable</class>
298 <property stdset="1"> 298 <property stdset="1">
299 <name>name</name> 299 <name>name</name>
300 <cstring>TableLookups</cstring> 300 <cstring>TableLookups</cstring>
301 </property> 301 </property>
302 <property stdset="1"> 302 <property stdset="1">
303 <name>font</name>
304 <font>
305 <pointsize>8</pointsize>
306 </font>
307 </property>
308 <property stdset="1">
303 <name>numRows</name> 309 <name>numRows</name>
304 <number>2</number> 310 <number>2</number>
305 </property> 311 </property>
306 <property stdset="1"> 312 <property stdset="1">
307 <name>numCols</name> 313 <name>numCols</name>
308 <number>2</number> 314 <number>2</number>
309 </property> 315 </property>
310 </widget> 316 </widget>
311 <widget row="1" column="0" > 317 <widget row="1" column="0" >
312 <class>QLayoutWidget</class> 318 <class>QLayoutWidget</class>
313 <property stdset="1"> 319 <property stdset="1">
314 <name>name</name> 320 <name>name</name>
315 <cstring>Layout9</cstring> 321 <cstring>Layout9</cstring>
316 </property> 322 </property>
317 <grid> 323 <grid>
318 <property stdset="1"> 324 <property stdset="1">
319 <name>margin</name> 325 <name>margin</name>
320 <number>0</number> 326 <number>0</number>
321 </property> 327 </property>
322 <property stdset="1"> 328 <property stdset="1">
323 <name>spacing</name> 329 <name>spacing</name>
324 <number>6</number> 330 <number>6</number>
325 </property> 331 </property>
326 <widget row="0" column="1" > 332 <widget row="0" column="1" >
327 <class>QLabel</class> 333 <class>QLabel</class>
328 <property stdset="1"> 334 <property stdset="1">
329 <name>name</name> 335 <name>name</name>
330 <cstring>TextLabelShift</cstring> 336 <cstring>TextLabelShift</cstring>
331 </property> 337 </property>
332 <property stdset="1"> 338 <property stdset="1">
333 <name>text</name> 339 <name>text</name>
334 <string>nan</string> 340 <string>nan</string>
335 </property> 341 </property>
336 </widget> 342 </widget>
337 <widget row="1" column="0" > 343 <widget row="1" column="0" >
338 <class>QLabel</class> 344 <class>QLabel</class>
339 <property stdset="1"> 345 <property stdset="1">
340 <name>name</name> 346 <name>name</name>
341 <cstring>TextLabel4</cstring> 347 <cstring>TextLabel4</cstring>
342 </property> 348 </property>
343 <property stdset="1"> 349 <property stdset="1">
344 <name>text</name> 350 <name>text</name>
345 <string>Esimated Shift:</string> 351 <string>Esimated Shift:</string>
346 </property> 352 </property>
347 </widget> 353 </widget>
348 <widget row="1" column="1" > 354 <widget row="1" column="1" >
349 <class>QLabel</class> 355 <class>QLabel</class>
350 <property stdset="1"> 356 <property stdset="1">
351 <name>name</name> 357 <name>name</name>
352 <cstring>TextLabelEstimatedShift</cstring> 358 <cstring>TextLabelEstimatedShift</cstring>
353 </property> 359 </property>
354 <property stdset="1"> 360 <property stdset="1">
355 <name>text</name> 361 <name>text</name>
356 <string>nan</string> 362 <string>nan</string>
357 </property> 363 </property>
358 </widget> 364 </widget>
359 <widget row="2" column="0" > 365 <widget row="2" column="0" >
360 <class>QLabel</class> 366 <class>QLabel</class>
361 <property stdset="1"> 367 <property stdset="1">
362 <name>name</name> 368 <name>name</name>
363 <cstring>TextLabel3_2</cstring> 369 <cstring>TextLabel3_2</cstring>
364 </property> 370 </property>
365 <property stdset="1"> 371 <property stdset="1">
366 <name>text</name> 372 <name>text</name>