summaryrefslogtreecommitdiff
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/clock/clock.cpp255
1 files changed, 124 insertions, 131 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp
index ea8e8ca..a85cc19 100644
--- a/noncore/tools/clock/clock.cpp
+++ b/noncore/tools/clock/clock.cpp
@@ -1,488 +1,481 @@
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
20 21
21#include "clock.h" 22#include "clock.h"
22#include "setAlarm.h" 23#include "setAlarm.h"
23 24
24#include <qpe/qpeapplication.h> 25#include <qpe/qpeapplication.h>
25#include <qpe/qcopenvelope_qws.h> 26#include <qpe/qcopenvelope_qws.h>
26#include <qpe/config.h> 27#include <qpe/config.h>
27#include <qpe/timestring.h> 28#include <qpe/timestring.h>
28#include <qpe/alarmserver.h> 29#include <qpe/alarmserver.h>
29#include <qpe/sound.h> 30#include <qpe/sound.h>
30#include <qpe/resource.h> 31#include <qpe/resource.h>
31#include <qsound.h> 32#include <qsound.h>
32#include <qtimer.h> 33#include <qtimer.h>
33 34
34#include <opie/oclickablelabel.h>
35
36#include <qlcdnumber.h> 35#include <qlcdnumber.h>
37#include <qslider.h> 36#include <qslider.h>
38#include <qlabel.h> 37#include <qlabel.h>
39#include <qlayout.h> 38#include <qlayout.h>
40#include <qtimer.h> 39#include <qtimer.h>
41#include <qpushbutton.h> 40#include <qpushbutton.h>
42#include <qradiobutton.h> 41#include <qradiobutton.h>
43#include <qbuttongroup.h> 42#include <qbuttongroup.h>
44#include <qpainter.h> 43#include <qpainter.h>
45#include <qmessagebox.h> 44#include <qmessagebox.h>
46#include <qdatetime.h> 45#include <qdatetime.h>
47 46
48#include <math.h> 47#include <math.h>
49 48
50const double deg2rad = 0.017453292519943295769; // pi/180 49const double deg2rad = 0.017453292519943295769; // pi/180
51const int sw_prec = 2; 50const int sw_prec = 2;
52 51
53static void toggleScreenSaver( bool on ) 52static void toggleScreenSaver( bool on )
54{ 53{
55 QCopEnvelope e("QPE/System", "setScreenSaverMode(int)" ); 54 QCopEnvelope e("QPE/System", "setScreenSaverMode(int)" );
56 e << (on ? QPEApplication::Enable: QPEApplication::DisableSuspend ); 55 e << (on ? QPEApplication::Enable: QPEApplication::DisableSuspend );
57} 56}
58 57
59Clock::Clock( QWidget * parent, const char * name, WFlags f ) 58Clock::Clock( QWidget * parent, const char * name, WFlags f )
60 : QVBox( parent, name , f ) 59 : QVBox( parent, name , f )
61{ 60{
62 setSpacing( 4 ); 61 setSpacing( 4 );
63 setMargin( 1 ); 62 setMargin( 1 );
64 63
65 Config config( "qpe" ); 64 Config config( "qpe" );
66 config.setGroup("Time"); 65 config.setGroup("Time");
67 ampm = config.readBoolEntry( "AMPM", TRUE ); 66 ampm = config.readBoolEntry( "AMPM", TRUE );
68 67
69 snoozeBtn = new QPushButton ( this); 68 snoozeBtn = new QPushButton ( this);
70 snoozeBtn->setText( tr( "Snooze" ) ); 69 snoozeBtn->setText( tr( "Snooze" ) );
71 70
72 aclock = new AnalogClock( this ); 71 aclock = new AnalogClock( this );
73 aclock->display( QTime::currentTime() ); 72 aclock->display( QTime::currentTime() );
74 aclock->setLineWidth( 2 ); 73 aclock->setLineWidth( 2 );
75 74
76 QHBox *hb = new QHBox( this ); 75 QHBox *hb = new QHBox( this );
77 hb->setMargin( 0 ); 76 hb->setMargin( 0 );
78 QWidget *space = new QWidget( hb ); 77 QWidget *space = new QWidget( hb );
79 lcd = new QLCDNumber( hb ); 78 lcd = new QLCDNumber( hb );
80 lcd->setSegmentStyle( QLCDNumber::Flat ); 79 lcd->setSegmentStyle( QLCDNumber::Flat );
81 lcd->setFrameStyle( QFrame::NoFrame ); 80 lcd->setFrameStyle( QFrame::NoFrame );
82 lcd->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) ); 81 lcd->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) );
83 lcd->setFixedHeight( 23 ); 82 lcd->setFixedHeight( 23 );
84 83
85 ampmLabel = new QLabel( tr("PM"), hb ); 84 ampmLabel = new QLabel( tr("PM"), hb );
86 ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); 85 ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) );
87 ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) ); 86 ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) );
88 ampmLabel->setAlignment( AlignLeft | AlignBottom ); 87 ampmLabel->setAlignment( AlignLeft | AlignBottom );
89 space = new QWidget( hb ); 88 space = new QWidget( hb );
90 89
91 date = new QLabel( this ); 90 date = new QLabel( this );
92 date->setAlignment( AlignHCenter | AlignVCenter ); 91 date->setAlignment( AlignHCenter | AlignVCenter );
93 date->setFont( QFont( "Helvetica", 14, QFont::Bold ) ); 92 date->setFont( QFont( "Helvetica", 14, QFont::Bold ) );
94 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 93 date->setText( TimeString::longDateString( QDate::currentDate() ) );
95 94
96 QWidget *controls = new QWidget( this ); 95 QWidget *controls = new QWidget( this );
97 QGridLayout *gl = new QGridLayout( controls, 3, 2, 6, 4 ); 96 QGridLayout *gl = new QGridLayout( controls, 2, 2, 6, 4 );
98 97
99 QButtonGroup *grp = new QButtonGroup( controls ); 98 QButtonGroup *grp = new QButtonGroup( controls );
100 grp->setRadioButtonExclusive( true ); 99 grp->setRadioButtonExclusive( true );
101 grp->hide(); 100 grp->hide();
102 101
103 clockRB = new QRadioButton ( tr( "Clock" ), controls ); 102 clockRB = new QRadioButton ( tr( "Clock" ), controls );
104 gl->addWidget( clockRB, 0, 0 ); 103 gl->addWidget( clockRB, 0, 0 );
105 grp->insert( clockRB ); 104 grp->insert( clockRB );
106 105
107 swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls ); 106 swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls );
108 gl->addWidget( swatchRB, 1, 0 ); 107 gl->addWidget( swatchRB, 1, 0 );
109 grp->insert( swatchRB ); 108 grp->insert( swatchRB );
110 109
111 connect( grp, SIGNAL(clicked(int)), this, SLOT(modeSelect(int)) ); 110 connect( grp, SIGNAL(clicked(int)), this, SLOT(modeSelect(int)) );
112 grp->setButton( 0 ); 111 grp->setButton( 0 );
113 112
114 set = new QPushButton ( controls ); 113 set = new QPushButton ( controls );
115 set->setMaximumSize(50,30); 114 set->setMaximumSize(50,30);
116 gl->addWidget( set, 0, 1 ); 115 gl->addWidget( set, 0, 1 );
117 set->setText( tr( "Start" ) ); 116 set->setText( tr( "Start" ) );
118 set->setEnabled( FALSE ); 117 set->setEnabled( FALSE );
119 grp->insert( set ); 118 grp->insert( set );
120 119
121 reset = new QPushButton ( controls ); 120 reset = new QPushButton ( controls );
122 gl->addWidget( reset, 1, 1 ); 121 gl->addWidget( reset, 1, 1 );
123 reset->setText( tr( "Reset" ) ); 122 reset->setText( tr( "Reset" ) );
124 reset->setEnabled( FALSE ); 123 reset->setEnabled( FALSE );
125 grp->insert( reset ); 124 grp->insert( reset );
126 125
127 alarmOffBtn = new QPushButton ( controls ); 126 alarmOffBtn = new QPushButton ( controls );
128// alarmOffBtn->setMaximumSize(60,30); 127// alarmOffBtn->setMaximumSize(60,30);
129 gl->addWidget( alarmOffBtn, 0, 2 ); 128 gl->addWidget( alarmOffBtn, 0, 2 );
130 129
131 alarmBtn = new QPushButton ( controls ); 130 alarmBtn = new QPushButton ( controls );
132 // alarmBtn->setMaximumSize(60,30); 131 // alarmBtn->setMaximumSize(60,30);
133 gl->addWidget( alarmBtn, 1, 2 ); 132 gl->addWidget( alarmBtn, 1, 2 );
134 alarmBtn->setText( tr( "Set Alarm" ) ); 133 alarmBtn->setText( tr( "Set Alarm" ) );
135 134
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
141 connect( set, SIGNAL( pressed() ), SLOT( slotSet() ) ); 135 connect( set, SIGNAL( pressed() ), SLOT( slotSet() ) );
142 connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) ); 136 connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) );
143 137
144 connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) ); 138 connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) );
145 connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) ); 139 connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) );
146 connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) ); 140 connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) );
147 141
148 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)), 142 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)),
149 this, SLOT(appMessage(const QCString&, const QByteArray&)) ); 143 this, SLOT(appMessage(const QCString&, const QByteArray&)) );
150 144
151 t = new QTimer( this ); 145 t = new QTimer( this );
152 connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) ); 146 connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) );
153 t->start( 1000 ); 147 t->start( 1000 );
154 148
155 connect( qApp, SIGNAL( timeChanged() ), SLOT( updateClock() ) ); 149 connect( qApp, SIGNAL( timeChanged() ), SLOT( updateClock() ) );
156 150
157 swatch_running = FALSE; 151 swatch_running = FALSE;
158 swatch_totalms = 0; 152 swatch_totalms = 0;
159 153
160 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); 154 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) );
161 155
162 QString tmp = config.readEntry("clockAlarmHour", ""); 156 QString tmp = config.readEntry("clockAlarmHour", "");
163 bool ok; 157 bool ok;
164 hour = tmp.toInt(&ok,10); 158 hour = tmp.toInt(&ok,10);
165 tmp = config.readEntry("clockAlarmMinute",""); 159 tmp = config.readEntry("clockAlarmMinute","");
166 minute = tmp.toInt(&ok,10); 160 minute = tmp.toInt(&ok,10);
167 161
168 if( config.readEntry("clockAlarmSet","FALSE") == "TRUE") { 162 if( config.readEntry("clockAlarmSet","FALSE") == "TRUE") {
169 alarmOffBtn->setText( tr( "Alarm Is On" ) ); 163 alarmOffBtn->setText( tr( "Alarm Is On" ) );
170 alarmBool=TRUE; 164 alarmBool=TRUE;
171 snoozeBtn->show(); 165 snoozeBtn->show();
172 } else { 166 } else {
173 alarmOffBtn->setText( tr( "Alarm Is Off" ) ); 167 alarmOffBtn->setText( tr( "Alarm Is Off" ) );
174 alarmBool=FALSE; 168 alarmBool=FALSE;
175 snoozeBtn->hide(); 169 snoozeBtn->hide();
176 } 170 }
177 171
178 QTimer::singleShot( 0, this, SLOT(updateClock()) ); 172 QTimer::singleShot( 0, this, SLOT(updateClock()) );
179 modeSelect(0); 173 modeSelect(0);
180} 174}
181 175
182Clock::~Clock() 176Clock::~Clock()
183{ 177{
184 toggleScreenSaver( true ); 178 toggleScreenSaver( true );
185} 179}
186 180
187void Clock::updateClock() 181void Clock::updateClock()
188{ 182{
189 if ( clockRB->isChecked() ) { 183 if ( clockRB->isChecked() ) {
190 QTime tm = QDateTime::currentDateTime().time(); 184 QTime tm = QDateTime::currentDateTime().time();
191 QString s; 185 QString s;
192 if ( ampm ) { 186 if ( ampm ) {
193 int hour = tm.hour(); 187 int hour = tm.hour();
194 if (hour == 0) 188 if (hour == 0)
195 hour = 12; 189 hour = 12;
196 if (hour > 12) 190 if (hour > 12)
197 hour -= 12; 191 hour -= 12;
198 s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); 192 s.sprintf( "%2d%c%02d", hour, ':', tm.minute() );
199 ampmLabel->setText( (tm.hour() >= 12) ? "PM" : "AM" ); 193 ampmLabel->setText( (tm.hour() >= 12) ? "PM" : "AM" );
200 ampmLabel->show(); 194 ampmLabel->show();
201 } else { 195 } else {
202 s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); 196 s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() );
203 ampmLabel->hide(); 197 ampmLabel->hide();
204 } 198 }
205 lcd->display( s ); 199 lcd->display( s );
206 lcd->repaint( FALSE ); 200 lcd->repaint( FALSE );
207 aclock->display( QTime::currentTime() ); 201 aclock->display( QTime::currentTime() );
208 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 202 date->setText( TimeString::longDateString( QDate::currentDate() ) );
209 } else { 203 } else {
210 QTime swatch_time; 204 QTime swatch_time;
211 QString lcdtext; 205 QString lcdtext;
212 int totalms = swatch_totalms; 206 int totalms = swatch_totalms;
213 if ( swatch_running ) 207 if ( swatch_running )
214 totalms += swatch_start.elapsed(); 208 totalms += swatch_start.elapsed();
215 swatch_time = QTime(0,0,0).addMSecs(totalms); 209 swatch_time = QTime(0,0,0).addMSecs(totalms);
216 QString d = swatch_running ? QString(" ") 210 QString d = swatch_running ? QString(" ")
217 : QString::number(totalms%1000+1000); 211 : QString::number(totalms%1000+1000);
218 lcdtext = swatch_time.toString() + "." + d.right(3).left(sw_prec); 212 lcdtext = swatch_time.toString() + "." + d.right(3).left(sw_prec);
219 lcd->display( lcdtext ); 213 lcd->display( lcdtext );
220 lcd->repaint( FALSE ); 214 lcd->repaint( FALSE );
221 aclock->display( swatch_time ); 215 aclock->display( swatch_time );
222 date->setText( TimeString::longDateString( QDate::currentDate() ) ); 216 date->setText( TimeString::longDateString( QDate::currentDate() ) );
223 } 217 }
224} 218}
225 219
226void Clock::changeClock( bool a ) 220void Clock::changeClock( bool a )
227{ 221{
228 ampm = a; 222 ampm = a;
229 updateClock(); 223 updateClock();
230} 224}
231 225
232void Clock::clearClock( void ) 226void Clock::clearClock( void )
233{ 227{
234 lcd->display( QTime( 0,0,0 ).toString() ); 228 lcd->display( QTime( 0,0,0 ).toString() );
235 aclock->display( QTime( 0,0,0 ) ); 229 aclock->display( QTime( 0,0,0 ) );
236} 230}
237 231
238void Clock::slotSet() 232void Clock::slotSet()
239{ 233{
240 if ( t->isActive() ) { 234 if ( t->isActive() ) {
241 swatch_totalms += swatch_start.elapsed(); 235 swatch_totalms += swatch_start.elapsed();
242 set->setText( tr( "Start" ) ); 236 set->setText( tr( "Start" ) );
243 t->stop(); 237 t->stop();
244 swatch_running = FALSE; 238 swatch_running = FALSE;
245 toggleScreenSaver( TRUE ); 239 toggleScreenSaver( TRUE );
246 updateClock(); 240 updateClock();
247 } else { 241 } else {
248 swatch_start.start(); 242 swatch_start.start();
249 set->setText( tr( "Stop" ) ); 243 set->setText( tr( "Stop" ) );
250 t->start( 1000 ); 244 t->start( 1000 );
251 swatch_running = TRUE; 245 swatch_running = TRUE;
252 // disable screensaver while stop watch is running 246 // disable screensaver while stop watch is running
253 toggleScreenSaver( FALSE ); 247 toggleScreenSaver( FALSE );
254 } 248 }
255} 249}
256 250
257void Clock::slotReset() 251void Clock::slotReset()
258{ 252{
259 t->stop(); 253 t->stop();
260 swatch_start.start(); 254 swatch_start.start();
261 swatch_totalms = 0; 255 swatch_totalms = 0;
262 256
263 if (swatch_running ) 257 if (swatch_running )
264 t->start(1000); 258 t->start(1000);
265 259
266 updateClock(); 260 updateClock();
267} 261}
268 262
269void Clock::modeSelect( int m ) 263void Clock::modeSelect( int m )
270{ 264{
271 if ( m ) { 265 if ( m ) {
272 lcd->setNumDigits( 8+1+sw_prec ); 266 lcd->setNumDigits( 8+1+sw_prec );
273 lcd->setMinimumWidth( lcd->sizeHint().width() ); 267 lcd->setMinimumWidth( lcd->sizeHint().width() );
274 set->setEnabled( TRUE ); 268 set->setEnabled( TRUE );
275 reset->setEnabled( TRUE ); 269 reset->setEnabled( TRUE );
276 ampmLabel->hide(); 270 ampmLabel->hide();
277 271
278 if ( !swatch_running ) 272 if ( !swatch_running )
279 t->stop(); 273 t->stop();
280 } else { 274 } else {
281 lcd->setNumDigits( 5 ); 275 lcd->setNumDigits( 5 );
282 lcd->setMinimumWidth( lcd->sizeHint().width() ); 276 lcd->setMinimumWidth( lcd->sizeHint().width() );
283 set->setEnabled( FALSE ); 277 set->setEnabled( FALSE );
284 reset->setEnabled( FALSE ); 278 reset->setEnabled( FALSE );
285 t->start(1000); 279 t->start(1000);
286 } 280 }
287 updateClock(); 281 updateClock();
288} 282}
289 283
290//this sets the alarm time 284//this sets the alarm time
291void Clock::slotSetAlarm() 285void Clock::slotSetAlarm()
292{ 286{
293 if( !snoozeBtn->isHidden()) 287 if( !snoozeBtn->isHidden())
294 slotToggleAlarm(); 288 slotToggleAlarm();
295 Set_Alarm *setAlarmDlg; 289 Set_Alarm *setAlarmDlg;
296 setAlarmDlg = new Set_Alarm(this,"SetAlarm", TRUE); 290 setAlarmDlg = new Set_Alarm(this,"SetAlarm", TRUE);
297 int result = setAlarmDlg->exec(); 291 int result = setAlarmDlg->exec();
298 if(result == 1) { 292 if(result == 1) {
299 Config config( "qpe" ); 293 Config config( "qpe" );
300 config.setGroup("Time"); 294 config.setGroup("Time");
301 QString tmp; 295 QString tmp;
302 hour = setAlarmDlg->Hour_Slider->value(); 296 hour = setAlarmDlg->Hour_Slider->value();
303 minute = setAlarmDlg->Minute_Slider->value(); 297 minute = setAlarmDlg->Minute_Slider->value();
304 snoozeTime=setAlarmDlg->SnoozeSlider->value(); 298 snoozeTime=setAlarmDlg->SnoozeSlider->value();
305 if(ampm) { 299 if(ampm) {
306 if(setAlarmDlg->Pm_RadioButton->isChecked() && hour < 12 ) 300 if(setAlarmDlg->Pm_RadioButton->isChecked() && hour < 12 )
307 hour+=12; 301 hour+=12;
308 } 302 }
309 config.writeEntry("clockAlarmHour", tmp.setNum( hour ),10); 303 config.writeEntry("clockAlarmHour", tmp.setNum( hour ),10);
310 config.writeEntry("clockAlarmMinute",tmp.setNum( minute ),10); 304 config.writeEntry("clockAlarmMinute",tmp.setNum( minute ),10);
311 config.writeEntry("clockAlarmSnooze",tmp.setNum( snoozeTime ),10); 305 config.writeEntry("clockAlarmSnooze",tmp.setNum( snoozeTime ),10);
312 config.write(); 306 config.write();
313 } 307 }
314} 308}
315 309
316void Clock::slotSnooze() 310void Clock::slotSnooze()
317{ 311{
318 bSound=FALSE; 312 bSound=FALSE;
319 int warn; 313 int warn;
320 QTime t = QTime::currentTime(); 314 QTime t = QTime::currentTime();
321 QDateTime whenl( when.date(), t.addSecs( snoozeTime*60)); 315 QDateTime whenl( when.date(), t.addSecs( snoozeTime*60));
322 when=whenl; 316 when=whenl;
323 AlarmServer::addAlarm( when, 317 AlarmServer::addAlarm( when,
324 "QPE/Application/clock", 318 "QPE/Application/clock",
325 "alarm(QDateTime,int)", warn ); 319 "alarm(QDateTime,int)", warn );
326 320
327} 321}
328 322
329//toggles alarm on/off 323//toggles alarm on/off
330void Clock::slotToggleAlarm() 324void Clock::slotToggleAlarm()
331{ 325{
332 Config config( "qpe" ); 326 Config config( "qpe" );
333 config.setGroup("Time"); 327 config.setGroup("Time");
334 if(alarmBool) { 328 if(alarmBool) {
335 config.writeEntry("clockAlarmSet","FALSE"); 329 config.writeEntry("clockAlarmSet","FALSE");
336 alarmOffBtn->setText( tr( "Alarm Is Off" ) ); 330 alarmOffBtn->setText( tr( "Alarm Is Off" ) );
337 snoozeBtn->hide(); 331 snoozeBtn->hide();
338 alarmBool=FALSE; 332 alarmBool=FALSE;
339 alarmOff(); 333 alarmOff();
340 } else { 334 } else {
341 config.writeEntry("clockAlarmSet","TRUE"); 335 config.writeEntry("clockAlarmSet","TRUE");
342 alarmOffBtn->setText( tr( "Alarm Is On" ) ); 336 alarmOffBtn->setText( tr( "Alarm Is On" ) );
343 snoozeBtn->show(); 337 snoozeBtn->show();
344 alarmBool=TRUE; 338 alarmBool=TRUE;
345 alarmOn(); 339 alarmOn();
346 } 340 }
347 config.write(); 341 config.write();
348} 342}
349 343
350void Clock::alarmOn() 344void Clock::alarmOn()
351{ 345{
352 QDate d = QDate::currentDate(); 346 QDate d = QDate::currentDate();
353 QTime tm((int)hour,(int)minute,0); 347 QTime tm((int)hour,(int)minute,0);
354 qDebug("Time set "+tm.toString()); 348 qDebug("Time set "+tm.toString());
355 QTime t = QTime::currentTime(); 349 QTime t = QTime::currentTime();
356 if( t > tm) 350 if( t > tm)
357 d = d.addDays(1); 351 d = d.addDays(1);
358 int warn; 352 int warn;
359 QDateTime whenl(d,tm); 353 QDateTime whenl(d,tm);
360 when=whenl; 354 when=whenl;
361 AlarmServer::addAlarm( when, 355 AlarmServer::addAlarm( when,
362 "QPE/Application/clock", 356 "QPE/Application/clock",
363 "alarm(QDateTime,int)", warn ); 357 "alarm(QDateTime,int)", warn );
364 QMessageBox::message("Note","Alarm is set for:\n"+ whenl.toString()); 358 setCaption("Alarm set: "+ whenl.toString());
365} 359}
366 360
367void Clock::alarmOff() 361void Clock::alarmOff()
368{ 362{
369 int warn; 363 int warn;
370 bSound=FALSE; 364 bSound=FALSE;
371 AlarmServer::deleteAlarm( when, 365 AlarmServer::deleteAlarm( when,
372 "QPE/Application/clock", 366 "QPE/Application/clock",
373 "alarm(QDateTime,int)", warn ); 367 "alarm(QDateTime,int)", warn );
374 qDebug("Alarm Off "+ when.toString()); 368 qDebug("Alarm Off "+ when.toString());
375 369 setCaption("Clock");
376} 370}
377 371
378void Clock::appMessage(const QCString& msg, const QByteArray& data) 372void Clock::appMessage(const QCString& msg, const QByteArray& data)
379{ 373{
380 int stopTimer = 0; 374 int stopTimer = 0;
381 int timerStay = 5000; 375 int timerStay = 5000;
382 bSound=TRUE; 376 bSound=TRUE;
383 if ( msg == "alarm(QDateTime,int)" ) { 377 if ( msg == "alarm(QDateTime,int)" ) {
384 Sound::soundAlarm(); 378 Sound::soundAlarm();
385 stopTimer = startTimer( timerStay); 379 stopTimer = startTimer( timerStay);
386 } 380 }
387} 381}
388 382
389void Clock::timerEvent( QTimerEvent *e ) 383void Clock::timerEvent( QTimerEvent *e )
390{ 384{
391 static int stop = 0; 385 static int stop = 0;
392 if ( stop < 10 && bSound) { 386 if ( stop < 120 && bSound) {
393 Sound::soundAlarm(); 387 Sound::soundAlarm();
394 stop++; 388 stop++;
395 } else { 389 } else {
396 stop = 0; 390 stop = 0;
397 killTimer( e->timerId() ); 391 killTimer( e->timerId() );
392 alarmOffBtn->setText( tr( "Alarm Is Off" ) );
393 alarmBool=FALSE;
394 snoozeBtn->hide();
395 setCaption("Clock: Alarm was missed.");
398 } 396 }
399} 397}
400 398
401 399
402QSizePolicy AnalogClock::sizePolicy() const 400QSizePolicy AnalogClock::sizePolicy() const
403{ 401{
404 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding ); 402 return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
405} 403}
406 404
407void AnalogClock::drawContents( QPainter *p ) 405void AnalogClock::drawContents( QPainter *p )
408{ 406{
409 QRect r = contentsRect(); 407 QRect r = contentsRect();
410 QPoint center( r.x() + r.width() / 2, r.y() + r.height() / 2 ); 408 QPoint center( r.x() + r.width() / 2, r.y() + r.height() / 2 );
411 409
412 QPoint l1( r.x() + r.width() / 2, r.y() + 2 ); 410 QPoint l1( r.x() + r.width() / 2, r.y() + 2 );
413 QPoint l2( r.x() + r.width() / 2, r.y() + 8 ); 411 QPoint l2( r.x() + r.width() / 2, r.y() + 8 );
414 412
415 QPoint h1( r.x() + r.width() / 2, r.y() + r.height() / 4 ); 413 QPoint h1( r.x() + r.width() / 2, r.y() + r.height() / 4 );
416 QPoint h2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); 414 QPoint h2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
417 415
418 QPoint m1( r.x() + r.width() / 2, r.y() + r.height() / 8 ); 416 QPoint m1( r.x() + r.width() / 2, r.y() + r.height() / 8 );
419 QPoint m2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); 417 QPoint m2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
420 418
421 QPoint s1( r.x() + r.width() / 2, r.y() + 8 ); 419 QPoint s1( r.x() + r.width() / 2, r.y() + 8 );
422 QPoint s2( r.x() + r.width() / 2, r.y() + r.height() / 2 ); 420 QPoint s2( r.x() + r.width() / 2, r.y() + r.height() / 2 );
423 421
424 QColor color( clear ? backgroundColor() : black ); 422 QColor color( clear ? backgroundColor() : black );
425 QTime time = clear ? prevTime : currTime; 423 QTime time = clear ? prevTime : currTime;
426 424
427 if ( clear && prevTime.secsTo(currTime) > 1 ) { 425 if ( clear && prevTime.secsTo(currTime) > 1 ) {
428 p->eraseRect( rect() ); 426 p->eraseRect( rect() );
429 return; 427 return;
430 } 428 }
431 429
432 if ( !clear ) { 430 if ( !clear ) {
433 // draw ticks 431 // draw ticks
434 p->setPen( QPen( color, 1 ) ); 432 p->setPen( QPen( color, 1 ) );
435 for ( int i = 0; i < 12; i++ ) 433 for ( int i = 0; i < 12; i++ )
436 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) ); 434 p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) );
437 } 435 }
438 436
439 if ( !clear || prevTime.minute() != currTime.minute() || 437 if ( !clear || prevTime.minute() != currTime.minute() ||
440 prevTime.hour() != currTime.hour() ) { 438 prevTime.hour() != currTime.hour() ) {
441 // draw hour pointer 439 // draw hour pointer
442 h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); 440 h1 = rotate( center, h1, 30 * ( time.hour() % 12 ) + time.minute() / 2 );
443 h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 ); 441 h2 = rotate( center, h2, 30 * ( time.hour() % 12 ) + time.minute() / 2 );
444 p->setPen( QPen( color, 3 ) ); 442 p->setPen( QPen( color, 3 ) );
445 p->drawLine( h1, h2 ); 443 p->drawLine( h1, h2 );
446 } 444 }
447 445
448 if ( !clear || prevTime.minute() != currTime.minute() ) { 446 if ( !clear || prevTime.minute() != currTime.minute() ) {
449 // draw minute pointer 447 // draw minute pointer
450 m1 = rotate( center, m1, time.minute() * 6 ); 448 m1 = rotate( center, m1, time.minute() * 6 );
451 m2 = rotate( center, m2, time.minute() * 6 ); 449 m2 = rotate( center, m2, time.minute() * 6 );
452 p->setPen( QPen( color, 2 ) ); 450 p->setPen( QPen( color, 2 ) );
453 p->drawLine( m1, m2 ); 451 p->drawLine( m1, m2 );
454 } 452 }
455 453
456 // draw second pointer 454 // draw second pointer
457 s1 = rotate( center, s1, time.second() * 6 ); 455 s1 = rotate( center, s1, time.second() * 6 );
458 s2 = rotate( center, s2, time.second() * 6 ); 456 s2 = rotate( center, s2, time.second() * 6 );
459 p->setPen( QPen( color, 1 ) ); 457 p->setPen( QPen( color, 1 ) );
460 p->drawLine( s1, s2 ); 458 p->drawLine( s1, s2 );
461 459
462 if ( !clear ) 460 if ( !clear )
463 prevTime = currTime; 461 prevTime = currTime;
464} 462}
465 463
466void AnalogClock::display( const QTime& t ) 464void AnalogClock::display( const QTime& t )
467{ 465{
468 currTime = t; 466 currTime = t;
469 clear = true; 467 clear = true;
470 repaint( false ); 468 repaint( false );
471 clear = false; 469 clear = false;
472 repaint( false ); 470 repaint( false );
473} 471}
474 472
475QPoint AnalogClock::rotate( QPoint c, QPoint p, int a ) 473QPoint AnalogClock::rotate( QPoint c, QPoint p, int a )
476{ 474{
477 double angle = deg2rad * ( - a + 180 ); 475 double angle = deg2rad * ( - a + 180 );
478 double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) - 476 double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) -
479 ( p.y() - c.y() ) * sin( angle ); 477 ( p.y() - c.y() ) * sin( angle );
480 double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) + 478 double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) +
481 ( p.x() - c.x() ) * sin( angle ); 479 ( p.x() - c.x() ) * sin( angle );
482 return QPoint( nx, ny ); 480 return QPoint( nx, ny );
483} 481}
484void Clock::slotAdjustTime()
485{
486 QCopEnvelope e("QPE/System", "execute(QString)");
487 e << QString("systemtime");
488}