summaryrefslogtreecommitdiff
Unidiff
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,47 +1,48 @@
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) );
@@ -202,48 +203,52 @@ void 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;