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