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 | |||
@@ -5,3 +5,5 @@ | |||
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> |
@@ -24,6 +26,14 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | |||
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)), |
@@ -34,5 +44,4 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | |||
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(); |
@@ -42,10 +51,6 @@ 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 | } |
@@ -57,3 +62,3 @@ void Ntp::slotRunNtp() | |||
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); |
@@ -71,3 +76,3 @@ void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) | |||
71 | { | 76 | { |
72 | // outPut->append(lineStr); | 77 | MultiLineEditntpOutPut->append(lineStr); |
73 | _ntpOutput += lineStr; | 78 | _ntpOutput += lineStr; |
@@ -92,3 +97,3 @@ void Ntp::ntpFinished(OProcess*) | |||
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 | { |
@@ -153,8 +158,8 @@ void Ntp::readLookups() | |||
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 ); |
@@ -166,4 +171,4 @@ void Ntp::readLookups() | |||
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; |
@@ -171,4 +176,4 @@ void Ntp::readLookups() | |||
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 | } |
@@ -187,5 +192,25 @@ void Ntp::preditctTime() | |||
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 | } |