author | tille <tille> | 2002-06-27 10:04:37 (UTC) |
---|---|---|
committer | tille <tille> | 2002-06-27 10:04:37 (UTC) |
commit | 7c3fe018ad8855011c6e0441ed1bef2c09e293f2 (patch) (unidiff) | |
tree | 299a1e9ffee7ca35f698165d07e02cb415f0010e /noncore | |
parent | 596749dc52cc89b5325f9089b79d0b9cc8240682 (diff) | |
download | opie-7c3fe018ad8855011c6e0441ed1bef2c09e293f2.zip opie-7c3fe018ad8855011c6e0441ed1bef2c09e293f2.tar.gz opie-7c3fe018ad8855011c6e0441ed1bef2c09e293f2.tar.bz2 |
imp. table
-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 28 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntp.h | 3 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntpbase.ui | 8 |
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 | |||
@@ -39,14 +39,12 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | |||
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 ); |
@@ -112,14 +110,12 @@ void Ntp::slotRunNtp() | |||
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"); |
@@ -139,22 +135,22 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) | |||
139 | } | 135 | } |
140 | lineStrOld = lineStr; | 136 | lineStrOld = lineStr; |
141 | } | 137 | } |
142 | 138 | ||
143 | void Ntp::ntpFinished(OProcess *p) | 139 | void 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(); |
@@ -191,20 +187,20 @@ float Ntp::getTimeShift() | |||
191 | } | 187 | } |
192 | 188 | ||
193 | void Ntp::readLookups() | 189 | void 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 ); |
@@ -215,15 +211,15 @@ void Ntp::readLookups() | |||
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 | ||
229 | void Ntp::preditctTime() | 225 | void Ntp::preditctTime() |
@@ -270,12 +266,13 @@ void Ntp::slotCheckNtp(int i) | |||
270 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 266 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
271 | } | 267 | } |
272 | } | 268 | } |
273 | 269 | ||
274 | void Ntp::slotProbeNtpServer() | 270 | void Ntp::slotProbeNtpServer() |
275 | { | 271 | { |
272 | qDebug("Ntp::slotProbeNtpServer()"); | ||
276 | ntpSock->connectToHost( getNtpServer() ,123); | 273 | ntpSock->connectToHost( getNtpServer() ,123); |
277 | } | 274 | } |
278 | 275 | ||
279 | void Ntp::slotNtpDelayChanged(int delay) | 276 | void Ntp::slotNtpDelayChanged(int delay) |
280 | { | 277 | { |
281 | ntpTimer->changeInterval( delay*1000*60 ); | 278 | ntpTimer->changeInterval( delay*1000*60 ); |
@@ -284,11 +281,6 @@ void Ntp::slotNtpDelayChanged(int delay) | |||
284 | void Ntp::ntpOutPut(QString out) | 281 | void 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 | ||
290 | void 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 | |||
@@ -22,13 +22,13 @@ protected: | |||
22 | 22 | ||
23 | private: | 23 | private: |
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(); |
@@ -39,10 +39,9 @@ private slots: | |||
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 | |||
@@ -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>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> |
@@ -297,12 +297,18 @@ | |||
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> |