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