summaryrefslogtreecommitdiff
authordrw <drw>2003-03-29 22:32:58 (UTC)
committer drw <drw>2003-03-29 22:32:58 (UTC)
commit340cb7e64fb898966996b00b93c03ca05a347aa5 (patch) (unidiff)
tree0db7548e03ba94e8a71fc73a98fbe74544043062
parent4e17e397c6df9e4e1ac6ee8315bbbced3e3b3b49 (diff)
downloadopie-340cb7e64fb898966996b00b93c03ca05a347aa5.zip
opie-340cb7e64fb898966996b00b93c03ca05a347aa5.tar.gz
opie-340cb7e64fb898966996b00b93c03ca05a347aa5.tar.bz2
Fix for bug #701 - update time and date controls on Main tab after retrieving time from ntpdate.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp5
1 files changed, 5 insertions, 0 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index aecefc1..f653cd0 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -1,119 +1,120 @@
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 <qcheckbox.h> 10#include <qcheckbox.h>
11#include <qtabwidget.h> 11#include <qtabwidget.h>
12#include <qlayout.h> 12#include <qlayout.h>
13#include <qmessagebox.h> 13#include <qmessagebox.h>
14#include <qmultilineedit.h> 14#include <qmultilineedit.h>
15#include <opie/oprocess.h> 15#include <opie/oprocess.h>
16#include <qpe/qpeapplication.h> 16#include <qpe/qpeapplication.h>
17#include <qpe/config.h> 17#include <qpe/config.h>
18#include <qpe/global.h> 18#include <qpe/global.h>
19#include <qpe/timeconversion.h> 19#include <qpe/timeconversion.h>
20#include <qpe/tzselect.h> 20#include <qpe/tzselect.h>
21#include <qpe/timestring.h> 21#include <qpe/timestring.h>
22#include <qpe/qpedialog.h> 22#include <qpe/qpedialog.h>
23#include <qpe/datebookdb.h> 23#include <qpe/datebookdb.h>
24#include <qpe/datebookmonth.h>
24#include <qpe/qcopenvelope_qws.h> 25#include <qpe/qcopenvelope_qws.h>
25#include <sys/time.h> 26#include <sys/time.h>
26#include <time.h> 27#include <time.h>
27#include <stdlib.h> 28#include <stdlib.h>
28 29
29 30
30Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) 31Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
31 : SetDateTime( parent, name, fl ) 32 : SetDateTime( parent, name, fl )
32{ 33{
33 _interactive = false; 34 _interactive = false;
34 Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); 35 Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File);
35 ntpSrvs.setGroup("servers"); 36 ntpSrvs.setGroup("servers");
36 int srvCount = ntpSrvs.readNumEntry("count", 0 ); 37 int srvCount = ntpSrvs.readNumEntry("count", 0 );
37 for (int i = 0; i < srvCount; i++) 38 for (int i = 0; i < srvCount; i++)
38 { 39 {
39 ntpSrvs.setGroup(QString::number(i)); 40 ntpSrvs.setGroup(QString::number(i));
40 ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); 41 ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") );
41 } 42 }
42 if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); 43 if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de"));
43 44
44 Config cfg("ntp",Config::User); 45 Config cfg("ntp",Config::User);
45 cfg.setGroup("settings"); 46 cfg.setGroup("settings");
46 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",720) ); 47 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",720) );
47 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",1440) ); 48 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",1440) );
48 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); 49 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) );
49 50
50 //make tab order 51 //make tab order
51 52
52 TabWidgetMain->removePage( tabMain ); 53 TabWidgetMain->removePage( tabMain );
53 TabWidgetMain->removePage( tabManualSetTime ); 54 TabWidgetMain->removePage( tabManualSetTime );
54 TabWidgetMain->removePage( TabSettings ); 55 TabWidgetMain->removePage( TabSettings );
55 TabWidgetMain->removePage( tabPredict ); 56 TabWidgetMain->removePage( tabPredict );
56 TabWidgetMain->removePage( tabNtp ); 57 TabWidgetMain->removePage( tabNtp );
57 58
58 TabWidgetMain->insertTab( tabMain, tr( "Main" ) ); 59 TabWidgetMain->insertTab( tabMain, tr( "Main" ) );
59 TabWidgetMain->insertTab( TabSettings, tr( "Settings" ) ); 60 TabWidgetMain->insertTab( TabSettings, tr( "Settings" ) );
60 TabWidgetMain->insertTab( tabPredict, tr( "Predict" ) ); 61 TabWidgetMain->insertTab( tabPredict, tr( "Predict" ) );
61 TabWidgetMain->insertTab( tabNtp, tr( "NTP" ) ); 62 TabWidgetMain->insertTab( tabNtp, tr( "NTP" ) );
62 NtpBaseLayout->addWidget( TabWidgetMain, 0, 0 ); 63 NtpBaseLayout->addWidget( TabWidgetMain, 0, 0 );
63 64
64 65
65 66
66 bool advMode = cfg.readBoolEntry("advancedFeatures", false ); 67 bool advMode = cfg.readBoolEntry("advancedFeatures", false );
67 showAdvancedFeatures(advMode); 68 showAdvancedFeatures(advMode);
68 CheckBoxAdvSettings->setChecked( advMode ); 69 CheckBoxAdvSettings->setChecked( advMode );
69 connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ), 70 connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ),
70 SLOT( showAdvancedFeatures( bool ) ) ); 71 SLOT( showAdvancedFeatures( bool ) ) );
71 72
72 makeChannel(); 73 makeChannel();
73 74
74 ntpTimer = new QTimer(this); 75 ntpTimer = new QTimer(this);
75 76
76 ntpProcess = new OProcess( ); 77 ntpProcess = new OProcess( );
77 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), 78 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ),
78 SLOT(slotNtpDelayChanged(int)) ); 79 SLOT(slotNtpDelayChanged(int)) );
79 80
80 ntpSock = new QSocket( this ); 81 ntpSock = new QSocket( this );
81 connect( ntpSock, SIGNAL( error(int) ),SLOT(slotCheckNtp(int)) ); 82 connect( ntpSock, SIGNAL( error(int) ),SLOT(slotCheckNtp(int)) );
82 slotProbeNtpServer(); 83 slotProbeNtpServer();
83 84
84 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), 85 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)),
85 this, SLOT(getNtpOutput(OProcess*,char*,int))); 86 this, SLOT(getNtpOutput(OProcess*,char*,int)));
86 connect ( ntpProcess, SIGNAL(processExited(OProcess*)), 87 connect ( ntpProcess, SIGNAL(processExited(OProcess*)),
87 this, SLOT(ntpFinished(OProcess*))); 88 this, SLOT(ntpFinished(OProcess*)));
88 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotButtonRunNtp())); 89 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotButtonRunNtp()));
89 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); 90 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime()));
90 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); 91 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime()));
91 slotCheckNtp(-1); 92 slotCheckNtp(-1);
92 readLookups(); 93 readLookups();
93} 94}
94 95
95Ntp::~Ntp() 96Ntp::~Ntp()
96{ 97{
97 delete ntpProcess; 98 delete ntpProcess;
98} 99}
99 100
100void Ntp::saveConfig(){ 101void Ntp::saveConfig(){
101 int srvCount = ComboNtpSrv->count(); 102 int srvCount = ComboNtpSrv->count();
102 bool serversChanged = true; 103 bool serversChanged = true;
103 int curSrv = ComboNtpSrv->currentItem(); 104 int curSrv = ComboNtpSrv->currentItem();
104 QString edit = ComboNtpSrv->currentText(); 105 QString edit = ComboNtpSrv->currentText();
105 for (int i = 0; i < srvCount; i++){ 106 for (int i = 0; i < srvCount; i++){
106 if ( edit == ComboNtpSrv->text(i)) serversChanged = false; 107 if ( edit == ComboNtpSrv->text(i)) serversChanged = false;
107 } 108 }
108 if (serversChanged){ 109 if (serversChanged){
109 Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); 110 Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File);
110 ntpSrvs.setGroup("servers"); 111 ntpSrvs.setGroup("servers");
111 ntpSrvs.writeEntry("count", ++srvCount); 112 ntpSrvs.writeEntry("count", ++srvCount);
112 ntpSrvs.setGroup("0"); 113 ntpSrvs.setGroup("0");
113 ntpSrvs.writeEntry( "name", edit ); 114 ntpSrvs.writeEntry( "name", edit );
114 curSrv = 0; 115 curSrv = 0;
115 for (int i = 1; i < srvCount; i++){ 116 for (int i = 1; i < srvCount; i++){
116 qDebug("ntpSrvs[%i/%i]=%s",i,srvCount,ComboNtpSrv->text(i).latin1()); 117 qDebug("ntpSrvs[%i/%i]=%s",i,srvCount,ComboNtpSrv->text(i).latin1());
117 ntpSrvs.setGroup(QString::number(i)); 118 ntpSrvs.setGroup(QString::number(i));
118 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i-1) ); 119 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i-1) );
119 } 120 }
@@ -130,192 +131,196 @@ bool Ntp::ntpDelayElapsed()
130{ 131{
131 Config cfg("ntp",Config::User); 132 Config cfg("ntp",Config::User);
132 cfg.setGroup("lookups"); 133 cfg.setGroup("lookups");
133 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); 134 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
134 if (_lookupDiff < 0) return true; 135 if (_lookupDiff < 0) return true;
135 int i =_lookupDiff - (SpinBoxNtpDelay->value()*60); 136 int i =_lookupDiff - (SpinBoxNtpDelay->value()*60);
136 return i > -60; 137 return i > -60;
137} 138}
138 139
139QString Ntp::getNtpServer() 140QString Ntp::getNtpServer()
140{ 141{
141 return ComboNtpSrv->currentText(); 142 return ComboNtpSrv->currentText();
142} 143}
143 144
144void Ntp::slotButtonRunNtp() 145void Ntp::slotButtonRunNtp()
145{ 146{
146 _interactive = true; 147 _interactive = true;
147 slotRunNtp(); 148 slotRunNtp();
148} 149}
149 150
150void Ntp::slotTimerRunNtp() 151void Ntp::slotTimerRunNtp()
151{ 152{
152 _interactive = false; 153 _interactive = false;
153 slotRunNtp(); 154 slotRunNtp();
154} 155}
155 156
156 157
157void Ntp::slotRunNtp() 158void Ntp::slotRunNtp()
158{ 159{
159 if ( !ntpDelayElapsed() && CheckBoxAdvSettings->isChecked() ) 160 if ( !ntpDelayElapsed() && CheckBoxAdvSettings->isChecked() )
160 { 161 {
161 switch ( 162 switch (
162 QMessageBox::warning(this, tr("Run NTP?"), 163 QMessageBox::warning(this, tr("Run NTP?"),
163 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ 164 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+
164 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+ 165 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+
165 "<br>"+tr("Rerun NTP?"), 166 "<br>"+tr("Rerun NTP?"),
166 QMessageBox::Ok,QMessageBox::Cancel) 167 QMessageBox::Ok,QMessageBox::Cancel)
167 ) { 168 ) {
168 case QMessageBox::Ok: break; 169 case QMessageBox::Ok: break;
169 case QMessageBox::Cancel: return; 170 case QMessageBox::Cancel: return;
170 default: return; 171 default: return;
171 } 172 }
172 } 173 }
173 TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); 174 TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
174 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); 175 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() );
175 176
176 ntpProcess->clearArguments(); 177 ntpProcess->clearArguments();
177 *ntpProcess << "ntpdate" << getNtpServer(); 178 *ntpProcess << "ntpdate" << getNtpServer();
178 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); 179 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
179 if ( !ret ) { 180 if ( !ret ) {
180 QMessageBox::critical(this, tr("ntp error"), 181 QMessageBox::critical(this, tr("ntp error"),
181 tr("Error while getting time form network!")); 182 tr("Error while getting time form network!"));
182 qDebug("Error while executing ntpdate"); 183 qDebug("Error while executing ntpdate");
183 ntpOutPut( tr("Error while executing ntpdate")); 184 ntpOutPut( tr("Error while executing ntpdate"));
184 } 185 }
185} 186}
186 187
187void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) 188void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
188{ 189{
189 if (! proc ) qDebug("Ntp::getNtpOutput OProcess is null"); 190 if (! proc ) qDebug("Ntp::getNtpOutput OProcess is null");
190 QString lineStr, lineStrOld; 191 QString lineStr, lineStrOld;
191 lineStr = buffer; 192 lineStr = buffer;
192 lineStr=lineStr.left(buflen); 193 lineStr=lineStr.left(buflen);
193 if (lineStr!=lineStrOld) 194 if (lineStr!=lineStrOld)
194 { 195 {
195 ntpOutPut(lineStr); 196 ntpOutPut(lineStr);
196 _ntpOutput += lineStr; 197 _ntpOutput += lineStr;
197 } 198 }
198 lineStrOld = lineStr; 199 lineStrOld = lineStr;
199} 200}
200 201
201void Ntp::ntpFinished(OProcess *p) 202void Ntp::ntpFinished(OProcess *p)
202{ 203{
203 qDebug("p->exitStatus() %i",p->exitStatus()); 204 qDebug("p->exitStatus() %i",p->exitStatus());
204 if (p->exitStatus()!=0 || !p->normalExit()) 205 if (p->exitStatus()!=0 || !p->normalExit())
205 { 206 {
206 if ( isVisible() && _interactive ){ 207 if ( isVisible() && _interactive ){
207 QMessageBox::critical(this, tr("ntp error"),tr("Error while getting time form\n server")+getNtpServer()+"\n"+_ntpOutput ); 208 QMessageBox::critical(this, tr("ntp error"),tr("Error while getting time form\n server")+getNtpServer()+"\n"+_ntpOutput );
208 } 209 }
209// slotCheckNtp(-1); 210// slotCheckNtp(-1);
210 return; 211 return;
211 } 212 }
212 213
213 Config cfg("ntp",Config::User); 214 Config cfg("ntp",Config::User);
214 cfg.setGroup("lookups"); 215 cfg.setGroup("lookups");
215 int lastLookup = cfg.readNumEntry("time",0); 216 int lastLookup = cfg.readNumEntry("time",0);
216 int lookupCount = cfg.readNumEntry("count",0); 217 int lookupCount = cfg.readNumEntry("count",0);
217 bool lastNtp = cfg.readBoolEntry("lastNtp",false); 218 bool lastNtp = cfg.readBoolEntry("lastNtp",false);
218 int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); 219 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
219 cfg.writeEntry("time", time); 220 cfg.writeEntry("time", time);
220 221
221 float timeShift = getTimeShift(); 222 float timeShift = getTimeShift();
222 if (timeShift == 0.0) return; 223 if (timeShift == 0.0) return;
223 int secsSinceLast = time - lastLookup; 224 int secsSinceLast = time - lastLookup;
224 TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); 225 TextLabelNewTime->setText(QDateTime::currentDateTime().toString());
225 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); 226 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds"));
227
228 dateButton->setDate( QDate::currentDate() );
229 timeButton->setTime( QDateTime::currentDateTime() );
230
226 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) 231 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value())
227 { 232 {
228 cfg.setGroup("lookup_"+QString::number(lookupCount)); 233 cfg.setGroup("lookup_"+QString::number(lookupCount));
229 lookupCount++; 234 lookupCount++;
230 _shiftPerSec = timeShift / secsSinceLast; 235 _shiftPerSec = timeShift / secsSinceLast;
231 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); 236 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec);
232 cfg.writeEntry("secsSinceLast",secsSinceLast); 237 cfg.writeEntry("secsSinceLast",secsSinceLast);
233 cfg.writeEntry("timeShift",QString::number(timeShift)); 238 cfg.writeEntry("timeShift",QString::number(timeShift));
234 cfg.setGroup("lookups"); 239 cfg.setGroup("lookups");
235 cfg.writeEntry("count",lookupCount); 240 cfg.writeEntry("count",lookupCount);
236 cfg.writeEntry("lastNtp",true); 241 cfg.writeEntry("lastNtp",true);
237 } 242 }
238} 243}
239 244
240 245
241float Ntp::getTimeShift() 246float Ntp::getTimeShift()
242{ 247{
243 QString _offset = "offset"; 248 QString _offset = "offset";
244 QString _sec = "sec"; 249 QString _sec = "sec";
245 QRegExp _reOffset = QRegExp(_offset); 250 QRegExp _reOffset = QRegExp(_offset);
246 QRegExp _reEndOffset = QRegExp(_sec); 251 QRegExp _reEndOffset = QRegExp(_sec);
247 int posOffset = _reOffset.match( _ntpOutput ); 252 int posOffset = _reOffset.match( _ntpOutput );
248 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); 253 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset );
249 posOffset += _offset.length() + 1; 254 posOffset += _offset.length() + 1;
250 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); 255 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1);
251 qDebug("%s", _ntpOutput.latin1()); 256 qDebug("%s", _ntpOutput.latin1());
252 qDebug("diff = >%s<",diff.latin1()); 257 qDebug("diff = >%s<",diff.latin1());
253 return diff.toFloat(); 258 return diff.toFloat();
254} 259}
255 260
256void Ntp::readLookups() 261void Ntp::readLookups()
257{ 262{
258 Config cfg("ntp",Config::User); 263 Config cfg("ntp",Config::User);
259 cfg.setGroup("lookups"); 264 cfg.setGroup("lookups");
260 int lookupCount = cfg.readNumEntry("count",0); 265 int lookupCount = cfg.readNumEntry("count",0);
261 float last, shift, shiftPerSec; 266 float last, shift, shiftPerSec;
262 qDebug("lookupCount = %i",lookupCount); 267 qDebug("lookupCount = %i",lookupCount);
263 TableLookups->setNumCols( 3 ); 268 TableLookups->setNumCols( 3 );
264 TableLookups->setNumRows( lookupCount); 269 TableLookups->setNumRows( lookupCount);
265 TableLookups->horizontalHeader()->setLabel(1,tr("last [h]")); 270 TableLookups->horizontalHeader()->setLabel(1,tr("last [h]"));
266 TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]")); 271 TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]"));
267 TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]")); 272 TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]"));
268 int cw = TableLookups->width()/4; 273 int cw = TableLookups->width()/4;
269 qDebug("column width %i",cw); 274 qDebug("column width %i",cw);
270 cw = 50; 275 cw = 50;
271 TableLookups->setColumnWidth( 0, cw+30 ); 276 TableLookups->setColumnWidth( 0, cw+30 );
272 TableLookups->setColumnWidth( 1, cw ); 277 TableLookups->setColumnWidth( 1, cw );
273 TableLookups->setColumnWidth( 2, cw ); 278 TableLookups->setColumnWidth( 2, cw );
274 TableLookups->sortColumn(0, false, true ); 279 TableLookups->sortColumn(0, false, true );
275 // TableLookups->setSorting( true ); 280 // TableLookups->setSorting( true );
276 _shiftPerSec = 0; 281 _shiftPerSec = 0;
277 for (int i=0; i < lookupCount; i++) 282 for (int i=0; i < lookupCount; i++)
278 { 283 {
279 cfg.setGroup("lookup_"+QString::number(i)); 284 cfg.setGroup("lookup_"+QString::number(i));
280 last = cfg.readEntry("secsSinceLast",0).toFloat(); 285 last = cfg.readEntry("secsSinceLast",0).toFloat();
281 shift = QString(cfg.readEntry("timeShift",0)).toFloat(); 286 shift = QString(cfg.readEntry("timeShift",0)).toFloat();
282 shiftPerSec = shift / last; 287 shiftPerSec = shift / last;
283 qDebug("%i shift %f",i,shiftPerSec); 288 qDebug("%i shift %f",i,shiftPerSec);
284 _shiftPerSec += shiftPerSec; 289 _shiftPerSec += shiftPerSec;
285 TableLookups->setText( i,0,QString::number(shiftPerSec*60*60)); 290 TableLookups->setText( i,0,QString::number(shiftPerSec*60*60));
286 TableLookups->setText( i,2,QString::number(shift)); 291 TableLookups->setText( i,2,QString::number(shift));
287 TableLookups->setText( i,1,QString::number(last/(60*60))); 292 TableLookups->setText( i,1,QString::number(last/(60*60)));
288 } 293 }
289 _shiftPerSec /= lookupCount; 294 _shiftPerSec /= lookupCount;
290 TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h")); 295 TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h"));
291} 296}
292 297
293void Ntp::preditctTime() 298void Ntp::preditctTime()
294{ 299{
295 Config cfg("ntp",Config::User); 300 Config cfg("ntp",Config::User);
296 cfg.setGroup("lookups"); 301 cfg.setGroup("lookups");
297 int lastTime = cfg.readNumEntry("time",0); 302 int lastTime = cfg.readNumEntry("time",0);
298 cfg.writeEntry("lastNtp",true); 303 cfg.writeEntry("lastNtp",true);
299 setenv( "TZ", tz->currentZone(), 1 ); 304 setenv( "TZ", tz->currentZone(), 1 );
300 int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); 305 int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
301 int corr = int((now - lastTime) * _shiftPerSec); 306 int corr = int((now - lastTime) * _shiftPerSec);
302 TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); 307 TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds"));
303 predictedTime = QDateTime::currentDateTime().addSecs(corr); 308 predictedTime = QDateTime::currentDateTime().addSecs(corr);
304 TextLabelPredTime->setText(predictedTime.toString()); 309 TextLabelPredTime->setText(predictedTime.toString());
305// TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); 310// TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>");
306} 311}
307 312
308void Ntp::setPredictTime() 313void Ntp::setPredictTime()
309{ 314{
310 qDebug("Ntp::setPredictTime"); 315 qDebug("Ntp::setPredictTime");
311 preditctTime(); 316 preditctTime();
312 timeButton->setTime( predictedTime ); 317 timeButton->setTime( predictedTime );
313} 318}
314 319
315void Ntp::slotCheckNtp(int i) 320void Ntp::slotCheckNtp(int i)
316{ 321{
317 qDebug(" Ntp::slotCheckNtp(%i)",i); 322 qDebug(" Ntp::slotCheckNtp(%i)",i);
318 if (i == 0) 323 if (i == 0)
319 { 324 {
320// TextLabelMainPredTime->hide(); 325// TextLabelMainPredTime->hide();
321 ButtonSetTime->setText( tr("Get time from network") ); 326 ButtonSetTime->setText( tr("Get time from network") );