summaryrefslogtreecommitdiff
authortille <tille>2002-06-26 14:27:43 (UTC)
committer tille <tille>2002-06-26 14:27:43 (UTC)
commit47a1461b3a250e079ab99a1075974ccea909216a (patch) (unidiff)
tree7e3586c6ba138203671bc173b06c1c0c7eee40f1
parent531bb3c03f5576523a3c7ccecc714362507f69e1 (diff)
downloadopie-47a1461b3a250e079ab99a1075974ccea909216a.zip
opie-47a1461b3a250e079ab99a1075974ccea909216a.tar.gz
opie-47a1461b3a250e079ab99a1075974ccea909216a.tar.bz2
inlc. timer for ntp update and ntpservers combo
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp74
-rw-r--r--noncore/settings/netsystemtime/ntp.h7
-rw-r--r--noncore/settings/netsystemtime/ntpbase.ui111
3 files changed, 157 insertions, 35 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index 52fc6be..364609d 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -3,2 +3,3 @@
3#include <qregexp.h> 3#include <qregexp.h>
4#include <qtimer.h>
4#include <qtable.h> 5#include <qtable.h>
@@ -25,2 +26,13 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
25{ 26{
27
28 Config ntpSrvs("/etc/ntpservers",Config::File);
29 ntpSrvs.setGroup("servers");
30 int srvCount = ntpSrvs.readNumEntry("count", 0 );
31 for (int i = 0; i < srvCount; i++)
32 {
33 ntpSrvs.setGroup(QString::number(i));
34 ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") );
35 }
36 if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de"));
37
26 Config cfg("ntp",Config::User); 38 Config cfg("ntp",Config::User);
@@ -29,11 +41,17 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
29// _minLookupDiff = cfg.readNumEntry("minLookupDiff",10); 41// _minLookupDiff = cfg.readNumEntry("minLookupDiff",10);
30 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",60) ); 42 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) );
31 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",60) ); 43 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) );
32 LineEditNtpSrv->setText( cfg.readEntry("ntpServer", tr("time.fu-berlin.de")) ); 44 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) );
45
46 ntpTimer = new QTimer(this);
47 ntpTimer->start(SpinBoxNtpDelay->value()*100);
48
33 ntpProcess = new OProcess( ); 49 ntpProcess = new OProcess( );
50 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ),
51 SLOT(slotNtpDelayChanged(int)) );
34 52
35 QSocket *ntpSock = new QSocket( this ); 53 ntpSock = new QSocket( this );
36 ntpSock->connectToHost( LineEditNtpSrv->text() ,123);
37 connect( ntpSock, SIGNAL( error(int) ), 54 connect( ntpSock, SIGNAL( error(int) ),
38 SLOT(slotCheckNtp(int)) ); 55 SLOT(slotCheckNtp(int)) );
56 slotProbeNtpServer();
39 57
@@ -45,4 +63,4 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
45 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); 63 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime()));
64 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime()));
46 slotCheckNtp(-1); 65 slotCheckNtp(-1);
47// slotRunNtp();
48 readLookups(); 66 readLookups();
@@ -52,5 +70,15 @@ Ntp::~Ntp()
52{ 70{
71 delete ntpProcess;
72 Config ntpSrvs("/etc/ntpservers",Config::File);
73 ntpSrvs.setGroup("servers");
74 int srvCount = ComboNtpSrv->count();
75 ntpSrvs.writeEntry("count", srvCount);
76 for (int i = 0; i < srvCount; i++)
77 {
78 ntpSrvs.setGroup(QString::number(i));
79 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) );
80 }
53 Config cfg("ntp",Config::User); 81 Config cfg("ntp",Config::User);
54 cfg.setGroup("settings"); 82 cfg.setGroup("settings");
55 cfg.writeEntry("ntpServer", LineEditNtpSrv->text()); 83 cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem());
56 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); 84 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() );
@@ -81,4 +109,5 @@ void Ntp::slotRunNtp()
81 TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); 109 TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
110 MultiLineEditntpOutPut->append( "\n"+tr("Running:")+"\nntpdate "+ ComboNtpSrv->currentText()+"\n");
82 ntpProcess->clearArguments(); 111 ntpProcess->clearArguments();
83 *ntpProcess << "ntpdate" << LineEditNtpSrv->text(); 112 *ntpProcess << "ntpdate" << ComboNtpSrv->currentText();
84 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); 113 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
@@ -192,2 +221,3 @@ void Ntp::preditctTime()
192 int corr = int((now - lastTime) * _shiftPerSec); 221 int corr = int((now - lastTime) * _shiftPerSec);
222 TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds"));
193 predictedTime = QDateTime::currentDateTime().addSecs(corr); 223 predictedTime = QDateTime::currentDateTime().addSecs(corr);
@@ -210,2 +240,13 @@ void Ntp::slotCheckNtp(int i)
210 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); 240 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) );
241 Config cfg("ntp",Config::User);
242 cfg.setGroup("lookups");
243 int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
244 if ( lookupDiff > SpinBoxNtpDelay->value()*60 )
245 {
246 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) );
247 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) );
248 }else{
249 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) );
250 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
251 }
211 }else{ 252 }else{
@@ -214,3 +255,18 @@ void Ntp::slotCheckNtp(int i)
214 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); 255 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) );
215 }; 256 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
257 }
258}
259
260void Ntp::slotProbeNtpServer()
261{
262 Config cfg("ntp",Config::User);
263 cfg.setGroup("lookups");
264 int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
265 if ( lookupDiff > SpinBoxNtpDelay->value()*60 )
266 ntpSock->connectToHost( ComboNtpSrv->currentText() ,123);
267}
268
269void Ntp::slotNtpDelayChanged(int delay)
270{
271 ntpTimer->changeInterval( delay*100 );
216} 272}
diff --git a/noncore/settings/netsystemtime/ntp.h b/noncore/settings/netsystemtime/ntp.h
index 284ae27..7cc309f 100644
--- a/noncore/settings/netsystemtime/ntp.h
+++ b/noncore/settings/netsystemtime/ntp.h
@@ -7,3 +7,4 @@ class OProcess;
7class QString; 7class QString;
8 8class QTimer;
9class QSocket;
9 10
@@ -25,2 +26,4 @@ private:
25 OProcess *ntpProcess; 26 OProcess *ntpProcess;
27 QTimer *ntpTimer;
28 QSocket *ntpSock;
26 29
@@ -35,2 +38,4 @@ private slots:
35 void setPredictTime(); 38 void setPredictTime();
39 void slotProbeNtpServer();
40 void slotNtpDelayChanged(int);
36}; 41};
diff --git a/noncore/settings/netsystemtime/ntpbase.ui b/noncore/settings/netsystemtime/ntpbase.ui
index 8d32849..4e10fd2 100644
--- a/noncore/settings/netsystemtime/ntpbase.ui
+++ b/noncore/settings/netsystemtime/ntpbase.ui
@@ -13,4 +13,4 @@
13 <y>0</y> 13 <y>0</y>
14 <width>330</width> 14 <width>331</width>
15 <height>419</height> 15 <height>426</height>
16 </rect> 16 </rect>
@@ -111,3 +111,3 @@
111 <name>text</name> 111 <name>text</name>
112 <string>get time from network</string> 112 <string>Get time from network</string>
113 </property> 113 </property>
@@ -289,3 +289,3 @@
289 <name>margin</name> 289 <name>margin</name>
290 <number>2</number> 290 <number>5</number>
291 </property> 291 </property>
@@ -293,3 +293,3 @@
293 <name>spacing</name> 293 <name>spacing</name>
294 <number>2</number> 294 <number>6</number>
295 </property> 295 </property>
@@ -310,13 +310,2 @@
310 </widget> 310 </widget>
311 <widget row="2" column="0" >
312 <class>QPushButton</class>
313 <property stdset="1">
314 <name>name</name>
315 <cstring>PushButtonPredict</cstring>
316 </property>
317 <property stdset="1">
318 <name>text</name>
319 <string>predict time</string>
320 </property>
321 </widget>
322 <widget row="1" column="0" > 311 <widget row="1" column="0" >
@@ -325,3 +314,3 @@
325 <name>name</name> 314 <name>name</name>
326 <cstring>Layout5</cstring> 315 <cstring>Layout9</cstring>
327 </property> 316 </property>
@@ -347,2 +336,13 @@
347 </widget> 336 </widget>
337 <widget row="1" column="0" >
338 <class>QLabel</class>
339 <property stdset="1">
340 <name>name</name>
341 <cstring>TextLabel4</cstring>
342 </property>
343 <property stdset="1">
344 <name>text</name>
345 <string>Esimated Shift:</string>
346 </property>
347 </widget>
348 <widget row="1" column="1" > 348 <widget row="1" column="1" >
@@ -351,3 +351,3 @@
351 <name>name</name> 351 <name>name</name>
352 <cstring>TextLabelPredTime</cstring> 352 <cstring>TextLabelEstimatedShift</cstring>
353 </property> 353 </property>
@@ -358,2 +358,13 @@
358 </widget> 358 </widget>
359 <widget row="2" column="0" >
360 <class>QLabel</class>
361 <property stdset="1">
362 <name>name</name>
363 <cstring>TextLabel3_2</cstring>
364 </property>
365 <property stdset="1">
366 <name>text</name>
367 <string>Predicted Time:</string>
368 </property>
369 </widget>
359 <widget row="0" column="0" > 370 <widget row="0" column="0" >
@@ -369,3 +380,3 @@
369 </widget> 380 </widget>
370 <widget row="1" column="0" > 381 <widget row="2" column="1" >
371 <class>QLabel</class> 382 <class>QLabel</class>
@@ -373,3 +384,3 @@
373 <name>name</name> 384 <name>name</name>
374 <cstring>TextLabel3_2</cstring> 385 <cstring>TextLabelPredTime</cstring>
375 </property> 386 </property>
@@ -377,3 +388,3 @@
377 <name>text</name> 388 <name>text</name>
378 <string>Pred. Time:</string> 389 <string>nan</string>
379 </property> 390 </property>
@@ -382,2 +393,41 @@
382 </widget> 393 </widget>
394 <widget row="2" column="0" >
395 <class>QLayoutWidget</class>
396 <property stdset="1">
397 <name>name</name>
398 <cstring>Layout11</cstring>
399 </property>
400 <hbox>
401 <property stdset="1">
402 <name>margin</name>
403 <number>0</number>
404 </property>
405 <property stdset="1">
406 <name>spacing</name>
407 <number>6</number>
408 </property>
409 <widget>
410 <class>QPushButton</class>
411 <property stdset="1">
412 <name>name</name>
413 <cstring>PushButtonSetPredTime</cstring>
414 </property>
415 <property stdset="1">
416 <name>text</name>
417 <string>Set predicted time</string>
418 </property>
419 </widget>
420 <widget>
421 <class>QPushButton</class>
422 <property stdset="1">
423 <name>name</name>
424 <cstring>PushButtonPredict</cstring>
425 </property>
426 <property stdset="1">
427 <name>text</name>
428 <string>Predict time</string>
429 </property>
430 </widget>
431 </hbox>
432 </widget>
383 </grid> 433 </grid>
@@ -488,6 +538,10 @@
488 <widget row="0" column="1" > 538 <widget row="0" column="1" >
489 <class>QLineEdit</class> 539 <class>QComboBox</class>
490 <property stdset="1"> 540 <property stdset="1">
491 <name>name</name> 541 <name>name</name>
492 <cstring>LineEditNtpSrv</cstring> 542 <cstring>ComboNtpSrv</cstring>
543 </property>
544 <property stdset="1">
545 <name>editable</name>
546 <bool>true</bool>
493 </property> 547 </property>
@@ -611,4 +665,11 @@
611 <property stdset="1"> 665 <property stdset="1">
666 <name>sizePolicy</name>
667 <sizepolicy>
668 <hsizetype>1</hsizetype>
669 <vsizetype>1</vsizetype>
670 </sizepolicy>
671 </property>
672 <property stdset="1">
612 <name>text</name> 673 <name>text</name>
613 <string>Wait for</string> 674 <string>Wait for </string>
614 </property> 675 </property>
@@ -634,3 +695,3 @@
634 <name>text</name> 695 <name>text</name>
635 <string>NTP syncronises the clock with the network</string> 696 <string>NTP tries to syncronises the clock with the network.</string>
636 </property> 697 </property>