-rw-r--r-- | kalarmd/simplealarmdaemonimpl.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/kalarmd/simplealarmdaemonimpl.cpp b/kalarmd/simplealarmdaemonimpl.cpp index 471836b..18e4299 100644 --- a/kalarmd/simplealarmdaemonimpl.cpp +++ b/kalarmd/simplealarmdaemonimpl.cpp @@ -280,206 +280,259 @@ void SimpleAlarmDaemonImpl::recieve( const QCString& msg, const QByteArray& ) 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 { QCopEnvelope e("QPE/Application/kopi", "-writeFileSilent"); //qDebug("-----system command %s ",tempfilename.latin1() ); if ( vfork () == 0 ) { execl ( tempfilename.latin1(), 0 ); return; } 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 ) ; } 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()); } 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); } 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"; + configString += " 1 h; 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 > 2 ) { + mTimerPopUp->insertItem( li[0], val); + } + } + } + } + } + file.close(); +#if 0 mTimerPopUp->insertItem( "24 h", 1440 ); // mTimerPopUp->insertItem( i18n("12 h"), 720 ); mTimerPopUp->insertItem( " 8 h", 480 ); mTimerPopUp->insertItem( " 5 h", 300 ); // mTimerPopUp->insertItem( i18n(" 2 h"), 120 ); mTimerPopUp->insertItem( " 1 h", 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?"), &dia ); dia.setCaption(("KO/Pi Timer Stop" )); QVBoxLayout lay( &dia ); lay.setMargin(5); lay.setSpacing(5); lay.addWidget( &lab); dia.resize( 200, dia.sizeHint().height() ); 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 ) mess += ( "Pizza is ready"); else if ( minutes == 45 ) mess += ( "Please wake up!"); else if ( minutes == 5 ) mess += ( "Tea is ready"); else if ( minutes == 3 ) { mess += mCustomText; minutes = mCustomMinutes ; } 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 hbox ( &dia ); QLabel lab3 (("h:"), &hbox ); QSpinBox spinh( 0, 24, 1,& hbox ); QLabel lab4 ((" min:"), &hbox ); QSpinBox spinm( 0, 59, 1,&hbox ); spinh.setValue( mCustomMinutes/60 ); spinm.setValue( mCustomMinutes%60 ); lay.addWidget( &hbox); 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; } else mess+= QString::number ( minutes ) + ( " minutes are past!"); } //minutes = 1; mRunningTimer = QDateTime::currentDateTime().addSecs( minutes * 60 ); timerMesssage = mess; |