summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp16
1 files changed, 10 insertions, 6 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index 551cedc..06d944d 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -1,435 +1,439 @@
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/qcopenvelope_qws.h> 24#include <qpe/qcopenvelope_qws.h>
25#include <sys/time.h> 25#include <sys/time.h>
26#include <time.h> 26#include <time.h>
27#include <stdlib.h> 27#include <stdlib.h>
28 28
29 29
30Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) 30Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
31 : SetDateTime( parent, name, fl ) 31 : SetDateTime( parent, name, fl )
32{ 32{
33 _interactive = false; 33 _interactive = false;
34 Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); 34 Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File);
35 ntpSrvs.setGroup("servers"); 35 ntpSrvs.setGroup("servers");
36 int srvCount = ntpSrvs.readNumEntry("count", 0 ); 36 int srvCount = ntpSrvs.readNumEntry("count", 0 );
37 for (int i = 0; i < srvCount; i++) 37 for (int i = 0; i < srvCount; i++)
38 { 38 {
39 ntpSrvs.setGroup(QString::number(i)); 39 ntpSrvs.setGroup(QString::number(i));
40 ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); 40 ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") );
41 } 41 }
42 if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); 42 if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de"));
43 43
44 Config cfg("ntp",Config::User); 44 Config cfg("ntp",Config::User);
45 cfg.setGroup("settings"); 45 cfg.setGroup("settings");
46 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",720) ); 46 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",720) );
47 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",1440) ); 47 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",1440) );
48 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); 48 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) );
49 49
50 //make tab order 50 //make tab order
51 51
52 TabWidgetMain->removePage( tabMain ); 52 TabWidgetMain->removePage( tabMain );
53 TabWidgetMain->removePage( tabManualSetTime ); 53 TabWidgetMain->removePage( tabManualSetTime );
54 TabWidgetMain->removePage( TabSettings ); 54 TabWidgetMain->removePage( TabSettings );
55 TabWidgetMain->removePage( tabPredict ); 55 TabWidgetMain->removePage( tabPredict );
56 TabWidgetMain->removePage( tabNtp ); 56 TabWidgetMain->removePage( tabNtp );
57 57
58 TabWidgetMain->insertTab( tabMain, tr( "Main" ) ); 58 TabWidgetMain->insertTab( tabMain, tr( "Main" ) );
59 TabWidgetMain->insertTab( TabSettings, tr( "Settings" ) ); 59 TabWidgetMain->insertTab( TabSettings, tr( "Settings" ) );
60 TabWidgetMain->insertTab( tabPredict, tr( "Predict" ) ); 60 TabWidgetMain->insertTab( tabPredict, tr( "Predict" ) );
61 TabWidgetMain->insertTab( tabNtp, tr( "NTP" ) ); 61 TabWidgetMain->insertTab( tabNtp, tr( "NTP" ) );
62 NtpBaseLayout->addWidget( TabWidgetMain, 0, 0 ); 62 NtpBaseLayout->addWidget( TabWidgetMain, 0, 0 );
63 63
64 64
65 65
66 bool advMode = cfg.readBoolEntry("advancedFeatures", false ); 66 bool advMode = cfg.readBoolEntry("advancedFeatures", false );
67 showAdvancedFeatures(advMode); 67 showAdvancedFeatures(advMode);
68 CheckBoxAdvSettings->setChecked( advMode ); 68 CheckBoxAdvSettings->setChecked( advMode );
69 connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ), 69 connect( CheckBoxAdvSettings, SIGNAL( toggled( bool ) ),
70 SLOT( showAdvancedFeatures( bool ) ) ); 70 SLOT( showAdvancedFeatures( bool ) ) );
71 71
72 makeChannel(); 72 makeChannel();
73 73
74 ntpTimer = new QTimer(this); 74 ntpTimer = new QTimer(this);
75 75
76 ntpProcess = new OProcess( ); 76 ntpProcess = new OProcess( );
77 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), 77 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ),
78 SLOT(slotNtpDelayChanged(int)) ); 78 SLOT(slotNtpDelayChanged(int)) );
79 79
80 ntpSock = new QSocket( this ); 80 ntpSock = new QSocket( this );
81 connect( ntpSock, SIGNAL( error(int) ),SLOT(slotCheckNtp(int)) ); 81 connect( ntpSock, SIGNAL( error(int) ),SLOT(slotCheckNtp(int)) );
82 slotProbeNtpServer(); 82 slotProbeNtpServer();
83 83
84 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), 84 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)),
85 this, SLOT(getNtpOutput(OProcess*,char*,int))); 85 this, SLOT(getNtpOutput(OProcess*,char*,int)));
86 connect ( ntpProcess, SIGNAL(processExited(OProcess*)), 86 connect ( ntpProcess, SIGNAL(processExited(OProcess*)),
87 this, SLOT(ntpFinished(OProcess*))); 87 this, SLOT(ntpFinished(OProcess*)));
88 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotButtonRunNtp())); 88 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotButtonRunNtp()));
89 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); 89 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime()));
90 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); 90 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime()));
91 slotCheckNtp(-1); 91 slotCheckNtp(-1);
92 readLookups(); 92 readLookups();
93} 93}
94 94
95Ntp::~Ntp() 95Ntp::~Ntp()
96{ 96{
97 delete ntpProcess; 97 delete ntpProcess;
98} 98}
99 99
100void Ntp::saveConfig(){ 100void Ntp::saveConfig(){
101 int srvCount = ComboNtpSrv->count(); 101 int srvCount = ComboNtpSrv->count();
102 bool serversChanged = true; 102 bool serversChanged = true;
103 int curSrv = ComboNtpSrv->currentItem();
103 QString edit = ComboNtpSrv->currentText(); 104 QString edit = ComboNtpSrv->currentText();
104 for (int i = 0; i < srvCount; i++){ 105 for (int i = 0; i < srvCount; i++){
105 if ( edit == ComboNtpSrv->text(i)) serversChanged = false; 106 if ( edit == ComboNtpSrv->text(i)) serversChanged = false;
106 } 107 }
107 if (serversChanged){ 108 if (serversChanged){
108 Config ntpSrvs("/etc/ntpservers",Config::File); 109 Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File);
109 ntpSrvs.setGroup("servers"); 110 ntpSrvs.setGroup("servers");
110 ntpSrvs.writeEntry("count", srvCount); 111 ntpSrvs.writeEntry("count", ++srvCount);
111 for (int i = 0; i < srvCount; i++){ 112 ntpSrvs.setGroup("0");
113 ntpSrvs.writeEntry( "name", edit );
114 curSrv = 0;
115 for (int i = 1; i < srvCount; i++){
112 qDebug("ntpSrvs[%i/%i]=%s",i,srvCount,ComboNtpSrv->text(i).latin1()); 116 qDebug("ntpSrvs[%i/%i]=%s",i,srvCount,ComboNtpSrv->text(i).latin1());
113 ntpSrvs.setGroup(QString::number(i)); 117 ntpSrvs.setGroup(QString::number(i));
114 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); 118 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i-1) );
115 } 119 }
116 } 120 }
117 Config cfg("ntp",Config::User); 121 Config cfg("ntp",Config::User);
118 cfg.setGroup("settings"); 122 cfg.setGroup("settings");
119 cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); 123 cfg.writeEntry("ntpServer", curSrv );
120 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); 124 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() );
121 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); 125 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() );
122 cfg.writeEntry( "advancedFeatures", CheckBoxAdvSettings->isChecked() ); 126 cfg.writeEntry( "advancedFeatures", CheckBoxAdvSettings->isChecked() );
123} 127}
124 128
125bool Ntp::ntpDelayElapsed() 129bool Ntp::ntpDelayElapsed()
126{ 130{
127 Config cfg("ntp",Config::User); 131 Config cfg("ntp",Config::User);
128 cfg.setGroup("lookups"); 132 cfg.setGroup("lookups");
129 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); 133 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
130 if (_lookupDiff < 0) return true; 134 if (_lookupDiff < 0) return true;
131 int i =_lookupDiff - (SpinBoxNtpDelay->value()*60); 135 int i =_lookupDiff - (SpinBoxNtpDelay->value()*60);
132 return i > -60; 136 return i > -60;
133} 137}
134 138
135QString Ntp::getNtpServer() 139QString Ntp::getNtpServer()
136{ 140{
137 return ComboNtpSrv->currentText(); 141 return ComboNtpSrv->currentText();
138} 142}
139 143
140void Ntp::slotButtonRunNtp() 144void Ntp::slotButtonRunNtp()
141{ 145{
142 _interactive = true; 146 _interactive = true;
143 slotRunNtp(); 147 slotRunNtp();
144} 148}
145 149
146void Ntp::slotTimerRunNtp() 150void Ntp::slotTimerRunNtp()
147{ 151{
148 _interactive = false; 152 _interactive = false;
149 slotRunNtp(); 153 slotRunNtp();
150} 154}
151 155
152 156
153void Ntp::slotRunNtp() 157void Ntp::slotRunNtp()
154{ 158{
155 if ( !ntpDelayElapsed() && CheckBoxAdvSettings->isChecked() ) 159 if ( !ntpDelayElapsed() && CheckBoxAdvSettings->isChecked() )
156 { 160 {
157 switch ( 161 switch (
158 QMessageBox::warning(this, tr("Run NTP?"), 162 QMessageBox::warning(this, tr("Run NTP?"),
159 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ 163 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+
160 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+ 164 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+
161 "<br>"+tr("Rerun NTP?"), 165 "<br>"+tr("Rerun NTP?"),
162 QMessageBox::Ok,QMessageBox::Cancel) 166 QMessageBox::Ok,QMessageBox::Cancel)
163 ) { 167 ) {
164 case QMessageBox::Ok: break; 168 case QMessageBox::Ok: break;
165 case QMessageBox::Cancel: return; 169 case QMessageBox::Cancel: return;
166 default: return; 170 default: return;
167 } 171 }
168 } 172 }
169 TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); 173 TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
170 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); 174 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() );
171 175
172 ntpProcess->clearArguments(); 176 ntpProcess->clearArguments();
173 *ntpProcess << "ntpdate" << getNtpServer(); 177 *ntpProcess << "ntpdate" << getNtpServer();
174 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); 178 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
175 if ( !ret ) { 179 if ( !ret ) {
176 QMessageBox::critical(this, tr("ntp error"), 180 QMessageBox::critical(this, tr("ntp error"),
177 tr("Error while getting time form network!")); 181 tr("Error while getting time form network!"));
178 qDebug("Error while executing ntpdate"); 182 qDebug("Error while executing ntpdate");
179 ntpOutPut( tr("Error while executing ntpdate")); 183 ntpOutPut( tr("Error while executing ntpdate"));
180 } 184 }
181} 185}
182 186
183void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) 187void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
184{ 188{
185 if (! proc ) qDebug("Ntp::getNtpOutput OProcess is null"); 189 if (! proc ) qDebug("Ntp::getNtpOutput OProcess is null");
186 QString lineStr, lineStrOld; 190 QString lineStr, lineStrOld;
187 lineStr = buffer; 191 lineStr = buffer;
188 lineStr=lineStr.left(buflen); 192 lineStr=lineStr.left(buflen);
189 if (lineStr!=lineStrOld) 193 if (lineStr!=lineStrOld)
190 { 194 {
191 ntpOutPut(lineStr); 195 ntpOutPut(lineStr);
192 _ntpOutput += lineStr; 196 _ntpOutput += lineStr;
193 } 197 }
194 lineStrOld = lineStr; 198 lineStrOld = lineStr;
195} 199}
196 200
197void Ntp::ntpFinished(OProcess *p) 201void Ntp::ntpFinished(OProcess *p)
198{ 202{
199 qDebug("p->exitStatus() %i",p->exitStatus()); 203 qDebug("p->exitStatus() %i",p->exitStatus());
200 if (p->exitStatus()!=0 || !p->normalExit()) 204 if (p->exitStatus()!=0 || !p->normalExit())
201 { 205 {
202 if ( isVisible() && _interactive ){ 206 if ( isVisible() && _interactive ){
203 QMessageBox::critical(this, tr("ntp error"),tr("Error while getting time form\n server")+getNtpServer()+"\n"+_ntpOutput ); 207 QMessageBox::critical(this, tr("ntp error"),tr("Error while getting time form\n server")+getNtpServer()+"\n"+_ntpOutput );
204 } 208 }
205// slotCheckNtp(-1); 209// slotCheckNtp(-1);
206 return; 210 return;
207 } 211 }
208 212
209 Config cfg("ntp",Config::User); 213 Config cfg("ntp",Config::User);
210 cfg.setGroup("lookups"); 214 cfg.setGroup("lookups");
211 int lastLookup = cfg.readNumEntry("time",0); 215 int lastLookup = cfg.readNumEntry("time",0);
212 int lookupCount = cfg.readNumEntry("count",0); 216 int lookupCount = cfg.readNumEntry("count",0);
213 bool lastNtp = cfg.readBoolEntry("lastNtp",false); 217 bool lastNtp = cfg.readBoolEntry("lastNtp",false);
214 int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); 218 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
215 cfg.writeEntry("time", time); 219 cfg.writeEntry("time", time);
216 220
217 float timeShift = getTimeShift(); 221 float timeShift = getTimeShift();
218 if (timeShift == 0.0) return; 222 if (timeShift == 0.0) return;
219 int secsSinceLast = time - lastLookup; 223 int secsSinceLast = time - lastLookup;
220 TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); 224 TextLabelNewTime->setText(QDateTime::currentDateTime().toString());
221 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); 225 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds"));
222 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) 226 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value())
223 { 227 {
224 cfg.setGroup("lookup_"+QString::number(lookupCount)); 228 cfg.setGroup("lookup_"+QString::number(lookupCount));
225 lookupCount++; 229 lookupCount++;
226 _shiftPerSec = timeShift / secsSinceLast; 230 _shiftPerSec = timeShift / secsSinceLast;
227 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); 231 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec);
228 cfg.writeEntry("secsSinceLast",secsSinceLast); 232 cfg.writeEntry("secsSinceLast",secsSinceLast);
229 cfg.writeEntry("timeShift",QString::number(timeShift)); 233 cfg.writeEntry("timeShift",QString::number(timeShift));
230 cfg.setGroup("lookups"); 234 cfg.setGroup("lookups");
231 cfg.writeEntry("count",lookupCount); 235 cfg.writeEntry("count",lookupCount);
232 cfg.writeEntry("lastNtp",true); 236 cfg.writeEntry("lastNtp",true);
233 } 237 }
234} 238}
235 239
236 240
237float Ntp::getTimeShift() 241float Ntp::getTimeShift()
238{ 242{
239 QString _offset = "offset"; 243 QString _offset = "offset";
240 QString _sec = "sec"; 244 QString _sec = "sec";
241 QRegExp _reOffset = QRegExp(_offset); 245 QRegExp _reOffset = QRegExp(_offset);
242 QRegExp _reEndOffset = QRegExp(_sec); 246 QRegExp _reEndOffset = QRegExp(_sec);
243 int posOffset = _reOffset.match( _ntpOutput ); 247 int posOffset = _reOffset.match( _ntpOutput );
244 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); 248 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset );
245 posOffset += _offset.length() + 1; 249 posOffset += _offset.length() + 1;
246 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); 250 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1);
247 qDebug("%s", _ntpOutput.latin1()); 251 qDebug("%s", _ntpOutput.latin1());
248 qDebug("diff = >%s<",diff.latin1()); 252 qDebug("diff = >%s<",diff.latin1());
249 return diff.toFloat(); 253 return diff.toFloat();
250} 254}
251 255
252void Ntp::readLookups() 256void Ntp::readLookups()
253{ 257{
254 Config cfg("ntp",Config::User); 258 Config cfg("ntp",Config::User);
255 cfg.setGroup("lookups"); 259 cfg.setGroup("lookups");
256 int lookupCount = cfg.readNumEntry("count",0); 260 int lookupCount = cfg.readNumEntry("count",0);
257 float last, shift, shiftPerSec; 261 float last, shift, shiftPerSec;
258 qDebug("lookupCount = %i",lookupCount); 262 qDebug("lookupCount = %i",lookupCount);
259 TableLookups->setNumCols( 3 ); 263 TableLookups->setNumCols( 3 );
260 TableLookups->setNumRows( lookupCount); 264 TableLookups->setNumRows( lookupCount);
261 TableLookups->horizontalHeader()->setLabel(1,tr("last [h]")); 265 TableLookups->horizontalHeader()->setLabel(1,tr("last [h]"));
262 TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]")); 266 TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]"));
263 TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]")); 267 TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]"));
264 int cw = TableLookups->width()/4; 268 int cw = TableLookups->width()/4;
265 qDebug("column width %i",cw); 269 qDebug("column width %i",cw);
266 cw = 50; 270 cw = 50;
267 TableLookups->setColumnWidth( 0, cw+30 ); 271 TableLookups->setColumnWidth( 0, cw+30 );
268 TableLookups->setColumnWidth( 1, cw ); 272 TableLookups->setColumnWidth( 1, cw );
269 TableLookups->setColumnWidth( 2, cw ); 273 TableLookups->setColumnWidth( 2, cw );
270 TableLookups->sortColumn(0, false, true ); 274 TableLookups->sortColumn(0, false, true );
271 // TableLookups->setSorting( true ); 275 // TableLookups->setSorting( true );
272 _shiftPerSec = 0; 276 _shiftPerSec = 0;
273 for (int i=0; i < lookupCount; i++) 277 for (int i=0; i < lookupCount; i++)
274 { 278 {
275 cfg.setGroup("lookup_"+QString::number(i)); 279 cfg.setGroup("lookup_"+QString::number(i));
276 last = cfg.readEntry("secsSinceLast",0).toFloat(); 280 last = cfg.readEntry("secsSinceLast",0).toFloat();
277 shift = QString(cfg.readEntry("timeShift",0)).toFloat(); 281 shift = QString(cfg.readEntry("timeShift",0)).toFloat();
278 shiftPerSec = shift / last; 282 shiftPerSec = shift / last;
279 qDebug("%i shift %f",i,shiftPerSec); 283 qDebug("%i shift %f",i,shiftPerSec);
280 _shiftPerSec += shiftPerSec; 284 _shiftPerSec += shiftPerSec;
281 TableLookups->setText( i,0,QString::number(shiftPerSec*60*60)); 285 TableLookups->setText( i,0,QString::number(shiftPerSec*60*60));
282 TableLookups->setText( i,2,QString::number(shift)); 286 TableLookups->setText( i,2,QString::number(shift));
283 TableLookups->setText( i,1,QString::number(last/(60*60))); 287 TableLookups->setText( i,1,QString::number(last/(60*60)));
284 } 288 }
285 _shiftPerSec /= lookupCount; 289 _shiftPerSec /= lookupCount;
286 TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h")); 290 TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h"));
287} 291}
288 292
289void Ntp::preditctTime() 293void Ntp::preditctTime()
290{ 294{
291 Config cfg("ntp",Config::User); 295 Config cfg("ntp",Config::User);
292 cfg.setGroup("lookups"); 296 cfg.setGroup("lookups");
293 int lastTime = cfg.readNumEntry("time",0); 297 int lastTime = cfg.readNumEntry("time",0);
294 cfg.writeEntry("lastNtp",true); 298 cfg.writeEntry("lastNtp",true);
295 setenv( "TZ", tz->currentZone(), 1 ); 299 setenv( "TZ", tz->currentZone(), 1 );
296 int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); 300 int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
297 int corr = int((now - lastTime) * _shiftPerSec); 301 int corr = int((now - lastTime) * _shiftPerSec);
298 TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); 302 TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds"));
299 predictedTime = QDateTime::currentDateTime().addSecs(corr); 303 predictedTime = QDateTime::currentDateTime().addSecs(corr);
300 TextLabelPredTime->setText(predictedTime.toString()); 304 TextLabelPredTime->setText(predictedTime.toString());
301// TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); 305// TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>");
302} 306}
303 307
304void Ntp::setPredictTime() 308void Ntp::setPredictTime()
305{ 309{
306 qDebug("Ntp::setPredictTime"); 310 qDebug("Ntp::setPredictTime");
307 preditctTime(); 311 preditctTime();
308 timeButton->setTime( predictedTime ); 312 timeButton->setTime( predictedTime );
309} 313}
310 314
311void Ntp::slotCheckNtp(int i) 315void Ntp::slotCheckNtp(int i)
312{ 316{
313 qDebug(" Ntp::slotCheckNtp(%i)",i); 317 qDebug(" Ntp::slotCheckNtp(%i)",i);
314 if (i == 0) 318 if (i == 0)
315 { 319 {
316// TextLabelMainPredTime->hide(); 320// TextLabelMainPredTime->hide();
317 ButtonSetTime->setText( tr("Get time from network") ); 321 ButtonSetTime->setText( tr("Get time from network") );
318 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotButtonRunNtp()) ); 322 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotButtonRunNtp()) );
319 if ( ntpDelayElapsed() ) 323 if ( ntpDelayElapsed() )
320 { 324 {
321 slotRunNtp(); 325 slotRunNtp();
322 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); 326 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) );
323 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotTimerRunNtp()) ); 327 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotTimerRunNtp()) );
324 }else{ 328 }else{
325 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotTimerRunNtp()) ); 329 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotTimerRunNtp()) );
326 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); 330 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
327 } 331 }
328 }else{ 332 }else{
329 preditctTime(); 333 preditctTime();
330 ButtonSetTime->setText( tr("Set predicted time: ")+predictedTime.toString() ); 334 ButtonSetTime->setText( tr("Set predicted time: ")+predictedTime.toString() );
331 if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); 335 if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer());
332 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); 336 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) );
333 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); 337 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
334 } 338 }
335} 339}
336 340
337void Ntp::slotProbeNtpServer() 341void Ntp::slotProbeNtpServer()
338{ 342{
339 ntpSock->connectToHost( getNtpServer() ,123); 343 ntpSock->connectToHost( getNtpServer() ,123);
340} 344}
341 345
342void Ntp::slotNtpDelayChanged(int delay) 346void Ntp::slotNtpDelayChanged(int delay)
343{ 347{
344 ntpTimer->changeInterval( delay*1000*60 ); 348 ntpTimer->changeInterval( delay*1000*60 );
345} 349}
346 350
347void Ntp::ntpOutPut(QString out) 351void Ntp::ntpOutPut(QString out)
348{ 352{
349 353
350 MultiLineEditntpOutPut->append(out); 354 MultiLineEditntpOutPut->append(out);
351 MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); 355 MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE);
352} 356}
353 357
354 358
355void Ntp::makeChannel() 359void Ntp::makeChannel()
356 { 360 {
357 channel = new QCopChannel( "QPE/Application/netsystemtime", this ); 361 channel = new QCopChannel( "QPE/Application/netsystemtime", this );
358 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), 362 connect( channel, SIGNAL(received(const QCString&, const QByteArray&)),
359 this, SLOT(receive(const QCString&, const QByteArray&)) ); 363 this, SLOT(receive(const QCString&, const QByteArray&)) );
360} 364}
361 365
362 366
363 367
364void Ntp::receive(const QCString &msg, const QByteArray &arg) 368void Ntp::receive(const QCString &msg, const QByteArray &arg)
365{ 369{
366 qDebug("QCop(Ntp) "+msg+" "+QCString(arg)); 370 qDebug("QCop(Ntp) "+msg+" "+QCString(arg));
367 if ( msg == "ntpLookup(QString)" ) 371 if ( msg == "ntpLookup(QString)" )
368 { 372 {
369 _interactive = false; 373 _interactive = false;
370 slotRunNtp(); 374 slotRunNtp();
371 } 375 }
372 if ( msg == "setPredictedTime(QString)" ) 376 if ( msg == "setPredictedTime(QString)" )
373 { 377 {
374 setPredictTime(); 378 setPredictTime();
375 }else{ 379 }else{
376 qDebug("Ntp::receive: Huh what do ya want"); 380 qDebug("Ntp::receive: Huh what do ya want");
377 } 381 }
378} 382}
379 383
380void Ntp::setDocument(const QString &fileName) 384void Ntp::setDocument(const QString &fileName)
381{ 385{
382 qDebug("Ntp::setDocument( %s )",fileName.latin1()); 386 qDebug("Ntp::setDocument( %s )",fileName.latin1());
383} 387}
384 388
385void Ntp::showAdvancedFeatures(bool advMode) 389void Ntp::showAdvancedFeatures(bool advMode)
386{ 390{
387 if (advMode) { 391 if (advMode) {
388 392
389 TabWidgetMain->addTab( tabPredict, tr( "Predict" ) ); 393 TabWidgetMain->addTab( tabPredict, tr( "Predict" ) );
390 TabWidgetMain->addTab( tabNtp, tr( "NTP" ) ); 394 TabWidgetMain->addTab( tabNtp, tr( "NTP" ) );
391 TextLabel1_2_2->show(); 395 TextLabel1_2_2->show();
392 TextLabel2_3->show(); 396 TextLabel2_3->show();
393 TextLabel3_3_2->show(); 397 TextLabel3_3_2->show();
394 TextLabel1_2->show(); 398 TextLabel1_2->show();
395 SpinBoxMinLookupDelay->show(); 399 SpinBoxMinLookupDelay->show();
396 TextLabel2->show(); 400 TextLabel2->show();
397 TextLabel3_3->show(); 401 TextLabel3_3->show();
398 SpinBoxNtpDelay->show(); 402 SpinBoxNtpDelay->show();
399 Line1->show(); 403 Line1->show();
400 }else{ 404 }else{
401 TabWidgetMain->removePage( tabPredict ); 405 TabWidgetMain->removePage( tabPredict );
402 TabWidgetMain->removePage( tabNtp ); 406 TabWidgetMain->removePage( tabNtp );
403 TextLabel1_2_2->hide(); 407 TextLabel1_2_2->hide();
404 TextLabel2_3->hide(); 408 TextLabel2_3->hide();
405 TextLabel3_3_2->hide(); 409 TextLabel3_3_2->hide();
406 TextLabel1_2->hide(); 410 TextLabel1_2->hide();
407 SpinBoxMinLookupDelay->hide(); 411 SpinBoxMinLookupDelay->hide();
408 TextLabel2->hide(); 412 TextLabel2->hide();
409 TextLabel3_3->hide(); 413 TextLabel3_3->hide();
410 SpinBoxNtpDelay->hide(); 414 SpinBoxNtpDelay->hide();
411 Line1->hide(); 415 Line1->hide();
412 }; 416 };
413 TabWidgetMain->show(); 417 TabWidgetMain->show();
414} 418}
415 419
416 420
417void Ntp::accept( ){ 421void Ntp::accept( ){
418 qDebug("saving"); 422 qDebug("saving");
419 //SetTimeDate 423 //SetTimeDate
420 commitTime(); 424 commitTime();
421 writeSettings(); 425 writeSettings();
422 updateSystem(); 426 updateSystem();
423 // Ntp 427 // Ntp
424 saveConfig(); 428 saveConfig();
425 qApp->quit(); 429 qApp->quit();
426} 430}
427 431
428void Ntp::reject( ){ 432void Ntp::reject( ){
429 qDebug("_oldTimeZone %s",_oldTimeZone.latin1()); 433 qDebug("_oldTimeZone %s",_oldTimeZone.latin1());
430 if (!_oldTimeZone.isEmpty()){ 434 if (!_oldTimeZone.isEmpty()){
431 qDebug("reverting timezone"); 435 qDebug("reverting timezone");
432 tzChange(_oldTimeZone); 436 tzChange(_oldTimeZone);
433 commitTime(); 437 commitTime();
434 } 438 }
435} \ No newline at end of file 439}