Diffstat (limited to 'noncore/settings/netsystemtime/settime.cpp') (more/less context) (ignore whitespace changes)
-rw-r--r-- | noncore/settings/netsystemtime/settime.cpp | 122 |
1 files changed, 77 insertions, 45 deletions
diff --git a/noncore/settings/netsystemtime/settime.cpp b/noncore/settings/netsystemtime/settime.cpp index 949fcb3..36166ae 100644 --- a/noncore/settings/netsystemtime/settime.cpp +++ b/noncore/settings/netsystemtime/settime.cpp | |||
@@ -26,77 +26,83 @@ | |||
26 | #include <qpe/datebookdb.h> | 26 | #include <qpe/datebookdb.h> |
27 | #include <qpe/datebookmonth.h> | 27 | #include <qpe/datebookmonth.h> |
28 | #include <qpe/global.h> | 28 | #include <qpe/global.h> |
29 | #include <qpe/resource.h> | 29 | #include <qpe/resource.h> |
30 | #include <qpe/timeconversion.h> | 30 | #include <qpe/timeconversion.h> |
31 | #include <qpe/tzselect.h> | 31 | #include <qpe/tzselect.h> |
32 | #include <qpe/timestring.h> | 32 | #include <qpe/timestring.h> |
33 | #include <qpe/qpedialog.h> | 33 | #include <qpe/qpedialog.h> |
34 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 34 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
35 | #include <qpe/qcopenvelope_qws.h> | 35 | #include <qpe/qcopenvelope_qws.h> |
36 | #endif | 36 | #endif |
37 | 37 | ||
38 | #include <qtimer.h> | ||
38 | #include <qbuttongroup.h> | 39 | #include <qbuttongroup.h> |
39 | #include <qcheckbox.h> | 40 | #include <qcheckbox.h> |
40 | #include <qlabel.h> | 41 | #include <qlabel.h> |
41 | #include <qlayout.h> | 42 | #include <qlayout.h> |
42 | #include <qradiobutton.h> | 43 | #include <qradiobutton.h> |
43 | #include <qspinbox.h> | 44 | #include <qspinbox.h> |
44 | #include <qtoolbutton.h> | 45 | #include <qtoolbutton.h> |
45 | #include <qwindowsystem_qws.h> | 46 | #include <qwindowsystem_qws.h> |
46 | #include <qcombobox.h> | 47 | #include <qcombobox.h> |
47 | 48 | ||
48 | #include <sys/time.h> | 49 | #include <sys/time.h> |
49 | #include <time.h> | 50 | #include <time.h> |
50 | #include <stdlib.h> | 51 | #include <stdlib.h> |
51 | #include <stdio.h> | 52 | #include <stdio.h> |
52 | 53 | ||
53 | 54 | ||
54 | SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f ) | 55 | SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f ) |
55 | : NtpBase( parent, name, f ) | 56 | : NtpBase( parent, name, true, f ) |
56 | { | 57 | { |
57 | // setCaption( tr("Set System Time") ); | 58 | setCaption( tr("System Time") ); |
58 | 59 | ||
59 | // QVBoxLayout *vb = new QVBoxLayout( this, 5 ); | ||
60 | QVBoxLayout *vb = new QVBoxLayout( FrameSystemTime, 5 ); | 60 | QVBoxLayout *vb = new QVBoxLayout( FrameSystemTime, 5 ); |
61 | QVBoxLayout *vb2 = new QVBoxLayout( FrameSetTime, 5 ); | ||
62 | 61 | ||
63 | TextLabelMainPredTime = new QLabel( FrameSystemTime ); | 62 | // TextLabelMainPredTime = new QLabel( FrameSystemTime ); |
64 | vb->addWidget( TextLabelMainPredTime, 1, 0 ); | 63 | // vb->addWidget( TextLabelMainPredTime, 1, 0 ); |
65 | 64 | ||
66 | QHBoxLayout *hb = new QHBoxLayout( vb, -1, "timezone layout" ); | 65 | timeButton = new SetTime( FrameSystemTime ); |
66 | vb->addWidget( timeButton ); | ||
67 | |||
68 | QHBoxLayout *db = new QHBoxLayout( vb ); | ||
69 | QLabel *dateLabel = new QLabel( tr("Date"), FrameSystemTime ); | ||
70 | db->addWidget( dateLabel, 1 ); | ||
71 | dateButton = new DateButton( TRUE, FrameSystemTime ); | ||
72 | db->addWidget( dateButton, 2 ); | ||
67 | 73 | ||
74 | ButtonSetTime = new QPushButton( FrameSystemTime ); | ||
75 | vb->addWidget( ButtonSetTime, 1, 0 ); | ||
76 | |||
77 | QFrame *hline = new QFrame( FrameSystemTime ); | ||
78 | hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); | ||
79 | vb->addWidget( hline ); | ||
80 | |||
81 | QHBoxLayout *hb = new QHBoxLayout( vb, -1, "timezone layout" ); | ||
82 | |||
68 | QLabel *lblZone = new QLabel( tr( "Time Zone" ), FrameSystemTime, "timezone label" ); | 83 | QLabel *lblZone = new QLabel( tr( "Time Zone" ), FrameSystemTime, "timezone label" ); |
69 | lblZone->setMaximumSize( lblZone->sizeHint() ); | 84 | lblZone->setMaximumSize( lblZone->sizeHint() ); |
70 | hb->addWidget( lblZone ); | 85 | hb->addWidget( lblZone ); |
71 | 86 | ||
72 | tz = new TimeZoneSelector( FrameSystemTime, "Timezone choices" ); | 87 | tz = new TimeZoneSelector( FrameSystemTime, "Timezone choices" ); |
73 | tz->setMinimumSize( tz->sizeHint() ); | 88 | tz->setMinimumSize( tz->sizeHint() ); |
74 | hb->addWidget( tz ); | 89 | hb->addWidget( tz ); |
75 | |||
76 | timeButton = new SetTime( FrameSetTime ); | ||
77 | vb2->addWidget( timeButton ); | ||
78 | |||
79 | QHBoxLayout *db = new QHBoxLayout( vb2 ); | ||
80 | QLabel *dateLabel = new QLabel( tr("Date"), FrameSetTime ); | ||
81 | db->addWidget( dateLabel, 1 ); | ||
82 | dateButton = new DateButton( TRUE, FrameSetTime ); | ||
83 | db->addWidget( dateButton, 2 ); | ||
84 | |||
85 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); | ||
86 | vb2->addItem( spacer ); | ||
87 | 90 | ||
88 | QFrame *hline = new QFrame( FrameSystemTime ); | 91 | hline = new QFrame( FrameSystemTime ); |
89 | hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); | 92 | hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); |
90 | vb->addWidget( hline ); | 93 | vb->addWidget( hline ); |
94 | |||
95 | QSpacerItem* spacer = new QSpacerItem( 20, 20, QSizePolicy::Minimum, QSizePolicy::Expanding ); | ||
96 | vb->addItem( spacer ); | ||
91 | 97 | ||
92 | Config config("qpe"); | 98 | Config config("qpe"); |
93 | config.setGroup( "Time" ); | 99 | config.setGroup( "Time" ); |
94 | 100 | ||
95 | QHBoxLayout *hb1 = new QHBoxLayout( vb ); | 101 | QHBoxLayout *hb1 = new QHBoxLayout( vb ); |
96 | 102 | ||
97 | QLabel *l = new QLabel( tr("Time format"), FrameSystemTime ); | 103 | QLabel *l = new QLabel( tr("Time format"), FrameSystemTime ); |
98 | hb1->addWidget( l, 1 ); | 104 | hb1->addWidget( l, 1 ); |
99 | 105 | ||
100 | 106 | ||
101 | ampmCombo = new QComboBox( FrameSystemTime ); | 107 | ampmCombo = new QComboBox( FrameSystemTime ); |
102 | ampmCombo->insertItem( tr("24 hour"), 0 ); | 108 | ampmCombo->insertItem( tr("24 hour"), 0 ); |
@@ -170,53 +176,49 @@ SetDateTime::SetDateTime(QWidget *parent, const char *name, WFlags f ) | |||
170 | 176 | ||
171 | clockAppletCombo = new QComboBox( FrameSystemTime ); | 177 | clockAppletCombo = new QComboBox( FrameSystemTime ); |
172 | clockAppletCombo->insertItem( tr("hh:mm"), 0 ); | 178 | clockAppletCombo->insertItem( tr("hh:mm"), 0 ); |
173 | clockAppletCombo->insertItem( tr("D/M hh:mm"), 1 ); | 179 | clockAppletCombo->insertItem( tr("D/M hh:mm"), 1 ); |
174 | clockAppletCombo->insertItem( tr("M/D hh:mm"), 2 ); | 180 | clockAppletCombo->insertItem( tr("M/D hh:mm"), 2 ); |
175 | 181 | ||
176 | hb4->addWidget( clockAppletCombo, 2 ); | 182 | hb4->addWidget( clockAppletCombo, 2 ); |
177 | int clockApplet = config.readNumEntry("ClockApplet",0); | 183 | int clockApplet = config.readNumEntry("ClockApplet",0); |
178 | clockAppletCombo->setCurrentItem( clockApplet ); | 184 | clockAppletCombo->setCurrentItem( clockApplet ); |
179 | 185 | ||
180 | vb->addStretch( 0 ); | 186 | vb->addStretch( 0 ); |
181 | 187 | ||
182 | hline = new QFrame( FrameSystemTime ); | 188 | // hline = new QFrame( FrameSystemTime ); |
183 | hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); | 189 | // hline->setFrameStyle( QFrame::HLine | QFrame::Sunken ); |
184 | vb->addWidget( hline ); | 190 | // vb->addWidget( hline ); |
191 | // | ||
192 | // ButtonSetTime = new QPushButton( FrameSystemTime ); | ||
193 | // vb->addWidget( ButtonSetTime, 1, 0 ); | ||
185 | 194 | ||
186 | ButtonSetTime = new QPushButton( FrameSystemTime ); | ||
187 | vb->addWidget( ButtonSetTime, 1, 0 ); | ||
188 | |||
189 | QObject::connect( PushButtonSetManualTime, SIGNAL(clicked()), | ||
190 | this, SLOT(commitTime())); | ||
191 | 195 | ||
192 | QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), | 196 | QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), |
193 | timeButton, SLOT( slotTzChange( const QString& ) ) ); | 197 | timeButton, SLOT( slotTzChange( const QString& ) ) ); |
194 | QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), | 198 | QObject::connect( tz, SIGNAL( signalNewTz( const QString& ) ), |
195 | SLOT( tzChange( const QString& ) ) ); | 199 | SLOT( tzChange( const QString& ) ) ); |
196 | 200 | ||
197 | QObject::connect( weekStartCombo, SIGNAL( activated ( int )), | 201 | // QObject::connect( weekStartCombo, SIGNAL( activated ( int )), |
198 | SLOT(updateSystem(int ) )); | 202 | // SLOT(updateSystem(int ) )); |
199 | QObject::connect( ampmCombo, SIGNAL( activated ( int )), | 203 | // QObject::connect( ampmCombo, SIGNAL( activated ( int )), |
200 | SLOT(updateSystem(int ) )); | 204 | // SLOT(updateSystem(int ) )); |
201 | QObject::connect( dateFormatCombo, SIGNAL( activated ( int )), | 205 | // QObject::connect( dateFormatCombo, SIGNAL( activated ( int )), |
202 | SLOT(updateSystem(int ) )); | 206 | // SLOT(updateSystem(int ) )); |
203 | QObject::connect( clockAppletCombo, SIGNAL( activated ( int )), | 207 | // QObject::connect( clockAppletCombo, SIGNAL( activated ( int )), |
204 | SLOT(updateSystem(int ) )); | 208 | // SLOT(updateSystem(int ) )); |
205 | } | 209 | } |
206 | 210 | ||
207 | SetDateTime::~SetDateTime() | 211 | SetDateTime::~SetDateTime() |
208 | { | 212 | { |
209 | writeSettings(); | ||
210 | |||
211 | } | 213 | } |
212 | 214 | ||
213 | void SetDateTime::writeSettings() | 215 | void SetDateTime::writeSettings() |
214 | { | 216 | { |
215 | Config config("qpe"); | 217 | Config config("qpe"); |
216 | config.setGroup( "Time" ); | 218 | config.setGroup( "Time" ); |
217 | config.writeEntry( "AMPM", ampmCombo->currentItem() ); | 219 | config.writeEntry( "AMPM", ampmCombo->currentItem() ); |
218 | config.writeEntry( "MONDAY", weekStartCombo->currentItem() ); | 220 | config.writeEntry( "MONDAY", weekStartCombo->currentItem() ); |
219 | config.setGroup( "Date" ); | 221 | config.setGroup( "Date" ); |
220 | DateFormat df = date_formats[dateFormatCombo->currentItem()]; | 222 | DateFormat df = date_formats[dateFormatCombo->currentItem()]; |
221 | config.writeEntry( "Separator", QString(df.separator())); | 223 | config.writeEntry( "Separator", QString(df.separator())); |
222 | config.writeEntry( "ShortOrder", df.shortOrder()); | 224 | config.writeEntry( "ShortOrder", df.shortOrder()); |
@@ -267,33 +269,33 @@ void SetDateTime::setTime(QDateTime dt) | |||
267 | Global::writeHWClock(); | 269 | Global::writeHWClock(); |
268 | // since time has changed quickly load in the datebookdb | 270 | // since time has changed quickly load in the datebookdb |
269 | // to allow the alarm server to get a better grip on itself | 271 | // to allow the alarm server to get a better grip on itself |
270 | // (example re-trigger alarms for when we travel back in time) | 272 | // (example re-trigger alarms for when we travel back in time) |
271 | DateBookDB db; | 273 | DateBookDB db; |
272 | //QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" ); | 274 | //QCopEnvelope timeApplet( "QPE/TaskBar", "reloadApplets()" ); |
273 | //timeApplet << ""; | 275 | //timeApplet << ""; |
274 | // Restore screensaver | 276 | // Restore screensaver |
275 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 277 | QCopEnvelope enableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
276 | enableScreenSaver << -1 << -1 << -1; | 278 | enableScreenSaver << -1 << -1 << -1; |
277 | } | 279 | } |
278 | 280 | ||
279 | void SetDateTime::updateSystem(int i) | 281 | void SetDateTime::updateSystem() |
280 | { | 282 | { |
281 | // really turn off the screensaver before doing anything | 283 | // really turn off the screensaver before doing anything |
282 | { | 284 | { |
283 | // Needs to be encased in { } so that it deconstructs and sends | 285 | // Needs to be encased in { } so that it deconstructs and sends |
284 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); | 286 | QCopEnvelope disableScreenSaver( "QPE/System", "setScreenSaverIntervals(int,int,int)" ); |
285 | disableScreenSaver << 0 << 0 << 0; | 287 | disableScreenSaver << 0 << 0 << 0; |
286 | } | 288 | } |
287 | qDebug("SetDateTime::updateSystem(int %i)",i); | 289 | qDebug("SetDateTime::updateSystem()"); |
288 | writeSettings(); | 290 | writeSettings(); |
289 | 291 | ||
290 | // set the timezone for everyone else... | 292 | // set the timezone for everyone else... |
291 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); | 293 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); |
292 | setTimeZone << tz->currentZone(); | 294 | setTimeZone << tz->currentZone(); |
293 | 295 | ||
294 | // AM/PM setting and notify time changed | 296 | // AM/PM setting and notify time changed |
295 | QCopEnvelope setClock( "QPE/System", "clockChange(bool)" ); | 297 | QCopEnvelope setClock( "QPE/System", "clockChange(bool)" ); |
296 | setClock << ampmCombo->currentItem(); | 298 | setClock << ampmCombo->currentItem(); |
297 | 299 | ||
298 | // Notify everyone what day we prefer to start the week on. | 300 | // Notify everyone what day we prefer to start the week on. |
299 | QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" ); | 301 | QCopEnvelope setWeek( "QPE/System", "weekChange(bool)" ); |
@@ -314,48 +316,52 @@ void SetDateTime::updateSystem(int i) | |||
314 | } | 316 | } |
315 | 317 | ||
316 | void SetDateTime::tzChange( const QString &tz ) | 318 | void SetDateTime::tzChange( const QString &tz ) |
317 | { | 319 | { |
318 | // set the TZ get the time and leave gracefully... | 320 | // set the TZ get the time and leave gracefully... |
319 | QString strSave; | 321 | QString strSave; |
320 | strSave = getenv( "TZ" ); | 322 | strSave = getenv( "TZ" ); |
321 | setenv( "TZ", tz, 1 ); | 323 | setenv( "TZ", tz, 1 ); |
322 | 324 | ||
323 | QDate d = QDate::currentDate(); | 325 | QDate d = QDate::currentDate(); |
324 | // reset the time. | 326 | // reset the time. |
325 | if ( !strSave.isNull() ) { | 327 | if ( !strSave.isNull() ) { |
326 | setenv( "TZ", strSave, 1 ); | 328 | setenv( "TZ", strSave, 1 ); |
327 | } | 329 | } |
328 | dateButton->setDate( d ); | 330 | dateButton->setDate( d ); |
329 | updateSystem(); | 331 | updateSystem(); |
330 | } | 332 | } |
331 | 333 | ||
332 | void SetDateTime::formatChanged(int i) | 334 | void SetDateTime::formatChanged(int i) |
333 | { | 335 | { |
334 | dateButton->setDateFormat(date_formats[i]); | 336 | dateButton->setDateFormat(date_formats[i]); |
335 | } | 337 | } |
336 | 338 | ||
337 | static const int ValueAM = 0; | 339 | static const int ValueAM = 0; |
338 | static const int ValuePM = 1; | 340 | static const int ValuePM = 1; |
339 | 341 | ||
340 | 342 | ||
341 | 343 | ||
342 | SetTime::SetTime( QWidget *parent, const char *name ) | 344 | SetTime::SetTime( QWidget *parent, const char *name ) |
343 | : QWidget( parent, name ) | 345 | : QWidget( parent, name ) |
344 | { | 346 | { |
347 | clock = new QTimer(this, "clock" ); | ||
348 | connect(clock, SIGNAL( timeout() ), SLOT(slotClockTick()) ); | ||
349 | clock->start( 1000 * 60 ); | ||
350 | |||
345 | use12hourTime = FALSE; | 351 | use12hourTime = FALSE; |
346 | 352 | ||
347 | QTime currTime = QTime::currentTime(); | 353 | _time = QDateTime::currentDateTime(); |
348 | hour = currTime.hour(); | 354 | hour = _time.time().hour(); |
349 | minute = currTime.minute(); | 355 | minute = _time.time().minute(); |
350 | 356 | ||
351 | QHBoxLayout *hb2 = new QHBoxLayout( this ); | 357 | QHBoxLayout *hb2 = new QHBoxLayout( this ); |
352 | hb2->setSpacing( 3 ); | 358 | hb2->setSpacing( 3 ); |
353 | 359 | ||
354 | QLabel *l = new QLabel( tr("Hour"), this ); | 360 | QLabel *l = new QLabel( tr("Hour"), this ); |
355 | // l->setAlignment( AlignRight | AlignVCenter ); | 361 | // l->setAlignment( AlignRight | AlignVCenter ); |
356 | hb2->addWidget( l ); | 362 | hb2->addWidget( l ); |
357 | 363 | ||
358 | sbHour = new QSpinBox( this ); | 364 | sbHour = new QSpinBox( this ); |
359 | sbHour->setMinimumWidth( 30 ); | 365 | sbHour->setMinimumWidth( 30 ); |
360 | if(use12hourTime) { | 366 | if(use12hourTime) { |
361 | sbHour->setMinValue(1); | 367 | sbHour->setMinValue(1); |
@@ -490,13 +496,39 @@ void SetTime::slotTzChange( const QString &tz ) | |||
490 | } else { | 496 | } else { |
491 | ampm->setCurrentItem( ValueAM ); | 497 | ampm->setCurrentItem( ValueAM ); |
492 | } | 498 | } |
493 | if (show_hour == 0) | 499 | if (show_hour == 0) |
494 | show_hour = 12; | 500 | show_hour = 12; |
495 | sbHour->setValue( show_hour ); | 501 | sbHour->setValue( show_hour ); |
496 | } else { | 502 | } else { |
497 | sbHour->setValue( t.hour() ); | 503 | sbHour->setValue( t.hour() ); |
498 | } | 504 | } |
499 | sbMin->setValue( t.minute() ); | 505 | sbMin->setValue( t.minute() ); |
500 | } | 506 | } |
501 | 507 | ||
508 | void SetTime::setTime( QDateTime dt ) | ||
509 | { | ||
510 | _time = dt; | ||
511 | QTime t = dt.time(); | ||
512 | // just set the spinboxes and let it propage through | ||
513 | if(use12hourTime) { | ||
514 | int show_hour = t.hour(); | ||
515 | if (t.hour() >= 12) { | ||
516 | show_hour -= 12; | ||
517 | ampm->setCurrentItem( ValuePM ); | ||
518 | } else { | ||
519 | ampm->setCurrentItem( ValueAM ); | ||
520 | } | ||
521 | if (show_hour == 0) | ||
522 | show_hour = 12; | ||
523 | sbHour->setValue( show_hour ); | ||
524 | } else { | ||
525 | sbHour->setValue( t.hour() ); | ||
526 | } | ||
527 | sbMin->setValue( t.minute() ); | ||
528 | } | ||
502 | 529 | ||
530 | void SetTime::slotClockTick() | ||
531 | { | ||
532 | setTime( _time.addSecs(60) ); | ||
533 | qDebug("SetTime::slotClockTick %s",_time.toString().latin1()); | ||
534 | } | ||