Remove harmattan specific bits from Sounds
authorMohammed Sameer <msameer@foolab.org>
Thu, 25 Jul 2013 21:24:44 +0000 (00:24 +0300)
committerMohammed Sameer <msameer@foolab.org>
Thu, 25 Jul 2013 21:24:44 +0000 (00:24 +0300)
All the harmattan audio route handling is now in a harmattan
specific implementation.
Application expects a component named SoundVolumeControl per platform

declarative/declarative.pro
declarative/sounds.cpp
declarative/sounds.h
qml/CameraView.qml
src/harmattan/harmattan.pri
src/harmattan/soundvolumecontrol.cpp [new file with mode: 0644]
src/harmattan/soundvolumecontrol.h [new file with mode: 0644]
src/main.cpp

index 3621bea..3e5731f 100644 (file)
@@ -6,7 +6,7 @@ include(../cameraplus.pri)
 
 CONFIG += link_pkgconfig plugin
 
-PKGCONFIG = gstreamer-pbutils-0.10 libcanberra contextsubscriber-1.0
+PKGCONFIG = gstreamer-pbutils-0.10 libcanberra
 
 LIBS += -L../lib/ -lqtcamera
 
index 238024b..a45dbfc 100644 (file)
@@ -25,7 +25,7 @@
 #include <QWaitCondition>
 #include <QDBusServiceWatcher>
 #include <QDBusConnection>
-#include <contextsubscriber/contextproperty.h>
+#include <QDeclarativeInfo>
 
 #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_volume(Sounds::VolumeHigh),
   m_watcher(new QDBusServiceWatcher("org.pulseaudio.Server",
                                    QDBusConnection::systemBus(),
                                    QDBusServiceWatcher::WatchForOwnerChange)) {
@@ -54,11 +53,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() {
@@ -198,13 +192,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;
   }
 }
 
@@ -251,14 +248,6 @@ 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;
 }
@@ -318,3 +307,14 @@ void Sounds::setAutoFocusAcquired(const QString& path) {
     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();
+  }
+}
index 813093b..9184d26 100644 (file)
@@ -27,7 +27,6 @@
 #include <canberra.h>
 
 class QDBusServiceWatcher;
-class ContextProperty;
 
 class Sounds : public QObject {
   Q_OBJECT
@@ -91,7 +90,6 @@ signals:
 private slots:
   void serviceOwnerChanged(const QString& serviceName, const QString& oldOwner,
                           const QString& newOwner);
-  void audioConnectionChanged();
 
 private:
   void cache(const QString& path, const char *id);
@@ -100,9 +98,9 @@ private:
 
   bool m_muted;
   ca_context *m_ctx;
+  Volume m_volume;
   QDBusServiceWatcher *m_watcher;
-  ContextProperty *m_audioRoute;
-  QString m_volume;
+  QString m_volumeString;
   QString m_imageCaptureStart;
   QString m_imageCaptureEnd;
   QString m_videoRecordingStart;
index 80d5579..ac4c778 100644 (file)
@@ -61,9 +61,14 @@ Camera {
         }
     }
 
+    SoundVolumeControl {
+        id: volumeControl
+    }
+
     sounds: Sounds {
         id: sounds
         mute: !settings.soundEnabled
+        volume: volumeControl.fullVolume ? Sounds.VolumeHigh : Sounds.VolumeLow
         imageCaptureStart: platformSettings.imageCaptureStartedSound
         imageCaptureEnd: platformSettings.imageCaptureEndedSound
         videoRecordingStart: platformSettings.videoRecordingStartedSound
index 3d0f4bc..57a9b11 100644 (file)
@@ -1,7 +1,7 @@
 DEPENDPATH += harmattan .
 INCLUDEPATH += harmattan .
 
-PKGCONFIG += quill
+PKGCONFIG += quill contextsubscriber-1.0
 
-HEADERS += quillitem.h
-SOURCES += quillitem.cpp
+HEADERS += quillitem.h soundvolumecontrol.h
+SOURCES += quillitem.cpp soundvolumecontrol.cpp
diff --git a/src/harmattan/soundvolumecontrol.cpp b/src/harmattan/soundvolumecontrol.cpp
new file mode 100644 (file)
index 0000000..1f39e92
--- /dev/null
@@ -0,0 +1,50 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#include "soundvolumecontrol.h"
+#include <contextsubscriber/contextproperty.h>
+
+#define AUDIO_ROUTE_PROPERTY         "/com/nokia/policy/audio_route"
+#define AUDIO_ROUTE_SPEAKERS         "ihf"
+
+SoundVolumeControl::SoundVolumeControl(QObject *parent) :
+  QObject(parent),
+  m_audioRoute(new ContextProperty(AUDIO_ROUTE_PROPERTY, this)) {
+
+  QObject::connect(m_audioRoute, SIGNAL(valueChanged()), this, SLOT(audioConnectionChanged()));
+  m_audioRoute->waitForSubscription(true);
+  audioConnectionChanged();
+}
+
+SoundVolumeControl::~SoundVolumeControl() {
+
+}
+
+bool SoundVolumeControl::fullVolume() {
+  return m_fullVolume;
+}
+
+void SoundVolumeControl::audioConnectionChanged() {
+  m_fullVolume = m_audioRoute->value().toString() == QLatin1String(AUDIO_ROUTE_SPEAKERS);
+
+  emit fullVolumeChanges();
+}
diff --git a/src/harmattan/soundvolumecontrol.h b/src/harmattan/soundvolumecontrol.h
new file mode 100644 (file)
index 0000000..0747833
--- /dev/null
@@ -0,0 +1,52 @@
+// -*- c++ -*-
+
+/*!
+ * This file is part of CameraPlus.
+ *
+ * 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
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+ */
+
+#ifndef SOUND_FOLUME_CONTROL_H
+#define SOUND_VOLUME_CONTROL_H
+
+#include <QObject>
+
+class ContextProperty;
+
+class SoundVolumeControl : public QObject {
+  Q_OBJECT
+
+  Q_PROPERTY(bool fullVolume READ fullVolume NOTIFY fullVolumeChanges);
+
+public:
+  SoundVolumeControl(QObject *parent = 0);
+  ~SoundVolumeControl();
+
+  bool fullVolume();
+
+signals:
+  void fullVolumeChanges();
+
+private slots:
+  void audioConnectionChanged();
+
+private:
+  ContextProperty *m_audioRoute;
+  bool m_fullVolume;
+};
+
+#endif /* SOUND_VOLUME_CONTROL_H */
index fd6cd8c..e0556b7 100644 (file)
@@ -29,6 +29,7 @@
 #include "filenaming.h"
 #ifdef HARMATTAN
 #include "quillitem.h"
+#include "soundvolumecontrol.h"
 #endif
 #include "displaystate.h"
 #include "fsmonitor.h"
@@ -90,6 +91,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) {
   qmlRegisterType<FileNaming>("CameraPlus", 1, 0, "FileNaming");
 #ifdef HARMATTAN
   qmlRegisterType<QuillItem>("CameraPlus", 1, 0, "QuillItem");
+  qmlRegisterType<SoundVolumeControl>("CameraPlus", 1, 0, "SoundVolumeControl");
 #endif
   qmlRegisterType<DisplayState>("CameraPlus", 1, 0, "DisplayState");
   qmlRegisterType<FSMonitor>("CameraPlus", 1, 0, "FSMonitor");