summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/clock/clock.cpp47
-rw-r--r--noncore/tools/clock/clock.h2
2 files changed, 28 insertions, 21 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp
index 9898332..0eb2b83 100644
--- a/noncore/tools/clock/clock.cpp
+++ b/noncore/tools/clock/clock.cpp
@@ -76,560 +76,565 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
76 : QVBox( parent, name , f ) 76 : QVBox( parent, name , f )
77{ 77{
78 setSpacing( 4 ); 78 setSpacing( 4 );
79 setMargin( 1 ); 79 setMargin( 1 );
80 80
81 81
82 snoozeBtn = new QPushButton ( this ); 82 snoozeBtn = new QPushButton ( this );
83 snoozeBtn->setText( tr( "Snooze" ) ); 83 snoozeBtn->setText( tr( "Snooze" ) );
84 84
85 aclock = new AnalogClock( this ); 85 aclock = new AnalogClock( this );
86 aclock->display( QTime::currentTime() ); 86 aclock->display( QTime::currentTime() );
87 aclock->setLineWidth( 2 ); 87 aclock->setLineWidth( 2 );
88 88
89 QHBox *hb = new QHBox( this ); 89 QHBox *hb = new QHBox( this );
90 hb->setMargin( 0 ); 90 hb->setMargin( 0 );
91 QWidget *space = new QWidget( hb ); 91 QWidget *space = new QWidget( hb );
92 lcd = new QLCDNumber( hb ); 92 lcd = new QLCDNumber( hb );
93 lcd->setSegmentStyle( QLCDNumber::Flat ); 93 lcd->setSegmentStyle( QLCDNumber::Flat );
94 lcd->setFrameStyle( QFrame::NoFrame ); 94 lcd->setFrameStyle( QFrame::NoFrame );
95 lcd->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); 95 lcd->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) );
96 lcd->setFixedHeight( 23 ); 96 lcd->setFixedHeight( 23 );
97 97
98 ampmLabel = new QLabel( tr( "PM" ), hb ); 98 ampmLabel = new QLabel( tr( "PM" ), hb );
99 ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); 99 ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) );
100 ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) ); 100 ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) );
101 ampmLabel->setAlignment( AlignLeft | AlignBottom ); 101 ampmLabel->setAlignment( AlignLeft | AlignBottom );
102 space = new QWidget( hb ); 102 space = new QWidget( hb );
103 103
104 date = new QLabel( this ); 104 date = new QLabel( this );
105 date->setAlignment( AlignHCenter | AlignVCenter ); 105 date->setAlignment( AlignHCenter | AlignVCenter );
106 date->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); 106 date->setFont( QFont( "Helvetica", 14, QFont::Bold ) );
107 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 107 date->setText( TimeString::longDateString( QDate::currentDate() ) );
108 108
109 QWidget *controls = new QWidget( this ); 109 QWidget *controls = new QWidget( this );
110 QGridLayout *gl = new QGridLayout( controls, 3, 2, 6, 4 ); 110 QGridLayout *gl = new QGridLayout( controls, 3, 2, 6, 4 );
111 111
112 QButtonGroup *grp = new QButtonGroup( controls ); 112 QButtonGroup *grp = new QButtonGroup( controls );
113 grp->setRadioButtonExclusive( true ); 113 grp->setRadioButtonExclusive( true );
114 grp->hide(); 114 grp->hide();
115 115
116 clockRB = new QRadioButton ( tr( "Clock" ), controls ); 116 clockRB = new QRadioButton ( tr( "Clock" ), controls );
117 gl->addWidget( clockRB, 0, 0 ); 117 gl->addWidget( clockRB, 0, 0 );
118 grp->insert( clockRB ); 118 grp->insert( clockRB );
119 119
120 swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls ); 120 swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls );
121 gl->addWidget( swatchRB, 1, 0 ); 121 gl->addWidget( swatchRB, 1, 0 );
122 grp->insert( swatchRB ); 122 grp->insert( swatchRB );
123 123
124 connect( grp, SIGNAL( clicked( int ) ), this, SLOT( modeSelect( int ) ) ); 124 connect( grp, SIGNAL( clicked( int ) ), this, SLOT( modeSelect( int ) ) );
125 grp->setButton( 0 ); 125 grp->setButton( 0 );
126 126
127 set = new QPushButton ( controls ); 127 set = new QPushButton ( controls );
128 set->setMaximumSize( 50, 30 ); 128 set->setMaximumSize( 50, 30 );
129 gl->addWidget( set , 0, 1 ); 129 gl->addWidget( set , 0, 1 );
130 set->setText( tr( "Start" ) ); 130 set->setText( tr( "Start" ) );
131 set->setEnabled( FALSE ); 131 set->setEnabled( FALSE );
132 grp->insert( set ); 132 grp->insert( set );
133 133
134 reset = new QPushButton ( controls ); 134 reset = new QPushButton ( controls );
135 gl->addWidget( reset, 1, 1 ); 135 gl->addWidget( reset, 1, 1 );
136 reset->setText( tr( "Reset" ) ); 136 reset->setText( tr( "Reset" ) );
137 reset->setEnabled( FALSE ); 137 reset->setEnabled( FALSE );
138 grp->insert( reset ); 138 grp->insert( reset );
139 139
140 alarmOffBtn = new QPushButton ( controls ); 140 alarmOffBtn = new QPushButton ( controls );
141 gl->addWidget( alarmOffBtn, 0, 2 ); 141 gl->addWidget( alarmOffBtn, 0, 2 );
142 142
143 alarmBtn = new QPushButton ( controls ); 143 alarmBtn = new QPushButton ( controls );
144 gl->addWidget( alarmBtn, 1, 2 ); 144 gl->addWidget( alarmBtn, 1, 2 );
145 145
146 alarmBtn->setText( tr( "Set Alarm" ) ); 146 alarmBtn->setText( tr( "Set Alarm" ) );
147 147
148 OClickableLabel *click = new OClickableLabel( controls, "label" ); 148 OClickableLabel *click = new OClickableLabel( controls, "label" );
149 click->setText( tr( "Set date and time." ) ); 149 click->setText( tr( "Set date and time." ) );
150 gl->addMultiCellWidget( click, 3, 3, 0, 2, AlignHCenter ); 150 gl->addMultiCellWidget( click, 3, 3, 0, 2, AlignHCenter );
151 connect( click, SIGNAL( clicked() ), this, SLOT( slotAdjustTime() ) ); 151 connect( click, SIGNAL( clicked() ), this, SLOT( slotAdjustTime() ) );
152 152
153 connect( set , SIGNAL( pressed() ), SLOT( slotSet() ) ); 153 connect( set , SIGNAL( pressed() ), SLOT( slotSet() ) );
154 connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) ); 154 connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) );
155 155
156 connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) ); 156 connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) );
157 connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) ); 157 connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) );
158 connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) ); 158 connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) );
159 159
160 connect( qApp, SIGNAL( appMessage( const QCString&, const QByteArray& ) ), 160 connect( qApp, SIGNAL( appMessage( const QCString&, const QByteArray& ) ),
161 this, SLOT( appMessage( const QCString&, const QByteArray& ) ) ); 161 this, SLOT( appMessage( const QCString&, const QByteArray& ) ) );
162 162
163 t = new QTimer( this ); 163 t = new QTimer( this );
164 connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) ); 164 connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) );
165 t->start( 1000 ); 165 t->start( 1000 );
166 166
167 connect( qApp, SIGNAL( timeChanged() ), SLOT( updateClock() ) ); 167 connect( qApp, SIGNAL( timeChanged() ), SLOT( updateClock() ) );
168 168
169 swatch_running = FALSE; 169 swatch_running = FALSE;
170 swatch_totalms = 0; 170 swatch_totalms = 0;
171 171
172 connect( qApp, SIGNAL( clockChanged( bool ) ), this, SLOT( changeClock( bool ) ) ); 172 connect( qApp, SIGNAL( clockChanged( bool ) ), this, SLOT( changeClock( bool ) ) );
173 173
174 174
175 Config config( "qpe" ); 175 Config config( "qpe" );
176 config.setGroup( "Time" ); 176 config.setGroup( "Time" );
177 ampm = config.readBoolEntry( "AMPM", TRUE ); 177 ampm = config.readBoolEntry( "AMPM", TRUE );
178 178
179 QString tmp = config.readEntry( "clockAlarmHour", "" ); 179 QString tmp = config.readEntry( "clockAlarmHour", "" );
180 bool ok; 180 bool ok;
181 hour = tmp.toInt( &ok, 10 ); 181 hour = tmp.toInt( &ok, 10 );
182 tmp = config.readEntry( "clockAlarmMinute", "" ); 182 tmp = config.readEntry( "clockAlarmMinute", "" );
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");setSwatchMode( mode);
203 modeSelect( mode); 203 modeSelect( mode);
204} 204}
205 205
206Clock::~Clock() 206Clock::~Clock()
207{ 207{
208 toggleScreenSaver( true ); 208 toggleScreenSaver( true );
209} 209}
210 210
211void Clock::updateClock() 211void Clock::updateClock()
212{ 212{
213 if ( clockRB->isChecked() ) 213 if ( clockRB->isChecked() )
214 { 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 {
219 int hour = tm.hour(); 219 int hour = tm.hour();
220 if ( hour == 0 ) 220 if ( hour == 0 )
221 hour = 12; 221 hour = 12;
222 if ( hour > 12 ) 222 if ( hour > 12 )
223 hour -= 12; 223 hour -= 12;
224 s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); 224 s.sprintf( "%2d%c%02d", hour, ':', tm.minute() );
225 ampmLabel->setText( ( tm.hour() >= 12 ) ? "PM" : "AM" ); 225 ampmLabel->setText( ( tm.hour() >= 12 ) ? "PM" : "AM" );
226 ampmLabel->show(); 226 ampmLabel->show();
227 } 227 }
228 else 228 else
229 { 229 {
230 s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); 230 s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() );
231 ampmLabel->hide(); 231 ampmLabel->hide();
232 } 232 }
233 lcd->display( s ); 233 lcd->display( s );
234 lcd->repaint( FALSE ); 234 lcd->repaint( FALSE );
235 aclock->display( QTime::currentTime() ); 235 aclock->display( QTime::currentTime() );
236 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 236 date->setText( TimeString::longDateString( QDate::currentDate() ) );
237 } 237 }
238 else 238 else
239 { 239 {
240 QTime swatch_time; 240 QTime swatch_time;
241 QString lcdtext; 241 QString lcdtext;
242 int totalms = swatch_totalms; 242 int totalms = swatch_totalms;
243 if ( swatch_running ) 243 if ( swatch_running )
244 totalms += swatch_start.elapsed(); 244 totalms += swatch_start.elapsed();
245 swatch_time = QTime( 0, 0, 0 ).addMSecs( totalms ); 245 swatch_time = QTime( 0, 0, 0 ).addMSecs( totalms );
246 QString d = swatch_running ? QString( " " ) 246 QString d = swatch_running ? QString( " " )
247 : QString::number( totalms % 1000 + 1000 ); 247 : QString::number( totalms % 1000 + 1000 );
248 lcdtext = swatch_time.toString() + "." + d.right( 3 ).left( sw_prec ); 248 lcdtext = swatch_time.toString() + "." + d.right( 3 ).left( sw_prec );
249 lcd->display( lcdtext ); 249 lcd->display( lcdtext );
250 lcd->repaint( FALSE ); 250 lcd->repaint( FALSE );
251 aclock->display( swatch_time ); 251 aclock->display( swatch_time );
252 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 252 date->setText( TimeString::longDateString( QDate::currentDate() ) );
253 } 253 }
254} 254}
255 255
256void Clock::changeClock( bool a ) 256void Clock::changeClock( bool a )
257{ 257{
258 ampm = a; 258 ampm = a;
259 updateClock(); 259 updateClock();
260} 260}
261 261
262void Clock::clearClock( void ) 262void Clock::clearClock( void )
263{ 263{
264 lcd->display( QTime( 0, 0, 0 ).toString() ); 264 lcd->display( QTime( 0, 0, 0 ).toString() );
265 aclock->display( QTime( 0, 0, 0 ) ); 265 aclock->display( QTime( 0, 0, 0 ) );
266} 266}
267 267
268void Clock::startSWatch()
269{
270 swatch_start.start();
271 set->setText( tr( "Stop" ) );
272 t->start( 1000 );
273 swatch_running = TRUE;
274 // disable screensaver while stop watch is running
275 toggleScreenSaver( FALSE );
276}
277
278void Clock::stopSWatch()
279{
280 swatch_totalms += swatch_start.elapsed();
281 set->setText( tr( "Start" ) );
282 t->stop();
283 swatch_running = FALSE;
284 toggleScreenSaver( TRUE );
285 updateClock();
286}
287
288
268void Clock::slotSet() 289void Clock::slotSet()
269{ 290{
270 if ( t->isActive() ) 291 if ( t->isActive() )
271 { 292 {
272 swatch_totalms += swatch_start.elapsed(); 293 startSWatch();
273 set->setText( tr( "Start" ) );
274 t->stop();
275 swatch_running = FALSE;
276 toggleScreenSaver( TRUE );
277 updateClock();
278 } 294 }
279 else 295 else
280 { 296 {
281 swatch_start.start(); 297 stopSWatch();
282 set->setText( tr( "Stop" ) );
283 t->start( 1000 );
284 swatch_running = TRUE;
285 // disable screensaver while stop watch is running
286 toggleScreenSaver( FALSE );
287 } 298 }
288} 299}
289 300
290void Clock::slotReset() 301void Clock::slotReset()
291{ 302{
292 t->stop(); 303 t->stop();
293 swatch_start.start(); 304 swatch_start.start();
294 swatch_totalms = 0; 305 swatch_totalms = 0;
295 306
296 if ( swatch_running ) 307 if ( swatch_running )
297 t->start( 1000 ); 308 t->start( 1000 );
298 309
299 updateClock(); 310 updateClock();
300} 311}
301 312
302void Clock::modeSelect( int m ) 313void Clock::modeSelect( int m )
303{ 314{
304 qDebug("Clock::modeSelect( %d) ", m); 315 qDebug("Clock::modeSelect( %d) ", m);
305 if ( m ) 316 if ( m )
306 { 317 {
307 lcd->setNumDigits( 8 + 1 + sw_prec ); 318 lcd->setNumDigits( 8 + 1 + sw_prec );
308 lcd->setMinimumWidth( lcd->sizeHint().width() ); 319 lcd->setMinimumWidth( lcd->sizeHint().width() );
309 set->setEnabled( TRUE ); 320 set->setEnabled( TRUE );
310 reset->setEnabled( TRUE ); 321 reset->setEnabled( TRUE );
311 ampmLabel->hide(); 322 ampmLabel->hide();
312 323
313 if ( !swatch_running ) 324 if ( !swatch_running )
314 t->stop(); 325 t->stop();
315 } 326 }
316 else 327 else
317 { 328 {
318 lcd->setNumDigits( 5 ); 329 lcd->setNumDigits( 5 );
319 lcd->setMinimumWidth( lcd->sizeHint().width() ); 330 lcd->setMinimumWidth( lcd->sizeHint().width() );
320 set->setEnabled( FALSE ); 331 set->setEnabled( FALSE );
321 reset->setEnabled( FALSE ); 332 reset->setEnabled( FALSE );
322 t->start( 1000 ); 333 t->start( 1000 );
323 } 334 }
324 335
325 Config config( "Clock" ); 336 Config config( "Clock" );
326 config.setGroup( "Mode" ); 337 config.setGroup( "Mode" );
327 config.writeEntry( "clockMode", m ); 338 config.writeEntry( "clockMode", m );
328 updateClock(); 339 updateClock();
329} 340}
330 341
331//this sets the alarm time 342//this sets the alarm time
332void Clock::slotSetAlarm() 343void Clock::slotSetAlarm()
333{ 344{
334 if ( !snoozeBtn->isHidden() ) 345 if ( !snoozeBtn->isHidden() )
335 slotToggleAlarm(); 346 slotToggleAlarm();
336 Set_Alarm *setAlarmDlg; 347 Set_Alarm *setAlarmDlg;
337 setAlarmDlg = new Set_Alarm( this, "SetAlarm", TRUE ); 348 setAlarmDlg = new Set_Alarm( this, "SetAlarm", TRUE );
338 int result = setAlarmDlg->exec(); 349 int result = setAlarmDlg->exec();
339 if ( result == 1 ) { 350 if ( result == 1 ) {
340 Config config( "qpe" ); 351 Config config( "qpe" );
341 config.setGroup( "Time" ); 352 config.setGroup( "Time" );
342 QString tmp; 353 QString tmp;
343 hour = setAlarmDlg->Hour_Slider->value(); 354 hour = setAlarmDlg->Hour_Slider->value();
344 minute = setAlarmDlg->Minute_Slider->value(); 355 minute = setAlarmDlg->Minute_Slider->value();
345 snoozeTime = setAlarmDlg->SnoozeSlider->value(); 356 snoozeTime = setAlarmDlg->SnoozeSlider->value();
346 if ( ampm ) { 357 if ( ampm ) {
347 if ( hour == 12 ) 358 if ( hour == 12 )
348 hour = 0; 359 hour = 0;
349 360
350 if ( setAlarmDlg->Pm_RadioButton->isChecked() && hour < 12 ) 361 if ( setAlarmDlg->Pm_RadioButton->isChecked() && hour < 12 )
351 hour += 12; 362 hour += 12;
352 } 363 }
353 config.writeEntry( "clockAlarmHour", tmp.setNum( hour ), 10 ); 364 config.writeEntry( "clockAlarmHour", tmp.setNum( hour ), 10 );
354 config.writeEntry( "clockAlarmMinute", tmp.setNum( minute ), 10 ); 365 config.writeEntry( "clockAlarmMinute", tmp.setNum( minute ), 10 );
355 config.writeEntry( "clockAlarmSnooze", tmp.setNum( snoozeTime ), 10 ); 366 config.writeEntry( "clockAlarmSnooze", tmp.setNum( snoozeTime ), 10 );
356 config.write(); 367 config.write();
357 } 368 }
358} 369}
359 370
360void Clock::slotSnooze() 371void Clock::slotSnooze()
361{ 372{
362 bSound = FALSE; 373 bSound = FALSE;
363 int warn = 0; 374 int warn = 0;
364 QTime t = QTime::currentTime(); 375 QTime t = QTime::currentTime();
365 QDateTime whenl( when.date(), t.addSecs( snoozeTime * 60 ) ); 376 QDateTime whenl( when.date(), t.addSecs( snoozeTime * 60 ) );
366 when = whenl; 377 when = whenl;
367 AlarmServer::addAlarm( when, 378 AlarmServer::addAlarm( when,
368 "QPE/Application/clock", 379 "QPE/Application/clock",
369 "alarm(QDateTime,int)", warn ); 380 "alarm(QDateTime,int)", warn );
370 381
371} 382}
372 383
373//toggles alarm on/off 384//toggles alarm on/off
374void Clock::slotToggleAlarm() 385void Clock::slotToggleAlarm()
375{ 386{
376 Config config( "qpe" ); 387 Config config( "qpe" );
377 config.setGroup( "Time" ); 388 config.setGroup( "Time" );
378 if ( alarmBool ) 389 if ( alarmBool )
379 { 390 {
380 config.writeEntry( "clockAlarmSet", "FALSE" ); 391 config.writeEntry( "clockAlarmSet", "FALSE" );
381 alarmOffBtn->setText( tr( "Alarm Is Off" ) ); 392 alarmOffBtn->setText( tr( "Alarm Is Off" ) );
382 snoozeBtn->hide(); 393 snoozeBtn->hide();
383 alarmBool = FALSE; 394 alarmBool = FALSE;
384 alarmOff(); 395 alarmOff();
385 } 396 }
386 else 397 else
387 { 398 {
388 config.writeEntry( "clockAlarmSet", "TRUE" ); 399 config.writeEntry( "clockAlarmSet", "TRUE" );
389 alarmOffBtn->setText( tr( "Alarm Is On" ) ); 400 alarmOffBtn->setText( tr( "Alarm Is On" ) );
390 snoozeBtn->show(); 401 snoozeBtn->show();
391 alarmBool = TRUE; 402 alarmBool = TRUE;
392 alarmOn(); 403 alarmOn();
393 } 404 }
394 config.write(); 405 config.write();
395} 406}
396 407
397void Clock::alarmOn() 408void Clock::alarmOn()
398{ 409{
399 QDate d = QDate::currentDate(); 410 QDate d = QDate::currentDate();
400 QTime tm( ( int ) hour, ( int ) minute, 0 ); 411 QTime tm( ( int ) hour, ( int ) minute, 0 );
401 qDebug( "Time set " + tm.toString() ); 412 qDebug( "Time set " + tm.toString() );
402 QTime t = QTime::currentTime(); 413 QTime t = QTime::currentTime();
403 if ( t > tm ) 414 if ( t > tm )
404 d = d.addDays( 1 ); 415 d = d.addDays( 1 );
405 int warn = 0; 416 int warn = 0;
406 QDateTime whenl( d, tm ); 417 QDateTime whenl( d, tm );
407 when = whenl; 418 when = whenl;
408 AlarmServer::addAlarm( when, 419 AlarmServer::addAlarm( when,
409 "QPE/Application/clock", 420 "QPE/Application/clock",
410 "alarm(QDateTime,int)", warn ); 421 "alarm(QDateTime,int)", warn );
411 setCaption( "Alarm set: " + whenl.toString() ); 422 setCaption( "Alarm set: " + whenl.toString() );
412} 423}
413 424
414void Clock::alarmOff() 425void Clock::alarmOff()
415{ 426{
416 int warn = 0; 427 int warn = 0;
417 bSound = FALSE; 428 bSound = FALSE;
418 AlarmServer::deleteAlarm( when, 429 AlarmServer::deleteAlarm( when,
419 "QPE/Application/clock", 430 "QPE/Application/clock",
420 "alarm(QDateTime,int)", warn ); 431 "alarm(QDateTime,int)", warn );
421 qDebug( "Alarm Off " + when.toString() ); 432 qDebug( "Alarm Off " + when.toString() );
422 setCaption( "Clock" ); 433 setCaption( "Clock" );
423} 434}
424 435
425void Clock::clearTimer() 436void Clock::clearTimer()
426{ 437{
427 alarmOffBtn->setText( tr( "Alarm Is Off" ) ); 438 alarmOffBtn->setText( tr( "Alarm Is Off" ) );
428 alarmBool = FALSE; 439 alarmBool = FALSE;
429 snoozeBtn->hide(); 440 snoozeBtn->hide();
430 setCaption( "Clock" ); 441 setCaption( "Clock" );
431} 442}
432 443
433void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ ) 444void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ )
434{ 445{
435 int stopTimer = 0; 446 int stopTimer = 0;
436 int timerStay = 5000; 447 int timerStay = 5000;
437 bSound = TRUE; 448 bSound = TRUE;
438 qDebug( "Message received in clock" ); 449 qDebug( "Message received in clock" );
439 if ( msg == "alarm(QDateTime,int)" ) 450 if ( msg == "alarm(QDateTime,int)" )
440 { 451 {
441 Config config( "qpe" ); 452 Config config( "qpe" );
442 config.setGroup( "Time" ); 453 config.setGroup( "Time" );
443 if ( config.readBoolEntry( "mp3Alarm", 0 ) ) 454 if ( config.readBoolEntry( "mp3Alarm", 0 ) )
444 { 455 {
445 clearTimer(); 456 clearTimer();
446 pthread_t thread; 457 pthread_t thread;
447 pthread_create(&thread, NULL, (void * (*) (void *))startPlayer, NULL/* &*/); 458 pthread_create(&thread, NULL, (void * (*) (void *))startPlayer, NULL/* &*/);
448 459
449 } 460 }
450 else 461 else
451 { 462 {
452 463
453 Sound::soundAlarm(); 464 Sound::soundAlarm();
454 stopTimer = startTimer( timerStay ); 465 stopTimer = startTimer( timerStay );
455 } 466 }
456 } 467 }
457 468
458 if ( msg == "timerStart()" ) 469 if ( msg == "timerStart()" )
459 { 470 {
460 slotStartTimer(); 471 slotStartTimer();
461 } 472 }
462 if ( msg == "timerStop()" ) 473 if ( msg == "timerStop()" )
463 { 474 {
464 slotStopTimer(); 475 slotStopTimer();
465 } 476 }
466 if ( msg == "timerReset()" ) 477 if ( msg == "timerReset()" )
467 { 478 {
468 slotResetTimer(); 479 slotResetTimer();
469 } 480 }
470 481
471 show(); 482 show();
472 raise(); 483 raise();
473 QPEApplication::setKeepRunning(); 484 QPEApplication::setKeepRunning();
474 setActiveWindow(); 485 setActiveWindow();
475} 486}
476 487
477void Clock::timerEvent( QTimerEvent *e ) 488void Clock::timerEvent( QTimerEvent *e )
478{ 489{
479 static int stop = 0; 490 static int stop = 0;
480 if ( stop < 120 && bSound ) 491 if ( stop < 120 && bSound )
481 { 492 {
482 Sound::soundAlarm(); 493 Sound::soundAlarm();
483 stop++; 494 stop++;
484 } 495 }
485 else 496 else
486 { 497 {
487 stop = 0; 498 stop = 0;
488 killTimer( e->timerId() ); 499 killTimer( e->timerId() );
489 clearTimer(); 500 clearTimer();
490 setCaption( tr( "Clock: Alarm was missed." ) ); 501 setCaption( tr( "Clock: Alarm was missed." ) );
491 } 502 }
492} 503}
493 504
494 505
495QSizePolicy AnalogClock::sizePolicy() const 506QSizePolicy AnalogClock::sizePolicy() const
496{ 507{
497 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); 508 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
498} 509}
499 510
500void AnalogClock::drawContents( QPainter *p ) 511void AnalogClock::drawContents( QPainter *p )
501{ 512{
502 QRect r = contentsRect(); 513 QRect r = contentsRect();
503 QRect fr; 514 QRect fr;
504 515
505 if ( r. width ( ) > r. height ( )) 516 if ( r. width ( ) > r. height ( ))
506 fr. setRect (( r. width ( ) - r. height ( )) / 2, r. y ( ), r. height ( ), r. height ( )); 517 fr. setRect (( r. width ( ) - r. height ( )) / 2, r. y ( ), r. height ( ), r. height ( ));
507 else 518 else
508 fr. setRect ( r. x ( ), ( r. height ( ) - r. width ( )) / 2, r. width ( ), r. width ( )); 519 fr. setRect ( r. x ( ), ( r. height ( ) - r. width ( )) / 2, r. width ( ), r. width ( ));
509 520
510 QPoint center = fr. center ( ); // ( fr.x() + fr.width() / 2, fr.y() + fr.height() / 2 ); 521 QPoint center = fr. center ( ); // ( fr.x() + fr.width() / 2, fr.y() + fr.height() / 2 );
511 QPoint l1 ( center. x ( ), fr. y ( ) + 2 ); 522 QPoint l1 ( center. x ( ), fr. y ( ) + 2 );
512 QPoint l2 ( center. x ( ), fr. y ( ) + 8 ); 523 QPoint l2 ( center. x ( ), fr. y ( ) + 8 );
513 524
514 525
515 526
516 if ( clear ) 527 if ( clear )
517 { 528 {
518 erase ( r ); 529 erase ( r );
519 p-> setPen ( NoPen ); 530 p-> setPen ( NoPen );
520 p-> setBrush ( colorGroup ( ). color ( QColorGroup::Base )); 531 p-> setBrush ( colorGroup ( ). color ( QColorGroup::Base ));
521 p-> drawEllipse ( fr ); 532 p-> drawEllipse ( fr );
522 p-> setBrush ( NoBrush ); 533 p-> setBrush ( NoBrush );
523 534
524 // draw ticks 535 // draw ticks
525 p->setPen( QPen( colorGroup ( ). color ( QColorGroup::Text ), 1 ) ); 536 p->setPen( QPen( colorGroup ( ). color ( QColorGroup::Text ), 1 ) );
526 for ( int i = 0; i < 12; i++ ) 537 for ( int i = 0; i < 12; i++ )
527 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); 538 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) );
528 } 539 }
529 else 540 else
530 { 541 {
531 drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Base ), prevTime, &currTime ); 542 drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Base ), prevTime, &currTime );
532 } 543 }
533 544
534 drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Text ), currTime ); 545 drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Text ), currTime );
535 546
536 prevTime = currTime; 547 prevTime = currTime;
537} 548}
538 549
539void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 ) 550void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 )
540{ 551{
541 QPoint center = r. center ( ); 552 QPoint center = r. center ( );
542 553
543 QPoint h1( center. x ( ), r. y ( ) + r. height ( ) / 4 ); 554 QPoint h1( center. x ( ), r. y ( ) + r. height ( ) / 4 );
544 QPoint h2( center. x ( ), center. y ( ) ); 555 QPoint h2( center. x ( ), center. y ( ) );
545 556
546 QPoint m1( center. x ( ), r.y() + r.height() / 8 ); 557 QPoint m1( center. x ( ), r.y() + r.height() / 8 );
547 QPoint m2( center. x ( ), center. y ( ) ); 558 QPoint m2( center. x ( ), center. y ( ) );
548 559
549 QPoint s1( center. x ( ), r. y ( ) + 8 ); 560 QPoint s1( center. x ( ), r. y ( ) + 8 );
550 QPoint s2( center. x ( ), center. y ( ) ); 561 QPoint s2( center. x ( ), center. y ( ) );
551 562
552 563
553 if ( !t2 || ( t. minute ( ) != t2-> minute ( ) || t. hour ( ) != t2-> hour ( ))) { 564 if ( !t2 || ( t. minute ( ) != t2-> minute ( ) || t. hour ( ) != t2-> hour ( ))) {
554 // draw hour pointer 565 // draw hour pointer
555 h1 = rotate( center, h1, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); 566 h1 = rotate( center, h1, 30 * ( t.hour() % 12 ) + t.minute() / 2 );
556 h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); 567 h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 );
557 p-> setPen ( QPen ( c, 3 )); 568 p-> setPen ( QPen ( c, 3 ));
558 p-> drawLine ( h1, h2 ); 569 p-> drawLine ( h1, h2 );
559 } 570 }
560 571
561 if ( !t2 || ( t. minute ( ) != t2-> minute ( ))) { 572 if ( !t2 || ( t. minute ( ) != t2-> minute ( ))) {
562 // draw minute pointer 573 // draw minute pointer
563 m1 = rotate( center, m1, t.minute() * 6 ); 574 m1 = rotate( center, m1, t.minute() * 6 );
564 m2 = rotate( center, m2, t.minute() * 6 ); 575 m2 = rotate( center, m2, t.minute() * 6 );
565 p-> setPen ( QPen ( c, 2 )); 576 p-> setPen ( QPen ( c, 2 ));
566 p-> drawLine ( m1, m2 ); 577 p-> drawLine ( m1, m2 );
567 } 578 }
568 579
569 if ( !t2 || ( t. second ( ) != t2-> second ( ))) { 580 if ( !t2 || ( t. second ( ) != t2-> second ( ))) {
570 // draw second pointer 581 // draw second pointer
571 s1 = rotate( center, s1, t.second() * 6 ); 582 s1 = rotate( center, s1, t.second() * 6 );
572 s2 = rotate( center, s2, t.second() * 6 ); 583 s2 = rotate( center, s2, t.second() * 6 );
573 p-> setPen ( QPen ( c, 1 )); 584 p-> setPen ( QPen ( c, 1 ));
574 p-> drawLine ( s1, s2 ); 585 p-> drawLine ( s1, s2 );
575 } 586 }
576} 587}
577 588
578void AnalogClock::display( const QTime& t ) 589void AnalogClock::display( const QTime& t )
579{ 590{
580 currTime = t; 591 currTime = t;
581 clear = false; 592 clear = false;
582 repaint( false ); 593 repaint( false );
583 clear = true; 594 clear = true;
584} 595}
585 596
586QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) 597QPoint AnalogClock::rotate( QPoint c, QPoint p, int a )
587{ 598{
588 double angle = deg2rad * ( - a + 180 ); 599 double angle = deg2rad * ( - a + 180 );
589 double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - 600 double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) -
590 ( p.y() - c.y() ) * sin( angle ); 601 ( p.y() - c.y() ) * sin( angle );
591 double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + 602 double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) +
592 ( p.x() - c.x() ) * sin( angle ); 603 ( p.x() - c.x() ) * sin( angle );
593 return QPoint( nx, ny ); 604 return QPoint( nx, ny );
594} 605}
595 606
596void Clock::slotAdjustTime() 607void Clock::slotAdjustTime()
597{ 608{
598 QCopEnvelope e( "QPE/System", "execute(QString)" ); 609 QCopEnvelope e( "QPE/System", "execute(QString)" );
599 e << QString( "systemtime" ); 610 e << QString( "systemtime" );
600} 611}
601 612
602void Clock::slotStartTimer() 613void Clock::slotStartTimer()
603{ 614{
604 Config cfg( "Clock" );
605 cfg.setGroup( "Mode" );
606 int mode = cfg.readBoolEntry( "clockMode");
607 if ( clockRB->isChecked() ) 615 if ( clockRB->isChecked() )
608 setSwatchMode( 1); 616 setSwatchMode( 1);
609 slotSet(); 617 startSWatch();
610} 618}
611 619
612void Clock::slotStopTimer() 620void Clock::slotStopTimer()
613{ 621{
614 Config cfg( "Clock" );
615 cfg.setGroup( "Mode" );
616 int mode = cfg.readBoolEntry( "clockMode");
617 if ( clockRB->isChecked() ) 622 if ( clockRB->isChecked() )
618 setSwatchMode( 1); 623 setSwatchMode( 1);
619slotSet(); 624 stopSWatch();
620} 625}
621 626
622void Clock::slotResetTimer() 627void Clock::slotResetTimer()
623{ 628{
624 if ( clockRB->isChecked() ) 629 if ( clockRB->isChecked() )
625 setSwatchMode( 1); 630 setSwatchMode( 1);
626slotReset(); 631slotReset();
627} 632}
628 633
629void Clock::setSwatchMode(int mode) 634void Clock::setSwatchMode(int mode)
630{ 635{
631 qDebug("Clock::setSwatchMode( %d)"), mode; 636 qDebug("Clock::setSwatchMode( %d)", mode);
632 swatchRB->setChecked( mode); 637 swatchRB->setChecked( mode);
633 clearClock( ); 638 clearClock( );
634 modeSelect( mode ); 639 modeSelect( mode );
635} 640}
diff --git a/noncore/tools/clock/clock.h b/noncore/tools/clock/clock.h
index 9b00e28..1e5aa2c 100644
--- a/noncore/tools/clock/clock.h
+++ b/noncore/tools/clock/clock.h
@@ -1,106 +1,108 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000 Trolltech AS. All rights reserved. 2** Copyright (C) 2000 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of Qtopia Environment. 4** This file is part of Qtopia Environment.
5** 5**
6** This file may be distributed and/or modified under the terms of the 6** This file may be distributed and/or modified under the terms of the
7** GNU General Public License version 2 as published by the Free Software 7** GNU General Public License version 2 as published by the Free Software
8** Foundation and appearing in the file LICENSE.GPL included in the 8** Foundation and appearing in the file LICENSE.GPL included in the
9** packaging of this file. 9** packaging of this file.
10** 10**
11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 11** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 12** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
13** 13**
14** See http://www.trolltech.com/gpl/ for GPL licensing information. 14** See http://www.trolltech.com/gpl/ for GPL licensing information.
15** 15**
16** Contact info@trolltech.com if any conditions of this licensing are 16** Contact info@trolltech.com if any conditions of this licensing are
17** not clear to you. 17** not clear to you.
18** 18**
19**********************************************************************/ 19**********************************************************************/
20#ifndef CLOCK_H 20#ifndef CLOCK_H
21#define CLOCK_H 21#define CLOCK_H
22 22
23#include <qdatetime.h> 23#include <qdatetime.h>
24#include <qvbox.h> 24#include <qvbox.h>
25 25
26class QLCDNumber; 26class QLCDNumber;
27class QLabel; 27class QLabel;
28class QTimer; 28class QTimer;
29class QRadioButton; 29class QRadioButton;
30class QPushButton; 30class QPushButton;
31class QDateTime; 31class QDateTime;
32 32
33class AnalogClock : public QFrame 33class AnalogClock : public QFrame
34{ 34{
35 Q_OBJECT 35 Q_OBJECT
36 36
37public: 37public:
38 AnalogClock( QWidget * parent = 0, const char * name = 0 ) 38 AnalogClock( QWidget * parent = 0, const char * name = 0 )
39 : QFrame( parent, name ), clear(true) {} 39 : QFrame( parent, name ), clear(true) {}
40 40
41 QSizePolicy sizePolicy() const; 41 QSizePolicy sizePolicy() const;
42 42
43 void display( const QTime& time ); 43 void display( const QTime& time );
44 44
45protected: 45protected:
46 void drawContents( QPainter *p ); 46 void drawContents( QPainter *p );
47 47
48private: 48private:
49 49
50 QTime currTime; 50 QTime currTime;
51 QTime prevTime; 51 QTime prevTime;
52 bool clear; 52 bool clear;
53 53
54 QPoint rotate( QPoint center, QPoint p, int angle ); 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 ); 55 void drawPointers ( QPainter *, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 = 0 );
56 56
57}; 57};
58 58
59class Clock : public QVBox 59class Clock : public QVBox
60{ 60{
61 Q_OBJECT 61 Q_OBJECT
62 62
63public: 63public:
64 Clock( QWidget * parent = 0, const char * name = 0, WFlags f=0 ); 64 Clock( QWidget * parent = 0, const char * name = 0, WFlags f=0 );
65 ~Clock(); 65 ~Clock();
66 QDateTime when; 66 QDateTime when;
67 bool bSound; 67 bool bSound;
68 int hour, minute, snoozeTime; 68 int hour, minute, snoozeTime;
69private slots: 69private slots:
70 void slotSet(); 70 void slotSet();
71 void slotReset(); 71 void slotReset();
72 void modeSelect(int); 72 void modeSelect(int);
73 void updateClock(); 73 void updateClock();
74 void changeClock( bool ); 74 void changeClock( bool );
75 void slotSetAlarm(); 75 void slotSetAlarm();
76 void slotSnooze(); 76 void slotSnooze();
77 void slotToggleAlarm(); 77 void slotToggleAlarm();
78 void alarmOn(); 78 void alarmOn();
79 void alarmOff(); 79 void alarmOff();
80 void appMessage(const QCString& msg, const QByteArray& data); 80 void appMessage(const QCString& msg, const QByteArray& data);
81 void timerEvent( QTimerEvent *e ); 81 void timerEvent( QTimerEvent *e );
82 void slotAdjustTime(); 82 void slotAdjustTime();
83 83
84 void slotStartTimer(); 84 void slotStartTimer();
85 void slotStopTimer(); 85 void slotStopTimer();
86 void slotResetTimer(); 86 void slotResetTimer();
87 void setSwatchMode( int ); 87 void setSwatchMode( int );
88private: 88private:
89 bool alarmBool; 89 bool alarmBool;
90 QTimer *t; 90 QTimer *t;
91 QLCDNumber *lcd; 91 QLCDNumber *lcd;
92 QLabel *date; 92 QLabel *date;
93 QLabel *ampmLabel; 93 QLabel *ampmLabel;
94 QPushButton *set, *reset, *alarmBtn, *snoozeBtn, *alarmOffBtn; 94 QPushButton *set, *reset, *alarmBtn, *snoozeBtn, *alarmOffBtn;
95 QRadioButton *clockRB, *swatchRB; 95 QRadioButton *clockRB, *swatchRB;
96 AnalogClock *aclock; 96 AnalogClock *aclock;
97 QTime swatch_start; 97 QTime swatch_start;
98 int swatch_totalms; 98 int swatch_totalms;
99 bool swatch_running; 99 bool swatch_running;
100 bool ampm; 100 bool ampm;
101 void clearClock(); 101 void clearClock();
102 void clearTimer(); 102 void clearTimer();
103 void startSWatch();
104 void stopSWatch();
103}; 105};
104 106
105#endif 107#endif
106 108