-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 42 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntp.h | 1 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntpbase.ui | 101 |
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 | |||
@@ -28,12 +28,13 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | |||
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 | ||
@@ -77,23 +78,23 @@ void Ntp::ntpFinished(OProcess*) | |||
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 | ||
99 | void Ntp::correctClock() | 100 | void Ntp::correctClock() |
@@ -134,13 +135,46 @@ float Ntp::getTimeShift() | |||
134 | 135 | ||
135 | void Ntp::readLookups() | 136 | void 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 | |||
170 | void 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 | |||
@@ -29,9 +29,10 @@ private: | |||
29 | void readLookups(); | 29 | void readLookups(); |
30 | private slots: | 30 | private 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 | |||
@@ -8,13 +8,13 @@ | |||
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> |
@@ -137,13 +137,13 @@ | |||
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> |
@@ -159,13 +159,13 @@ | |||
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> |
@@ -181,13 +181,13 @@ | |||
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> |
@@ -256,36 +256,109 @@ | |||
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> |