Diffstat (limited to 'kalarmd/simplealarmdaemonimpl.cpp') (more/less context) (show whitespace changes)
-rw-r--r-- | kalarmd/simplealarmdaemonimpl.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/kalarmd/simplealarmdaemonimpl.cpp b/kalarmd/simplealarmdaemonimpl.cpp index 141a9ce..15eff28 100644 --- a/kalarmd/simplealarmdaemonimpl.cpp +++ b/kalarmd/simplealarmdaemonimpl.cpp @@ -257,478 +257,491 @@ void SimpleAlarmDaemonImpl::saveSlot( int load ) configString += "CUMI " + QString::number( mCustomMinutes ) + "\n"; configString += "SUTI " + QString::number( mAlarmDialog->getSuspendTime( )) + "\n"; QTextStream ts( &file ); ts << configString ; file.close(); } } void SimpleAlarmDaemonImpl::confSuspend( int num ) { mSuspendPopUp->setItemChecked ( mSuspend,false ); mSuspend = num; mSuspendPopUp->setItemChecked ( mSuspend,true ); } void SimpleAlarmDaemonImpl::confPause( int num ) { mPausePopUp->setItemChecked ( mPausePlay,false ); mPausePlay = num; mPausePopUp->setItemChecked ( mPausePlay,true ); } void SimpleAlarmDaemonImpl::confSound( int num ) { if ( num == 0 ) { wavAlarm = false; mSoundPopUp->setItemChecked ( 0, true ); mSoundPopUp->setItemChecked ( 1, false ); } else { wavAlarm = true; mSoundPopUp->setItemChecked ( 0, false ); mSoundPopUp->setItemChecked ( 1, true ); } } void SimpleAlarmDaemonImpl::slotPlayBeep( int num ) { if ( num == 1000 ) { simulate(); return; } mBeepPopUp->setItemChecked ( mPlayBeeps,false ); mPlayBeeps = num; mBeepPopUp->setItemChecked ( mPlayBeeps, true ); } void SimpleAlarmDaemonImpl::recieve( const QCString& msg, const QByteArray& ) { //qDebug("SimpleAlarmDaemonImpl::ALARM RECEIVED! %s", msg.data()); QString mess = QString::fromUtf8(msg.data()); mAlarmMessage = mess.mid( 9 ); QString filename = getenv("QPEDIR") ; filename += "/pics/kdepim/korganizer/koalarm.wav"; QString tempfilename; if ( mess.left( 13 ) == "suspend_alarm") { bool error = false; int len = mess.mid( 13 ).find("+++"); if ( len < 2 ) error = true; else { tempfilename = mess.mid( 13, len ); if ( !QFile::exists( tempfilename ) ) error = true; } if ( ! error ) { filename = tempfilename; } mAlarmMessage = mess.mid( 13+len+3 ); //qDebug("suspend file %s ",tempfilename.latin1() ); startAlarm( mAlarmMessage, filename); return; } if ( mess.left( 11 ) == "timer_alarm") { mTimerTime = 0; startAlarm( mess.mid( 11 ), filename ); return; } if ( mess.left( 10 ) == "proc_alarm") { bool error = false; int len = mess.mid( 10 ).find("+++"); if ( len < 2 ) error = true; else { tempfilename = mess.mid( 10, len ); if ( !QFile::exists( tempfilename ) ) error = true; } if ( error ) { mAlarmMessage = "Procedure Alarm\nError - File not found\n"; mAlarmMessage += mess.mid( 10+len+3+9 ); } else { //qDebug("-----system command %s ",tempfilename.latin1() ); if ( vfork () == 0 ) { execl ( tempfilename.latin1(), 0 ); return; } QTimer::singleShot( 2000, this, SLOT ( writeFile() ) ); return; } //qDebug("+++++++system command %s ",tempfilename.latin1() ); } if ( mess.left( 11 ) == "audio_alarm") { bool error = false; int len = mess.mid( 11 ).find("+++"); if ( len < 2 ) error = true; else { tempfilename = mess.mid( 11, len ); if ( !QFile::exists( tempfilename ) ) error = true; } if ( ! error ) { filename = tempfilename; } mAlarmMessage = mess.mid( 11+len+3+9 ); //qDebug("audio file command %s ",tempfilename.latin1() ); } if ( mess.left( 9 ) == "cal_alarm") { mAlarmMessage = mess.mid( 9 ) ; } QTimer::singleShot( 2000, this, SLOT ( writeFile() ) ); startAlarm( mAlarmMessage, filename ); } int SimpleAlarmDaemonImpl::getFileNameLen( QString mess ) { return 0; } 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() + " (countdown)"); } 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 timer "+ mRunningTimerText , 0 ); mTimerPopUp->insertItem( t.toString() + " (countdown)",1); mTimerPopUp->insertItem( mRunningTimer.time().toString() + " (alarm)",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 += "24 hours; 1440\n"; configString += "9 hours; 540\n"; configString += "8 hours; 480\n"; configString += "1 hour; 60\n"; configString += "30 min; 30\n"; configString += "15 min; 15\n"; configString += "SEPARATOR\n"; configString += "Pizza; 22\n"; configString += "Nap; 45\n"; configString += "Tea; 5\n"; QTextStream ts( &file ); ts << configString ; file.close(); } if (!file.open( IO_ReadOnly ) ) { return ; } QString line; bool ok; while ( file.readLine( line, 1024 ) > 0 ) { //qDebug("read %s ", line.latin1()); if ( line.left(1 ) != "#" ) { // no comment if ( line.left(9 ) == "SEPARATOR" ) { mTimerPopUp->insertSeparator(); } else { QStringList li = QStringList::split(";",line); ok = false; if ( li.count() == 2 ) { int val = li[1].toInt( &ok ); if ( ok && val > 0 ) { mTimerPopUp->insertItem( li[0], val+10); } } } } } file.close(); #if 0 mTimerPopUp->insertItem( "24 hours", 1440 ); // mTimerPopUp->insertItem( i18n("12 h"), 720 ); mTimerPopUp->insertItem( " 8 hours", 480 ); mTimerPopUp->insertItem( " 5 hours", 300 ); // mTimerPopUp->insertItem( i18n(" 2 h"), 120 ); mTimerPopUp->insertItem( " 1 hour", 60 ); mTimerPopUp->insertItem( "30 min", 30 ); mTimerPopUp->insertItem( "15 min", 15 ); mTimerPopUp->insertItem( "10 min", 10 ); //mTimerPopUp->insertItem( " 5 min", 5 ); mTimerPopUp->insertSeparator(); mTimerPopUp->insertItem( "Pizza", 22 ); mTimerPopUp->insertItem( "Nap", 45 ); mTimerPopUp->insertItem( "Tea", 5 ); #endif QString text = mCustomText.stripWhiteSpace (); int in = text.find( " " ); text = text.left ( in ); mTimerPopUp->insertItem( text, 3 ); mTimerPopUp->insertSeparator(); mTimerPopUp->insertItem( "Customize", 2 ); } } 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?\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); dia.resize(dia.sizeHint() ); if ( !dia.exec() ) return; AlarmServer::deleteAlarm ( mRunningTimer,"koalarm" , timerMesssage.utf8() ); mTimerTime = 0; return; } if ( mTimerTime ) return; if ( minutes == 1 ) { return; } QString mess = "timer_alarm"; QString disp; mess += ("Timer Alarm!\n"); if ( minutes == 3 ) { mess += mCustomText; minutes = mCustomMinutes ; mRunningTimerText = mCustomText.stripWhiteSpace (); int in = mRunningTimerText.find( " " ); mRunningTimerText = mRunningTimerText.left ( in ); disp = mCustomText; } 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 ); QSpinBox spinh( 0, 24, 1,& 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 ); QPushButton ok ( "Start timer", &dia); ok.setDefault( true ); ok.setFont( fo ); spinh.setFocus(); 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; disp = mCustomText; minutes = mCustomMinutes; mRunningTimerText = mCustomText.stripWhiteSpace (); int in = mRunningTimerText.find( " " ); mRunningTimerText = mRunningTimerText.left ( in ); } else { mess += mTimerPopUp->text( minutes ); disp = mTimerPopUp->text( minutes ); mRunningTimerText = mTimerPopUp->text( minutes ); minutes -= 10; } } //minutes = 1; mRunningTimer = QDateTime::currentDateTime().addSecs( minutes * 60 ); timerMesssage = mess; + QString timerDuration ; + if ( minutes < 60 ) { + timerDuration = QString::number( minutes ) + " min"; + } else { + if ( minutes % 60 ) { + timerDuration = QString::number( minutes/60 ) +":"; + minutes = minutes%60; + if ( minutes < 10 ) timerDuration += "0"; + timerDuration += QString::number( minutes ) + " h"; + } + else + timerDuration = QString::number( minutes / 60 )+ " hours"; + } AlarmServer::addAlarm ( mRunningTimer,"koalarm",timerMesssage.utf8()); - mTimerStartLabel->setText( disp + "\n\nTimer started!" ); + mTimerStartLabel->setText( disp + "\n\n" + timerDuration +"\n\nTimer started!" ); int w = mTimerStartLabel->sizeHint().width()+20; int h = mTimerStartLabel->sizeHint().height()+40 ; int dw = QApplication::desktop()->width(); int dh = QApplication::desktop()->height(); mTimerStartLabel->setGeometry( (dw-w)/2, (dh - h )/2 ,w,h ); mTimerStartLabel->show(); QTimer::singleShot( 4000, mTimerStartLabel, SLOT ( hide() ) ); mTimerTime = 1; } void SimpleAlarmDaemonImpl::confFontSize( int size ) { mFontsizePopup->setItemChecked( mPopupFontSize, false ); mPopupFontSize = size; mFontsizePopup->setItemChecked( mPopupFontSize, true ); QFont fon = mTimerPopUp->font(); fon.setPointSize( mPopupFontSize ); mTimerPopUp->setFont( fon ); mPopUp->setFont( fon ); fon.setBold( true ); fon.setPointSize( mPopupFontSize * 2 ); mTimerStartLabel->setFont( fon ); } void SimpleAlarmDaemonImpl::writeFile() { QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); //QCopEnvelope e("QPE/Application/kopi", "-writeFile"); } void SimpleAlarmDaemonImpl::showWN() { QCopEnvelope e("QPE/Application/kopi", "-showWN"); } void SimpleAlarmDaemonImpl::newTodo() { QCopEnvelope e("QPE/Application/kopi", "-newTodo"); } void SimpleAlarmDaemonImpl::newEvent() { QCopEnvelope e("QPE/Application/kopi", "-newEvent"); } void SimpleAlarmDaemonImpl::newMail() { QCopEnvelope e("QPE/Application/ompi", "newMail()"); } void SimpleAlarmDaemonImpl::showAdd() { QCopEnvelope e("QPE/Application/kapi", "raise()"); } void SimpleAlarmDaemonImpl::ringSync() { QCopEnvelope e("QPE/Application/kopi", "-ringSync"); } void SimpleAlarmDaemonImpl::newCountdown() { //recieve("cal_alarm", 10 ); } void SimpleAlarmDaemonImpl::simulate() { QTimer::singleShot( 2000, this, SLOT ( writeFile() ) ); QString filename = getenv("QPEDIR") ; filename += "/pics/kdepim/korganizer/koalarm.wav"; startAlarm("Alarm simulation", filename ); } void SimpleAlarmDaemonImpl::showKO() { QCopEnvelope e("QPE/Application/kopi", "-showKO"); // testing only //QCopEnvelope e("QPE/Application/kopi", "nextView()"); } void SimpleAlarmDaemonImpl::showTodo() { QCopEnvelope e("QPE/Application/kopi", "-showTodo"); } void SimpleAlarmDaemonImpl::writeJournal() { QCopEnvelope e("QPE/Application/kopi", "-showJournal"); } void SimpleAlarmDaemonImpl::mousePressEvent( QMouseEvent * ) { mPopUp->popup(mapToGlobal(QPoint (0, -mPopUp->height() ))); } |