summaryrefslogtreecommitdiff
authortille <tille>2002-10-19 15:33:05 (UTC)
committer tille <tille>2002-10-19 15:33:05 (UTC)
commit7a1c7fca5105427ff569f8219fb96873571a749a (patch) (unidiff)
tree4c5620553e8647c72fb9a9f42eb069600f62e3ea
parent04d045931cb66c8ff13b1247e6a366ff77c36474 (diff)
downloadopie-7a1c7fca5105427ff569f8219fb96873571a749a.zip
opie-7a1c7fca5105427ff569f8219fb96873571a749a.tar.gz
opie-7a1c7fca5105427ff569f8219fb96873571a749a.tar.bz2
typo
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/settings/netsystemtime/ntp.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp
index 9572993..fbd65a2 100644
--- a/noncore/settings/netsystemtime/ntp.cpp
+++ b/noncore/settings/netsystemtime/ntp.cpp
@@ -13,193 +13,193 @@
13#include <qpe/qpeapplication.h> 13#include <qpe/qpeapplication.h>
14#include <qpe/config.h> 14#include <qpe/config.h>
15#include <qpe/global.h> 15#include <qpe/global.h>
16#include <qpe/timeconversion.h> 16#include <qpe/timeconversion.h>
17#include <qpe/tzselect.h> 17#include <qpe/tzselect.h>
18#include <qpe/timestring.h> 18#include <qpe/timestring.h>
19#include <qpe/qpedialog.h> 19#include <qpe/qpedialog.h>
20#include <qpe/datebookdb.h> 20#include <qpe/datebookdb.h>
21#include <qpe/qcopenvelope_qws.h> 21#include <qpe/qcopenvelope_qws.h>
22#include <sys/time.h> 22#include <sys/time.h>
23#include <time.h> 23#include <time.h>
24#include <stdlib.h> 24#include <stdlib.h>
25 25
26 26
27Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) 27Ntp::Ntp( QWidget* parent, const char* name, WFlags fl )
28 : SetDateTime( parent, name, fl ) 28 : SetDateTime( parent, name, fl )
29{ 29{
30 Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); 30 Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File);
31 ntpSrvs.setGroup("servers"); 31 ntpSrvs.setGroup("servers");
32 int srvCount = ntpSrvs.readNumEntry("count", 0 ); 32 int srvCount = ntpSrvs.readNumEntry("count", 0 );
33 for (int i = 0; i < srvCount; i++) 33 for (int i = 0; i < srvCount; i++)
34 { 34 {
35 ntpSrvs.setGroup(QString::number(i)); 35 ntpSrvs.setGroup(QString::number(i));
36 ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); 36 ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") );
37 } 37 }
38 if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); 38 if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de"));
39 39
40 Config cfg("ntp",Config::User); 40 Config cfg("ntp",Config::User);
41 cfg.setGroup("settings"); 41 cfg.setGroup("settings");
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 makeChannel(); 46 makeChannel();
47 47
48 ntpTimer = new QTimer(this); 48 ntpTimer = new QTimer(this);
49 49
50 ntpProcess = new OProcess( ); 50 ntpProcess = new OProcess( );
51 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), 51 connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ),
52 SLOT(slotNtpDelayChanged(int)) ); 52 SLOT(slotNtpDelayChanged(int)) );
53 53
54 ntpSock = new QSocket( this ); 54 ntpSock = new QSocket( this );
55 connect( ntpSock, SIGNAL( error(int) ), 55 connect( ntpSock, SIGNAL( error(int) ),
56 SLOT(slotCheckNtp(int)) ); 56 SLOT(slotCheckNtp(int)) );
57 slotProbeNtpServer(); 57 slotProbeNtpServer();
58 58
59 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), 59 connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)),
60 this, SLOT(getNtpOutput(OProcess*,char*,int))); 60 this, SLOT(getNtpOutput(OProcess*,char*,int)));
61 connect ( ntpProcess, SIGNAL(processExited(OProcess*)), 61 connect ( ntpProcess, SIGNAL(processExited(OProcess*)),
62 this, SLOT(ntpFinished(OProcess*))); 62 this, SLOT(ntpFinished(OProcess*)));
63 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); 63 connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp()));
64 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); 64 connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime()));
65 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); 65 connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime()));
66 slotCheckNtp(-1); 66 slotCheckNtp(-1);
67 readLookups(); 67 readLookups();
68} 68}
69 69
70Ntp::~Ntp() 70Ntp::~Ntp()
71{ 71{
72 delete ntpProcess; 72 delete ntpProcess;
73 Config ntpSrvs("/etc/ntpservers",Config::File); 73 Config ntpSrvs("/etc/ntpservers",Config::File);
74 ntpSrvs.setGroup("servers"); 74 ntpSrvs.setGroup("servers");
75 int srvCount = ComboNtpSrv->count(); 75 int srvCount = ComboNtpSrv->count();
76 ntpSrvs.writeEntry("count", srvCount); 76 ntpSrvs.writeEntry("count", srvCount);
77 for (int i = 0; i < srvCount; i++) 77 for (int i = 0; i < srvCount; i++)
78 { 78 {
79 ntpSrvs.setGroup(QString::number(i)); 79 ntpSrvs.setGroup(QString::number(i));
80 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); 80 ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) );
81 } 81 }
82 Config cfg("ntp",Config::User); 82 Config cfg("ntp",Config::User);
83 cfg.setGroup("settings"); 83 cfg.setGroup("settings");
84 cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); 84 cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem());
85 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); 85 cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() );
86 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); 86 cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() );
87} 87}
88 88
89bool Ntp::ntpDelayElapsed() 89bool Ntp::ntpDelayElapsed()
90{ 90{
91 Config cfg("ntp",Config::User); 91 Config cfg("ntp",Config::User);
92 cfg.setGroup("lookups"); 92 cfg.setGroup("lookups");
93 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); 93 _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0);
94 return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60; 94 return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60;
95} 95}
96 96
97QString Ntp::getNtpServer() 97QString Ntp::getNtpServer()
98{ 98{
99 return ComboNtpSrv->currentText(); 99 return ComboNtpSrv->currentText();
100} 100}
101 101
102void Ntp::slotRunNtp() 102void Ntp::slotRunNtp()
103{ 103{
104 if ( !ntpDelayElapsed() ) 104 if ( !ntpDelayElapsed() )
105 { 105 {
106 switch ( 106 switch (
107 QMessageBox::warning(this, tr("Run NTP?"), 107 QMessageBox::warning(this, tr("Run NTP?"),
108 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ 108 tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+
109 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+ 109 QString::number(_lookupDiff/60)+tr(" minutes elapsed since last lookup.")+
110 "<br>"+tr("Rerun NTP?"), 110 "<br>"+tr("Rerun NTP?"),
111 QMessageBox::Ok,QMessageBox::Cancel) 111 QMessageBox::Ok,QMessageBox::Cancel)
112 ) { 112 ) {
113 case QMessageBox::Ok: break; 113 case QMessageBox::Ok: break;
114 case QMessageBox::Cancel: return; 114 case QMessageBox::Cancel: return;
115 default: return; 115 default: return;
116 } 116 }
117 } 117 }
118 TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); 118 TextLabelStartTime->setText(QDateTime::currentDateTime().toString());
119 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); 119 ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() );
120 120
121 ntpProcess->clearArguments(); 121 ntpProcess->clearArguments();
122 *ntpProcess << "ntpdate" << getNtpServer(); 122 *ntpProcess << "ntpdate" << getNtpServer();
123 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); 123 bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput);
124 if ( !ret ) { 124 if ( !ret ) {
125 qDebug("Error while executing ntpdate"); 125 qDebug("Error while executing ntpdate");
126 ntpOutPut( tr("Error while executing ntpdate")); 126 ntpOutPut( tr("Error while executing ntpdate"));
127 } 127 }
128} 128}
129 129
130void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) 130void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen)
131{ 131{
132 QString lineStr, lineStrOld; 132 QString lineStr, lineStrOld;
133 lineStr = buffer; 133 lineStr = buffer;
134 lineStr=lineStr.left(buflen); 134 lineStr=lineStr.left(buflen);
135 if (lineStr!=lineStrOld) 135 if (lineStr!=lineStrOld)
136 { 136 {
137 ntpOutPut(lineStr); 137 ntpOutPut(lineStr);
138 _ntpOutput += lineStr; 138 _ntpOutput += lineStr;
139 } 139 }
140 lineStrOld = lineStr; 140 lineStrOld = lineStr;
141} 141}
142 142
143void Ntp::ntpFinished(OProcess *p) 143void Ntp::ntpFinished(OProcess *p)
144{ 144{
145 qDebug("p->exitStatus() %i",p->exitStatus()); 145 qDebug("p->exitStatus() %i",p->exitStatus());
146 if (p->exitStatus()!=0 || !p->normalExit()) 146 if (p->exitStatus()!=0 || !p->normalExit())
147 { 147 {
148 slotProbeNtpServer(); 148 slotProbeNtpServer();
149 return; 149 return;
150 } 150 }
151 151
152 Global::writeHWClock(); 152 Global::writeHWClock();
153 // since time has changed quickly load in the datebookdb 153 // since time has changed quickly load in the datebookdb
154 // to allow the alarm server to get a better grip on itself 154 // to allow the alarm server to get a better grip on itself
155 // (example re-trigger alarms for when we travel back in time) 155 // (example re-trigger alarms for when we travel back in time)
156 DateBookDB db; 156 DateBookDB db;
157 157
158// QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" ); 158// QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" );
159// timeApplet << ""; 159// timeApplet << "";
160 160
161 Config cfg("ntp",Config::User); 161 Config cfg("ntp",Config::User);
162 cfg.setGroup("lookups"); 162 cfg.setGroup("lookups");
163 int lastLookup = cfg.readNumEntry("time",0); 163 int lastLookup = cfg.readNumEntry("time",0);
164 int lookupCount = cfg.readNumEntry("count",0); 164 int lookupCount = cfg.readNumEntry("count",0);
165 bool lastNtp = cfg.readBoolEntry("lastNtp",false); 165 bool lastNtp = cfg.readBoolEntry("lastNtp",false);
166 int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); 166 int time = TimeConversion::toUTC( QDateTime::currentDateTime() );
167 cfg.writeEntry("time", time); 167 cfg.writeEntry("time", time);
168 168
169 float timeShift = getTimeShift(); 169 float timeShift = getTimeShift();
170 if (timeShift == 0.0) return; 170 if (timeShift == 0.0) return;
171 int secsSinceLast = time - lastLookup; 171 int secsSinceLast = time - lastLookup;
172 TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); 172 TextLabelNewTime->setText(QDateTime::currentDateTime().toString());
173 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); 173 TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds"));
174 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) 174 if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value())
175 { 175 {
176 cfg.setGroup("lookup_"+QString::number(lookupCount)); 176 cfg.setGroup("lookup_"+QString::number(lookupCount));
177 lookupCount++; 177 lookupCount++;
178 _shiftPerSec = timeShift / secsSinceLast; 178 _shiftPerSec = timeShift / secsSinceLast;
179 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); 179 qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec);
180 cfg.writeEntry("secsSinceLast",secsSinceLast); 180 cfg.writeEntry("secsSinceLast",secsSinceLast);
181 cfg.writeEntry("timeShift",QString::number(timeShift)); 181 cfg.writeEntry("timeShift",QString::number(timeShift));
182 cfg.setGroup("lookups"); 182 cfg.setGroup("lookups");
183 cfg.writeEntry("count",lookupCount); 183 cfg.writeEntry("count",lookupCount);
184 cfg.writeEntry("lastNtp",true); 184 cfg.writeEntry("lastNtp",true);
185 } 185 }
186} 186}
187 187
188 188
189float Ntp::getTimeShift() 189float Ntp::getTimeShift()
190{ 190{
191 QString _offset = "offset"; 191 QString _offset = "offset";
192 QString _sec = "sec"; 192 QString _sec = "sec";
193 QRegExp _reOffset = QRegExp(_offset); 193 QRegExp _reOffset = QRegExp(_offset);
194 QRegExp _reEndOffset = QRegExp(_sec); 194 QRegExp _reEndOffset = QRegExp(_sec);
195 int posOffset = _reOffset.match( _ntpOutput ); 195 int posOffset = _reOffset.match( _ntpOutput );
196 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); 196 int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset );
197 posOffset += _offset.length() + 1; 197 posOffset += _offset.length() + 1;
198 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); 198 QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1);
199 qDebug("%s", _ntpOutput.latin1()); 199 qDebug("%s", _ntpOutput.latin1());
200 qDebug("diff = >%s<",diff.latin1()); 200 qDebug("diff = >%s<",diff.latin1());
201 return diff.toFloat(); 201 return diff.toFloat();
202} 202}
203 203
204void Ntp::readLookups() 204void Ntp::readLookups()
205{ 205{