Added sticky alerts
[kitchenalert] / src / timer.cpp
index 1b3eed6..1a182b9 100644 (file)
@@ -1,7 +1,7 @@
 /**************************************************************************
         KitchenAlert
 
-        Copyright (C) 2010  Heli Hyvättinen
+        Copyright (C) 2010-2011  Heli Hyvättinen
 
         This file is part of KitchenAlert.
 
@@ -29,7 +29,6 @@
 #include <qdebug.h>
 #include <QFile>
 #include <QXmlStreamWriter>
-#include <QXmlStreamReader>
 
 Timer::Timer(QObject *parent) :
     QObject(parent)
@@ -40,8 +39,9 @@ Timer::Timer(QObject *parent) :
     connect(&_actualTimer, SIGNAL(timeout()), this, SLOT(secondPassed()));
 
     alerting_ = false;
-}
 
+    _remainingTime = 0; //Same as when stopped
+}
 
 
 int Timer::getOriginalTimeInSeconds()
@@ -77,8 +77,9 @@ void Timer::secondPassed()
     if (_remainingTime == 0)
     {
         alerting_ = true;
+        alertSound_.play();
         emit alert(whereAmI());
-        qDebug() << "alerted";
+//        qDebug() << "alerting";
     }
 
     emit remainingTimeChanged(); //after alerting in case of alert so that status gets updated immediately
@@ -89,15 +90,22 @@ void Timer::start()
     _remainingTime = _originalTime;
     _actualTimer.start();
 
-    alerting_ = false;
 
-    if (_originalTime == 0) //has to be checked here, since 00:00:00 alert will already be negative when checked next time
-    //THIS ALERTS EVERY SECOND TIME THE TIMER IS STARTED! //This bug disappeared without explanation...
+
+    if (_originalTime == 0) //a 00:00:00 alert has to  be checked here, since it's already negative when checked for the next time
     {
-        alerting_ = true;
+        alerting_  = true;
+        alertSound_.play();
         emit alert(whereAmI());
-        qDebug () << "Alerted for 00:00:00 alert";
+//        qDebug () << "Alerting 00:00:00 from row: " << whereAmI().row();
     }
+
+    else
+    {
+        alerting_ = false;
+        alertSound_.stop();
+    }
+
 }
 
 
@@ -107,6 +115,7 @@ void Timer::stop()
     _remainingTime = 0; //Stopped timer shows 00:00:00
 
     alerting_ = false;
+    alertSound_.stop();
 }
 
 void Timer::snooze()
@@ -114,6 +123,7 @@ void Timer::snooze()
     _remainingTime = 120;
 
     alerting_ = false;
+    alertSound_.stop();
 }
 
 
@@ -140,6 +150,19 @@ QModelIndex Timer::whereAmI()
 
 }
 
+void Timer::enableDefaultSound()
+{
+alertSound_.setDefaultSound();
+}
+
+void Timer::changeAlertSound(QString filename)
+{
+alertSound_.setSound(filename);
+}
+
+
+
+
 bool Timer::save(QString filename)
 {
     QFile file(filename);
@@ -184,10 +207,15 @@ bool Timer::load(QString filename)
 
     _alertText = reader.attributes().value("alert_text").toString();
     _originalTime = reader.attributes().value("time_in_seconds").toString().toInt();
-    return true;
 
+    filenameWithPath_ = filename;
 
+    return true;
+}
 
+//QString Timer::getFilename()
+//{
+//    return filenameWithPath_;
+//}
 
-}