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,71 +1,72 @@
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
@@ -178,96 +179,100 @@ void Ntp::slotRunNtp()
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 );