summaryrefslogtreecommitdiff
authortille <tille>2002-06-24 11:16:30 (UTC)
committer tille <tille>2002-06-24 11:16:30 (UTC)
commit5bbfde2c34b3bbccdae89171fa0528ca8ae22b32 (patch) (unidiff)
tree69546c118ae88be28c29196db39205620de702f1
parent191d88cc062f4c50b28984e17b93139c685efee1 (diff)
downloadopie-5bbfde2c34b3bbccdae89171fa0528ca8ae22b32.zip
opie-5bbfde2c34b3bbccdae89171fa0528ca8ae22b32.tar.gz
opie-5bbfde2c34b3bbccdae89171fa0528ca8ae22b32.tar.bz2
added predict time
Diffstat (more/less context) (show 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.ui101
3 files changed, 126 insertions, 18 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
@@ -22,24 +22,25 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
22{ 22{
23 Config cfg("ntp",Config::User); 23 Config cfg("ntp",Config::User);
24 cfg.setGroup("settings"); 24 cfg.setGroup("settings");
25 _maxOffset = cfg.readNumEntry("maxOffset",5); 25 _maxOffset = cfg.readNumEntry("maxOffset",5);
26 _minLookupDiff = cfg.readNumEntry("minLookupDiff",10); 26 _minLookupDiff = cfg.readNumEntry("minLookupDiff",10);
27 LineEditNtpServer->setText( cfg.readEntry("ntpServer") ); 27 LineEditNtpServer->setText( cfg.readEntry("ntpServer") );
28 ntpProcess = new OProcess( ); 28 ntpProcess = new OProcess( );
29 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), 29 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)),
30 this, SLOT(getNtpOutput(OProcess*,char*,int))); 30 this, SLOT(getNtpOutput(OProcess*,char*,int)));
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();
37 readLookups(); 38 readLookups();
38} 39}
39 40
40Ntp::~Ntp() 41Ntp::~Ntp()
41{ 42{
42 Config cfg("ntp",Config::User); 43 Config cfg("ntp",Config::User);
43 cfg.setGroup("settings"); 44 cfg.setGroup("settings");
44 cfg.writeEntry("ntpServer", LineEditNtpServer->text()); 45 cfg.writeEntry("ntpServer", LineEditNtpServer->text());
45} 46}
@@ -71,35 +72,35 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
71} 72}
72 73
73void Ntp::ntpFinished(OProcess*) 74void Ntp::ntpFinished(OProcess*)
74{ 75{
75 Config cfg("ntp",Config::User); 76 Config cfg("ntp",Config::User);
76 cfg.setGroup("lookups"); 77 cfg.setGroup("lookups");
77 int lastLookup = cfg.readNumEntry("time",0); 78 int lastLookup = cfg.readNumEntry("time",0);
78 int lookupCount = cfg.readNumEntry("count",-1); 79 int lookupCount = cfg.readNumEntry("count",-1);
79 int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); 80 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
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)
87 { 88 {
88 lookupCount++; 89 lookupCount++;
89 cfg.writeEntry("count",lookupCount); 90 cfg.writeEntry("count",lookupCount);
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 }
97} 98}
98 99
99void Ntp::correctClock() 100void Ntp::correctClock()
100{ 101{
101 qDebug("current time: %s",QDateTime::currentDateTime().toString().latin1()); 102 qDebug("current time: %s",QDateTime::currentDateTime().toString().latin1());
102 Config cfg("ntp",Config::User); 103 Config cfg("ntp",Config::User);
103 cfg.setGroup("correction"); 104 cfg.setGroup("correction");
104 int lastTime = cfg.readNumEntry("time",0); 105 int lastTime = cfg.readNumEntry("time",0);
105 int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); 106 int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
@@ -128,19 +129,52 @@ float Ntp::getTimeShift()
128 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); 129 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1);
129 qDebug("%s", _ntpOutput.latin1()); 130 qDebug("%s", _ntpOutput.latin1());
130 qDebug("diff = >%s<",diff.latin1()); 131 qDebug("diff = >%s<",diff.latin1());
131 TextLabelTimeShift->setText(diff); 132 TextLabelTimeShift->setText(diff);
132 return diff.toFloat(); 133 return diff.toFloat();
133} 134}
134 135
135void Ntp::readLookups() 136void Ntp::readLookups()
136{ 137{
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
@@ -23,15 +23,16 @@ private:
23 int _maxOffset; 23 int _maxOffset;
24 float _shiftPerSec; 24 float _shiftPerSec;
25 QTimer *_nextCorrection; 25 QTimer *_nextCorrection;
26 int _minLookupDiff; 26 int _minLookupDiff;
27 27
28 float getTimeShift(); 28 float getTimeShift();
29 void readLookups(); 29 void readLookups();
30private slots: 30private slots:
31 void slotRunNtp(); 31 void slotRunNtp();
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
@@ -2,25 +2,25 @@
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>296</width> 14 <width>292</width>
15 <height>337</height> 15 <height>337</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>
@@ -131,69 +131,69 @@
131 <name>text</name> 131 <name>text</name>
132 <string>Start Time:</string> 132 <string>Start Time:</string>
133 </property> 133 </property>
134 </widget> 134 </widget>
135 <widget> 135 <widget>
136 <class>QLabel</class> 136 <class>QLabel</class>
137 <property stdset="1"> 137 <property stdset="1">
138 <name>name</name> 138 <name>name</name>
139 <cstring>TextLabelStartTime</cstring> 139 <cstring>TextLabelStartTime</cstring>
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>
147 <class>QLabel</class> 147 <class>QLabel</class>
148 <property stdset="1"> 148 <property stdset="1">
149 <name>name</name> 149 <name>name</name>
150 <cstring>TextLabel3</cstring> 150 <cstring>TextLabel3</cstring>
151 </property> 151 </property>
152 <property stdset="1"> 152 <property stdset="1">
153 <name>text</name> 153 <name>text</name>
154 <string>Time Shift:</string> 154 <string>Time Shift:</string>
155 </property> 155 </property>
156 </widget> 156 </widget>
157 <widget> 157 <widget>
158 <class>QLabel</class> 158 <class>QLabel</class>
159 <property stdset="1"> 159 <property stdset="1">
160 <name>name</name> 160 <name>name</name>
161 <cstring>TextLabelTimeShift</cstring> 161 <cstring>TextLabelTimeShift</cstring>
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>
169 <class>QLabel</class> 169 <class>QLabel</class>
170 <property stdset="1"> 170 <property stdset="1">
171 <name>name</name> 171 <name>name</name>
172 <cstring>TextLabel5</cstring> 172 <cstring>TextLabel5</cstring>
173 </property> 173 </property>
174 <property stdset="1"> 174 <property stdset="1">
175 <name>text</name> 175 <name>text</name>
176 <string>New Time:</string> 176 <string>New Time:</string>
177 </property> 177 </property>
178 </widget> 178 </widget>
179 <widget> 179 <widget>
180 <class>QLabel</class> 180 <class>QLabel</class>
181 <property stdset="1"> 181 <property stdset="1">
182 <name>name</name> 182 <name>name</name>
183 <cstring>TextLabelNewTime</cstring> 183 <cstring>TextLabelNewTime</cstring>
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>
191 <property> 191 <property>
192 <name>name</name> 192 <name>name</name>
193 <cstring>Spacer1</cstring> 193 <cstring>Spacer1</cstring>
194 </property> 194 </property>
195 <property stdset="1"> 195 <property stdset="1">
196 <name>orientation</name> 196 <name>orientation</name>
197 <enum>Vertical</enum> 197 <enum>Vertical</enum>
198 </property> 198 </property>
199 <property stdset="1"> 199 <property stdset="1">
@@ -250,48 +250,121 @@
250 </grid> 250 </grid>
251 </widget> 251 </widget>
252 <widget> 252 <widget>
253 <class>QWidget</class> 253 <class>QWidget</class>
254 <property stdset="1"> 254 <property stdset="1">
255 <name>name</name> 255 <name>name</name>
256 <cstring>tab</cstring> 256 <cstring>tab</cstring>
257 </property> 257 </property>
258 <attribute> 258 <attribute>
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 <property stdset="1">
264 <name>margin</name>
265 <number>2</number>
266 </property>
267 <property stdset="1">
268 <name>spacing</name>
269 <number>2</number>
270 </property>
271 <widget row="0" column="0" >
263 <class>QTable</class> 272 <class>QTable</class>
264 <property stdset="1"> 273 <property stdset="1">
265 <name>name</name> 274 <name>name</name>
266 <cstring>TableLookups</cstring> 275 <cstring>TableLookups</cstring>
267 </property> 276 </property>
268 <property stdset="1"> 277 <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">
278 <name>numRows</name> 278 <name>numRows</name>
279 <number>2</number> 279 <number>2</number>
280 </property> 280 </property>
281 <property stdset="1"> 281 <property stdset="1">
282 <name>numCols</name> 282 <name>numCols</name>
283 <number>2</number> 283 <number>2</number>
284 </property> 284 </property>
285 </widget> 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>
289 <property stdset="1"> 362 <property stdset="1">
290 <name>name</name> 363 <name>name</name>
291 <cstring>TabDebug</cstring> 364 <cstring>TabDebug</cstring>
292 </property> 365 </property>
293 <attribute> 366 <attribute>
294 <name>title</name> 367 <name>title</name>
295 <string>Debug</string> 368 <string>Debug</string>
296 </attribute> 369 </attribute>
297 <grid> 370 <grid>