-rw-r--r-- | noncore/settings/netsystemtime/ntp.cpp | 10 | ||||
-rw-r--r-- | noncore/settings/netsystemtime/settime.cpp | 6 |
2 files changed, 10 insertions, 6 deletions
diff --git a/noncore/settings/netsystemtime/ntp.cpp b/noncore/settings/netsystemtime/ntp.cpp index 2b779fa..15dae93 100644 --- a/noncore/settings/netsystemtime/ntp.cpp +++ b/noncore/settings/netsystemtime/ntp.cpp | |||
@@ -185,141 +185,145 @@ void Ntp::ntpFinished(OProcess *p) | |||
185 | 185 | ||
186 | float Ntp::getTimeShift() | 186 | float Ntp::getTimeShift() |
187 | { | 187 | { |
188 | QString _offset = "offset"; | 188 | QString _offset = "offset"; |
189 | QString _sec = "sec"; | 189 | QString _sec = "sec"; |
190 | QRegExp _reOffset = QRegExp(_offset); | 190 | QRegExp _reOffset = QRegExp(_offset); |
191 | QRegExp _reEndOffset = QRegExp(_sec); | 191 | QRegExp _reEndOffset = QRegExp(_sec); |
192 | int posOffset = _reOffset.match( _ntpOutput ); | 192 | int posOffset = _reOffset.match( _ntpOutput ); |
193 | int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); | 193 | int posEndOffset = _reEndOffset.match( _ntpOutput, posOffset ); |
194 | posOffset += _offset.length() + 1; | 194 | posOffset += _offset.length() + 1; |
195 | QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); | 195 | QString diff = _ntpOutput.mid(posOffset, posEndOffset-posOffset-1); |
196 | qDebug("%s", _ntpOutput.latin1()); | 196 | qDebug("%s", _ntpOutput.latin1()); |
197 | qDebug("diff = >%s<",diff.latin1()); | 197 | qDebug("diff = >%s<",diff.latin1()); |
198 | return diff.toFloat(); | 198 | return diff.toFloat(); |
199 | } | 199 | } |
200 | 200 | ||
201 | void Ntp::readLookups() | 201 | void Ntp::readLookups() |
202 | { | 202 | { |
203 | Config cfg("ntp",Config::User); | 203 | Config cfg("ntp",Config::User); |
204 | cfg.setGroup("lookups"); | 204 | cfg.setGroup("lookups"); |
205 | int lookupCount = cfg.readNumEntry("count",0); | 205 | int lookupCount = cfg.readNumEntry("count",0); |
206 | float last, shift, shiftPerSec; | 206 | float last, shift, shiftPerSec; |
207 | qDebug("lookupCount = %i",lookupCount); | 207 | qDebug("lookupCount = %i",lookupCount); |
208 | TableLookups->setNumCols( 3 ); | 208 | TableLookups->setNumCols( 3 ); |
209 | TableLookups->setNumRows( lookupCount); | 209 | TableLookups->setNumRows( lookupCount); |
210 | TableLookups->horizontalHeader()->setLabel(1,tr("last [h]")); | 210 | TableLookups->horizontalHeader()->setLabel(1,tr("last [h]")); |
211 | TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]")); | 211 | TableLookups->horizontalHeader()->setLabel(2,tr("offset [s]")); |
212 | TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]")); | 212 | TableLookups->horizontalHeader()->setLabel(0,tr("shift [s/h]")); |
213 | int cw = TableLookups->width()/4; | 213 | int cw = TableLookups->width()/4; |
214 | qDebug("column width %i",cw); | 214 | qDebug("column width %i",cw); |
215 | cw = 50; | 215 | cw = 50; |
216 | TableLookups->setColumnWidth( 0, cw+30 ); | 216 | TableLookups->setColumnWidth( 0, cw+30 ); |
217 | TableLookups->setColumnWidth( 1, cw ); | 217 | TableLookups->setColumnWidth( 1, cw ); |
218 | TableLookups->setColumnWidth( 2, cw ); | 218 | TableLookups->setColumnWidth( 2, cw ); |
219 | TableLookups->sortColumn(0, false, true ); | 219 | TableLookups->sortColumn(0, false, true ); |
220 | // TableLookups->setSorting( true ); | 220 | // TableLookups->setSorting( true ); |
221 | _shiftPerSec = 0; | 221 | _shiftPerSec = 0; |
222 | for (int i=0; i < lookupCount; i++) | 222 | for (int i=0; i < lookupCount; i++) |
223 | { | 223 | { |
224 | cfg.setGroup("lookup_"+QString::number(i)); | 224 | cfg.setGroup("lookup_"+QString::number(i)); |
225 | last = cfg.readEntry("secsSinceLast",0).toFloat(); | 225 | last = cfg.readEntry("secsSinceLast",0).toFloat(); |
226 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); | 226 | shift = QString(cfg.readEntry("timeShift",0)).toFloat(); |
227 | shiftPerSec = shift / last; | 227 | shiftPerSec = shift / last; |
228 | qDebug("%i shift %f",i,shiftPerSec); | 228 | qDebug("%i shift %f",i,shiftPerSec); |
229 | _shiftPerSec += shiftPerSec; | 229 | _shiftPerSec += shiftPerSec; |
230 | TableLookups->setText( i,0,QString::number(shiftPerSec*60*60)); | 230 | TableLookups->setText( i,0,QString::number(shiftPerSec*60*60)); |
231 | TableLookups->setText( i,2,QString::number(shift)); | 231 | TableLookups->setText( i,2,QString::number(shift)); |
232 | TableLookups->setText( i,1,QString::number(last/(60*60))); | 232 | TableLookups->setText( i,1,QString::number(last/(60*60))); |
233 | } | 233 | } |
234 | _shiftPerSec /= lookupCount; | 234 | _shiftPerSec /= lookupCount; |
235 | TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h")); | 235 | TextLabelShift->setText(QString::number(_shiftPerSec*60*60)+tr(" s/h")); |
236 | } | 236 | } |
237 | 237 | ||
238 | void Ntp::preditctTime() | 238 | void Ntp::preditctTime() |
239 | { | 239 | { |
240 | Config cfg("ntp",Config::User); | 240 | Config cfg("ntp",Config::User); |
241 | cfg.setGroup("lookups"); | 241 | cfg.setGroup("lookups"); |
242 | int lastTime = cfg.readNumEntry("time",0); | 242 | int lastTime = cfg.readNumEntry("time",0); |
243 | cfg.writeEntry("lastNtp",true); | 243 | cfg.writeEntry("lastNtp",true); |
244 | setenv( "TZ", tz->currentZone(), 1 ); | 244 | setenv( "TZ", tz->currentZone(), 1 ); |
245 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); | 245 | int now = TimeConversion::toUTC( QDateTime::currentDateTime() ); |
246 | int corr = int((now - lastTime) * _shiftPerSec); | 246 | int corr = int((now - lastTime) * _shiftPerSec); |
247 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); | 247 | TextLabelEstimatedShift->setText(QString::number(corr)+tr(" seconds")); |
248 | predictedTime = QDateTime::currentDateTime().addSecs(corr); | 248 | predictedTime = QDateTime::currentDateTime().addSecs(corr); |
249 | TextLabelPredTime->setText(predictedTime.toString()); | 249 | TextLabelPredTime->setText(predictedTime.toString()); |
250 | TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); | 250 | TextLabelMainPredTime->setText(tr("Predicted time:")+"<br><b>"+predictedTime.toString()+"</b>"); |
251 | } | 251 | } |
252 | 252 | ||
253 | void Ntp::setPredictTime() | 253 | void Ntp::setPredictTime() |
254 | { | 254 | { |
255 | preditctTime(); | 255 | preditctTime(); |
256 | setTime( predictedTime ); | 256 | setTime( predictedTime ); |
257 | } | 257 | } |
258 | 258 | ||
259 | void Ntp::slotCheckNtp(int i) | 259 | void Ntp::slotCheckNtp(int i) |
260 | { | 260 | { |
261 | if (i == 0) | 261 | if (i == 0) |
262 | { | 262 | { |
263 | TextLabelMainPredTime->hide(); | 263 | TextLabelMainPredTime->hide(); |
264 | ButtonSetTime->setText( tr("Get time from network") ); | 264 | ButtonSetTime->setText( tr("Get time from network") ); |
265 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); | 265 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(slotRunNtp()) ); |
266 | if ( ntpDelayElapsed() ) | 266 | if ( ntpDelayElapsed() ) |
267 | { | 267 | { |
268 | slotRunNtp(); | 268 | slotRunNtp(); |
269 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); | 269 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotProbeNtpServer()) ); |
270 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); | 270 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotRunNtp()) ); |
271 | }else{ | 271 | }else{ |
272 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); | 272 | disconnect(ntpTimer, SIGNAL( timeout() ), this, SLOT(slotRunNtp()) ); |
273 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 273 | connect(ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
274 | } | 274 | } |
275 | }else{ | 275 | }else{ |
276 | preditctTime(); | 276 | preditctTime(); |
277 | ButtonSetTime->setText( tr("Set predicted time") ); | 277 | ButtonSetTime->setText( tr("Set predicted time") ); |
278 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); | 278 | if (i>0)ntpOutPut(tr("Could not connect to server ")+getNtpServer()); |
279 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); | 279 | connect( ButtonSetTime, SIGNAL(clicked()), SLOT(setPredictTime()) ); |
280 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); | 280 | connect( ntpTimer, SIGNAL( timeout() ), SLOT(slotProbeNtpServer()) ); |
281 | } | 281 | } |
282 | } | 282 | } |
283 | 283 | ||
284 | void Ntp::slotProbeNtpServer() | 284 | void Ntp::slotProbeNtpServer() |
285 | { | 285 | { |
286 | qDebug("Ntp::slotProbeNtpServer()"); | 286 | qDebug("Ntp::slotProbeNtpServer()"); |
287 | ntpSock->connectToHost( getNtpServer() ,123); | 287 | ntpSock->connectToHost( getNtpServer() ,123); |
288 | } | 288 | } |
289 | 289 | ||
290 | void Ntp::slotNtpDelayChanged(int delay) | 290 | void Ntp::slotNtpDelayChanged(int delay) |
291 | { | 291 | { |
292 | ntpTimer->changeInterval( delay*1000*60 ); | 292 | ntpTimer->changeInterval( delay*1000*60 ); |
293 | } | 293 | } |
294 | 294 | ||
295 | void Ntp::ntpOutPut(QString out) | 295 | void Ntp::ntpOutPut(QString out) |
296 | { | 296 | { |
297 | MultiLineEditntpOutPut->append(out); | 297 | MultiLineEditntpOutPut->append(out); |
298 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); | 298 | MultiLineEditntpOutPut->setCursorPosition(MultiLineEditntpOutPut->numLines() + 1,0,FALSE); |
299 | } | 299 | } |
300 | 300 | ||
301 | 301 | ||
302 | void Ntp::makeChannel() | 302 | void Ntp::makeChannel() |
303 | { | 303 | { |
304 | channel = new QCopChannel( "QPE/Application/netsystemtime", this ); | 304 | channel = new QCopChannel( "QPE/Application/netsystemtime", this ); |
305 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), | 305 | connect( channel, SIGNAL(received(const QCString&, const QByteArray&)), |
306 | this, SLOT(receive(const QCString&, const QByteArray&)) ); | 306 | this, SLOT(receive(const QCString&, const QByteArray&)) ); |
307 | } | 307 | } |
308 | 308 | ||
309 | 309 | ||
310 | 310 | ||
311 | void Ntp::receive(const QCString &msg, const QByteArray &arg) | 311 | void Ntp::receive(const QCString &msg, const QByteArray &arg) |
312 | { | 312 | { |
313 | qDebug("QCop "+msg+" "+QCString(arg)); | 313 | qDebug("QCop(Ntp) "+msg+" "+QCString(arg)); |
314 | if ( msg == "open(QString)" ) | 314 | if ( msg == "ntpLookup(QString)" ) |
315 | { | 315 | { |
316 | //qApp->exec(); | 316 | slotRunNtp(); |
317 | } | ||
318 | if ( msg == "setPredictedTime(QString)" ) | ||
319 | { | ||
320 | setPredictTime(); | ||
317 | }else{ | 321 | }else{ |
318 | qDebug("Ntp::receive: Huh what do ya want"); | 322 | qDebug("Ntp::receive: Huh what do ya want"); |
319 | } | 323 | } |
320 | } | 324 | } |
321 | 325 | ||
322 | void Ntp::setDocument(const QString &fileName) | 326 | void Ntp::setDocument(const QString &fileName) |
323 | { | 327 | { |
324 | 328 | ||
325 | } \ No newline at end of file | 329 | } \ No newline at end of file |
diff --git a/noncore/settings/netsystemtime/settime.cpp b/noncore/settings/netsystemtime/settime.cpp index 9c5323a..b0fcb74 100644 --- a/noncore/settings/netsystemtime/settime.cpp +++ b/noncore/settings/netsystemtime/settime.cpp | |||
@@ -143,259 +143,259 @@ SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f ) | |||
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); | 233 | Config cfg("ntp",Config::User); |
234 | cfg.setGroup("lookups"); | 234 | cfg.setGroup("lookups"); |
235 | cfg.writeEntry("lastNtp",false); | 235 | cfg.writeEntry("lastNtp",false); |
236 | tz->setFocus(); | 236 | tz->setFocus(); |
237 | // Need to process the QCOP event generated above before proceeding | 237 | // Need to process the QCOP event generated above before proceeding |
238 | qApp->processEvents(); | 238 | qApp->processEvents(); |
239 | 239 | ||
240 | // before we progress further, set our TZ! | 240 | // before we progress further, set our TZ! |
241 | setenv( "TZ", tz->currentZone(), 1 ); | 241 | setenv( "TZ", tz->currentZone(), 1 ); |
242 | // now set the time... | 242 | // now set the time... |
243 | QDateTime dt( dateButton->date(), timeButton->time() ); | 243 | QDateTime dt( dateButton->date(), timeButton->time() ); |
244 | 244 | ||
245 | if ( dt.isValid() ) setTime(dt); | 245 | if ( dt.isValid() ) setTime(dt); |
246 | } | 246 | } |
247 | 247 | ||
248 | void SetDateTime::setTime(QDateTime dt) | 248 | void SetDateTime::setTime(QDateTime dt) |
249 | { | 249 | { |
250 | // really turn off the screensaver before doing anything | 250 | // really turn off the screensaver before doing anything |
251 | { | 251 | { |
252 | // Needs to be encased in { } so that it deconstructs and sends | 252 | // Needs to be encased in { } so that it deconstructs and sends |
253 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 253 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
254 | disableScreenSaver << 0 << 0 << 0; | 254 | disableScreenSaver << 0 << 0 << 0; |
255 | } | 255 | } |
256 | Config cfg("ntp",Config::User); | 256 | Config cfg("ntp",Config::User); |
257 | cfg.setGroup("correction"); | 257 | cfg.setGroup("correction"); |
258 | int t = TimeConversion::toUTC(dt); | 258 | int t = TimeConversion::toUTC(dt); |
259 | struct timeval myTv; | 259 | struct timeval myTv; |
260 | myTv.tv_sec = t; | 260 | myTv.tv_sec = t; |
261 | cfg.writeEntry("time", t ); | 261 | cfg.writeEntry("time", t ); |
262 | myTv.tv_usec = 0; | 262 | myTv.tv_usec = 0; |
263 | 263 | ||
264 | if ( myTv.tv_sec != -1 ) | 264 | if ( myTv.tv_sec != -1 ) |
265 | ::settimeofday( &myTv, 0 ); | 265 | ::settimeofday( &myTv, 0 ); |
266 | Global::writeHWClock(); | 266 | Global::writeHWClock(); |
267 | // since time has changed quickly load in the datebookdb | 267 | // since time has changed quickly load in the datebookdb |
268 | // 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 |
269 | // (example re-trigger alarms for when we travel back in time) | 269 | // (example re-trigger alarms for when we travel back in time) |
270 | DateBookDB db; | 270 | DateBookDB db; |
271 | // Restore screensaver | 271 | // Restore screensaver |
272 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 272 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
273 | enableScreenSaver << -1 << -1 << -1; | 273 | enableScreenSaver << -1 << -1 << -1; |
274 | } | 274 | } |
275 | 275 | ||
276 | void SetDateTime::updateSystem(int i) | 276 | void SetDateTime::updateSystem(int i) |
277 | { | 277 | { |
278 | // really turn off the screensaver before doing anything | 278 | // really turn off the screensaver before doing anything |
279 | { | 279 | { |
280 | // Needs to be encased in { } so that it deconstructs and sends | 280 | // Needs to be encased in { } so that it deconstructs and sends |
281 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 281 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
282 | disableScreenSaver << 0 << 0 << 0; | 282 | disableScreenSaver << 0 << 0 << 0; |
283 | } | 283 | } |
284 | qDebug("SetDateTime::updateSystem(int %i)",i); | 284 | qDebug("SetDateTime::updateSystem(int %i)",i); |
285 | writeSettings(); | 285 | writeSettings(); |
286 | 286 | ||
287 | // set the timezone for everyone else... | 287 | // set the timezone for everyone else... |
288 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); | 288 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); |
289 | setTimeZone << tz->currentZone(); | 289 | setTimeZone << tz->currentZone(); |
290 | 290 | ||
291 | // AM/PM setting and notify time changed | 291 | // AM/PM setting and notify time changed |
292 | QCopEnvelope setClock( "QPE/System", "clockChange(bool)" ); | 292 | QCopEnvelope setClock( "QPE/System", "clockChange(bool)" ); |
293 | setClock << ampmCombo->currentItem(); | 293 | setClock << ampmCombo->currentItem(); |
294 | 294 | ||
295 | // Notify everyone what day we prefer to start the week on. | 295 | // Notify everyone what day we prefer to start the week on. |
296 | QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" ); | 296 | QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" ); |
297 | setWeek << weekStartCombo->currentItem(); | 297 | setWeek << weekStartCombo->currentItem(); |
298 | 298 | ||
299 | // Notify everyone what date format to use | 299 | // Notify everyone what date format to use |
300 | QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" ); | 300 | QCopEnvelope setDateFormat( "QPE/System", "setDateFormat(DateFormat)" ); |
301 | setDateFormat << date_formats[dateFormatCombo->currentItem()]; | 301 | setDateFormat << date_formats[dateFormatCombo->currentItem()]; |
302 | 302 | ||
303 | // Restore screensaver | 303 | // Restore screensaver |
304 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 304 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
305 | enableScreenSaver << -1 << -1 << -1; | 305 | enableScreenSaver << -1 << -1 << -1; |
306 | // since time has changed quickly load in the datebookdb | 306 | // since time has changed quickly load in the datebookdb |
307 | // 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 |
308 | // (example re-trigger alarms for when we travel back in time) | 308 | // (example re-trigger alarms for when we travel back in time) |
309 | DateBookDB db; | 309 | DateBookDB db; |
310 | 310 | ||
311 | } | 311 | } |
312 | 312 | ||
313 | void SetDateTime::tzChange( const QString &tz ) | 313 | void SetDateTime::tzChange( const QString &tz ) |
314 | { | 314 | { |
315 | // set the TZ get the time and leave gracefully... | 315 | // set the TZ get the time and leave gracefully... |
316 | QString strSave; | 316 | QString strSave; |
317 | strSave = getenv( "TZ" ); | 317 | strSave = getenv( "TZ" ); |
318 | setenv( "TZ", tz, 1 ); | 318 | setenv( "TZ", tz, 1 ); |
319 | 319 | ||
320 | QDate d = QDate::currentDate(); | 320 | QDate d = QDate::currentDate(); |
321 | // reset the time. | 321 | // reset the time. |
322 | if ( !strSave.isNull() ) { | 322 | if ( !strSave.isNull() ) { |
323 | setenv( "TZ", strSave, 1 ); | 323 | setenv( "TZ", strSave, 1 ); |
324 | } | 324 | } |
325 | dateButton->setDate( d ); | 325 | dateButton->setDate( d ); |
326 | updateSystem(); | 326 | updateSystem(); |
327 | } | 327 | } |
328 | 328 | ||
329 | void SetDateTime::formatChanged(int i) | 329 | void SetDateTime::formatChanged(int i) |
330 | { | 330 | { |
331 | dateButton->setDateFormat(date_formats[i]); | 331 | dateButton->setDateFormat(date_formats[i]); |
332 | } | 332 | } |
333 | 333 | ||
334 | static const int ValueAM = 0; | 334 | static const int ValueAM = 0; |
335 | static const int ValuePM = 1; | 335 | static const int ValuePM = 1; |
336 | 336 | ||
337 | 337 | ||
338 | 338 | ||
339 | SetTime::SetTime( QWidget *parent, const char *name ) | 339 | SetTime::SetTime( QWidget *parent, const char *name ) |
340 | : QWidget( parent, name ) | 340 | : QWidget( parent, name ) |
341 | { | 341 | { |
342 | use12hourTime = FALSE; | 342 | use12hourTime = FALSE; |
343 | 343 | ||
344 | QTime currTime = QTime::currentTime(); | 344 | QTime currTime = QTime::currentTime(); |
345 | hour = currTime.hour(); | 345 | hour = currTime.hour(); |
346 | minute = currTime.minute(); | 346 | minute = currTime.minute(); |
347 | 347 | ||
348 | QHBoxLayout *hb2 = new QHBoxLayout( this ); | 348 | QHBoxLayout *hb2 = new QHBoxLayout( this ); |
349 | hb2->setSpacing( 3 ); | 349 | hb2->setSpacing( 3 ); |
350 | 350 | ||
351 | QLabel *l = new QLabel( tr("Hour"), this ); | 351 | QLabel *l = new QLabel( tr("Hour"), this ); |
352 | // l->setAlignment( AlignRight | AlignVCenter ); | 352 | // l->setAlignment( AlignRight | AlignVCenter ); |
353 | hb2->addWidget( l ); | 353 | hb2->addWidget( l ); |
354 | 354 | ||
355 | sbHour = new QSpinBox( this ); | 355 | sbHour = new QSpinBox( this ); |
356 | sbHour->setMinimumWidth( 30 ); | 356 | sbHour->setMinimumWidth( 30 ); |
357 | if(use12hourTime) { | 357 | if(use12hourTime) { |
358 | sbHour->setMinValue(1); | 358 | sbHour->setMinValue(1); |
359 | sbHour->setMaxValue( 12 ); | 359 | sbHour->setMaxValue( 12 ); |
360 | int show_hour = hour; | 360 | int show_hour = hour; |
361 | if (hour > 12) | 361 | if (hour > 12) |
362 | show_hour -= 12; | 362 | show_hour -= 12; |
363 | if (show_hour == 0) | 363 | if (show_hour == 0) |
364 | show_hour = 12; | 364 | show_hour = 12; |
365 | 365 | ||
366 | sbHour->setValue( show_hour ); | 366 | sbHour->setValue( show_hour ); |
367 | } else { | 367 | } else { |
368 | sbHour->setMinValue( 0 ); | 368 | sbHour->setMinValue( 0 ); |
369 | sbHour->setMaxValue( 23 ); | 369 | sbHour->setMaxValue( 23 ); |
370 | sbHour->setValue( hour ); | 370 | sbHour->setValue( hour ); |
371 | } | 371 | } |
372 | sbHour->setWrapping(TRUE); | 372 | sbHour->setWrapping(TRUE); |
373 | connect( sbHour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)) ); | 373 | connect( sbHour, SIGNAL(valueChanged(int)), this, SLOT(hourChanged(int)) ); |
374 | hb2->addWidget( sbHour ); | 374 | hb2->addWidget( sbHour ); |
375 | 375 | ||
376 | hb2->addStretch( 1 ); | 376 | hb2->addStretch( 1 ); |
377 | 377 | ||
378 | l = new QLabel( tr("Minute"), this ); | 378 | l = new QLabel( tr("Minute"), this ); |
379 | //l->setAlignment( AlignRight | AlignVCenter ); | 379 | //l->setAlignment( AlignRight | AlignVCenter ); |
380 | hb2->addWidget( l ); | 380 | hb2->addWidget( l ); |
381 | 381 | ||
382 | sbMin = new QSpinBox( this ); | 382 | sbMin = new QSpinBox( this ); |
383 | sbMin->setMinValue( 0 ); | 383 | sbMin->setMinValue( 0 ); |
384 | sbMin->setMaxValue( 59 ); | 384 | sbMin->setMaxValue( 59 ); |
385 | sbMin->setWrapping(TRUE); | 385 | sbMin->setWrapping(TRUE); |
386 | sbMin->setValue( minute ); | 386 | sbMin->setValue( minute ); |
387 | sbMin->setMinimumWidth( 30 ); | 387 | sbMin->setMinimumWidth( 30 ); |
388 | connect( sbMin, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)) ); | 388 | connect( sbMin, SIGNAL(valueChanged(int)), this, SLOT(minuteChanged(int)) ); |
389 | hb2->addWidget( sbMin ); | 389 | hb2->addWidget( sbMin ); |
390 | 390 | ||
391 | hb2->addStretch( 1 ); | 391 | hb2->addStretch( 1 ); |
392 | 392 | ||
393 | ampm = new QComboBox( this ); | 393 | ampm = new QComboBox( this ); |
394 | ampm->insertItem( tr("AM"), ValueAM ); | 394 | ampm->insertItem( tr("AM"), ValueAM ); |
395 | ampm->insertItem( tr("PM"), ValuePM ); | 395 | ampm->insertItem( tr("PM"), ValuePM ); |
396 | connect( ampm, SIGNAL(activated(int)), this, SLOT(checkedPM(int)) ); | 396 | connect( ampm, SIGNAL(activated(int)), this, SLOT(checkedPM(int)) ); |
397 | hb2->addWidget( ampm ); | 397 | hb2->addWidget( ampm ); |
398 | 398 | ||
399 | hb2->addStretch( 1 ); | 399 | hb2->addStretch( 1 ); |
400 | 400 | ||
401 | } | 401 | } |