author | paule <paule> | 2007-01-14 03:02:55 (UTC) |
---|---|---|
committer | paule <paule> | 2007-01-14 03:02:55 (UTC) |
commit | ca67251af3f46d685afac8dc6bfe452799c2546e (patch) (unidiff) | |
tree | 3e7ae7ed8d06e97c5556b52c5cf3826426cedd9b | |
parent | 81de0baf254bd2d935d0fdf035143e5510354fa7 (diff) | |
download | opie-ca67251af3f46d685afac8dc6bfe452799c2546e.zip opie-ca67251af3f46d685afac8dc6bfe452799c2546e.tar.gz opie-ca67251af3f46d685afac8dc6bfe452799c2546e.tar.bz2 |
When selecting a time zone, warn the user if the time zone file in /usr/share/zoneinfo for the selected time zone is missing
-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 | |||
@@ -1,309 +1,318 @@ | |||
1 | /* | 1 | /* |
2 | This file is part of the Opie Project | 2 | This file is part of the Opie Project |
3 | 3 | ||
4 | Copyright (C) Opie Team <opie-devel@handhelds.org> | 4 | Copyright (C) Opie Team <opie-devel@handhelds.org> |
5 | =. | 5 | =. |
6 | .=l. | 6 | .=l. |
7 | .>+-= | 7 | .>+-= |
8 | _;:, .> :=|. This program is free software; you can | 8 | _;:, .> :=|. This program is free software; you can |
9 | .> <`_, > . <= redistribute it and/or modify it under | 9 | .> <`_, > . <= redistribute it and/or modify it under |
10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public | 10 | :`=1 )Y*s>-.-- : the terms of the GNU Library General Public |
11 | .="- .-=="i, .._ License as published by the Free Software | 11 | .="- .-=="i, .._ License as published by the Free Software |
12 | - . .-<_> .<> Foundation; either version 2 of the License, | 12 | - . .-<_> .<> Foundation; either version 2 of the License, |
13 | ._= =} : or (at your option) any later version. | 13 | ._= =} : or (at your option) any later version. |
14 | .%`+i> _;_. | 14 | .%`+i> _;_. |
15 | .i_,=:_. -<s. This program is distributed in the hope that | 15 | .i_,=:_. -<s. This program is distributed in the hope that |
16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; | 16 | + . -:. = it will be useful, but WITHOUT ANY WARRANTY; |
17 | : .. .:, . . . without even the implied warranty of | 17 | : .. .:, . . . without even the implied warranty of |
18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A | 18 | =_ + =;=|` MERCHANTABILITY or FITNESS FOR A |
19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU | 19 | _.=:. : :=>`: PARTICULAR PURPOSE. See the GNU |
20 | ..}^=.= = ; Library General Public License for more | 20 | ..}^=.= = ; Library General Public License for more |
21 | ++= -. .` .: details. | 21 | ++= -. .` .: details. |
22 | : = ...= . :.=- | 22 | : = ...= . :.=- |
23 | -. .:....=;==+<; You should have received a copy of the GNU | 23 | -. .:....=;==+<; You should have received a copy of the GNU |
24 | -_. . . )=. = Library General Public License along with | 24 | -_. . . )=. = Library General Public License along with |
25 | -- :-=` this library; see the file COPYING.LIB. | 25 | -- :-=` this library; see the file COPYING.LIB. |
26 | If not, write to the Free Software Foundation, | 26 | If not, write to the Free Software Foundation, |
27 | Inc., 59 Temple Place - Suite 330, | 27 | Inc., 59 Temple Place - Suite 330, |
28 | Boston, MA 02111-1307, USA. | 28 | Boston, MA 02111-1307, USA. |
29 | */ | 29 | */ |
30 | 30 | ||
31 | #include "timetabwidget.h" | 31 | #include "timetabwidget.h" |
32 | 32 | ||
33 | #include <opie2/oresource.h> | 33 | #include <opie2/oresource.h> |
34 | 34 | ||
35 | #include <qpe/applnk.h> | 35 | #include <qpe/applnk.h> |
36 | #include <qpe/config.h> | 36 | #include <qpe/config.h> |
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 | ||
69 | QVBoxLayout *tmpvb = new QVBoxLayout( this ); | 71 | QVBoxLayout *tmpvb = new QVBoxLayout( this ); |
70 | QScrollView *sv = new QScrollView( this ); | 72 | QScrollView *sv = new QScrollView( this ); |
71 | tmpvb->addWidget( sv, 0, 0 ); | 73 | tmpvb->addWidget( sv, 0, 0 ); |
72 | sv->setResizePolicy( QScrollView::AutoOneFit ); | 74 | sv->setResizePolicy( QScrollView::AutoOneFit ); |
73 | sv->setFrameStyle( QFrame::NoFrame ); | 75 | sv->setFrameStyle( QFrame::NoFrame ); |
74 | QWidget *container = new QWidget( sv->viewport() ); | 76 | QWidget *container = new QWidget( sv->viewport() ); |
75 | sv->addChild( container ); | 77 | sv->addChild( container ); |
76 | 78 | ||
77 | QGridLayout *layout = new QGridLayout( container ); | 79 | QGridLayout *layout = new QGridLayout( container ); |
78 | layout->setMargin( 2 ); | 80 | layout->setMargin( 2 ); |
79 | layout->setSpacing( 4 ); | 81 | layout->setSpacing( 4 ); |
80 | 82 | ||
81 | // Hours | 83 | // Hours |
82 | layout->addMultiCellWidget( new QLabel( tr( "Hour" ), container ), 1, 1, 0, 1 ); | 84 | layout->addMultiCellWidget( new QLabel( tr( "Hour" ), container ), 1, 1, 0, 1 ); |
83 | sbHour = new QSpinBox( container ); | 85 | sbHour = new QSpinBox( container ); |
84 | sbHour->setWrapping( TRUE ); | 86 | sbHour->setWrapping( TRUE ); |
85 | layout->addMultiCellWidget( sbHour, 2, 2, 0, 1 ); | 87 | layout->addMultiCellWidget( sbHour, 2, 2, 0, 1 ); |
86 | 88 | ||
87 | // Minutes | 89 | // Minutes |
88 | layout->addMultiCellWidget( new QLabel( tr( "Minute" ), container ), 1, 1, 2, 3 ); | 90 | layout->addMultiCellWidget( new QLabel( tr( "Minute" ), container ), 1, 1, 2, 3 ); |
89 | sbMin = new QSpinBox( container ); | 91 | sbMin = new QSpinBox( container ); |
90 | sbMin->setWrapping( TRUE ); | 92 | sbMin->setWrapping( TRUE ); |
91 | sbMin->setMinValue( 0 ); | 93 | sbMin->setMinValue( 0 ); |
92 | sbMin->setMaxValue( 59 ); | 94 | sbMin->setMaxValue( 59 ); |
93 | layout->addMultiCellWidget( sbMin, 2, 2, 2, 3 ); | 95 | layout->addMultiCellWidget( sbMin, 2, 2, 2, 3 ); |
94 | 96 | ||
95 | // AM/PM | 97 | // AM/PM |
96 | cbAmpm = new QComboBox( container ); | 98 | cbAmpm = new QComboBox( container ); |
97 | cbAmpm->insertItem( tr( "AM" ), ValueAM ); | 99 | cbAmpm->insertItem( tr( "AM" ), ValueAM ); |
98 | cbAmpm->insertItem( tr( "PM" ), ValuePM ); | 100 | cbAmpm->insertItem( tr( "PM" ), ValuePM ); |
99 | layout->addMultiCellWidget( cbAmpm, 2, 2, 4, 5 ); | 101 | layout->addMultiCellWidget( cbAmpm, 2, 2, 4, 5 ); |
100 | 102 | ||
101 | // Date | 103 | // Date |
102 | layout->addWidget( new QLabel( tr( "Date" ), container ), 4, 0 ); | 104 | layout->addWidget( new QLabel( tr( "Date" ), container ), 4, 0 ); |
103 | btnDate = new DateButton( TRUE, container ); | 105 | btnDate = new DateButton( TRUE, container ); |
104 | layout->addMultiCellWidget( btnDate, 4, 4, 1, 5 ); | 106 | layout->addMultiCellWidget( btnDate, 4, 4, 1, 5 ); |
105 | 107 | ||
106 | // Timezone | 108 | // Timezone |
107 | layout->addMultiCellWidget( new QLabel( tr( "Time zone" ), container ), 6, 6, 0, 1 ); | 109 | layout->addMultiCellWidget( new QLabel( tr( "Time zone" ), container ), 6, 6, 0, 1 ); |
108 | selTimeZone = new TimeZoneSelector( container ); | 110 | selTimeZone = new TimeZoneSelector( container ); |
109 | connect( selTimeZone, SIGNAL(signalNewTz(const QString&)), this, SLOT(slotTZChanged(const QString&)) ); | 111 | connect( selTimeZone, SIGNAL(signalNewTz(const QString&)), this, SLOT(slotTZChanged(const QString&)) ); |
110 | layout->addMultiCellWidget( selTimeZone, 6, 6, 2, 5 ); | 112 | layout->addMultiCellWidget( selTimeZone, 6, 6, 2, 5 ); |
111 | 113 | ||
112 | // Space filler | 114 | // Space filler |
113 | layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 7, 0 ); | 115 | layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 7, 0 ); |
114 | 116 | ||
115 | // Set NTP time button | 117 | // Set NTP time button |
116 | m_ntpBtn = new QPushButton( Opie::Core::OResource::loadPixmap( "netsystemtime/ntptab", Opie::Core::OResource::SmallIcon ), | 118 | m_ntpBtn = new QPushButton( Opie::Core::OResource::loadPixmap( "netsystemtime/ntptab", Opie::Core::OResource::SmallIcon ), |
117 | tr( "Get time from the network" ), container ); | 119 | tr( "Get time from the network" ), container ); |
118 | m_ntpBtn->setMinimumHeight( AppLnk::smallIconSize()+4 ); | 120 | m_ntpBtn->setMinimumHeight( AppLnk::smallIconSize()+4 ); |
119 | connect( m_ntpBtn, SIGNAL(clicked()), this, SIGNAL(getNTPTime()) ); | 121 | connect( m_ntpBtn, SIGNAL(clicked()), this, SIGNAL(getNTPTime()) ); |
120 | layout->addMultiCellWidget( m_ntpBtn, 8, 8, 0, 5 ); | 122 | layout->addMultiCellWidget( m_ntpBtn, 8, 8, 0, 5 ); |
121 | 123 | ||
122 | // Set predicted time button | 124 | // Set predicted time button |
123 | QPushButton *pb = new QPushButton( Opie::Core::OResource::loadPixmap( "netsystemtime/predicttab", Opie::Core::OResource::SmallIcon ), | 125 | QPushButton *pb = new QPushButton( Opie::Core::OResource::loadPixmap( "netsystemtime/predicttab", Opie::Core::OResource::SmallIcon ), |
124 | tr( "Set predicted time" ), container ); | 126 | tr( "Set predicted time" ), container ); |
125 | pb->setMinimumHeight( AppLnk::smallIconSize()+4 ); | 127 | pb->setMinimumHeight( AppLnk::smallIconSize()+4 ); |
126 | connect( pb, SIGNAL(clicked()), this, SIGNAL(getPredictedTime()) ); | 128 | connect( pb, SIGNAL(clicked()), this, SIGNAL(getPredictedTime()) ); |
127 | layout->addMultiCellWidget( pb, 9, 9, 0, 5 ); | 129 | layout->addMultiCellWidget( pb, 9, 9, 0, 5 ); |
128 | 130 | ||
129 | // Space filler at bottom of widget | 131 | // Space filler at bottom of widget |
130 | layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 10, 0 ); | 132 | layout->addItem( new QSpacerItem( 1, 1, QSizePolicy::Minimum, QSizePolicy::Expanding ), 10, 0 ); |
131 | 133 | ||
132 | // Initialize values | 134 | // Initialize values |
133 | Config config( "locale" ); | 135 | Config config( "locale" ); |
134 | config.setGroup( "Location" ); | 136 | config.setGroup( "Location" ); |
135 | selTimeZone->setCurrentZone( config.readEntry( "Timezone", "America/New_York" ) ); | 137 | selTimeZone->setCurrentZone( config.readEntry( "Timezone", "America/New_York" ) ); |
136 | use12HourTime = FALSE; | 138 | use12HourTime = FALSE; |
137 | setDateTime( QDateTime::currentDateTime() ); | 139 | setDateTime( QDateTime::currentDateTime() ); |
138 | } | 140 | } |
139 | 141 | ||
140 | TimeTabWidget::~TimeTabWidget() | 142 | TimeTabWidget::~TimeTabWidget() |
141 | { | 143 | { |
142 | } | 144 | } |
143 | 145 | ||
144 | void TimeTabWidget::saveSettings( bool commit ) | 146 | void TimeTabWidget::saveSettings( bool commit ) |
145 | { | 147 | { |
146 | if ( commit ) | 148 | if ( commit ) |
147 | { | 149 | { |
148 | // Set timezone and announce to world | 150 | // Set timezone and announce to world |
149 | QString tz = selTimeZone->currentZone(); | 151 | QString tz = selTimeZone->currentZone(); |
150 | Config config("locale"); | 152 | Config config("locale"); |
151 | config.setGroup( "Location" ); | 153 | config.setGroup( "Location" ); |
152 | config.writeEntry( "Timezone", tz ); | 154 | config.writeEntry( "Timezone", tz ); |
153 | setenv( "TZ", tz, 1 ); | 155 | setenv( "TZ", tz, 1 ); |
154 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); | 156 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); |
155 | setTimeZone << tz; | 157 | setTimeZone << tz; |
156 | 158 | ||
157 | // If controls have a valid date & time, update systemtime | 159 | // If controls have a valid date & time, update systemtime |
158 | int hour = sbHour->value(); | 160 | int hour = sbHour->value(); |
159 | if ( use12HourTime && cbAmpm->currentItem() == ValuePM ) | 161 | if ( use12HourTime && cbAmpm->currentItem() == ValuePM ) |
160 | hour += 12; | 162 | hour += 12; |
161 | QDateTime dt( btnDate->date(), QTime ( hour, sbMin->value(), QTime::currentTime().second() ) ); | 163 | QDateTime dt( btnDate->date(), QTime ( hour, sbMin->value(), QTime::currentTime().second() ) ); |
162 | setSystemTime( dt ); | 164 | setSystemTime( dt ); |
163 | } | 165 | } |
164 | else | 166 | else |
165 | { | 167 | { |
166 | // Reset systemtime to hardware clock (i.e. undo any changes made by this app) | 168 | // Reset systemtime to hardware clock (i.e. undo any changes made by this app) |
167 | system("/sbin/hwclock --hctosys --utc"); | 169 | system("/sbin/hwclock --hctosys --utc"); |
168 | } | 170 | } |
169 | } | 171 | } |
170 | 172 | ||
171 | void TimeTabWidget::setDateTime( const QDateTime &dt ) | 173 | void TimeTabWidget::setDateTime( const QDateTime &dt ) |
172 | { | 174 | { |
173 | // Set time | 175 | // Set time |
174 | QTime t = dt.time(); | 176 | QTime t = dt.time(); |
175 | if( use12HourTime ) | 177 | if( use12HourTime ) |
176 | { | 178 | { |
177 | int show_hour = t.hour(); | 179 | int show_hour = t.hour(); |
178 | if ( t.hour() >= 12 ) | 180 | if ( t.hour() >= 12 ) |
179 | { | 181 | { |
180 | show_hour -= 12; | 182 | show_hour -= 12; |
181 | cbAmpm->setCurrentItem( ValuePM ); | 183 | cbAmpm->setCurrentItem( ValuePM ); |
182 | } | 184 | } |
183 | else | 185 | else |
184 | { | 186 | { |
185 | cbAmpm->setCurrentItem( ValueAM ); | 187 | cbAmpm->setCurrentItem( ValueAM ); |
186 | } | 188 | } |
187 | if ( show_hour == 0 ) | 189 | if ( show_hour == 0 ) |
188 | show_hour = 12; | 190 | show_hour = 12; |
189 | sbHour->setValue( show_hour ); | 191 | sbHour->setValue( show_hour ); |
190 | } | 192 | } |
191 | else | 193 | else |
192 | { | 194 | { |
193 | sbHour->setValue( t.hour() ); | 195 | sbHour->setValue( t.hour() ); |
194 | } | 196 | } |
195 | sbMin->setValue( t.minute() ); | 197 | sbMin->setValue( t.minute() ); |
196 | 198 | ||
197 | // Set date | 199 | // Set date |
198 | btnDate->setDate( dt.date() ); | 200 | btnDate->setDate( dt.date() ); |
199 | } | 201 | } |
200 | 202 | ||
201 | void TimeTabWidget::setNTPBtnEnabled( bool enabled ) | 203 | void TimeTabWidget::setNTPBtnEnabled( bool enabled ) |
202 | { | 204 | { |
203 | m_ntpBtn->setEnabled( enabled ); | 205 | m_ntpBtn->setEnabled( enabled ); |
204 | } | 206 | } |
205 | 207 | ||
206 | void TimeTabWidget::setSystemTime( const QDateTime &dt ) | 208 | void TimeTabWidget::setSystemTime( const QDateTime &dt ) |
207 | { | 209 | { |
208 | // Set system clock | 210 | // Set system clock |
209 | if ( dt.isValid() ) | 211 | if ( dt.isValid() ) |
210 | { | 212 | { |
211 | struct timeval myTv; | 213 | struct timeval myTv; |
212 | int t = TimeConversion::toUTC( dt ); | 214 | int t = TimeConversion::toUTC( dt ); |
213 | myTv.tv_sec = t; | 215 | myTv.tv_sec = t; |
214 | myTv.tv_usec = 0; | 216 | myTv.tv_usec = 0; |
215 | 217 | ||
216 | if ( myTv.tv_sec != -1 ) | 218 | if ( myTv.tv_sec != -1 ) |
217 | ::settimeofday( &myTv, 0 ); | 219 | ::settimeofday( &myTv, 0 ); |
218 | 220 | ||
219 | /* | 221 | /* |
220 | * Commit the datetime to the 'hardware' | 222 | * Commit the datetime to the 'hardware' |
221 | * as Global::writeHWClock() is a NOOP with Opie Alarm | 223 | * as Global::writeHWClock() is a NOOP with Opie Alarm |
222 | */ | 224 | */ |
223 | system("/sbin/hwclock --systohc --utc"); | 225 | system("/sbin/hwclock --systohc --utc"); |
224 | } | 226 | } |
225 | } | 227 | } |
226 | 228 | ||
227 | void TimeTabWidget::slotUse12HourTime( int i ) | 229 | void TimeTabWidget::slotUse12HourTime( int i ) |
228 | { | 230 | { |
229 | use12HourTime = (i == 1); | 231 | use12HourTime = (i == 1); |
230 | 232 | ||
231 | cbAmpm->setEnabled( use12HourTime ); | 233 | cbAmpm->setEnabled( use12HourTime ); |
232 | 234 | ||
233 | int show_hour = sbHour->value(); | 235 | int show_hour = sbHour->value(); |
234 | 236 | ||
235 | if ( use12HourTime ) | 237 | if ( use12HourTime ) |
236 | { | 238 | { |
237 | sbHour->setMinValue( 1 ); | 239 | sbHour->setMinValue( 1 ); |
238 | sbHour->setMaxValue( 12 ); | 240 | sbHour->setMaxValue( 12 ); |
239 | 241 | ||
240 | if ( show_hour >= 12 ) | 242 | if ( show_hour >= 12 ) |
241 | { | 243 | { |
242 | show_hour -= 12; | 244 | show_hour -= 12; |
243 | cbAmpm->setCurrentItem( ValuePM ); | 245 | cbAmpm->setCurrentItem( ValuePM ); |
244 | } | 246 | } |
245 | else | 247 | else |
246 | { | 248 | { |
247 | cbAmpm->setCurrentItem( ValueAM ); | 249 | cbAmpm->setCurrentItem( ValueAM ); |
248 | } | 250 | } |
249 | if ( show_hour == 0 ) | 251 | if ( show_hour == 0 ) |
250 | show_hour = 12; | 252 | show_hour = 12; |
251 | } | 253 | } |
252 | else | 254 | else |
253 | { | 255 | { |
254 | sbHour->setMinValue( 0 ); | 256 | sbHour->setMinValue( 0 ); |
255 | sbHour->setMaxValue( 23 ); | 257 | sbHour->setMaxValue( 23 ); |
256 | 258 | ||
257 | if ( cbAmpm->currentItem() == ValuePM ) | 259 | if ( cbAmpm->currentItem() == ValuePM ) |
258 | { | 260 | { |
259 | show_hour += 12; | 261 | show_hour += 12; |
260 | if ( show_hour == 24 ) | 262 | if ( show_hour == 24 ) |
261 | show_hour = 0; | 263 | show_hour = 0; |
262 | } | 264 | } |
263 | } | 265 | } |
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 | } |