summaryrefslogtreecommitdiff
authorzecke <zecke>2004-04-04 11:38:52 (UTC)
committer zecke <zecke>2004-04-04 11:38:52 (UTC)
commit321f82bb3d43cbab358434fef52fe76f17e7d1e3 (patch) (unidiff)
tree7a7a25db1b639a95ed5087bd5f90167a38252789
parent56b4b6a658854637f688975874390938260f2afc (diff)
downloadopie-321f82bb3d43cbab358434fef52fe76f17e7d1e3.zip
opie-321f82bb3d43cbab358434fef52fe76f17e7d1e3.tar.gz
opie-321f82bb3d43cbab358434fef52fe76f17e7d1e3.tar.bz2
use alarmbell
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/clock/clock.cpp2
1 files changed, 1 insertions, 1 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp
index ad422a6..e681650 100644
--- a/noncore/tools/clock/clock.cpp
+++ b/noncore/tools/clock/clock.cpp
@@ -1,806 +1,806 @@
1/********************************************************************** 1/**********************************************************************
2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved. 2** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
3** 3**
4** This file is part of the Qtopia Environment. 4** This file is part of the 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// changes added and Copyright (C) by Holger Freyther 2004 21// changes added and Copyright (C) by Holger Freyther 2004
22 22
23#include "clock.h" 23#include "clock.h"
24 24
25#include "analogclock.h" 25#include "analogclock.h"
26 26
27#include <qtabwidget.h> 27#include <qtabwidget.h>
28 28
29#include <opie2/ofiledialog.h> 29#include <opie2/ofiledialog.h>
30 30
31#include <qpe/qpeapplication.h> 31#include <qpe/qpeapplication.h>
32#include <qpe/qcopenvelope_qws.h> 32#include <qpe/qcopenvelope_qws.h>
33#include <qpe/config.h> 33#include <qpe/config.h>
34#include <qpe/timestring.h> 34#include <qpe/timestring.h>
35#include <qpe/alarmserver.h> 35#include <qpe/alarmserver.h>
36#include <qpe/sound.h> 36#include <qpe/sound.h>
37#include <qpe/resource.h> 37#include <qpe/resource.h>
38#include <qsound.h> 38#include <qsound.h>
39#include <qtimer.h> 39#include <qtimer.h>
40 40
41 41
42 42
43#include <qlcdnumber.h> 43#include <qlcdnumber.h>
44#include <qslider.h> 44#include <qslider.h>
45#include <qlabel.h> 45#include <qlabel.h>
46#include <qtimer.h> 46#include <qtimer.h>
47#include <qpushbutton.h> 47#include <qpushbutton.h>
48#include <qtoolbutton.h> 48#include <qtoolbutton.h>
49#include <qpainter.h> 49#include <qpainter.h>
50#include <qmessagebox.h> 50#include <qmessagebox.h>
51#include <qdatetime.h> 51#include <qdatetime.h>
52#include <qspinbox.h> 52#include <qspinbox.h>
53#include <qcombobox.h> 53#include <qcombobox.h>
54#include <qcheckbox.h> 54#include <qcheckbox.h>
55#include <qgroupbox.h> 55#include <qgroupbox.h>
56#include <qlayout.h> 56#include <qlayout.h>
57#include <qhbox.h> 57#include <qhbox.h>
58#include <qlineedit.h> 58#include <qlineedit.h>
59 59
60static const int sw_prec = 2; 60static const int sw_prec = 2;
61static const int magic_daily = 2292922; 61static const int magic_daily = 2292922;
62static const int magic_countdown = 2292923; 62static const int magic_countdown = 2292923;
63static const int magic_snooze = 2292924; 63static const int magic_snooze = 2292924;
64static const int magic_playmp = 2292925; 64static const int magic_playmp = 2292925;
65 65
66#include <math.h> 66#include <math.h>
67#include <unistd.h> 67#include <unistd.h>
68#include <sys/types.h> 68#include <sys/types.h>
69 69
70#include <pthread.h> 70#include <pthread.h>
71 71
72 72
73static void toggleScreenSaver( bool on ) 73static void toggleScreenSaver( bool on )
74{ 74{
75 QCopEnvelope e( "QPE/System", "setScreenSaverMode(int)" ); 75 QCopEnvelope e( "QPE/System", "setScreenSaverMode(int)" );
76 e << ( on ? QPEApplication::Enable : QPEApplication::DisableSuspend ); 76 e << ( on ? QPEApplication::Enable : QPEApplication::DisableSuspend );
77} 77}
78 78
79static void startPlayer() 79static void startPlayer()
80{ 80{
81 Config config( "qpe" ); 81 Config config( "qpe" );
82 config.setGroup( "Time" ); 82 config.setGroup( "Time" );
83 sleep(15); 83 sleep(15);
84 QCopEnvelope e( "QPE/Application/opieplayer", "setDocument(QString)" ); 84 QCopEnvelope e( "QPE/Application/opieplayer", "setDocument(QString)" );
85 e << config.readEntry( "mp3File", "" ); 85 e << config.readEntry( "mp3File", "" );
86} 86}
87 87
88class MySpinBox : public QSpinBox 88class MySpinBox : public QSpinBox
89{ 89{
90public: 90public:
91 QLineEdit *lineEdit() const { 91 QLineEdit *lineEdit() const {
92 return editor(); 92 return editor();
93 } 93 }
94}; 94};
95 95
96// 96//
97// 97//
98// 98//
99AlarmDlg::AlarmDlg(QWidget *parent, const char *name, bool modal, 99AlarmDlg::AlarmDlg(QWidget *parent, const char *name, bool modal,
100 const QString &txt) : 100 const QString &txt) :
101 AlarmDlgBase(parent, name, modal) 101 AlarmDlgBase(parent, name, modal)
102{ 102{
103 setCaption( tr("Clock") ); 103 setCaption( tr("Clock") );
104 pixmap->setPixmap( Resource::loadPixmap("alarmbell") ); 104 pixmap->setPixmap( Resource::loadPixmap("clock/alarmbell") );
105 alarmDlgLabel->setText(txt); 105 alarmDlgLabel->setText(txt);
106 106
107 connect(snoozeTime, SIGNAL(valueChanged(int)), this, 107 connect(snoozeTime, SIGNAL(valueChanged(int)), this,
108 SLOT(changePrompt(int))); 108 SLOT(changePrompt(int)));
109 connect(cmdOk, SIGNAL(clicked()), this, SLOT(checkSnooze())); 109 connect(cmdOk, SIGNAL(clicked()), this, SLOT(checkSnooze()));
110} 110}
111 111
112// 112//
113// 113//
114// 114//
115void 115void
116AlarmDlg::setText(const QString &txt) 116AlarmDlg::setText(const QString &txt)
117{ 117{
118 alarmDlgLabel->setText(txt); 118 alarmDlgLabel->setText(txt);
119} 119}
120 120
121// 121//
122// 122//
123// 123//
124void 124void
125AlarmDlg::checkSnooze(void) 125AlarmDlg::checkSnooze(void)
126{ 126{
127 // 127 //
128 // Ensure we have only one snooze alarm. 128 // Ensure we have only one snooze alarm.
129 // 129 //
130 AlarmServer::deleteAlarm(QDateTime(), "QPE/Application/clock", 130 AlarmServer::deleteAlarm(QDateTime(), "QPE/Application/clock",
131 "alarm(QDateTime,int)", magic_snooze); 131 "alarm(QDateTime,int)", magic_snooze);
132 132
133 if (snoozeTime->value() > 0) { 133 if (snoozeTime->value() > 0) {
134 QDateTime wake = QDateTime::currentDateTime(); 134 QDateTime wake = QDateTime::currentDateTime();
135 wake = wake.addSecs(snoozeTime->value() * 60); // snoozeTime in minutes 135 wake = wake.addSecs(snoozeTime->value() * 60); // snoozeTime in minutes
136 136
137 AlarmServer::addAlarm(wake, "QPE/Application/clock", 137 AlarmServer::addAlarm(wake, "QPE/Application/clock",
138 "alarm(QDateTime,int)", magic_snooze); 138 "alarm(QDateTime,int)", magic_snooze);
139 } 139 }
140 accept(); 140 accept();
141} 141}
142 142
143 143
144 144
145void 145void
146AlarmDlg::changePrompt(int mins) 146AlarmDlg::changePrompt(int mins)
147{ 147{
148 cmdOk->setText(mins > 0 ? tr("Snooze") : tr("Close") ); 148 cmdOk->setText(mins > 0 ? tr("Snooze") : tr("Close") );
149} 149}
150 150
151 151
152 152
153Clock::Clock( QWidget * parent, const char *, WFlags f ) 153Clock::Clock( QWidget * parent, const char *, WFlags f )
154 : ClockBase( parent, "clock", f ), swatch_splitms(99), init(FALSE) // No tr 154 : ClockBase( parent, "clock", f ), swatch_splitms(99), init(FALSE) // No tr
155{ 155{
156 alarmDlg = 0; 156 alarmDlg = 0;
157 swLayout = 0; 157 swLayout = 0;
158 dayBtn = new QToolButton * [7]; 158 dayBtn = new QToolButton * [7];
159 159
160 Config config( "qpe" ); 160 Config config( "qpe" );
161 config.setGroup("Time"); 161 config.setGroup("Time");
162 ampm = config.readBoolEntry( "AMPM", TRUE ); 162 ampm = config.readBoolEntry( "AMPM", TRUE );
163 onMonday = config.readBoolEntry( "MONDAY" ); 163 onMonday = config.readBoolEntry( "MONDAY" );
164 164
165 connect( tabs, SIGNAL(currentChanged(QWidget*)), 165 connect( tabs, SIGNAL(currentChanged(QWidget*)),
166 this, SLOT(tabChanged(QWidget*)) ); 166 this, SLOT(tabChanged(QWidget*)) );
167 167
168 analogStopwatch = new AnalogClock( swFrame ); 168 analogStopwatch = new AnalogClock( swFrame );
169 stopwatchLcd = new QLCDNumber( swFrame ); 169 stopwatchLcd = new QLCDNumber( swFrame );
170 stopwatchLcd->setFrameStyle( QFrame::NoFrame ); 170 stopwatchLcd->setFrameStyle( QFrame::NoFrame );
171 stopwatchLcd->setSegmentStyle( QLCDNumber::Flat ); 171 stopwatchLcd->setSegmentStyle( QLCDNumber::Flat );
172 stopwatchLcd->setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred) ); 172 stopwatchLcd->setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred) );
173 173
174 analogClock->display( QTime::currentTime() ); 174 analogClock->display( QTime::currentTime() );
175 clockLcd->setNumDigits( 5 ); 175 clockLcd->setNumDigits( 5 );
176 clockLcd->setFixedWidth( clockLcd->sizeHint().width() ); 176 clockLcd->setFixedWidth( clockLcd->sizeHint().width() );
177 date->setText( TimeString::dateString( QDate::currentDate(), TimeString::currentDateFormat() ) ); 177 date->setText( TimeString::dateString( QDate::currentDate(), TimeString::currentDateFormat() ) );
178 if ( qApp->desktop()->width() < 200 ) 178 if ( qApp->desktop()->width() < 200 )
179 date->setFont( QFont(date->font().family(), 14, QFont::Bold) ); 179 date->setFont( QFont(date->font().family(), 14, QFont::Bold) );
180 if ( qApp->desktop()->height() > 240 ) { 180 if ( qApp->desktop()->height() > 240 ) {
181 clockLcd->setFixedHeight( 30 ); 181 clockLcd->setFixedHeight( 30 );
182 stopwatchLcd->setFixedHeight( 30 ); 182 stopwatchLcd->setFixedHeight( 30 );
183 } 183 }
184 184
185 connect( stopStart, SIGNAL(pressed()), SLOT(stopStartStopWatch()) ); 185 connect( stopStart, SIGNAL(pressed()), SLOT(stopStartStopWatch()) );
186 connect( reset, SIGNAL(pressed()), SLOT(resetStopWatch()) ); 186 connect( reset, SIGNAL(pressed()), SLOT(resetStopWatch()) );
187 187
188 t = new QTimer( this ); 188 t = new QTimer( this );
189 connect( t, SIGNAL(timeout()), SLOT(updateClock()) ); 189 connect( t, SIGNAL(timeout()), SLOT(updateClock()) );
190 t->start( 1000 ); 190 t->start( 1000 );
191 191
192 applyAlarmTimer = new QTimer( this ); 192 applyAlarmTimer = new QTimer( this );
193 connect( applyAlarmTimer, SIGNAL(timeout()), 193 connect( applyAlarmTimer, SIGNAL(timeout()),
194 this, SLOT(applyDailyAlarm()) ); 194 this, SLOT(applyDailyAlarm()) );
195 195
196 alarmt = new QTimer( this ); 196 alarmt = new QTimer( this );
197 connect( alarmt, SIGNAL(timeout()), SLOT(alarmTimeout()) ); 197 connect( alarmt, SIGNAL(timeout()), SLOT(alarmTimeout()) );
198 198
199 connect( qApp, SIGNAL(timeChanged()), SLOT(updateClock()) ); 199 connect( qApp, SIGNAL(timeChanged()), SLOT(updateClock()) );
200 connect( qApp, SIGNAL(timeChanged()), SLOT(applyDailyAlarm()) ); 200 connect( qApp, SIGNAL(timeChanged()), SLOT(applyDailyAlarm()) );
201 201
202 swatch_running = FALSE; 202 swatch_running = FALSE;
203 swatch_totalms = 0; 203 swatch_totalms = 0;
204 swatch_currLap = 0; 204 swatch_currLap = 0;
205 swatch_dispLap = 0; 205 swatch_dispLap = 0;
206 stopwatchLcd->setNumDigits( 8+1+sw_prec ); 206 stopwatchLcd->setNumDigits( 8+1+sw_prec );
207 stopwatchLcd->display( "00:00:00.00" ); 207 stopwatchLcd->display( "00:00:00.00" );
208 208
209 QVBoxLayout *lvb = new QVBoxLayout( lapFrame ); 209 QVBoxLayout *lvb = new QVBoxLayout( lapFrame );
210 nextLapBtn = new QToolButton( UpArrow, lapFrame ); 210 nextLapBtn = new QToolButton( UpArrow, lapFrame );
211 connect( nextLapBtn, SIGNAL(clicked()), this, SLOT(nextLap()) ); 211 connect( nextLapBtn, SIGNAL(clicked()), this, SLOT(nextLap()) );
212 nextLapBtn->setAccel( Key_Up ); 212 nextLapBtn->setAccel( Key_Up );
213 lvb->addWidget( nextLapBtn ); 213 lvb->addWidget( nextLapBtn );
214 prevLapBtn = new QToolButton( DownArrow, lapFrame ); 214 prevLapBtn = new QToolButton( DownArrow, lapFrame );
215 connect( prevLapBtn, SIGNAL(clicked()), this, SLOT(prevLap()) ); 215 connect( prevLapBtn, SIGNAL(clicked()), this, SLOT(prevLap()) );
216 prevLapBtn->setAccel( Key_Down ); 216 prevLapBtn->setAccel( Key_Down );
217 prevLapBtn->setMinimumWidth( 15 ); 217 prevLapBtn->setMinimumWidth( 15 );
218 lvb->addWidget( prevLapBtn ); 218 lvb->addWidget( prevLapBtn );
219 prevLapBtn->setEnabled( FALSE ); 219 prevLapBtn->setEnabled( FALSE );
220 nextLapBtn->setEnabled( FALSE ); 220 nextLapBtn->setEnabled( FALSE );
221 221
222 reset->setEnabled( FALSE ); 222 reset->setEnabled( FALSE );
223 223
224 lapLcd->setNumDigits( 8+1+sw_prec ); 224 lapLcd->setNumDigits( 8+1+sw_prec );
225 lapLcd->display( "00:00:00.00" ); 225 lapLcd->display( "00:00:00.00" );
226 226
227 splitLcd->setNumDigits( 8+1+sw_prec ); 227 splitLcd->setNumDigits( 8+1+sw_prec );
228 splitLcd->display( "00:00:00.00" ); 228 splitLcd->display( "00:00:00.00" );
229 229
230 lapNumLcd->display( 1 ); 230 lapNumLcd->display( 1 );
231 231
232 lapTimer = new QTimer( this ); 232 lapTimer = new QTimer( this );
233 connect( lapTimer, SIGNAL(timeout()), this, SLOT(lapTimeout()) ); 233 connect( lapTimer, SIGNAL(timeout()), this, SLOT(lapTimeout()) );
234 234
235 for (uint s = 0; s < swatch_splitms.count(); s++ ) 235 for (uint s = 0; s < swatch_splitms.count(); s++ )
236 swatch_splitms[(int)s] = 0; 236 swatch_splitms[(int)s] = 0;
237 237
238 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) ); 238 connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) );
239 239
240 cdGroup->hide(); // XXX implement countdown timer. 240 cdGroup->hide(); // XXX implement countdown timer.
241 241
242 connect( dailyHour, SIGNAL(valueChanged(int)), this, SLOT(scheduleApplyDailyAlarm()) ); 242 connect( dailyHour, SIGNAL(valueChanged(int)), this, SLOT(scheduleApplyDailyAlarm()) );
243 connect( dailyMinute, SIGNAL(valueChanged(int)), this, SLOT(setDailyMinute(int)) ); 243 connect( dailyMinute, SIGNAL(valueChanged(int)), this, SLOT(setDailyMinute(int)) );
244 connect( dailyAmPm, SIGNAL(activated(int)), this, SLOT(setDailyAmPm(int)) ); 244 connect( dailyAmPm, SIGNAL(activated(int)), this, SLOT(setDailyAmPm(int)) );
245 connect( dailyEnabled, SIGNAL(toggled(bool)), this, SLOT(enableDaily(bool)) ); 245 connect( dailyEnabled, SIGNAL(toggled(bool)), this, SLOT(enableDaily(bool)) );
246 cdLcd->display( "00:00" ); 246 cdLcd->display( "00:00" );
247 247
248 dailyMinute->setValidator(0); 248 dailyMinute->setValidator(0);
249 249
250 Config cConfig( "Clock" ); // No tr 250 Config cConfig( "Clock" ); // No tr
251 cConfig.setGroup( "Daily Alarm" ); 251 cConfig.setGroup( "Daily Alarm" );
252 252
253 QStringList days; 253 QStringList days;
254 days.append( tr("Mon", "Monday") ); 254 days.append( tr("Mon", "Monday") );
255 days.append( tr("Tue", "Tuesday") ); 255 days.append( tr("Tue", "Tuesday") );
256 days.append( tr("Wed", "Wednesday") ); 256 days.append( tr("Wed", "Wednesday") );
257 days.append( tr("Thu", "Thursday") ); 257 days.append( tr("Thu", "Thursday") );
258 days.append( tr("Fri", "Friday") ); 258 days.append( tr("Fri", "Friday") );
259 days.append( tr("Sat", "Saturday") ); 259 days.append( tr("Sat", "Saturday") );
260 days.append( tr("Sun", "Sunday") ); 260 days.append( tr("Sun", "Sunday") );
261 261
262 int i; 262 int i;
263 QHBoxLayout *hb = new QHBoxLayout( daysFrame ); 263 QHBoxLayout *hb = new QHBoxLayout( daysFrame );
264 for ( i = 0; i < 7; i++ ) { 264 for ( i = 0; i < 7; i++ ) {
265 dayBtn[i] = new QToolButton( daysFrame ); 265 dayBtn[i] = new QToolButton( daysFrame );
266 hb->addWidget( dayBtn[i] ); 266 hb->addWidget( dayBtn[i] );
267 dayBtn[i]->setToggleButton( TRUE ); 267 dayBtn[i]->setToggleButton( TRUE );
268 dayBtn[i]->setOn( TRUE ); 268 dayBtn[i]->setOn( TRUE );
269 dayBtn[i]->setFocusPolicy( StrongFocus ); 269 dayBtn[i]->setFocusPolicy( StrongFocus );
270 connect( dayBtn[i], SIGNAL(toggled(bool)), this, SLOT(scheduleApplyDailyAlarm()) ); 270 connect( dayBtn[i], SIGNAL(toggled(bool)), this, SLOT(scheduleApplyDailyAlarm()) );
271 } 271 }
272 272
273 for ( i = 0; i < 7; i++ ) 273 for ( i = 0; i < 7; i++ )
274 dayBtn[dayBtnIdx(i+1)]->setText( days[i] ); 274 dayBtn[dayBtnIdx(i+1)]->setText( days[i] );
275 275
276 QStringList exclDays = cConfig.readListEntry( "ExcludeDays", ',' ); 276 QStringList exclDays = cConfig.readListEntry( "ExcludeDays", ',' );
277 QStringList::Iterator it; 277 QStringList::Iterator it;
278 for ( it = exclDays.begin(); it != exclDays.end(); ++it ) { 278 for ( it = exclDays.begin(); it != exclDays.end(); ++it ) {
279 int d = (*it).toInt(); 279 int d = (*it).toInt();
280 if ( d >= 1 && d <= 7 ) 280 if ( d >= 1 && d <= 7 )
281 dayBtn[dayBtnIdx(d)]->setOn( FALSE ); 281 dayBtn[dayBtnIdx(d)]->setOn( FALSE );
282 } 282 }
283 283
284 bool alarm = cConfig.readBoolEntry("Enabled", FALSE); 284 bool alarm = cConfig.readBoolEntry("Enabled", FALSE);
285 bool sound = cConfig.readBoolEntry("SoundEnabled", FALSE ); 285 bool sound = cConfig.readBoolEntry("SoundEnabled", FALSE );
286 dailyEnabled->setChecked( alarm ); 286 dailyEnabled->setChecked( alarm );
287 sndGroup->setEnabled( alarm ); 287 sndGroup->setEnabled( alarm );
288 sndCheck->setChecked( sound ); 288 sndCheck->setChecked( sound );
289 sndChoose->setEnabled( sound ); 289 sndChoose->setEnabled( sound );
290 sndFileName->setEnabled( sound ); 290 sndFileName->setEnabled( sound );
291 291
292 // FIXME ODP migrate to own config class.. merge config options 292 // FIXME ODP migrate to own config class.. merge config options
293 Config cfg_qpe( "qpe" ); 293 Config cfg_qpe( "qpe" );
294 cfg_qpe.setGroup( "Time" ); 294 cfg_qpe.setGroup( "Time" );
295 sndFileName->setText( cfg_qpe.readEntry( "mp3File" ) ); 295 sndFileName->setText( cfg_qpe.readEntry( "mp3File" ) );
296 // 296 //
297 297
298 int m = cConfig.readNumEntry( "Minute", 0 ); 298 int m = cConfig.readNumEntry( "Minute", 0 );
299 dailyMinute->setValue( m ); 299 dailyMinute->setValue( m );
300// dailyMinute->setPrefix( m <= 9 ? "0" : "" ); 300// dailyMinute->setPrefix( m <= 9 ? "0" : "" );
301 int h = cConfig.readNumEntry( "Hour", 7 ); 301 int h = cConfig.readNumEntry( "Hour", 7 );
302 if ( ampm ) { 302 if ( ampm ) {
303 if (h > 12) { 303 if (h > 12) {
304 h -= 12; 304 h -= 12;
305 dailyAmPm->setCurrentItem( 1 ); 305 dailyAmPm->setCurrentItem( 1 );
306 } 306 }
307 if (h == 0) h = 12; 307 if (h == 0) h = 12;
308 dailyHour->setMinValue( 1 ); 308 dailyHour->setMinValue( 1 );
309 dailyHour->setMaxValue( 12 ); 309 dailyHour->setMaxValue( 12 );
310 } else { 310 } else {
311 dailyAmPm->hide(); 311 dailyAmPm->hide();
312 } 312 }
313 dailyHour->setValue( h ); 313 dailyHour->setValue( h );
314 314
315 connect( ((MySpinBox*)dailyHour)->lineEdit(), SIGNAL(textChanged(const QString&)), 315 connect( ((MySpinBox*)dailyHour)->lineEdit(), SIGNAL(textChanged(const QString&)),
316 this, SLOT(dailyEdited()) ); 316 this, SLOT(dailyEdited()) );
317 connect( ((MySpinBox*)dailyMinute)->lineEdit(), SIGNAL(textChanged(const QString&)), 317 connect( ((MySpinBox*)dailyMinute)->lineEdit(), SIGNAL(textChanged(const QString&)),
318 this, SLOT(dailyEdited()) ); 318 this, SLOT(dailyEdited()) );
319 319
320#if defined(Q_WS_QWS) && !defined(QT_NO_COP) 320#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
321 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)), 321 connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)),
322 this, SLOT(appMessage(const QCString&,const QByteArray&)) ); 322 this, SLOT(appMessage(const QCString&,const QByteArray&)) );
323#endif 323#endif
324 324
325 QTimer::singleShot( 0, this, SLOT(updateClock()) ); 325 QTimer::singleShot( 0, this, SLOT(updateClock()) );
326 swFrame->installEventFilter( this ); 326 swFrame->installEventFilter( this );
327 327
328 init = TRUE; 328 init = TRUE;
329} 329}
330 330
331Clock::~Clock() 331Clock::~Clock()
332{ 332{
333 toggleScreenSaver( true ); 333 toggleScreenSaver( true );
334 delete [] dayBtn; 334 delete [] dayBtn;
335} 335}
336 336
337void Clock::updateClock() 337void Clock::updateClock()
338{ 338{
339 if ( tabs->currentPageIndex() == 0 ) { 339 if ( tabs->currentPageIndex() == 0 ) {
340 QTime tm = QDateTime::currentDateTime().time(); 340 QTime tm = QDateTime::currentDateTime().time();
341 QString s; 341 QString s;
342 if ( ampm ) { 342 if ( ampm ) {
343 int hour = tm.hour(); 343 int hour = tm.hour();
344 if (hour == 0) 344 if (hour == 0)
345 hour = 12; 345 hour = 12;
346 if (hour > 12) 346 if (hour > 12)
347 hour -= 12; 347 hour -= 12;
348 s.sprintf( "%2d%c%02d", hour, ':', tm.minute() ); 348 s.sprintf( "%2d%c%02d", hour, ':', tm.minute() );
349 clockAmPm->setText( (tm.hour() >= 12) ? "PM" : "AM" ); 349 clockAmPm->setText( (tm.hour() >= 12) ? "PM" : "AM" );
350 clockAmPm->show(); 350 clockAmPm->show();
351 } else { 351 } else {
352 s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() ); 352 s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() );
353 clockAmPm->hide(); 353 clockAmPm->hide();
354 } 354 }
355 clockLcd->display( s ); 355 clockLcd->display( s );
356 clockLcd->repaint( FALSE ); 356 clockLcd->repaint( FALSE );
357 analogClock->display( QTime::currentTime() ); 357 analogClock->display( QTime::currentTime() );
358 date->setText( TimeString::dateString( QDate::currentDate(), TimeString::currentDateFormat() ) ); 358 date->setText( TimeString::dateString( QDate::currentDate(), TimeString::currentDateFormat() ) );
359 } else if ( tabs->currentPageIndex() == 1 ) { 359 } else if ( tabs->currentPageIndex() == 1 ) {
360 int totalms = swatch_totalms; 360 int totalms = swatch_totalms;
361 if ( swatch_running ) 361 if ( swatch_running )
362 totalms += swatch_start.elapsed(); 362 totalms += swatch_start.elapsed();
363 setSwatchLcd( stopwatchLcd, totalms, !swatch_running ); 363 setSwatchLcd( stopwatchLcd, totalms, !swatch_running );
364 QTime swatch_time = QTime(0,0,0).addMSecs(totalms); 364 QTime swatch_time = QTime(0,0,0).addMSecs(totalms);
365 analogStopwatch->display( swatch_time ); 365 analogStopwatch->display( swatch_time );
366 if ( swatch_dispLap == swatch_currLap ) { 366 if ( swatch_dispLap == swatch_currLap ) {
367 swatch_splitms[swatch_currLap] = swatch_totalms; 367 swatch_splitms[swatch_currLap] = swatch_totalms;
368 if ( swatch_running ) 368 if ( swatch_running )
369 swatch_splitms[swatch_currLap] += swatch_start.elapsed(); 369 swatch_splitms[swatch_currLap] += swatch_start.elapsed();
370 updateLap(); 370 updateLap();
371 } 371 }
372 } else if ( tabs->currentPageIndex() == 2 ) { 372 } else if ( tabs->currentPageIndex() == 2 ) {
373 // nothing. 373 // nothing.
374 } 374 }
375} 375}
376 376
377void Clock::changeClock( bool a ) 377void Clock::changeClock( bool a )
378{ 378{
379 if ( ampm != a ) { 379 if ( ampm != a ) {
380 int minute = dailyMinute->value(); 380 int minute = dailyMinute->value();
381 int hour = dailyHour->value(); 381 int hour = dailyHour->value();
382 if ( ampm ) { 382 if ( ampm ) {
383 if (hour == 12) 383 if (hour == 12)
384 hour = 0; 384 hour = 0;
385 if (dailyAmPm->currentItem() == 1 ) 385 if (dailyAmPm->currentItem() == 1 )
386 hour += 12; 386 hour += 12;
387 dailyHour->setMinValue( 0 ); 387 dailyHour->setMinValue( 0 );
388 dailyHour->setMaxValue( 23 ); 388 dailyHour->setMaxValue( 23 );
389 dailyAmPm->hide(); 389 dailyAmPm->hide();
390 } else { 390 } else {
391 if (hour > 12) { 391 if (hour > 12) {
392 hour -= 12; 392 hour -= 12;
393 dailyAmPm->setCurrentItem( 1 ); 393 dailyAmPm->setCurrentItem( 1 );
394 } 394 }
395 if (hour == 0) hour = 12; 395 if (hour == 0) hour = 12;
396 dailyHour->setMinValue( 1 ); 396 dailyHour->setMinValue( 1 );
397 dailyHour->setMaxValue( 12 ); 397 dailyHour->setMaxValue( 12 );
398 dailyAmPm->show(); 398 dailyAmPm->show();
399 } 399 }
400 dailyMinute->setValue( minute ); 400 dailyMinute->setValue( minute );
401 dailyHour->setValue( hour ); 401 dailyHour->setValue( hour );
402 } 402 }
403 ampm = a; 403 ampm = a;
404 updateClock(); 404 updateClock();
405} 405}
406 406
407void Clock::stopStartStopWatch() 407void Clock::stopStartStopWatch()
408{ 408{
409 if ( swatch_running ) { 409 if ( swatch_running ) {
410 swatch_totalms += swatch_start.elapsed(); 410 swatch_totalms += swatch_start.elapsed();
411 swatch_splitms[swatch_currLap] = swatch_totalms; 411 swatch_splitms[swatch_currLap] = swatch_totalms;
412 stopStart->setText( tr("Start") ); 412 stopStart->setText( tr("Start") );
413 reset->setText( tr("Reset") ); 413 reset->setText( tr("Reset") );
414 reset->setEnabled( TRUE ); 414 reset->setEnabled( TRUE );
415 t->stop(); 415 t->stop();
416 swatch_running = FALSE; 416 swatch_running = FALSE;
417 toggleScreenSaver( TRUE ); 417 toggleScreenSaver( TRUE );
418 updateClock(); 418 updateClock();
419 } else { 419 } else {
420 swatch_start.start(); 420 swatch_start.start();
421 stopStart->setText( tr("Stop") ); 421 stopStart->setText( tr("Stop") );
422 reset->setText( tr("Lap/Split") ); 422 reset->setText( tr("Lap/Split") );
423 reset->setEnabled( swatch_currLap < 98 ); 423 reset->setEnabled( swatch_currLap < 98 );
424 t->start( 1000 ); 424 t->start( 1000 );
425 swatch_running = TRUE; 425 swatch_running = TRUE;
426 // disable screensaver while stop watch is running 426 // disable screensaver while stop watch is running
427 toggleScreenSaver( FALSE ); 427 toggleScreenSaver( FALSE );
428 } 428 }
429 swatch_dispLap = swatch_currLap; 429 swatch_dispLap = swatch_currLap;
430 updateLap(); 430 updateLap();
431 prevLapBtn->setEnabled( swatch_dispLap ); 431 prevLapBtn->setEnabled( swatch_dispLap );
432 nextLapBtn->setEnabled( swatch_dispLap < swatch_currLap ); 432 nextLapBtn->setEnabled( swatch_dispLap < swatch_currLap );
433 stopStart->setAccel( Key_Return ); 433 stopStart->setAccel( Key_Return );
434} 434}
435 435
436void Clock::resetStopWatch() 436void Clock::resetStopWatch()
437{ 437{
438 if ( swatch_running ) { 438 if ( swatch_running ) {
439 swatch_splitms[swatch_currLap] = swatch_totalms+swatch_start.elapsed(); 439 swatch_splitms[swatch_currLap] = swatch_totalms+swatch_start.elapsed();
440 swatch_dispLap = swatch_currLap; 440 swatch_dispLap = swatch_currLap;
441 if ( swatch_currLap < 98 ) // allow up to 99 laps 441 if ( swatch_currLap < 98 ) // allow up to 99 laps
442 swatch_currLap++; 442 swatch_currLap++;
443 reset->setEnabled( swatch_currLap < 98 ); 443 reset->setEnabled( swatch_currLap < 98 );
444 updateLap(); 444 updateLap();
445 lapTimer->start( 2000, TRUE ); 445 lapTimer->start( 2000, TRUE );
446 } else { 446 } else {
447 swatch_start.start(); 447 swatch_start.start();
448 swatch_totalms = 0; 448 swatch_totalms = 0;
449 swatch_currLap = 0; 449 swatch_currLap = 0;
450 swatch_dispLap = 0; 450 swatch_dispLap = 0;
451 for ( uint i = 0; i < swatch_splitms.count(); i++ ) 451 for ( uint i = 0; i < swatch_splitms.count(); i++ )
452 swatch_splitms[(int)i] = 0; 452 swatch_splitms[(int)i] = 0;
453 updateLap(); 453 updateLap();
454 updateClock(); 454 updateClock();
455 reset->setText( tr("Lap/Split") ); 455 reset->setText( tr("Lap/Split") );
456 reset->setEnabled( FALSE ); 456 reset->setEnabled( FALSE );
457 } 457 }
458 prevLapBtn->setEnabled( swatch_dispLap ); 458 prevLapBtn->setEnabled( swatch_dispLap );
459 nextLapBtn->setEnabled( swatch_dispLap < swatch_currLap ); 459 nextLapBtn->setEnabled( swatch_dispLap < swatch_currLap );
460} 460}
461 461
462void Clock::prevLap() 462void Clock::prevLap()
463{ 463{
464 if ( swatch_dispLap > 0 ) { 464 if ( swatch_dispLap > 0 ) {
465 swatch_dispLap--; 465 swatch_dispLap--;
466 updateLap(); 466 updateLap();
467 prevLapBtn->setEnabled( swatch_dispLap ); 467 prevLapBtn->setEnabled( swatch_dispLap );
468 nextLapBtn->setEnabled( swatch_dispLap < swatch_currLap ); 468 nextLapBtn->setEnabled( swatch_dispLap < swatch_currLap );
469 } 469 }
470} 470}
471 471
472void Clock::nextLap() 472void Clock::nextLap()
473{ 473{
474 if ( swatch_dispLap < swatch_currLap ) { 474 if ( swatch_dispLap < swatch_currLap ) {
475 swatch_dispLap++; 475 swatch_dispLap++;
476 updateLap(); 476 updateLap();
477 prevLapBtn->setEnabled( swatch_dispLap ); 477 prevLapBtn->setEnabled( swatch_dispLap );
478 nextLapBtn->setEnabled( swatch_dispLap < swatch_currLap ); 478 nextLapBtn->setEnabled( swatch_dispLap < swatch_currLap );
479 } 479 }
480} 480}
481 481
482void Clock::lapTimeout() 482void Clock::lapTimeout()
483{ 483{
484 swatch_dispLap = swatch_currLap; 484 swatch_dispLap = swatch_currLap;
485 updateLap(); 485 updateLap();
486 prevLapBtn->setEnabled( swatch_dispLap ); 486 prevLapBtn->setEnabled( swatch_dispLap );
487 nextLapBtn->setEnabled( swatch_dispLap < swatch_currLap ); 487 nextLapBtn->setEnabled( swatch_dispLap < swatch_currLap );
488} 488}
489 489
490void Clock::updateLap() 490void Clock::updateLap()
491{ 491{
492 if ( swatch_running && swatch_currLap == swatch_dispLap ) { 492 if ( swatch_running && swatch_currLap == swatch_dispLap ) {
493 swatch_splitms[swatch_currLap] = swatch_totalms; 493 swatch_splitms[swatch_currLap] = swatch_totalms;
494 swatch_splitms[swatch_currLap] += swatch_start.elapsed(); 494 swatch_splitms[swatch_currLap] += swatch_start.elapsed();
495 } 495 }
496 int split = swatch_splitms[swatch_dispLap]; 496 int split = swatch_splitms[swatch_dispLap];
497 int lap; 497 int lap;
498 if ( swatch_dispLap > 0 ) 498 if ( swatch_dispLap > 0 )
499 lap = swatch_splitms[swatch_dispLap] - swatch_splitms[swatch_dispLap-1]; 499 lap = swatch_splitms[swatch_dispLap] - swatch_splitms[swatch_dispLap-1];
500 else 500 else
501 lap = swatch_splitms[swatch_dispLap]; 501 lap = swatch_splitms[swatch_dispLap];
502 502
503 lapNumLcd->display( swatch_dispLap+1 ); 503 lapNumLcd->display( swatch_dispLap+1 );
504 bool showMs = !swatch_running || swatch_dispLap!=swatch_currLap; 504 bool showMs = !swatch_running || swatch_dispLap!=swatch_currLap;
505 setSwatchLcd( lapLcd, lap, showMs ); 505 setSwatchLcd( lapLcd, lap, showMs );
506 setSwatchLcd( splitLcd, split, showMs ); 506 setSwatchLcd( splitLcd, split, showMs );
507} 507}
508 508
509void Clock::setSwatchLcd( QLCDNumber *lcd, int ms, bool showMs ) 509void Clock::setSwatchLcd( QLCDNumber *lcd, int ms, bool showMs )
510{ 510{
511 QTime swatch_time = QTime(0,0,0).addMSecs(ms); 511 QTime swatch_time = QTime(0,0,0).addMSecs(ms);
512 QString d = showMs ? QString::number(ms%1000+1000) : QString(" "); 512 QString d = showMs ? QString::number(ms%1000+1000) : QString(" ");
513 QString lcdtext = swatch_time.toString() + "." + d.right(3).left(sw_prec); 513 QString lcdtext = swatch_time.toString() + "." + d.right(3).left(sw_prec);
514 lcd->display( lcdtext ); 514 lcd->display( lcdtext );
515 lcd->repaint( FALSE ); 515 lcd->repaint( FALSE );
516} 516}
517 517
518bool Clock::eventFilter( QObject *o, QEvent *e ) 518bool Clock::eventFilter( QObject *o, QEvent *e )
519{ 519{
520 if ( o == swFrame && e->type() == QEvent::Resize ) { 520 if ( o == swFrame && e->type() == QEvent::Resize ) {
521 QResizeEvent *re = (QResizeEvent *)e; 521 QResizeEvent *re = (QResizeEvent *)e;
522 delete swLayout; 522 delete swLayout;
523 if ( re->size().height() < 80 || re->size().height()*3 < re->size().width() ) 523 if ( re->size().height() < 80 || re->size().height()*3 < re->size().width() )
524 swLayout = new QHBoxLayout( swFrame ); 524 swLayout = new QHBoxLayout( swFrame );
525 else 525 else
526 swLayout = new QVBoxLayout( swFrame ); 526 swLayout = new QVBoxLayout( swFrame );
527 swLayout->addWidget( analogStopwatch ); 527 swLayout->addWidget( analogStopwatch );
528 swLayout->addWidget( stopwatchLcd ); 528 swLayout->addWidget( stopwatchLcd );
529 swLayout->activate(); 529 swLayout->activate();
530 } 530 }
531 531
532 return FALSE; 532 return FALSE;
533} 533}
534 534
535void Clock::tabChanged( QWidget * ) 535void Clock::tabChanged( QWidget * )
536{ 536{
537 if ( tabs->currentPageIndex() == 0 ) { 537 if ( tabs->currentPageIndex() == 0 ) {
538 t->start(1000); 538 t->start(1000);
539 } else if ( tabs->currentPageIndex() == 1 ) { 539 } else if ( tabs->currentPageIndex() == 1 ) {
540 if ( !swatch_running ) 540 if ( !swatch_running )
541 t->stop(); 541 t->stop();
542 stopStart->setAccel( Key_Return ); 542 stopStart->setAccel( Key_Return );
543 } else if ( tabs->currentPageIndex() == 2 ) { 543 } else if ( tabs->currentPageIndex() == 2 ) {
544 t->start(1000); 544 t->start(1000);
545 } 545 }
546 updateClock(); 546 updateClock();
547} 547}
548 548
549void Clock::setDailyAmPm(int) 549void Clock::setDailyAmPm(int)
550{ 550{
551 scheduleApplyDailyAlarm(); 551 scheduleApplyDailyAlarm();
552} 552}
553 553
554void Clock::setDailyMinute( int m ) 554void Clock::setDailyMinute( int m )
555{ 555{
556 dailyMinute->setPrefix( m <= 9 ? "0" : "" ); 556 dailyMinute->setPrefix( m <= 9 ? "0" : "" );
557} 557}
558 558
559void Clock::dailyEdited() 559void Clock::dailyEdited()
560{ 560{
561 if ( spinBoxValid(dailyMinute) && spinBoxValid(dailyHour) ) 561 if ( spinBoxValid(dailyMinute) && spinBoxValid(dailyHour) )
562 scheduleApplyDailyAlarm(); 562 scheduleApplyDailyAlarm();
563 else 563 else
564 applyAlarmTimer->stop(); 564 applyAlarmTimer->stop();
565} 565}
566 566
567void Clock::enableDaily( bool ) 567void Clock::enableDaily( bool )
568{ 568{
569 scheduleApplyDailyAlarm(); 569 scheduleApplyDailyAlarm();
570} 570}
571 571
572void Clock::appMessage( const QCString &msg, const QByteArray &data ) 572void Clock::appMessage( const QCString &msg, const QByteArray &data )
573{ 573{
574 if ( msg == "alarm(QDateTime,int)" ) { 574 if ( msg == "alarm(QDateTime,int)" ) {
575 QDataStream ds(data,IO_ReadOnly); 575 QDataStream ds(data,IO_ReadOnly);
576 QDateTime when; 576 QDateTime when;
577 int t; 577 int t;
578 ds >> when >> t; 578 ds >> when >> t;
579 QTime theTime( when.time() ); 579 QTime theTime( when.time() );
580 if ( t == magic_daily || t == magic_snooze || 580 if ( t == magic_daily || t == magic_snooze ||
581 t == magic_playmp ) { 581 t == magic_playmp ) {
582 QString msg = tr("<b>Daily Alarm:</b><p>"); 582 QString msg = tr("<b>Daily Alarm:</b><p>");
583 QString ts; 583 QString ts;
584 if ( ampm ) { 584 if ( ampm ) {
585 bool pm = FALSE; 585 bool pm = FALSE;
586 int h = theTime.hour(); 586 int h = theTime.hour();
587 if (h > 12) { 587 if (h > 12) {
588 h -= 12; 588 h -= 12;
589 pm = TRUE; 589 pm = TRUE;
590 } 590 }
591 if (h == 0) h = 12; 591 if (h == 0) h = 12;
592 ts.sprintf( "%02d:%02d %s", h, theTime.minute(), pm?"PM":"AM" ); 592 ts.sprintf( "%02d:%02d %s", h, theTime.minute(), pm?"PM":"AM" );
593 } else { 593 } else {
594 ts.sprintf( "%02d:%02d", theTime.hour(), theTime.minute() ); 594 ts.sprintf( "%02d:%02d", theTime.hour(), theTime.minute() );
595 } 595 }
596 msg += ts; 596 msg += ts;
597 597
598 if (t == magic_playmp ) { 598 if (t == magic_playmp ) {
599 pthread_t thread; 599 pthread_t thread;
600 pthread_create(&thread,NULL, (void * (*) (void *))startPlayer, NULL/* &*/ ); 600 pthread_create(&thread,NULL, (void * (*) (void *))startPlayer, NULL/* &*/ );
601 }else { 601 }else {
602 Sound::soundAlarm(); 602 Sound::soundAlarm();
603 alarmCount = 0; 603 alarmCount = 0;
604 alarmt->start( 5000 ); 604 alarmt->start( 5000 );
605 } 605 }
606 if ( !alarmDlg ) { 606 if ( !alarmDlg ) {
607 alarmDlg = new AlarmDlg(this); 607 alarmDlg = new AlarmDlg(this);
608 } 608 }
609 alarmDlg->setText(msg); 609 alarmDlg->setText(msg);
610 610
611 // Set for tomorrow, so user wakes up every day, even if they 611 // Set for tomorrow, so user wakes up every day, even if they
612 // don't confirm the dialog. Don't set it again when snoozing. 612 // don't confirm the dialog. Don't set it again when snoozing.
613 if (t != magic_snooze) { 613 if (t != magic_snooze) {
614 applyDailyAlarm(); 614 applyDailyAlarm();
615 } 615 }
616 616
617 617
618 if ( !alarmDlg->isVisible() ) { 618 if ( !alarmDlg->isVisible() ) {
619 QPEApplication::execDialog(alarmDlg); 619 QPEApplication::execDialog(alarmDlg);
620 alarmt->stop(); 620 alarmt->stop();
621 } 621 }
622 } else if ( t == magic_countdown ) { 622 } else if ( t == magic_countdown ) {
623 // countdown 623 // countdown
624 Sound::soundAlarm(); 624 Sound::soundAlarm();
625 } 625 }
626 } else if ( msg == "setDailyEnabled(int)" ) { 626 } else if ( msg == "setDailyEnabled(int)" ) {
627 QDataStream ds(data,IO_ReadOnly); 627 QDataStream ds(data,IO_ReadOnly);
628 int enableDaily; 628 int enableDaily;
629 ds >> enableDaily; 629 ds >> enableDaily;
630 dailyEnabled->setChecked( enableDaily ); 630 dailyEnabled->setChecked( enableDaily );
631 applyDailyAlarm(); 631 applyDailyAlarm();
632 } else if ( msg == "editDailyAlarm()" ) { 632 } else if ( msg == "editDailyAlarm()" ) {
633 tabs->setCurrentPage(2); 633 tabs->setCurrentPage(2);
634 QPEApplication::setKeepRunning(); 634 QPEApplication::setKeepRunning();
635 } else if (msg == "showClock()") { 635 } else if (msg == "showClock()") {
636 tabs->setCurrentPage(0); 636 tabs->setCurrentPage(0);
637 QPEApplication::setKeepRunning(); 637 QPEApplication::setKeepRunning();
638 } else if (msg == "timerStart()" ) { 638 } else if (msg == "timerStart()" ) {
639 if ( !swatch_running ) 639 if ( !swatch_running )
640 stopStartStopWatch(); 640 stopStartStopWatch();
641 tabs->setCurrentPage(1); 641 tabs->setCurrentPage(1);
642 QPEApplication::setKeepRunning(); 642 QPEApplication::setKeepRunning();
643 } else if (msg == "timerStop()" ) { 643 } else if (msg == "timerStop()" ) {
644 if ( swatch_running ) 644 if ( swatch_running )
645 stopStartStopWatch(); 645 stopStartStopWatch();
646 tabs->setCurrentPage(1); 646 tabs->setCurrentPage(1);
647 QPEApplication::setKeepRunning(); 647 QPEApplication::setKeepRunning();
648 } else if (msg == "timerReset()" ) { 648 } else if (msg == "timerReset()" ) {
649 resetStopWatch(); 649 resetStopWatch();
650 tabs->setCurrentPage(1); 650 tabs->setCurrentPage(1);
651 QPEApplication::setKeepRunning(); 651 QPEApplication::setKeepRunning();
652 } 652 }
653} 653}
654 654
655void Clock::alarmTimeout() 655void Clock::alarmTimeout()
656{ 656{
657 if ( alarmCount < 10 ) { 657 if ( alarmCount < 10 ) {
658 Sound::soundAlarm(); 658 Sound::soundAlarm();
659 alarmCount++; 659 alarmCount++;
660 } else { 660 } else {
661 alarmCount = 0; 661 alarmCount = 0;
662 alarmt->stop(); 662 alarmt->stop();
663 } 663 }
664} 664}
665 665
666QDateTime Clock::nextAlarm( int h, int m ) 666QDateTime Clock::nextAlarm( int h, int m )
667{ 667{
668 QDateTime now = QDateTime::currentDateTime(); 668 QDateTime now = QDateTime::currentDateTime();
669 QTime at( h, m ); 669 QTime at( h, m );
670 QDateTime when( now.date(), at ); 670 QDateTime when( now.date(), at );
671 int count = 0; 671 int count = 0;
672 int dow = when.date().dayOfWeek(); 672 int dow = when.date().dayOfWeek();
673 while ( when < now || !dayBtn[dayBtnIdx(dow)]->isOn() ) { 673 while ( when < now || !dayBtn[dayBtnIdx(dow)]->isOn() ) {
674 when = when.addDays( 1 ); 674 when = when.addDays( 1 );
675 dow = when.date().dayOfWeek(); 675 dow = when.date().dayOfWeek();
676 if ( ++count > 7 ) 676 if ( ++count > 7 )
677 return QDateTime(); 677 return QDateTime();
678 } 678 }
679 679
680 return when; 680 return when;
681} 681}
682 682
683int Clock::dayBtnIdx( int d ) const 683int Clock::dayBtnIdx( int d ) const
684{ 684{
685 if ( onMonday ) 685 if ( onMonday )
686 return d-1; 686 return d-1;
687 else if ( d == 7 ) 687 else if ( d == 7 )
688 return 0; 688 return 0;
689 else 689 else
690 return d; 690 return d;
691} 691}
692 692
693void Clock::scheduleApplyDailyAlarm() 693void Clock::scheduleApplyDailyAlarm()
694{ 694{
695 applyAlarmTimer->start( 5000, TRUE ); 695 applyAlarmTimer->start( 5000, TRUE );
696} 696}
697 697
698void Clock::applyDailyAlarm() 698void Clock::applyDailyAlarm()
699{ 699{
700 if ( !init ) 700 if ( !init )
701 return; 701 return;
702 702
703 applyAlarmTimer->stop(); 703 applyAlarmTimer->stop();
704 int minute = dailyMinute->value(); 704 int minute = dailyMinute->value();
705 int hour = dailyHour->value(); 705 int hour = dailyHour->value();
706 if ( ampm ) { 706 if ( ampm ) {
707 if (hour == 12) 707 if (hour == 12)
708 hour = 0; 708 hour = 0;
709 if (dailyAmPm->currentItem() == 1 ) 709 if (dailyAmPm->currentItem() == 1 )
710 hour += 12; 710 hour += 12;
711 } 711 }
712 712
713 Config config( "Clock" ); 713 Config config( "Clock" );
714 config.setGroup( "Daily Alarm" ); 714 config.setGroup( "Daily Alarm" );
715 config.writeEntry( "Hour", hour ); 715 config.writeEntry( "Hour", hour );
716 config.writeEntry( "Minute", minute ); 716 config.writeEntry( "Minute", minute );
717 717
718 bool enableDaily = dailyEnabled->isChecked(); 718 bool enableDaily = dailyEnabled->isChecked();
719 bool wasSound = config.readEntry( "SoundEnabled" ); 719 bool wasSound = config.readEntry( "SoundEnabled" );
720 bool isSound = sndCheck->isChecked(); 720 bool isSound = sndCheck->isChecked();
721 int oldMagic = wasSound ? magic_playmp : magic_daily; 721 int oldMagic = wasSound ? magic_playmp : magic_daily;
722 int isMagic = isSound ? magic_playmp : magic_daily; 722 int isMagic = isSound ? magic_playmp : magic_daily;
723 config.writeEntry( "Enabled", enableDaily ); 723 config.writeEntry( "Enabled", enableDaily );
724 config.writeEntry( "SoundEnabled", isSound ); 724 config.writeEntry( "SoundEnabled", isSound );
725 725
726 QString exclDays; 726 QString exclDays;
727 int exclCount = 0; 727 int exclCount = 0;
728 for ( int i = 1; i <= 7; i++ ) { 728 for ( int i = 1; i <= 7; i++ ) {
729 if ( !dayBtn[dayBtnIdx(i)]->isOn() ) { 729 if ( !dayBtn[dayBtnIdx(i)]->isOn() ) {
730 if ( !exclDays.isEmpty() ) 730 if ( !exclDays.isEmpty() )
731 exclDays += ","; 731 exclDays += ",";
732 exclDays += QString::number( i ); 732 exclDays += QString::number( i );
733 exclCount++; 733 exclCount++;
734 } 734 }
735 } 735 }
736 config.writeEntry( "ExcludeDays", exclDays ); 736 config.writeEntry( "ExcludeDays", exclDays );
737 737
738 /* try to delete both */ 738 /* try to delete both */
739 AlarmServer::deleteAlarm(QDateTime(), "QPE/Application/clock", 739 AlarmServer::deleteAlarm(QDateTime(), "QPE/Application/clock",
740 "alarm(QDateTime,int)", oldMagic); 740 "alarm(QDateTime,int)", oldMagic);
741 if ( enableDaily && exclCount < 7 ) { 741 if ( enableDaily && exclCount < 7 ) {
742 QDateTime when = nextAlarm( hour, minute ); 742 QDateTime when = nextAlarm( hour, minute );
743 AlarmServer::addAlarm(when, "QPE/Application/clock", 743 AlarmServer::addAlarm(when, "QPE/Application/clock",
744 "alarm(QDateTime,int)", isMagic); 744 "alarm(QDateTime,int)", isMagic);
745 } 745 }
746} 746}
747 747
748bool Clock::validDaysSelected(void) 748bool Clock::validDaysSelected(void)
749{ 749{
750 for ( int i = 1; i <= 7; i++ ) { 750 for ( int i = 1; i <= 7; i++ ) {
751 if ( dayBtn[dayBtnIdx(i)]->isOn() ) { 751 if ( dayBtn[dayBtnIdx(i)]->isOn() ) {
752 return TRUE; 752 return TRUE;
753 } 753 }
754 } 754 }
755 return FALSE; 755 return FALSE;
756} 756}
757 757
758void Clock::closeEvent( QCloseEvent *e ) 758void Clock::closeEvent( QCloseEvent *e )
759{ 759{
760 if (dailyEnabled->isChecked()) { 760 if (dailyEnabled->isChecked()) {
761 if (!validDaysSelected()) { 761 if (!validDaysSelected()) {
762 QMessageBox::warning(this, tr("Select Day"), 762 QMessageBox::warning(this, tr("Select Day"),
763 tr("Daily alarm requires at least\none day to be selected.")); 763 tr("Daily alarm requires at least\none day to be selected."));
764 return; 764 return;
765 } 765 }
766 } 766 }
767 767
768 applyDailyAlarm(); 768 applyDailyAlarm();
769 ClockBase::closeEvent(e); 769 ClockBase::closeEvent(e);
770} 770}
771 771
772bool Clock::spinBoxValid( QSpinBox *sb ) 772bool Clock::spinBoxValid( QSpinBox *sb )
773{ 773{
774 bool valid = TRUE; 774 bool valid = TRUE;
775 QString tv = sb->text(); 775 QString tv = sb->text();
776 for ( uint i = 0; i < tv.length(); i++ ) { 776 for ( uint i = 0; i < tv.length(); i++ ) {
777 if ( !tv[0].isDigit() ) 777 if ( !tv[0].isDigit() )
778 valid = FALSE; 778 valid = FALSE;
779 } 779 }
780 bool ok = FALSE; 780 bool ok = FALSE;
781 int v = tv.toInt( &ok ); 781 int v = tv.toInt( &ok );
782 if ( !ok ) 782 if ( !ok )
783 valid = FALSE; 783 valid = FALSE;
784 if ( v < sb->minValue() || v > sb->maxValue() ) 784 if ( v < sb->minValue() || v > sb->maxValue() )
785 valid = FALSE; 785 valid = FALSE;
786 786
787 return valid; 787 return valid;
788} 788}
789 789
790void Clock::slotBrowseMp3File() { 790void Clock::slotBrowseMp3File() {
791 Config config( "qpe" ); 791 Config config( "qpe" );
792 config.setGroup("Time"); 792 config.setGroup("Time");
793 793
794 QMap<QString, QStringList> map; 794 QMap<QString, QStringList> map;
795 map.insert(tr("All"), QStringList() ); 795 map.insert(tr("All"), QStringList() );
796 QStringList text; 796 QStringList text;
797 text << "audio/*"; 797 text << "audio/*";
798 map.insert(tr("Audio"), text ); 798 map.insert(tr("Audio"), text );
799 QString str = Opie::Ui::OFileDialog::getOpenFileName( 2,"/", QString::null, map); 799 QString str = Opie::Ui::OFileDialog::getOpenFileName( 2,"/", QString::null, map);
800 if(!str.isEmpty() ) { 800 if(!str.isEmpty() ) {
801 config.writeEntry("mp3Alarm",1); 801 config.writeEntry("mp3Alarm",1);
802 config.writeEntry("mp3File",str); 802 config.writeEntry("mp3File",str);
803 sndFileName->setText( str ); 803 sndFileName->setText( str );
804 scheduleApplyDailyAlarm(); 804 scheduleApplyDailyAlarm();
805 } 805 }
806} 806}