summaryrefslogtreecommitdiff
authortille <tille>2002-06-26 14:27:43 (UTC)
committer tille <tille>2002-06-26 14:27:43 (UTC)
commit47a1461b3a250e079ab99a1075974ccea909216a (patch) (side-by-side diff)
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) (show 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.ui109
3 files changed, 156 insertions, 34 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 @@
#include <qregexp.h>
+#include <qtimer.h>
#include <qtable.h>
@@ -25,2 +26,13 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
{
+
+ Config ntpSrvs("/etc/ntpservers",Config::File);
+ ntpSrvs.setGroup("servers");
+ int srvCount = ntpSrvs.readNumEntry("count", 0 );
+ for (int i = 0; i < srvCount; i++)
+ {
+ ntpSrvs.setGroup(QString::number(i));
+ ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") );
+ }
+ if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de"));
+
Config cfg("ntp",Config::User);
@@ -29,11 +41,17 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
// _minLookupDiff = cfg.readNumEntry("minLookupDiff",10);
- SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",60) );
- SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",60) );
- LineEditNtpSrv->setText( cfg.readEntry("ntpServer", tr("time.fu-berlin.de")) );
+ SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) );
+ SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) );
+ ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) );
+
+ ntpTimer = new QTimer(this);
+ ntpTimer->start(SpinBoxNtpDelay->value()*100);
+
ntpProcess = new OProcess( );
+ connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ),
+ SLOT(slotNtpDelayChanged(int)) );
- QSocket *ntpSock = new QSocket( this );
- ntpSock->connectToHost( LineEditNtpSrv->text() ,123);
+ ntpSock = new QSocket( this );
connect( ntpSock, SIGNAL( error(int) ),
SLOT(slotCheckNtp(int)) );
+ slotProbeNtpServer();
@@ -45,4 +63,4 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime()));
+ connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime()));
slotCheckNtp(-1);
-// slotRunNtp();
readLookups();
@@ -52,5 +70,15 @@ Ntp::~Ntp()
{
+ delete ntpProcess;
+ Config ntpSrvs("/etc/ntpservers",Config::File);
+ ntpSrvs.setGroup("servers");
+ int srvCount = ComboNtpSrv->count();
+ ntpSrvs.writeEntry("count", srvCount);
+ for (int i = 0; i < srvCount; i++)
+ {
+ ntpSrvs.setGroup(QString::number(i));
+ ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) );
+ }
Config cfg("ntp",Config::User);
cfg.setGroup("settings");
- cfg.writeEntry("ntpServer", LineEditNtpSrv->text());
+ cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem());
cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() );
@@ -81,4 +109,5 @@ void Ntp::slotRunNtp()
TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
+ MultiLineEditntpOutPut->append( "\n"+tr("Running:")+"\nntpdate "+ ComboNtpSrv->currentText()+"\n");
ntpProcess->clearArguments();
- *ntpProcess << "ntpdate" << LineEditNtpSrv->text();
+ *ntpProcess << "ntpdate" << ComboNtpSrv->currentText();
bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
@@ -192,2 +221,3 @@ void Ntp::preditctTime()
int corr = int((now - lastTime) * _shiftPerSec);
+ TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds"));
predictedTime = QDateTime::currentDateTime().addSecs(corr);
@@ -210,2 +240,13 @@ void Ntp::slotCheckNtp(int i)
connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) );
+ Config cfg("ntp",Config::User);
+ cfg.setGroup("lookups");
+ int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
+ if ( lookupDiff > SpinBoxNtpDelay->value()*60 )
+ {
+ disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) );
+ connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) );
+ }else{
+ disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) );
+ connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
+ }
}else{
@@ -214,3 +255,18 @@ void Ntp::slotCheckNtp(int i)
connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) );
- };
+ connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
+ }
+}
+
+void Ntp::slotProbeNtpServer()
+{
+ Config cfg("ntp",Config::User);
+ cfg.setGroup("lookups");
+ int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
+ if ( lookupDiff > SpinBoxNtpDelay->value()*60 )
+ ntpSock->connectToHost( ComboNtpSrv->currentText() ,123);
+}
+
+void Ntp::slotNtpDelayChanged(int delay)
+{
+ ntpTimer->changeInterval( delay*100 );
}
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;
class QString;
-
+class QTimer;
+class QSocket;
@@ -25,2 +26,4 @@ private:
OProcess *ntpProcess;
+ QTimer *ntpTimer;
+ QSocket *ntpSock;
@@ -35,2 +38,4 @@ private slots:
void setPredictTime();
+ void slotProbeNtpServer();
+ void slotNtpDelayChanged(int);
};
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 @@
<y>0</y>
- <width>330</width>
- <height>419</height>
+ <width>331</width>
+ <height>426</height>
</rect>
@@ -111,3 +111,3 @@
<name>text</name>
- <string>get time from network</string>
+ <string>Get time from network</string>
</property>
@@ -289,3 +289,3 @@
<name>margin</name>
- <number>2</number>
+ <number>5</number>
</property>
@@ -293,3 +293,3 @@
<name>spacing</name>
- <number>2</number>
+ <number>6</number>
</property>
@@ -310,13 +310,2 @@
</widget>
- <widget row="2" column="0" >
- <class>QPushButton</class>
- <property stdset="1">
- <name>name</name>
- <cstring>PushButtonPredict</cstring>
- </property>
- <property stdset="1">
- <name>text</name>
- <string>predict time</string>
- </property>
- </widget>
<widget row="1" column="0" >
@@ -325,3 +314,3 @@
<name>name</name>
- <cstring>Layout5</cstring>
+ <cstring>Layout9</cstring>
</property>
@@ -347,2 +336,13 @@
</widget>
+ <widget row="1" column="0" >
+ <class>QLabel</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>TextLabel4</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>Esimated Shift:</string>
+ </property>
+ </widget>
<widget row="1" column="1" >
@@ -351,3 +351,3 @@
<name>name</name>
- <cstring>TextLabelPredTime</cstring>
+ <cstring>TextLabelEstimatedShift</cstring>
</property>
@@ -358,2 +358,13 @@
</widget>
+ <widget row="2" column="0" >
+ <class>QLabel</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>TextLabel3_2</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>Predicted Time:</string>
+ </property>
+ </widget>
<widget row="0" column="0" >
@@ -369,3 +380,3 @@
</widget>
- <widget row="1" column="0" >
+ <widget row="2" column="1" >
<class>QLabel</class>
@@ -373,3 +384,3 @@
<name>name</name>
- <cstring>TextLabel3_2</cstring>
+ <cstring>TextLabelPredTime</cstring>
</property>
@@ -377,3 +388,3 @@
<name>text</name>
- <string>Pred. Time:</string>
+ <string>nan</string>
</property>
@@ -382,2 +393,41 @@
</widget>
+ <widget row="2" column="0" >
+ <class>QLayoutWidget</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>Layout11</cstring>
+ </property>
+ <hbox>
+ <property stdset="1">
+ <name>margin</name>
+ <number>0</number>
+ </property>
+ <property stdset="1">
+ <name>spacing</name>
+ <number>6</number>
+ </property>
+ <widget>
+ <class>QPushButton</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>PushButtonSetPredTime</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>Set predicted time</string>
+ </property>
+ </widget>
+ <widget>
+ <class>QPushButton</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>PushButtonPredict</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>Predict time</string>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
</grid>
@@ -488,6 +538,10 @@
<widget row="0" column="1" >
- <class>QLineEdit</class>
+ <class>QComboBox</class>
<property stdset="1">
<name>name</name>
- <cstring>LineEditNtpSrv</cstring>
+ <cstring>ComboNtpSrv</cstring>
+ </property>
+ <property stdset="1">
+ <name>editable</name>
+ <bool>true</bool>
</property>
@@ -611,2 +665,9 @@
<property stdset="1">
+ <name>sizePolicy</name>
+ <sizepolicy>
+ <hsizetype>1</hsizetype>
+ <vsizetype>1</vsizetype>
+ </sizepolicy>
+ </property>
+ <property stdset="1">
<name>text</name>
@@ -634,3 +695,3 @@
<name>text</name>
- <string>NTP syncronises the clock with the network</string>
+ <string>NTP tries to syncronises the clock with the network.</string>
</property>