Added sticky alerts
[kitchenalert] / src / alertsound.cpp
index b11f538..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
@@ -26,8 +26,9 @@
 
 #include <QDebug>
 #include <QSettings>
-#include <QList>
 
+// Initialize static const
+ const QString AlertSound::defaultsound_  = "/home/opt/KitchenAlert/DoorbellModifiedFinal.mp3";
 
 
 
@@ -35,7 +36,7 @@ AlertSound::AlertSound(QObject *parent) :
     QObject(parent)
 {
 
-    defaultsound_ = "/opt/KitchenAlert/06capemaycloser_modifiedlouder.mp3";
+
     QString filename;
 
     QSettings settings("KitchenAlert","KitchenAlert");
@@ -43,7 +44,7 @@ AlertSound::AlertSound(QObject *parent) :
    // settings.clear(); //REMOVE THIS AFTER TESTING!!!!!!
 
     bool useDefaultSound = settings.value("UseDefaultSound",true).toBool();
-    qDebug() << "In AlertSound constructor UseDefaultSound is " << useDefaultSound;
+//    qDebug() << "In AlertSound constructor UseDefaultSound is " << useDefaultSound;
     if (useDefaultSound == true)
     {
         filename = defaultsound_;
@@ -52,54 +53,46 @@ AlertSound::AlertSound(QObject *parent) :
     {
         filename = settings.value("soundfile",defaultsound_).toString();
     }
-    pSound_ = Phonon::createPlayer(Phonon::MusicCategory, Phonon::MediaSource(filename));
 
 
-    //TESTCODE!!!
 
-    QList<Phonon::AudioOutputDevice> audioOutputDevices =
-                 Phonon::BackendCapabilities::availableAudioOutputDevices();
+      pSound_ = new QMediaPlayer;
+      pSound_->setMedia(QUrl::fromLocalFile(filename));
+}
+
+AlertSound::~AlertSound()
+{
 
-    foreach (Phonon::AudioOutputDevice device, audioOutputDevices)
+    if (pSound_ != NULL)
     {
-    qDebug() << device.name() << device.description();
+        delete pSound_;
     }
 }
 
 void AlertSound::play()
 {
-
-    //TESTCODE
-
-    Phonon::AudioOutput *audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this);
-
-    Phonon::Path path = Phonon::createPath(pSound_, audioOutput);
-
-    audioOutput->setVolumeDecibel(0);
-
-    //TESTCODE ENDS
-
-    pSound_->play();
-    qDebug() << "Sound should be played now";
+     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)
 {
-   QSettings settings("KitchenAlert","KitchenAlert");
-   settings.setValue("UseDefaultSound",false);
-   settings.setValue("soundfile",filename);
-   pSound_->setCurrentSource(filename);
+
+   pSound_->setMedia(QUrl::fromLocalFile(filename));
 }
 
 void AlertSound::setDefaultSound()
 {
-    QSettings settings ("KitchenAlert","KitchenAlert");
-    settings.setValue("UseDefaultSound",true);
-    pSound_->setCurrentSource(defaultsound_);
+
+    pSound_->setMedia(QUrl::fromLocalFile(defaultsound_));
 }