summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2003-03-04 16:50:17 (UTC)
committer llornkcor <llornkcor>2003-03-04 16:50:17 (UTC)
commitbb765b9cd286d85eb8fa1d18199dfb7a29d57fc5 (patch) (unidiff)
tree80d69eef2975d1fb27a758aea7629d34c678a270
parent628a783e5d7ec07b5c073c94a77b614439d937ba (diff)
downloadopie-bb765b9cd286d85eb8fa1d18199dfb7a29d57fc5.zip
opie-bb765b9cd286d85eb8fa1d18199dfb7a29d57fc5.tar.gz
opie-bb765b9cd286d85eb8fa1d18199dfb7a29d57fc5.tar.bz2
added 3 qcop calls. timerStart(), timerStop() and timerReset()
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--noncore/tools/clock/clock.cpp171
-rw-r--r--noncore/tools/clock/clock.h15
2 files changed, 121 insertions, 65 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp
index 0937362..9898332 100644
--- a/noncore/tools/clock/clock.cpp
+++ b/noncore/tools/clock/clock.cpp
@@ -78,10 +78,6 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
78 setSpacing( 4 ); 78 setSpacing( 4 );
79 setMargin( 1 ); 79 setMargin( 1 );
80 80
81 Config config( "qpe" );
82 config.setGroup( "Time" );
83 ampm = config.readBoolEntry( "AMPM", TRUE );
84
85 81
86 snoozeBtn = new QPushButton ( this ); 82 snoozeBtn = new QPushButton ( this );
87 snoozeBtn->setText( tr( "Snooze" ) ); 83 snoozeBtn->setText( tr( "Snooze" ) );
@@ -128,18 +124,12 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
128 connect( grp, SIGNAL( clicked( int ) ), this, SLOT( modeSelect( int ) ) ); 124 connect( grp, SIGNAL( clicked( int ) ), this, SLOT( modeSelect( int ) ) );
129 grp->setButton( 0 ); 125 grp->setButton( 0 );
130 126
131 set 127 set = new QPushButton ( controls );
132 = new QPushButton ( controls ); 128 set->setMaximumSize( 50, 30 );
133 set 129 gl->addWidget( set , 0, 1 );
134 ->setMaximumSize( 50, 30 ); 130 set->setText( tr( "Start" ) );
135 gl->addWidget( set 131 set->setEnabled( FALSE );
136 , 0, 1 ); 132 grp->insert( set );
137 set
138 ->setText( tr( "Start" ) );
139 set
140 ->setEnabled( FALSE );
141 grp->insert( set
142 );
143 133
144 reset = new QPushButton ( controls ); 134 reset = new QPushButton ( controls );
145 gl->addWidget( reset, 1, 1 ); 135 gl->addWidget( reset, 1, 1 );
@@ -148,12 +138,11 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
148 grp->insert( reset ); 138 grp->insert( reset );
149 139
150 alarmOffBtn = new QPushButton ( controls ); 140 alarmOffBtn = new QPushButton ( controls );
151 // alarmOffBtn->setMaximumSize(60,30);
152 gl->addWidget( alarmOffBtn, 0, 2 ); 141 gl->addWidget( alarmOffBtn, 0, 2 );
153 142
154 alarmBtn = new QPushButton ( controls ); 143 alarmBtn = new QPushButton ( controls );
155 // alarmBtn->setMaximumSize(60,30);
156 gl->addWidget( alarmBtn, 1, 2 ); 144 gl->addWidget( alarmBtn, 1, 2 );
145
157 alarmBtn->setText( tr( "Set Alarm" ) ); 146 alarmBtn->setText( tr( "Set Alarm" ) );
158 147
159 OClickableLabel *click = new OClickableLabel( controls, "label" ); 148 OClickableLabel *click = new OClickableLabel( controls, "label" );
@@ -161,8 +150,7 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
161 gl->addMultiCellWidget( click, 3, 3, 0, 2, AlignHCenter ); 150 gl->addMultiCellWidget( click, 3, 3, 0, 2, AlignHCenter );
162 connect( click, SIGNAL( clicked() ), this, SLOT( slotAdjustTime() ) ); 151 connect( click, SIGNAL( clicked() ), this, SLOT( slotAdjustTime() ) );
163 152
164 connect( set 153 connect( set , SIGNAL( pressed() ), SLOT( slotSet() ) );
165 , SIGNAL( pressed() ), SLOT( slotSet() ) );
166 connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) ); 154 connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) );
167 155
168 connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) ); 156 connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) );
@@ -183,25 +171,36 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
183 171
184 connect( qApp, SIGNAL( clockChanged( bool ) ), this, SLOT( changeClock( bool ) ) ); 172 connect( qApp, SIGNAL( clockChanged( bool ) ), this, SLOT( changeClock( bool ) ) );
185 173
174
175 Config config( "qpe" );
176 config.setGroup( "Time" );
177 ampm = config.readBoolEntry( "AMPM", TRUE );
178
186 QString tmp = config.readEntry( "clockAlarmHour", "" ); 179 QString tmp = config.readEntry( "clockAlarmHour", "" );
187 bool ok; 180 bool ok;
188 hour = tmp.toInt( &ok, 10 ); 181 hour = tmp.toInt( &ok, 10 );
189 tmp = config.readEntry( "clockAlarmMinute", "" ); 182 tmp = config.readEntry( "clockAlarmMinute", "" );
190 minute = tmp.toInt( &ok, 10 ); 183 minute = tmp.toInt( &ok, 10 );
191 184
192 if ( config.readEntry( "clockAlarmSet", "FALSE" ) == "TRUE" ) { 185 if ( config.readEntry( "clockAlarmSet", "FALSE" ) == "TRUE" )
186 {
193 alarmOffBtn->setText( tr( "Alarm Is On" ) ); 187 alarmOffBtn->setText( tr( "Alarm Is On" ) );
194 alarmBool = TRUE; 188 alarmBool = TRUE;
195 snoozeBtn->show(); 189 snoozeBtn->show();
196 } 190 }
197 else { 191 else
192 {
198 alarmOffBtn->setText( tr( "Alarm Is Off" ) ); 193 alarmOffBtn->setText( tr( "Alarm Is Off" ) );
199 alarmBool = FALSE; 194 alarmBool = FALSE;
200 snoozeBtn->hide(); 195 snoozeBtn->hide();
201 } 196 }
202 197
203 QTimer::singleShot( 0, this, SLOT( updateClock() ) ); 198 QTimer::singleShot( 0, this, SLOT( updateClock() ) );
204 modeSelect( 0 ); 199
200 Config cfg( "Clock" );
201 cfg.setGroup( "Mode" );
202 int mode = cfg.readBoolEntry( "clockMode");setSwatchMode( mode);
203 modeSelect( mode);
205} 204}
206 205
207Clock::~Clock() 206Clock::~Clock()
@@ -211,10 +210,12 @@ Clock::~Clock()
211 210
212void Clock::updateClock() 211void Clock::updateClock()
213{ 212{
214 if ( clockRB->isChecked() ) { 213 if ( clockRB->isChecked() )
214 {
215 QTime tm = QDateTime::currentDateTime().time(); 215 QTime tm = QDateTime::currentDateTime().time();
216 QString s; 216 QString s;
217 if ( ampm ) { 217 if ( ampm )
218 {
218 int hour = tm.hour(); 219 int hour = tm.hour();
219 if ( hour == 0 ) 220 if ( hour == 0 )
220 hour = 12; 221 hour = 12;
@@ -224,7 +225,8 @@ void Clock::updateClock()
224 ampmLabel->setText( ( tm.hour() >= 12 ) ? "PM" : "AM" ); 225 ampmLabel->setText( ( tm.hour() >= 12 ) ? "PM" : "AM" );
225 ampmLabel->show(); 226 ampmLabel->show();
226 } 227 }
227 else { 228 else
229 {
228 s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); 230 s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() );
229 ampmLabel->hide(); 231 ampmLabel->hide();
230 } 232 }
@@ -233,7 +235,8 @@ void Clock::updateClock()
233 aclock->display( QTime::currentTime() ); 235 aclock->display( QTime::currentTime() );
234 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 236 date->setText( TimeString::longDateString( QDate::currentDate() ) );
235 } 237 }
236 else { 238 else
239 {
237 QTime swatch_time; 240 QTime swatch_time;
238 QString lcdtext; 241 QString lcdtext;
239 int totalms = swatch_totalms; 242 int totalms = swatch_totalms;
@@ -264,19 +267,19 @@ void Clock::clearClock( void )
264 267
265void Clock::slotSet() 268void Clock::slotSet()
266{ 269{
267 if ( t->isActive() ) { 270 if ( t->isActive() )
271 {
268 swatch_totalms += swatch_start.elapsed(); 272 swatch_totalms += swatch_start.elapsed();
269 set 273 set->setText( tr( "Start" ) );
270 ->setText( tr( "Start" ) );
271 t->stop(); 274 t->stop();
272 swatch_running = FALSE; 275 swatch_running = FALSE;
273 toggleScreenSaver( TRUE ); 276 toggleScreenSaver( TRUE );
274 updateClock(); 277 updateClock();
275 } 278 }
276 else { 279 else
280 {
277 swatch_start.start(); 281 swatch_start.start();
278 set 282 set->setText( tr( "Stop" ) );
279 ->setText( tr( "Stop" ) );
280 t->start( 1000 ); 283 t->start( 1000 );
281 swatch_running = TRUE; 284 swatch_running = TRUE;
282 // disable screensaver while stop watch is running 285 // disable screensaver while stop watch is running
@@ -298,25 +301,30 @@ void Clock::slotReset()
298 301
299void Clock::modeSelect( int m ) 302void Clock::modeSelect( int m )
300{ 303{
301 if ( m ) { 304 qDebug("Clock::modeSelect( %d) ", m);
305 if ( m )
306 {
302 lcd->setNumDigits( 8 + 1 + sw_prec ); 307 lcd->setNumDigits( 8 + 1 + sw_prec );
303 lcd->setMinimumWidth( lcd->sizeHint().width() ); 308 lcd->setMinimumWidth( lcd->sizeHint().width() );
304 set 309 set->setEnabled( TRUE );
305 ->setEnabled( TRUE );
306 reset->setEnabled( TRUE ); 310 reset->setEnabled( TRUE );
307 ampmLabel->hide(); 311 ampmLabel->hide();
308 312
309 if ( !swatch_running ) 313 if ( !swatch_running )
310 t->stop(); 314 t->stop();
311 } 315 }
312 else { 316 else
317 {
313 lcd->setNumDigits( 5 ); 318 lcd->setNumDigits( 5 );
314 lcd->setMinimumWidth( lcd->sizeHint().width() ); 319 lcd->setMinimumWidth( lcd->sizeHint().width() );
315 set 320 set->setEnabled( FALSE );
316 ->setEnabled( FALSE );
317 reset->setEnabled( FALSE ); 321 reset->setEnabled( FALSE );
318 t->start( 1000 ); 322 t->start( 1000 );
319 } 323 }
324
325 Config config( "Clock" );
326 config.setGroup( "Mode" );
327 config.writeEntry( "clockMode", m );
320 updateClock(); 328 updateClock();
321} 329}
322 330
@@ -367,14 +375,16 @@ void Clock::slotToggleAlarm()
367{ 375{
368 Config config( "qpe" ); 376 Config config( "qpe" );
369 config.setGroup( "Time" ); 377 config.setGroup( "Time" );
370 if ( alarmBool ) { 378 if ( alarmBool )
379 {
371 config.writeEntry( "clockAlarmSet", "FALSE" ); 380 config.writeEntry( "clockAlarmSet", "FALSE" );
372 alarmOffBtn->setText( tr( "Alarm Is Off" ) ); 381 alarmOffBtn->setText( tr( "Alarm Is Off" ) );
373 snoozeBtn->hide(); 382 snoozeBtn->hide();
374 alarmBool = FALSE; 383 alarmBool = FALSE;
375 alarmOff(); 384 alarmOff();
376 } 385 }
377 else { 386 else
387 {
378 config.writeEntry( "clockAlarmSet", "TRUE" ); 388 config.writeEntry( "clockAlarmSet", "TRUE" );
379 alarmOffBtn->setText( tr( "Alarm Is On" ) ); 389 alarmOffBtn->setText( tr( "Alarm Is On" ) );
380 snoozeBtn->show(); 390 snoozeBtn->show();
@@ -426,29 +436,15 @@ void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ )
426 int timerStay = 5000; 436 int timerStay = 5000;
427 bSound = TRUE; 437 bSound = TRUE;
428 qDebug( "Message received in clock" ); 438 qDebug( "Message received in clock" );
429 if ( msg == "alarm(QDateTime,int)" ) { 439 if ( msg == "alarm(QDateTime,int)" )
440 {
430 Config config( "qpe" ); 441 Config config( "qpe" );
431 config.setGroup( "Time" ); 442 config.setGroup( "Time" );
432 if ( config.readBoolEntry( "mp3Alarm", 0 ) ) 443 if ( config.readBoolEntry( "mp3Alarm", 0 ) )
433 { 444 {
434 clearTimer(); 445 clearTimer();
435// pid_t pid;
436// switch(pid = fork())
437// {
438// case -1:
439// {//failed
440// }
441// break;
442// case 0:
443// {//child
444// QCopEnvelope e( "QPE/Application/opieplayer", "setDocument(QString)" );
445// e << config.readEntry( "mp3File", "" );
446 pthread_t thread; 446 pthread_t thread;
447 pthread_create(&thread, NULL, (void * (*) (void *))startPlayer, NULL/* &*/); 447 pthread_create(&thread, NULL, (void * (*) (void *))startPlayer, NULL/* &*/);
448// startPlayer();
449// }
450// break;
451// };
452 448
453 } 449 }
454 else 450 else
@@ -458,6 +454,20 @@ void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ )
458 stopTimer = startTimer( timerStay ); 454 stopTimer = startTimer( timerStay );
459 } 455 }
460 } 456 }
457
458 if ( msg == "timerStart()" )
459 {
460 slotStartTimer();
461 }
462 if ( msg == "timerStop()" )
463 {
464 slotStopTimer();
465 }
466 if ( msg == "timerReset()" )
467 {
468 slotResetTimer();
469 }
470
461 show(); 471 show();
462 raise(); 472 raise();
463 QPEApplication::setKeepRunning(); 473 QPEApplication::setKeepRunning();
@@ -467,11 +477,13 @@ void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ )
467void Clock::timerEvent( QTimerEvent *e ) 477void Clock::timerEvent( QTimerEvent *e )
468{ 478{
469 static int stop = 0; 479 static int stop = 0;
470 if ( stop < 120 && bSound ) { 480 if ( stop < 120 && bSound )
481 {
471 Sound::soundAlarm(); 482 Sound::soundAlarm();
472 stop++; 483 stop++;
473 } 484 }
474 else { 485 else
486 {
475 stop = 0; 487 stop = 0;
476 killTimer( e->timerId() ); 488 killTimer( e->timerId() );
477 clearTimer(); 489 clearTimer();
@@ -501,7 +513,8 @@ void AnalogClock::drawContents( QPainter *p )
501 513
502 514
503 515
504 if ( clear ) { 516 if ( clear )
517 {
505 erase ( r ); 518 erase ( r );
506 p-> setPen ( NoPen ); 519 p-> setPen ( NoPen );
507 p-> setBrush ( colorGroup ( ). color ( QColorGroup::Base )); 520 p-> setBrush ( colorGroup ( ). color ( QColorGroup::Base ));
@@ -513,7 +526,8 @@ void AnalogClock::drawContents( QPainter *p )
513 for ( int i = 0; i < 12; i++ ) 526 for ( int i = 0; i < 12; i++ )
514 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); 527 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) );
515 } 528 }
516 else { 529 else
530 {
517 drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Base ), prevTime, &currTime ); 531 drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Base ), prevTime, &currTime );
518 } 532 }
519 533
@@ -584,3 +598,38 @@ void Clock::slotAdjustTime()
584 QCopEnvelope e( "QPE/System", "execute(QString)" ); 598 QCopEnvelope e( "QPE/System", "execute(QString)" );
585 e << QString( "systemtime" ); 599 e << QString( "systemtime" );
586} 600}
601
602void Clock::slotStartTimer()
603{
604 Config cfg( "Clock" );
605 cfg.setGroup( "Mode" );
606 int mode = cfg.readBoolEntry( "clockMode");
607 if ( clockRB->isChecked() )
608 setSwatchMode( 1);
609 slotSet();
610}
611
612void Clock::slotStopTimer()
613{
614 Config cfg( "Clock" );
615 cfg.setGroup( "Mode" );
616 int mode = cfg.readBoolEntry( "clockMode");
617 if ( clockRB->isChecked() )
618 setSwatchMode( 1);
619slotSet();
620}
621
622void Clock::slotResetTimer()
623{
624 if ( clockRB->isChecked() )
625 setSwatchMode( 1);
626slotReset();
627}
628
629void Clock::setSwatchMode(int mode)
630{
631 qDebug("Clock::setSwatchMode( %d)"), mode;
632 swatchRB->setChecked( mode);
633 clearClock( );
634 modeSelect( mode );
635}
diff --git a/noncore/tools/clock/clock.h b/noncore/tools/clock/clock.h
index 23cc143..9b00e28 100644
--- a/noncore/tools/clock/clock.h
+++ b/noncore/tools/clock/clock.h
@@ -46,12 +46,14 @@ protected:
46 void drawContents( QPainter *p ); 46 void drawContents( QPainter *p );
47 47
48private: 48private:
49 QPoint rotate( QPoint center, QPoint p, int angle );
50 void drawPointers ( QPainter *, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 = 0 );
51 49
52 QTime currTime; 50 QTime currTime;
53 QTime prevTime; 51 QTime prevTime;
54 bool clear; 52 bool clear;
53
54 QPoint rotate( QPoint center, QPoint p, int angle );
55 void drawPointers ( QPainter *, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 = 0 );
56
55}; 57};
56 58
57class Clock : public QVBox 59class Clock : public QVBox
@@ -78,9 +80,12 @@ private slots:
78 void appMessage(const QCString& msg, const QByteArray& data); 80 void appMessage(const QCString& msg, const QByteArray& data);
79 void timerEvent( QTimerEvent *e ); 81 void timerEvent( QTimerEvent *e );
80 void slotAdjustTime(); 82 void slotAdjustTime();
83
84 void slotStartTimer();
85 void slotStopTimer();
86 void slotResetTimer();
87 void setSwatchMode( int );
81private: 88private:
82 void clearClock();
83 void clearTimer();
84 bool alarmBool; 89 bool alarmBool;
85 QTimer *t; 90 QTimer *t;
86 QLCDNumber *lcd; 91 QLCDNumber *lcd;
@@ -93,6 +98,8 @@ private:
93 int swatch_totalms; 98 int swatch_totalms;
94 bool swatch_running; 99 bool swatch_running;
95 bool ampm; 100 bool ampm;
101 void clearClock();
102 void clearTimer();
96}; 103};
97 104
98#endif 105#endif