summaryrefslogtreecommitdiff
path: root/noncore/settings/netsystemtime/ntp.cpp
authortille <tille>2002-06-26 12:45:03 (UTC)
committer tille <tille>2002-06-26 12:45:03 (UTC)
commit541bbcbb89a9e6a054fb545a82739c0bcf7804fe (patch) (unidiff)
treee2d4278a88226849cc5d46d5f69502499dc94efc /noncore/settings/netsystemtime/ntp.cpp
parent4b0e72bed1ead4e3c7af2209a11f34aa9209653c (diff)
downloadopie-541bbcbb89a9e6a054fb545a82739c0bcf7804fe.zip
opie-541bbcbb89a9e6a054fb545a82739c0bcf7804fe.tar.gz
opie-541bbcbb89a9e6a054fb545a82739c0bcf7804fe.tar.bz2
settings...
Diffstat (limited to 'noncore/settings/netsystemtime/ntp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp60
1 files changed, 30 insertions, 30 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index b2f192a..52fc6be 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -6,6 +6,7 @@
6#include <qsocket.h> 6#include <qsocket.h>
7#include <qlineedit.h> 7#include <qlineedit.h>
8#include <qspinbox.h> 8#include <qspinbox.h>
9#include <qmessagebox.h>
9#include <qmultilineedit.h> 10#include <qmultilineedit.h>
10#include <opie/oprocess.h> 11#include <opie/oprocess.h>
11#include <qpe/config.h> 12#include <qpe/config.h>
@@ -26,8 +27,8 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
26 cfg.setGroup("settings"); 27 cfg.setGroup("settings");
27 // _maxOffset = cfg.readNumEntry("maxOffset",5); 28 // _maxOffset = cfg.readNumEntry("maxOffset",5);
28// _minLookupDiff = cfg.readNumEntry("minLookupDiff",10); 29// _minLookupDiff = cfg.readNumEntry("minLookupDiff",10);
29 SpinBoxMinDelay->setValue( cfg.readNumEntry("minLookupDiff",10) ); 30 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",60) );
30 SpinBoxMinDelay->setMinValue( 7 ); 31 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",60) );
31 LineEditNtpSrv->setText( cfg.readEntry("ntpServer", tr("time.fu-berlin.de")) ); 32 LineEditNtpSrv->setText( cfg.readEntry("ntpServer", tr("time.fu-berlin.de")) );
32 ntpProcess = new OProcess( ); 33 ntpProcess = new OProcess( );
33 34
@@ -52,12 +53,31 @@ Ntp::~Ntp()
52 Config cfg("ntp",Config::User); 53 Config cfg("ntp",Config::User);
53 cfg.setGroup("settings"); 54 cfg.setGroup("settings");
54 cfg.writeEntry("ntpServer", LineEditNtpSrv->text()); 55 cfg.writeEntry("ntpServer", LineEditNtpSrv->text());
55 cfg.writeEntry( "minLookupDiff", SpinBoxMinDelay->value() ); 56 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() );
57 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() );
56} 58}
57 59
58 60
59void Ntp::slotRunNtp() 61void Ntp::slotRunNtp()
60{ 62{
63 Config cfg("ntp",Config::User);
64 cfg.setGroup("lookups");
65 int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
66
67 if ( lookupDiff < SpinBoxNtpDelay->value()*60 )
68 {
69 switch (
70 QMessageBox::warning(this, tr("Run ntp?"),
71 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+
72 QString::number(lookupDiff%60)+tr(" minutes elapsed since last loopup.")+
73 "<br>"+tr("Rerun ntp?"),
74 QMessageBox::Ok,QMessageBox::Cancel)
75 ) {
76 case QMessageBox::Ok: break;
77 case QMessageBox::Cancel: return;
78 default: return;
79 }
80 }
61 TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); 81 TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
62 ntpProcess->clearArguments(); 82 ntpProcess->clearArguments();
63 *ntpProcess << "ntpdate" << LineEditNtpSrv->text(); 83 *ntpProcess << "ntpdate" << LineEditNtpSrv->text();
@@ -95,7 +115,8 @@ void Ntp::ntpFinished(OProcess*)
95 if (timeShift == 0.0) return; 115 if (timeShift == 0.0) return;
96 int secsSinceLast = time - lastLookup; 116 int secsSinceLast = time - lastLookup;
97 TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); 117 TextLabelNewTime->setText(QDateTime::currentDateTime().toString());
98 if ( lastLookup > 0 && secsSinceLast > 60*24* SpinBoxMinDelay->value()) 118 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds"));
119 if ( lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value())
99 { 120 {
100 lookupCount++; 121 lookupCount++;
101 cfg.writeEntry("count",lookupCount); 122 cfg.writeEntry("count",lookupCount);
@@ -108,28 +129,6 @@ void Ntp::ntpFinished(OProcess*)
108 } 129 }
109} 130}
110 131
111//void Ntp::correctClock()
112//{
113 //qDebug("current time: %s",QDateTime::currentDateTime().toString().latin1());
114 //Config cfg("ntp",Config::User);
115// cfg.setGroup("correction");
116 // int lastTime = cfg.readNumEntry("time",0);
117// if ( lastTime == 0 )
118// {
119 // return;
120// }
121// int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
122// int corr = int((now - lastTime) * _shiftPerSec);
123// struct timeval myTv;
124// myTv.tv_sec = TimeConversion::toUTC( QDateTime::currentDateTime().addSecs(corr) );
125// myTv.tv_usec = 0;
126//
127// if ( myTv.tv_sec != -1 )
128// ::settimeofday( &myTv, 0 );
129// Global::writeHWClock();
130// cfg.writeEntry("time",now);
131 //qDebug("current time: %s",QDateTime::currentDateTime().toString().latin1());
132//}
133 132
134float Ntp::getTimeShift() 133float Ntp::getTimeShift()
135{ 134{
@@ -143,7 +142,6 @@ float Ntp::getTimeShift()
143 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); 142 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1);
144 qDebug("%s", _ntpOutput.latin1()); 143 qDebug("%s", _ntpOutput.latin1());
145 qDebug("diff = >%s<",diff.latin1()); 144 qDebug("diff = >%s<",diff.latin1());
146 TextLabelTimeShift->setText(diff);
147 return diff.toFloat(); 145 return diff.toFloat();
148} 146}
149 147
@@ -164,6 +162,8 @@ void Ntp::readLookups()
164 TableLookups->setColumnWidth( 0, cw+30 ); 162 TableLookups->setColumnWidth( 0, cw+30 );
165 TableLookups->setColumnWidth( 1, cw ); 163 TableLookups->setColumnWidth( 1, cw );
166 TableLookups->setColumnWidth( 2, cw ); 164 TableLookups->setColumnWidth( 2, cw );
165 TableLookups->sortColumn(0, false, true );
166 // TableLookups->setSorting( true );
167 for (int i=0; i < lookupCount; i++) 167 for (int i=0; i < lookupCount; i++)
168 { 168 {
169 cfg.setGroup("lookup_"+QString::number(i)); 169 cfg.setGroup("lookup_"+QString::number(i));
@@ -178,7 +178,7 @@ void Ntp::readLookups()
178 TableLookups->setText( i,1,QString::number(last)); 178 TableLookups->setText( i,1,QString::number(last));
179 } 179 }
180 _shiftPerSec /= lookupCount+1; 180 _shiftPerSec /= lookupCount+1;
181 TextLabelShift->setText(QString::number(_shiftPerSec)); 181 TextLabelShift->setText(QString::number(_shiftPerSec)+tr(" seconds"));
182} 182}
183 183
184void Ntp::preditctTime() 184void Ntp::preditctTime()
@@ -192,7 +192,7 @@ void Ntp::preditctTime()
192 int corr = int((now - lastTime) * _shiftPerSec); 192 int corr = int((now - lastTime) * _shiftPerSec);
193 predictedTime = QDateTime::currentDateTime().addSecs(corr); 193 predictedTime = QDateTime::currentDateTime().addSecs(corr);
194 TextLabelPredTime->setText(predictedTime.toString()); 194 TextLabelPredTime->setText(predictedTime.toString());
195 TextLabelMainPredTime->setText(predictedTime.toString()); 195 TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>");
196} 196}
197 197
198void Ntp::setPredictTime() 198void Ntp::setPredictTime()
@@ -210,7 +210,7 @@ void Ntp::slotCheckNtp(int i)
210 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); 210 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) );
211 }else{ 211 }else{
212 preditctTime(); 212 preditctTime();
213 ButtonSetTime->setText( tr("Predict time") ); 213 ButtonSetTime->setText( tr("Set predicted time") );
214 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); 214 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) );
215 }; 215 };
216} 216}