summaryrefslogtreecommitdiff
path: root/noncore
authortille <tille>2002-06-24 11:16:30 (UTC)
committer tille <tille>2002-06-24 11:16:30 (UTC)
commit5bbfde2c34b3bbccdae89171fa0528ca8ae22b32 (patch) (unidiff)
tree69546c118ae88be28c29196db39205620de702f1 /noncore
parent191d88cc062f4c50b28984e17b93139c685efee1 (diff)
downloadopie-5bbfde2c34b3bbccdae89171fa0528ca8ae22b32.zip
opie-5bbfde2c34b3bbccdae89171fa0528ca8ae22b32.tar.gz
opie-5bbfde2c34b3bbccdae89171fa0528ca8ae22b32.tar.bz2
added predict time
Diffstat (limited to 'noncore') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp42
-rw-r--r--noncore/settings/netsystemtime/ntp.h1
-rw-r--r--noncore/settings/netsystemtime/ntpbase.ui117
3 files changed, 134 insertions, 26 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index c2b64f0..04b113b 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -31,6 +31,7 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
31 connect ( ntpProcess, SIGNAL(processExited(OProcess*)), 31 connect ( ntpProcess, SIGNAL(processExited(OProcess*)),
32 this, SLOT(ntpFinished(OProcess*))); 32 this, SLOT(ntpFinished(OProcess*)));
33 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); 33 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp()));
34 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime()));
34 _nextCorrection = new QTimer( this ); 35 _nextCorrection = new QTimer( this );
35 connect( _nextCorrection, SIGNAL(timeout()), SLOT(correctClock()) ); 36 connect( _nextCorrection, SIGNAL(timeout()), SLOT(correctClock()) );
36 slotRunNtp(); 37 slotRunNtp();
@@ -80,7 +81,7 @@ void Ntp::ntpFinished(OProcess*)
80 cfg.writeEntry("time", time); 81 cfg.writeEntry("time", time);
81 82
82 float timeShift = getTimeShift(); 83 float timeShift = getTimeShift();
83 if (timeShift = 0.0) return; 84 if (timeShift == 0.0) return;
84 int secsSinceLast = time - lastLookup; 85 int secsSinceLast = time - lastLookup;
85 TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); 86 TextLabelNewTime->setText(QDateTime::currentDateTime().toString());
86 if ( lastLookup > 0 && secsSinceLast > 60*_minLookupDiff) 87 if ( lastLookup > 0 && secsSinceLast > 60*_minLookupDiff)
@@ -90,7 +91,7 @@ void Ntp::ntpFinished(OProcess*)
90 cfg.setGroup("lookup_"+QString::number(lookupCount)); 91 cfg.setGroup("lookup_"+QString::number(lookupCount));
91 _shiftPerSec = timeShift / secsSinceLast; 92 _shiftPerSec = timeShift / secsSinceLast;
92 float nextCorr = _maxOffset / _shiftPerSec; 93 float nextCorr = _maxOffset / _shiftPerSec;
93 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec);qDebug("in %f secs the time will be shifted by %i", nextCorr,_maxOffset); 94 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec);
94 cfg.writeEntry("secsSinceLast",secsSinceLast); 95 cfg.writeEntry("secsSinceLast",secsSinceLast);
95 cfg.writeEntry("timeShift",QString::number(timeShift)); 96 cfg.writeEntry("timeShift",QString::number(timeShift));
96 } 97 }
@@ -137,10 +138,43 @@ void Ntp::readLookups()
137 Config cfg("ntp",Config::User); 138 Config cfg("ntp",Config::User);
138 cfg.setGroup("lookups"); 139 cfg.setGroup("lookups");
139 int lookupCount = cfg.readNumEntry("count",-1); 140 int lookupCount = cfg.readNumEntry("count",-1);
141 float last, shift, shiftPerSec;
142 qDebug("lookupCount = %i",lookupCount);
143 TableLookups->setNumCols( 3 );
144 TableLookups->setNumRows( lookupCount);
145 TableLookups->horizontalHeader()->setLabel(2,"secsSinceLast");
146 TableLookups->horizontalHeader()->setLabel(1,"timeShift");
147 TableLookups->horizontalHeader()->setLabel(0,"shift/s");
148 int cw = TableLookups->width()/4;
149 qDebug("column width %i",cw);
150 TableLookups->setColumnWidth( 0, cw );
151 TableLookups->setColumnWidth( 1, cw );
152 TableLookups->setColumnWidth( 2, cw );
140 for (int i=0; i < lookupCount; i++) 153 for (int i=0; i < lookupCount; i++)
141 { 154 {
142 cfg.setGroup("lookup_"+QString::number(i)); 155 cfg.setGroup("lookup_"+QString::number(i));
143 TableLookups->setText( 1,i,cfg.readEntry("secsSinceLast",0)); 156 last = cfg.readEntry("secsSinceLast",0).toFloat();
144 TableLookups->setText( 2,i,cfg.readEntry("timeShift",0)); 157 shift = QString(cfg.readEntry("timeShift",0)).toFloat();
158 qDebug("%i last %f",i,last);
159 qDebug("%i shift %f",i,shift);
160 shiftPerSec = shift / last;
161 _shiftPerSec += shiftPerSec;
162 TableLookups->setText( i,0,QString::number(shiftPerSec));
163 TableLookups->setText( i,1,QString::number(shift));
164 TableLookups->setText( i,2,QString::number(last));
145 } 165 }
166 _shiftPerSec /= lookupCount+1;
167 TextLabelShift->setText(QString::number(_shiftPerSec));
168}
169
170void Ntp::preditctTime()
171{
172 qDebug("current time: %s",QDateTime::currentDateTime().toString().latin1());
173 Config cfg("ntp",Config::User);
174 cfg.setGroup("lookups");
175 int lastTime = cfg.readNumEntry("time",0);
176 int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
177 int corr = int((now - lastTime) * _shiftPerSec);
178 outPut->append( "time will be shifted by "+QString::number(corr)+ "secs");
179 TextLabelPredTime->setText(QDateTime::currentDateTime().addSecs(corr).toString());
146} 180}
diff --git a/noncore/settings/netsystemtime/ntp.h b/noncore/settings/netsystemtime/ntp.h
index 4dc04b1..e3f6d16 100644
--- a/noncore/settings/netsystemtime/ntp.h
+++ b/noncore/settings/netsystemtime/ntp.h
@@ -32,6 +32,7 @@ private slots:
32 void getNtpOutput(OProcess *proc, char *buffer, int buflen); 32 void getNtpOutput(OProcess *proc, char *buffer, int buflen);
33 void ntpFinished(OProcess*); 33 void ntpFinished(OProcess*);
34 void correctClock(); 34 void correctClock();
35 void preditctTime();
35}; 36};
36 37
37#endif 38#endif
diff --git a/noncore/settings/netsystemtime/ntpbase.ui b/noncore/settings/netsystemtime/ntpbase.ui
index eb09e4a..1c1e1aa 100644
--- a/noncore/settings/netsystemtime/ntpbase.ui
+++ b/noncore/settings/netsystemtime/ntpbase.ui
@@ -11,7 +11,7 @@
11 <rect> 11 <rect>
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>296</width> 14 <width>292</width>
15 <height>337</height> 15 <height>337</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
@@ -140,7 +140,7 @@
140 </property> 140 </property>
141 <property stdset="1"> 141 <property stdset="1">
142 <name>text</name> 142 <name>text</name>
143 <string></string> 143 <string>nan</string>
144 </property> 144 </property>
145 </widget> 145 </widget>
146 <widget> 146 <widget>
@@ -162,7 +162,7 @@
162 </property> 162 </property>
163 <property stdset="1"> 163 <property stdset="1">
164 <name>text</name> 164 <name>text</name>
165 <string></string> 165 <string>nan</string>
166 </property> 166 </property>
167 </widget> 167 </widget>
168 <widget> 168 <widget>
@@ -184,7 +184,7 @@
184 </property> 184 </property>
185 <property stdset="1"> 185 <property stdset="1">
186 <name>text</name> 186 <name>text</name>
187 <string></string> 187 <string>nan</string>
188 </property> 188 </property>
189 </widget> 189 </widget>
190 <spacer> 190 <spacer>
@@ -259,30 +259,103 @@
259 <name>title</name> 259 <name>title</name>
260 <string>Auto Correction</string> 260 <string>Auto Correction</string>
261 </attribute> 261 </attribute>
262 <widget> 262 <grid>
263 <class>QTable</class>
264 <property stdset="1">
265 <name>name</name>
266 <cstring>TableLookups</cstring>
267 </property>
268 <property stdset="1">
269 <name>geometry</name>
270 <rect>
271 <x>10</x>
272 <y>10</y>
273 <width>270</width>
274 <height>220</height>
275 </rect>
276 </property>
277 <property stdset="1"> 263 <property stdset="1">
278 <name>numRows</name> 264 <name>margin</name>
279 <number>2</number> 265 <number>2</number>
280 </property> 266 </property>
281 <property stdset="1"> 267 <property stdset="1">
282 <name>numCols</name> 268 <name>spacing</name>
283 <number>2</number> 269 <number>2</number>
284 </property> 270 </property>
285 </widget> 271 <widget row="0" column="0" >
272 <class>QTable</class>
273 <property stdset="1">
274 <name>name</name>
275 <cstring>TableLookups</cstring>
276 </property>
277 <property stdset="1">
278 <name>numRows</name>
279 <number>2</number>
280 </property>
281 <property stdset="1">
282 <name>numCols</name>
283 <number>2</number>
284 </property>
285 </widget>
286 <widget row="2" column="0" >
287 <class>QPushButton</class>
288 <property stdset="1">
289 <name>name</name>
290 <cstring>PushButtonPredict</cstring>
291 </property>
292 <property stdset="1">
293 <name>text</name>
294 <string>predict time</string>
295 </property>
296 </widget>
297 <widget row="1" column="0" >
298 <class>QLayoutWidget</class>
299 <property stdset="1">
300 <name>name</name>
301 <cstring>Layout5</cstring>
302 </property>
303 <grid>
304 <property stdset="1">
305 <name>margin</name>
306 <number>0</number>
307 </property>
308 <property stdset="1">
309 <name>spacing</name>
310 <number>6</number>
311 </property>
312 <widget row="0" column="1" >
313 <class>QLabel</class>
314 <property stdset="1">
315 <name>name</name>
316 <cstring>TextLabelShift</cstring>
317 </property>
318 <property stdset="1">
319 <name>text</name>
320 <string>nan</string>
321 </property>
322 </widget>
323 <widget row="1" column="1" >
324 <class>QLabel</class>
325 <property stdset="1">
326 <name>name</name>
327 <cstring>TextLabelPredTime</cstring>
328 </property>
329 <property stdset="1">
330 <name>text</name>
331 <string>nan</string>
332 </property>
333 </widget>
334 <widget row="0" column="0" >
335 <class>QLabel</class>
336 <property stdset="1">
337 <name>name</name>
338 <cstring>Mean_shift_label</cstring>
339 </property>
340 <property stdset="1">
341 <name>text</name>
342 <string>Mean shift:</string>
343 </property>
344 </widget>
345 <widget row="1" column="0" >
346 <class>QLabel</class>
347 <property stdset="1">
348 <name>name</name>
349 <cstring>TextLabel3_2</cstring>
350 </property>
351 <property stdset="1">
352 <name>text</name>
353 <string>Pred. Time:</string>
354 </property>
355 </widget>
356 </grid>
357 </widget>
358 </grid>
286 </widget> 359 </widget>
287 <widget> 360 <widget>
288 <class>QWidget</class> 361 <class>QWidget</class>