summaryrefslogtreecommitdiff
path: root/noncore/tools/clock
authorllornkcor <llornkcor>2003-03-04 16:50:17 (UTC)
committer llornkcor <llornkcor>2003-03-04 16:50:17 (UTC)
commitbb765b9cd286d85eb8fa1d18199dfb7a29d57fc5 (patch) (unidiff)
tree80d69eef2975d1fb27a758aea7629d34c678a270 /noncore/tools/clock
parent628a783e5d7ec07b5c073c94a77b614439d937ba (diff)
downloadopie-bb765b9cd286d85eb8fa1d18199dfb7a29d57fc5.zip
opie-bb765b9cd286d85eb8fa1d18199dfb7a29d57fc5.tar.gz
opie-bb765b9cd286d85eb8fa1d18199dfb7a29d57fc5.tar.bz2
added 3 qcop calls. timerStart(), timerStop() and timerReset()
Diffstat (limited to 'noncore/tools/clock') (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
@@ -79,8 +79,4 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
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 );
@@ -129,16 +125,10 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
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 );
@@ -149,10 +139,9 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
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
@@ -162,6 +151,5 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
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
@@ -184,4 +172,9 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
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;
@@ -190,10 +183,12 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
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;
@@ -202,5 +197,9 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
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
@@ -212,8 +211,10 @@ Clock::~Clock()
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 )
@@ -225,5 +226,6 @@ void Clock::updateClock()
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();
@@ -234,5 +236,6 @@ void Clock::updateClock()
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;
@@ -265,8 +268,8 @@ void Clock::clearClock( void )
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;
@@ -274,8 +277,8 @@ void Clock::slotSet()
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;
@@ -299,9 +302,10 @@ void Clock::slotReset()
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();
@@ -310,12 +314,16 @@ void Clock::modeSelect( int m )
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}
@@ -368,5 +376,6 @@ void Clock::slotToggleAlarm()
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" ) );
@@ -375,5 +384,6 @@ void Clock::slotToggleAlarm()
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" ) );
@@ -427,5 +437,6 @@ void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ )
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" );
@@ -433,21 +444,6 @@ void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ )
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 }
@@ -459,4 +455,18 @@ void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ )
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();
@@ -468,9 +478,11 @@ void 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() );
@@ -502,5 +514,6 @@ void AnalogClock::drawContents( QPainter *p )
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 );
@@ -514,5 +527,6 @@ void AnalogClock::drawContents( QPainter *p )
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 }
@@ -585,2 +599,37 @@ void Clock::slotAdjustTime()
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
@@ -47,10 +47,12 @@ protected:
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
@@ -79,7 +81,10 @@ private slots:
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;
@@ -94,4 +99,6 @@ private:
94 bool swatch_running; 99 bool swatch_running;
95 bool ampm; 100 bool ampm;
101 void clearClock();
102 void clearTimer();
96}; 103};
97 104