author | tille <tille> | 2002-07-04 13:52:07 (UTC) |
---|---|---|
committer | tille <tille> | 2002-07-04 13:52:07 (UTC) |
commit | a53847b7d27938551bb4f1c8891e7bacc93143ee (patch) (unidiff) | |
tree | 5910685b0156b089af8a117d261ea02d05a44b95 | |
parent | 61b99edb481444aea41fa47853a5d60c78bfaa3c (diff) | |
download | opie-a53847b7d27938551bb4f1c8891e7bacc93143ee.zip opie-a53847b7d27938551bb4f1c8891e7bacc93143ee.tar.gz opie-a53847b7d27938551bb4f1c8891e7bacc93143ee.tar.bz2 |
aply ntp on set not on quit -- hopefully
-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index 40b5531..0b13b6d 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp | |||
@@ -1,51 +1,52 @@ | |||
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/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 <sys/time.h> | 21 | #include <sys/time.h> |
21 | #include <time.h> | 22 | #include <time.h> |
22 | #include <stdlib.h> | 23 | #include <stdlib.h> |
23 | 24 | ||
24 | 25 | ||
25 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | 26 | Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) |
26 | : SetDateTime( parent, name, fl ) | 27 | : SetDateTime( parent, name, fl ) |
27 | { | 28 | { |
28 | Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); | 29 | Config ntpSrvs(QPEApplication::qpeDir()+"etc/ntpservers",Config::File); |
29 | ntpSrvs.setGroup("servers"); | 30 | ntpSrvs.setGroup("servers"); |
30 | int srvCount = ntpSrvs.readNumEntry("count", 0 ); | 31 | int srvCount = ntpSrvs.readNumEntry("count", 0 ); |
31 | for (int i = 0; i < srvCount; i++) | 32 | for (int i = 0; i < srvCount; i++) |
32 | { | 33 | { |
33 | ntpSrvs.setGroup(QString::number(i)); | 34 | ntpSrvs.setGroup(QString::number(i)); |
34 | ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); | 35 | ComboNtpSrv->insertItem( ntpSrvs.readEntry("name") ); |
35 | } | 36 | } |
36 | if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); | 37 | if ( srvCount==0 ) ComboNtpSrv->insertItem(tr("time.fu-berlin.de")); |
37 | 38 | ||
38 | Config cfg("ntp",Config::User); | 39 | Config cfg("ntp",Config::User); |
39 | cfg.setGroup("settings"); | 40 | cfg.setGroup("settings"); |
40 | SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) ); | 41 | SpinBoxMinLookupDelay->setValue( cfg.readNumEntry("minLookupDiff",41) ); |
41 | SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) ); | 42 | SpinBoxNtpDelay->setValue( cfg.readNumEntry("ntpRefreshFreq",42) ); |
42 | ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); | 43 | ComboNtpSrv->setCurrentItem( cfg.readNumEntry("ntpServer", 0) ); |
43 | 44 | ||
44 | ntpTimer = new QTimer(this); | 45 | ntpTimer = new QTimer(this); |
45 | 46 | ||
46 | ntpProcess = new OProcess( ); | 47 | ntpProcess = new OProcess( ); |
47 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), | 48 | connect( SpinBoxNtpDelay, SIGNAL( valueChanged(int) ), |
48 | SLOT(slotNtpDelayChanged(int)) ); | 49 | SLOT(slotNtpDelayChanged(int)) ); |
49 | 50 | ||
50 | ntpSock = new QSocket( this ); | 51 | ntpSock = new QSocket( this ); |
51 | connect( ntpSock, SIGNAL( error(int) ), | 52 | connect( ntpSock, SIGNAL( error(int) ), |
@@ -115,64 +116,71 @@ void Ntp::slotRunNtp() | |||
115 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); | 116 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); |
116 | 117 | ||
117 | ntpProcess->clearArguments(); | 118 | ntpProcess->clearArguments(); |
118 | *ntpProcess << "ntpdate" << getNtpServer(); | 119 | *ntpProcess << "ntpdate" << getNtpServer(); |
119 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); | 120 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); |
120 | if ( !ret ) { | 121 | if ( !ret ) { |
121 | qDebug("Error while executing ntpdate"); | 122 | qDebug("Error while executing ntpdate"); |
122 | ntpOutPut( tr("Error while executing ntpdate")); | 123 | ntpOutPut( tr("Error while executing ntpdate")); |
123 | } | 124 | } |
124 | } | 125 | } |
125 | 126 | ||
126 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) | 127 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) |
127 | { | 128 | { |
128 | QString lineStr, lineStrOld; | 129 | QString lineStr, lineStrOld; |
129 | lineStr = buffer; | 130 | lineStr = buffer; |
130 | lineStr=lineStr.left(buflen); | 131 | lineStr=lineStr.left(buflen); |
131 | if (lineStr!=lineStrOld) | 132 | if (lineStr!=lineStrOld) |
132 | { | 133 | { |
133 | ntpOutPut(lineStr); | 134 | ntpOutPut(lineStr); |
134 | _ntpOutput += lineStr; | 135 | _ntpOutput += lineStr; |
135 | } | 136 | } |
136 | lineStrOld = lineStr; | 137 | lineStrOld = lineStr; |
137 | } | 138 | } |
138 | 139 | ||
139 | void Ntp::ntpFinished(OProcess *p) | 140 | void Ntp::ntpFinished(OProcess *p) |
140 | { | 141 | { |
141 | qDebug("p->exitStatus() %i",p->exitStatus()); | 142 | qDebug("p->exitStatus() %i",p->exitStatus()); |
142 | if (p->exitStatus()!=0 || !p->normalExit()) | 143 | if (p->exitStatus()!=0 || !p->normalExit()) |
143 | { | 144 | { |
144 | slotProbeNtpServer(); | 145 | slotProbeNtpServer(); |
145 | return; | 146 | return; |
146 | } | 147 | } |
148 | |||
149 | Global::writeHWClock(); | ||
150 | // since time has changed quickly load in the datebookdb | ||
151 | // to allow the alarm server to get a better grip on itself | ||
152 | // (example re-trigger alarms for when we travel back in time) | ||
153 | DateBookDB db; | ||
154 | |||
147 | Config cfg("ntp",Config::User); | 155 | Config cfg("ntp",Config::User); |
148 | cfg.setGroup("lookups"); | 156 | cfg.setGroup("lookups"); |
149 | int lastLookup = cfg.readNumEntry("time",0); | 157 | int lastLookup = cfg.readNumEntry("time",0); |
150 | int lookupCount = cfg.readNumEntry("count",0); | 158 | int lookupCount = cfg.readNumEntry("count",0); |
151 | bool lastNtp = cfg.readBoolEntry("lastNtp",false); | 159 | bool lastNtp = cfg.readBoolEntry("lastNtp",false); |
152 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 160 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
153 | cfg.writeEntry("time", time); | 161 | cfg.writeEntry("time", time); |
154 | 162 | ||
155 | float timeShift = getTimeShift(); | 163 | float timeShift = getTimeShift(); |
156 | if (timeShift == 0.0) return; | 164 | if (timeShift == 0.0) return; |
157 | int secsSinceLast = time - lastLookup; | 165 | int secsSinceLast = time - lastLookup; |
158 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); | 166 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); |
159 | TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); | 167 | TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); |
160 | if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) | 168 | if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) |
161 | { | 169 | { |
162 | cfg.setGroup("lookup_"+QString::number(lookupCount)); | 170 | cfg.setGroup("lookup_"+QString::number(lookupCount)); |
163 | lookupCount++; | 171 | lookupCount++; |
164 | _shiftPerSec = timeShift / secsSinceLast; | 172 | _shiftPerSec = timeShift / secsSinceLast; |
165 | qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); | 173 | qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); |
166 | cfg.writeEntry("secsSinceLast",secsSinceLast); | 174 | cfg.writeEntry("secsSinceLast",secsSinceLast); |
167 | cfg.writeEntry("timeShift",QString::number(timeShift)); | 175 | cfg.writeEntry("timeShift",QString::number(timeShift)); |
168 | cfg.setGroup("lookups"); | 176 | cfg.setGroup("lookups"); |
169 | cfg.writeEntry("count",lookupCount); | 177 | cfg.writeEntry("count",lookupCount); |
170 | cfg.writeEntry("lastNtp",true); | 178 | cfg.writeEntry("lastNtp",true); |
171 | } | 179 | } |
172 | } | 180 | } |
173 | 181 | ||
174 | 182 | ||
175 | float Ntp::getTimeShift() | 183 | float Ntp::getTimeShift() |
176 | { | 184 | { |
177 | QString _offset = "offset"; | 185 | QString _offset = "offset"; |
178 | QString _sec = "sec"; | 186 | QString _sec = "sec"; |