author | tille <tille> | 2002-06-24 11:16:30 (UTC) |
---|---|---|
committer | tille <tille> | 2002-06-24 11:16:30 (UTC) |
commit | 5bbfde2c34b3bbccdae89171fa0528ca8ae22b32 (patch) (side-by-side diff) | |
tree | 69546c118ae88be28c29196db39205620de702f1 /noncore | |
parent | 191d88cc062f4c50b28984e17b93139c685efee1 (diff) | |
download | opie-5bbfde2c34b3bbccdae89171fa0528ca8ae22b32.zip opie-5bbfde2c34b3bbccdae89171fa0528ca8ae22b32.tar.gz opie-5bbfde2c34b3bbccdae89171fa0528ca8ae22b32.tar.bz2 |
added predict time
-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 42 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntp.h | 1 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntpbase.ui | 117 |
3 files changed, 134 insertions, 26 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 @@ -33,2 +33,3 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); + connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); _nextCorrection = new QTimer( this ); @@ -82,3 +83,3 @@ void Ntp::ntpFinished(OProcess*) float timeShift = getTimeShift(); - if (timeShift = 0.0) return; + if (timeShift == 0.0) return; int secsSinceLast = time - lastLookup; @@ -92,3 +93,3 @@ void Ntp::ntpFinished(OProcess*) float nextCorr = _maxOffset / _shiftPerSec; - 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); + qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); cfg.writeEntry("secsSinceLast",secsSinceLast); @@ -139,2 +140,14 @@ void Ntp::readLookups() int lookupCount = cfg.readNumEntry("count",-1); + float last, shift, shiftPerSec; + qDebug("lookupCount = %i",lookupCount); + TableLookups->setNumCols( 3 ); + TableLookups->setNumRows( lookupCount); + TableLookups->horizontalHeader()->setLabel(2,"secsSinceLast"); + TableLookups->horizontalHeader()->setLabel(1,"timeShift"); + TableLookups->horizontalHeader()->setLabel(0,"shift/s"); + int cw = TableLookups->width()/4; + qDebug("column width %i",cw); + TableLookups->setColumnWidth( 0, cw ); + TableLookups->setColumnWidth( 1, cw ); + TableLookups->setColumnWidth( 2, cw ); for (int i=0; i < lookupCount; i++) @@ -142,5 +155,26 @@ void Ntp::readLookups() cfg.setGroup("lookup_"+QString::number(i)); - TableLookups->setText( 1,i,cfg.readEntry("secsSinceLast",0)); - TableLookups->setText( 2,i,cfg.readEntry("timeShift",0)); + last = cfg.readEntry("secsSinceLast",0).toFloat(); + shift = QString(cfg.readEntry("timeShift",0)).toFloat(); + qDebug("%i last %f",i,last); + qDebug("%i shift %f",i,shift); + shiftPerSec = shift / last; + _shiftPerSec += shiftPerSec; + TableLookups->setText( i,0,QString::number(shiftPerSec)); + TableLookups->setText( i,1,QString::number(shift)); + TableLookups->setText( i,2,QString::number(last)); } + _shiftPerSec /= lookupCount+1; + TextLabelShift->setText(QString::number(_shiftPerSec)); +} + +void Ntp::preditctTime() +{ + qDebug("current time: %s",QDateTime::currentDateTime().toString().latin1()); + Config cfg("ntp",Config::User); + cfg.setGroup("lookups"); + int lastTime = cfg.readNumEntry("time",0); + int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); + int corr = int((now - lastTime) * _shiftPerSec); + outPut->append( "time will be shifted by "+QString::number(corr)+ "secs"); + TextLabelPredTime->setText(QDateTime::currentDateTime().addSecs(corr).toString()); } diff --git a/noncore/settings/netsystemtime/ntp.h b/noncore/settings/netsystemtime/ntp.h index 4dc04b1..e3f6d16 100644 --- a/noncore/settings/netsystemtime/ntp.h +++ b/noncore/settings/netsystemtime/ntp.h @@ -34,2 +34,3 @@ private slots: void correctClock(); + void preditctTime(); }; diff --git a/noncore/settings/netsystemtime/ntpbase.ui b/noncore/settings/netsystemtime/ntpbase.ui index eb09e4a..1c1e1aa 100644 --- a/noncore/settings/netsystemtime/ntpbase.ui +++ b/noncore/settings/netsystemtime/ntpbase.ui @@ -13,3 +13,3 @@ <y>0</y> - <width>296</width> + <width>292</width> <height>337</height> @@ -142,3 +142,3 @@ <name>text</name> - <string></string> + <string>nan</string> </property> @@ -164,3 +164,3 @@ <name>text</name> - <string></string> + <string>nan</string> </property> @@ -186,3 +186,3 @@ <name>text</name> - <string></string> + <string>nan</string> </property> @@ -261,19 +261,5 @@ </attribute> - <widget> - <class>QTable</class> - <property stdset="1"> - <name>name</name> - <cstring>TableLookups</cstring> - </property> - <property stdset="1"> - <name>geometry</name> - <rect> - <x>10</x> - <y>10</y> - <width>270</width> - <height>220</height> - </rect> - </property> + <grid> <property stdset="1"> - <name>numRows</name> + <name>margin</name> <number>2</number> @@ -281,6 +267,93 @@ <property stdset="1"> - <name>numCols</name> + <name>spacing</name> <number>2</number> </property> - </widget> + <widget row="0" column="0" > + <class>QTable</class> + <property stdset="1"> + <name>name</name> + <cstring>TableLookups</cstring> + </property> + <property stdset="1"> + <name>numRows</name> + <number>2</number> + </property> + <property stdset="1"> + <name>numCols</name> + <number>2</number> + </property> + </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" > + <class>QLayoutWidget</class> + <property stdset="1"> + <name>name</name> + <cstring>Layout5</cstring> + </property> + <grid> + <property stdset="1"> + <name>margin</name> + <number>0</number> + </property> + <property stdset="1"> + <name>spacing</name> + <number>6</number> + </property> + <widget row="0" column="1" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabelShift</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>nan</string> + </property> + </widget> + <widget row="1" column="1" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabelPredTime</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>nan</string> + </property> + </widget> + <widget row="0" column="0" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>Mean_shift_label</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Mean shift:</string> + </property> + </widget> + <widget row="1" column="0" > + <class>QLabel</class> + <property stdset="1"> + <name>name</name> + <cstring>TextLabel3_2</cstring> + </property> + <property stdset="1"> + <name>text</name> + <string>Pred. Time:</string> + </property> + </widget> + </grid> + </widget> + </grid> </widget> |