Restored some changes that allow changing the alert sound when there are no alerts...
[kitchenalert] / src / kitchenalertmainwindow.cpp
index 3d9a8dc..4fc1c18 100644 (file)
@@ -2,7 +2,7 @@
 
         KitchenAlert
 
-        Copyright (C) 2010  Heli Hyvättinen
+        Copyright (C) 2010-2011  Heli Hyvättinen
 
         This file is part of KitchenAlert.
 
@@ -137,7 +137,7 @@ void KitchenAlertMainWindow::newTimerSequence()
 
        connect(timer1,SIGNAL(alert(QModelIndex)),this,SLOT(alert(QModelIndex)));
 
-       //TODO: FIND A WAY TO INFORM THE TIMERS' ALERTSOUND'S OF A CHANGE OF THE SOUND FILE THEY SHOULD USE!!!!
+
 
        connect(this,SIGNAL(defaultSoundEnabled()),timer1,SLOT(enableDefaultSound()));
        connect(this,SIGNAL(soundChanged(QString)),timer1,SLOT(changeAlertSound(QString)));
@@ -175,7 +175,10 @@ void KitchenAlertMainWindow::alert(QModelIndex indexOfAlerter)
 
 
     activateWindow();
-    raise();
+
+// removing everything below does not solve the bug #6752!
+
+    raise();  //this may be unnecessary
 
     // The alerting timer is selected
     ui->ComingAlertsTableView->selectionModel()->select(QItemSelection(indexOfAlerter,indexOfAlerter),QItemSelectionModel::SelectCurrent | QItemSelectionModel::Rows );
@@ -190,17 +193,7 @@ void KitchenAlertMainWindow::alert(QModelIndex indexOfAlerter)
 
 
     ui->SnoozeButton->setEnabled(true);
-
-    //Debug message
-
-
-
-    ui->debugLabel->setText(tr("Alert received from row %1").arg(indexOfAlerter.row()));
-    qDebug() << "Wrote the debug message";
-
-    //The alert sound is played
-   //TESTING TO MOVE THIS OPERATION TO THE TIMER ITSELF
-//    alertSound_.play();
+//qDebug ("Snooze on when alerting");
 
 }
 
@@ -222,8 +215,13 @@ void KitchenAlertMainWindow::timerSelected(QItemSelection selected,QItemSelectio
         if (model_.isThisTimerAlerting(index) == true)
         {
              ui->SnoozeButton->setEnabled(true);
+//qDebug() << "Snooze on";
+        }
+        else
+        {
+            ui->SnoozeButton->setDisabled(true);
+//qDebug() << "Snooze off";
         }
-        else ui->SnoozeButton->setDisabled(true);
     }
 
 }
@@ -236,7 +234,7 @@ void KitchenAlertMainWindow::snooze()
         model_.snoozeTimer(row);
     }
     ui->SnoozeButton->setDisabled(true);
-  //  alertSound_.stop();
+
 
 }
 
@@ -248,8 +246,14 @@ void KitchenAlertMainWindow::restart()
 
         model_.startTimer(row);
     }
-    ui->SnoozeButton->setDisabled(true);
- //   alertSound_.stop();
+
+
+   if (model_.isThisTimerAlerting(row) == false) //This has to be checked, because 00:00:00 alerts alert *before* the program execution reaches here
+    {
+        ui->SnoozeButton->setDisabled(true);
+    }
+ //   qDebug () << "disabled snooze because of restart";
+
 
 }
 
@@ -261,7 +265,7 @@ void KitchenAlertMainWindow::stop()
         model_.stopTimer(row);
     }
     ui->SnoozeButton->setDisabled(true);
-//    alertSound_.stop();
+
 }
 
 QModelIndex KitchenAlertMainWindow::selectedRow()
@@ -282,10 +286,22 @@ void KitchenAlertMainWindow::openSelectSoundDialog()
     SelectSoundDialog dialog;
    if ( dialog.exec() == QDialog::Accepted) //if user pressed OK
     {
+       QSettings settings ("KitchenAlert","KitchenAlert");
+      
        if (dialog.isDefaultSoundChecked() == true)
+       { 
+        
+          settings.setValue("UseDefaultSound",true); 
            emit defaultSoundEnabled();
-       else
-           emit soundChanged(dialog.getSoundFileName());
+       }   
+      else
+       {
+           QString filename = dialog.getSoundFileName();
+           settings.setValue("UseDefaultSound",false);
+           settings.setValue("soundfile",filename);
+           emit soundChanged(filename);
+       }
+
     }
 
 }
@@ -293,7 +309,7 @@ void KitchenAlertMainWindow::openSelectSoundDialog()
 void KitchenAlertMainWindow::openAbout()
 {
     QMessageBox::about(this,tr("About KitchenAlert"),tr("<p>Version %1"
-                                                        "<p>Copyright &copy; Heli Hyv&auml;ttinen 2010"
+                                                        "<p>Copyright &copy; Heli Hyv&auml;ttinen 2010-2011"
                                                          "<p>License: General Public License v3"
                                                          "<p>Web page: http://kitchenalert.garage.maemo.org/"
                                                          "<p>Bugtracker: https://garage.maemo.org/projects/kitchenalert/").arg(QApplication::applicationVersion()));
@@ -308,12 +324,12 @@ bool KitchenAlertMainWindow::event(QEvent *event)
         case QEvent::WindowActivate:
 
             model_.setUpdateViewOnChanges(true);
-            ui->debugLabel->setText("Returned to the application!");
+//            ui->debugLabel->setText("Returned to the application!");
             break;
 
        case QEvent::WindowDeactivate:
             model_.setUpdateViewOnChanges(false);
-            ui->debugLabel->setText("");
+//            ui->debugLabel->setText("");
             break;
 
        default: