author | tille <tille> | 2002-06-27 22:28:03 (UTC) |
---|---|---|
committer | tille <tille> | 2002-06-27 22:28:03 (UTC) |
commit | 2f9c9f9dfe6aff27381a3c671bbd50870976677c (patch) (unidiff) | |
tree | 28ea446384f0abc3b8c9b49d9631b46bd174b32d | |
parent | 49710f20cf0e52ea3393027ed066f11e977e3457 (diff) | |
download | opie-2f9c9f9dfe6aff27381a3c671bbd50870976677c.zip opie-2f9c9f9dfe6aff27381a3c671bbd50870976677c.tar.gz opie-2f9c9f9dfe6aff27381a3c671bbd50870976677c.tar.bz2 |
conffile count
-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 9 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/settime.cpp | 3 |
2 files changed, 8 insertions, 4 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index 830c0c3..7971f9a 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp | |||
@@ -55,233 +55,234 @@ Ntp::Ntp( QWidget* parent, const char* name, WFlags fl ) | |||
55 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), | 55 | connect ( ntpProcess, SIGNAL(receivedStdout(OProcess*,char*,int)), |
56 | this, SLOT(getNtpOutput(OProcess*,char*,int))); | 56 | this, SLOT(getNtpOutput(OProcess*,char*,int))); |
57 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), | 57 | connect ( ntpProcess, SIGNAL(processExited(OProcess*)), |
58 | this, SLOT(ntpFinished(OProcess*))); | 58 | this, SLOT(ntpFinished(OProcess*))); |
59 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); | 59 | connect(runNtp, SIGNAL(clicked()), this, SLOT(slotRunNtp())); |
60 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); | 60 | connect(PushButtonPredict, SIGNAL(clicked()), this, SLOT(preditctTime())); |
61 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); | 61 | connect(PushButtonSetPredTime, SIGNAL(clicked()), this, SLOT(setPredictTime())); |
62 | slotCheckNtp(-1); | 62 | slotCheckNtp(-1); |
63 | readLookups(); | 63 | readLookups(); |
64 | } | 64 | } |
65 | 65 | ||
66 | Ntp::~Ntp() | 66 | Ntp::~Ntp() |
67 | { | 67 | { |
68 | delete ntpProcess; | 68 | delete ntpProcess; |
69 | Config ntpSrvs("/etc/ntpservers",Config::File); | 69 | Config ntpSrvs("/etc/ntpservers",Config::File); |
70 | ntpSrvs.setGroup("servers"); | 70 | ntpSrvs.setGroup("servers"); |
71 | int srvCount = ComboNtpSrv->count(); | 71 | int srvCount = ComboNtpSrv->count(); |
72 | ntpSrvs.writeEntry("count", srvCount); | 72 | ntpSrvs.writeEntry("count", srvCount); |
73 | for (int i = 0; i < srvCount; i++) | 73 | for (int i = 0; i < srvCount; i++) |
74 | { | 74 | { |
75 | ntpSrvs.setGroup(QString::number(i)); | 75 | ntpSrvs.setGroup(QString::number(i)); |
76 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); | 76 | ntpSrvs.writeEntry( "name", ComboNtpSrv->text(i) ); |
77 | } | 77 | } |
78 | Config cfg("ntp",Config::User); | 78 | Config cfg("ntp",Config::User); |
79 | cfg.setGroup("settings"); | 79 | cfg.setGroup("settings"); |
80 | cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); | 80 | cfg.writeEntry("ntpServer", ComboNtpSrv->currentItem()); |
81 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); | 81 | cfg.writeEntry( "minLookupDiff", SpinBoxMinLookupDelay->value() ); |
82 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); | 82 | cfg.writeEntry( "ntpRefreshFreq", SpinBoxNtpDelay->value() ); |
83 | } | 83 | } |
84 | 84 | ||
85 | bool Ntp::ntpDelayElapsed() | 85 | bool Ntp::ntpDelayElapsed() |
86 | { | 86 | { |
87 | Config cfg("ntp",Config::User); | 87 | Config cfg("ntp",Config::User); |
88 | cfg.setGroup("lookups"); | 88 | cfg.setGroup("lookups"); |
89 | _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); | 89 | _lookupDiff = TimeConversion::toUTC(QDateTime::currentDateTime()) - cfg.readNumEntry("time",0); |
90 | return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60; | 90 | return (_lookupDiff - (SpinBoxNtpDelay->value()*60)) > -60; |
91 | } | 91 | } |
92 | 92 | ||
93 | QString Ntp::getNtpServer() | 93 | QString Ntp::getNtpServer() |
94 | { | 94 | { |
95 | return ComboNtpSrv->currentText(); | 95 | return ComboNtpSrv->currentText(); |
96 | } | 96 | } |
97 | 97 | ||
98 | void Ntp::slotRunNtp() | 98 | void Ntp::slotRunNtp() |
99 | { | 99 | { |
100 | if ( !ntpDelayElapsed() ) | 100 | if ( !ntpDelayElapsed() ) |
101 | { | 101 | { |
102 | switch ( | 102 | switch ( |
103 | QMessageBox::warning(this, tr("Run NTP?"), | 103 | QMessageBox::warning(this, tr("Run NTP?"), |
104 | tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ | 104 | tr("You asked for a delay of ")+SpinBoxNtpDelay->text()+tr(" minutes, but only ")+ |
105 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+ | 105 | QString::number(_lookupDiff/60)+tr(" minutes elapsed since last loopup.")+ |
106 | "<br>"+tr("Rerun NTP?"), | 106 | "<br>"+tr("Rerun NTP?"), |
107 | QMessageBox::Ok,QMessageBox::Cancel) | 107 | QMessageBox::Ok,QMessageBox::Cancel) |
108 | ) { | 108 | ) { |
109 | case QMessageBox::Ok: break; | 109 | case QMessageBox::Ok: break; |
110 | case QMessageBox::Cancel: return; | 110 | case QMessageBox::Cancel: return; |
111 | default: return; | 111 | default: return; |
112 | } | 112 | } |
113 | } | 113 | } |
114 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); | 114 | TextLabelStartTime->setText(QDateTime::currentDateTime().toString()); |
115 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); | 115 | ntpOutPut( tr("Running:")+"\nntpdate "+getNtpServer() ); |
116 | 116 | ||
117 | ntpProcess->clearArguments(); | 117 | ntpProcess->clearArguments(); |
118 | *ntpProcess << "ntpdate" << getNtpServer(); | 118 | *ntpProcess << "ntpdate" << getNtpServer(); |
119 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); | 119 | bool ret = ntpProcess->start(OProcess::NotifyOnExit,OProcess::AllOutput); |
120 | if ( !ret ) { | 120 | if ( !ret ) { |
121 | qDebug("Error while executing ntpdate"); | 121 | qDebug("Error while executing ntpdate"); |
122 | ntpOutPut( tr("Error while executing ntpdate")); | 122 | ntpOutPut( tr("Error while executing ntpdate")); |
123 | } | 123 | } |
124 | } | 124 | } |
125 | 125 | ||
126 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) | 126 | void Ntp::getNtpOutput(OProcess *proc, char *buffer, int buflen) |
127 | { | 127 | { |
128 | QString lineStr, lineStrOld; | 128 | QString lineStr, lineStrOld; |
129 | lineStr = buffer; | 129 | lineStr = buffer; |
130 | lineStr=lineStr.left(buflen); | 130 | lineStr=lineStr.left(buflen); |
131 | if (lineStr!=lineStrOld) | 131 | if (lineStr!=lineStrOld) |
132 | { | 132 | { |
133 | ntpOutPut(lineStr); | 133 | ntpOutPut(lineStr); |
134 | _ntpOutput += lineStr; | 134 | _ntpOutput += lineStr; |
135 | } | 135 | } |
136 | lineStrOld = lineStr; | 136 | lineStrOld = lineStr; |
137 | } | 137 | } |
138 | 138 | ||
139 | void Ntp::ntpFinished(OProcess *p) | 139 | void Ntp::ntpFinished(OProcess *p) |
140 | { | 140 | { |
141 | qDebug("p->exitStatus() %i",p->exitStatus()); | 141 | qDebug("p->exitStatus() %i",p->exitStatus()); |
142 | if (p->exitStatus()!=0 || !p->normalExit()) | 142 | if (p->exitStatus()!=0 || !p->normalExit()) |
143 | { | 143 | { |
144 | slotProbeNtpServer(); | 144 | slotProbeNtpServer(); |
145 | return; | 145 | return; |
146 | } | 146 | } |
147 | Config cfg("ntp",Config::User); | 147 | Config cfg("ntp",Config::User); |
148 | cfg.setGroup("lookups"); | 148 | cfg.setGroup("lookups"); |
149 | int lastLookup = cfg.readNumEntry("time",0); | 149 | int lastLookup = cfg.readNumEntry("time",0); |
150 | int lookupCount = cfg.readNumEntry("count",0); | 150 | int lookupCount = cfg.readNumEntry("count",0); |
151 | bool lastNtp = cfg.readBoolEntry("lastNtp",false); | ||
151 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 152 | int time = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
152 | cfg.writeEntry("time", time); | 153 | cfg.writeEntry("time", time); |
153 | cfg.setGroup("correction"); | ||
154 | cfg.writeEntry("time", time); | ||
155 | 154 | ||
156 | float timeShift = getTimeShift(); | 155 | float timeShift = getTimeShift(); |
157 | if (timeShift == 0.0) return; | 156 | if (timeShift == 0.0) return; |
158 | int secsSinceLast = time - lastLookup; | 157 | int secsSinceLast = time - lastLookup; |
159 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); | 158 | TextLabelNewTime->setText(QDateTime::currentDateTime().toString()); |
160 | TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); | 159 | TextLabelTimeShift->setText(QString::number(timeShift)+tr(" seconds")); |
161 | if ( lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) | 160 | if ( lastNtp && lastLookup > 0 && secsSinceLast > 60* SpinBoxMinLookupDelay->value()) |
162 | { | 161 | { |
162 | cfg.setGroup("lookup_"+QString::number(lookupCount)); | ||
163 | lookupCount++; | 163 | lookupCount++; |
164 | cfg.writeEntry("count",lookupCount); | 164 | cfg.writeEntry("count",lookupCount); |
165 | cfg.setGroup("lookup_"+QString::number(lookupCount)); | ||
166 | _shiftPerSec = timeShift / secsSinceLast; | 165 | _shiftPerSec = timeShift / secsSinceLast; |
167 | qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); | 166 | qDebug("secs since last lookup %i", secsSinceLast);qDebug("timeshift since last lookup %f", timeShift);qDebug("timeshift since per sec %f", _shiftPerSec); |
168 | cfg.writeEntry("secsSinceLast",secsSinceLast); | 167 | cfg.writeEntry("secsSinceLast",secsSinceLast); |
169 | cfg.writeEntry("timeShift",QString::number(timeShift)); | 168 | cfg.writeEntry("timeShift",QString::number(timeShift)); |
169 | cfg.writeEntry("lastNtp",true); | ||
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | ||
173 | 173 | ||
174 | float Ntp::getTimeShift() | 174 | float Ntp::getTimeShift() |
175 | { | 175 | { |
176 | QString _offset = "offset"; | 176 | QString _offset = "offset"; |
177 | QString _sec = "sec"; | 177 | QString _sec = "sec"; |
178 | QRegExp _reOffset = QRegExp(_offset); | 178 | QRegExp _reOffset = QRegExp(_offset); |
179 | QRegExp _reEndOffset = QRegExp(_sec); | 179 | QRegExp _reEndOffset = QRegExp(_sec); |
180 | int posOffset = _reOffset.match( _ntpOutput ); | 180 | int posOffset = _reOffset.match( _ntpOutput ); |
181 | int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); | 181 | int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); |
182 | posOffset += _offset.length() + 1; | 182 | posOffset += _offset.length() + 1; |
183 | QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); | 183 | QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); |
184 | qDebug("%s", _ntpOutput.latin1()); | 184 | qDebug("%s", _ntpOutput.latin1()); |
185 | qDebug("diff = >%s<",diff.latin1()); | 185 | qDebug("diff = >%s<",diff.latin1()); |
186 | return diff.toFloat(); | 186 | return diff.toFloat(); |
187 | } | 187 | } |
188 | 188 | ||
189 | void Ntp::readLookups() | 189 | void Ntp::readLookups() |
190 | { | 190 | { |
191 | Config cfg("ntp",Config::User); | 191 | Config cfg("ntp",Config::User); |
192 | cfg.setGroup("lookups"); | 192 | cfg.setGroup("lookups"); |
193 | int lookupCount = cfg.readNumEntry("count",0); | 193 | int lookupCount = cfg.readNumEntry("count",0); |
194 | float last, shift, shiftPerSec; | 194 | float last, shift, shiftPerSec; |
195 | qDebug("lookupCount = %i",lookupCount); | 195 | qDebug("lookupCount = %i",lookupCount); |
196 | TableLookups->setNumCols( 3 ); | 196 | TableLookups->setNumCols( 3 ); |
197 | TableLookups->setNumRows( lookupCount); | 197 | TableLookups->setNumRows( lookupCount); |
198 | TableLookups->horizontalHeader()->setLabel(1,tr("last [h]")); | 198 | TableLookups->horizontalHeader()->setLabel(1,tr("last [h]")); |
199 | TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]")); | 199 | TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]")); |
200 | TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]")); | 200 | TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]")); |
201 | int cw = TableLookups->width()/4; | 201 | int cw = TableLookups->width()/4; |
202 | qDebug("column width %i",cw); | 202 | qDebug("column width %i",cw); |
203 | cw = 50; | 203 | cw = 50; |
204 | TableLookups->setColumnWidth( 0, cw+30 ); | 204 | TableLookups->setColumnWidth( 0, cw+30 ); |
205 | TableLookups->setColumnWidth( 1, cw ); | 205 | TableLookups->setColumnWidth( 1, cw ); |
206 | TableLookups->setColumnWidth( 2, cw ); | 206 | TableLookups->setColumnWidth( 2, cw ); |
207 | TableLookups->sortColumn(0, false, true ); | 207 | TableLookups->sortColumn(0, false, true ); |
208 | // TableLookups->setSorting( true ); | 208 | // TableLookups->setSorting( true ); |
209 | for (int i=0; i < lookupCount; i++) | 209 | for (int i=0; i < lookupCount; i++) |
210 | { | 210 | { |
211 | cfg.setGroup("lookup_"+QString::number(i)); | 211 | cfg.setGroup("lookup_"+QString::number(i)); |
212 | last = cfg.readEntry("secsSinceLast",0).toFloat(); | 212 | last = cfg.readEntry("secsSinceLast",0).toFloat(); |
213 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); | 213 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); |
214 | // qDebug("%i last %f",i,last); | 214 | // qDebug("%i last %f",i,last); |
215 | // qDebug("%i shift %f",i,shift); | 215 | // qDebug("%i shift %f",i,shift); |
216 | shiftPerSec = shift / last; | 216 | shiftPerSec = shift / last; |
217 | _shiftPerSec += shiftPerSec; | 217 | _shiftPerSec += shiftPerSec; |
218 | TableLookups->setText( i,0,QString::number(shiftPerSec*60*60)); | 218 | TableLookups->setText( i,0,QString::number(shiftPerSec*60*60)); |
219 | TableLookups->setText( i,2,QString::number(shift)); | 219 | TableLookups->setText( i,2,QString::number(shift)); |
220 | TableLookups->setText( i,1,QString::number(last/(60*60))); | 220 | TableLookups->setText( i,1,QString::number(last/(60*60))); |
221 | } | 221 | } |
222 | _shiftPerSec /= lookupCount; | 222 | _shiftPerSec /= lookupCount; |
223 | TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h")); | 223 | TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h")); |
224 | } | 224 | } |
225 | 225 | ||
226 | void Ntp::preditctTime() | 226 | void Ntp::preditctTime() |
227 | { | 227 | { |
228 | Config cfg("ntp",Config::User); | 228 | Config cfg("ntp",Config::User); |
229 | cfg.setGroup("lookups"); | 229 | cfg.setGroup("lookups"); |
230 | int lastTime = cfg.readNumEntry("time",0); | 230 | int lastTime = cfg.readNumEntry("time",0); |
231 | cfg.writeEntry("lastNtp",true); | ||
231 | setenv( "TZ", tz->currentZone(), 1 ); | 232 | setenv( "TZ", tz->currentZone(), 1 ); |
232 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 233 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
233 | int corr = int((now - lastTime) * _shiftPerSec); | 234 | int corr = int((now - lastTime) * _shiftPerSec); |
234 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); | 235 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); |
235 | predictedTime = QDateTime::currentDateTime().addSecs(corr); | 236 | predictedTime = QDateTime::currentDateTime().addSecs(corr); |
236 | TextLabelPredTime->setText(predictedTime.toString()); | 237 | TextLabelPredTime->setText(predictedTime.toString()); |
237 | TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); | 238 | TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); |
238 | } | 239 | } |
239 | 240 | ||
240 | void Ntp::setPredictTime() | 241 | void Ntp::setPredictTime() |
241 | { | 242 | { |
242 | preditctTime(); | 243 | preditctTime(); |
243 | setTime( predictedTime ); | 244 | setTime( predictedTime ); |
244 | } | 245 | } |
245 | 246 | ||
246 | void Ntp::slotCheckNtp(int i) | 247 | void Ntp::slotCheckNtp(int i) |
247 | { | 248 | { |
248 | if (i == 0) | 249 | if (i == 0) |
249 | { | 250 | { |
250 | TextLabelMainPredTime->hide(); | 251 | TextLabelMainPredTime->hide(); |
251 | ButtonSetTime->setText( tr("Get time from network") ); | 252 | ButtonSetTime->setText( tr("Get time from network") ); |
252 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); | 253 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); |
253 | if ( ntpDelayElapsed() ) | 254 | if ( ntpDelayElapsed() ) |
254 | { | 255 | { |
255 | slotRunNtp(); | 256 | slotRunNtp(); |
256 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); | 257 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); |
257 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); | 258 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); |
258 | }else{ | 259 | }else{ |
259 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); | 260 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); |
260 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 261 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
261 | } | 262 | } |
262 | }else{ | 263 | }else{ |
263 | preditctTime(); | 264 | preditctTime(); |
264 | ButtonSetTime->setText( tr("Set predicted time") ); | 265 | ButtonSetTime->setText( tr("Set predicted time") ); |
265 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); | 266 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); |
266 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); | 267 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); |
267 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 268 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
268 | } | 269 | } |
269 | } | 270 | } |
270 | 271 | ||
271 | void Ntp::slotProbeNtpServer() | 272 | void Ntp::slotProbeNtpServer() |
272 | { | 273 | { |
273 | qDebug("Ntp::slotProbeNtpServer()"); | 274 | qDebug("Ntp::slotProbeNtpServer()"); |
274 | ntpSock->connectToHost( getNtpServer() ,123); | 275 | ntpSock->connectToHost( getNtpServer() ,123); |
275 | } | 276 | } |
276 | 277 | ||
277 | void Ntp::slotNtpDelayChanged(int delay) | 278 | void Ntp::slotNtpDelayChanged(int delay) |
278 | { | 279 | { |
279 | ntpTimer->changeInterval( delay*1000*60 ); | 280 | ntpTimer->changeInterval( delay*1000*60 ); |
280 | } | 281 | } |
281 | 282 | ||
282 | void Ntp::ntpOutPut(QString out) | 283 | void Ntp::ntpOutPut(QString out) |
283 | { | 284 | { |
284 | MultiLineEditntpOutPut->append(out); | 285 | MultiLineEditntpOutPut->append(out); |
285 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); | 286 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); |
286 | } | 287 | } |
287 | 288 | ||
diff --git a/noncore/settings/netsystemtime/settime.cpp b/noncore/settings/netsystemtime/settime.cpp index e7e604f..9c5323a 100644 --- a/noncore/settings/netsystemtime/settime.cpp +++ b/noncore/settings/netsystemtime/settime.cpp | |||
@@ -137,192 +137,195 @@ SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f ) | |||
137 | 137 | ||
138 | 138 | ||
139 | QHBoxLayout *hb3 = new QHBoxLayout( vb ); | 139 | QHBoxLayout *hb3 = new QHBoxLayout( vb ); |
140 | l = new QLabel( tr("Date format" ), FrameSystemTime ); | 140 | l = new QLabel( tr("Date format" ), FrameSystemTime ); |
141 | hb3->addWidget( l, 1 ); | 141 | hb3->addWidget( l, 1 ); |
142 | dateFormatCombo = new QComboBox( FrameSystemTime ); | 142 | dateFormatCombo = new QComboBox( FrameSystemTime ); |
143 | hb3->addWidget( dateFormatCombo, 2 ); | 143 | hb3->addWidget( dateFormatCombo, 2 ); |
144 | 144 | ||
145 | config.setGroup( "Date" ); | 145 | config.setGroup( "Date" ); |
146 | DateFormat df(QChar(config.readEntry("Separator", "/")[0]), | 146 | DateFormat df(QChar(config.readEntry("Separator", "/")[0]), |
147 | (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear), | 147 | (DateFormat::Order)config .readNumEntry("ShortOrder", DateFormat::DayMonthYear), |
148 | (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear)); | 148 | (DateFormat::Order)config.readNumEntry("LongOrder", DateFormat::DayMonthYear)); |
149 | 149 | ||
150 | int currentdf = 0; | 150 | int currentdf = 0; |
151 | date_formats[0] = DateFormat('/', DateFormat::MonthDayYear); | 151 | date_formats[0] = DateFormat('/', DateFormat::MonthDayYear); |
152 | dateFormatCombo->insertItem( tr( date_formats[0].toNumberString()) ); | 152 | dateFormatCombo->insertItem( tr( date_formats[0].toNumberString()) ); |
153 | date_formats[1] = DateFormat('.', DateFormat::DayMonthYear); | 153 | date_formats[1] = DateFormat('.', DateFormat::DayMonthYear); |
154 | if (df == date_formats[1]) | 154 | if (df == date_formats[1]) |
155 | currentdf = 1; | 155 | currentdf = 1; |
156 | dateFormatCombo->insertItem( tr( date_formats[1].toNumberString() ) ); | 156 | dateFormatCombo->insertItem( tr( date_formats[1].toNumberString() ) ); |
157 | date_formats[2] = DateFormat('-', DateFormat::YearMonthDay, | 157 | date_formats[2] = DateFormat('-', DateFormat::YearMonthDay, |
158 | DateFormat::DayMonthYear); | 158 | DateFormat::DayMonthYear); |
159 | if (df == date_formats[2]) | 159 | if (df == date_formats[2]) |
160 | currentdf = 2; | 160 | currentdf = 2; |
161 | dateFormatCombo->insertItem( tr( date_formats[2].toNumberString() ) ); //ISO8601 | 161 | dateFormatCombo->insertItem( tr( date_formats[2].toNumberString() ) ); //ISO8601 |
162 | date_formats[3] = DateFormat('/', DateFormat::DayMonthYear); | 162 | date_formats[3] = DateFormat('/', DateFormat::DayMonthYear); |
163 | if (df == date_formats[3]) | 163 | if (df == date_formats[3]) |
164 | currentdf = 3; | 164 | currentdf = 3; |
165 | dateFormatCombo->insertItem( tr( date_formats[3].toNumberString() ) ); | 165 | dateFormatCombo->insertItem( tr( date_formats[3].toNumberString() ) ); |
166 | 166 | ||
167 | dateFormatCombo->setCurrentItem( currentdf ); | 167 | dateFormatCombo->setCurrentItem( currentdf ); |
168 | dateButton->setDateFormat( df ); | 168 | dateButton->setDateFormat( df ); |
169 | 169 | ||
170 | connect( dateFormatCombo, SIGNAL( activated(int)), | 170 | connect( dateFormatCombo, SIGNAL( activated(int)), |
171 | SLOT(formatChanged(int))); | 171 | SLOT(formatChanged(int))); |
172 | 172 | ||
173 | QHBoxLayout *hb4 = new QHBoxLayout( vb ); | 173 | QHBoxLayout *hb4 = new QHBoxLayout( vb ); |
174 | l = new QLabel( tr("Applet format" ), FrameSystemTime ); | 174 | l = new QLabel( tr("Applet format" ), FrameSystemTime ); |
175 | hb4->addWidget( l, 1 ); | 175 | hb4->addWidget( l, 1 ); |
176 | 176 | ||
177 | clockAppletCombo = new QComboBox( FrameSystemTime ); | 177 | clockAppletCombo = new QComboBox( FrameSystemTime ); |
178 | clockAppletCombo->insertItem( tr("hh:mm"), 0 ); | 178 | clockAppletCombo->insertItem( tr("hh:mm"), 0 ); |
179 | clockAppletCombo->insertItem( tr("D/M hh:mm"), 1 ); | 179 | clockAppletCombo->insertItem( tr("D/M hh:mm"), 1 ); |
180 | clockAppletCombo->insertItem( tr("M/D hh:mm"), 2 ); | 180 | clockAppletCombo->insertItem( tr("M/D hh:mm"), 2 ); |
181 | 181 | ||
182 | hb4->addWidget( clockAppletCombo, 2 ); | 182 | hb4->addWidget( clockAppletCombo, 2 ); |
183 | int clockApplet = config.readNumEntry("ClockApplet",0); | 183 | int clockApplet = config.readNumEntry("ClockApplet",0); |
184 | clockAppletCombo->setCurrentItem( clockApplet ); | 184 | clockAppletCombo->setCurrentItem( clockApplet ); |
185 | 185 | ||
186 | vb->addStretch( 0 ); | 186 | vb->addStretch( 0 ); |
187 | 187 | ||
188 | QObject::connect( PushButtonSetManualTime, SIGNAL(clicked()), | 188 | QObject::connect( PushButtonSetManualTime, SIGNAL(clicked()), |
189 | this, SLOT(commitTime())); | 189 | this, SLOT(commitTime())); |
190 | 190 | ||
191 | QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), | 191 | QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), |
192 | timeButton, SLOT( slotTzChange( const QString& ) ) ); | 192 | timeButton, SLOT( slotTzChange( const QString& ) ) ); |
193 | QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), | 193 | QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), |
194 | SLOT( tzChange( const QString& ) ) ); | 194 | SLOT( tzChange( const QString& ) ) ); |
195 | 195 | ||
196 | QObject::connect( weekStartCombo, SIGNAL( activated ( int )), | 196 | QObject::connect( weekStartCombo, SIGNAL( activated ( int )), |
197 | SLOT(updateSystem(int ) )); | 197 | SLOT(updateSystem(int ) )); |
198 | QObject::connect( ampmCombo, SIGNAL( activated ( int )), | 198 | QObject::connect( ampmCombo, SIGNAL( activated ( int )), |
199 | SLOT(updateSystem(int ) )); | 199 | SLOT(updateSystem(int ) )); |
200 | QObject::connect( dateFormatCombo, SIGNAL( activated ( int )), | 200 | QObject::connect( dateFormatCombo, SIGNAL( activated ( int )), |
201 | SLOT(updateSystem(int ) )); | 201 | SLOT(updateSystem(int ) )); |
202 | QObject::connect( clockAppletCombo, SIGNAL( activated ( int )), | 202 | QObject::connect( clockAppletCombo, SIGNAL( activated ( int )), |
203 | SLOT(updateSystem(int ) )); | 203 | SLOT(updateSystem(int ) )); |
204 | } | 204 | } |
205 | 205 | ||
206 | SetDateTime::~SetDateTime() | 206 | SetDateTime::~SetDateTime() |
207 | { | 207 | { |
208 | writeSettings(); | 208 | writeSettings(); |
209 | 209 | ||
210 | } | 210 | } |
211 | 211 | ||
212 | void SetDateTime::writeSettings() | 212 | void SetDateTime::writeSettings() |
213 | { | 213 | { |
214 | Config config("qpe"); | 214 | Config config("qpe"); |
215 | config.setGroup( "Time" ); | 215 | config.setGroup( "Time" ); |
216 | config.writeEntry( "AMPM", ampmCombo->currentItem() ); | 216 | config.writeEntry( "AMPM", ampmCombo->currentItem() ); |
217 | config.writeEntry( "MONDAY", weekStartCombo->currentItem() ); | 217 | config.writeEntry( "MONDAY", weekStartCombo->currentItem() ); |
218 | config.setGroup( "Date" ); | 218 | config.setGroup( "Date" ); |
219 | DateFormat df = date_formats[dateFormatCombo->currentItem()]; | 219 | DateFormat df = date_formats[dateFormatCombo->currentItem()]; |
220 | config.writeEntry( "Separator", QString(df.separator())); | 220 | config.writeEntry( "Separator", QString(df.separator())); |
221 | config.writeEntry( "ShortOrder", df.shortOrder()); | 221 | config.writeEntry( "ShortOrder", df.shortOrder()); |
222 | config.writeEntry( "LongOrder", df.longOrder()); | 222 | config.writeEntry( "LongOrder", df.longOrder()); |
223 | config.writeEntry( "ClockApplet", clockAppletCombo->currentItem() ); | 223 | config.writeEntry( "ClockApplet", clockAppletCombo->currentItem() ); |
224 | 224 | ||
225 | Config lconfig("locale"); | 225 | Config lconfig("locale"); |
226 | lconfig.setGroup( "Location" ); | 226 | lconfig.setGroup( "Location" ); |
227 | lconfig.writeEntry( "Timezone", tz->currentZone() ); | 227 | lconfig.writeEntry( "Timezone", tz->currentZone() ); |
228 | 228 | ||
229 | } | 229 | } |
230 | 230 | ||
231 | void SetDateTime::commitTime() | 231 | void SetDateTime::commitTime() |
232 | { | 232 | { |
233 | Config cfg("ntp",Config::User); | ||
234 | cfg.setGroup("lookups"); | ||
235 | cfg.writeEntry("lastNtp",false); | ||
233 | tz->setFocus(); | 236 | tz->setFocus(); |
234 | // Need to process the QCOP event generated above before proceeding | 237 | // Need to process the QCOP event generated above before proceeding |
235 | qApp->processEvents(); | 238 | qApp->processEvents(); |
236 | 239 | ||
237 | // before we progress further, set our TZ! | 240 | // before we progress further, set our TZ! |
238 | setenv( "TZ", tz->currentZone(), 1 ); | 241 | setenv( "TZ", tz->currentZone(), 1 ); |
239 | // now set the time... | 242 | // now set the time... |
240 | QDateTime dt( dateButton->date(), timeButton->time() ); | 243 | QDateTime dt( dateButton->date(), timeButton->time() ); |
241 | 244 | ||
242 | if ( dt.isValid() ) setTime(dt); | 245 | if ( dt.isValid() ) setTime(dt); |
243 | } | 246 | } |
244 | 247 | ||
245 | void SetDateTime::setTime(QDateTime dt) | 248 | void SetDateTime::setTime(QDateTime dt) |
246 | { | 249 | { |
247 | // really turn off the screensaver before doing anything | 250 | // really turn off the screensaver before doing anything |
248 | { | 251 | { |
249 | // Needs to be encased in { } so that it deconstructs and sends | 252 | // Needs to be encased in { } so that it deconstructs and sends |
250 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 253 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
251 | disableScreenSaver << 0 << 0 << 0; | 254 | disableScreenSaver << 0 << 0 << 0; |
252 | } | 255 | } |
253 | Config cfg("ntp",Config::User); | 256 | Config cfg("ntp",Config::User); |
254 | cfg.setGroup("correction"); | 257 | cfg.setGroup("correction"); |
255 | int t = TimeConversion::toUTC(dt); | 258 | int t = TimeConversion::toUTC(dt); |
256 | struct timeval myTv; | 259 | struct timeval myTv; |
257 | myTv.tv_sec = t; | 260 | myTv.tv_sec = t; |
258 | cfg.writeEntry("time", t ); | 261 | cfg.writeEntry("time", t ); |
259 | myTv.tv_usec = 0; | 262 | myTv.tv_usec = 0; |
260 | 263 | ||
261 | if ( myTv.tv_sec != -1 ) | 264 | if ( myTv.tv_sec != -1 ) |
262 | ::settimeofday( &myTv, 0 ); | 265 | ::settimeofday( &myTv, 0 ); |
263 | Global::writeHWClock(); | 266 | Global::writeHWClock(); |
264 | // since time has changed quickly load in the datebookdb | 267 | // since time has changed quickly load in the datebookdb |
265 | // to allow the alarm server to get a better grip on itself | 268 | // to allow the alarm server to get a better grip on itself |
266 | // (example re-trigger alarms for when we travel back in time) | 269 | // (example re-trigger alarms for when we travel back in time) |
267 | DateBookDB db; | 270 | DateBookDB db; |
268 | // Restore screensaver | 271 | // Restore screensaver |
269 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 272 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
270 | enableScreenSaver << -1 << -1 << -1; | 273 | enableScreenSaver << -1 << -1 << -1; |
271 | } | 274 | } |
272 | 275 | ||
273 | void SetDateTime::updateSystem(int i) | 276 | void SetDateTime::updateSystem(int i) |
274 | { | 277 | { |
275 | // really turn off the screensaver before doing anything | 278 | // really turn off the screensaver before doing anything |
276 | { | 279 | { |
277 | // Needs to be encased in { } so that it deconstructs and sends | 280 | // Needs to be encased in { } so that it deconstructs and sends |
278 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 281 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
279 | disableScreenSaver << 0 << 0 << 0; | 282 | disableScreenSaver << 0 << 0 << 0; |
280 | } | 283 | } |
281 | qDebug("SetDateTime::updateSystem(int %i)",i); | 284 | qDebug("SetDateTime::updateSystem(int %i)",i); |
282 | writeSettings(); | 285 | writeSettings(); |
283 | 286 | ||
284 | // set the timezone for everyone else... | 287 | // set the timezone for everyone else... |
285 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); | 288 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); |
286 | setTimeZone << tz->currentZone(); | 289 | setTimeZone << tz->currentZone(); |
287 | 290 | ||
288 | // AM/PM setting and notify time changed | 291 | // AM/PM setting and notify time changed |
289 | QCopEnvelope setClock( "QPE/System", "clockChange(bool)" ); | 292 | QCopEnvelope setClock( "QPE/System", "clockChange(bool)" ); |
290 | setClock << ampmCombo->currentItem(); | 293 | setClock << ampmCombo->currentItem(); |
291 | 294 | ||
292 | // Notify everyone what day we prefer to start the week on. | 295 | // Notify everyone what day we prefer to start the week on. |
293 | QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" ); | 296 | QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" ); |
294 | setWeek << weekStartCombo->currentItem(); | 297 | setWeek << weekStartCombo->currentItem(); |
295 | 298 | ||
296 | // Notify everyone what date format to use | 299 | // Notify everyone what date format to use |
297 | QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" ); | 300 | QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" ); |
298 | setDateFormat << date_formats[dateFormatCombo->currentItem()]; | 301 | setDateFormat << date_formats[dateFormatCombo->currentItem()]; |
299 | 302 | ||
300 | // Restore screensaver | 303 | // Restore screensaver |
301 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 304 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
302 | enableScreenSaver << -1 << -1 << -1; | 305 | enableScreenSaver << -1 << -1 << -1; |
303 | // since time has changed quickly load in the datebookdb | 306 | // since time has changed quickly load in the datebookdb |
304 | // to allow the alarm server to get a better grip on itself | 307 | // to allow the alarm server to get a better grip on itself |
305 | // (example re-trigger alarms for when we travel back in time) | 308 | // (example re-trigger alarms for when we travel back in time) |
306 | DateBookDB db; | 309 | DateBookDB db; |
307 | 310 | ||
308 | } | 311 | } |
309 | 312 | ||
310 | void SetDateTime::tzChange( const QString &tz ) | 313 | void SetDateTime::tzChange( const QString &tz ) |
311 | { | 314 | { |
312 | // set the TZ get the time and leave gracefully... | 315 | // set the TZ get the time and leave gracefully... |
313 | QString strSave; | 316 | QString strSave; |
314 | strSave = getenv( "TZ" ); | 317 | strSave = getenv( "TZ" ); |
315 | setenv( "TZ", tz, 1 ); | 318 | setenv( "TZ", tz, 1 ); |
316 | 319 | ||
317 | QDate d = QDate::currentDate(); | 320 | QDate d = QDate::currentDate(); |
318 | // reset the time. | 321 | // reset the time. |
319 | if ( !strSave.isNull() ) { | 322 | if ( !strSave.isNull() ) { |
320 | setenv( "TZ", strSave, 1 ); | 323 | setenv( "TZ", strSave, 1 ); |
321 | } | 324 | } |
322 | dateButton->setDate( d ); | 325 | dateButton->setDate( d ); |
323 | updateSystem(); | 326 | updateSystem(); |
324 | } | 327 | } |
325 | 328 | ||
326 | void SetDateTime::formatChanged(int i) | 329 | void SetDateTime::formatChanged(int i) |
327 | { | 330 | { |
328 | dateButton->setDateFormat(date_formats[i]); | 331 | dateButton->setDateFormat(date_formats[i]); |