summaryrefslogtreecommitdiff
authortille <tille>2002-06-26 16:24:42 (UTC)
committer tille <tille>2002-06-26 16:24:42 (UTC)
commite9b05e2b93bf000777ae1c55e7d5cac35a67145d (patch) (unidiff)
tree11848aecc3f8ee23fd71d84cb7b821090bad19dc
parent97e2050f5880cb27d2cd028ed61eef1dc59d1ad1 (diff)
downloadopie-e9b05e2b93bf000777ae1c55e7d5cac35a67145d.zip
opie-e9b05e2b93bf000777ae1c55e7d5cac35a67145d.tar.gz
opie-e9b05e2b93bf000777ae1c55e7d5cac35a67145d.tar.bz2
timer working
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp58
-rw-r--r--noncore/settings/netsystemtime/ntp.h4
-rw-r--r--noncore/settings/netsystemtime/ntpbase.ui4
-rw-r--r--noncore/settings/netsystemtime/opie-netsystemtime.control2
-rw-r--r--noncore/settings/netsystemtime/settime.cpp2
5 files changed, 41 insertions, 29 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index 364609d..bcbf7a1 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -45,5 +45,5 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
45 45
46 ntpTimer = new QTimer(this); 46 ntpTimer = new QTimer(this);
47 ntpTimer->start(SpinBoxNtpDelay->value()*100); 47 ntpTimer->start(SpinBoxNtpDelay->value()*1000*60);
48 48
49 ntpProcess = new OProcess( ); 49 ntpProcess = new OProcess( );
@@ -86,18 +86,26 @@ Ntp::~Ntp()
86} 86}
87 87
88 88bool Ntp::ntpDelayElapsed()
89void Ntp::slotRunNtp()
90{ 89{
91 Config cfg("ntp",Config::User); 90 Config cfg("ntp",Config::User);
92 cfg.setGroup("lookups"); 91 cfg.setGroup("lookups");
93 int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); 92 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
93 return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60;
94}
94 95
95 if ( lookupDiff < SpinBoxNtpDelay->value()*60 ) 96QString Ntp::getNtpServer()
97{
98 return ComboNtpSrv->currentText();
99}
100
101void Ntp::slotRunNtp()
102{
103 if ( !ntpDelayElapsed() )
96 { 104 {
97 switch ( 105 switch (
98 QMessageBox::warning(this, tr("Run ntp?"), 106 QMessageBox::warning(this, tr("Run NTP?"),
99 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ 107 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+
100 QString::number(lookupDiff%60)+tr(" minutes elapsed since last loopup.")+ 108 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+
101 "<br>"+tr("Rerun ntp?"), 109 "<br>"+tr("Rerun NTP?"),
102 QMessageBox::Ok,QMessageBox::Cancel) 110 QMessageBox::Ok,QMessageBox::Cancel)
103 ) { 111 ) {
@@ -108,10 +116,11 @@ void Ntp::slotRunNtp()
108 } 116 }
109 TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); 117 TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
110 MultiLineEditntpOutPut->append( "\n"+tr("Running:")+"\nntpdate "+ ComboNtpSrv->currentText()+"\n"); 118 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() );
111 ntpProcess->clearArguments(); 119 ntpProcess->clearArguments();
112 *ntpProcess << "ntpdate" << ComboNtpSrv->currentText(); 120 *ntpProcess << "ntpdate" << getNtpServer();
113 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); 121 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
114 if ( !ret ) { 122 if ( !ret ) {
115 qDebug("Error while executing ntp"); 123 qDebug("Error while executing ntpdate");
124 ntpOutPut( tr("Error while executing ntpdate"));
116 } 125 }
117} 126}
@@ -124,5 +133,5 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
124 if (lineStr!=lineStrOld) 133 if (lineStr!=lineStrOld)
125 { 134 {
126 MultiLineEditntpOutPut->append(lineStr); 135 ntpOutPut(lineStr);
127 _ntpOutput += lineStr; 136 _ntpOutput += lineStr;
128 } 137 }
@@ -152,5 +161,4 @@ void Ntp::ntpFinished(OProcess*)
152 cfg.setGroup("lookup_"+QString::number(lookupCount)); 161 cfg.setGroup("lookup_"+QString::number(lookupCount));
153 _shiftPerSec = timeShift / secsSinceLast; 162 _shiftPerSec = timeShift / secsSinceLast;
154// float nextCorr = _maxOffset / _shiftPerSec;
155 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); 163 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec);
156 cfg.writeEntry("secsSinceLast",secsSinceLast); 164 cfg.writeEntry("secsSinceLast",secsSinceLast);
@@ -213,5 +221,4 @@ void Ntp::readLookups()
213void Ntp::preditctTime() 221void Ntp::preditctTime()
214{ 222{
215 qDebug("current time: %s",QDateTime::currentDateTime().toString().latin1());
216 Config cfg("ntp",Config::User); 223 Config cfg("ntp",Config::User);
217 cfg.setGroup("lookups"); 224 cfg.setGroup("lookups");
@@ -239,9 +246,7 @@ void Ntp::slotCheckNtp(int i)
239 ButtonSetTime->setText( tr("Get time from network") ); 246 ButtonSetTime->setText( tr("Get time from network") );
240 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); 247 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) );
241 Config cfg("ntp",Config::User); 248 if ( ntpDelayElapsed() )
242 cfg.setGroup("lookups");
243 int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
244 if ( lookupDiff > SpinBoxNtpDelay->value()*60 )
245 { 249 {
250 slotRunNtp();
246 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); 251 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) );
247 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); 252 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) );
@@ -253,20 +258,25 @@ void Ntp::slotCheckNtp(int i)
253 preditctTime(); 258 preditctTime();
254 ButtonSetTime->setText( tr("Set predicted time") ); 259 ButtonSetTime->setText( tr("Set predicted time") );
260 if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer());
255 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); 261 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) );
256 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); 262 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
257 } 263 }
264 //ntpTimer->start(SpinBoxNtpDelay->value()*1000*60);
258} 265}
259 266
260void Ntp::slotProbeNtpServer() 267void Ntp::slotProbeNtpServer()
261{ 268{
262 Config cfg("ntp",Config::User); 269 if ( ntpDelayElapsed() )
263 cfg.setGroup("lookups"); 270 ntpSock->connectToHost( getNtpServer() ,123);
264 int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
265 if ( lookupDiff > SpinBoxNtpDelay->value()*60 )
266 ntpSock->connectToHost( ComboNtpSrv->currentText() ,123);
267} 271}
268 272
269void Ntp::slotNtpDelayChanged(int delay) 273void Ntp::slotNtpDelayChanged(int delay)
270{ 274{
271 ntpTimer->changeInterval( delay*100 ); 275 ntpTimer->changeInterval( delay*1000*60 );
276}
277
278void Ntp::ntpOutPut(QString out)
279{
280 MultiLineEditntpOutPut->append(out);
281 MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE);
272} 282}
diff --git a/noncore/settings/netsystemtime/ntp.h b/noncore/settings/netsystemtime/ntp.h
index 7cc309f..c78dc55 100644
--- a/noncore/settings/netsystemtime/ntp.h
+++ b/noncore/settings/netsystemtime/ntp.h
@@ -24,4 +24,5 @@ private:
24 QString _ntpOutput; 24 QString _ntpOutput;
25 float _shiftPerSec; 25 float _shiftPerSec;
26 int _lookupDiff;
26 OProcess *ntpProcess; 27 OProcess *ntpProcess;
27 QTimer *ntpTimer; 28 QTimer *ntpTimer;
@@ -30,4 +31,7 @@ private:
30 float getTimeShift(); 31 float getTimeShift();
31 void readLookups(); 32 void readLookups();
33 void ntpOutPut(QString);
34 bool ntpDelayElapsed();
35 QString getNtpServer();
32private slots: 36private slots:
33 void slotRunNtp(); 37 void slotRunNtp();
diff --git a/noncore/settings/netsystemtime/ntpbase.ui b/noncore/settings/netsystemtime/ntpbase.ui
index 4e10fd2..a83dc93 100644
--- a/noncore/settings/netsystemtime/ntpbase.ui
+++ b/noncore/settings/netsystemtime/ntpbase.ui
@@ -12,6 +12,6 @@
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>331</width> 14 <width>328</width>
15 <height>426</height> 15 <height>411</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
diff --git a/noncore/settings/netsystemtime/opie-netsystemtime.control b/noncore/settings/netsystemtime/opie-netsystemtime.control
index 406d7b0..d3290e9 100644
--- a/noncore/settings/netsystemtime/opie-netsystemtime.control
+++ b/noncore/settings/netsystemtime/opie-netsystemtime.control
@@ -1,3 +1,3 @@
1Files: bin/netsystemtime apps/Settings/ntpdatetime.desktop 1Files: bin/netsystemtime apps/Settings/ntpdatetime.desktop etc/ntpservers
2Priority: optional 2Priority: optional
3Section: opie/settings 3Section: opie/settings
diff --git a/noncore/settings/netsystemtime/settime.cpp b/noncore/settings/netsystemtime/settime.cpp
index 2398c08..93543cd 100644
--- a/noncore/settings/netsystemtime/settime.cpp
+++ b/noncore/settings/netsystemtime/settime.cpp
@@ -301,5 +301,4 @@ void SetDateTime::updateSystem(int i)
301void SetDateTime::tzChange( const QString &tz ) 301void SetDateTime::tzChange( const QString &tz )
302{ 302{
303 qDebug("SetDateTime::tzChange");
304 // set the TZ get the time and leave gracefully... 303 // set the TZ get the time and leave gracefully...
305 QString strSave; 304 QString strSave;
@@ -457,5 +456,4 @@ void SetTime::checkedPM( int c )
457void SetTime::slotTzChange( const QString &tz ) 456void SetTime::slotTzChange( const QString &tz )
458{ 457{
459 qDebug("SetTime::slotTzChange");
460 // set the TZ get the time and leave gracefully... 458 // set the TZ get the time and leave gracefully...
461 QString strSave; 459 QString strSave;