summaryrefslogtreecommitdiff
path: root/noncore/tools/clock/clock.cpp
authorllornkcor <llornkcor>2002-03-15 04:29:42 (UTC)
committer llornkcor <llornkcor>2002-03-15 04:29:42 (UTC)
commita0d6c8fdac4e8644c31d1b2e2a321131be4b57c2 (patch) (unidiff)
tree319d9a01475596ccefa9765cc324485a4ce7e5aa /noncore/tools/clock/clock.cpp
parent320291b5006c75e3e42ba1cbbac9639a54309553 (diff)
downloadopie-a0d6c8fdac4e8644c31d1b2e2a321131be4b57c2.zip
opie-a0d6c8fdac4e8644c31d1b2e2a321131be4b57c2.tar.gz
opie-a0d6c8fdac4e8644c31d1b2e2a321131be4b57c2.tar.bz2
added simple 24 hr alarm features
Diffstat (limited to 'noncore/tools/clock/clock.cpp') (more/less context) (show whitespace changes)
-rw-r--r--noncore/tools/clock/clock.cpp157
1 files changed, 157 insertions, 0 deletions
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp
index ef93e11..d5d77bc 100644
--- a/noncore/tools/clock/clock.cpp
+++ b/noncore/tools/clock/clock.cpp
@@ -21,2 +21,3 @@
21#include "clock.h" 21#include "clock.h"
22#include "setAlarm.h"
22 23
@@ -26,4 +27,10 @@
26#include <qpe/timestring.h> 27#include <qpe/timestring.h>
28#include <qpe/alarmserver.h>
29#include <qpe/sound.h>
30#include <qpe/resource.h>
31#include <qsound.h>
32#include <qtimer.h>
27 33
28#include <qlcdnumber.h> 34#include <qlcdnumber.h>
35#include <qslider.h>
29#include <qlabel.h> 36#include <qlabel.h>
@@ -35,2 +42,4 @@
35#include <qpainter.h> 42#include <qpainter.h>
43#include <qmessagebox.h>
44#include <qdatetime.h>
36 45
@@ -57,2 +66,5 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
57 66
67 snoozeBtn = new QPushButton ( this);
68 snoozeBtn->setText( tr( "Snooze" ) );
69
58 aclock = new AnalogClock( this ); 70 aclock = new AnalogClock( this );
@@ -100,2 +112,3 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
100 set = new QPushButton ( controls ); 112 set = new QPushButton ( controls );
113 set->setMaximumSize(50,30);
101 gl->addWidget( set, 0, 1 ); 114 gl->addWidget( set, 0, 1 );
@@ -111,2 +124,11 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
111 124
125 alarmOffBtn = new QPushButton ( controls );
126 alarmOffBtn->setMaximumSize(60,30);
127 gl->addWidget( alarmOffBtn, 0, 2 );
128
129 alarmBtn = new QPushButton ( controls );
130 alarmBtn->setMaximumSize(60,30);
131 gl->addWidget( alarmBtn, 1, 2 );
132 alarmBtn->setText( tr( "Set Alarm" ) );
133
112 connect( set, SIGNAL( pressed() ), SLOT( slotSet() ) ); 134 connect( set, SIGNAL( pressed() ), SLOT( slotSet() ) );
@@ -114,2 +136,9 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
114 136
137 connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) );
138 connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) );
139 connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) );
140
141 connect( qApp, SIGNAL(appMessage(const QCString&, const QByteArray&)),
142 this, SLOT(appMessage(const QCString&, const QByteArray&)) );
143
115 t = new QTimer( this ); 144 t = new QTimer( this );
@@ -125,2 +154,18 @@ Clock::Clock( QWidget * parent, const char * name, WFlags f )
125 154
155 QString tmp = config.readEntry("clockAlarmHour", "");
156 bool ok;
157 hour = tmp.toInt(&ok,10);
158 tmp = config.readEntry("clockAlarmMinute","");
159 minute = tmp.toInt(&ok,10);
160
161 if( config.readEntry("clockAlarmSet","FALSE") == "TRUE") {
162 alarmOffBtn->setText( tr( "Alarm On" ) );
163 alarmBool=TRUE;
164 snoozeBtn->show();
165 } else {
166 alarmOffBtn->setText( tr( "Alarm Off" ) );
167 alarmBool=FALSE;
168 snoozeBtn->hide();
169 }
170
126 QTimer::singleShot( 0, this, SLOT(updateClock()) ); 171 QTimer::singleShot( 0, this, SLOT(updateClock()) );
@@ -237,2 +282,114 @@ void Clock::modeSelect( int m )
237 282
283//this sets the alarm time
284void Clock::slotSetAlarm()
285{
286 if( !snoozeBtn->isHidden())
287 slotToggleAlarm();
288 Set_Alarm *setAlarmDlg;
289 setAlarmDlg = new Set_Alarm(this,"SetAlarm", TRUE);
290 int result = setAlarmDlg->exec();
291 if(result == 1) {
292 Config config( "qpe" );
293 config.setGroup("Time");
294 QString tmp;
295 hour = setAlarmDlg->Hour_Slider->value();
296 minute = setAlarmDlg->Minute_Slider->value();
297 snoozeTime=setAlarmDlg->SnoozeSlider->value();
298 if(ampm) {
299 if(setAlarmDlg->Pm_RadioButton->isChecked() && hour < 12 )
300 hour+=12;
301 }
302 config.writeEntry("clockAlarmHour", tmp.setNum( hour ),10);
303 config.writeEntry("clockAlarmMinute",tmp.setNum( minute ),10);
304 config.writeEntry("clockAlarmSnooze",tmp.setNum( snoozeTime ),10);
305 config.write();
306 }
307}
308
309void Clock::slotSnooze()
310{
311 bSound=FALSE;
312 int warn;
313 QTime t = QTime::currentTime();
314 QDateTime whenl( when.date(), t.addSecs( snoozeTime*60));
315 when=whenl;
316 AlarmServer::addAlarm( when,
317 "QPE/Application/clock",
318 "alarm(QDateTime,int)", warn );
319
320}
321
322//toggles alarm on/off
323void Clock::slotToggleAlarm()
324{
325 Config config( "qpe" );
326 config.setGroup("Time");
327 if(alarmBool) {
328 config.writeEntry("clockAlarmSet","FALSE");
329 alarmOffBtn->setText( tr( "Alarm Off" ) );
330 snoozeBtn->hide();
331 alarmBool=FALSE;
332 alarmOff();
333 } else {
334 config.writeEntry("clockAlarmSet","TRUE");
335 alarmOffBtn->setText( tr( "Alarm On" ) );
336 snoozeBtn->show();
337 alarmBool=TRUE;
338 alarmOn();
339 }
340 config.write();
341}
342
343void Clock::alarmOn()
344{
345 QDate d = QDate::currentDate();
346 QTime tm((int)hour,(int)minute,0);
347 qDebug("Time set "+tm.toString());
348 QTime t = QTime::currentTime();
349 if( t > tm)
350 d = d.addDays(1);
351 int warn;
352 QDateTime whenl(d,tm);
353 when=whenl;
354 AlarmServer::addAlarm( when,
355 "QPE/Application/clock",
356 "alarm(QDateTime,int)", warn );
357 QMessageBox::message("Note","Alarm is set for:\n"+ whenl.toString());
358}
359
360void Clock::alarmOff()
361{
362 int warn;
363 bSound=FALSE;
364 AlarmServer::deleteAlarm( when,
365 "QPE/Application/clock",
366 "alarm(QDateTime,int)", warn );
367 qDebug("Alarm Off "+ when.toString());
368
369}
370
371void Clock::appMessage(const QCString& msg, const QByteArray& data)
372{
373 int stopTimer = 0;
374 int timerStay = 5000;
375 bSound=TRUE;
376 if ( msg == "alarm(QDateTime,int)" ) {
377 Sound::soundAlarm();
378 stopTimer = startTimer( timerStay);
379 }
380}
381
382void Clock::timerEvent( QTimerEvent *e )
383{
384 static int stop = 0;
385 if ( stop < 10 && bSound) {
386 Sound::soundAlarm();
387 stop++;
388 } else {
389 stop = 0;
390 killTimer( e->timerId() );
391 }
392}
393
394
238QSizePolicy AnalogClock::sizePolicy() const 395QSizePolicy AnalogClock::sizePolicy() const