summaryrefslogtreecommitdiffabout
authorzautrix <zautrix>2004-08-30 23:18:58 (UTC)
committer zautrix <zautrix>2004-08-30 23:18:58 (UTC)
commitdef659747d354789f84a992f18df2c3f80f12d01 (patch) (unidiff)
tree9ee66d8e8ef7ab81c9b5e8a32b417746b6cdf8a0
parentcec54f6e21264341191e4f94f9dd7bd19b2eea8d (diff)
downloadkdepimpi-def659747d354789f84a992f18df2c3f80f12d01.zip
kdepimpi-def659747d354789f84a992f18df2c3f80f12d01.tar.gz
kdepimpi-def659747d354789f84a992f18df2c3f80f12d01.tar.bz2
Made timer configurable
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--kalarmd/simplealarmdaemonimpl.cpp53
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
@@ -328,110 +328,163 @@ void SimpleAlarmDaemonImpl::recieve( const QCString& msg, const QByteArray& )
328 } 328 }
329 if ( mess.left( 9 ) == "cal_alarm") { 329 if ( mess.left( 9 ) == "cal_alarm") {
330 mAlarmMessage = mess.mid( 9 ) ; 330 mAlarmMessage = mess.mid( 9 ) ;
331 } 331 }
332 332
333 writeFile(); 333 writeFile();
334 startAlarm( mAlarmMessage, filename ); 334 startAlarm( mAlarmMessage, filename );
335 335
336} 336}
337 337
338int SimpleAlarmDaemonImpl::getFileNameLen( QString mess ) 338int SimpleAlarmDaemonImpl::getFileNameLen( QString mess )
339{ 339{
340 return 0; 340 return 0;
341} 341}
342void SimpleAlarmDaemonImpl::startAlarm( QString mess, QString filename ) 342void SimpleAlarmDaemonImpl::startAlarm( QString mess, QString filename )
343{ 343{
344 //mAlarmDialog->show(); 344 //mAlarmDialog->show();
345 //mAlarmDialog->raise(); 345 //mAlarmDialog->raise();
346 mAlarmDialog->eventNotification( mess, mPlayBeeps, filename, wavAlarm,mPausePlay ,mSuspend ); 346 mAlarmDialog->eventNotification( mess, mPlayBeeps, filename, wavAlarm,mPausePlay ,mSuspend );
347} 347}
348 348
349 349
350void SimpleAlarmDaemonImpl::fillTimerPopUp() 350void SimpleAlarmDaemonImpl::fillTimerPopUp()
351{ 351{
352 352
353 // qDebug(" timer %d %d ",mTimerPopupConf, mTimerTime ); 353 // qDebug(" timer %d %d ",mTimerPopupConf, mTimerTime );
354 if ( mTimerPopupConf == mTimerTime ) { 354 if ( mTimerPopupConf == mTimerTime ) {
355 if ( mTimerTime ) { 355 if ( mTimerTime ) {
356 int secs = QDateTime::currentDateTime().secsTo ( mRunningTimer ); 356 int secs = QDateTime::currentDateTime().secsTo ( mRunningTimer );
357 QTime t ( secs/3600, (secs/60)%60, secs%60 ); 357 QTime t ( secs/3600, (secs/60)%60, secs%60 );
358 mTimerPopUp->changeItem ( 1 , t.toString()); 358 mTimerPopUp->changeItem ( 1 , t.toString());
359 } 359 }
360 else { 360 else {
361 QString text = mCustomText.stripWhiteSpace (); 361 QString text = mCustomText.stripWhiteSpace ();
362 int in = text.find( " " ); 362 int in = text.find( " " );
363 text = text.left ( in ); 363 text = text.left ( in );
364 mTimerPopUp->changeItem ( 3, text ); 364 mTimerPopUp->changeItem ( 3, text );
365 } 365 }
366 return; 366 return;
367 } 367 }
368 mTimerPopupConf = mTimerTime; 368 mTimerPopupConf = mTimerTime;
369 mTimerPopUp->clear(); 369 mTimerPopUp->clear();
370 if ( mTimerTime ) { 370 if ( mTimerTime ) {
371 int secs = QDateTime::currentDateTime().secsTo ( mRunningTimer ); 371 int secs = QDateTime::currentDateTime().secsTo ( mRunningTimer );
372 QTime t ( secs/3600, (secs/60)%60, secs%60 ); 372 QTime t ( secs/3600, (secs/60)%60, secs%60 );
373 mTimerPopUp->insertItem( "Stop", 0 ); 373 mTimerPopUp->insertItem( "Stop", 0 );
374 mTimerPopUp->insertItem( t.toString(),1); 374 mTimerPopUp->insertItem( t.toString(),1);
375 } else { 375 } else {
376
377 QString fileName = QDir::homeDirPath() +"/.kopialarmtimerrc";
378 QFile file( fileName );
379 if( !QFile::exists( fileName) ) {
380 // write defaults
381 if (!file.open( IO_WriteOnly ) ) {
382 return;
383 }
384 QString configString ;
385 configString += "#config file for kopi alarm timer\n";
386 configString += "#format: <Text for popup menu>;<timer countdown in minutes>\n";
387 configString += "#NOTE: minimum value for timer are 3 minutes!\n";
388 configString += "24 h; 1440\n";
389 configString += " 8 h; 480\n";
390 configString += " 5 h; 300\n";
391 configString += " 1 h; 60\n";
392 configString += "30 min; 30\n";
393 configString += "15 min; 15\n";
394 configString += "SEPARATOR\n";
395 configString += "Pizza; 22\n";
396 configString += "Nap; 45\n";
397 configString += "Tea; 5\n";
398 QTextStream ts( &file );
399 ts << configString ;
400 file.close();
401 }
402
403 if (!file.open( IO_ReadOnly ) ) {
404 return ;
405 }
406 QString line;
407 bool ok;
408 while ( file.readLine( line, 1024 ) > 0 ) {
409 //qDebug("read %s ", line.latin1());
410 if ( line.left(1 ) != "#" ) {
411 // no comment
412 if ( line.left(9 ) == "SEPARATOR" ) {
413 mTimerPopUp->insertSeparator();
414 } else {
415 QStringList li = QStringList::split(";",line);
416 ok = false;
417 if ( li.count() == 2 ) {
418 int val = li[1].toInt( &ok );
419 if ( ok && val > 2 ) {
420 mTimerPopUp->insertItem( li[0], val);
421 }
422 }
423 }
424 }
425 }
426 file.close();
427#if 0
376 mTimerPopUp->insertItem( "24 h", 1440 ); 428 mTimerPopUp->insertItem( "24 h", 1440 );
377 // mTimerPopUp->insertItem( i18n("12 h"), 720 ); 429 // mTimerPopUp->insertItem( i18n("12 h"), 720 );
378 mTimerPopUp->insertItem( " 8 h", 480 ); 430 mTimerPopUp->insertItem( " 8 h", 480 );
379 mTimerPopUp->insertItem( " 5 h", 300 ); 431 mTimerPopUp->insertItem( " 5 h", 300 );
380 // mTimerPopUp->insertItem( i18n(" 2 h"), 120 ); 432 // mTimerPopUp->insertItem( i18n(" 2 h"), 120 );
381 mTimerPopUp->insertItem( " 1 h", 60 ); 433 mTimerPopUp->insertItem( " 1 h", 60 );
382 mTimerPopUp->insertItem( "30 min", 30 ); 434 mTimerPopUp->insertItem( "30 min", 30 );
383 mTimerPopUp->insertItem( "15 min", 15 ); 435 mTimerPopUp->insertItem( "15 min", 15 );
384 mTimerPopUp->insertItem( "10 min", 10 ); 436 mTimerPopUp->insertItem( "10 min", 10 );
385 //mTimerPopUp->insertItem( " 5 min", 5 ); 437 //mTimerPopUp->insertItem( " 5 min", 5 );
386 mTimerPopUp->insertSeparator(); 438 mTimerPopUp->insertSeparator();
387 mTimerPopUp->insertItem( "Pizza", 22 ); 439 mTimerPopUp->insertItem( "Pizza", 22 );
388 mTimerPopUp->insertItem( "Nap", 45 ); 440 mTimerPopUp->insertItem( "Nap", 45 );
389 mTimerPopUp->insertItem( "Tea", 5 ); 441 mTimerPopUp->insertItem( "Tea", 5 );
442#endif
390 QString text = mCustomText.stripWhiteSpace (); 443 QString text = mCustomText.stripWhiteSpace ();
391 int in = text.find( " " ); 444 int in = text.find( " " );
392 text = text.left ( in ); 445 text = text.left ( in );
393 mTimerPopUp->insertItem( text, 3 ); 446 mTimerPopUp->insertItem( text, 3 );
394 mTimerPopUp->insertSeparator(); 447 mTimerPopUp->insertSeparator();
395 mTimerPopUp->insertItem( "Customize", 2 ); 448 mTimerPopUp->insertItem( "Customize", 2 );
396 } 449 }
397 450
398} 451}
399 452
400void SimpleAlarmDaemonImpl::showTimer() 453void SimpleAlarmDaemonImpl::showTimer()
401{ 454{
402 fillTimerPopUp(); 455 fillTimerPopUp();
403} 456}
404 457
405void SimpleAlarmDaemonImpl::confTimer( int time ) 458void SimpleAlarmDaemonImpl::confTimer( int time )
406{ 459{
407 //qDebug("impleAlarmDaemonImpl::confTimer() %d ", time ); 460 //qDebug("impleAlarmDaemonImpl::confTimer() %d ", time );
408 int minutes = time; 461 int minutes = time;
409 if ( minutes == 0 ) { 462 if ( minutes == 0 ) {
410 if ( ! mTimerTime ) 463 if ( ! mTimerTime )
411 return; 464 return;
412 465
413 QDialog dia ( 0, ("Stop Timer" ), true ); 466 QDialog dia ( 0, ("Stop Timer" ), true );
414 QLabel lab (("Really stop the timer?"), &dia ); 467 QLabel lab (("Really stop the timer?"), &dia );
415 dia.setCaption(("KO/Pi Timer Stop" )); 468 dia.setCaption(("KO/Pi Timer Stop" ));
416 QVBoxLayout lay( &dia ); 469 QVBoxLayout lay( &dia );
417 lay.setMargin(5); 470 lay.setMargin(5);
418 lay.setSpacing(5); 471 lay.setSpacing(5);
419 lay.addWidget( &lab); 472 lay.addWidget( &lab);
420 dia.resize( 200, dia.sizeHint().height() ); 473 dia.resize( 200, dia.sizeHint().height() );
421 474
422 if ( !dia.exec() ) 475 if ( !dia.exec() )
423 return; 476 return;
424 477
425 AlarmServer::deleteAlarm ( mRunningTimer,"koalarm" , timerMesssage.latin1() ); 478 AlarmServer::deleteAlarm ( mRunningTimer,"koalarm" , timerMesssage.latin1() );
426 mTimerTime = 0; 479 mTimerTime = 0;
427 return; 480 return;
428 } 481 }
429 if ( mTimerTime ) 482 if ( mTimerTime )
430 return; 483 return;
431 if ( minutes == 1 ) { 484 if ( minutes == 1 ) {
432 return; 485 return;
433 } 486 }
434 QString mess = "timer_alarm"; 487 QString mess = "timer_alarm";
435 mess += ("Timer Alarm!\n"); 488 mess += ("Timer Alarm!\n");
436 if ( minutes == 22 ) 489 if ( minutes == 22 )
437 mess += ( "Pizza is ready"); 490 mess += ( "Pizza is ready");