summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp58
-rw-r--r--noncore/settings/netsystemtime/ntp.h4
-rw-r--r--noncore/settings/netsystemtime/ntpbase.ui4
-rw-r--r--noncore/settings/netsystemtime/opie-netsystemtime.control2
-rw-r--r--noncore/settings/netsystemtime/settime.cpp2
5 files changed, 41 insertions, 29 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index 364609d..bcbf7a1 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -1,272 +1,282 @@
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
24Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) 24Ntp::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); 40 // _maxOffset = cfg.readNumEntry("maxOffset",5);
41// _minLookupDiff = cfg.readNumEntry("minLookupDiff",10); 41// _minLookupDiff = cfg.readNumEntry("minLookupDiff",10);
42 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) ); 42 SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) );
43 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) ); 43 SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) );
44 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); 44 ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) );
45 45
46 ntpTimer = new QTimer(this); 46 ntpTimer = new QTimer(this);
47 ntpTimer->start(SpinBoxNtpDelay->value()*100); 47 ntpTimer->start(SpinBoxNtpDelay->value()*1000*60);
48 48
49 ntpProcess = new OProcess( ); 49 ntpProcess = new OProcess( );
50 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), 50 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ),
51 SLOT(slotNtpDelayChanged(int)) ); 51 SLOT(slotNtpDelayChanged(int)) );
52 52
53 ntpSock = new QSocket( this ); 53 ntpSock = new QSocket( this );
54 connect( ntpSock, SIGNAL( error(int) ), 54 connect( ntpSock, SIGNAL( error(int) ),
55 SLOT(slotCheckNtp(int)) ); 55 SLOT(slotCheckNtp(int)) );
56 slotProbeNtpServer(); 56 slotProbeNtpServer();
57 57
58 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), 58 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)),
59 this, SLOT(getNtpOutput(OProcess*,char*,int))); 59 this, SLOT(getNtpOutput(OProcess*,char*,int)));
60 connect ( ntpProcess, SIGNAL(processExited(OProcess*)), 60 connect ( ntpProcess, SIGNAL(processExited(OProcess*)),
61 this, SLOT(ntpFinished(OProcess*))); 61 this, SLOT(ntpFinished(OProcess*)));
62 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); 62 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp()));
63 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); 63 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime()));
64 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); 64 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime()));
65 slotCheckNtp(-1); 65 slotCheckNtp(-1);
66 readLookups(); 66 readLookups();
67} 67}
68 68
69Ntp::~Ntp() 69Ntp::~Ntp()
70{ 70{
71 delete ntpProcess; 71 delete ntpProcess;
72 Config ntpSrvs("/etc/ntpservers",Config::File); 72 Config ntpSrvs("/etc/ntpservers",Config::File);
73 ntpSrvs.setGroup("servers"); 73 ntpSrvs.setGroup("servers");
74 int srvCount = ComboNtpSrv->count(); 74 int srvCount = ComboNtpSrv->count();
75 ntpSrvs.writeEntry("count", srvCount); 75 ntpSrvs.writeEntry("count", srvCount);
76 for (int i = 0; i < srvCount; i++) 76 for (int i = 0; i < srvCount; i++)
77 { 77 {
78 ntpSrvs.setGroup(QString::number(i)); 78 ntpSrvs.setGroup(QString::number(i));
79 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); 79 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) );
80 } 80 }
81 Config cfg("ntp",Config::User); 81 Config cfg("ntp",Config::User);
82 cfg.setGroup("settings"); 82 cfg.setGroup("settings");
83 cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); 83 cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem());
84 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); 84 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() );
85 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); 85 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() );
86} 86}
87 87
88 88bool Ntp::ntpDelayElapsed()
89void Ntp::slotRunNtp()
90{ 89{
91 Config cfg("ntp",Config::User); 90 Config cfg("ntp",Config::User);
92 cfg.setGroup("lookups"); 91 cfg.setGroup("lookups");
93 int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); 92 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
93 return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60;
94}
94 95
95 if ( lookupDiff < SpinBoxNtpDelay->value()*60 ) 96QString Ntp::getNtpServer()
97{
98 return ComboNtpSrv->currentText();
99}
100
101void Ntp::slotRunNtp()
102{
103 if ( !ntpDelayElapsed() )
96 { 104 {
97 switch ( 105 switch (
98 QMessageBox::warning(this, tr("Run ntp?"), 106 QMessageBox::warning(this, tr("Run NTP?"),
99 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ 107 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+
100 QString::number(lookupDiff%60)+tr(" minutes elapsed since last loopup.")+ 108 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+
101 "<br>"+tr("Rerun ntp?"), 109 "<br>"+tr("Rerun NTP?"),
102 QMessageBox::Ok,QMessageBox::Cancel) 110 QMessageBox::Ok,QMessageBox::Cancel)
103 ) { 111 ) {
104 case QMessageBox::Ok: break; 112 case QMessageBox::Ok: break;
105 case QMessageBox::Cancel: return; 113 case QMessageBox::Cancel: return;
106 default: return; 114 default: return;
107 } 115 }
108 } 116 }
109 TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); 117 TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
110 MultiLineEditntpOutPut->append( "\n"+tr("Running:")+"\nntpdate "+ ComboNtpSrv->currentText()+"\n"); 118 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() );
111 ntpProcess->clearArguments(); 119 ntpProcess->clearArguments();
112 *ntpProcess << "ntpdate" << ComboNtpSrv->currentText(); 120 *ntpProcess << "ntpdate" << getNtpServer();
113 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); 121 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
114 if ( !ret ) { 122 if ( !ret ) {
115 qDebug("Error while executing ntp"); 123 qDebug("Error while executing ntpdate");
124 ntpOutPut( tr("Error while executing ntpdate"));
116 } 125 }
117} 126}
118 127
119void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) 128void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
120{ 129{
121 QString lineStr, lineStrOld; 130 QString lineStr, lineStrOld;
122 lineStr = buffer; 131 lineStr = buffer;
123 lineStr=lineStr.left(buflen); 132 lineStr=lineStr.left(buflen);
124 if (lineStr!=lineStrOld) 133 if (lineStr!=lineStrOld)
125 { 134 {
126 MultiLineEditntpOutPut->append(lineStr); 135 ntpOutPut(lineStr);
127 _ntpOutput += lineStr; 136 _ntpOutput += lineStr;
128 } 137 }
129 lineStrOld = lineStr; 138 lineStrOld = lineStr;
130} 139}
131 140
132void Ntp::ntpFinished(OProcess*) 141void Ntp::ntpFinished(OProcess*)
133{ 142{
134 Config cfg("ntp",Config::User); 143 Config cfg("ntp",Config::User);
135 cfg.setGroup("lookups"); 144 cfg.setGroup("lookups");
136 int lastLookup = cfg.readNumEntry("time",0); 145 int lastLookup = cfg.readNumEntry("time",0);
137 int lookupCount = cfg.readNumEntry("count",-1); 146 int lookupCount = cfg.readNumEntry("count",-1);
138 int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); 147 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
139 cfg.writeEntry("time", time); 148 cfg.writeEntry("time", time);
140 cfg.setGroup("correction"); 149 cfg.setGroup("correction");
141 cfg.writeEntry("time", time); 150 cfg.writeEntry("time", time);
142 151
143 float timeShift = getTimeShift(); 152 float timeShift = getTimeShift();
144 if (timeShift == 0.0) return; 153 if (timeShift == 0.0) return;
145 int secsSinceLast = time - lastLookup; 154 int secsSinceLast = time - lastLookup;
146 TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); 155 TextLabelNewTime->setText(QDateTime::currentDateTime().toString());
147 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); 156 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds"));
148 if ( lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) 157 if ( lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value())
149 { 158 {
150 lookupCount++; 159 lookupCount++;
151 cfg.writeEntry("count",lookupCount); 160 cfg.writeEntry("count",lookupCount);
152 cfg.setGroup("lookup_"+QString::number(lookupCount)); 161 cfg.setGroup("lookup_"+QString::number(lookupCount));
153 _shiftPerSec = timeShift / secsSinceLast; 162 _shiftPerSec = timeShift / secsSinceLast;
154// float nextCorr = _maxOffset / _shiftPerSec;
155 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); 163 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec);
156 cfg.writeEntry("secsSinceLast",secsSinceLast); 164 cfg.writeEntry("secsSinceLast",secsSinceLast);
157 cfg.writeEntry("timeShift",QString::number(timeShift)); 165 cfg.writeEntry("timeShift",QString::number(timeShift));
158 } 166 }
159} 167}
160 168
161 169
162float Ntp::getTimeShift() 170float Ntp::getTimeShift()
163{ 171{
164 QString _offset = "offset"; 172 QString _offset = "offset";
165 QString _sec = "sec"; 173 QString _sec = "sec";
166 QRegExp _reOffset = QRegExp(_offset); 174 QRegExp _reOffset = QRegExp(_offset);
167 QRegExp _reEndOffset = QRegExp(_sec); 175 QRegExp _reEndOffset = QRegExp(_sec);
168 int posOffset = _reOffset.match( _ntpOutput ); 176 int posOffset = _reOffset.match( _ntpOutput );
169 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); 177 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset );
170 posOffset += _offset.length() + 1; 178 posOffset += _offset.length() + 1;
171 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); 179 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1);
172 qDebug("%s", _ntpOutput.latin1()); 180 qDebug("%s", _ntpOutput.latin1());
173 qDebug("diff = >%s<",diff.latin1()); 181 qDebug("diff = >%s<",diff.latin1());
174 return diff.toFloat(); 182 return diff.toFloat();
175} 183}
176 184
177void Ntp::readLookups() 185void Ntp::readLookups()
178{ 186{
179 Config cfg("ntp",Config::User); 187 Config cfg("ntp",Config::User);
180 cfg.setGroup("lookups"); 188 cfg.setGroup("lookups");
181 int lookupCount = cfg.readNumEntry("count",-1); 189 int lookupCount = cfg.readNumEntry("count",-1);
182 float last, shift, shiftPerSec; 190 float last, shift, shiftPerSec;
183 qDebug("lookupCount = %i",lookupCount); 191 qDebug("lookupCount = %i",lookupCount);
184 TableLookups->setNumCols( 3 ); 192 TableLookups->setNumCols( 3 );
185 TableLookups->setNumRows( lookupCount); 193 TableLookups->setNumRows( lookupCount);
186 TableLookups->horizontalHeader()->setLabel(1,"secsSinceLast"); 194 TableLookups->horizontalHeader()->setLabel(1,"secsSinceLast");
187 TableLookups->horizontalHeader()->setLabel(2,"timeShift"); 195 TableLookups->horizontalHeader()->setLabel(2,"timeShift");
188 TableLookups->horizontalHeader()->setLabel(0,"shift/s"); 196 TableLookups->horizontalHeader()->setLabel(0,"shift/s");
189 int cw = 50;//TableLookups->width()/4; 197 int cw = 50;//TableLookups->width()/4;
190 qDebug("column width %i",cw); 198 qDebug("column width %i",cw);
191 TableLookups->setColumnWidth( 0, cw+30 ); 199 TableLookups->setColumnWidth( 0, cw+30 );
192 TableLookups->setColumnWidth( 1, cw ); 200 TableLookups->setColumnWidth( 1, cw );
193 TableLookups->setColumnWidth( 2, cw ); 201 TableLookups->setColumnWidth( 2, cw );
194 TableLookups->sortColumn(0, false, true ); 202 TableLookups->sortColumn(0, false, true );
195 // TableLookups->setSorting( true ); 203 // TableLookups->setSorting( true );
196 for (int i=0; i < lookupCount; i++) 204 for (int i=0; i < lookupCount; i++)
197 { 205 {
198 cfg.setGroup("lookup_"+QString::number(i)); 206 cfg.setGroup("lookup_"+QString::number(i));
199 last = cfg.readEntry("secsSinceLast",0).toFloat(); 207 last = cfg.readEntry("secsSinceLast",0).toFloat();
200 shift = QString(cfg.readEntry("timeShift",0)).toFloat(); 208 shift = QString(cfg.readEntry("timeShift",0)).toFloat();
201 // qDebug("%i last %f",i,last); 209 // qDebug("%i last %f",i,last);
202 // qDebug("%i shift %f",i,shift); 210 // qDebug("%i shift %f",i,shift);
203 shiftPerSec = shift / last; 211 shiftPerSec = shift / last;
204 _shiftPerSec += shiftPerSec; 212 _shiftPerSec += shiftPerSec;
205 TableLookups->setText( i,0,QString::number(shiftPerSec)); 213 TableLookups->setText( i,0,QString::number(shiftPerSec));
206 TableLookups->setText( i,2,QString::number(shift)); 214 TableLookups->setText( i,2,QString::number(shift));
207 TableLookups->setText( i,1,QString::number(last)); 215 TableLookups->setText( i,1,QString::number(last));
208 } 216 }
209 _shiftPerSec /= lookupCount+1; 217 _shiftPerSec /= lookupCount+1;
210 TextLabelShift->setText(QString::number(_shiftPerSec)+tr(" seconds")); 218 TextLabelShift->setText(QString::number(_shiftPerSec)+tr(" seconds"));
211} 219}
212 220
213void Ntp::preditctTime() 221void Ntp::preditctTime()
214{ 222{
215 qDebug("current time: %s",QDateTime::currentDateTime().toString().latin1());
216 Config cfg("ntp",Config::User); 223 Config cfg("ntp",Config::User);
217 cfg.setGroup("lookups"); 224 cfg.setGroup("lookups");
218 int lastTime = cfg.readNumEntry("time",0); 225 int lastTime = cfg.readNumEntry("time",0);
219 setenv( "TZ", tz->currentZone(), 1 ); 226 setenv( "TZ", tz->currentZone(), 1 );
220 int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); 227 int now = TimeConversion::toUTC( QDateTime::currentDateTime() );
221 int corr = int((now - lastTime) * _shiftPerSec); 228 int corr = int((now - lastTime) * _shiftPerSec);
222 TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); 229 TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds"));
223 predictedTime = QDateTime::currentDateTime().addSecs(corr); 230 predictedTime = QDateTime::currentDateTime().addSecs(corr);
224 TextLabelPredTime->setText(predictedTime.toString()); 231 TextLabelPredTime->setText(predictedTime.toString());
225 TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); 232 TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>");
226} 233}
227 234
228void Ntp::setPredictTime() 235void Ntp::setPredictTime()
229{ 236{
230 preditctTime(); 237 preditctTime();
231 setTime( predictedTime ); 238 setTime( predictedTime );
232} 239}
233 240
234void Ntp::slotCheckNtp(int i) 241void Ntp::slotCheckNtp(int i)
235{ 242{
236 if (i == 0) 243 if (i == 0)
237 { 244 {
238 TextLabelMainPredTime->hide(); 245 TextLabelMainPredTime->hide();
239 ButtonSetTime->setText( tr("Get time from network") ); 246 ButtonSetTime->setText( tr("Get time from network") );
240 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); 247 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) );
241 Config cfg("ntp",Config::User); 248 if ( ntpDelayElapsed() )
242 cfg.setGroup("lookups");
243 int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
244 if ( lookupDiff > SpinBoxNtpDelay->value()*60 )
245 { 249 {
250 slotRunNtp();
246 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); 251 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) );
247 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); 252 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) );
248 }else{ 253 }else{
249 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); 254 disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) );
250 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); 255 connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
251 } 256 }
252 }else{ 257 }else{
253 preditctTime(); 258 preditctTime();
254 ButtonSetTime->setText( tr("Set predicted time") ); 259 ButtonSetTime->setText( tr("Set predicted time") );
260 if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer());
255 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); 261 connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) );
256 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); 262 connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) );
257 } 263 }
264 //ntpTimer->start(SpinBoxNtpDelay->value()*1000*60);
258} 265}
259 266
260void Ntp::slotProbeNtpServer() 267void Ntp::slotProbeNtpServer()
261{ 268{
262 Config cfg("ntp",Config::User); 269 if ( ntpDelayElapsed() )
263 cfg.setGroup("lookups"); 270 ntpSock->connectToHost( getNtpServer() ,123);
264 int lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
265 if ( lookupDiff > SpinBoxNtpDelay->value()*60 )
266 ntpSock->connectToHost( ComboNtpSrv->currentText() ,123);
267} 271}
268 272
269void Ntp::slotNtpDelayChanged(int delay) 273void Ntp::slotNtpDelayChanged(int delay)
270{ 274{
271 ntpTimer->changeInterval( delay*100 ); 275 ntpTimer->changeInterval( delay*1000*60 );
276}
277
278void Ntp::ntpOutPut(QString out)
279{
280 MultiLineEditntpOutPut->append(out);
281 MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE);
272} 282}
diff --git a/noncore/settings/netsystemtime/ntp.h b/noncore/settings/netsystemtime/ntp.h
index 7cc309f..c78dc55 100644
--- a/noncore/settings/netsystemtime/ntp.h
+++ b/noncore/settings/netsystemtime/ntp.h
@@ -1,43 +1,47 @@
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
6class OProcess; 6class OProcess;
7class QString; 7class QString;
8class QTimer; 8class QTimer;
9class QSocket; 9class QSocket;
10 10
11class Ntp : public SetDateTime 11class Ntp : public SetDateTime
12{ 12{
13 Q_OBJECT 13 Q_OBJECT
14 14
15public: 15public:
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
19protected: 19protected:
20 QDateTime predictedTime; 20 QDateTime predictedTime;
21 21
22 22
23private: 23private:
24 QString _ntpOutput; 24 QString _ntpOutput;
25 float _shiftPerSec; 25 float _shiftPerSec;
26 int _lookupDiff;
26 OProcess *ntpProcess; 27 OProcess *ntpProcess;
27 QTimer *ntpTimer; 28 QTimer *ntpTimer;
28 QSocket *ntpSock; 29 QSocket *ntpSock;
29 30
30 float getTimeShift(); 31 float getTimeShift();
31 void readLookups(); 32 void readLookups();
33 void ntpOutPut(QString);
34 bool ntpDelayElapsed();
35 QString getNtpServer();
32private slots: 36private slots:
33 void slotRunNtp(); 37 void slotRunNtp();
34 void getNtpOutput(OProcess *proc, char *buffer, int buflen); 38 void getNtpOutput(OProcess *proc, char *buffer, int buflen);
35 void ntpFinished(OProcess*); 39 void ntpFinished(OProcess*);
36 void preditctTime(); 40 void preditctTime();
37 void slotCheckNtp(int); 41 void slotCheckNtp(int);
38 void setPredictTime(); 42 void setPredictTime();
39 void slotProbeNtpServer(); 43 void slotProbeNtpServer();
40 void slotNtpDelayChanged(int); 44 void slotNtpDelayChanged(int);
41}; 45};
42 46
43#endif 47#endif
diff --git a/noncore/settings/netsystemtime/ntpbase.ui b/noncore/settings/netsystemtime/ntpbase.ui
index 4e10fd2..a83dc93 100644
--- a/noncore/settings/netsystemtime/ntpbase.ui
+++ b/noncore/settings/netsystemtime/ntpbase.ui
@@ -1,63 +1,63 @@
1<!DOCTYPE UI><UI> 1<!DOCTYPE UI><UI>
2<class>NtpBase</class> 2<class>NtpBase</class>
3<widget> 3<widget>
4 <class>QWidget</class> 4 <class>QWidget</class>
5 <property stdset="1"> 5 <property stdset="1">
6 <name>name</name> 6 <name>name</name>
7 <cstring>NtpBase</cstring> 7 <cstring>NtpBase</cstring>
8 </property> 8 </property>
9 <property stdset="1"> 9 <property stdset="1">
10 <name>geometry</name> 10 <name>geometry</name>
11 <rect> 11 <rect>
12 <x>0</x> 12 <x>0</x>
13 <y>0</y> 13 <y>0</y>
14 <width>331</width> 14 <width>328</width>
15 <height>426</height> 15 <height>411</height>
16 </rect> 16 </rect>
17 </property> 17 </property>
18 <property stdset="1"> 18 <property stdset="1">
19 <name>caption</name> 19 <name>caption</name>
20 <string>Network Time</string> 20 <string>Network Time</string>
21 </property> 21 </property>
22 <property> 22 <property>
23 <name>layoutMargin</name> 23 <name>layoutMargin</name>
24 </property> 24 </property>
25 <property> 25 <property>
26 <name>layoutSpacing</name> 26 <name>layoutSpacing</name>
27 </property> 27 </property>
28 <grid> 28 <grid>
29 <property stdset="1"> 29 <property stdset="1">
30 <name>margin</name> 30 <name>margin</name>
31 <number>2</number> 31 <number>2</number>
32 </property> 32 </property>
33 <property stdset="1"> 33 <property stdset="1">
34 <name>spacing</name> 34 <name>spacing</name>
35 <number>2</number> 35 <number>2</number>
36 </property> 36 </property>
37 <widget row="0" column="0" > 37 <widget row="0" column="0" >
38 <class>QTabWidget</class> 38 <class>QTabWidget</class>
39 <property stdset="1"> 39 <property stdset="1">
40 <name>name</name> 40 <name>name</name>
41 <cstring>TabWidgetMain</cstring> 41 <cstring>TabWidgetMain</cstring>
42 </property> 42 </property>
43 <property> 43 <property>
44 <name>layoutMargin</name> 44 <name>layoutMargin</name>
45 </property> 45 </property>
46 <property> 46 <property>
47 <name>layoutSpacing</name> 47 <name>layoutSpacing</name>
48 </property> 48 </property>
49 <widget> 49 <widget>
50 <class>QWidget</class> 50 <class>QWidget</class>
51 <property stdset="1"> 51 <property stdset="1">
52 <name>name</name> 52 <name>name</name>
53 <cstring>tabMain</cstring> 53 <cstring>tabMain</cstring>
54 </property> 54 </property>
55 <attribute> 55 <attribute>
56 <name>title</name> 56 <name>title</name>
57 <string>Main</string> 57 <string>Main</string>
58 </attribute> 58 </attribute>
59 <grid> 59 <grid>
60 <property stdset="1"> 60 <property stdset="1">
61 <name>margin</name> 61 <name>margin</name>
62 <number>2</number> 62 <number>2</number>
63 </property> 63 </property>
diff --git a/noncore/settings/netsystemtime/opie-netsystemtime.control b/noncore/settings/netsystemtime/opie-netsystemtime.control
index 406d7b0..d3290e9 100644
--- a/noncore/settings/netsystemtime/opie-netsystemtime.control
+++ b/noncore/settings/netsystemtime/opie-netsystemtime.control
@@ -1,11 +1,11 @@
1Files: bin/netsystemtime apps/Settings/ntpdatetime.desktop 1Files: bin/netsystemtime apps/Settings/ntpdatetime.desktop etc/ntpservers
2Priority: optional 2Priority: optional
3Section: opie/settings 3Section: opie/settings
4Depends: ntpdate 4Depends: ntpdate
5Conflicts: opie-systemtime 5Conflicts: opie-systemtime
6Maintainer: Patrick S. Vogt <tille@handhelds.org> 6Maintainer: Patrick S. Vogt <tille@handhelds.org>
7Architecture: arm 7Architecture: arm
8Version: $QPE_VERSION-$SUB_VERSION 8Version: $QPE_VERSION-$SUB_VERSION
9Depends: opie-base ($QPE_VERSION), ntpdate 9Depends: opie-base ($QPE_VERSION), ntpdate
10Description: ntp ( Network Time Protocol) gui 10Description: ntp ( Network Time Protocol) gui
11This utility syncs system time with a atomic timerserver via internet 11This utility syncs system time with a atomic timerserver via internet
diff --git a/noncore/settings/netsystemtime/settime.cpp b/noncore/settings/netsystemtime/settime.cpp
index 2398c08..93543cd 100644
--- a/noncore/settings/netsystemtime/settime.cpp
+++ b/noncore/settings/netsystemtime/settime.cpp
@@ -255,97 +255,96 @@ void SetDateTime::setTime(QDateTime dt)
255 int t = TimeConversion::toUTC(dt); 255 int t = TimeConversion::toUTC(dt);
256 struct timeval myTv; 256 struct timeval myTv;
257 myTv.tv_sec = t; 257 myTv.tv_sec = t;
258 cfg.writeEntry("time", t ); 258 cfg.writeEntry("time", t );
259 myTv.tv_usec = 0; 259 myTv.tv_usec = 0;
260 260
261 if ( myTv.tv_sec != -1 ) 261 if ( myTv.tv_sec != -1 )
262 ::settimeofday( &myTv, 0 ); 262 ::settimeofday( &myTv, 0 );
263 Global::writeHWClock(); 263 Global::writeHWClock();
264 // since time has changed quickly load in the datebookdb 264 // since time has changed quickly load in the datebookdb
265 // to allow the alarm server to get a better grip on itself 265 // to allow the alarm server to get a better grip on itself
266 // (example re-trigger alarms for when we travel back in time) 266 // (example re-trigger alarms for when we travel back in time)
267 DateBookDB db; 267 DateBookDB db;
268} 268}
269 269
270void SetDateTime::updateSystem(int i) 270void SetDateTime::updateSystem(int i)
271{ 271{
272 qDebug("SetDateTime::updateSystem(int %i)",i); 272 qDebug("SetDateTime::updateSystem(int %i)",i);
273 writeSettings(); 273 writeSettings();
274 274
275 // set the timezone for everyone else... 275 // set the timezone for everyone else...
276 QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); 276 QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" );
277 setTimeZone << tz->currentZone(); 277 setTimeZone << tz->currentZone();
278 278
279 // AM/PM setting and notify time changed 279 // AM/PM setting and notify time changed
280 QCopEnvelope setClock( "QPE/System", "clockChange(bool)" ); 280 QCopEnvelope setClock( "QPE/System", "clockChange(bool)" );
281 setClock << ampmCombo->currentItem(); 281 setClock << ampmCombo->currentItem();
282 282
283 // Notify everyone what day we prefer to start the week on. 283 // Notify everyone what day we prefer to start the week on.
284 QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" ); 284 QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" );
285 setWeek << weekStartCombo->currentItem(); 285 setWeek << weekStartCombo->currentItem();
286 286
287 // Notify everyone what date format to use 287 // Notify everyone what date format to use
288 QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" ); 288 QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" );
289 setDateFormat << date_formats[dateFormatCombo->currentItem()]; 289 setDateFormat << date_formats[dateFormatCombo->currentItem()];
290 290
291 // Restore screensaver 291 // Restore screensaver
292 QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); 292 QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" );
293 enableScreenSaver << -1 << -1 << -1; 293 enableScreenSaver << -1 << -1 << -1;
294 // since time has changed quickly load in the datebookdb 294 // since time has changed quickly load in the datebookdb
295 // to allow the alarm server to get a better grip on itself 295 // to allow the alarm server to get a better grip on itself
296 // (example re-trigger alarms for when we travel back in time) 296 // (example re-trigger alarms for when we travel back in time)
297 DateBookDB db; 297 DateBookDB db;
298 298
299} 299}
300 300
301void SetDateTime::tzChange( const QString &tz ) 301void SetDateTime::tzChange( const QString &tz )
302{ 302{
303 qDebug("SetDateTime::tzChange");
304 // set the TZ get the time and leave gracefully... 303 // set the TZ get the time and leave gracefully...
305 QString strSave; 304 QString strSave;
306 strSave = getenv( "TZ" ); 305 strSave = getenv( "TZ" );
307 setenv( "TZ", tz, 1 ); 306 setenv( "TZ", tz, 1 );
308 307
309 QDate d = QDate::currentDate(); 308 QDate d = QDate::currentDate();
310 // reset the time. 309 // reset the time.
311 if ( !strSave.isNull() ) { 310 if ( !strSave.isNull() ) {
312 setenv( "TZ", strSave, 1 ); 311 setenv( "TZ", strSave, 1 );
313 } 312 }
314 dateButton->setDate( d ); 313 dateButton->setDate( d );
315 updateSystem(); 314 updateSystem();
316} 315}
317 316
318void SetDateTime::formatChanged(int i) 317void SetDateTime::formatChanged(int i)
319{ 318{
320 dateButton->setDateFormat(date_formats[i]); 319 dateButton->setDateFormat(date_formats[i]);
321} 320}
322 321
323static const int ValueAM = 0; 322static const int ValueAM = 0;
324static const int ValuePM = 1; 323static const int ValuePM = 1;
325 324
326 325
327 326
328SetTime::SetTime( QWidget *parent, const char *name ) 327SetTime::SetTime( QWidget *parent, const char *name )
329 : QWidget( parent, name ) 328 : QWidget( parent, name )
330{ 329{
331 use12hourTime = FALSE; 330 use12hourTime = FALSE;
332 331
333 QTime currTime = QTime::currentTime(); 332 QTime currTime = QTime::currentTime();
334 hour = currTime.hour(); 333 hour = currTime.hour();
335 minute = currTime.minute(); 334 minute = currTime.minute();
336 335
337 QHBoxLayout *hb2 = new QHBoxLayout( this ); 336 QHBoxLayout *hb2 = new QHBoxLayout( this );
338 hb2->setSpacing( 3 ); 337 hb2->setSpacing( 3 );
339 338
340 QLabel *l = new QLabel( tr("Hour"), this ); 339 QLabel *l = new QLabel( tr("Hour"), this );
341 // l->setAlignment( AlignRight | AlignVCenter ); 340 // l->setAlignment( AlignRight | AlignVCenter );
342 hb2->addWidget( l ); 341 hb2->addWidget( l );
343 342
344 sbHour = new QSpinBox( this ); 343 sbHour = new QSpinBox( this );
345 sbHour->setMinimumWidth( 30 ); 344 sbHour->setMinimumWidth( 30 );
346 if(use12hourTime) { 345 if(use12hourTime) {
347 sbHour->setMinValue(1); 346 sbHour->setMinValue(1);
348 sbHour->setMaxValue( 12 ); 347 sbHour->setMaxValue( 12 );
349 int show_hour = hour; 348 int show_hour = hour;
350 if (hour > 12) 349 if (hour > 12)
351 show_hour -= 12; 350 show_hour -= 12;
@@ -411,79 +410,78 @@ void SetTime::minuteChanged( int value )
411{ 410{
412 minute = value; 411 minute = value;
413} 412}
414 413
415void SetTime::show12hourTime( int on ) 414void SetTime::show12hourTime( int on )
416{ 415{
417 use12hourTime = on; 416 use12hourTime = on;
418 ampm->setEnabled(on); 417 ampm->setEnabled(on);
419 418
420 int show_hour = hour; 419 int show_hour = hour;
421 if ( on ) { 420 if ( on ) {
422 /* this might change the value of hour */ 421 /* this might change the value of hour */
423 sbHour->setMinValue(1); 422 sbHour->setMinValue(1);
424 sbHour->setMaxValue( 12 ); 423 sbHour->setMaxValue( 12 );
425 424
426 /* so use one we saved earlier */ 425 /* so use one we saved earlier */
427 if (show_hour >= 12) { 426 if (show_hour >= 12) {
428 show_hour -= 12; 427 show_hour -= 12;
429 ampm->setCurrentItem( ValuePM ); 428 ampm->setCurrentItem( ValuePM );
430 } else { 429 } else {
431 ampm->setCurrentItem( ValueAM ); 430 ampm->setCurrentItem( ValueAM );
432 } 431 }
433 if (show_hour == 0) 432 if (show_hour == 0)
434 show_hour = 12; 433 show_hour = 12;
435 434
436 } else { 435 } else {
437 sbHour->setMinValue( 0 ); 436 sbHour->setMinValue( 0 );
438 sbHour->setMaxValue( 23 ); 437 sbHour->setMaxValue( 23 );
439 } 438 }
440 439
441 440
442 sbHour->setValue( show_hour ); 441 sbHour->setValue( show_hour );
443} 442}
444 443
445void SetTime::checkedPM( int c ) 444void SetTime::checkedPM( int c )
446{ 445{
447 int show_hour = sbHour->value(); 446 int show_hour = sbHour->value();
448 if (show_hour == 12) 447 if (show_hour == 12)
449 show_hour = 0; 448 show_hour = 0;
450 449
451 if ( c == ValuePM ) 450 if ( c == ValuePM )
452 show_hour += 12; 451 show_hour += 12;
453 452
454 hour = show_hour; 453 hour = show_hour;
455} 454}
456 455
457void SetTime::slotTzChange( const QString &tz ) 456void SetTime::slotTzChange( const QString &tz )
458{ 457{
459 qDebug("SetTime::slotTzChange");
460 // set the TZ get the time and leave gracefully... 458 // set the TZ get the time and leave gracefully...
461 QString strSave; 459 QString strSave;
462 strSave = getenv( "TZ" ); 460 strSave = getenv( "TZ" );
463 setenv( "TZ", tz, 1 ); 461 setenv( "TZ", tz, 1 );
464 462
465 QTime t = QTime::currentTime(); 463 QTime t = QTime::currentTime();
466 // reset the time. 464 // reset the time.
467 if ( !strSave.isNull() ) { 465 if ( !strSave.isNull() ) {
468 setenv( "TZ", strSave, 1 ); 466 setenv( "TZ", strSave, 1 );
469 } 467 }
470 468
471 // just set the spinboxes and let it propage through 469 // just set the spinboxes and let it propage through
472 if(use12hourTime) { 470 if(use12hourTime) {
473 int show_hour = t.hour(); 471 int show_hour = t.hour();
474 if (t.hour() >= 12) { 472 if (t.hour() >= 12) {
475 show_hour -= 12; 473 show_hour -= 12;
476 ampm->setCurrentItem( ValuePM ); 474 ampm->setCurrentItem( ValuePM );
477 } else { 475 } else {
478 ampm->setCurrentItem( ValueAM ); 476 ampm->setCurrentItem( ValueAM );
479 } 477 }
480 if (show_hour == 0) 478 if (show_hour == 0)
481 show_hour = 12; 479 show_hour = 12;
482 sbHour->setValue( show_hour ); 480 sbHour->setValue( show_hour );
483 } else { 481 } else {
484 sbHour->setValue( t.hour() ); 482 sbHour->setValue( t.hour() );
485 } 483 }
486 sbMin->setValue( t.minute() ); 484 sbMin->setValue( t.minute() );
487} 485}
488 486
489 487