author | tille <tille> | 2002-06-26 17:12:58 (UTC) |
---|---|---|
committer | tille <tille> | 2002-06-26 17:12:58 (UTC) |
commit | 18905bcc671622ab11b4e3d4447e4cd34f7308ee (patch) (unidiff) | |
tree | d239f73841774b4514dea4476109b1e4336124a5 | |
parent | 9d692658a94c59889c6e46baaeae971226952eb8 (diff) | |
download | opie-18905bcc671622ab11b4e3d4447e4cd34f7308ee.zip opie-18905bcc671622ab11b4e3d4447e4cd34f7308ee.tar.gz opie-18905bcc671622ab11b4e3d4447e4cd34f7308ee.tar.bz2 |
network changes
-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 21 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/ntp.h | 3 |
2 files changed, 19 insertions, 5 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index b2f5332..6a5c062 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp | |||
@@ -1,281 +1,294 @@ | |||
1 | #include "ntp.h" | 1 | #include "ntp.h" |
2 | #include <qpushbutton.h> | 2 | #include <qpushbutton.h> |
3 | #include <qregexp.h> | 3 | #include <qregexp.h> |
4 | #include <qtimer.h> | 4 | #include <qtimer.h> |
5 | #include <qtable.h> | 5 | #include <qtable.h> |
6 | #include <qlabel.h> | 6 | #include <qlabel.h> |
7 | #include <qsocket.h> | 7 | #include <qsocket.h> |
8 | #include <qlineedit.h> | 8 | #include <qlineedit.h> |
9 | #include <qspinbox.h> | 9 | #include <qspinbox.h> |
10 | #include <qmessagebox.h> | 10 | #include <qmessagebox.h> |
11 | #include <qmultilineedit.h> | 11 | #include <qmultilineedit.h> |
12 | #include <opie/oprocess.h> | 12 | #include <opie/oprocess.h> |
13 | #include <qpe/config.h> | 13 | #include <qpe/config.h> |
14 | #include <qpe/global.h> | 14 | #include <qpe/global.h> |
15 | #include <qpe/timeconversion.h> | 15 | #include <qpe/timeconversion.h> |
16 | #include <qpe/tzselect.h> | 16 | #include <qpe/tzselect.h> |
17 | #include <qpe/timestring.h> | 17 | #include <qpe/timestring.h> |
18 | #include <qpe/qpedialog.h> | 18 | #include <qpe/qpedialog.h> |
19 | #include <sys/time.h> | 19 | #include <sys/time.h> |
20 | #include <time.h> | 20 | #include <time.h> |
21 | #include <stdlib.h> | 21 | #include <stdlib.h> |
22 | 22 | ||
23 | 23 | ||
24 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | 24 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) |
25 | : SetDateTime( parent, name, fl ) | 25 | : SetDateTime( parent, name, fl ) |
26 | { | 26 | { |
27 | 27 | ||
28 | Config ntpSrvs("/etc/ntpservers",Config::File); | 28 | Config ntpSrvs("/etc/ntpservers",Config::File); |
29 | ntpSrvs.setGroup("servers"); | 29 | ntpSrvs.setGroup("servers"); |
30 | int srvCount = ntpSrvs.readNumEntry("count", 0 ); | 30 | int srvCount = ntpSrvs.readNumEntry("count", 0 ); |
31 | for (int i = 0; i < srvCount; i++) | 31 | for (int i = 0; i < srvCount; i++) |
32 | { | 32 | { |
33 | ntpSrvs.setGroup(QString::number(i)); | 33 | ntpSrvs.setGroup(QString::number(i)); |
34 | ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); | 34 | ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); |
35 | } | 35 | } |
36 | if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); | 36 | if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); |
37 | 37 | ||
38 | Config cfg("ntp",Config::User); | 38 | Config cfg("ntp",Config::User); |
39 | cfg.setGroup("settings"); | 39 | cfg.setGroup("settings"); |
40 | // _maxOffset = cfg.readNumEntry("maxOffset",5); | ||
41 | // _minLookupDiff = cfg.readNumEntry("minLookupDiff",10); | ||
42 | SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) ); | 40 | SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) ); |
43 | SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) ); | 41 | SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) ); |
44 | ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); | 42 | ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); |
45 | 43 | ||
46 | ntpTimer = new QTimer(this); | 44 | ntpTimer = new QTimer(this); |
45 | processTimer = new QTimer(this); | ||
47 | ntpTimer->start(SpinBoxNtpDelay->value()*1000*60); | 46 | ntpTimer->start(SpinBoxNtpDelay->value()*1000*60); |
48 | 47 | ||
49 | ntpProcess = new OProcess( ); | 48 | ntpProcess = new OProcess( ); |
50 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), | 49 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), |
51 | SLOT(slotNtpDelayChanged(int)) ); | 50 | SLOT(slotNtpDelayChanged(int)) ); |
52 | 51 | ||
53 | ntpSock = new QSocket( this ); | 52 | ntpSock = new QSocket( this ); |
54 | connect( ntpSock, SIGNAL( error(int) ), | 53 | connect( ntpSock, SIGNAL( error(int) ), |
55 | SLOT(slotCheckNtp(int)) ); | 54 | SLOT(slotCheckNtp(int)) ); |
56 | slotProbeNtpServer(); | 55 | slotProbeNtpServer(); |
57 | 56 | ||
58 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), | 57 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), |
59 | this, SLOT(getNtpOutput(OProcess*,char*,int))); | 58 | this, SLOT(getNtpOutput(OProcess*,char*,int))); |
60 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), | 59 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), |
61 | this, SLOT(ntpFinished(OProcess*))); | 60 | this, SLOT(ntpFinished(OProcess*))); |
62 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); | 61 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); |
63 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); | 62 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); |
64 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); | 63 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); |
65 | slotCheckNtp(-1); | 64 | slotCheckNtp(-1); |
66 | readLookups(); | 65 | readLookups(); |
67 | } | 66 | } |
68 | 67 | ||
69 | Ntp::~Ntp() | 68 | Ntp::~Ntp() |
70 | { | 69 | { |
71 | delete ntpProcess; | 70 | delete ntpProcess; |
72 | Config ntpSrvs("/etc/ntpservers",Config::File); | 71 | Config ntpSrvs("/etc/ntpservers",Config::File); |
73 | ntpSrvs.setGroup("servers"); | 72 | ntpSrvs.setGroup("servers"); |
74 | int srvCount = ComboNtpSrv->count(); | 73 | int srvCount = ComboNtpSrv->count(); |
75 | ntpSrvs.writeEntry("count", srvCount); | 74 | ntpSrvs.writeEntry("count", srvCount); |
76 | for (int i = 0; i < srvCount; i++) | 75 | for (int i = 0; i < srvCount; i++) |
77 | { | 76 | { |
78 | ntpSrvs.setGroup(QString::number(i)); | 77 | ntpSrvs.setGroup(QString::number(i)); |
79 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); | 78 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); |
80 | } | 79 | } |
81 | Config cfg("ntp",Config::User); | 80 | Config cfg("ntp",Config::User); |
82 | cfg.setGroup("settings"); | 81 | cfg.setGroup("settings"); |
83 | cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); | 82 | cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); |
84 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); | 83 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); |
85 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); | 84 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); |
86 | } | 85 | } |
87 | 86 | ||
88 | bool Ntp::ntpDelayElapsed() | 87 | bool Ntp::ntpDelayElapsed() |
89 | { | 88 | { |
90 | Config cfg("ntp",Config::User); | 89 | Config cfg("ntp",Config::User); |
91 | cfg.setGroup("lookups"); | 90 | cfg.setGroup("lookups"); |
92 | _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); | 91 | _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); |
93 | return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60; | 92 | return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60; |
94 | } | 93 | } |
95 | 94 | ||
96 | QString Ntp::getNtpServer() | 95 | QString Ntp::getNtpServer() |
97 | { | 96 | { |
98 | return ComboNtpSrv->currentText(); | 97 | return ComboNtpSrv->currentText(); |
99 | } | 98 | } |
100 | 99 | ||
101 | void Ntp::slotRunNtp() | 100 | void Ntp::slotRunNtp() |
102 | { | 101 | { |
103 | if ( !ntpDelayElapsed() ) | 102 | if ( !ntpDelayElapsed() ) |
104 | { | 103 | { |
105 | switch ( | 104 | switch ( |
106 | QMessageBox::warning(this, tr("Run NTP?"), | 105 | QMessageBox::warning(this, tr("Run NTP?"), |
107 | tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ | 106 | tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ |
108 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+ | 107 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+ |
109 | "<br>"+tr("Rerun NTP?"), | 108 | "<br>"+tr("Rerun NTP?"), |
110 | QMessageBox::Ok,QMessageBox::Cancel) | 109 | QMessageBox::Ok,QMessageBox::Cancel) |
111 | ) { | 110 | ) { |
112 | case QMessageBox::Ok: break; | 111 | case QMessageBox::Ok: break; |
113 | case QMessageBox::Cancel: return; | 112 | case QMessageBox::Cancel: return; |
114 | default: return; | 113 | default: return; |
115 | } | 114 | } |
116 | } | 115 | } |
117 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); | 116 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); |
118 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); | 117 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); |
118 | connect( processTimer, SIGNAL( timeout() ), SLOT(slotTimeoutNtpProcess()) ); | ||
119 | processTimer->start(2*1000*60, true); | ||
120 | |||
119 | ntpProcess->clearArguments(); | 121 | ntpProcess->clearArguments(); |
120 | *ntpProcess << "ntpdate" << getNtpServer(); | 122 | *ntpProcess << "ntpdate" << getNtpServer(); |
121 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); | 123 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); |
122 | if ( !ret ) { | 124 | if ( !ret ) { |
123 | qDebug("Error while executing ntpdate"); | 125 | qDebug("Error while executing ntpdate"); |
124 | ntpOutPut( tr("Error while executing ntpdate")); | 126 | ntpOutPut( tr("Error while executing ntpdate")); |
125 | } | 127 | } |
126 | } | 128 | } |
127 | 129 | ||
128 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) | 130 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) |
129 | { | 131 | { |
130 | QString lineStr, lineStrOld; | 132 | QString lineStr, lineStrOld; |
131 | lineStr = buffer; | 133 | lineStr = buffer; |
132 | lineStr=lineStr.left(buflen); | 134 | lineStr=lineStr.left(buflen); |
133 | if (lineStr!=lineStrOld) | 135 | if (lineStr!=lineStrOld) |
134 | { | 136 | { |
135 | ntpOutPut(lineStr); | 137 | ntpOutPut(lineStr); |
136 | _ntpOutput += lineStr; | 138 | _ntpOutput += lineStr; |
137 | } | 139 | } |
138 | lineStrOld = lineStr; | 140 | lineStrOld = lineStr; |
139 | } | 141 | } |
140 | 142 | ||
141 | void Ntp::ntpFinished(OProcess*) | 143 | void Ntp::ntpFinished(OProcess *p) |
142 | { | 144 | { |
145 | if (!p->normalExit()) | ||
146 | { | ||
147 | slotProbeNtpServer(); | ||
148 | return; | ||
149 | } | ||
150 | processTimer->stop(); | ||
143 | Config cfg("ntp",Config::User); | 151 | Config cfg("ntp",Config::User); |
144 | cfg.setGroup("lookups"); | 152 | cfg.setGroup("lookups"); |
145 | int lastLookup = cfg.readNumEntry("time",0); | 153 | int lastLookup = cfg.readNumEntry("time",0); |
146 | int lookupCount = cfg.readNumEntry("count",-1); | 154 | int lookupCount = cfg.readNumEntry("count",-1); |
147 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 155 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
148 | cfg.writeEntry("time", time); | 156 | cfg.writeEntry("time", time); |
149 | cfg.setGroup("correction"); | 157 | cfg.setGroup("correction"); |
150 | cfg.writeEntry("time", time); | 158 | cfg.writeEntry("time", time); |
151 | 159 | ||
152 | float timeShift = getTimeShift(); | 160 | float timeShift = getTimeShift(); |
153 | if (timeShift == 0.0) return; | 161 | if (timeShift == 0.0) return; |
154 | int secsSinceLast = time - lastLookup; | 162 | int secsSinceLast = time - lastLookup; |
155 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); | 163 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); |
156 | TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); | 164 | TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); |
157 | if ( lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) | 165 | if ( lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) |
158 | { | 166 | { |
159 | lookupCount++; | 167 | lookupCount++; |
160 | cfg.writeEntry("count",lookupCount); | 168 | cfg.writeEntry("count",lookupCount); |
161 | cfg.setGroup("lookup_"+QString::number(lookupCount)); | 169 | cfg.setGroup("lookup_"+QString::number(lookupCount)); |
162 | _shiftPerSec = timeShift / secsSinceLast; | 170 | _shiftPerSec = timeShift / secsSinceLast; |
163 | qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); | 171 | qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); |
164 | cfg.writeEntry("secsSinceLast",secsSinceLast); | 172 | cfg.writeEntry("secsSinceLast",secsSinceLast); |
165 | cfg.writeEntry("timeShift",QString::number(timeShift)); | 173 | cfg.writeEntry("timeShift",QString::number(timeShift)); |
166 | } | 174 | } |
167 | } | 175 | } |
168 | 176 | ||
169 | 177 | ||
170 | float Ntp::getTimeShift() | 178 | float Ntp::getTimeShift() |
171 | { | 179 | { |
172 | QString _offset = "offset"; | 180 | QString _offset = "offset"; |
173 | QString _sec = "sec"; | 181 | QString _sec = "sec"; |
174 | QRegExp _reOffset = QRegExp(_offset); | 182 | QRegExp _reOffset = QRegExp(_offset); |
175 | QRegExp _reEndOffset = QRegExp(_sec); | 183 | QRegExp _reEndOffset = QRegExp(_sec); |
176 | int posOffset = _reOffset.match( _ntpOutput ); | 184 | int posOffset = _reOffset.match( _ntpOutput ); |
177 | int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); | 185 | int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); |
178 | posOffset += _offset.length() + 1; | 186 | posOffset += _offset.length() + 1; |
179 | QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); | 187 | QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); |
180 | qDebug("%s", _ntpOutput.latin1()); | 188 | qDebug("%s", _ntpOutput.latin1()); |
181 | qDebug("diff = >%s<",diff.latin1()); | 189 | qDebug("diff = >%s<",diff.latin1()); |
182 | return diff.toFloat(); | 190 | return diff.toFloat(); |
183 | } | 191 | } |
184 | 192 | ||
185 | void Ntp::readLookups() | 193 | void Ntp::readLookups() |
186 | { | 194 | { |
187 | Config cfg("ntp",Config::User); | 195 | Config cfg("ntp",Config::User); |
188 | cfg.setGroup("lookups"); | 196 | cfg.setGroup("lookups"); |
189 | int lookupCount = cfg.readNumEntry("count",-1); | 197 | int lookupCount = cfg.readNumEntry("count",-1); |
190 | float last, shift, shiftPerSec; | 198 | float last, shift, shiftPerSec; |
191 | qDebug("lookupCount = %i",lookupCount); | 199 | qDebug("lookupCount = %i",lookupCount); |
192 | TableLookups->setNumCols( 3 ); | 200 | TableLookups->setNumCols( 3 ); |
193 | TableLookups->setNumRows( lookupCount); | 201 | TableLookups->setNumRows( lookupCount); |
194 | TableLookups->horizontalHeader()->setLabel(1,"secsSinceLast"); | 202 | TableLookups->horizontalHeader()->setLabel(1,"secsSinceLast"); |
195 | TableLookups->horizontalHeader()->setLabel(2,"timeShift"); | 203 | TableLookups->horizontalHeader()->setLabel(2,"timeShift"); |
196 | TableLookups->horizontalHeader()->setLabel(0,"shift/s"); | 204 | TableLookups->horizontalHeader()->setLabel(0,"shift/s"); |
197 | int cw = 50;//TableLookups->width()/4; | 205 | int cw = 50;//TableLookups->width()/4; |
198 | qDebug("column width %i",cw); | 206 | qDebug("column width %i",cw); |
199 | TableLookups->setColumnWidth( 0, cw+30 ); | 207 | TableLookups->setColumnWidth( 0, cw+30 ); |
200 | TableLookups->setColumnWidth( 1, cw ); | 208 | TableLookups->setColumnWidth( 1, cw ); |
201 | TableLookups->setColumnWidth( 2, cw ); | 209 | TableLookups->setColumnWidth( 2, cw ); |
202 | TableLookups->sortColumn(0, false, true ); | 210 | TableLookups->sortColumn(0, false, true ); |
203 | // TableLookups->setSorting( true ); | 211 | // TableLookups->setSorting( true ); |
204 | for (int i=0; i < lookupCount; i++) | 212 | for (int i=0; i < lookupCount; i++) |
205 | { | 213 | { |
206 | cfg.setGroup("lookup_"+QString::number(i)); | 214 | cfg.setGroup("lookup_"+QString::number(i)); |
207 | last = cfg.readEntry("secsSinceLast",0).toFloat(); | 215 | last = cfg.readEntry("secsSinceLast",0).toFloat(); |
208 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); | 216 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); |
209 | // qDebug("%i last %f",i,last); | 217 | // qDebug("%i last %f",i,last); |
210 | // qDebug("%i shift %f",i,shift); | 218 | // qDebug("%i shift %f",i,shift); |
211 | shiftPerSec = shift / last; | 219 | shiftPerSec = shift / last; |
212 | _shiftPerSec += shiftPerSec; | 220 | _shiftPerSec += shiftPerSec; |
213 | TableLookups->setText( i,0,QString::number(shiftPerSec)); | 221 | TableLookups->setText( i,0,QString::number(shiftPerSec)); |
214 | TableLookups->setText( i,2,QString::number(shift)); | 222 | TableLookups->setText( i,2,QString::number(shift)); |
215 | TableLookups->setText( i,1,QString::number(last)); | 223 | TableLookups->setText( i,1,QString::number(last)); |
216 | } | 224 | } |
217 | _shiftPerSec /= lookupCount+1; | 225 | _shiftPerSec /= lookupCount+1; |
218 | TextLabelShift->setText(QString::number(_shiftPerSec)+tr(" seconds")); | 226 | TextLabelShift->setText(QString::number(_shiftPerSec)+tr(" seconds")); |
219 | } | 227 | } |
220 | 228 | ||
221 | void Ntp::preditctTime() | 229 | void Ntp::preditctTime() |
222 | { | 230 | { |
223 | Config cfg("ntp",Config::User); | 231 | Config cfg("ntp",Config::User); |
224 | cfg.setGroup("lookups"); | 232 | cfg.setGroup("lookups"); |
225 | int lastTime = cfg.readNumEntry("time",0); | 233 | int lastTime = cfg.readNumEntry("time",0); |
226 | setenv( "TZ", tz->currentZone(), 1 ); | 234 | setenv( "TZ", tz->currentZone(), 1 ); |
227 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 235 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
228 | int corr = int((now - lastTime) * _shiftPerSec); | 236 | int corr = int((now - lastTime) * _shiftPerSec); |
229 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); | 237 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); |
230 | predictedTime = QDateTime::currentDateTime().addSecs(corr); | 238 | predictedTime = QDateTime::currentDateTime().addSecs(corr); |
231 | TextLabelPredTime->setText(predictedTime.toString()); | 239 | TextLabelPredTime->setText(predictedTime.toString()); |
232 | TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); | 240 | TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); |
233 | } | 241 | } |
234 | 242 | ||
235 | void Ntp::setPredictTime() | 243 | void Ntp::setPredictTime() |
236 | { | 244 | { |
237 | preditctTime(); | 245 | preditctTime(); |
238 | setTime( predictedTime ); | 246 | setTime( predictedTime ); |
239 | } | 247 | } |
240 | 248 | ||
241 | void Ntp::slotCheckNtp(int i) | 249 | void Ntp::slotCheckNtp(int i) |
242 | { | 250 | { |
243 | if (i == 0) | 251 | if (i == 0) |
244 | { | 252 | { |
245 | TextLabelMainPredTime->hide(); | 253 | TextLabelMainPredTime->hide(); |
246 | ButtonSetTime->setText( tr("Get time from network") ); | 254 | ButtonSetTime->setText( tr("Get time from network") ); |
247 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); | 255 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); |
248 | if ( ntpDelayElapsed() ) | 256 | if ( ntpDelayElapsed() ) |
249 | { | 257 | { |
250 | slotRunNtp(); | 258 | slotRunNtp(); |
251 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); | 259 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); |
252 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); | 260 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); |
253 | }else{ | 261 | }else{ |
254 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); | 262 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); |
255 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 263 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
256 | } | 264 | } |
257 | }else{ | 265 | }else{ |
258 | preditctTime(); | 266 | preditctTime(); |
259 | ButtonSetTime->setText( tr("Set predicted time") ); | 267 | ButtonSetTime->setText( tr("Set predicted time") ); |
260 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); | 268 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); |
261 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); | 269 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); |
262 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 270 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
263 | } | 271 | } |
264 | //ntpTimer->start(SpinBoxNtpDelay->value()*1000*60); | ||
265 | } | 272 | } |
266 | 273 | ||
267 | void Ntp::slotProbeNtpServer() | 274 | void Ntp::slotProbeNtpServer() |
268 | { | 275 | { |
269 | ntpSock->connectToHost( getNtpServer() ,123); | 276 | ntpSock->connectToHost( getNtpServer() ,123); |
270 | } | 277 | } |
271 | 278 | ||
272 | void Ntp::slotNtpDelayChanged(int delay) | 279 | void Ntp::slotNtpDelayChanged(int delay) |
273 | { | 280 | { |
274 | ntpTimer->changeInterval( delay*1000*60 ); | 281 | ntpTimer->changeInterval( delay*1000*60 ); |
275 | } | 282 | } |
276 | 283 | ||
277 | void Ntp::ntpOutPut(QString out) | 284 | void Ntp::ntpOutPut(QString out) |
278 | { | 285 | { |
279 | MultiLineEditntpOutPut->append(out); | 286 | MultiLineEditntpOutPut->append(out); |
280 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); | 287 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); |
281 | } | 288 | } |
289 | |||
290 | void Ntp::slotTimeoutNtpProcess() | ||
291 | { | ||
292 | ntpProcess->kill(); | ||
293 | slotProbeNtpServer(); | ||
294 | } | ||
diff --git a/noncore/settings/netsystemtime/ntp.h b/noncore/settings/netsystemtime/ntp.h index c78dc55..d166973 100644 --- a/noncore/settings/netsystemtime/ntp.h +++ b/noncore/settings/netsystemtime/ntp.h | |||
@@ -1,47 +1,48 @@ | |||
1 | #ifndef NTP_H | 1 | #ifndef NTP_H |
2 | #define NTP_H | 2 | #define NTP_H |
3 | #include "settime.h" | 3 | #include "settime.h" |
4 | #include <qdatetime.h> | 4 | #include <qdatetime.h> |
5 | 5 | ||
6 | class OProcess; | 6 | class OProcess; |
7 | class QString; | 7 | class QString; |
8 | class QTimer; | 8 | class QTimer; |
9 | class QSocket; | 9 | class QSocket; |
10 | 10 | ||
11 | class Ntp : public SetDateTime | 11 | class Ntp : public SetDateTime |
12 | { | 12 | { |
13 | Q_OBJECT | 13 | Q_OBJECT |
14 | 14 | ||
15 | public: | 15 | public: |
16 | Ntp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); | 16 | Ntp( QWidget* parent = 0, const char* name = 0, WFlags fl = 0 ); |
17 | ~Ntp(); | 17 | ~Ntp(); |
18 | 18 | ||
19 | protected: | 19 | protected: |
20 | QDateTime predictedTime; | 20 | QDateTime predictedTime; |
21 | 21 | ||
22 | 22 | ||
23 | private: | 23 | private: |
24 | QString _ntpOutput; | 24 | QString _ntpOutput; |
25 | float _shiftPerSec; | 25 | float _shiftPerSec; |
26 | int _lookupDiff; | 26 | int _lookupDiff; |
27 | OProcess *ntpProcess; | 27 | OProcess *ntpProcess; |
28 | QTimer *ntpTimer; | 28 | QTimer *ntpTimer, *processTimer; |
29 | QSocket *ntpSock; | 29 | QSocket *ntpSock; |
30 | 30 | ||
31 | float getTimeShift(); | 31 | float getTimeShift(); |
32 | void readLookups(); | 32 | void readLookups(); |
33 | void ntpOutPut(QString); | 33 | void ntpOutPut(QString); |
34 | bool ntpDelayElapsed(); | 34 | bool ntpDelayElapsed(); |
35 | QString getNtpServer(); | 35 | QString getNtpServer(); |
36 | private slots: | 36 | private slots: |
37 | void slotRunNtp(); | 37 | void slotRunNtp(); |
38 | void getNtpOutput(OProcess *proc, char *buffer, int buflen); | 38 | void getNtpOutput(OProcess *proc, char *buffer, int buflen); |
39 | void ntpFinished(OProcess*); | 39 | void ntpFinished(OProcess*); |
40 | void preditctTime(); | 40 | void preditctTime(); |
41 | void slotCheckNtp(int); | 41 | void slotCheckNtp(int); |
42 | void setPredictTime(); | 42 | void setPredictTime(); |
43 | void slotProbeNtpServer(); | 43 | void slotProbeNtpServer(); |
44 | void slotNtpDelayChanged(int); | 44 | void slotNtpDelayChanged(int); |
45 | void slotTimeoutNtpProcess(); | ||
45 | }; | 46 | }; |
46 | 47 | ||
47 | #endif | 48 | #endif |