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
@@ -1,640 +1,654 @@
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// changes added and Copyright (C) by L. J. Potter <ljp@llornkcor.com> 2002 20// changes added and Copyright (C) by L. J. Potter <ljp@llornkcor.com> 2002
21 21
22#include "clock.h" 22#include "clock.h"
23#include "setAlarm.h" 23#include "setAlarm.h"
24 24
25#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
26#include <qpe/qcopenvelope_qws.h> 26#include <qpe/qcopenvelope_qws.h>
27#include <qpe/config.h> 27#include <qpe/config.h>
28#include <qpe/timestring.h> 28#include <qpe/timestring.h>
29#include <qpe/alarmserver.h> 29#include <qpe/alarmserver.h>
30#include <qpe/sound.h> 30#include <qpe/sound.h>
31#include <qpe/resource.h> 31#include <qpe/resource.h>
32#include <qsound.h> 32#include <qsound.h>
33#include <qtimer.h> 33#include <qtimer.h>
34 34
35#include <opie/oclickablelabel.h> 35#include <opie/oclickablelabel.h>
36 36
37#include <qlcdnumber.h> 37#include <qlcdnumber.h>
38#include <qslider.h> 38#include <qslider.h>
39#include <qlabel.h> 39#include <qlabel.h>
40#include <qlayout.h> 40#include <qlayout.h>
41#include <qtimer.h> 41#include <qtimer.h>
42#include <qpushbutton.h> 42#include <qpushbutton.h>
43#include <qradiobutton.h> 43#include <qradiobutton.h>
44#include <qbuttongroup.h> 44#include <qbuttongroup.h>
45#include <qpainter.h> 45#include <qpainter.h>
46#include <qmessagebox.h> 46#include <qmessagebox.h>
47#include <qdatetime.h> 47#include <qdatetime.h>
48 48
49#include <math.h> 49#include <math.h>
50#include <unistd.h> 50#include <unistd.h>
51#include <sys/types.h> 51#include <sys/types.h>
52 52
53#include <pthread.h> 53#include <pthread.h>
54 54
55 55
56const double deg2rad = 0.017453292519943295769; // pi/180 56const double deg2rad = 0.017453292519943295769; // pi/180
57const int sw_prec = 2; 57const int sw_prec = 2;
58 58
59void startPlayer() 59void 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}
67 67
68 68
69static void toggleScreenSaver( bool on ) 69static void toggleScreenSaver( bool on )
70{ 70{
71 QCopEnvelope e( "QPE/System", "setScreenSaverMode(int)" ); 71 QCopEnvelope e( "QPE/System", "setScreenSaverMode(int)" );
72 e << ( on ? QPEApplication::Enable : QPEApplication::DisableSuspend ); 72 e << ( on ? QPEApplication::Enable : QPEApplication::DisableSuspend );
73} 73}
74 74
75Clock::Clock( QWidget * parent, const char * name, WFlags f ) 75Clock::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");
203 modeSelect( mode); 203 setSwatchMode( mode);
204 modeSelect( mode);
204} 205}
205 206
206Clock::~Clock() 207Clock::~Clock()
207{ 208{
208 toggleScreenSaver( true ); 209 toggleScreenSaver( true );
209} 210}
210 211
211void Clock::updateClock() 212void Clock::updateClock()
212{ 213{
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}
255 256
256void Clock::changeClock( bool a ) 257void Clock::changeClock( bool a )
257{ 258{
258 ampm = a; 259 ampm = a;
259 updateClock(); 260 updateClock();
260} 261}
261 262
262void Clock::clearClock( void ) 263void Clock::clearClock( void )
263{ 264{
264 lcd->display( QTime( 0, 0, 0 ).toString() ); 265 lcd->display( QTime( 0, 0, 0 ).toString() );
265 aclock->display( QTime( 0, 0, 0 ) ); 266 aclock->display( QTime( 0, 0, 0 ) );
266} 267}
267 268
268void Clock::startSWatch() 269void 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}
277 283
278void Clock::stopSWatch() 284void 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}
287 294
288 295
289void Clock::slotSet() 296void Clock::slotSet()
290{ 297{
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}
300 307
301void Clock::slotReset() 308void Clock::slotReset()
302{ 309{
303 t->stop(); 310 t->stop();
304 swatch_start.start(); 311 swatch_start.start();
305 swatch_totalms = 0; 312 swatch_totalms = 0;
306 313
307 if ( swatch_running ) 314 if ( swatch_running )
308 t->start( 1000 ); 315 t->start( 1000 );
309 316
310 updateClock(); 317 updateClock();
311} 318}
312 319
313void Clock::modeSelect( int m ) 320void 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();
340} 354}
341 355
342//this sets the alarm time 356//this sets the alarm time
343void Clock::slotSetAlarm() 357void Clock::slotSetAlarm()
344{ 358{
345 if ( !snoozeBtn->isHidden() ) 359 if ( !snoozeBtn->isHidden() )
346 slotToggleAlarm(); 360 slotToggleAlarm();
347 Set_Alarm *setAlarmDlg; 361 Set_Alarm *setAlarmDlg;
348 setAlarmDlg = new Set_Alarm( this, "SetAlarm", TRUE ); 362 setAlarmDlg = new Set_Alarm( this, "SetAlarm", TRUE );
349 int result = setAlarmDlg->exec(); 363 int result = setAlarmDlg->exec();
350 if ( result == 1 ) { 364 if ( result == 1 ) {
351 Config config( "qpe" ); 365 Config config( "qpe" );
352 config.setGroup( "Time" ); 366 config.setGroup( "Time" );
353 QString tmp; 367 QString tmp;
354 hour = setAlarmDlg->Hour_Slider->value(); 368 hour = setAlarmDlg->Hour_Slider->value();
355 minute = setAlarmDlg->Minute_Slider->value(); 369 minute = setAlarmDlg->Minute_Slider->value();
356 snoozeTime = setAlarmDlg->SnoozeSlider->value(); 370 snoozeTime = setAlarmDlg->SnoozeSlider->value();
357 if ( ampm ) { 371 if ( ampm ) {
358 if ( hour == 12 ) 372 if ( hour == 12 )
359 hour = 0; 373 hour = 0;
360 374
361 if ( setAlarmDlg->Pm_RadioButton->isChecked() && hour < 12 ) 375 if ( setAlarmDlg->Pm_RadioButton->isChecked() && hour < 12 )
362 hour += 12; 376 hour += 12;
363 } 377 }
364 config.writeEntry( "clockAlarmHour", tmp.setNum( hour ), 10 ); 378 config.writeEntry( "clockAlarmHour", tmp.setNum( hour ), 10 );
365 config.writeEntry( "clockAlarmMinute", tmp.setNum( minute ), 10 ); 379 config.writeEntry( "clockAlarmMinute", tmp.setNum( minute ), 10 );
366 config.writeEntry( "clockAlarmSnooze", tmp.setNum( snoozeTime ), 10 ); 380 config.writeEntry( "clockAlarmSnooze", tmp.setNum( snoozeTime ), 10 );
367 config.write(); 381 config.write();
368 } 382 }
369} 383}
370 384
371void Clock::slotSnooze() 385void Clock::slotSnooze()
372{ 386{
373 bSound = FALSE; 387 bSound = FALSE;
374 int warn = 0; 388 int warn = 0;
375 QTime t = QTime::currentTime(); 389 QTime t = QTime::currentTime();
376 QDateTime whenl( when.date(), t.addSecs( snoozeTime * 60 ) ); 390 QDateTime whenl( when.date(), t.addSecs( snoozeTime * 60 ) );
377 when = whenl; 391 when = whenl;
378 AlarmServer::addAlarm( when, 392 AlarmServer::addAlarm( when,
379 "QPE/Application/clock", 393 "QPE/Application/clock",
380 "alarm(QDateTime,int)", warn ); 394 "alarm(QDateTime,int)", warn );
381 395
382} 396}
383 397
384//toggles alarm on/off 398//toggles alarm on/off
385void Clock::slotToggleAlarm() 399void Clock::slotToggleAlarm()
386{ 400{
387 Config config( "qpe" ); 401 Config config( "qpe" );
388 config.setGroup( "Time" ); 402 config.setGroup( "Time" );
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();
406} 420}
407 421
408void Clock::alarmOn() 422void Clock::alarmOn()
409{ 423{
410 QDate d = QDate::currentDate(); 424 QDate d = QDate::currentDate();
411 QTime tm( ( int ) hour, ( int ) minute, 0 ); 425 QTime tm( ( int ) hour, ( int ) minute, 0 );
412 qDebug( "Time set " + tm.toString() ); 426 qDebug( "Time set " + tm.toString() );
413 QTime t = QTime::currentTime(); 427 QTime t = QTime::currentTime();
414 if ( t > tm ) 428 if ( t > tm )
415 d = d.addDays( 1 ); 429 d = d.addDays( 1 );
416 int warn = 0; 430 int warn = 0;
417 QDateTime whenl( d, tm ); 431 QDateTime whenl( d, tm );
418 when = whenl; 432 when = whenl;
419 AlarmServer::addAlarm( when, 433 AlarmServer::addAlarm( when,
420 "QPE/Application/clock", 434 "QPE/Application/clock",
421 "alarm(QDateTime,int)", warn ); 435 "alarm(QDateTime,int)", warn );
422 setCaption( "Alarm set: " + whenl.toString() ); 436 setCaption( "Alarm set: " + whenl.toString() );
423} 437}
424 438
425void Clock::alarmOff() 439void Clock::alarmOff()
426{ 440{
427 int warn = 0; 441 int warn = 0;
428 bSound = FALSE; 442 bSound = FALSE;
429 AlarmServer::deleteAlarm( when, 443 AlarmServer::deleteAlarm( when,
430 "QPE/Application/clock", 444 "QPE/Application/clock",
431 "alarm(QDateTime,int)", warn ); 445 "alarm(QDateTime,int)", warn );
432 qDebug( "Alarm Off " + when.toString() ); 446 qDebug( "Alarm Off " + when.toString() );
433 setCaption( "Clock" ); 447 setCaption( "Clock" );
434} 448}
435 449
436void Clock::clearTimer() 450void 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}
443 457
444void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ ) 458void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ )
445{ 459{
446 int stopTimer = 0; 460 int stopTimer = 0;
447 int timerStay = 5000; 461 int timerStay = 5000;
448 bSound = TRUE; 462 bSound = TRUE;
449 qDebug( "Message received in clock" ); 463 qDebug( "Message received in clock" );
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
482 show(); 496 show();
483 raise(); 497 raise();
484 QPEApplication::setKeepRunning(); 498 QPEApplication::setKeepRunning();
485 setActiveWindow(); 499 setActiveWindow();
486} 500}
487 501
488void Clock::timerEvent( QTimerEvent *e ) 502void Clock::timerEvent( QTimerEvent *e )
489{ 503{
490 static int stop = 0; 504 static int stop = 0;
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}
504 518
505 519
506QSizePolicy AnalogClock::sizePolicy() const 520QSizePolicy AnalogClock::sizePolicy() const
507{ 521{
508 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); 522 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
509} 523}
510 524
511void AnalogClock::drawContents( QPainter *p ) 525void AnalogClock::drawContents( QPainter *p )
512{ 526{
513 QRect r = contentsRect(); 527 QRect r = contentsRect();
514 QRect fr; 528 QRect fr;
515 529
516 if ( r. width ( ) > r. height ( )) 530 if ( r. width ( ) > r. height ( ))
517 fr. setRect (( r. width ( ) - r. height ( )) / 2, r. y ( ), r. height ( ), r. height ( )); 531 fr. setRect (( r. width ( ) - r. height ( )) / 2, r. y ( ), r. height ( ), r. height ( ));
518 else 532 else
519 fr. setRect ( r. x ( ), ( r. height ( ) - r. width ( )) / 2, r. width ( ), r. width ( )); 533 fr. setRect ( r. x ( ), ( r. height ( ) - r. width ( )) / 2, r. width ( ), r. width ( ));
520 534
521 QPoint center = fr. center ( ); // ( fr.x() + fr.width() / 2, fr.y() + fr.height() / 2 ); 535 QPoint center = fr. center ( ); // ( fr.x() + fr.width() / 2, fr.y() + fr.height() / 2 );
522 QPoint l1 ( center. x ( ), fr. y ( ) + 2 ); 536 QPoint l1 ( center. x ( ), fr. y ( ) + 2 );
523 QPoint l2 ( center. x ( ), fr. y ( ) + 8 ); 537 QPoint l2 ( center. x ( ), fr. y ( ) + 8 );
524 538
525 539
526 540
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
545 drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Text ), currTime ); 559 drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Text ), currTime );
546 560
547 prevTime = currTime; 561 prevTime = currTime;
548} 562}
549 563
550void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 ) 564void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 )
551{ 565{
552 QPoint center = r. center ( ); 566 QPoint center = r. center ( );
553 567
554 QPoint h1( center. x ( ), r. y ( ) + r. height ( ) / 4 ); 568 QPoint h1( center. x ( ), r. y ( ) + r. height ( ) / 4 );
555 QPoint h2( center. x ( ), center. y ( ) ); 569 QPoint h2( center. x ( ), center. y ( ) );
556 570
557 QPoint m1( center. x ( ), r.y() + r.height() / 8 ); 571 QPoint m1( center. x ( ), r.y() + r.height() / 8 );
558 QPoint m2( center. x ( ), center. y ( ) ); 572 QPoint m2( center. x ( ), center. y ( ) );
559 573
560 QPoint s1( center. x ( ), r. y ( ) + 8 ); 574 QPoint s1( center. x ( ), r. y ( ) + 8 );
561 QPoint s2( center. x ( ), center. y ( ) ); 575 QPoint s2( center. x ( ), center. y ( ) );
562 576
563 577
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 );
567 h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 ); 581 h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 );
568 p-> setPen ( QPen ( c, 3 )); 582 p-> setPen ( QPen ( c, 3 ));
569 p-> drawLine ( h1, h2 ); 583 p-> drawLine ( h1, h2 );
570 } 584 }
571 585
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 );
575 m2 = rotate( center, m2, t.minute() * 6 ); 589 m2 = rotate( center, m2, t.minute() * 6 );
576 p-> setPen ( QPen ( c, 2 )); 590 p-> setPen ( QPen ( c, 2 ));
577 p-> drawLine ( m1, m2 ); 591 p-> drawLine ( m1, m2 );
578 } 592 }
579 593
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 );
583 s2 = rotate( center, s2, t.second() * 6 ); 597 s2 = rotate( center, s2, t.second() * 6 );
584 p-> setPen ( QPen ( c, 1 )); 598 p-> setPen ( QPen ( c, 1 ));
585 p-> drawLine ( s1, s2 ); 599 p-> drawLine ( s1, s2 );
586 } 600 }
587} 601}
588 602
589void AnalogClock::display( const QTime& t ) 603void AnalogClock::display( const QTime& t )
590{ 604{
591 currTime = t; 605 currTime = t;
592 clear = false; 606 clear = false;
593 repaint( false ); 607 repaint( false );
594 clear = true; 608 clear = true;
595} 609}
596 610
597QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) 611QPoint AnalogClock::rotate( QPoint c, QPoint p, int a )
598{ 612{
599 double angle = deg2rad * ( - a + 180 ); 613 double angle = deg2rad * ( - a + 180 );
600 double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - 614 double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) -
601 ( p.y() - c.y() ) * sin( angle ); 615 ( p.y() - c.y() ) * sin( angle );
602 double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + 616 double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) +
603 ( p.x() - c.x() ) * sin( angle ); 617 ( p.x() - c.x() ) * sin( angle );
604 return QPoint( nx, ny ); 618 return QPoint( nx, ny );
605} 619}
606 620
607void Clock::slotAdjustTime() 621void Clock::slotAdjustTime()
608{ 622{
609 QCopEnvelope e( "QPE/System", "execute(QString)" ); 623 QCopEnvelope e( "QPE/System", "execute(QString)" );
610 e << QString( "systemtime" ); 624 e << QString( "systemtime" );
611} 625}
612 626
613void Clock::slotStartTimer() 627void Clock::slotStartTimer()
614{ 628{
615 if ( clockRB->isChecked() ) 629 if ( clockRB->isChecked() )
616 setSwatchMode( 1); 630 setSwatchMode( 1);
617 startSWatch(); 631 startSWatch();
618} 632}
619 633
620void Clock::slotStopTimer() 634void Clock::slotStopTimer()
621{ 635{
622 if ( clockRB->isChecked() ) 636 if ( clockRB->isChecked() )
623 setSwatchMode( 1); 637 setSwatchMode( 1);
624 stopSWatch(); 638 stopSWatch();
625} 639}
626 640
627void Clock::slotResetTimer() 641void Clock::slotResetTimer()
628{ 642{
629 if ( clockRB->isChecked() ) 643 if ( clockRB->isChecked() )
630 setSwatchMode( 1); 644 setSwatchMode( 1);
631slotReset(); 645slotReset();
632} 646}
633 647
634void Clock::setSwatchMode(int mode) 648void 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}