summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/clock/clock.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp
index ecbf12f..4d92683 100644
--- a/noncore/tools/clock/clock.cpp
+++ b/noncore/tools/clock/clock.cpp
@@ -394,257 +394,259 @@ void Clock::slotSnooze()
394 "alarm(QDateTime,int)", warn ); 394 "alarm(QDateTime,int)", warn );
395 395
396} 396}
397 397
398//toggles alarm on/off 398//toggles alarm on/off
399void Clock::slotToggleAlarm() 399void Clock::slotToggleAlarm()
400{ 400{
401 Config config( "qpe" ); 401 Config config( "qpe" );
402 config.setGroup( "Time" ); 402 config.setGroup( "Time" );
403 if ( alarmBool ) 403 if ( alarmBool )
404 { 404 {
405 config.writeEntry( "clockAlarmSet", "FALSE" ); 405 config.writeEntry( "clockAlarmSet", "FALSE" );
406 alarmOffBtn->setText( tr( "Alarm Is Off" ) ); 406 alarmOffBtn->setText( tr( "Alarm Is Off" ) );
407 snoozeBtn->hide(); 407 snoozeBtn->hide();
408 alarmBool = FALSE; 408 alarmBool = FALSE;
409 alarmOff(); 409 alarmOff();
410 } 410 }
411 else 411 else
412 { 412 {
413 config.writeEntry( "clockAlarmSet", "TRUE" ); 413 config.writeEntry( "clockAlarmSet", "TRUE" );
414 alarmOffBtn->setText( tr( "Alarm Is On" ) ); 414 alarmOffBtn->setText( tr( "Alarm Is On" ) );
415 snoozeBtn->show(); 415 snoozeBtn->show();
416 alarmBool = TRUE; 416 alarmBool = TRUE;
417 alarmOn(); 417 alarmOn();
418 } 418 }
419 config.write(); 419 config.write();
420} 420}
421 421
422void Clock::alarmOn() 422void Clock::alarmOn()
423{ 423{
424 QDate d = QDate::currentDate(); 424 QDate d = QDate::currentDate();
425 QTime tm( ( int ) hour, ( int ) minute, 0 ); 425 QTime tm( ( int ) hour, ( int ) minute, 0 );
426 qDebug( "Time set " + tm.toString() ); 426 qDebug( "Time set " + tm.toString() );
427 QTime t = QTime::currentTime(); 427 QTime t = QTime::currentTime();
428 if ( t > tm ) 428 if ( t > tm )
429 d = d.addDays( 1 ); 429 d = d.addDays( 1 );
430 int warn = 0; 430 int warn = 0;
431 QDateTime whenl( d, tm ); 431 QDateTime whenl( d, tm );
432 when = whenl; 432 when = whenl;
433 AlarmServer::addAlarm( when, 433 AlarmServer::addAlarm( when,
434 "QPE/Application/clock", 434 "QPE/Application/clock",
435 "alarm(QDateTime,int)", warn ); 435 "alarm(QDateTime,int)", warn );
436// setCaption( "Alarm set: " + whenl.toString() ); 436// setCaption( "Alarm set: " + whenl.toString() );
437 setCaption( tr("Alarm set: %1" ).arg(whenl.toString()) ); 437 setCaption( tr("Alarm set: %1" ).arg(whenl.toString()) );
438} 438}
439 439
440void Clock::alarmOff() 440void Clock::alarmOff()
441{ 441{
442 int warn = 0; 442 int warn = 0;
443 bSound = FALSE; 443 bSound = FALSE;
444 AlarmServer::deleteAlarm( when, 444 AlarmServer::deleteAlarm( when,
445 "QPE/Application/clock", 445 "QPE/Application/clock",
446 "alarm(QDateTime,int)", warn ); 446 "alarm(QDateTime,int)", warn );
447 qDebug( "Alarm Off " + when.toString() ); 447 qDebug( "Alarm Off " + when.toString() );
448 setCaption( tr("Clock") ); 448 setCaption( tr("Clock") );
449} 449}
450 450
451void Clock::clearTimer() 451void Clock::clearTimer()
452{ 452{
453 alarmOffBtn->setText( tr( "Alarm Is Off" ) ); 453 alarmOffBtn->setText( tr( "Alarm Is Off" ) );
454 alarmBool = FALSE; 454 alarmBool = FALSE;
455 snoozeBtn->hide(); 455 snoozeBtn->hide();
456 setCaption( tr("Clock") ); 456 setCaption( tr("Clock") );
457} 457}
458 458
459void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ ) 459void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ )
460{ 460{
461 int stopTimer = 0; 461 int stopTimer = 0;
462 int timerStay = 5000; 462 int timerStay = 5000;
463 bSound = TRUE; 463 bSound = TRUE;
464 qDebug( "Message received in clock" ); 464 qDebug( "Message received in clock" );
465 if ( msg == "alarm(QDateTime,int)" ) 465 if ( msg == "alarm(QDateTime,int)" )
466 { 466 {
467 Config config( "qpe" ); 467 Config config( "qpe" );
468 config.setGroup( "Time" ); 468 config.setGroup( "Time" );
469 if ( config.readBoolEntry( "mp3Alarm", 0 ) ) 469 if ( config.readBoolEntry( "mp3Alarm", 0 ) )
470 { 470 {
471 clearTimer(); 471 clearTimer();
472 pthread_t thread; 472 pthread_t thread;
473 pthread_create(&thread, NULL, (void * (*) (void *))startPlayer, NULL/* &*/); 473 pthread_create(&thread, NULL, (void * (*) (void *))startPlayer, NULL/* &*/);
474 474
475 } 475 }
476 else 476 else
477 { 477 {
478 478
479 Sound::soundAlarm(); 479 Sound::soundAlarm();
480 stopTimer = startTimer( timerStay ); 480 stopTimer = startTimer( timerStay );
481 } 481 }
482 } 482 }
483 483
484 if ( msg == "timerStart()" ) 484 if ( msg == "timerStart()" )
485 { 485 {
486 slotStartTimer(); 486 slotStartTimer();
487 } 487 }
488 if ( msg == "timerStop()" ) 488 if ( msg == "timerStop()" )
489 { 489 {
490 slotStopTimer(); 490 slotStopTimer();
491 } 491 }
492 if ( msg == "timerReset()" ) 492 if ( msg == "timerReset()" )
493 { 493 {
494 slotResetTimer(); 494 slotResetTimer();
495 } 495 }
496 496
497 show(); 497 show();
498 raise(); 498 raise();
499 QPEApplication::setKeepRunning(); 499 QPEApplication::setKeepRunning();
500 setActiveWindow(); 500 setActiveWindow();
501} 501}
502 502
503void Clock::timerEvent( QTimerEvent *e ) 503void Clock::timerEvent( QTimerEvent *e )
504{ 504{
505 static int stop = 0; 505 static int stop = 0;
506 if ( stop < 120 && bSound ) 506 if ( stop < 120 && bSound )
507 { 507 {
508 Sound::soundAlarm(); 508 Sound::soundAlarm();
509 stop++; 509 stop++;
510 } 510 }
511 else 511 else
512 { 512 {
513 stop = 0; 513 stop = 0;
514 killTimer( e->timerId() ); 514 killTimer( e->timerId() );
515 clearTimer(); 515 clearTimer();
516 setCaption( tr( "Clock: Alarm was missed." ) ); 516 setCaption( tr( "Clock: Alarm was missed." ) );
517 } 517 }
518} 518}
519 519
520AnalogClock::AnalogClock(QWidget * parent, const char * name) : QFrame( parent, name ), clear(true) 520AnalogClock::AnalogClock(QWidget * parent, const char * name) : QFrame( parent, name ), clear(true)
521{ 521{
522 bg = Resource::loadPixmap("clock/bg"); 522 QWidget *d = QApplication::desktop();
523 if(d->width() <= 240)
524 bg = Resource::loadPixmap("clock/bg");
523} 525}
524 526
525QSizePolicy AnalogClock::sizePolicy() const 527QSizePolicy AnalogClock::sizePolicy() const
526{ 528{
527 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); 529 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
528} 530}
529 531
530void AnalogClock::drawContents( QPainter *p ) 532void AnalogClock::drawContents( QPainter *p )
531{ 533{
532 QRect r = contentsRect(); 534 QRect r = contentsRect();
533 QRect fr; 535 QRect fr;
534 536
535 p->drawPixmap(QPoint(0, 0), bg, r); 537 p->drawPixmap(QPoint(0, 0), bg, r);
536 538
537 if ( r. width ( ) > r. height ( )) 539 if ( r. width ( ) > r. height ( ))
538 fr. setRect (( r. width ( ) - r. height ( )) / 2, r. y ( ), r. height ( ), r. height ( )); 540 fr. setRect (( r. width ( ) - r. height ( )) / 2, r. y ( ), r. height ( ), r. height ( ));
539 else 541 else
540 fr. setRect ( r. x ( ), ( r. height ( ) - r. width ( )) / 2, r. width ( ), r. width ( )); 542 fr. setRect ( r. x ( ), ( r. height ( ) - r. width ( )) / 2, r. width ( ), r. width ( ));
541 543
542 QPoint center = fr. center ( ); // ( fr.x() + fr.width() / 2, fr.y() + fr.height() / 2 ); 544 QPoint center = fr. center ( ); // ( fr.x() + fr.width() / 2, fr.y() + fr.height() / 2 );
543 QPoint l1 ( center. x ( ), fr. y ( ) + 2 ); 545 QPoint l1 ( center. x ( ), fr. y ( ) + 2 );
544 QPoint l2 ( center. x ( ), fr. y ( ) + 8 ); 546 QPoint l2 ( center. x ( ), fr. y ( ) + 8 );
545 547
546 548
547 549
548 if ( clear ) 550 if ( clear )
549 { 551 {
550 erase ( r ); 552 erase ( r );
551 p-> setPen ( NoPen ); 553 p-> setPen ( NoPen );
552 p-> setBrush ( colorGroup ( ). color ( QColorGroup::Base )); 554 p-> setBrush ( colorGroup ( ). color ( QColorGroup::Base ));
553 p-> drawEllipse ( fr ); 555 p-> drawEllipse ( fr );
554 p-> setBrush ( NoBrush ); 556 p-> setBrush ( NoBrush );
555 557
556 // draw ticks 558 // draw ticks
557 p->setPen( QPen( colorGroup ( ). color ( QColorGroup::Text ), 1 ) ); 559 p->setPen( QPen( colorGroup ( ). color ( QColorGroup::Text ), 1 ) );
558 for ( int i = 0; i < 12; i++ ) 560 for ( int i = 0; i < 12; i++ )
559 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); 561 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) );
560 } 562 }
561 else 563 else
562 { 564 {
563 drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Base ), prevTime, &currTime ); 565 drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Base ), prevTime, &currTime );
564 } 566 }
565 567
566 drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Text ), currTime ); 568 drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Text ), currTime );
567 569
568 prevTime = currTime; 570 prevTime = currTime;
569} 571}
570 572
571void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 ) 573void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 )
572{ 574{
573 QPoint center = r. center ( ); 575 QPoint center = r. center ( );
574 576
575 QPoint h1( center. x ( ), r. y ( ) + r. height ( ) / 4 ); 577 QPoint h1( center. x ( ), r. y ( ) + r. height ( ) / 4 );
576 QPoint h2( center. x ( ), center. y ( ) ); 578 QPoint h2( center. x ( ), center. y ( ) );
577 579
578 QPoint m1( center. x ( ), r.y() + r.height() / 8 ); 580 QPoint m1( center. x ( ), r.y() + r.height() / 8 );
579 QPoint m2( center. x ( ), center. y ( ) ); 581 QPoint m2( center. x ( ), center. y ( ) );
580 582
581 QPoint s1( center. x ( ), r. y ( ) + 8 ); 583 QPoint s1( center. x ( ), r. y ( ) + 8 );
582 QPoint s2( center. x ( ), center. y ( ) ); 584 QPoint s2( center. x ( ), center. y ( ) );
583 585
584 586
585 if ( !t2 || ( t. minute ( ) != t2-> minute ( ) || t. hour ( ) != t2-> hour ( ))) { 587 if ( !t2 || ( t. minute ( ) != t2-> minute ( ) || t. hour ( ) != t2-> hour ( ))) {
586 // draw hour pointer 588 // draw hour pointer
587 h1 = rotate( center, h1, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); 589 h1 = rotate( center, h1, 30 * ( t.hour() % 12 ) + t.minute() / 2 );
588 h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); 590 h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 );
589 p-> setPen ( QPen ( c, 3 )); 591 p-> setPen ( QPen ( c, 3 ));
590 p-> drawLine ( h1, h2 ); 592 p-> drawLine ( h1, h2 );
591 } 593 }
592 594
593 if ( !t2 || ( t. minute ( ) != t2-> minute ( ))) { 595 if ( !t2 || ( t. minute ( ) != t2-> minute ( ))) {
594 // draw minute pointer 596 // draw minute pointer
595 m1 = rotate( center, m1, t.minute() * 6 ); 597 m1 = rotate( center, m1, t.minute() * 6 );
596 m2 = rotate( center, m2, t.minute() * 6 ); 598 m2 = rotate( center, m2, t.minute() * 6 );
597 p-> setPen ( QPen ( c, 2 )); 599 p-> setPen ( QPen ( c, 2 ));
598 p-> drawLine ( m1, m2 ); 600 p-> drawLine ( m1, m2 );
599 } 601 }
600 602
601 if ( !t2 || ( t. second ( ) != t2-> second ( ))) { 603 if ( !t2 || ( t. second ( ) != t2-> second ( ))) {
602 // draw second pointer 604 // draw second pointer
603 s1 = rotate( center, s1, t.second() * 6 ); 605 s1 = rotate( center, s1, t.second() * 6 );
604 s2 = rotate( center, s2, t.second() * 6 ); 606 s2 = rotate( center, s2, t.second() * 6 );
605 p-> setPen ( QPen ( c, 1 )); 607 p-> setPen ( QPen ( c, 1 ));
606 p-> drawLine ( s1, s2 ); 608 p-> drawLine ( s1, s2 );
607 } 609 }
608} 610}
609 611
610void AnalogClock::display( const QTime& t ) 612void AnalogClock::display( const QTime& t )
611{ 613{
612 currTime = t; 614 currTime = t;
613 clear = false; 615 clear = false;
614 repaint( false ); 616 repaint( false );
615 clear = true; 617 clear = true;
616} 618}
617 619
618QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) 620QPoint AnalogClock::rotate( QPoint c, QPoint p, int a )
619{ 621{
620 double angle = deg2rad * ( - a + 180 ); 622 double angle = deg2rad * ( - a + 180 );
621 double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - 623 double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) -
622 ( p.y() - c.y() ) * sin( angle ); 624 ( p.y() - c.y() ) * sin( angle );
623 double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + 625 double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) +
624 ( p.x() - c.x() ) * sin( angle ); 626 ( p.x() - c.x() ) * sin( angle );
625 return QPoint( nx, ny ); 627 return QPoint( nx, ny );
626} 628}
627 629
628void Clock::slotAdjustTime() 630void Clock::slotAdjustTime()
629{ 631{
630 QCopEnvelope e( "QPE/System", "execute(QString)" ); 632 QCopEnvelope e( "QPE/System", "execute(QString)" );
631 e << QString( "systemtime" ); 633 e << QString( "systemtime" );
632} 634}
633 635
634void Clock::slotStartTimer() 636void Clock::slotStartTimer()
635{ 637{
636 if ( clockRB->isChecked() ) 638 if ( clockRB->isChecked() )
637 setSwatchMode( 1); 639 setSwatchMode( 1);
638 startSWatch(); 640 startSWatch();
639} 641}
640 642
641void Clock::slotStopTimer() 643void Clock::slotStopTimer()
642{ 644{
643 if ( clockRB->isChecked() ) 645 if ( clockRB->isChecked() )
644 setSwatchMode( 1); 646 setSwatchMode( 1);
645 stopSWatch(); 647 stopSWatch();
646} 648}
647 649
648void Clock::slotResetTimer() 650void Clock::slotResetTimer()
649{ 651{
650 if ( clockRB->isChecked() ) 652 if ( clockRB->isChecked() )