summaryrefslogtreecommitdiff
authortille <tille>2002-06-26 16:34:14 (UTC)
committer tille <tille>2002-06-26 16:34:14 (UTC)
commit9d692658a94c59889c6e46baaeae971226952eb8 (patch) (unidiff)
tree4cd8a9cf939a5e096e3c1610feac1678131b1673
parent12ec527b60e774d0f794fa98f8b6fdf9c194b7a9 (diff)
downloadopie-9d692658a94c59889c6e46baaeae971226952eb8.zip
opie-9d692658a94c59889c6e46baaeae971226952eb8.tar.gz
opie-9d692658a94c59889c6e46baaeae971226952eb8.tar.bz2
improved startup
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp3
1 files changed, 1 insertions, 2 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index bcbf7a1..b2f5332 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -77,206 +77,205 @@ Ntp::~Ntp()
77 { 77 {
78 ntpSrvs.setGroup(QString::number(i)); 78 ntpSrvs.setGroup(QString::number(i));
79 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); 79 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) );
80 } 80 }
81 Config cfg("ntp",Config::User); 81 Config cfg("ntp",Config::User);
82 cfg.setGroup("settings"); 82 cfg.setGroup("settings");
83 cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); 83 cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem());
84 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); 84 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() );
85 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); 85 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() );
86} 86}
87 87
88bool Ntp::ntpDelayElapsed() 88bool Ntp::ntpDelayElapsed()
89{ 89{
90 Config cfg("ntp",Config::User); 90 Config cfg("ntp",Config::User);
91 cfg.setGroup("lookups"); 91 cfg.setGroup("lookups");
92 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); 92 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
93 return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60; 93 return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60;
94} 94}
95 95
96QString Ntp::getNtpServer() 96QString Ntp::getNtpServer()
97{ 97{
98 return ComboNtpSrv->currentText(); 98 return ComboNtpSrv->currentText();
99} 99}
100 100
101void Ntp::slotRunNtp() 101void Ntp::slotRunNtp()
102{ 102{
103 if ( !ntpDelayElapsed() ) 103 if ( !ntpDelayElapsed() )
104 { 104 {
105 switch ( 105 switch (
106 QMessageBox::warning(this, tr("Run NTP?"), 106 QMessageBox::warning(this, tr("Run NTP?"),
107 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ 107 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+
108 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+ 108 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+
109 "<br>"+tr("Rerun NTP?"), 109 "<br>"+tr("Rerun NTP?"),
110 QMessageBox::Ok,QMessageBox::Cancel) 110 QMessageBox::Ok,QMessageBox::Cancel)
111 ) { 111 ) {
112 case QMessageBox::Ok: break; 112 case QMessageBox::Ok: break;
113 case QMessageBox::Cancel: return; 113 case QMessageBox::Cancel: return;
114 default: return; 114 default: return;
115 } 115 }
116 } 116 }
117 TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); 117 TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
118 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); 118 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() );
119 ntpProcess->clearArguments(); 119 ntpProcess->clearArguments();
120 *ntpProcess << "ntpdate" << getNtpServer(); 120 *ntpProcess << "ntpdate" << getNtpServer();
121 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); 121 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
122 if ( !ret ) { 122 if ( !ret ) {
123 qDebug("Error while executing ntpdate"); 123 qDebug("Error while executing ntpdate");
124 ntpOutPut( tr("Error while executing ntpdate")); 124 ntpOutPut( tr("Error while executing ntpdate"));
125 } 125 }
126} 126}
127 127
128void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) 128void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
129{ 129{
130 QString lineStr, lineStrOld; 130 QString lineStr, lineStrOld;
131 lineStr = buffer; 131 lineStr = buffer;
132 lineStr=lineStr.left(buflen); 132 lineStr=lineStr.left(buflen);
133 if (lineStr!=lineStrOld) 133 if (lineStr!=lineStrOld)
134 { 134 {
135 ntpOutPut(lineStr); 135 ntpOutPut(lineStr);
136 _ntpOutput += lineStr; 136 _ntpOutput += lineStr;
137 } 137 }
138 lineStrOld = lineStr; 138 lineStrOld = lineStr;
139} 139}
140 140
141void Ntp::ntpFinished(OProcess*) 141void Ntp::ntpFinished(OProcess*)
142{ 142{
143 Config cfg("ntp",Config::User); 143 Config cfg("ntp",Config::User);
144 cfg.setGroup("lookups"); 144 cfg.setGroup("lookups");
145 int lastLookup = cfg.readNumEntry("time",0); 145 int lastLookup = cfg.readNumEntry("time",0);
146 int lookupCount = cfg.readNumEntry("count",-1); 146 int lookupCount = cfg.readNumEntry("count",-1);
147 int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); 147 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
148 cfg.writeEntry("time", time); 148 cfg.writeEntry("time", time);
149 cfg.setGroup("correction"); 149 cfg.setGroup("correction");
150 cfg.writeEntry("time", time); 150 cfg.writeEntry("time", time);
151 151
152 float timeShift = getTimeShift(); 152 float timeShift = getTimeShift();
153 if (timeShift == 0.0) return; 153 if (timeShift == 0.0) return;
154 int secsSinceLast = time - lastLookup; 154 int secsSinceLast = time - lastLookup;
155 TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); 155 TextLabelNewTime->setText(QDateTime::currentDateTime().toString());
156 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); 156 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds"));
157 if ( lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) 157 if ( lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value())
158 { 158 {
159 lookupCount++; 159 lookupCount++;
160 cfg.writeEntry("count",lookupCount); 160 cfg.writeEntry("count",lookupCount);
161 cfg.setGroup("lookup_"+QString::number(lookupCount)); 161 cfg.setGroup("lookup_"+QString::number(lookupCount));
162 _shiftPerSec = timeShift / secsSinceLast; 162 _shiftPerSec = timeShift / secsSinceLast;
163 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); 163 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec);
164 cfg.writeEntry("secsSinceLast",secsSinceLast); 164 cfg.writeEntry("secsSinceLast",secsSinceLast);
165 cfg.writeEntry("timeShift",QString::number(timeShift)); 165 cfg.writeEntry("timeShift",QString::number(timeShift));
166 } 166 }
167} 167}
168 168
169 169
170float Ntp::getTimeShift() 170float Ntp::getTimeShift()
171{ 171{
172 QString _offset = "offset"; 172 QString _offset = "offset";
173 QString _sec = "sec"; 173 QString _sec = "sec";
174 QRegExp _reOffset = QRegExp(_offset); 174 QRegExp _reOffset = QRegExp(_offset);
175 QRegExp _reEndOffset = QRegExp(_sec); 175 QRegExp _reEndOffset = QRegExp(_sec);
176 int posOffset = _reOffset.match( _ntpOutput ); 176 int posOffset = _reOffset.match( _ntpOutput );
177 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); 177 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset );
178 posOffset += _offset.length() + 1; 178 posOffset += _offset.length() + 1;
179 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); 179 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1);
180 qDebug("%s", _ntpOutput.latin1()); 180 qDebug("%s", _ntpOutput.latin1());
181 qDebug("diff = >%s<",diff.latin1()); 181 qDebug("diff = >%s<",diff.latin1());
182 return diff.toFloat(); 182 return diff.toFloat();
183} 183}
184 184
185void Ntp::readLookups() 185void Ntp::readLookups()
186{ 186{
187 Config cfg("ntp",Config::User); 187 Config cfg("ntp",Config::User);
188 cfg.setGroup("lookups"); 188 cfg.setGroup("lookups");
189 int lookupCount = cfg.readNumEntry("count",-1); 189 int lookupCount = cfg.readNumEntry("count",-1);
190 float last, shift, shiftPerSec; 190 float last, shift, shiftPerSec;
191 qDebug("lookupCount = %i",lookupCount); 191 qDebug("lookupCount = %i",lookupCount);
192 TableLookups->setNumCols( 3 ); 192 TableLookups->setNumCols( 3 );
193 TableLookups->setNumRows( lookupCount); 193 TableLookups->setNumRows( lookupCount);
194 TableLookups->horizontalHeader()->setLabel(1,"secsSinceLast"); 194 TableLookups->horizontalHeader()->setLabel(1,"secsSinceLast");
195 TableLookups->horizontalHeader()->setLabel(2,"timeShift"); 195 TableLookups->horizontalHeader()->setLabel(2,"timeShift");
196 TableLookups->horizontalHeader()->setLabel(0,"shift/s"); 196 TableLookups->horizontalHeader()->setLabel(0,"shift/s");
197 int cw = 50;//TableLookups->width()/4; 197 int cw = 50;//TableLookups->width()/4;
198 qDebug("column width %i",cw); 198 qDebug("column width %i",cw);
199 TableLookups->setColumnWidth( 0, cw+30 ); 199 TableLookups->setColumnWidth( 0, cw+30 );
200 TableLookups->setColumnWidth( 1, cw ); 200 TableLookups->setColumnWidth( 1, cw );
201 TableLookups->setColumnWidth( 2, cw ); 201 TableLookups->setColumnWidth( 2, cw );
202 TableLookups->sortColumn(0, false, true ); 202 TableLookups->sortColumn(0, false, true );
203 // TableLookups->setSorting( true ); 203 // TableLookups->setSorting( true );
204 for (int i=0; i < lookupCount; i++) 204 for (int i=0; i < lookupCount; i++)
205 { 205 {
206 cfg.setGroup("lookup_"+QString::number(i)); 206 cfg.setGroup("lookup_"+QString::number(i));
207 last = cfg.readEntry("secsSinceLast",0).toFloat(); 207 last = cfg.readEntry("secsSinceLast",0).toFloat();
208 shift = QString(cfg.readEntry("timeShift",0)).toFloat(); 208 shift = QString(cfg.readEntry("timeShift",0)).toFloat();
209 // qDebug("%i last %f",i,last); 209 // qDebug("%i last %f",i,last);
210 // qDebug("%i shift %f",i,shift); 210 // qDebug("%i shift %f",i,shift);
211 shiftPerSec = shift / last; 211 shiftPerSec = shift / last;
212 _shiftPerSec += shiftPerSec; 212 _shiftPerSec += shiftPerSec;
213 TableLookups->setText( i,0,QString::number(shiftPerSec)); 213 TableLookups->setText( i,0,QString::number(shiftPerSec));
214 TableLookups->setText( i,2,QString::number(shift)); 214 TableLookups->setText( i,2,QString::number(shift));
215 TableLookups->setText( i,1,QString::number(last)); 215 TableLookups->setText( i,1,QString::number(last));
216 } 216 }
217 _shiftPerSec /= lookupCount+1; 217 _shiftPerSec /= lookupCount+1;
218 TextLabelShift->setText(QString::number(_shiftPerSec)+tr(" seconds")); 218 TextLabelShift->setText(QString::number(_shiftPerSec)+tr(" seconds"));
219} 219}
220 220
221void Ntp::preditctTime() 221void Ntp::preditctTime()
222{ 222{
223 Config cfg("ntp",Config::User); 223 Config cfg("ntp",Config::User);
224 cfg.setGroup("lookups"); 224 cfg.setGroup("lookups");
225 int lastTime = cfg.readNumEntry("time",0); 225 int lastTime = cfg.readNumEntry("time",0);
226 setenv( "TZ", tz->currentZone(), 1 ); 226 setenv( "TZ", tz->currentZone(), 1 );
227 int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); 227 int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
228 int corr = int((now - lastTime) * _shiftPerSec); 228 int corr = int((now - lastTime) * _shiftPerSec);
229 TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); 229 TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds"));
230 predictedTime = QDateTime::currentDateTime().addSecs(corr); 230 predictedTime = QDateTime::currentDateTime().addSecs(corr);
231 TextLabelPredTime->setText(predictedTime.toString()); 231 TextLabelPredTime->setText(predictedTime.toString());
232 TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); 232 TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>");
233} 233}
234 234
235void Ntp::setPredictTime() 235void Ntp::setPredictTime()
236{ 236{
237 preditctTime(); 237 preditctTime();
238 setTime( predictedTime ); 238 setTime( predictedTime );
239} 239}
240 240
241void Ntp::slotCheckNtp(int i) 241void Ntp::slotCheckNtp(int i)
242{ 242{
243 if (i == 0) 243 if (i == 0)
244 { 244 {
245 TextLabelMainPredTime->hide(); 245 TextLabelMainPredTime->hide();
246 ButtonSetTime->setText( tr("Get time from network") ); 246 ButtonSetTime->setText( tr("Get time from network") );
247 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); 247 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) );
248 if ( ntpDelayElapsed() ) 248 if ( ntpDelayElapsed() )
249 { 249 {
250 slotRunNtp(); 250 slotRunNtp();
251 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); 251 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) );
252 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); 252 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) );
253 }else{ 253 }else{
254 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); 254 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) );
255 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); 255 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
256 } 256 }
257 }else{ 257 }else{
258 preditctTime(); 258 preditctTime();
259 ButtonSetTime->setText( tr("Set predicted time") ); 259 ButtonSetTime->setText( tr("Set predicted time") );
260 if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); 260 if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer());
261 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); 261 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) );
262 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); 262 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
263 } 263 }
264 //ntpTimer->start(SpinBoxNtpDelay->value()*1000*60); 264 //ntpTimer->start(SpinBoxNtpDelay->value()*1000*60);
265} 265}
266 266
267void Ntp::slotProbeNtpServer() 267void Ntp::slotProbeNtpServer()
268{ 268{
269 if ( ntpDelayElapsed() ) 269 ntpSock->connectToHost( getNtpServer() ,123);
270 ntpSock->connectToHost( getNtpServer() ,123);
271} 270}
272 271
273void Ntp::slotNtpDelayChanged(int delay) 272void Ntp::slotNtpDelayChanged(int delay)
274{ 273{
275 ntpTimer->changeInterval( delay*1000*60 ); 274 ntpTimer->changeInterval( delay*1000*60 );
276} 275}
277 276
278void Ntp::ntpOutPut(QString out) 277void Ntp::ntpOutPut(QString out)
279{ 278{
280 MultiLineEditntpOutPut->append(out); 279 MultiLineEditntpOutPut->append(out);
281 MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); 280 MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE);
282} 281}