-rw-r--r-- | noncore/settings/netsystemtime/timetabwidget.cpp | 61 |
1 files changed, 35 insertions, 26 deletions
diff --git a/noncore/settings/netsystemtime/timetabwidget.cpp b/noncore/settings/netsystemtime/timetabwidget.cpp index bcfbdf7..895514b 100644 --- a/noncore/settings/netsystemtime/timetabwidget.cpp +++ b/noncore/settings/netsystemtime/timetabwidget.cpp | |||
@@ -37,32 +37,34 @@ | |||
37 | #include <qpe/datebookmonth.h> | 37 | #include <qpe/datebookmonth.h> |
38 | #include <qpe/global.h> | 38 | #include <qpe/global.h> |
39 | #include <qpe/tzselect.h> | 39 | #include <qpe/tzselect.h> |
40 | 40 | ||
41 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) | 41 | #if ( defined Q_WS_QWS || defined(_WS_QWS_) ) && !defined(QT_NO_COP) |
42 | #include <qpe/qcopenvelope_qws.h> | 42 | #include <qpe/qcopenvelope_qws.h> |
43 | #endif | 43 | #endif |
44 | 44 | ||
45 | #include <qcombobox.h> | 45 | #include <qcombobox.h> |
46 | #include <qdatetime.h> | 46 | #include <qdatetime.h> |
47 | #include <qframe.h> | 47 | #include <qframe.h> |
48 | #include <qlabel.h> | 48 | #include <qlabel.h> |
49 | #include <qlayout.h> | 49 | #include <qlayout.h> |
50 | #include <qpushbutton.h> | 50 | #include <qpushbutton.h> |
51 | #include <qscrollview.h> | 51 | #include <qscrollview.h> |
52 | #include <qspinbox.h> | 52 | #include <qspinbox.h> |
53 | #include <qmessagebox.h> | ||
54 | #include <qfile.h> | ||
53 | 55 | ||
54 | #include <stdlib.h> | 56 | #include <stdlib.h> |
55 | #include <sys/time.h> | 57 | #include <sys/time.h> |
56 | 58 | ||
57 | static const int ValueAM = 0; | 59 | static const int ValueAM = 0; |
58 | static const int ValuePM = 1; | 60 | static const int ValuePM = 1; |
59 | 61 | ||
60 | TimeTabWidget::TimeTabWidget( QWidget *parent ) | 62 | TimeTabWidget::TimeTabWidget( QWidget *parent ) |
61 | : QWidget( parent, 0x0, 0 ) | 63 | : QWidget( parent, 0x0, 0 ) |
62 | { | 64 | { |
63 | // Synchronize HW clock to systemtime | 65 | // Synchronize HW clock to systemtime |
64 | // This app will update systemtime | 66 | // This app will update systemtime |
65 | // - if Cancel is clicked, will reset systemtime to HW clock's time | 67 | // - if Cancel is clicked, will reset systemtime to HW clock's time |
66 | // - if Ok is clicked, will leave systemtime as is | 68 | // - if Ok is clicked, will leave systemtime as is |
67 | system("/sbin/hwclock --systohc --utc"); | 69 | system("/sbin/hwclock --systohc --utc"); |
68 | 70 | ||
@@ -264,46 +266,53 @@ void TimeTabWidget::slotUse12HourTime( int i ) | |||
264 | 266 | ||
265 | sbHour->setValue( show_hour ); | 267 | sbHour->setValue( show_hour ); |
266 | } | 268 | } |
267 | 269 | ||
268 | void TimeTabWidget::slotDateFormatChanged( const DateFormat &df ) | 270 | void TimeTabWidget::slotDateFormatChanged( const DateFormat &df ) |
269 | { | 271 | { |
270 | btnDate->setDateFormat( df ); | 272 | btnDate->setDateFormat( df ); |
271 | } | 273 | } |
272 | 274 | ||
273 | void TimeTabWidget::slotWeekStartChanged( int monday ) | 275 | void TimeTabWidget::slotWeekStartChanged( int monday ) |
274 | { | 276 | { |
275 | btnDate->setWeekStartsMonday( monday ); | 277 | btnDate->setWeekStartsMonday( monday ); |
276 | } | 278 | } |
277 | 279 | ||
278 | void TimeTabWidget::slotTZChanged( const QString &newtz ) | 280 | void TimeTabWidget::slotTZChanged( const QString &newtz ) |
279 | { | 281 | { |
280 | // If controls have a valid date & time, update systemtime | 282 | // Check timezone has a valid file in /usr/share/zoneinfo |
281 | int hour = sbHour->value(); | 283 | if(!QFile::exists("/usr/share/zoneinfo/" + newtz)) { |
282 | if ( use12HourTime && cbAmpm->currentItem() == ValuePM ) | 284 | QMessageBox::warning(this, tr("Time zone file missing"), |
283 | hour += 12; | 285 | (tr("There is no time zone file for the\nselected time zone (%1).\nYou will need to install it before the\nsystem time zone can be set correctly.")).arg(newtz)); |
284 | QDateTime dt( btnDate->date(), QTime ( hour, sbMin->value(), QTime::currentTime().second() ) ); | ||
285 | setSystemTime( dt ); | ||
286 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); | ||
287 | setTimeZone << newtz; | ||
288 | |||
289 | // Set system timezone | ||
290 | QString currtz = getenv( "TZ" ); | ||
291 | setenv( "TZ", newtz, 1 ); | ||
292 | |||
293 | // Get new date/time | ||
294 | hour = sbHour->value(); | ||
295 | if ( use12HourTime && cbAmpm->currentItem() == ValuePM ) | ||
296 | hour += 12; | ||
297 | dt = QDateTime::currentDateTime(); | ||
298 | |||
299 | // Reset system timezone | ||
300 | if ( !currtz.isNull() ) | ||
301 | { | ||
302 | setenv( "TZ", currtz, 1 ); | ||
303 | } | 286 | } |
287 | else { | ||
288 | // If controls have a valid date & time, update systemtime | ||
289 | int hour = sbHour->value(); | ||
290 | if ( use12HourTime && cbAmpm->currentItem() == ValuePM ) | ||
291 | hour += 12; | ||
292 | QDateTime dt( btnDate->date(), QTime ( hour, sbMin->value(), QTime::currentTime().second() ) ); | ||
293 | setSystemTime( dt ); | ||
294 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); | ||
295 | setTimeZone << newtz; | ||
304 | 296 | ||
305 | // Set controls to new time | 297 | // Set system timezone |
306 | setDateTime( dt ); | 298 | QString currtz = getenv( "TZ" ); |
299 | setenv( "TZ", newtz, 1 ); | ||
307 | 300 | ||
308 | emit tzChanged( newtz ); | 301 | // Get new date/time |
302 | hour = sbHour->value(); | ||
303 | if ( use12HourTime && cbAmpm->currentItem() == ValuePM ) | ||
304 | hour += 12; | ||
305 | dt = QDateTime::currentDateTime(); | ||
306 | |||
307 | // Reset system timezone | ||
308 | if ( !currtz.isNull() ) | ||
309 | { | ||
310 | setenv( "TZ", currtz, 1 ); | ||
311 | } | ||
312 | |||
313 | // Set controls to new time | ||
314 | setDateTime( dt ); | ||
315 | |||
316 | emit tzChanged( newtz ); | ||
317 | } | ||
309 | } | 318 | } |