Diffstat (limited to 'noncore/settings/netsystemtime/ntp.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 77 |
1 files changed, 51 insertions, 26 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index 87b20ec..4a7959e 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp | |||
@@ -4,5 +4,7 @@ | |||
4 | #include <qtable.h> | 4 | #include <qtable.h> |
5 | #include <qlabel.h> | 5 | #include <qlabel.h> |
6 | #include <qsocket.h> | ||
6 | #include <qlineedit.h> | 7 | #include <qlineedit.h> |
8 | #include <qspinbox.h> | ||
7 | #include <qmultilineedit.h> | 9 | #include <qmultilineedit.h> |
8 | #include <opie/oprocess.h> | 10 | #include <opie/oprocess.h> |
@@ -23,8 +25,16 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | |||
23 | Config cfg("ntp",Config::User); | 25 | Config cfg("ntp",Config::User); |
24 | cfg.setGroup("settings"); | 26 | cfg.setGroup("settings"); |
25 | _maxOffset = cfg.readNumEntry("maxOffset",5); | 27 | // _maxOffset = cfg.readNumEntry("maxOffset",5); |
26 | _minLookupDiff = cfg.readNumEntry("minLookupDiff",10); | 28 | // _minLookupDiff = cfg.readNumEntry("minLookupDiff",10); |
27 | LineEditNtpServer->setText( cfg.readEntry("ntpServer") ); | 29 | SpinBoxMinDelay->setValue( cfg.readNumEntry("minLookupDiff",10) ); |
30 | SpinBoxMinDelay->setMinValue( 7 ); | ||
31 | LineEditNtpSrv->setText( cfg.readEntry("ntpServer", tr("time.fu-berlin.de")) ); | ||
28 | ntpProcess = new OProcess( ); | 32 | ntpProcess = new OProcess( ); |
33 | |||
34 | QSocket *ntpSock = new QSocket( this ); | ||
35 | ntpSock->connectToHost( LineEditNtpSrv->text() ,123); | ||
36 | connect( ntpSock, SIGNAL( error(int) ), | ||
37 | SLOT(slotCheckNtp(int)) ); | ||
38 | |||
29 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), | 39 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), |
30 | this, SLOT(getNtpOutput(OProcess*,char*,int))); | 40 | this, SLOT(getNtpOutput(OProcess*,char*,int))); |
@@ -33,7 +43,6 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | |||
33 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); | 43 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); |
34 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); | 44 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); |
35 | // _nextCorrection = new QTimer( this ); | 45 | |
36 | // connect( _nextCorrection, SIGNAL(timeout()), SLOT(correctClock()) ); | 46 | // slotRunNtp(); |
37 | slotRunNtp(); | ||
38 | readLookups(); | 47 | readLookups(); |
39 | } | 48 | } |
@@ -41,12 +50,8 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | |||
41 | Ntp::~Ntp() | 50 | Ntp::~Ntp() |
42 | { | 51 | { |
43 | |||
44 | } | ||
45 | |||
46 | void Ntp::accept() | ||
47 | { | ||
48 | Config cfg("ntp",Config::User); | 52 | Config cfg("ntp",Config::User); |
49 | cfg.setGroup("settings"); | 53 | cfg.setGroup("settings"); |
50 | cfg.writeEntry("ntpServer", LineEditNtpServer->text()); | 54 | cfg.writeEntry("ntpServer", LineEditNtpSrv->text()); |
55 | cfg.writeEntry( "minLookupDiff", SpinBoxMinDelay->value() ); | ||
51 | } | 56 | } |
52 | 57 | ||
@@ -56,5 +61,5 @@ void Ntp::slotRunNtp() | |||
56 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); | 61 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); |
57 | ntpProcess->clearArguments(); | 62 | ntpProcess->clearArguments(); |
58 | *ntpProcess << "ntpdate" << LineEditNtpServer->text(); | 63 | *ntpProcess << "ntpdate" << LineEditNtpSrv->text(); |
59 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); | 64 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); |
60 | if ( !ret ) { | 65 | if ( !ret ) { |
@@ -70,5 +75,5 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) | |||
70 | if (lineStr!=lineStrOld) | 75 | if (lineStr!=lineStrOld) |
71 | { | 76 | { |
72 | // outPut->append(lineStr); | 77 | MultiLineEditntpOutPut->append(lineStr); |
73 | _ntpOutput += lineStr; | 78 | _ntpOutput += lineStr; |
74 | } | 79 | } |
@@ -91,5 +96,5 @@ void Ntp::ntpFinished(OProcess*) | |||
91 | int secsSinceLast = time - lastLookup; | 96 | int secsSinceLast = time - lastLookup; |
92 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); | 97 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); |
93 | if ( lastLookup > 0 && secsSinceLast > 60*_minLookupDiff) | 98 | if ( lastLookup > 0 && secsSinceLast > 60*24* SpinBoxMinDelay->value()) |
94 | { | 99 | { |
95 | lookupCount++; | 100 | lookupCount++; |
@@ -152,10 +157,10 @@ void Ntp::readLookups() | |||
152 | TableLookups->setNumCols( 3 ); | 157 | TableLookups->setNumCols( 3 ); |
153 | TableLookups->setNumRows( lookupCount); | 158 | TableLookups->setNumRows( lookupCount); |
154 | TableLookups->horizontalHeader()->setLabel(2,"secsSinceLast"); | 159 | TableLookups->horizontalHeader()->setLabel(1,"secsSinceLast"); |
155 | TableLookups->horizontalHeader()->setLabel(1,"timeShift"); | 160 | TableLookups->horizontalHeader()->setLabel(2,"timeShift"); |
156 | TableLookups->horizontalHeader()->setLabel(0,"shift/s"); | 161 | TableLookups->horizontalHeader()->setLabel(0,"shift/s"); |
157 | int cw = TableLookups->width()/4; | 162 | int cw = 50;//TableLookups->width()/4; |
158 | qDebug("column width %i",cw); | 163 | qDebug("column width %i",cw); |
159 | TableLookups->setColumnWidth( 0, cw ); | 164 | TableLookups->setColumnWidth( 0, cw+30 ); |
160 | TableLookups->setColumnWidth( 1, cw ); | 165 | TableLookups->setColumnWidth( 1, cw ); |
161 | TableLookups->setColumnWidth( 2, cw ); | 166 | TableLookups->setColumnWidth( 2, cw ); |
@@ -165,11 +170,11 @@ void Ntp::readLookups() | |||
165 | last = cfg.readEntry("secsSinceLast",0).toFloat(); | 170 | last = cfg.readEntry("secsSinceLast",0).toFloat(); |
166 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); | 171 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); |
167 | qDebug("%i last %f",i,last); | 172 | // qDebug("%i last %f",i,last); |
168 | qDebug("%i shift %f",i,shift); | 173 | // qDebug("%i shift %f",i,shift); |
169 | shiftPerSec = shift / last; | 174 | shiftPerSec = shift / last; |
170 | _shiftPerSec += shiftPerSec; | 175 | _shiftPerSec += shiftPerSec; |
171 | TableLookups->setText( i,0,QString::number(shiftPerSec)); | 176 | TableLookups->setText( i,0,QString::number(shiftPerSec)); |
172 | TableLookups->setText( i,1,QString::number(shift)); | 177 | TableLookups->setText( i,2,QString::number(shift)); |
173 | TableLookups->setText( i,2,QString::number(last)); | 178 | TableLookups->setText( i,1,QString::number(last)); |
174 | } | 179 | } |
175 | _shiftPerSec /= lookupCount+1; | 180 | _shiftPerSec /= lookupCount+1; |
@@ -186,6 +191,26 @@ void Ntp::preditctTime() | |||
186 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 191 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
187 | int corr = int((now - lastTime) * _shiftPerSec); | 192 | int corr = int((now - lastTime) * _shiftPerSec); |
188 | QDateTime dt = QDateTime::currentDateTime().addSecs(corr); | 193 | predictedTime = QDateTime::currentDateTime().addSecs(corr); |
189 | setTime(dt); | 194 | TextLabelPredTime->setText(predictedTime.toString()); |
190 | TextLabelPredTime->setText(dt.toString()); | 195 | TextLabelMainPredTime->setText(predictedTime.toString()); |
196 | } | ||
197 | |||
198 | void Ntp::setPredictTime() | ||
199 | { | ||
200 | preditctTime(); | ||
201 | setTime( predictedTime ); | ||
202 | } | ||
203 | |||
204 | void Ntp::slotCheckNtp(int i) | ||
205 | { | ||
206 | if (i == 0) | ||
207 | { | ||
208 | TextLabelMainPredTime->hide(); | ||
209 | ButtonSetTime->setText( tr("Get time from network") ); | ||
210 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); | ||
211 | }else{ | ||
212 | preditctTime(); | ||
213 | ButtonSetTime->setText( tr("Predict time") ); | ||
214 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); | ||
215 | }; | ||
191 | } | 216 | } |