Changelog for 0.0.8
[harmattan/cameraplus] / declarative / sounds.cpp
index af49bb8..084b094 100644 (file)
@@ -1,7 +1,7 @@
 /*!
  * This file is part of CameraPlus.
  *
- * Copyright (C) 2012 Mohammed Sameer <msameer@foolab.org>
+ * Copyright (C) 2012-2013 Mohammed Sameer <msameer@foolab.org>
  *
  * This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
 #include <QWaitCondition>
 #include <QDBusServiceWatcher>
 #include <QDBusConnection>
-#include <contextsubscriber/contextproperty.h>
+#if defined(QT4)
+#include <QDeclarativeInfo>
+#elif defined(QT5)
+#include <QQmlInfo>
+#endif
 
 #define CAMERA_IMAGE_START_SOUND_ID  "camera-image-start"
 #define CAMERA_IMAGE_END_SOUND_ID    "camera-image-end"
 // Odd, volume has to be a char *
 #define CANBERRA_FULL_VOLUME         "0.0"
 #define CANBERRA_HEADSET_VOLUME      "-24.0"
-#define AUDIO_ROUTE_PROPERTY         "/com/nokia/policy/audio_route"
-#define AUDIO_ROUTE_SPEAKERS         "ihf"
 
 Sounds::Sounds(QObject *parent) :
   QObject(parent),
   m_muted(false),
   m_ctx(0),
-  m_conf(0),
+  m_volume(Sounds::VolumeHigh),
   m_watcher(new QDBusServiceWatcher("org.pulseaudio.Server",
                                    QDBusConnection::systemBus(),
                                    QDBusServiceWatcher::WatchForOwnerChange)) {
@@ -55,11 +57,6 @@ Sounds::Sounds(QObject *parent) :
 
   // No idea why but canberra will not cache without that!!!
   setenv("CANBERRA_EVENT_LOOKUP", "1", 1);
-
-  m_audioRoute = new ContextProperty(AUDIO_ROUTE_PROPERTY, this);
-  QObject::connect(m_audioRoute, SIGNAL(valueChanged()), this, SLOT(audioConnectionChanged()));
-  m_audioRoute->waitForSubscription(true);
-  audioConnectionChanged();
 }
 
 Sounds::~Sounds() {
@@ -69,10 +66,6 @@ Sounds::~Sounds() {
   }
 }
 
-void Sounds::setConfig(QtCamConfig *conf) {
-  m_conf = conf;
-}
-
 void Sounds::serviceOwnerChanged(const QString& serviceName, const QString& oldOwner,
                                 const QString& newOwner) {
   Q_UNUSED(serviceName);
@@ -90,7 +83,7 @@ void Sounds::serviceOwnerChanged(const QString& serviceName, const QString& oldO
   }
 }
 
-void Sounds::imageCaptureStarted() {
+void Sounds::playImageCaptureStartedSound() {
   if (isMuted() || !m_ctx) {
     return;
   }
@@ -98,7 +91,7 @@ void Sounds::imageCaptureStarted() {
   play(CAMERA_IMAGE_START_SOUND_ID);
 }
 
-void Sounds::imageCaptureEnded() {
+void Sounds::playImageCaptureEndedSound() {
   if (isMuted() || !m_ctx) {
     return;
   }
@@ -106,7 +99,7 @@ void Sounds::imageCaptureEnded() {
   play(CAMERA_IMAGE_END_SOUND_ID);
 }
 
-void Sounds::videoRecordingStarted() {
+void Sounds::playVideoRecordingStartedSound() {
   if (isMuted() || !m_ctx) {
     return;
   }
@@ -114,7 +107,7 @@ void Sounds::videoRecordingStarted() {
   playAndBlock(CAMERA_VIDEO_START_SOUND_ID);
 }
 
-void Sounds::videoRecordingEnded() {
+void Sounds::playVideoRecordingEndedSound() {
   if (isMuted() || !m_ctx) {
     return;
   }
@@ -122,7 +115,7 @@ void Sounds::videoRecordingEnded() {
   play(CAMERA_VIDEO_STOP_SOUND_ID);
 }
 
-void Sounds::autoFocusAcquired() {
+void Sounds::playAutoFocusAcquiredSound() {
   if (isMuted() || !m_ctx) {
     return;
   }
@@ -175,11 +168,11 @@ void Sounds::reload() {
     return;
   }
 
-  cache(m_conf->imageCaptureStartedSound(), CAMERA_IMAGE_START_SOUND_ID);
-  cache(m_conf->imageCaptureEndedSound(), CAMERA_IMAGE_END_SOUND_ID);
-  cache(m_conf->videoRecordingStartedSound(), CAMERA_VIDEO_START_SOUND_ID);
-  cache(m_conf->videoRecordingEndedSound(), CAMERA_VIDEO_STOP_SOUND_ID);
-  cache(m_conf->autoFocusAcquiredSound(), CAMERA_FOCUS_SOUND_ID);
+  cache(m_imageCaptureStart, CAMERA_IMAGE_START_SOUND_ID);
+  cache(m_imageCaptureEnd, CAMERA_IMAGE_END_SOUND_ID);
+  cache(m_videoRecordingStart, CAMERA_VIDEO_START_SOUND_ID);
+  cache(m_videoRecordingEnd, CAMERA_VIDEO_STOP_SOUND_ID);
+  cache(m_autoFocusAcquired, CAMERA_FOCUS_SOUND_ID);
 }
 
 void Sounds::cache(const QString& path, const char *id) {
@@ -203,13 +196,16 @@ void Sounds::play(const char *id) {
     return;
   }
 
+  const char *volume = m_volume == Sounds::VolumeLow ?
+    CANBERRA_HEADSET_VOLUME : CANBERRA_FULL_VOLUME;
+
   int code = ca_context_play(m_ctx, 0,
-                            CA_PROP_CANBERRA_VOLUME, m_volume.toAscii().constData(),
+                            CA_PROP_CANBERRA_VOLUME, volume,
                             CA_PROP_EVENT_ID, id,
                             CA_PROP_MEDIA_ROLE, "camera-sound-effect",
                             NULL);
   if (code != CA_SUCCESS) {
-    qDebug() << "Failed to play sound" << ca_strerror(code) << code;
+    qmlInfo(this) << "Failed to play sound" << ca_strerror(code) << code;
   }
 }
 
@@ -256,10 +252,73 @@ void Sounds::playAndBlock(const char *id) {
   mutex.unlock();
 }
 
-void Sounds::audioConnectionChanged() {
-  if (m_audioRoute->value().toString() != AUDIO_ROUTE_SPEAKERS) {
-    m_volume = CANBERRA_HEADSET_VOLUME;
-  } else {
-    m_volume = CANBERRA_FULL_VOLUME;
+QString Sounds::imageCaptureStart() const {
+  return m_imageCaptureStart;
+}
+
+void Sounds::setImageCaptureStart(const QString& path) {
+  if (path != m_imageCaptureStart) {
+    m_imageCaptureStart = path;
+    cache(m_imageCaptureStart, CAMERA_IMAGE_START_SOUND_ID);
+    emit imageCaptureStartChanged();
+  }
+}
+
+QString Sounds::imageCaptureEnd() const {
+  return m_imageCaptureEnd;
+}
+
+void Sounds::setImageCaptureEnd(const QString& path) {
+  if (path != m_imageCaptureEnd) {
+    m_imageCaptureEnd = path;
+    cache(m_imageCaptureEnd, CAMERA_IMAGE_END_SOUND_ID);
+    emit imageCaptureEndChanged();
+  }
+}
+
+QString Sounds::videoRecordingStart() const {
+  return m_videoRecordingStart;
+}
+
+void Sounds::setVideoRecordingStart(const QString& path) {
+  if (path != m_videoRecordingStart) {
+    m_videoRecordingStart = path;
+    cache(m_videoRecordingStart, CAMERA_VIDEO_START_SOUND_ID);
+    emit videoRecordingStartChanged();
+  }
+}
+
+QString Sounds::videoRecordingEnd() const {
+  return m_videoRecordingEnd;
+}
+
+void Sounds::setVideoRecordingEnd(const QString& path) {
+  if (path != m_videoRecordingEnd) {
+    m_videoRecordingEnd = path;
+    cache(m_videoRecordingEnd, CAMERA_VIDEO_STOP_SOUND_ID);
+    emit videoRecordingEndChanged();
+  }
+}
+
+QString Sounds::autoFocusAcquired() const {
+  return m_autoFocusAcquired;
+}
+
+void Sounds::setAutoFocusAcquired(const QString& path) {
+  if (path != m_autoFocusAcquired) {
+    m_autoFocusAcquired = path;
+    cache(m_autoFocusAcquired, CAMERA_FOCUS_SOUND_ID);
+    emit autoFocusAcquiredChanged();
+  }
+}
+
+Sounds::Volume Sounds::volume() const {
+  return m_volume;
+}
+
+void Sounds::setVolume(const Sounds::Volume& volume) {
+  if (m_volume != volume) {
+    m_volume = volume;
+    emit volumeChanged();
   }
 }