author | erik <erik> | 2007-04-23 20:38:22 (UTC) |
---|---|---|
committer | erik <erik> | 2007-04-23 20:38:22 (UTC) |
commit | d38e40fe9ee475230425fa83e924c49e5946b87c (patch) (unidiff) | |
tree | f10fceda92538e1bc9cee66f82062773974ec092 /noncore | |
parent | 1edbb754d3c8cfccf1630e2ad1e531e907555cbd (diff) | |
download | opie-d38e40fe9ee475230425fa83e924c49e5946b87c.zip opie-d38e40fe9ee475230425fa83e924c49e5946b87c.tar.gz opie-d38e40fe9ee475230425fa83e924c49e5946b87c.tar.bz2 |
Fix for bug 1848 where the outcome of setting the time to 12:00AM did not
work.
This commit is based on a patch submitted by harlekin. Thank you!
-rw-r--r-- | noncore/settings/netsystemtime/timetabwidget.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/noncore/settings/netsystemtime/timetabwidget.cpp b/noncore/settings/netsystemtime/timetabwidget.cpp index 895514b..e6fcf7f 100644 --- a/noncore/settings/netsystemtime/timetabwidget.cpp +++ b/noncore/settings/netsystemtime/timetabwidget.cpp | |||
@@ -132,159 +132,159 @@ TimeTabWidget::TimeTabWidget( QWidget *parent ) | |||
132 | 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 ); |
133 | 133 | ||
134 | // Initialize values | 134 | // Initialize values |
135 | Config config( "locale" ); | 135 | Config config( "locale" ); |
136 | config.setGroup( "Location" ); | 136 | config.setGroup( "Location" ); |
137 | selTimeZone->setCurrentZone( config.readEntry( "Timezone", "America/New_York" ) ); | 137 | selTimeZone->setCurrentZone( config.readEntry( "Timezone", "America/New_York" ) ); |
138 | use12HourTime = FALSE; | 138 | use12HourTime = FALSE; |
139 | setDateTime( QDateTime::currentDateTime() ); | 139 | setDateTime( QDateTime::currentDateTime() ); |
140 | } | 140 | } |
141 | 141 | ||
142 | TimeTabWidget::~TimeTabWidget() | 142 | TimeTabWidget::~TimeTabWidget() |
143 | { | 143 | { |
144 | } | 144 | } |
145 | 145 | ||
146 | void TimeTabWidget::saveSettings( bool commit ) | 146 | void TimeTabWidget::saveSettings( bool commit ) |
147 | { | 147 | { |
148 | if ( commit ) | 148 | if ( commit ) |
149 | { | 149 | { |
150 | // Set timezone and announce to world | 150 | // Set timezone and announce to world |
151 | QString tz = selTimeZone->currentZone(); | 151 | QString tz = selTimeZone->currentZone(); |
152 | Config config("locale"); | 152 | Config config("locale"); |
153 | config.setGroup( "Location" ); | 153 | config.setGroup( "Location" ); |
154 | config.writeEntry( "Timezone", tz ); | 154 | config.writeEntry( "Timezone", tz ); |
155 | setenv( "TZ", tz, 1 ); | 155 | setenv( "TZ", tz, 1 ); |
156 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); | 156 | QCopEnvelope setTimeZone( "QPE/System", "timeChange(QString)" ); |
157 | setTimeZone << tz; | 157 | setTimeZone << tz; |
158 | 158 | ||
159 | // If controls have a valid date & time, update systemtime | 159 | // If controls have a valid date & time, update systemtime |
160 | int hour = sbHour->value(); | 160 | int hour = sbHour->value(); |
161 | if ( use12HourTime && cbAmpm->currentItem() == ValuePM ) | 161 | if ( use12HourTime && cbAmpm->currentItem() == ValuePM ) |
162 | hour += 12; | 162 | hour += 12; |
163 | QDateTime dt( btnDate->date(), QTime ( hour, sbMin->value(), QTime::currentTime().second() ) ); | 163 | QDateTime dt( btnDate->date(), QTime ( hour, sbMin->value(), QTime::currentTime().second() ) ); |
164 | setSystemTime( dt ); | 164 | setSystemTime( dt ); |
165 | } | 165 | } |
166 | else | 166 | else |
167 | { | 167 | { |
168 | // 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) |
169 | system("/sbin/hwclock --hctosys --utc"); | 169 | system("/sbin/hwclock --hctosys --utc"); |
170 | } | 170 | } |
171 | } | 171 | } |
172 | 172 | ||
173 | void TimeTabWidget::setDateTime( const QDateTime &dt ) | 173 | void TimeTabWidget::setDateTime( const QDateTime &dt ) |
174 | { | 174 | { |
175 | // Set time | 175 | // Set time |
176 | QTime t = dt.time(); | 176 | QTime t = dt.time(); |
177 | if( use12HourTime ) | 177 | if( use12HourTime ) |
178 | { | 178 | { |
179 | int show_hour = t.hour(); | 179 | int show_hour = t.hour(); |
180 | if ( t.hour() >= 12 ) | 180 | if ( t.hour() > 12 ) |
181 | { | 181 | { |
182 | show_hour -= 12; | 182 | show_hour -= 12; |
183 | cbAmpm->setCurrentItem( ValuePM ); | 183 | cbAmpm->setCurrentItem( ValuePM ); |
184 | } | 184 | } |
185 | else | 185 | else |
186 | { | 186 | { |
187 | cbAmpm->setCurrentItem( ValueAM ); | 187 | cbAmpm->setCurrentItem( ValueAM ); |
188 | } | 188 | } |
189 | if ( show_hour == 0 ) | 189 | if ( show_hour == 0 ) |
190 | show_hour = 12; | 190 | show_hour = 12; |
191 | sbHour->setValue( show_hour ); | 191 | sbHour->setValue( show_hour ); |
192 | } | 192 | } |
193 | else | 193 | else |
194 | { | 194 | { |
195 | sbHour->setValue( t.hour() ); | 195 | sbHour->setValue( t.hour() ); |
196 | } | 196 | } |
197 | sbMin->setValue( t.minute() ); | 197 | sbMin->setValue( t.minute() ); |
198 | 198 | ||
199 | // Set date | 199 | // Set date |
200 | btnDate->setDate( dt.date() ); | 200 | btnDate->setDate( dt.date() ); |
201 | } | 201 | } |
202 | 202 | ||
203 | void TimeTabWidget::setNTPBtnEnabled( bool enabled ) | 203 | void TimeTabWidget::setNTPBtnEnabled( bool enabled ) |
204 | { | 204 | { |
205 | m_ntpBtn->setEnabled( enabled ); | 205 | m_ntpBtn->setEnabled( enabled ); |
206 | } | 206 | } |
207 | 207 | ||
208 | void TimeTabWidget::setSystemTime( const QDateTime &dt ) | 208 | void TimeTabWidget::setSystemTime( const QDateTime &dt ) |
209 | { | 209 | { |
210 | // Set system clock | 210 | // Set system clock |
211 | if ( dt.isValid() ) | 211 | if ( dt.isValid() ) |
212 | { | 212 | { |
213 | struct timeval myTv; | 213 | struct timeval myTv; |
214 | int t = TimeConversion::toUTC( dt ); | 214 | int t = TimeConversion::toUTC( dt ); |
215 | myTv.tv_sec = t; | 215 | myTv.tv_sec = t; |
216 | myTv.tv_usec = 0; | 216 | myTv.tv_usec = 0; |
217 | 217 | ||
218 | if ( myTv.tv_sec != -1 ) | 218 | if ( myTv.tv_sec != -1 ) |
219 | ::settimeofday( &myTv, 0 ); | 219 | ::settimeofday( &myTv, 0 ); |
220 | 220 | ||
221 | /* | 221 | /* |
222 | * Commit the datetime to the 'hardware' | 222 | * Commit the datetime to the 'hardware' |
223 | * as Global::writeHWClock() is a NOOP with Opie Alarm | 223 | * as Global::writeHWClock() is a NOOP with Opie Alarm |
224 | */ | 224 | */ |
225 | system("/sbin/hwclock --systohc --utc"); | 225 | system("/sbin/hwclock --systohc --utc"); |
226 | } | 226 | } |
227 | } | 227 | } |
228 | 228 | ||
229 | void TimeTabWidget::slotUse12HourTime( int i ) | 229 | void TimeTabWidget::slotUse12HourTime( int i ) |
230 | { | 230 | { |
231 | use12HourTime = (i == 1); | 231 | use12HourTime = (i == 1); |
232 | 232 | ||
233 | cbAmpm->setEnabled( use12HourTime ); | 233 | cbAmpm->setEnabled( use12HourTime ); |
234 | 234 | ||
235 | int show_hour = sbHour->value(); | 235 | int show_hour = sbHour->value(); |
236 | 236 | ||
237 | if ( use12HourTime ) | 237 | if ( use12HourTime ) |
238 | { | 238 | { |
239 | sbHour->setMinValue( 1 ); | 239 | sbHour->setMinValue( 1 ); |
240 | sbHour->setMaxValue( 12 ); | 240 | sbHour->setMaxValue( 12 ); |
241 | 241 | ||
242 | if ( show_hour >= 12 ) | 242 | if ( show_hour > 12 ) |
243 | { | 243 | { |
244 | show_hour -= 12; | 244 | show_hour -= 12; |
245 | cbAmpm->setCurrentItem( ValuePM ); | 245 | cbAmpm->setCurrentItem( ValuePM ); |
246 | } | 246 | } |
247 | else | 247 | else |
248 | { | 248 | { |
249 | cbAmpm->setCurrentItem( ValueAM ); | 249 | cbAmpm->setCurrentItem( ValueAM ); |
250 | } | 250 | } |
251 | if ( show_hour == 0 ) | 251 | if ( show_hour == 0 ) |
252 | show_hour = 12; | 252 | show_hour = 12; |
253 | } | 253 | } |
254 | else | 254 | else |
255 | { | 255 | { |
256 | sbHour->setMinValue( 0 ); | 256 | sbHour->setMinValue( 0 ); |
257 | sbHour->setMaxValue( 23 ); | 257 | sbHour->setMaxValue( 23 ); |
258 | 258 | ||
259 | if ( cbAmpm->currentItem() == ValuePM ) | 259 | if ( cbAmpm->currentItem() == ValuePM ) |
260 | { | 260 | { |
261 | show_hour += 12; | 261 | show_hour += 12; |
262 | if ( show_hour == 24 ) | 262 | if ( show_hour == 24 ) |
263 | show_hour = 0; | 263 | show_hour = 0; |
264 | } | 264 | } |
265 | } | 265 | } |
266 | 266 | ||
267 | sbHour->setValue( show_hour ); | 267 | sbHour->setValue( show_hour ); |
268 | } | 268 | } |
269 | 269 | ||
270 | void TimeTabWidget::slotDateFormatChanged( const DateFormat &df ) | 270 | void TimeTabWidget::slotDateFormatChanged( const DateFormat &df ) |
271 | { | 271 | { |
272 | btnDate->setDateFormat( df ); | 272 | btnDate->setDateFormat( df ); |
273 | } | 273 | } |
274 | 274 | ||
275 | void TimeTabWidget::slotWeekStartChanged( int monday ) | 275 | void TimeTabWidget::slotWeekStartChanged( int monday ) |
276 | { | 276 | { |
277 | btnDate->setWeekStartsMonday( monday ); | 277 | btnDate->setWeekStartsMonday( monday ); |
278 | } | 278 | } |
279 | 279 | ||
280 | void TimeTabWidget::slotTZChanged( const QString &newtz ) | 280 | void TimeTabWidget::slotTZChanged( const QString &newtz ) |
281 | { | 281 | { |
282 | // Check timezone has a valid file in /usr/share/zoneinfo | 282 | // Check timezone has a valid file in /usr/share/zoneinfo |
283 | if(!QFile::exists("/usr/share/zoneinfo/" + newtz)) { | 283 | if(!QFile::exists("/usr/share/zoneinfo/" + newtz)) { |
284 | QMessageBox::warning(this, tr("Time zone file missing"), | 284 | QMessageBox::warning(this, tr("Time zone file missing"), |
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)); | 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)); |
286 | } | 286 | } |
287 | else { | 287 | else { |
288 | // If controls have a valid date & time, update systemtime | 288 | // If controls have a valid date & time, update systemtime |
289 | int hour = sbHour->value(); | 289 | int hour = sbHour->value(); |
290 | if ( use12HourTime && cbAmpm->currentItem() == ValuePM ) | 290 | if ( use12HourTime && cbAmpm->currentItem() == ValuePM ) |