summaryrefslogtreecommitdiff
authorllornkcor <llornkcor>2002-05-31 12:12:02 (UTC)
committer llornkcor <llornkcor>2002-05-31 12:12:02 (UTC)
commitdd08e7fa2ccbcc0489c17ed305b20a9a7d187161 (patch) (unidiff)
tree59399ddb7c89ad178c85e576018db9471d292b52
parent40eac37ff82dd4499a95adb786eb063fd0b81584 (diff)
downloadopie-dd08e7fa2ccbcc0489c17ed305b20a9a7d187161.zip
opie-dd08e7fa2ccbcc0489c17ed305b20a9a7d187161.tar.gz
opie-dd08e7fa2ccbcc0489c17ed305b20a9a7d187161.tar.bz2
add zeckes change in again *DOH*, and initialize some silly int's to get rid of silly compiler warnings
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/clock/clock.cpp253
-rw-r--r--noncore/tools/clock/clock.h2
2 files changed, 133 insertions, 122 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp
index a85cc19..0a21146 100644
--- a/noncore/tools/clock/clock.cpp
+++ b/noncore/tools/clock/clock.cpp
@@ -1,23 +1,22 @@
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// code added and Copyright (C) by L. J. Potter <ljp@llornkcor.com> 2002
21 20
22#include "clock.h" 21#include "clock.h"
23#include "setAlarm.h" 22#include "setAlarm.h"
@@ -32,6 +31,8 @@
32#include <qsound.h> 31#include <qsound.h>
33#include <qtimer.h> 32#include <qtimer.h>
34 33
34#include <opie/oclickablelabel.h>
35
35#include <qlcdnumber.h> 36#include <qlcdnumber.h>
36#include <qslider.h> 37#include <qslider.h>
37#include <qlabel.h> 38#include <qlabel.h>
@@ -56,7 +57,7 @@ static void toggleScreenSaver( bool on )
56} 57}
57 58
58Clock::Clock( QWidget * parent, const char * name, WFlags f ) 59Clock::Clock( QWidget * parent, const char * name, WFlags f )
59 : QVBox( parent, name , f ) 60 : QVBox( parent, name , f )
60{ 61{
61 setSpacing( 4 ); 62 setSpacing( 4 );
62 setMargin( 1 ); 63 setMargin( 1 );
@@ -93,7 +94,7 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
93 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 94 date->setText( TimeString::longDateString( QDate::currentDate() ) );
94 95
95 QWidget *controls = new QWidget( this ); 96 QWidget *controls = new QWidget( this );
96 QGridLayout *gl = new QGridLayout( controls, 2, 2, 6, 4 ); 97 QGridLayout *gl = new QGridLayout( controls, 3, 2, 6, 4 );
97 98
98 QButtonGroup *grp = new QButtonGroup( controls ); 99 QButtonGroup *grp = new QButtonGroup( controls );
99 grp->setRadioButtonExclusive( true ); 100 grp->setRadioButtonExclusive( true );
@@ -132,6 +133,11 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
132 gl->addWidget( alarmBtn, 1, 2 ); 133 gl->addWidget( alarmBtn, 1, 2 );
133 alarmBtn->setText( tr( "Set Alarm" ) ); 134 alarmBtn->setText( tr( "Set Alarm" ) );
134 135
136 OClickableLabel *click = new OClickableLabel(controls, "label" );
137 click->setText(tr("Set date and time." ) );
138 gl->addMultiCellWidget( click, 3, 3, 0, 2, AlignHCenter);
139 connect( click, SIGNAL(clicked() ), this, SLOT(slotAdjustTime() ) );
140
135 connect( set, SIGNAL( pressed() ), SLOT( slotSet() ) ); 141 connect( set, SIGNAL( pressed() ), SLOT( slotSet() ) );
136 connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) ); 142 connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) );
137 143
@@ -140,7 +146,7 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
140 connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) ); 146 connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) );
141 147
142 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), 148 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)),
143 this, SLOT(appMessage(const QCString&, const QByteArray&)) ); 149 this, SLOT(appMessage(const QCString&, const QByteArray&)) );
144 150
145 t = new QTimer( this ); 151 t = new QTimer( this );
146 connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) ); 152 connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) );
@@ -168,7 +174,7 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
168 alarmBool=FALSE; 174 alarmBool=FALSE;
169 snoozeBtn->hide(); 175 snoozeBtn->hide();
170 } 176 }
171 177
172 QTimer::singleShot( 0, this, SLOT(updateClock()) ); 178 QTimer::singleShot( 0, this, SLOT(updateClock()) );
173 modeSelect(0); 179 modeSelect(0);
174} 180}
@@ -181,39 +187,39 @@ Clock::~Clock()
181void Clock::updateClock() 187void Clock::updateClock()
182{ 188{
183 if ( clockRB->isChecked() ) { 189 if ( clockRB->isChecked() ) {
184 QTime tm = QDateTime::currentDateTime().time(); 190 QTime tm = QDateTime::currentDateTime().time();
185 QString s; 191 QString s;
186 if ( ampm ) { 192 if ( ampm ) {
187 int hour = tm.hour(); 193 int hour = tm.hour();
188 if (hour == 0) 194 if (hour == 0)
189 hour = 12; 195 hour = 12;
190 if (hour > 12) 196 if (hour > 12)
191 hour -= 12; 197 hour -= 12;
192 s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); 198 s.sprintf( "%2d%c%02d", hour, ':', tm.minute() );
193 ampmLabel->setText( (tm.hour() >= 12) ? "PM" : "AM" ); 199 ampmLabel->setText( (tm.hour() >= 12) ? "PM" : "AM" );
194 ampmLabel->show(); 200 ampmLabel->show();
195 } else { 201 } else {
196 s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); 202 s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() );
197 ampmLabel->hide(); 203 ampmLabel->hide();
198 } 204 }
199 lcd->display( s ); 205 lcd->display( s );
200 lcd->repaint( FALSE ); 206 lcd->repaint( FALSE );
201 aclock->display( QTime::currentTime() ); 207 aclock->display( QTime::currentTime() );
202 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 208 date->setText( TimeString::longDateString( QDate::currentDate() ) );
203 } else { 209 } else {
204 QTime swatch_time; 210 QTime swatch_time;
205 QString lcdtext; 211 QString lcdtext;
206 int totalms = swatch_totalms; 212 int totalms = swatch_totalms;
207 if ( swatch_running ) 213 if ( swatch_running )
208 totalms += swatch_start.elapsed(); 214 totalms += swatch_start.elapsed();
209 swatch_time = QTime(0,0,0).addMSecs(totalms); 215 swatch_time = QTime(0,0,0).addMSecs(totalms);
210 QString d = swatch_running ? QString(" ") 216 QString d = swatch_running ? QString(" ")
211 : QString::number(totalms%1000+1000); 217 : QString::number(totalms%1000+1000);
212 lcdtext = swatch_time.toString() + "." + d.right(3).left(sw_prec); 218 lcdtext = swatch_time.toString() + "." + d.right(3).left(sw_prec);
213 lcd->display( lcdtext ); 219 lcd->display( lcdtext );
214 lcd->repaint( FALSE ); 220 lcd->repaint( FALSE );
215 aclock->display( swatch_time ); 221 aclock->display( swatch_time );
216 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 222 date->setText( TimeString::longDateString( QDate::currentDate() ) );
217 } 223 }
218} 224}
219 225
@@ -232,19 +238,19 @@ void Clock::clearClock( void )
232void Clock::slotSet() 238void Clock::slotSet()
233{ 239{
234 if ( t->isActive() ) { 240 if ( t->isActive() ) {
235 swatch_totalms += swatch_start.elapsed(); 241 swatch_totalms += swatch_start.elapsed();
236 set->setText( tr( "Start" ) ); 242 set->setText( tr( "Start" ) );
237 t->stop(); 243 t->stop();
238 swatch_running = FALSE; 244 swatch_running = FALSE;
239 toggleScreenSaver( TRUE ); 245 toggleScreenSaver( TRUE );
240 updateClock(); 246 updateClock();
241 } else { 247 } else {
242 swatch_start.start(); 248 swatch_start.start();
243 set->setText( tr( "Stop" ) ); 249 set->setText( tr( "Stop" ) );
244 t->start( 1000 ); 250 t->start( 1000 );
245 swatch_running = TRUE; 251 swatch_running = TRUE;
246 // disable screensaver while stop watch is running 252 // disable screensaver while stop watch is running
247 toggleScreenSaver( FALSE ); 253 toggleScreenSaver( FALSE );
248 } 254 }
249} 255}
250 256
@@ -255,7 +261,7 @@ void Clock::slotReset()
255 swatch_totalms = 0; 261 swatch_totalms = 0;
256 262
257 if (swatch_running ) 263 if (swatch_running )
258 t->start(1000); 264 t->start(1000);
259 265
260 updateClock(); 266 updateClock();
261} 267}
@@ -263,26 +269,26 @@ void Clock::slotReset()
263void Clock::modeSelect( int m ) 269void Clock::modeSelect( int m )
264{ 270{
265 if ( m ) { 271 if ( m ) {
266 lcd->setNumDigits( 8+1+sw_prec ); 272 lcd->setNumDigits( 8+1+sw_prec );
267 lcd->setMinimumWidth( lcd->sizeHint().width() ); 273 lcd->setMinimumWidth( lcd->sizeHint().width() );
268 set->setEnabled( TRUE ); 274 set->setEnabled( TRUE );
269 reset->setEnabled( TRUE ); 275 reset->setEnabled( TRUE );
270 ampmLabel->hide(); 276 ampmLabel->hide();
271 277
272 if ( !swatch_running ) 278 if ( !swatch_running )
273 t->stop(); 279 t->stop();
274 } else { 280 } else {
275 lcd->setNumDigits( 5 ); 281 lcd->setNumDigits( 5 );
276 lcd->setMinimumWidth( lcd->sizeHint().width() ); 282 lcd->setMinimumWidth( lcd->sizeHint().width() );
277 set->setEnabled( FALSE ); 283 set->setEnabled( FALSE );
278 reset->setEnabled( FALSE ); 284 reset->setEnabled( FALSE );
279 t->start(1000); 285 t->start(1000);
280 } 286 }
281 updateClock(); 287 updateClock();
282} 288}
283 289
284//this sets the alarm time 290//this sets the alarm time
285void Clock::slotSetAlarm() 291void Clock::slotSetAlarm()
286{ 292{
287 if( !snoozeBtn->isHidden()) 293 if( !snoozeBtn->isHidden())
288 slotToggleAlarm(); 294 slotToggleAlarm();
@@ -304,24 +310,24 @@ void Clock::slotSetAlarm()
304 config.writeEntry("clockAlarmMinute",tmp.setNum( minute ),10); 310 config.writeEntry("clockAlarmMinute",tmp.setNum( minute ),10);
305 config.writeEntry("clockAlarmSnooze",tmp.setNum( snoozeTime ),10); 311 config.writeEntry("clockAlarmSnooze",tmp.setNum( snoozeTime ),10);
306 config.write(); 312 config.write();
307 } 313 }
308} 314}
309 315
310void Clock::slotSnooze() 316void Clock::slotSnooze()
311{ 317{
312 bSound=FALSE; 318 bSound=FALSE;
313 int warn; 319 int warn = 0;
314 QTime t = QTime::currentTime(); 320 QTime t = QTime::currentTime();
315 QDateTime whenl( when.date(), t.addSecs( snoozeTime*60)); 321 QDateTime whenl( when.date(), t.addSecs( snoozeTime*60));
316 when=whenl; 322 when=whenl;
317 AlarmServer::addAlarm( when, 323 AlarmServer::addAlarm( when,
318 "QPE/Application/clock", 324 "QPE/Application/clock",
319 "alarm(QDateTime,int)", warn ); 325 "alarm(QDateTime,int)", warn );
320 326
321} 327}
322 328
323//toggles alarm on/off 329//toggles alarm on/off
324void Clock::slotToggleAlarm() 330void Clock::slotToggleAlarm()
325{ 331{
326 Config config( "qpe" ); 332 Config config( "qpe" );
327 config.setGroup("Time"); 333 config.setGroup("Time");
@@ -349,24 +355,24 @@ void Clock::alarmOn()
349 QTime t = QTime::currentTime(); 355 QTime t = QTime::currentTime();
350 if( t > tm) 356 if( t > tm)
351 d = d.addDays(1); 357 d = d.addDays(1);
352 int warn; 358 int warn = 0;
353 QDateTime whenl(d,tm); 359 QDateTime whenl(d,tm);
354 when=whenl; 360 when=whenl;
355 AlarmServer::addAlarm( when, 361 AlarmServer::addAlarm( when,
356 "QPE/Application/clock", 362 "QPE/Application/clock",
357 "alarm(QDateTime,int)", warn ); 363 "alarm(QDateTime,int)", warn );
358 setCaption("Alarm set: "+ whenl.toString()); 364 setCaption("Alarm set: "+ whenl.toString());
359} 365}
360 366
361void Clock::alarmOff() 367void Clock::alarmOff()
362{ 368{
363 int warn; 369 int warn = 0;
364 bSound=FALSE; 370 bSound=FALSE;
365 AlarmServer::deleteAlarm( when, 371 AlarmServer::deleteAlarm( when,
366 "QPE/Application/clock", 372 "QPE/Application/clock",
367 "alarm(QDateTime,int)", warn ); 373 "alarm(QDateTime,int)", warn );
368 qDebug("Alarm Off "+ when.toString()); 374 qDebug("Alarm Off "+ when.toString());
369 setCaption("Clock"); 375 setCaption("Clock");
370} 376}
371 377
372void Clock::appMessage(const QCString& msg, const QByteArray& data) 378void Clock::appMessage(const QCString& msg, const QByteArray& data)
@@ -374,10 +380,10 @@ void Clock::appMessage(const QCString& msg, const QByteArray& data)
374 int stopTimer = 0; 380 int stopTimer = 0;
375 int timerStay = 5000; 381 int timerStay = 5000;
376 bSound=TRUE; 382 bSound=TRUE;
377 if ( msg == "alarm(QDateTime,int)" ) { 383 if ( msg == "alarm(QDateTime,int)" ) {
378 Sound::soundAlarm(); 384 Sound::soundAlarm();
379 stopTimer = startTimer( timerStay); 385 stopTimer = startTimer( timerStay);
380 } 386 }
381} 387}
382 388
383void Clock::timerEvent( QTimerEvent *e ) 389void Clock::timerEvent( QTimerEvent *e )
@@ -423,42 +429,42 @@ void AnalogClock::drawContents( QPainter *p )
423 QTime time = clear ? prevTime : currTime; 429 QTime time = clear ? prevTime : currTime;
424 430
425 if ( clear && prevTime.secsTo(currTime) > 1 ) { 431 if ( clear && prevTime.secsTo(currTime) > 1 ) {
426 p->eraseRect( rect() ); 432 p->eraseRect( rect() );
427 return; 433 return;
428 } 434 }
429 435
430 if ( !clear ) { 436 if ( !clear ) {
431 // draw ticks 437 // draw ticks
432 p->setPen( QPen( color, 1 ) ); 438 p->setPen( QPen( color, 1 ) );
433 for ( int i = 0; i < 12; i++ ) 439 for ( int i = 0; i < 12; i++ )
434 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); 440 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) );
435 } 441 }
436 442
437 if ( !clear || prevTime.minute() != currTime.minute() || 443 if ( !clear || prevTime.minute() != currTime.minute() ||
438 prevTime.hour() != currTime.hour() ) { 444 prevTime.hour() != currTime.hour() ) {
439 // draw hour pointer 445 // draw hour pointer
440 h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); 446 h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 );
441 h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); 447 h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 );
442 p->setPen( QPen( color, 3 ) ); 448 p->setPen( QPen( color, 3 ) );
443 p->drawLine( h1, h2 ); 449 p->drawLine( h1, h2 );
444 } 450 }
445 451
446 if ( !clear || prevTime.minute() != currTime.minute() ) { 452 if ( !clear || prevTime.minute() != currTime.minute() ) {
447 // draw minute pointer 453 // draw minute pointer
448 m1 = rotate( center, m1, time.minute() * 6 ); 454 m1 = rotate( center, m1, time.minute() * 6 );
449 m2 = rotate( center, m2, time.minute() * 6 ); 455 m2 = rotate( center, m2, time.minute() * 6 );
450 p->setPen( QPen( color, 2 ) ); 456 p->setPen( QPen( color, 2 ) );
451 p->drawLine( m1, m2 ); 457 p->drawLine( m1, m2 );
452 } 458 }
453 459
454 // draw second pointer 460 // draw second pointer
455 s1 = rotate( center, s1, time.second() * 6 ); 461 s1 = rotate( center, s1, time.second() * 6 );
456 s2 = rotate( center, s2, time.second() * 6 ); 462 s2 = rotate( center, s2, time.second() * 6 );
457 p->setPen( QPen( color, 1 ) ); 463 p->setPen( QPen( color, 1 ) );
458 p->drawLine( s1, s2 ); 464 p->drawLine( s1, s2 );
459 465
460 if ( !clear ) 466 if ( !clear )
461 prevTime = currTime; 467 prevTime = currTime;
462} 468}
463 469
464void AnalogClock::display( const QTime& t ) 470void AnalogClock::display( const QTime& t )
@@ -474,8 +480,13 @@ QPoint AnalogClock::rotate( QPoint c, QPoint p, int a )
474{ 480{
475 double angle = deg2rad * ( - a + 180 ); 481 double angle = deg2rad * ( - a + 180 );
476 double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - 482 double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) -
477 ( p.y() - c.y() ) * sin( angle ); 483 ( p.y() - c.y() ) * sin( angle );
478 double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + 484 double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) +
479 ( p.x() - c.x() ) * sin( angle ); 485 ( p.x() - c.x() ) * sin( angle );
480 return QPoint( nx, ny ); 486 return QPoint( nx, ny );
481} 487}
488void Clock::slotAdjustTime()
489{
490 QCopEnvelope e("QPE/System", "execute(QString)");
491 e << QString("systemtime");
492}
diff --git a/noncore/tools/clock/clock.h b/noncore/tools/clock/clock.h
index e5ed13c..024dd28 100644
--- a/noncore/tools/clock/clock.h
+++ b/noncore/tools/clock/clock.h
@@ -76,7 +76,7 @@ private slots:
76 void alarmOff(); 76 void alarmOff();
77 void appMessage(const QCString& msg, const QByteArray& data); 77 void appMessage(const QCString& msg, const QByteArray& data);
78 void timerEvent( QTimerEvent *e ); 78 void timerEvent( QTimerEvent *e );
79// void slotAdjustTime(); 79 void slotAdjustTime();
80 80
81private: 81private:
82 void clearClock(); 82 void clearClock();