Diffstat (limited to 'noncore/settings/netsystemtime/ntp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 42 |
1 files changed, 38 insertions, 4 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index c2b64f0..04b113b 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp | |||
@@ -31,6 +31,7 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | |||
31 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), | 31 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), |
32 | this, SLOT(ntpFinished(OProcess*))); | 32 | this, SLOT(ntpFinished(OProcess*))); |
33 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); | 33 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); |
34 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); | ||
34 | _nextCorrection = new QTimer( this ); | 35 | _nextCorrection = new QTimer( this ); |
35 | connect( _nextCorrection, SIGNAL(timeout()), SLOT(correctClock()) ); | 36 | connect( _nextCorrection, SIGNAL(timeout()), SLOT(correctClock()) ); |
36 | slotRunNtp(); | 37 | slotRunNtp(); |
@@ -80,7 +81,7 @@ void Ntp::ntpFinished(OProcess*) | |||
80 | cfg.writeEntry("time", time); | 81 | cfg.writeEntry("time", time); |
81 | 82 | ||
82 | float timeShift = getTimeShift(); | 83 | float timeShift = getTimeShift(); |
83 | if (timeShift = 0.0) return; | 84 | if (timeShift == 0.0) return; |
84 | int secsSinceLast = time - lastLookup; | 85 | int secsSinceLast = time - lastLookup; |
85 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); | 86 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); |
86 | if ( lastLookup > 0 && secsSinceLast > 60*_minLookupDiff) | 87 | if ( lastLookup > 0 && secsSinceLast > 60*_minLookupDiff) |
@@ -90,7 +91,7 @@ void Ntp::ntpFinished(OProcess*) | |||
90 | cfg.setGroup("lookup_"+QString::number(lookupCount)); | 91 | cfg.setGroup("lookup_"+QString::number(lookupCount)); |
91 | _shiftPerSec = timeShift / secsSinceLast; | 92 | _shiftPerSec = timeShift / secsSinceLast; |
92 | float nextCorr = _maxOffset / _shiftPerSec; | 93 | float nextCorr = _maxOffset / _shiftPerSec; |
93 | qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec);qDebug("in %f secs the time will be shifted by %i", nextCorr,_maxOffset); | 94 | qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); |
94 | cfg.writeEntry("secsSinceLast",secsSinceLast); | 95 | cfg.writeEntry("secsSinceLast",secsSinceLast); |
95 | cfg.writeEntry("timeShift",QString::number(timeShift)); | 96 | cfg.writeEntry("timeShift",QString::number(timeShift)); |
96 | } | 97 | } |
@@ -137,10 +138,43 @@ void Ntp::readLookups() | |||
137 | Config cfg("ntp",Config::User); | 138 | Config cfg("ntp",Config::User); |
138 | cfg.setGroup("lookups"); | 139 | cfg.setGroup("lookups"); |
139 | int lookupCount = cfg.readNumEntry("count",-1); | 140 | int lookupCount = cfg.readNumEntry("count",-1); |
141 | float last, shift, shiftPerSec; | ||
142 | qDebug("lookupCount = %i",lookupCount); | ||
143 | TableLookups->setNumCols( 3 ); | ||
144 | TableLookups->setNumRows( lookupCount); | ||
145 | TableLookups->horizontalHeader()->setLabel(2,"secsSinceLast"); | ||
146 | TableLookups->horizontalHeader()->setLabel(1,"timeShift"); | ||
147 | TableLookups->horizontalHeader()->setLabel(0,"shift/s"); | ||
148 | int cw = TableLookups->width()/4; | ||
149 | qDebug("column width %i",cw); | ||
150 | TableLookups->setColumnWidth( 0, cw ); | ||
151 | TableLookups->setColumnWidth( 1, cw ); | ||
152 | TableLookups->setColumnWidth( 2, cw ); | ||
140 | for (int i=0; i < lookupCount; i++) | 153 | for (int i=0; i < lookupCount; i++) |
141 | { | 154 | { |
142 | cfg.setGroup("lookup_"+QString::number(i)); | 155 | cfg.setGroup("lookup_"+QString::number(i)); |
143 | TableLookups->setText( 1,i,cfg.readEntry("secsSinceLast",0)); | 156 | last = cfg.readEntry("secsSinceLast",0).toFloat(); |
144 | TableLookups->setText( 2,i,cfg.readEntry("timeShift",0)); | 157 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); |
158 | qDebug("%i last %f",i,last); | ||
159 | qDebug("%i shift %f",i,shift); | ||
160 | shiftPerSec = shift / last; | ||
161 | _shiftPerSec += shiftPerSec; | ||
162 | TableLookups->setText( i,0,QString::number(shiftPerSec)); | ||
163 | TableLookups->setText( i,1,QString::number(shift)); | ||
164 | TableLookups->setText( i,2,QString::number(last)); | ||
145 | } | 165 | } |
166 | _shiftPerSec /= lookupCount+1; | ||
167 | TextLabelShift->setText(QString::number(_shiftPerSec)); | ||
168 | } | ||
169 | |||
170 | void Ntp::preditctTime() | ||
171 | { | ||
172 | qDebug("current time: %s",QDateTime::currentDateTime().toString().latin1()); | ||
173 | Config cfg("ntp",Config::User); | ||
174 | cfg.setGroup("lookups"); | ||
175 | int lastTime = cfg.readNumEntry("time",0); | ||
176 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); | ||
177 | int corr = int((now - lastTime) * _shiftPerSec); | ||
178 | outPut->append( "time will be shifted by "+QString::number(corr)+ "secs"); | ||
179 | TextLabelPredTime->setText(QDateTime::currentDateTime().addSecs(corr).toString()); | ||
146 | } | 180 | } |