-rw-r--r-- | noncore/tools/clock/clock.cpp | 380 |
1 files changed, 197 insertions, 183 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp index 0eb2b83..74b7147 100644 --- a/noncore/tools/clock/clock.cpp +++ b/noncore/tools/clock/clock.cpp | |||
@@ -58,11 +58,11 @@ const int sw_prec = 2; | |||
58 | 58 | ||
59 | void startPlayer() | 59 | void startPlayer() |
60 | { | 60 | { |
61 | Config config( "qpe" ); | 61 | Config config( "qpe" ); |
62 | config.setGroup( "Time" ); | 62 | config.setGroup( "Time" ); |
63 | sleep(15); | 63 | sleep(15); |
64 | QCopEnvelope e( "QPE/Application/opieplayer", "setDocument(QString)" ); | 64 | QCopEnvelope e( "QPE/Application/opieplayer", "setDocument(QString)" ); |
65 | e << config.readEntry( "mp3File", "" ); | 65 | e << config.readEntry( "mp3File", "" ); |
66 | } | 66 | } |
67 | 67 | ||
68 | 68 | ||
@@ -183,24 +183,25 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f ) | |||
183 | minute = tmp.toInt( &ok, 10 ); | 183 | minute = tmp.toInt( &ok, 10 ); |
184 | 184 | ||
185 | if ( config.readEntry( "clockAlarmSet", "FALSE" ) == "TRUE" ) | 185 | if ( config.readEntry( "clockAlarmSet", "FALSE" ) == "TRUE" ) |
186 | { | 186 | { |
187 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); | 187 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); |
188 | alarmBool = TRUE; | 188 | alarmBool = TRUE; |
189 | snoozeBtn->show(); | 189 | snoozeBtn->show(); |
190 | } | 190 | } |
191 | else | 191 | else |
192 | { | 192 | { |
193 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); | 193 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); |
194 | alarmBool = FALSE; | 194 | alarmBool = FALSE; |
195 | snoozeBtn->hide(); | 195 | snoozeBtn->hide(); |
196 | } | 196 | } |
197 | 197 | ||
198 | QTimer::singleShot( 0, this, SLOT( updateClock() ) ); | 198 | QTimer::singleShot( 0, this, SLOT( updateClock() ) ); |
199 | 199 | ||
200 | Config cfg( "Clock" ); | 200 | Config cfg( "Clock" ); |
201 | cfg.setGroup( "Mode" ); | 201 | cfg.setGroup( "Mode" ); |
202 | int mode = cfg.readBoolEntry( "clockMode");setSwatchMode( mode); | 202 | int mode = cfg.readBoolEntry( "clockMode"); |
203 | modeSelect( mode); | 203 | setSwatchMode( mode); |
204 | modeSelect( mode); | ||
204 | } | 205 | } |
205 | 206 | ||
206 | Clock::~Clock() | 207 | Clock::~Clock() |
@@ -211,46 +212,46 @@ Clock::~Clock() | |||
211 | void Clock::updateClock() | 212 | void Clock::updateClock() |
212 | { | 213 | { |
213 | if ( clockRB->isChecked() ) | 214 | if ( clockRB->isChecked() ) |
214 | { | 215 | { |
215 | QTime tm = QDateTime::currentDateTime().time(); | 216 | QTime tm = QDateTime::currentDateTime().time(); |
216 | QString s; | 217 | QString s; |
217 | if ( ampm ) | 218 | if ( ampm ) |
218 | { | 219 | { |
219 | int hour = tm.hour(); | 220 | int hour = tm.hour(); |
220 | if ( hour == 0 ) | 221 | if ( hour == 0 ) |
221 | hour = 12; | 222 | hour = 12; |
222 | if ( hour > 12 ) | 223 | if ( hour > 12 ) |
223 | hour -= 12; | 224 | hour -= 12; |
224 | s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); | 225 | s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); |
225 | ampmLabel->setText( ( tm.hour() >= 12 ) ? "PM" : "AM" ); | 226 | ampmLabel->setText( ( tm.hour() >= 12 ) ? "PM" : "AM" ); |
226 | ampmLabel->show(); | 227 | ampmLabel->show(); |
227 | } | 228 | } |
228 | else | 229 | else |
229 | { | 230 | { |
230 | s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); | 231 | s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); |
231 | ampmLabel->hide(); | 232 | ampmLabel->hide(); |
232 | } | 233 | } |
233 | lcd->display( s ); | 234 | lcd->display( s ); |
234 | lcd->repaint( FALSE ); | 235 | lcd->repaint( FALSE ); |
235 | aclock->display( QTime::currentTime() ); | 236 | aclock->display( QTime::currentTime() ); |
236 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); | 237 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); |
237 | } | 238 | } |
238 | else | 239 | else |
239 | { | 240 | { |
240 | QTime swatch_time; | 241 | QTime swatch_time; |
241 | QString lcdtext; | 242 | QString lcdtext; |
242 | int totalms = swatch_totalms; | 243 | int totalms = swatch_totalms; |
243 | if ( swatch_running ) | 244 | if ( swatch_running ) |
244 | totalms += swatch_start.elapsed(); | 245 | totalms += swatch_start.elapsed(); |
245 | swatch_time = QTime( 0, 0, 0 ).addMSecs( totalms ); | 246 | swatch_time = QTime( 0, 0, 0 ).addMSecs( totalms ); |
246 | QString d = swatch_running ? QString( " " ) | 247 | QString d = swatch_running ? QString( " " ) |
247 | : QString::number( totalms % 1000 + 1000 ); | 248 | : QString::number( totalms % 1000 + 1000 ); |
248 | lcdtext = swatch_time.toString() + "." + d.right( 3 ).left( sw_prec ); | 249 | lcdtext = swatch_time.toString() + "." + d.right( 3 ).left( sw_prec ); |
249 | lcd->display( lcdtext ); | 250 | lcd->display( lcdtext ); |
250 | lcd->repaint( FALSE ); | 251 | lcd->repaint( FALSE ); |
251 | aclock->display( swatch_time ); | 252 | aclock->display( swatch_time ); |
252 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); | 253 | date->setText( TimeString::longDateString( QDate::currentDate() ) ); |
253 | } | 254 | } |
254 | } | 255 | } |
255 | 256 | ||
256 | void Clock::changeClock( bool a ) | 257 | void Clock::changeClock( bool a ) |
@@ -267,35 +268,41 @@ void Clock::clearClock( void ) | |||
267 | 268 | ||
268 | void Clock::startSWatch() | 269 | void Clock::startSWatch() |
269 | { | 270 | { |
270 | swatch_start.start(); | 271 | if(swatch_running) { |
271 | set->setText( tr( "Stop" ) ); | 272 | stopSWatch(); |
272 | t->start( 1000 ); | 273 | return; |
273 | swatch_running = TRUE; | 274 | } |
274 | // disable screensaver while stop watch is running | 275 | qDebug("startSWatch()"); |
275 | toggleScreenSaver( FALSE ); | 276 | swatch_start.start(); |
277 | set->setText( tr( "Stop" ) ); | ||
278 | t->start( 1000 ); | ||
279 | swatch_running = TRUE; | ||
280 | // disable screensaver while stop watch is running | ||
281 | toggleScreenSaver( FALSE ); | ||
276 | } | 282 | } |
277 | 283 | ||
278 | void Clock::stopSWatch() | 284 | void Clock::stopSWatch() |
279 | { | 285 | { |
280 | swatch_totalms += swatch_start.elapsed(); | 286 | qDebug("stopSWatch()"); |
281 | set->setText( tr( "Start" ) ); | 287 | swatch_totalms += swatch_start.elapsed(); |
282 | t->stop(); | 288 | set->setText( tr( "Start" ) ); |
283 | swatch_running = FALSE; | 289 | t->stop(); |
284 | toggleScreenSaver( TRUE ); | 290 | swatch_running = FALSE; |
285 | updateClock(); | 291 | toggleScreenSaver( TRUE ); |
292 | updateClock(); | ||
286 | } | 293 | } |
287 | 294 | ||
288 | 295 | ||
289 | void Clock::slotSet() | 296 | void Clock::slotSet() |
290 | { | 297 | { |
291 | if ( t->isActive() ) | 298 | if ( t->isActive() ) |
292 | { | 299 | { |
293 | startSWatch(); | 300 | startSWatch(); |
294 | } | 301 | } |
295 | else | 302 | else |
296 | { | 303 | { |
297 | stopSWatch(); | 304 | stopSWatch(); |
298 | } | 305 | } |
299 | } | 306 | } |
300 | 307 | ||
301 | void Clock::slotReset() | 308 | void Clock::slotReset() |
@@ -312,30 +319,37 @@ void Clock::slotReset() | |||
312 | 319 | ||
313 | void Clock::modeSelect( int m ) | 320 | void Clock::modeSelect( int m ) |
314 | { | 321 | { |
315 | qDebug("Clock::modeSelect( %d) ", m); | 322 | qDebug("Clock::modeSelect( %d) ", m); |
316 | if ( m ) | 323 | if ( m != 0 ) |
317 | { | 324 | { |
318 | lcd->setNumDigits( 8 + 1 + sw_prec ); | 325 | lcd->setNumDigits( 8 + 1 + sw_prec ); |
319 | lcd->setMinimumWidth( lcd->sizeHint().width() ); | 326 | lcd->setMinimumWidth( lcd->sizeHint().width() ); |
320 | set->setEnabled( TRUE ); | 327 | set->setEnabled( TRUE ); |
321 | reset->setEnabled( TRUE ); | 328 | reset->setEnabled( TRUE ); |
322 | ampmLabel->hide(); | 329 | ampmLabel->hide(); |
323 | 330 | ||
324 | if ( !swatch_running ) | 331 | // if(m == 2) { |
325 | t->stop(); | 332 | if ( !swatch_running ) { |
326 | } | 333 | t->start( 1000 ); |
327 | else | 334 | } |
328 | { | 335 | // else |
329 | lcd->setNumDigits( 5 ); | 336 | // { |
330 | lcd->setMinimumWidth( lcd->sizeHint().width() ); | 337 | // stopSWatch(); |
331 | set->setEnabled( FALSE ); | 338 | // } |
332 | reset->setEnabled( FALSE ); | 339 | // } |
333 | t->start( 1000 ); | 340 | } |
334 | } | 341 | else //clock mode |
335 | 342 | { | |
336 | Config config( "Clock" ); | 343 | lcd->setNumDigits( 5 ); |
337 | config.setGroup( "Mode" ); | 344 | lcd->setMinimumWidth( lcd->sizeHint().width() ); |
338 | config.writeEntry( "clockMode", m ); | 345 | set->setEnabled( FALSE ); |
346 | reset->setEnabled( FALSE ); | ||
347 | t->start( 1000 ); | ||
348 | } | ||
349 | |||
350 | Config config( "Clock" ); | ||
351 | config.setGroup( "Mode" ); | ||
352 | config.writeEntry( "clockMode", m ); | ||
339 | updateClock(); | 353 | updateClock(); |
340 | } | 354 | } |
341 | 355 | ||
@@ -387,21 +401,21 @@ void Clock::slotToggleAlarm() | |||
387 | Config config( "qpe" ); | 401 | Config config( "qpe" ); |
388 | config.setGroup( "Time" ); | 402 | config.setGroup( "Time" ); |
389 | if ( alarmBool ) | 403 | if ( alarmBool ) |
390 | { | 404 | { |
391 | config.writeEntry( "clockAlarmSet", "FALSE" ); | 405 | config.writeEntry( "clockAlarmSet", "FALSE" ); |
392 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); | 406 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); |
393 | snoozeBtn->hide(); | 407 | snoozeBtn->hide(); |
394 | alarmBool = FALSE; | 408 | alarmBool = FALSE; |
395 | alarmOff(); | 409 | alarmOff(); |
396 | } | 410 | } |
397 | else | 411 | else |
398 | { | 412 | { |
399 | config.writeEntry( "clockAlarmSet", "TRUE" ); | 413 | config.writeEntry( "clockAlarmSet", "TRUE" ); |
400 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); | 414 | alarmOffBtn->setText( tr( "Alarm Is On" ) ); |
401 | snoozeBtn->show(); | 415 | snoozeBtn->show(); |
402 | alarmBool = TRUE; | 416 | alarmBool = TRUE; |
403 | alarmOn(); | 417 | alarmOn(); |
404 | } | 418 | } |
405 | config.write(); | 419 | config.write(); |
406 | } | 420 | } |
407 | 421 | ||
@@ -435,10 +449,10 @@ void Clock::alarmOff() | |||
435 | 449 | ||
436 | void Clock::clearTimer() | 450 | void Clock::clearTimer() |
437 | { | 451 | { |
438 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); | 452 | alarmOffBtn->setText( tr( "Alarm Is Off" ) ); |
439 | alarmBool = FALSE; | 453 | alarmBool = FALSE; |
440 | snoozeBtn->hide(); | 454 | snoozeBtn->hide(); |
441 | setCaption( "Clock" ); | 455 | setCaption( "Clock" ); |
442 | } | 456 | } |
443 | 457 | ||
444 | void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ ) | 458 | void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ ) |
@@ -448,36 +462,36 @@ void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ ) | |||
448 | bSound = TRUE; | 462 | bSound = TRUE; |
449 | qDebug( "Message received in clock" ); | 463 | qDebug( "Message received in clock" ); |
450 | if ( msg == "alarm(QDateTime,int)" ) | 464 | if ( msg == "alarm(QDateTime,int)" ) |
451 | { | 465 | { |
452 | Config config( "qpe" ); | 466 | Config config( "qpe" ); |
453 | config.setGroup( "Time" ); | 467 | config.setGroup( "Time" ); |
454 | if ( config.readBoolEntry( "mp3Alarm", 0 ) ) | 468 | if ( config.readBoolEntry( "mp3Alarm", 0 ) ) |
455 | { | 469 | { |
456 | clearTimer(); | 470 | clearTimer(); |
457 | pthread_t thread; | 471 | pthread_t thread; |
458 | pthread_create(&thread, NULL, (void * (*) (void *))startPlayer, NULL/* &*/); | 472 | pthread_create(&thread, NULL, (void * (*) (void *))startPlayer, NULL/* &*/); |
459 | 473 | ||
460 | } | 474 | } |
461 | else | 475 | else |
462 | { | 476 | { |
463 | 477 | ||
464 | Sound::soundAlarm(); | 478 | Sound::soundAlarm(); |
465 | stopTimer = startTimer( timerStay ); | 479 | stopTimer = startTimer( timerStay ); |
466 | } | 480 | } |
467 | } | 481 | } |
468 | 482 | ||
469 | if ( msg == "timerStart()" ) | 483 | if ( msg == "timerStart()" ) |
470 | { | 484 | { |
471 | slotStartTimer(); | 485 | slotStartTimer(); |
472 | } | 486 | } |
473 | if ( msg == "timerStop()" ) | 487 | if ( msg == "timerStop()" ) |
474 | { | 488 | { |
475 | slotStopTimer(); | 489 | slotStopTimer(); |
476 | } | 490 | } |
477 | if ( msg == "timerReset()" ) | 491 | if ( msg == "timerReset()" ) |
478 | { | 492 | { |
479 | slotResetTimer(); | 493 | slotResetTimer(); |
480 | } | 494 | } |
481 | 495 | ||
482 | show(); | 496 | show(); |
483 | raise(); | 497 | raise(); |
@@ -489,17 +503,17 @@ void Clock::timerEvent( QTimerEvent *e ) | |||
489 | { | 503 | { |
490 | static int stop = 0; | 504 | static int stop = 0; |
491 | if ( stop < 120 && bSound ) | 505 | if ( stop < 120 && bSound ) |
492 | { | 506 | { |
493 | Sound::soundAlarm(); | 507 | Sound::soundAlarm(); |
494 | stop++; | 508 | stop++; |
495 | } | 509 | } |
496 | else | 510 | else |
497 | { | 511 | { |
498 | stop = 0; | 512 | stop = 0; |
499 | killTimer( e->timerId() ); | 513 | killTimer( e->timerId() ); |
500 | clearTimer(); | 514 | clearTimer(); |
501 | setCaption( tr( "Clock: Alarm was missed." ) ); | 515 | setCaption( tr( "Clock: Alarm was missed." ) ); |
502 | } | 516 | } |
503 | } | 517 | } |
504 | 518 | ||
505 | 519 | ||
@@ -525,22 +539,22 @@ void AnalogClock::drawContents( QPainter *p ) | |||
525 | 539 | ||
526 | 540 | ||
527 | if ( clear ) | 541 | if ( clear ) |
528 | { | 542 | { |
529 | erase ( r ); | 543 | erase ( r ); |
530 | p-> setPen ( NoPen ); | 544 | p-> setPen ( NoPen ); |
531 | p-> setBrush ( colorGroup ( ). color ( QColorGroup::Base )); | 545 | p-> setBrush ( colorGroup ( ). color ( QColorGroup::Base )); |
532 | p-> drawEllipse ( fr ); | 546 | p-> drawEllipse ( fr ); |
533 | p-> setBrush ( NoBrush ); | 547 | p-> setBrush ( NoBrush ); |
534 | 548 | ||
535 | // draw ticks | 549 | // draw ticks |
536 | p->setPen( QPen( colorGroup ( ). color ( QColorGroup::Text ), 1 ) ); | 550 | p->setPen( QPen( colorGroup ( ). color ( QColorGroup::Text ), 1 ) ); |
537 | for ( int i = 0; i < 12; i++ ) | 551 | for ( int i = 0; i < 12; i++ ) |
538 | p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); | 552 | p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); |
539 | } | 553 | } |
540 | else | 554 | else |
541 | { | 555 | { |
542 | drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Base ), prevTime, &currTime ); | 556 | drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Base ), prevTime, &currTime ); |
543 | } | 557 | } |
544 | 558 | ||
545 | drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Text ), currTime ); | 559 | drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Text ), currTime ); |
546 | 560 | ||
@@ -562,7 +576,7 @@ void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, c | |||
562 | 576 | ||
563 | 577 | ||
564 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ) || t. hour ( ) != t2-> hour ( ))) { | 578 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ) || t. hour ( ) != t2-> hour ( ))) { |
565 | // draw hour pointer | 579 | // draw hour pointer |
566 | h1 = rotate( center, h1, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); | 580 | h1 = rotate( center, h1, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); |
567 | h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); | 581 | h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); |
568 | p-> setPen ( QPen ( c, 3 )); | 582 | p-> setPen ( QPen ( c, 3 )); |
@@ -570,7 +584,7 @@ void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, c | |||
570 | } | 584 | } |
571 | 585 | ||
572 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ))) { | 586 | if ( !t2 || ( t. minute ( ) != t2-> minute ( ))) { |
573 | // draw minute pointer | 587 | // draw minute pointer |
574 | m1 = rotate( center, m1, t.minute() * 6 ); | 588 | m1 = rotate( center, m1, t.minute() * 6 ); |
575 | m2 = rotate( center, m2, t.minute() * 6 ); | 589 | m2 = rotate( center, m2, t.minute() * 6 ); |
576 | p-> setPen ( QPen ( c, 2 )); | 590 | p-> setPen ( QPen ( c, 2 )); |
@@ -578,7 +592,7 @@ void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, c | |||
578 | } | 592 | } |
579 | 593 | ||
580 | if ( !t2 || ( t. second ( ) != t2-> second ( ))) { | 594 | if ( !t2 || ( t. second ( ) != t2-> second ( ))) { |
581 | // draw second pointer | 595 | // draw second pointer |
582 | s1 = rotate( center, s1, t.second() * 6 ); | 596 | s1 = rotate( center, s1, t.second() * 6 ); |
583 | s2 = rotate( center, s2, t.second() * 6 ); | 597 | s2 = rotate( center, s2, t.second() * 6 ); |
584 | p-> setPen ( QPen ( c, 1 )); | 598 | p-> setPen ( QPen ( c, 1 )); |
@@ -613,28 +627,28 @@ void Clock::slotAdjustTime() | |||
613 | void Clock::slotStartTimer() | 627 | void Clock::slotStartTimer() |
614 | { | 628 | { |
615 | if ( clockRB->isChecked() ) | 629 | if ( clockRB->isChecked() ) |
616 | setSwatchMode( 1); | 630 | setSwatchMode( 1); |
617 | startSWatch(); | 631 | startSWatch(); |
618 | } | 632 | } |
619 | 633 | ||
620 | void Clock::slotStopTimer() | 634 | void Clock::slotStopTimer() |
621 | { | 635 | { |
622 | if ( clockRB->isChecked() ) | 636 | if ( clockRB->isChecked() ) |
623 | setSwatchMode( 1); | 637 | setSwatchMode( 1); |
624 | stopSWatch(); | 638 | stopSWatch(); |
625 | } | 639 | } |
626 | 640 | ||
627 | void Clock::slotResetTimer() | 641 | void Clock::slotResetTimer() |
628 | { | 642 | { |
629 | if ( clockRB->isChecked() ) | 643 | if ( clockRB->isChecked() ) |
630 | setSwatchMode( 1); | 644 | setSwatchMode( 1); |
631 | slotReset(); | 645 | slotReset(); |
632 | } | 646 | } |
633 | 647 | ||
634 | void Clock::setSwatchMode(int mode) | 648 | void Clock::setSwatchMode(int mode) |
635 | { | 649 | { |
636 | qDebug("Clock::setSwatchMode( %d)", mode); | 650 | qDebug("Clock::setSwatchMode( %d)", mode); |
637 | swatchRB->setChecked( mode); | 651 | swatchRB->setChecked( mode); |
638 | clearClock( ); | 652 | clearClock( ); |
639 | modeSelect( mode ); | 653 | modeSelect( mode ); |
640 | } | 654 | } |