summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/clock/clock.cpp380
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
@@ -60,7 +60,7 @@ 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}
@@ -185,13 +185,13 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
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
@@ -201,4 +201,5 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
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}
@@ -213,42 +214,42 @@ void Clock::updateClock()
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}
@@ -269,8 +270,13 @@ 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}
@@ -279,8 +285,9 @@ 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}
@@ -291,9 +298,9 @@ void Clock::slotSet()
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}
@@ -314,26 +321,33 @@ 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();
@@ -389,17 +403,17 @@ void Clock::slotToggleAlarm()
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();
@@ -437,6 +451,6 @@ 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}
@@ -450,32 +464,32 @@ void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ )
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
@@ -491,13 +505,13 @@ void Clock::timerEvent( QTimerEvent *e )
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}
@@ -527,18 +541,18 @@ void AnalogClock::drawContents( QPainter *p )
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
@@ -564,3 +578,3 @@ void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, c
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 );
@@ -572,3 +586,3 @@ void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, c
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 );
@@ -580,3 +594,3 @@ void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, c
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 );
@@ -615,4 +629,4 @@ void Clock::slotStartTimer()
615 if ( clockRB->isChecked() ) 629 if ( clockRB->isChecked() )
616 setSwatchMode( 1); 630 setSwatchMode( 1);
617 startSWatch(); 631 startSWatch();
618} 632}
@@ -622,4 +636,4 @@ void Clock::slotStopTimer()
622 if ( clockRB->isChecked() ) 636 if ( clockRB->isChecked() )
623 setSwatchMode( 1); 637 setSwatchMode( 1);
624 stopSWatch(); 638 stopSWatch();
625} 639}
@@ -629,3 +643,3 @@ void Clock::slotResetTimer()
629 if ( clockRB->isChecked() ) 643 if ( clockRB->isChecked() )
630 setSwatchMode( 1); 644 setSwatchMode( 1);
631slotReset(); 645slotReset();
@@ -635,6 +649,6 @@ 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}