Timer now knows where it was loaded from
[kitchenalert] / src / alertsound.cpp
index fc8e6d3..b6c1fa3 100644 (file)
@@ -1,7 +1,7 @@
 /**************************************************************************
-        This file is part of KitchenAlert v.0.09
+        This file is part of KitchenAlert
 
-        Copyright (C) 2010  Heli Hyvättinen
+        Copyright (C) 2010-2011  Heli Hyvättinen
 
         Kitchen Alert is free software: you can redistribute it and/or modify
         it under the terms of the GNU General Public License as published by
 #include "alertsound.h"
 
 #include <QDebug>
+#include <QSettings>
+
+// Initialize static const
+ const QString AlertSound::defaultsound_  = "/home/opt/KitchenAlert/DoorbellModifiedFinal.mp3";
 
 
 
@@ -33,18 +37,62 @@ AlertSound::AlertSound(QObject *parent) :
 {
 
 
-    pSound_ = Phonon::createPlayer(Phonon::MusicCategory, Phonon::MediaSource("/home/user/MyDocs/KitchenAlertTestSound1.wav"));
+    QString filename;
+
+    QSettings settings("KitchenAlert","KitchenAlert");
+
+   // settings.clear(); //REMOVE THIS AFTER TESTING!!!!!!
+
+    bool useDefaultSound = settings.value("UseDefaultSound",true).toBool();
+//    qDebug() << "In AlertSound constructor UseDefaultSound is " << useDefaultSound;
+    if (useDefaultSound == true)
+    {
+        filename = defaultsound_;
+    }
+    else
+    {
+        filename = settings.value("soundfile",defaultsound_).toString();
+    }
+
+
+
+      pSound_ = new QMediaPlayer;
+      pSound_->setMedia(QUrl::fromLocalFile(filename));
 }
 
-void AlertSound::play()
+AlertSound::~AlertSound()
 {
 
-    pSound_->play();
-    qDebug() << "Sound should be played now";
+    if (pSound_ != NULL)
+    {
+        delete pSound_;
+    }
+}
+
+void AlertSound::play()
+{
+     pSound_->play();
+  //  qDebug() << "Sound should be played now";
 }
 
 void AlertSound::stop()
 {
 
     pSound_->stop();
+//    qDebug() << pSound_->state();
+//    qDebug() << "Sound stopped by AlertSound.";
+}
+
+
+
+void AlertSound::setSound(QString filename)
+{
+
+   pSound_->setMedia(QUrl::fromLocalFile(filename));
+}
+
+void AlertSound::setDefaultSound()
+{
+
+    pSound_->setMedia(QUrl::fromLocalFile(defaultsound_));
 }