summaryrefslogtreecommitdiff
path: root/noncore/tools/clock
authorzecke <zecke>2004-04-03 20:10:15 (UTC)
committer zecke <zecke>2004-04-03 20:10:15 (UTC)
commit1f03371e4c5d9db806e941bf3687b4bf340aa4fa (patch) (side-by-side diff)
tree08d4855e6babf252493ad677f30e5e35ba7a5751 /noncore/tools/clock
parent93aeaa0de75ba89bd565c845e79e470a80816b0a (diff)
downloadopie-1f03371e4c5d9db806e941bf3687b4bf340aa4fa.zip
opie-1f03371e4c5d9db806e941bf3687b4bf340aa4fa.tar.gz
opie-1f03371e4c5d9db806e941bf3687b4bf340aa4fa.tar.bz2
This is the merged Qtopia Clock with our changes included
-Seperate Clock, StopWatch, Alarm -Allow starting stopping the stop watch by QCOP -Allow Daily alarms -Call OpiePlayer on resume
Diffstat (limited to 'noncore/tools/clock') (more/less context) (ignore whitespace changes)
-rw-r--r--noncore/tools/clock/analogclock.cpp2
-rw-r--r--noncore/tools/clock/clock.cpp1156
-rw-r--r--noncore/tools/clock/clock.h112
-rw-r--r--noncore/tools/clock/clock.pro9
-rw-r--r--noncore/tools/clock/clockbase.ui111
-rw-r--r--noncore/tools/clock/main.cpp8
6 files changed, 823 insertions, 575 deletions
diff --git a/noncore/tools/clock/analogclock.cpp b/noncore/tools/clock/analogclock.cpp
index bf358e2..c5f0155 100644
--- a/noncore/tools/clock/analogclock.cpp
+++ b/noncore/tools/clock/analogclock.cpp
@@ -44,7 +44,7 @@ void AnalogClock::drawContents( QPainter *p )
#if !defined(NO_DEBUG)
static bool first = true;
if ( first ) {
- QTOPIA_PROFILE("first paint event");
+// QTOPIA_PROFILE("first paint event");
first = false;
}
#endif
diff --git a/noncore/tools/clock/clock.cpp b/noncore/tools/clock/clock.cpp
index 485354b..ad422a6 100644
--- a/noncore/tools/clock/clock.cpp
+++ b/noncore/tools/clock/clock.cpp
@@ -1,7 +1,7 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
@@ -18,9 +18,15 @@
**
**********************************************************************/
// changes added and Copyright (C) by L. J. Potter <ljp@llornkcor.com> 2002
+// changes added and Copyright (C) by Holger Freyther 2004
#include "clock.h"
-#include "setAlarm.h"
+
+#include "analogclock.h"
+
+#include <qtabwidget.h>
+
+#include <opie2/ofiledialog.h>
#include <qpe/qpeapplication.h>
#include <qpe/qcopenvelope_qws.h>
@@ -32,19 +38,30 @@
#include <qsound.h>
#include <qtimer.h>
-#include <opie2/oclickablelabel.h>
+
#include <qlcdnumber.h>
#include <qslider.h>
#include <qlabel.h>
-#include <qlayout.h>
#include <qtimer.h>
#include <qpushbutton.h>
-#include <qradiobutton.h>
-#include <qbuttongroup.h>
+#include <qtoolbutton.h>
#include <qpainter.h>
#include <qmessagebox.h>
#include <qdatetime.h>
+#include <qspinbox.h>
+#include <qcombobox.h>
+#include <qcheckbox.h>
+#include <qgroupbox.h>
+#include <qlayout.h>
+#include <qhbox.h>
+#include <qlineedit.h>
+
+static const int sw_prec = 2;
+static const int magic_daily = 2292922;
+static const int magic_countdown = 2292923;
+static const int magic_snooze = 2292924;
+static const int magic_playmp = 2292925;
#include <math.h>
#include <unistd.h>
@@ -53,612 +70,737 @@
#include <pthread.h>
-const double deg2rad = 0.017453292519943295769; // pi/180
-const int sw_prec = 2;
-
-using namespace Opie::Ui;
-void startPlayer()
+static void toggleScreenSaver( bool on )
{
- Config config( "qpe" );
- config.setGroup( "Time" );
- sleep(15);
- QCopEnvelope e( "QPE/Application/opieplayer", "setDocument(QString)" );
- e << config.readEntry( "mp3File", "" );
+ QCopEnvelope e( "QPE/System", "setScreenSaverMode(int)" );
+ e << ( on ? QPEApplication::Enable : QPEApplication::DisableSuspend );
}
-
-static void toggleScreenSaver( bool on )
+static void startPlayer()
{
- QCopEnvelope e( "QPE/System", "setScreenSaverMode(int)" );
- e << ( on ? QPEApplication::Enable : QPEApplication::DisableSuspend );
+ Config config( "qpe" );
+ config.setGroup( "Time" );
+ sleep(15);
+ QCopEnvelope e( "QPE/Application/opieplayer", "setDocument(QString)" );
+ e << config.readEntry( "mp3File", "" );
}
-Clock::Clock( QWidget * parent, const char * name, WFlags f )
- : QVBox( parent, name , f )
+class MySpinBox : public QSpinBox
{
- setSpacing( 4 );
- setMargin( 1 );
-
-
- snoozeBtn = new QPushButton ( this );
- snoozeBtn->setText( tr( "Snooze" ) );
-
- aclock = new AnalogClock( this );
- aclock->display( QTime::currentTime() );
- aclock->setLineWidth( 2 );
-
- QHBox *hb = new QHBox( this );
- hb->setMargin( 0 );
- QWidget *space = new QWidget( hb );
- lcd = new QLCDNumber( hb );
- lcd->setSegmentStyle( QLCDNumber::Flat );
- lcd->setFrameStyle( QFrame::NoFrame );
- lcd->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Minimum ) );
- lcd->setFixedHeight( 23 );
-
- ampmLabel = new QLabel( tr( "PM" ), hb );
- ampmLabel->setFont( QFont( "Helvetica", 14, QFont::Bold ) );
- ampmLabel->setSizePolicy( QSizePolicy( QSizePolicy::Minimum, QSizePolicy::Preferred ) );
- ampmLabel->setAlignment( AlignLeft | AlignBottom );
- space = new QWidget( hb );
-
- date = new QLabel( this );
- date->setAlignment( AlignHCenter | AlignVCenter );
- date->setFont( QFont( "Helvetica", 14, QFont::Bold ) );
- date->setText( TimeString::longDateString( QDate::currentDate() ) );
-
- QWidget *controls = new QWidget( this );
- QGridLayout *gl = new QGridLayout( controls, 3, 2, 6, 4 );
+public:
+ QLineEdit *lineEdit() const {
+ return editor();
+ }
+};
+
+//
+//
+//
+AlarmDlg::AlarmDlg(QWidget *parent, const char *name, bool modal,
+ const QString &txt) :
+ AlarmDlgBase(parent, name, modal)
+{
+ setCaption( tr("Clock") );
+ pixmap->setPixmap( Resource::loadPixmap("alarmbell") );
+ alarmDlgLabel->setText(txt);
- QButtonGroup *grp = new QButtonGroup( controls );
- grp->setRadioButtonExclusive( true );
- grp->hide();
+ connect(snoozeTime, SIGNAL(valueChanged(int)), this,
+ SLOT(changePrompt(int)));
+ connect(cmdOk, SIGNAL(clicked()), this, SLOT(checkSnooze()));
+}
- clockRB = new QRadioButton ( tr( "Clock" ), controls );
- gl->addWidget( clockRB, 0, 0 );
- grp->insert( clockRB );
+//
+//
+//
+void
+AlarmDlg::setText(const QString &txt)
+{
+ alarmDlgLabel->setText(txt);
+}
- swatchRB = new QRadioButton ( tr( "Stopwatch" ), controls );
- gl->addWidget( swatchRB, 1, 0 );
- grp->insert( swatchRB );
+//
+//
+//
+void
+AlarmDlg::checkSnooze(void)
+{
+ //
+ // Ensure we have only one snooze alarm.
+ //
+ AlarmServer::deleteAlarm(QDateTime(), "QPE/Application/clock",
+ "alarm(QDateTime,int)", magic_snooze);
+
+ if (snoozeTime->value() > 0) {
+ QDateTime wake = QDateTime::currentDateTime();
+ wake = wake.addSecs(snoozeTime->value() * 60); // snoozeTime in minutes
+
+ AlarmServer::addAlarm(wake, "QPE/Application/clock",
+ "alarm(QDateTime,int)", magic_snooze);
+ }
+ accept();
+}
- connect( grp, SIGNAL( clicked(int) ), this, SLOT( modeSelect(int) ) );
- grp->setButton( 0 );
- set = new QPushButton ( controls );
- set->setMaximumSize( 50, 30 );
- gl->addWidget( set , 0, 1 );
- set->setText( tr( "Start" ) );
- set->setEnabled( FALSE );
- grp->insert( set );
- reset = new QPushButton ( controls );
- gl->addWidget( reset, 1, 1 );
- reset->setText( tr( "Reset" ) );
- reset->setEnabled( FALSE );
- grp->insert( reset );
+void
+AlarmDlg::changePrompt(int mins)
+{
+ cmdOk->setText(mins > 0 ? tr("Snooze") : tr("Close") );
+}
- alarmOffBtn = new QPushButton ( controls );
- gl->addWidget( alarmOffBtn, 0, 2 );
- alarmBtn = new QPushButton ( controls );
- gl->addWidget( alarmBtn, 1, 2 );
- alarmBtn->setText( tr( "Set Alarm" ) );
+Clock::Clock( QWidget * parent, const char *, WFlags f )
+ : ClockBase( parent, "clock", f ), swatch_splitms(99), init(FALSE) // No tr
+{
+ alarmDlg = 0;
+ swLayout = 0;
+ dayBtn = new QToolButton * [7];
- OClickableLabel *click = new Opie::Ui::OClickableLabel( controls, "label" );
- click->setText( tr( "Set date and time." ) );
- gl->addMultiCellWidget( click, 3, 3, 0, 2, AlignHCenter );
- connect( click, SIGNAL( clicked() ), this, SLOT( slotAdjustTime() ) );
+ Config config( "qpe" );
+ config.setGroup("Time");
+ ampm = config.readBoolEntry( "AMPM", TRUE );
+ onMonday = config.readBoolEntry( "MONDAY" );
+
+ connect( tabs, SIGNAL(currentChanged(QWidget*)),
+ this, SLOT(tabChanged(QWidget*)) );
+
+ analogStopwatch = new AnalogClock( swFrame );
+ stopwatchLcd = new QLCDNumber( swFrame );
+ stopwatchLcd->setFrameStyle( QFrame::NoFrame );
+ stopwatchLcd->setSegmentStyle( QLCDNumber::Flat );
+ stopwatchLcd->setSizePolicy( QSizePolicy(QSizePolicy::Expanding, QSizePolicy::Preferred) );
+
+ analogClock->display( QTime::currentTime() );
+ clockLcd->setNumDigits( 5 );
+ clockLcd->setFixedWidth( clockLcd->sizeHint().width() );
+ date->setText( TimeString::dateString( QDate::currentDate(), TimeString::currentDateFormat() ) );
+ if ( qApp->desktop()->width() < 200 )
+ date->setFont( QFont(date->font().family(), 14, QFont::Bold) );
+ if ( qApp->desktop()->height() > 240 ) {
+ clockLcd->setFixedHeight( 30 );
+ stopwatchLcd->setFixedHeight( 30 );
+ }
- connect( set , SIGNAL( pressed() ), SLOT( slotSet() ) );
- connect( reset, SIGNAL( clicked() ), SLOT( slotReset() ) );
+ connect( stopStart, SIGNAL(pressed()), SLOT(stopStartStopWatch()) );
+ connect( reset, SIGNAL(pressed()), SLOT(resetStopWatch()) );
- connect( alarmBtn, SIGNAL( clicked() ), SLOT( slotSetAlarm() ) );
- connect( snoozeBtn, SIGNAL( clicked() ), SLOT( slotSnooze() ) );
- connect( alarmOffBtn, SIGNAL( clicked() ), SLOT( slotToggleAlarm() ) );
+ t = new QTimer( this );
+ connect( t, SIGNAL(timeout()), SLOT(updateClock()) );
+ t->start( 1000 );
- connect( qApp, SIGNAL( appMessage(const QCString&,const QByteArray&) ),
- this, SLOT( appMessage(const QCString&,const QByteArray&) ) );
+ applyAlarmTimer = new QTimer( this );
+ connect( applyAlarmTimer, SIGNAL(timeout()),
+ this, SLOT(applyDailyAlarm()) );
- t = new QTimer( this );
- connect( t, SIGNAL( timeout() ), SLOT( updateClock() ) );
- t->start( 1000 );
+ alarmt = new QTimer( this );
+ connect( alarmt, SIGNAL(timeout()), SLOT(alarmTimeout()) );
- connect( qApp, SIGNAL( timeChanged() ), SLOT( updateClock() ) );
+ connect( qApp, SIGNAL(timeChanged()), SLOT(updateClock()) );
+ connect( qApp, SIGNAL(timeChanged()), SLOT(applyDailyAlarm()) );
- swatch_running = FALSE;
- swatch_totalms = 0;
+ swatch_running = FALSE;
+ swatch_totalms = 0;
+ swatch_currLap = 0;
+ swatch_dispLap = 0;
+ stopwatchLcd->setNumDigits( 8+1+sw_prec );
+ stopwatchLcd->display( "00:00:00.00" );
+
+ QVBoxLayout *lvb = new QVBoxLayout( lapFrame );
+ nextLapBtn = new QToolButton( UpArrow, lapFrame );
+ connect( nextLapBtn, SIGNAL(clicked()), this, SLOT(nextLap()) );
+ nextLapBtn->setAccel( Key_Up );
+ lvb->addWidget( nextLapBtn );
+ prevLapBtn = new QToolButton( DownArrow, lapFrame );
+ connect( prevLapBtn, SIGNAL(clicked()), this, SLOT(prevLap()) );
+ prevLapBtn->setAccel( Key_Down );
+ prevLapBtn->setMinimumWidth( 15 );
+ lvb->addWidget( prevLapBtn );
+ prevLapBtn->setEnabled( FALSE );
+ nextLapBtn->setEnabled( FALSE );
+
+ reset->setEnabled( FALSE );
+
+ lapLcd->setNumDigits( 8+1+sw_prec );
+ lapLcd->display( "00:00:00.00" );
+
+ splitLcd->setNumDigits( 8+1+sw_prec );
+ splitLcd->display( "00:00:00.00" );
+
+ lapNumLcd->display( 1 );
+
+ lapTimer = new QTimer( this );
+ connect( lapTimer, SIGNAL(timeout()), this, SLOT(lapTimeout()) );
+
+ for (uint s = 0; s < swatch_splitms.count(); s++ )
+ swatch_splitms[(int)s] = 0;
+
+ connect( qApp, SIGNAL(clockChanged(bool)), this, SLOT(changeClock(bool)) );
+
+ cdGroup->hide(); // XXX implement countdown timer.
+
+ connect( dailyHour, SIGNAL(valueChanged(int)), this, SLOT(scheduleApplyDailyAlarm()) );
+ connect( dailyMinute, SIGNAL(valueChanged(int)), this, SLOT(setDailyMinute(int)) );
+ connect( dailyAmPm, SIGNAL(activated(int)), this, SLOT(setDailyAmPm(int)) );
+ connect( dailyEnabled, SIGNAL(toggled(bool)), this, SLOT(enableDaily(bool)) );
+ cdLcd->display( "00:00" );
+
+ dailyMinute->setValidator(0);
+
+ Config cConfig( "Clock" ); // No tr
+ cConfig.setGroup( "Daily Alarm" );
+
+ QStringList days;
+ days.append( tr("Mon", "Monday") );
+ days.append( tr("Tue", "Tuesday") );
+ days.append( tr("Wed", "Wednesday") );
+ days.append( tr("Thu", "Thursday") );
+ days.append( tr("Fri", "Friday") );
+ days.append( tr("Sat", "Saturday") );
+ days.append( tr("Sun", "Sunday") );
+
+ int i;
+ QHBoxLayout *hb = new QHBoxLayout( daysFrame );
+ for ( i = 0; i < 7; i++ ) {
+ dayBtn[i] = new QToolButton( daysFrame );
+ hb->addWidget( dayBtn[i] );
+ dayBtn[i]->setToggleButton( TRUE );
+ dayBtn[i]->setOn( TRUE );
+ dayBtn[i]->setFocusPolicy( StrongFocus );
+ connect( dayBtn[i], SIGNAL(toggled(bool)), this, SLOT(scheduleApplyDailyAlarm()) );
+ }
- connect( qApp, SIGNAL( clockChanged(bool) ), this, SLOT( changeClock(bool) ) );
+ for ( i = 0; i < 7; i++ )
+ dayBtn[dayBtnIdx(i+1)]->setText( days[i] );
+ QStringList exclDays = cConfig.readListEntry( "ExcludeDays", ',' );
+ QStringList::Iterator it;
+ for ( it = exclDays.begin(); it != exclDays.end(); ++it ) {
+ int d = (*it).toInt();
+ if ( d >= 1 && d <= 7 )
+ dayBtn[dayBtnIdx(d)]->setOn( FALSE );
+ }
- Config config( "qpe" );
- config.setGroup( "Time" );
- ampm = config.readBoolEntry( "AMPM", TRUE );
+ bool alarm = cConfig.readBoolEntry("Enabled", FALSE);
+ bool sound = cConfig.readBoolEntry("SoundEnabled", FALSE );
+ dailyEnabled->setChecked( alarm );
+ sndGroup->setEnabled( alarm );
+ sndCheck->setChecked( sound );
+ sndChoose->setEnabled( sound );
+ sndFileName->setEnabled( sound );
+
+ // FIXME ODP migrate to own config class.. merge config options
+ Config cfg_qpe( "qpe" );
+ cfg_qpe.setGroup( "Time" );
+ sndFileName->setText( cfg_qpe.readEntry( "mp3File" ) );
+ //
+
+ int m = cConfig.readNumEntry( "Minute", 0 );
+ dailyMinute->setValue( m );
+// dailyMinute->setPrefix( m <= 9 ? "0" : "" );
+ int h = cConfig.readNumEntry( "Hour", 7 );
+ if ( ampm ) {
+ if (h > 12) {
+ h -= 12;
+ dailyAmPm->setCurrentItem( 1 );
+ }
+ if (h == 0) h = 12;
+ dailyHour->setMinValue( 1 );
+ dailyHour->setMaxValue( 12 );
+ } else {
+ dailyAmPm->hide();
+ }
+ dailyHour->setValue( h );
- QString tmp = config.readEntry( "clockAlarmHour", "" );
- bool ok;
- hour = tmp.toInt( &ok, 10 );
- tmp = config.readEntry( "clockAlarmMinute", "" );
- minute = tmp.toInt( &ok, 10 );
+ connect( ((MySpinBox*)dailyHour)->lineEdit(), SIGNAL(textChanged(const QString&)),
+ this, SLOT(dailyEdited()) );
+ connect( ((MySpinBox*)dailyMinute)->lineEdit(), SIGNAL(textChanged(const QString&)),
+ this, SLOT(dailyEdited()) );
- if ( config.readEntry( "clockAlarmSet", "FALSE" ) == "TRUE" )
- {
- alarmOffBtn->setText( tr( "Alarm Is On" ) );
- alarmBool = TRUE;
- snoozeBtn->show();
- }
- else
- {
- alarmOffBtn->setText( tr( "Alarm Is Off" ) );
- alarmBool = FALSE;
- snoozeBtn->hide();
- }
+#if defined(Q_WS_QWS) && !defined(QT_NO_COP)
+ connect( qApp, SIGNAL(appMessage(const QCString&,const QByteArray&)),
+ this, SLOT(appMessage(const QCString&,const QByteArray&)) );
+#endif
- QTimer::singleShot( 0, this, SLOT( updateClock() ) );
+ QTimer::singleShot( 0, this, SLOT(updateClock()) );
+ swFrame->installEventFilter( this );
- Config cfg( "Clock" );
- cfg.setGroup( "Mode" );
- int mode = cfg.readBoolEntry( "clockMode");
- setSwatchMode( mode);
- modeSelect( mode);
+ init = TRUE;
}
Clock::~Clock()
{
- toggleScreenSaver( true );
+ toggleScreenSaver( true );
+ delete [] dayBtn;
}
void Clock::updateClock()
{
- if ( clockRB->isChecked() )
- {
- QTime tm = QDateTime::currentDateTime().time();
- QString s;
- if ( ampm )
- {
- int hour = tm.hour();
- if ( hour == 0 )
- hour = 12;
- if ( hour > 12 )
- hour -= 12;
- s.sprintf( "%2d%c%02d", hour, ':', tm.minute() );
- ampmLabel->setText( ( tm.hour() >= 12 ) ? "PM" : "AM" );
- ampmLabel->show();
- }
- else
- {
- s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() );
- ampmLabel->hide();
- }
- lcd->display( s );
- lcd->repaint( FALSE );
- aclock->display( QTime::currentTime() );
- date->setText( TimeString::longDateString( QDate::currentDate() ) );
- }
- else
- {
- QTime swatch_time;
- QString lcdtext;
- int totalms = swatch_totalms;
- if ( swatch_running )
- totalms += swatch_start.elapsed();
- swatch_time = QTime( 0, 0, 0 ).addMSecs( totalms );
- QString d = swatch_running ? QString( " " )
- : QString::number( totalms % 1000 + 1000 );
- lcdtext = swatch_time.toString() + "." + d.right( 3 ).left( sw_prec );
- lcd->display( lcdtext );
- lcd->repaint( FALSE );
- aclock->display( swatch_time );
- date->setText( TimeString::longDateString( QDate::currentDate() ) );
+ if ( tabs->currentPageIndex() == 0 ) {
+ QTime tm = QDateTime::currentDateTime().time();
+ QString s;
+ if ( ampm ) {
+ int hour = tm.hour();
+ if (hour == 0)
+ hour = 12;
+ if (hour > 12)
+ hour -= 12;
+ s.sprintf( "%2d%c%02d", hour, ':', tm.minute() );
+ clockAmPm->setText( (tm.hour() >= 12) ? "PM" : "AM" );
+ clockAmPm->show();
+ } else {
+ s.sprintf( "%2d%c%02d", tm.hour(), ':', tm.minute() );
+ clockAmPm->hide();
+ }
+ clockLcd->display( s );
+ clockLcd->repaint( FALSE );
+ analogClock->display( QTime::currentTime() );
+ date->setText( TimeString::dateString( QDate::currentDate(), TimeString::currentDateFormat() ) );
+ } else if ( tabs->currentPageIndex() == 1 ) {
+ int totalms = swatch_totalms;
+ if ( swatch_running )
+ totalms += swatch_start.elapsed();
+ setSwatchLcd( stopwatchLcd, totalms, !swatch_running );
+ QTime swatch_time = QTime(0,0,0).addMSecs(totalms);
+ analogStopwatch->display( swatch_time );
+ if ( swatch_dispLap == swatch_currLap ) {
+ swatch_splitms[swatch_currLap] = swatch_totalms;
+ if ( swatch_running )
+ swatch_splitms[swatch_currLap] += swatch_start.elapsed();
+ updateLap();
+ }
+ } else if ( tabs->currentPageIndex() == 2 ) {
+ // nothing.
}
}
void Clock::changeClock( bool a )
{
- ampm = a;
- updateClock();
+ if ( ampm != a ) {
+ int minute = dailyMinute->value();
+ int hour = dailyHour->value();
+ if ( ampm ) {
+ if (hour == 12)
+ hour = 0;
+ if (dailyAmPm->currentItem() == 1 )
+ hour += 12;
+ dailyHour->setMinValue( 0 );
+ dailyHour->setMaxValue( 23 );
+ dailyAmPm->hide();
+ } else {
+ if (hour > 12) {
+ hour -= 12;
+ dailyAmPm->setCurrentItem( 1 );
+ }
+ if (hour == 0) hour = 12;
+ dailyHour->setMinValue( 1 );
+ dailyHour->setMaxValue( 12 );
+ dailyAmPm->show();
+ }
+ dailyMinute->setValue( minute );
+ dailyHour->setValue( hour );
+ }
+ ampm = a;
+ updateClock();
}
-void Clock::clearClock( void )
+void Clock::stopStartStopWatch()
{
- lcd->display( QTime( 0, 0, 0 ).toString() );
- aclock->display( QTime( 0, 0, 0 ) );
+ if ( swatch_running ) {
+ swatch_totalms += swatch_start.elapsed();
+ swatch_splitms[swatch_currLap] = swatch_totalms;
+ stopStart->setText( tr("Start") );
+ reset->setText( tr("Reset") );
+ reset->setEnabled( TRUE );
+ t->stop();
+ swatch_running = FALSE;
+ toggleScreenSaver( TRUE );
+ updateClock();
+ } else {
+ swatch_start.start();
+ stopStart->setText( tr("Stop") );
+ reset->setText( tr("Lap/Split") );
+ reset->setEnabled( swatch_currLap < 98 );
+ t->start( 1000 );
+ swatch_running = TRUE;
+ // disable screensaver while stop watch is running
+ toggleScreenSaver( FALSE );
+ }
+ swatch_dispLap = swatch_currLap;
+ updateLap();
+ prevLapBtn->setEnabled( swatch_dispLap );
+ nextLapBtn->setEnabled( swatch_dispLap < swatch_currLap );
+ stopStart->setAccel( Key_Return );
}
-void Clock::startSWatch()
+void Clock::resetStopWatch()
{
- if(swatch_running) {
- stopSWatch();
- return;
- }
- qDebug("startSWatch()");
- swatch_start.start();
- set->setText( tr( "Stop" ) );
- t->start( 1000 );
- swatch_running = TRUE;
- // disable screensaver while stop watch is running
- toggleScreenSaver( FALSE );
+ if ( swatch_running ) {
+ swatch_splitms[swatch_currLap] = swatch_totalms+swatch_start.elapsed();
+ swatch_dispLap = swatch_currLap;
+ if ( swatch_currLap < 98 ) // allow up to 99 laps
+ swatch_currLap++;
+ reset->setEnabled( swatch_currLap < 98 );
+ updateLap();
+ lapTimer->start( 2000, TRUE );
+ } else {
+ swatch_start.start();
+ swatch_totalms = 0;
+ swatch_currLap = 0;
+ swatch_dispLap = 0;
+ for ( uint i = 0; i < swatch_splitms.count(); i++ )
+ swatch_splitms[(int)i] = 0;
+ updateLap();
+ updateClock();
+ reset->setText( tr("Lap/Split") );
+ reset->setEnabled( FALSE );
+ }
+ prevLapBtn->setEnabled( swatch_dispLap );
+ nextLapBtn->setEnabled( swatch_dispLap < swatch_currLap );
}
-void Clock::stopSWatch()
+void Clock::prevLap()
{
- qDebug("stopSWatch()");
- swatch_totalms += swatch_start.elapsed();
- set->setText( tr( "Start" ) );
- t->stop();
- swatch_running = FALSE;
- toggleScreenSaver( TRUE );
- updateClock();
+ if ( swatch_dispLap > 0 ) {
+ swatch_dispLap--;
+ updateLap();
+ prevLapBtn->setEnabled( swatch_dispLap );
+ nextLapBtn->setEnabled( swatch_dispLap < swatch_currLap );
+ }
}
-
-void Clock::slotSet()
+void Clock::nextLap()
{
- if ( t->isActive() )
- {
- startSWatch();
- }
- else
- {
- stopSWatch();
+ if ( swatch_dispLap < swatch_currLap ) {
+ swatch_dispLap++;
+ updateLap();
+ prevLapBtn->setEnabled( swatch_dispLap );
+ nextLapBtn->setEnabled( swatch_dispLap < swatch_currLap );
}
}
-void Clock::slotReset()
+void Clock::lapTimeout()
{
- t->stop();
- swatch_start.start();
- swatch_totalms = 0;
-
- if ( swatch_running )
- t->start( 1000 );
-
- updateClock();
-}
-
-void Clock::modeSelect( int m )
-{
- qDebug("Clock::modeSelect( %d) ", m);
- if ( m != 0 )
- {
- lcd->setNumDigits( 8 + 1 + sw_prec );
- lcd->setMinimumWidth( lcd->sizeHint().width() );
- set->setEnabled( TRUE );
- reset->setEnabled( TRUE );
- ampmLabel->hide();
-
-// if(m == 2) {
- if ( !swatch_running ) {
- t->start( 1000 );
- }
-// else
-// {
-// stopSWatch();
-// }
-// }
- }
- else //clock mode
- {
- lcd->setNumDigits( 5 );
- lcd->setMinimumWidth( lcd->sizeHint().width() );
- set->setEnabled( FALSE );
- reset->setEnabled( FALSE );
- t->start( 1000 );
- }
-
- Config config( "Clock" );
- config.setGroup( "Mode" );
- config.writeEntry( "clockMode", m );
- updateClock();
+ swatch_dispLap = swatch_currLap;
+ updateLap();
+ prevLapBtn->setEnabled( swatch_dispLap );
+ nextLapBtn->setEnabled( swatch_dispLap < swatch_currLap );
}
-//this sets the alarm time
-void Clock::slotSetAlarm()
+void Clock::updateLap()
{
- if ( !snoozeBtn->isHidden() )
- slotToggleAlarm();
- Set_Alarm *setAlarmDlg;
- setAlarmDlg = new Set_Alarm( this, "SetAlarm", TRUE );
- int result = setAlarmDlg->exec();
- if ( result == 1 ) {
- Config config( "qpe" );
- config.setGroup( "Time" );
- QString tmp;
- hour = setAlarmDlg->Hour_Slider->value();
- minute = setAlarmDlg->Minute_Slider->value();
- snoozeTime = setAlarmDlg->SnoozeSlider->value();
- if ( ampm ) {
- if ( hour == 12 )
- hour = 0;
-
- if ( setAlarmDlg->Pm_RadioButton->isChecked() && hour < 12 )
- hour += 12;
+ if ( swatch_running && swatch_currLap == swatch_dispLap ) {
+ swatch_splitms[swatch_currLap] = swatch_totalms;
+ swatch_splitms[swatch_currLap] += swatch_start.elapsed();
}
- config.writeEntry( "clockAlarmHour", tmp.setNum( hour ), 10 );
- config.writeEntry( "clockAlarmMinute", tmp.setNum( minute ), 10 );
- config.writeEntry( "clockAlarmSnooze", tmp.setNum( snoozeTime ), 10 );
- config.write();
- }
-}
-
-void Clock::slotSnooze()
-{
- bSound = FALSE;
- int warn = 0;
- QTime t = QTime::currentTime();
- QDateTime whenl( when.date(), t.addSecs( snoozeTime * 60 ) );
- when = whenl;
- AlarmServer::addAlarm( when,
- "QPE/Application/clock",
- "alarm(QDateTime,int)", warn );
-
-}
-
-//toggles alarm on/off
-void Clock::slotToggleAlarm()
-{
- Config config( "qpe" );
- config.setGroup( "Time" );
- if ( alarmBool )
- {
- config.writeEntry( "clockAlarmSet", "FALSE" );
- alarmOffBtn->setText( tr( "Alarm Is Off" ) );
- snoozeBtn->hide();
- alarmBool = FALSE;
- alarmOff();
- }
- else
- {
- config.writeEntry( "clockAlarmSet", "TRUE" );
- alarmOffBtn->setText( tr( "Alarm Is On" ) );
- snoozeBtn->show();
- alarmBool = TRUE;
- alarmOn();
- }
- config.write();
-}
-
-void Clock::alarmOn()
-{
- QDate d = QDate::currentDate();
- QTime tm( ( int ) hour, ( int ) minute, 0 );
- qDebug( "Time set " + tm.toString() );
- QTime t = QTime::currentTime();
- if ( t > tm )
- d = d.addDays( 1 );
- int warn = 0;
- QDateTime whenl( d, tm );
- when = whenl;
- AlarmServer::addAlarm( when,
- "QPE/Application/clock",
- "alarm(QDateTime,int)", warn );
-// setCaption( "Alarm set: " + whenl.toString() );
- setCaption( tr("Alarm set: %1" ).arg(whenl.toString()) );
-}
-
-void Clock::alarmOff()
-{
- int warn = 0;
- bSound = FALSE;
- AlarmServer::deleteAlarm( when,
- "QPE/Application/clock",
- "alarm(QDateTime,int)", warn );
- qDebug( "Alarm Off " + when.toString() );
- setCaption( tr("Clock") );
-}
-
-void Clock::clearTimer()
-{
- alarmOffBtn->setText( tr( "Alarm Is Off" ) );
- alarmBool = FALSE;
- snoozeBtn->hide();
- setCaption( tr("Clock") );
-}
-
-void Clock::appMessage( const QCString& msg, const QByteArray& /*data*/ )
-{
- int stopTimer = 0;
- int timerStay = 5000;
- bSound = TRUE;
- qDebug( "Message received in clock" );
- if ( msg == "alarm(QDateTime,int)" )
- {
- Config config( "qpe" );
- config.setGroup( "Time" );
- if ( config.readBoolEntry( "mp3Alarm", 0 ) )
- {
- clearTimer();
- pthread_t thread;
- pthread_create(&thread, NULL, (void * (*) (void *))startPlayer, NULL/* &*/);
-
- }
- else
- {
+ int split = swatch_splitms[swatch_dispLap];
+ int lap;
+ if ( swatch_dispLap > 0 )
+ lap = swatch_splitms[swatch_dispLap] - swatch_splitms[swatch_dispLap-1];
+ else
+ lap = swatch_splitms[swatch_dispLap];
+
+ lapNumLcd->display( swatch_dispLap+1 );
+ bool showMs = !swatch_running || swatch_dispLap!=swatch_currLap;
+ setSwatchLcd( lapLcd, lap, showMs );
+ setSwatchLcd( splitLcd, split, showMs );
+}
- Sound::soundAlarm();
- stopTimer = startTimer( timerStay );
- }
- }
+void Clock::setSwatchLcd( QLCDNumber *lcd, int ms, bool showMs )
+{
+ QTime swatch_time = QTime(0,0,0).addMSecs(ms);
+ QString d = showMs ? QString::number(ms%1000+1000) : QString(" ");
+ QString lcdtext = swatch_time.toString() + "." + d.right(3).left(sw_prec);
+ lcd->display( lcdtext );
+ lcd->repaint( FALSE );
+}
- if ( msg == "timerStart()" )
- {
- slotStartTimer();
- }
- if ( msg == "timerStop()" )
- {
- slotStopTimer();
- }
- if ( msg == "timerReset()" )
- {
- slotResetTimer();
+bool Clock::eventFilter( QObject *o, QEvent *e )
+{
+ if ( o == swFrame && e->type() == QEvent::Resize ) {
+ QResizeEvent *re = (QResizeEvent *)e;
+ delete swLayout;
+ if ( re->size().height() < 80 || re->size().height()*3 < re->size().width() )
+ swLayout = new QHBoxLayout( swFrame );
+ else
+ swLayout = new QVBoxLayout( swFrame );
+ swLayout->addWidget( analogStopwatch );
+ swLayout->addWidget( stopwatchLcd );
+ swLayout->activate();
}
- show();
- raise();
- QPEApplication::setKeepRunning();
- setActiveWindow();
+ return FALSE;
}
-void Clock::timerEvent( QTimerEvent *e )
+void Clock::tabChanged( QWidget * )
{
- static int stop = 0;
- if ( stop < 120 && bSound )
- {
- Sound::soundAlarm();
- stop++;
- }
- else
- {
- stop = 0;
- killTimer( e->timerId() );
- clearTimer();
- setCaption( tr( "Clock: Alarm was missed." ) );
+ if ( tabs->currentPageIndex() == 0 ) {
+ t->start(1000);
+ } else if ( tabs->currentPageIndex() == 1 ) {
+ if ( !swatch_running )
+ t->stop();
+ stopStart->setAccel( Key_Return );
+ } else if ( tabs->currentPageIndex() == 2 ) {
+ t->start(1000);
}
+ updateClock();
}
-AnalogClock::AnalogClock(QWidget * parent, const char * name) : QFrame( parent, name ), clear(true)
+void Clock::setDailyAmPm(int)
{
- QWidget *d = QApplication::desktop();
- if(d->width() <= 240)
- bg = Resource::loadPixmap("clock/bg");
+ scheduleApplyDailyAlarm();
}
-QSizePolicy AnalogClock::sizePolicy() const
+void Clock::setDailyMinute( int m )
{
- return QSizePolicy( QSizePolicy::Expanding, QSizePolicy::Expanding );
+ dailyMinute->setPrefix( m <= 9 ? "0" : "" );
}
-void AnalogClock::drawContents( QPainter *p )
+void Clock::dailyEdited()
{
- QRect r = contentsRect();
- QRect fr;
-
- p->drawPixmap(QPoint(0, 0), bg, r);
-
- if ( r. width ( ) > r. height ( ))
- fr. setRect (( r. width ( ) - r. height ( )) / 2, r. y ( ), r. height ( ), r. height ( ));
- else
- fr. setRect ( r. x ( ), ( r. height ( ) - r. width ( )) / 2, r. width ( ), r. width ( ));
-
- QPoint center = fr. center ( ); // ( fr.x() + fr.width() / 2, fr.y() + fr.height() / 2 );
- QPoint l1 ( center. x ( ), fr. y ( ) + 2 );
- QPoint l2 ( center. x ( ), fr. y ( ) + 8 );
-
-
+ if ( spinBoxValid(dailyMinute) && spinBoxValid(dailyHour) )
+ scheduleApplyDailyAlarm();
+ else
+ applyAlarmTimer->stop();
+}
- if ( clear )
- {
- erase ( r );
- p-> setPen ( NoPen );
- p-> setBrush ( colorGroup ( ). color ( QColorGroup::Base ));
- p-> drawEllipse ( fr );
- p-> setBrush ( NoBrush );
+void Clock::enableDaily( bool )
+{
+ scheduleApplyDailyAlarm();
+}
- // draw ticks
- p->setPen( QPen( colorGroup ( ). color ( QColorGroup::Text ), 1 ) );
- for ( int i = 0; i < 12; i++ )
- p->drawLine( rotate( center, l1, i * 30 ), rotate( center, l2, i * 30 ) );
- }
- else
- {
- drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Base ), prevTime, &currTime );
+void Clock::appMessage( const QCString &msg, const QByteArray &data )
+{
+ if ( msg == "alarm(QDateTime,int)" ) {
+ QDataStream ds(data,IO_ReadOnly);
+ QDateTime when;
+ int t;
+ ds >> when >> t;
+ QTime theTime( when.time() );
+ if ( t == magic_daily || t == magic_snooze ||
+ t == magic_playmp ) {
+ QString msg = tr("<b>Daily Alarm:</b><p>");
+ QString ts;
+ if ( ampm ) {
+ bool pm = FALSE;
+ int h = theTime.hour();
+ if (h > 12) {
+ h -= 12;
+ pm = TRUE;
+ }
+ if (h == 0) h = 12;
+ ts.sprintf( "%02d:%02d %s", h, theTime.minute(), pm?"PM":"AM" );
+ } else {
+ ts.sprintf( "%02d:%02d", theTime.hour(), theTime.minute() );
+ }
+ msg += ts;
+
+ if (t == magic_playmp ) {
+ pthread_t thread;
+ pthread_create(&thread,NULL, (void * (*) (void *))startPlayer, NULL/* &*/ );
+ }else {
+ Sound::soundAlarm();
+ alarmCount = 0;
+ alarmt->start( 5000 );
+ }
+ if ( !alarmDlg ) {
+ alarmDlg = new AlarmDlg(this);
+ }
+ alarmDlg->setText(msg);
+
+ // Set for tomorrow, so user wakes up every day, even if they
+ // don't confirm the dialog. Don't set it again when snoozing.
+ if (t != magic_snooze) {
+ applyDailyAlarm();
+ }
+
+
+ if ( !alarmDlg->isVisible() ) {
+ QPEApplication::execDialog(alarmDlg);
+ alarmt->stop();
+ }
+ } else if ( t == magic_countdown ) {
+ // countdown
+ Sound::soundAlarm();
+ }
+ } else if ( msg == "setDailyEnabled(int)" ) {
+ QDataStream ds(data,IO_ReadOnly);
+ int enableDaily;
+ ds >> enableDaily;
+ dailyEnabled->setChecked( enableDaily );
+ applyDailyAlarm();
+ } else if ( msg == "editDailyAlarm()" ) {
+ tabs->setCurrentPage(2);
+ QPEApplication::setKeepRunning();
+ } else if (msg == "showClock()") {
+ tabs->setCurrentPage(0);
+ QPEApplication::setKeepRunning();
+ } else if (msg == "timerStart()" ) {
+ if ( !swatch_running )
+ stopStartStopWatch();
+ tabs->setCurrentPage(1);
+ QPEApplication::setKeepRunning();
+ } else if (msg == "timerStop()" ) {
+ if ( swatch_running )
+ stopStartStopWatch();
+ tabs->setCurrentPage(1);
+ QPEApplication::setKeepRunning();
+ } else if (msg == "timerReset()" ) {
+ resetStopWatch();
+ tabs->setCurrentPage(1);
+ QPEApplication::setKeepRunning();
}
-
- drawPointers ( p, fr, colorGroup ( ). color ( QColorGroup::Text ), currTime );
-
- prevTime = currTime;
}
-void AnalogClock::drawPointers ( QPainter *p, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 )
+void Clock::alarmTimeout()
{
- QPoint center = r. center ( );
-
- QPoint h1( center. x ( ), r. y ( ) + r. height ( ) / 4 );
- QPoint h2( center. x ( ), center. y ( ) );
-
- QPoint m1( center. x ( ), r.y() + r.height() / 8 );
- QPoint m2( center. x ( ), center. y ( ) );
-
- QPoint s1( center. x ( ), r. y ( ) + 8 );
- QPoint s2( center. x ( ), center. y ( ) );
-
-
- if ( !t2 || ( t. minute ( ) != t2-> minute ( ) || t. hour ( ) != t2-> hour ( ))) {
- // draw hour pointer
- h1 = rotate( center, h1, 30 * ( t.hour() % 12 ) + t.minute() / 2 );
- h2 = rotate( center, h2, 30 * ( t.hour() % 12 ) + t.minute() / 2 );
- p-> setPen ( QPen ( c, 3 ));
- p-> drawLine ( h1, h2 );
- }
+ if ( alarmCount < 10 ) {
+ Sound::soundAlarm();
+ alarmCount++;
+ } else {
+ alarmCount = 0;
+ alarmt->stop();
+ }
+}
- if ( !t2 || ( t. minute ( ) != t2-> minute ( ))) {
- // draw minute pointer
- m1 = rotate( center, m1, t.minute() * 6 );
- m2 = rotate( center, m2, t.minute() * 6 );
- p-> setPen ( QPen ( c, 2 ));
- p-> drawLine ( m1, m2 );
- }
+QDateTime Clock::nextAlarm( int h, int m )
+{
+ QDateTime now = QDateTime::currentDateTime();
+ QTime at( h, m );
+ QDateTime when( now.date(), at );
+ int count = 0;
+ int dow = when.date().dayOfWeek();
+ while ( when < now || !dayBtn[dayBtnIdx(dow)]->isOn() ) {
+ when = when.addDays( 1 );
+ dow = when.date().dayOfWeek();
+ if ( ++count > 7 )
+ return QDateTime();
+ }
- if ( !t2 || ( t. second ( ) != t2-> second ( ))) {
- // draw second pointer
- s1 = rotate( center, s1, t.second() * 6 );
- s2 = rotate( center, s2, t.second() * 6 );
- p-> setPen ( QPen ( c, 1 ));
- p-> drawLine ( s1, s2 );
- }
+ return when;
}
-void AnalogClock::display( const QTime& t )
+int Clock::dayBtnIdx( int d ) const
{
- currTime = t;
- clear = false;
- repaint( false );
- clear = true;
+ if ( onMonday )
+ return d-1;
+ else if ( d == 7 )
+ return 0;
+ else
+ return d;
}
-QPoint AnalogClock::rotate( QPoint c, QPoint p, int a )
+void Clock::scheduleApplyDailyAlarm()
{
- double angle = deg2rad * ( - a + 180 );
- double nx = c.x() - ( p.x() - c.x() ) * cos( angle ) -
- ( p.y() - c.y() ) * sin( angle );
- double ny = c.y() - ( p.y() - c.y() ) * cos( angle ) +
- ( p.x() - c.x() ) * sin( angle );
- return QPoint( nx, ny );
+ applyAlarmTimer->start( 5000, TRUE );
}
-void Clock::slotAdjustTime()
+void Clock::applyDailyAlarm()
{
- QCopEnvelope e( "QPE/System", "execute(QString)" );
- e << QString( "systemtime" );
+ if ( !init )
+ return;
+
+ applyAlarmTimer->stop();
+ int minute = dailyMinute->value();
+ int hour = dailyHour->value();
+ if ( ampm ) {
+ if (hour == 12)
+ hour = 0;
+ if (dailyAmPm->currentItem() == 1 )
+ hour += 12;
+ }
+
+ Config config( "Clock" );
+ config.setGroup( "Daily Alarm" );
+ config.writeEntry( "Hour", hour );
+ config.writeEntry( "Minute", minute );
+
+ bool enableDaily = dailyEnabled->isChecked();
+ bool wasSound = config.readEntry( "SoundEnabled" );
+ bool isSound = sndCheck->isChecked();
+ int oldMagic = wasSound ? magic_playmp : magic_daily;
+ int isMagic = isSound ? magic_playmp : magic_daily;
+ config.writeEntry( "Enabled", enableDaily );
+ config.writeEntry( "SoundEnabled", isSound );
+
+ QString exclDays;
+ int exclCount = 0;
+ for ( int i = 1; i <= 7; i++ ) {
+ if ( !dayBtn[dayBtnIdx(i)]->isOn() ) {
+ if ( !exclDays.isEmpty() )
+ exclDays += ",";
+ exclDays += QString::number( i );
+ exclCount++;
+ }
+ }
+ config.writeEntry( "ExcludeDays", exclDays );
+
+ /* try to delete both */
+ AlarmServer::deleteAlarm(QDateTime(), "QPE/Application/clock",
+ "alarm(QDateTime,int)", oldMagic);
+ if ( enableDaily && exclCount < 7 ) {
+ QDateTime when = nextAlarm( hour, minute );
+ AlarmServer::addAlarm(when, "QPE/Application/clock",
+ "alarm(QDateTime,int)", isMagic);
+ }
}
-void Clock::slotStartTimer()
+bool Clock::validDaysSelected(void)
{
- if ( clockRB->isChecked() )
- setSwatchMode( 1);
- startSWatch();
+ for ( int i = 1; i <= 7; i++ ) {
+ if ( dayBtn[dayBtnIdx(i)]->isOn() ) {
+ return TRUE;
+ }
+ }
+ return FALSE;
}
-void Clock::slotStopTimer()
+void Clock::closeEvent( QCloseEvent *e )
{
- if ( clockRB->isChecked() )
- setSwatchMode( 1);
- stopSWatch();
+ if (dailyEnabled->isChecked()) {
+ if (!validDaysSelected()) {
+ QMessageBox::warning(this, tr("Select Day"),
+ tr("Daily alarm requires at least\none day to be selected."));
+ return;
+ }
+ }
+
+ applyDailyAlarm();
+ ClockBase::closeEvent(e);
}
-void Clock::slotResetTimer()
+bool Clock::spinBoxValid( QSpinBox *sb )
{
- if ( clockRB->isChecked() )
- setSwatchMode( 1);
-slotReset();
+ bool valid = TRUE;
+ QString tv = sb->text();
+ for ( uint i = 0; i < tv.length(); i++ ) {
+ if ( !tv[0].isDigit() )
+ valid = FALSE;
+ }
+ bool ok = FALSE;
+ int v = tv.toInt( &ok );
+ if ( !ok )
+ valid = FALSE;
+ if ( v < sb->minValue() || v > sb->maxValue() )
+ valid = FALSE;
+
+ return valid;
}
-void Clock::setSwatchMode(int mode)
-{
- qDebug("Clock::setSwatchMode( %d)", mode);
- swatchRB->setChecked( mode);
- clearClock( );
- modeSelect( mode );
+void Clock::slotBrowseMp3File() {
+ Config config( "qpe" );
+ config.setGroup("Time");
+
+ QMap<QString, QStringList> map;
+ map.insert(tr("All"), QStringList() );
+ QStringList text;
+ text << "audio/*";
+ map.insert(tr("Audio"), text );
+ QString str = Opie::Ui::OFileDialog::getOpenFileName( 2,"/", QString::null, map);
+ if(!str.isEmpty() ) {
+ config.writeEntry("mp3Alarm",1);
+ config.writeEntry("mp3File",str);
+ sndFileName->setText( str );
+ scheduleApplyDailyAlarm();
+ }
}
diff --git a/noncore/tools/clock/clock.h b/noncore/tools/clock/clock.h
index 00d097d..c063a9b 100644
--- a/noncore/tools/clock/clock.h
+++ b/noncore/tools/clock/clock.h
@@ -1,7 +1,7 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
@@ -20,50 +20,39 @@
#ifndef CLOCK_H
#define CLOCK_H
+#include "clockbase.h"
+#include "alarmdlgbase.h"
#include <qdatetime.h>
-#include <qvbox.h>
-#include <qpixmap.h>
-class QLCDNumber;
-class QLabel;
class QTimer;
-class QRadioButton;
-class QPushButton;
-class QDateTime;
+class QLabel;
+class QDialog;
+class AnalogClock;
+class QBoxLayout;
+class QToolButton;
-class AnalogClock : public QFrame
+class AlarmDlg: public AlarmDlgBase
{
Q_OBJECT
public:
- AnalogClock( QWidget * parent = 0, const char * name = 0 );
-
- QSizePolicy sizePolicy() const;
-
- void display( const QTime& time );
-
-
-protected:
- void drawContents( QPainter *p );
-
-private:
+ AlarmDlg(QWidget *parent = 0, const char *name = 0, bool modal = TRUE,
+ const QString &txt = "Alarm");
- QPixmap bg;
- QTime currTime;
- QTime prevTime;
- bool clear;
+ void setText(const QString &txt);
- QPoint rotate( QPoint center, QPoint p, int angle );
- void drawPointers ( QPainter *, const QRect &r, const QColor &c, const QTime &t, const QTime *t2 = 0 );
+private slots:
+ void checkSnooze(void);
+ void changePrompt(int minutes);
};
-class Clock : public QVBox
+class Clock : public ClockBase
{
Q_OBJECT
public:
- Clock( QWidget * parent = 0, const char * name = 0, WFlags f=0 );
+ Clock( QWidget *parent=0, const char *name=0, WFlags fl=0 );
~Clock();
QDateTime when;
bool bSound;
@@ -71,41 +60,56 @@ public:
static QString appName() { return QString::fromLatin1("clock"); }
private slots:
- void slotSet();
- void slotReset();
- void modeSelect(int);
+ void stopStartStopWatch();
+ void resetStopWatch();
+ void prevLap();
+ void nextLap();
+ void lapTimeout();
+ void tabChanged(QWidget*);
void updateClock();
void changeClock( bool );
- void slotSetAlarm();
- void slotSnooze();
- void slotToggleAlarm();
- void alarmOn();
- void alarmOff();
+ void setDailyAmPm( int );
+ void setDailyMinute( int );
+ void dailyEdited();
+ void enableDaily( bool );
void appMessage(const QCString& msg, const QByteArray& data);
- void timerEvent( QTimerEvent *e );
- void slotAdjustTime();
+ void alarmTimeout();
+ void applyDailyAlarm();
+ void scheduleApplyDailyAlarm();
+ void slotBrowseMp3File();
+
+protected:
+ QDateTime nextAlarm( int h, int m );
+ int dayBtnIdx( int ) const;
+ void closeEvent( QCloseEvent *e );
+ void updateLap();
+ void setSwatchLcd( QLCDNumber *lcd, int ms, bool showMs );
+ bool eventFilter( QObject *, QEvent * );
+ bool spinBoxValid( QSpinBox *sb );
+ bool validDaysSelected(void);
- void slotStartTimer();
- void slotStopTimer();
- void slotResetTimer();
- void setSwatchMode( int );
private:
- bool alarmBool;
QTimer *t;
- QLCDNumber *lcd;
- QLabel *date;
- QLabel *ampmLabel;
- QPushButton *set, *reset, *alarmBtn, *snoozeBtn, *alarmOffBtn;
- QRadioButton *clockRB, *swatchRB;
- AnalogClock *aclock;
+ QTimer *alarmt;
QTime swatch_start;
int swatch_totalms;
+ QArray<int> swatch_splitms;
bool swatch_running;
+ int swatch_currLap;
+ int swatch_dispLap;
+ QToolButton *prevLapBtn;
+ QToolButton *nextLapBtn;
+ QTimer *lapTimer;
+ AnalogClock* analogStopwatch;
+ QLCDNumber* stopwatchLcd;
+ QBoxLayout *swLayout;
bool ampm;
- void clearClock();
- void clearTimer();
- void startSWatch();
- void stopSWatch();
+ bool onMonday;
+ int alarmCount;
+ AlarmDlg* alarmDlg;
+ QToolButton **dayBtn;
+ bool init;
+ QTimer *applyAlarmTimer;
};
#endif
diff --git a/noncore/tools/clock/clock.pro b/noncore/tools/clock/clock.pro
index ad5c205..90a8d29 100644
--- a/noncore/tools/clock/clock.pro
+++ b/noncore/tools/clock/clock.pro
@@ -1,10 +1,15 @@
CONFIG = qt warn_on quick-app
-HEADERS = clock.h setAlarm.h
-SOURCES = clock.cpp setAlarm.cpp \
+HEADERS = clock.h analogclock.h
+SOURCES = clock.cpp analogclock.cpp \
main.cpp
+
INCLUDEPATH += $(OPIEDIR)/include
DEPENDPATH += $(OPIEDIR)/include
LIBS += -lqpe -lopiecore2 -lopieui2 -lpthread
TARGET = clock
+
+INTERFACES = clockbase.ui \
+ alarmdlgbase.ui
+
include ( $(OPIEDIR)/include.pro )
diff --git a/noncore/tools/clock/clockbase.ui b/noncore/tools/clock/clockbase.ui
index 91d0da0..0e1a90e 100644
--- a/noncore/tools/clock/clockbase.ui
+++ b/noncore/tools/clock/clockbase.ui
@@ -11,8 +11,8 @@
<rect>
<x>0</x>
<y>0</y>
- <width>220</width>
- <height>337</height>
+ <width>287</width>
+ <height>389</height>
</rect>
</property>
<property stdset="1">
@@ -516,11 +516,11 @@
<vbox>
<property stdset="1">
<name>margin</name>
- <number>6</number>
+ <number>-1</number>
</property>
<property stdset="1">
<name>spacing</name>
- <number>4</number>
+ <number>-1</number>
</property>
<widget>
<class>QGroupBox</class>
@@ -870,10 +870,77 @@
</widget>
</grid>
</widget>
+ <widget>
+ <class>QGroupBox</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>sndGroup</cstring>
+ </property>
+ <property stdset="1">
+ <name>title</name>
+ <string>Play Sound</string>
+ </property>
+ <vbox>
+ <property stdset="1">
+ <name>margin</name>
+ <number>11</number>
+ </property>
+ <property stdset="1">
+ <name>spacing</name>
+ <number>6</number>
+ </property>
+ <widget>
+ <class>QCheckBox</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>sndCheck</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>Play File</string>
+ </property>
+ </widget>
+ <widget>
+ <class>QLayoutWidget</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>Layout6</cstring>
+ </property>
+ <hbox>
+ <property stdset="1">
+ <name>margin</name>
+ <number>0</number>
+ </property>
+ <property stdset="1">
+ <name>spacing</name>
+ <number>6</number>
+ </property>
+ <widget>
+ <class>QLineEdit</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>sndFileName</cstring>
+ </property>
+ </widget>
+ <widget>
+ <class>QToolButton</class>
+ <property stdset="1">
+ <name>name</name>
+ <cstring>sndChoose</cstring>
+ </property>
+ <property stdset="1">
+ <name>text</name>
+ <string>...</string>
+ </property>
+ </widget>
+ </hbox>
+ </widget>
+ </vbox>
+ </widget>
<spacer>
<property>
<name>name</name>
- <cstring>Spacer1</cstring>
+ <cstring>Spacer3</cstring>
</property>
<property stdset="1">
<name>orientation</name>
@@ -918,4 +985,38 @@
<data format="XPM.GZ" length="646">789c6dd2c10ac2300c00d07bbf2234b7229d1be245fc04c5a3201e4615f430059d0711ff5ddb2e6bb236ec90eed134cb5a19d8ef36602af5ecdbfeeac05dda0798d3abebde87e3faa374d3807fa0d633a52d38d8de6f679fe33fc776e196f53cd010188256a3600a292882096246517815ca99884606e18044a3a40d91824820924265a7923a2e8bcd05f33db1173e002913175f2a6be6d3294871a2d95fa00e8a94ee017b69d339d90df1e77c57ea072ede6758</data>
</image>
</images>
+<connections>
+ <connection>
+ <sender>dailyEnabled</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>sndGroup</receiver>
+ <slot>setEnabled(bool)</slot>
+ </connection>
+ <connection>
+ <sender>sndCheck</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>sndFileName</receiver>
+ <slot>setEnabled(bool)</slot>
+ </connection>
+ <connection>
+ <sender>sndCheck</sender>
+ <signal>toggled(bool)</signal>
+ <receiver>sndChoose</receiver>
+ <slot>setEnabled(bool)</slot>
+ </connection>
+ <connection>
+ <sender>sndChoose</sender>
+ <signal>clicked()</signal>
+ <receiver>ClockBase</receiver>
+ <slot>slotBrowseMp3File()</slot>
+ </connection>
+ <connection>
+ <sender>sndCheck</sender>
+ <signal>stateChanged(int)</signal>
+ <receiver>ClockBase</receiver>
+ <slot>scheduleApplyDailyAlarm()</slot>
+ </connection>
+ <slot access="public">scheduleApplyDailyAlarm()</slot>
+ <slot access="protected">slotBrowseMp3File()</slot>
+</connections>
</UI>
diff --git a/noncore/tools/clock/main.cpp b/noncore/tools/clock/main.cpp
index 237d9f0..380bfeb 100644
--- a/noncore/tools/clock/main.cpp
+++ b/noncore/tools/clock/main.cpp
@@ -1,7 +1,7 @@
/**********************************************************************
-** Copyright (C) 2000 Trolltech AS. All rights reserved.
+** Copyright (C) 2000-2002 Trolltech AS. All rights reserved.
**
-** This file is part of Qtopia Environment.
+** This file is part of the Qtopia Environment.
**
** This file may be distributed and/or modified under the terms of the
** GNU General Public License version 2 as published by the Free Software
@@ -19,10 +19,6 @@
**********************************************************************/
#include "clock.h"
-
#include <opie2/oapplicationfactory.h>
-
-
-using namespace Opie::Core;
using namespace Opie::Core;
OPIE_EXPORT_APP( OApplicationFactory<Clock> )