-rw-r--r-- | kalarmd/simplealarmdaemonimpl.cpp | 102 | ||||
-rw-r--r-- | kalarmd/simplealarmdaemonimpl.h | 33 |
2 files changed, 121 insertions, 14 deletions
diff --git a/kalarmd/simplealarmdaemonimpl.cpp b/kalarmd/simplealarmdaemonimpl.cpp index 50c4605..ec7f730 100644 --- a/kalarmd/simplealarmdaemonimpl.cpp +++ b/kalarmd/simplealarmdaemonimpl.cpp @@ -18,65 +18,71 @@ As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #include "simplealarmdaemonimpl.h" #include "alarmdialog.h" #include <qpopupmenu.h> #include <qapp.h> #include <qdir.h> #include <qfile.h> #include <qhbox.h> #include <qtimer.h> #include <qfile.h> +#include <qdatetime.h> +#include <qpushbutton.h> #include <qlayout.h> #include <qlineedit.h> #include <qdialog.h> +#define protected public #include <qspinbox.h> +#undef protected #include <qtextstream.h> #include <qtopia/qcopenvelope_qws.h> #include <qtopia/alarmserver.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> SimpleAlarmDaemonImpl::SimpleAlarmDaemonImpl( QWidget *parent ) : QLabel( parent ) { mAlarmDialog = new AlarmDialog( 0 ); mPopUp = new QPopupMenu( this ); mPopUp->insertItem( "What's Next?", this, SLOT ( showWN() ) ); mPopUp->insertItem( "Next Days!", this, SLOT ( showKO() ) ); mPopUp->insertSeparator(); mPopUp->insertItem( "What's Todo?", this, SLOT ( showTodo() ) ); mPopUp->insertSeparator(); mPopUp->insertItem( "Addresses", this, SLOT ( showAdd() ) ); mPopUp->insertSeparator(); mPopUp->insertItem( "Edit Journal", this, SLOT ( writeJournal() ) ); mPopUp->insertItem( "New Event", this, SLOT ( newEvent() ) ); mPopUp->insertItem( "New Todo", this, SLOT ( newTodo() ) ); mPopUp->insertItem( "New Mail", this, SLOT ( newMail() ) ); mPopUp->insertSeparator(); mPopUp->insertItem( "Multi Sync", this, SLOT ( ringSync() ) ); mTimerPopUp = new QPopupMenu( this ); - + QFont fon = mTimerPopUp->font(); + fon.setPointSize( fon.pointSize() *3/2 ); + mTimerPopUp->setFont( fon ); mBeepPopUp = new QPopupMenu( this ); mSoundPopUp = new QPopupMenu( this ); mPausePopUp = new QPopupMenu( this ); QPopupMenu* savePopUp = new QPopupMenu( this ); savePopUp->insertItem( "Save", 0 ); savePopUp->insertItem( "Load", 1 ); mSoundPopUp->insertItem( "Buzzer", 0 ); mSoundPopUp->insertItem( "Wav file", 1 ); mPausePopUp->insertItem( " 1 sec", 1 ); mPausePopUp->insertItem( " 2 sec", 2 ); mPausePopUp->insertItem( " 3 sec", 3 ); mPausePopUp->insertItem( " 5 sec", 5 ); mPausePopUp->insertItem( "10 sec", 10 ); mPausePopUp->insertItem( "30 sec", 30 ); mPausePopUp->insertItem( " 1 min", 60 ); mPausePopUp->insertItem( " 5 min", 300 ); @@ -342,49 +348,52 @@ int SimpleAlarmDaemonImpl::getFileNameLen( QString mess ) void SimpleAlarmDaemonImpl::startAlarm( QString mess, QString filename ) { //mAlarmDialog->show(); //mAlarmDialog->raise(); mAlarmDialog->eventNotification( mess, mPlayBeeps, filename, wavAlarm,mPausePlay ,mSuspend ); } void SimpleAlarmDaemonImpl::fillTimerPopUp() { // qDebug(" timer %d %d ",mTimerPopupConf, mTimerTime ); if ( mTimerPopupConf == mTimerTime ) { if ( mTimerTime ) { int secs = QDateTime::currentDateTime().secsTo ( mRunningTimer ); QTime t ( secs/3600, (secs/60)%60, secs%60 ); - mTimerPopUp->changeItem ( 1 , t.toString()); + mTimerPopUp->changeItem ( 1 , t.toString() + " (remaining time)"); } else { QString text = mCustomText.stripWhiteSpace (); int in = text.find( " " ); text = text.left ( in ); mTimerPopUp->changeItem ( 3, text ); } return; } mTimerPopupConf = mTimerTime; mTimerPopUp->clear(); if ( mTimerTime ) { int secs = QDateTime::currentDateTime().secsTo ( mRunningTimer ); QTime t ( secs/3600, (secs/60)%60, secs%60 ); - mTimerPopUp->insertItem( "Stop", 0 ); - mTimerPopUp->insertItem( t.toString(),1); + + + mTimerPopUp->insertItem( "Stop timer "+ mRunningTimerText , 0 ); + mTimerPopUp->insertItem( t.toString() + " (remaining time)",1); + mTimerPopUp->insertItem( mRunningTimer.time().toString() + " (alarm time)",2); } else { QString fileName = QDir::homeDirPath() +"/.kopialarmtimerrc"; QFile file( fileName ); if( !QFile::exists( fileName) ) { // write defaults if (!file.open( IO_WriteOnly ) ) { return; } QString configString ; configString += "#config file for kopi alarm timer\n"; configString += "#format: <Text for popup menu>;<timer countdown in minutes>\n"; configString += "#NOTE: minimum value for timer are 3 minutes!\n"; configString += "24 h; 1440\n"; configString += " 8 h; 480\n"; configString += " 5 h; 300\n"; @@ -451,100 +460,165 @@ void SimpleAlarmDaemonImpl::fillTimerPopUp() } void SimpleAlarmDaemonImpl::showTimer() { fillTimerPopUp(); } void SimpleAlarmDaemonImpl::confTimer( int time ) { //qDebug("impleAlarmDaemonImpl::confTimer() %d ", time ); int minutes = time; if ( minutes == 0 ) { if ( ! mTimerTime ) return; QDialog dia ( 0, ("Stop Timer" ), true ); - QLabel lab (("Really stop the timer?"), &dia ); + QLabel lab (("Really stop the timer?\n\n"+ mRunningTimerText+"\n"), &dia ); + lab.setAlignment( AlignCenter ); dia.setCaption(("KO/Pi Timer Stop" )); QVBoxLayout lay( &dia ); + lay.addWidget( &lab); + QPushButton ok ( "Stop timer!", &dia); + QFont fo = dia.font(); + fo.setPointSize( 36 ); + ok.setFont( fo ); + lay.addWidget( &ok); + connect ( &ok, SIGNAL (clicked()), &dia, SLOT ( accept() ) ); + QPushButton con ( "Continue timer!", &dia); + fo.setPointSize( 36 ); + con.setFont( fo ); + lay.addWidget( &con); + connect ( &con, SIGNAL (clicked()), &dia, SLOT ( reject() ) ); lay.setMargin(5); lay.setSpacing(5); - lay.addWidget( &lab); - dia.resize( 200, dia.sizeHint().height() ); + dia.resize(dia.sizeHint() ); if ( !dia.exec() ) return; AlarmServer::deleteAlarm ( mRunningTimer,"koalarm" , timerMesssage.latin1() ); mTimerTime = 0; return; } if ( mTimerTime ) return; if ( minutes == 1 ) { return; } QString mess = "timer_alarm"; mess += ("Timer Alarm!\n"); - if ( minutes == 22 ) + if ( minutes == 22 ) { mess += ( "Pizza is ready"); - else if ( minutes == 45 ) + mRunningTimerText = "Pizza"; + } + else if ( minutes == 45 ) { mess += ( "Please wake up!"); - else if ( minutes == 5 ) + mRunningTimerText = "Nap"; + } + else if ( minutes == 5 ) { mess += ( "Tea is ready"); + mRunningTimerText = "Tea"; + } else if ( minutes == 3 ) { mess += mCustomText; minutes = mCustomMinutes ; + mRunningTimerText = mCustomText.stripWhiteSpace (); + int in = mRunningTimerText.find( " " ); + mRunningTimerText = mRunningTimerText.left ( in ); } else { if ( minutes == 2 ) { // ask time QDialog dia ( 0, ("Customize Timer" ), true ); QLabel lab (("Message Text:"), &dia ); dia.setCaption(("KO/Pi Timer" )); QVBoxLayout lay( &dia ); lay.setMargin(5); lay.setSpacing(5); lay.addWidget( &lab); QLineEdit lEdit( mCustomText, &dia ); lay.addWidget( &lEdit); QLabel lab2 (("Countdown time (1 min - 24 h):"), &dia ); lay.addWidget( &lab2); + QHBox hbox1 ( &dia ); + lay.addWidget( &hbox1); + QLabel lab3 (("Hours"), &hbox1 ); + QLabel lab4 (("Minutes"), &hbox1 ); QHBox hbox ( &dia ); - QLabel lab3 (("h:"), &hbox ); QSpinBox spinh( 0, 24, 1,& hbox ); - QLabel lab4 ((" min:"), &hbox ); + QFont fo = dia.font(); + fo.setPointSize( 36 ); QSpinBox spinm( 0, 59, 1,&hbox ); + spinm.setFont( fo ); + spinh.setFont( fo ); + spinh.setButtonSymbols( QSpinBox::PlusMinus ); + spinm.setButtonSymbols( QSpinBox::PlusMinus ); + spinh.upButton ()->setFixedSize( QSize( 48, 30 )); + spinh.downButton ()->setFixedSize( QSize( 48, 30 )); + //spinh.editor ()->setFixedSize( QSize( 50, 100 )); + spinh.setFixedSize( 100,62 ); + spinm.upButton ()->setFixedSize( QSize( 48, 30 )); + spinm.downButton ()->setFixedSize( QSize( 48, 30 )); + spinm.downButton ()->setGeometry( 50,50,50,50); + spinm.setSuffix( " m" ); + spinh.setSuffix( " h" ); + spinm.setWrapping ( true ); + //spinm.editor ()->setFixedSize( QSize( 50, 100 )); + spinm.setLineStep( 1 ); + spinm.setFixedSize( 110,62 ); + lay.addWidget( &hbox); + QLabel lab5 ("Timer fires at:", &dia ); + lab5.setAlignment( AlignCenter ); + lay.addWidget( &lab5); + KODateLabel dl ( &dia ); + dl.setAlignment( AlignCenter ); + dl.setFont( fo ); + connect ( &spinh, SIGNAL ( valueChanged (int)), &dl, SLOT ( slot_hours( int ) ) ); + connect ( &spinm, SIGNAL ( valueChanged (int)), &dl, SLOT ( slot_minutes( int ) ) ); + lay.addWidget( &dl); spinh.setValue( mCustomMinutes/60 ); spinm.setValue( mCustomMinutes%60 ); - lay.addWidget( &hbox); + QPushButton ok ( "Start timer", &dia); + ok.setFont( fo ); + lay.addWidget( &ok); + connect ( &ok, SIGNAL (clicked()), &dia, SLOT ( accept() ) ); dia.resize( dia.sizeHint().width(), dia.sizeHint().height() ); + if ( !dia.exec() ) return; mCustomText = lEdit.text(); mCustomMinutes = spinh.value()*60+spinm.value(); if ( mCustomMinutes == 0 ) mCustomMinutes = 1; if ( mCustomMinutes > 1440 ) mCustomMinutes = 1440; mess += mCustomText; minutes = mCustomMinutes; + mRunningTimerText = mCustomText.stripWhiteSpace (); + int in = mRunningTimerText.find( " " ); + mRunningTimerText = mRunningTimerText.left ( in ); } - else + else { mess+= QString::number ( minutes ) + ( " minutes are past!"); + int min = minutes; + if ( min % 60 == 0 ) + mRunningTimerText = QString::number ( min/60 ) + ( " hours"); + else + mRunningTimerText = QString::number ( minutes ) + ( " minutes"); + } } //minutes = 1; mRunningTimer = QDateTime::currentDateTime().addSecs( minutes * 60 ); timerMesssage = mess; AlarmServer::addAlarm ( mRunningTimer,"koalarm",timerMesssage.latin1()); mTimerTime = 1; } void SimpleAlarmDaemonImpl::writeFile() { QCopEnvelope e("QPE/Application/kopi", "-writeFile"); } void SimpleAlarmDaemonImpl::showWN() { QCopEnvelope e("QPE/Application/kopi", "-showWN"); } diff --git a/kalarmd/simplealarmdaemonimpl.h b/kalarmd/simplealarmdaemonimpl.h index 32a3867..cbdba47 100644 --- a/kalarmd/simplealarmdaemonimpl.h +++ b/kalarmd/simplealarmdaemonimpl.h @@ -13,32 +13,33 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. As a special exception, permission is given to link this program with any edition of Qt, and distribute the resulting executable, without including the source code for Qt in the source distribution. */ #ifndef SIMPLEALARMDAEMONIMPL_H #define SIMPLEALARMDAEMONIMPL_H //#include "simplealarmdaemon.h" #include <qdatetime.h> #include <qlabel.h> +#include <qtimer.h> class QLabel; class QTimer; class QPopupMenu; class AlarmDialog; class SimpleAlarmDaemonImpl : public QLabel { Q_OBJECT public: SimpleAlarmDaemonImpl( QWidget *parent = 0 ); ~SimpleAlarmDaemonImpl(); protected slots: void recieve( const QCString& msg, const QByteArray& data ); void newTodo(); @@ -65,22 +66,54 @@ class SimpleAlarmDaemonImpl : public QLabel protected: void mousePressEvent( QMouseEvent * ); private: AlarmDialog *mAlarmDialog; int mPlayBeeps; int mPausePlay; int mSuspend; QString mAlarmMessage; int mTimerTime; int getFileNameLen( QString ); QPopupMenu* mPopUp, *mBeepPopUp, *mTimerPopUp, *mSoundPopUp,*mPausePopUp,*mSuspendPopUp; QDateTime mRunningTimer; void fillTimerPopUp(); QString timerMesssage; QString mCustomText; + QString mRunningTimerText; int mCustomMinutes; int mTimerPopupConf; bool wavAlarm; }; +class KODateLabel : public QLabel +{ + Q_OBJECT + public: + KODateLabel( QWidget *parent=0, const char *name=0 ) : + QLabel( parent, name ) + { + hour = 0; + minutes = 0; + QTimer * ti = new QTimer( this ); + connect ( ti, SIGNAL ( timeout () ), this, SLOT ( updateText() )); + ti->start( 1000 ); + } +public slots: + void slot_minutes( int m ) + { + minutes = m; updateText(); + } + void slot_hours( int h ) + { + hour = h; updateText(); + } +private slots: + void updateText() + { + QDateTime dt = QDateTime::currentDateTime(); + dt = dt.addSecs( minutes * 60 + hour * 3600 ); + setText( dt.time().toString() ); + } + int hour, minutes; +}; #endif |