CONFIG += link_pkgconfig plugin
-PKGCONFIG = gstreamer-pbutils-0.10 libcanberra contextsubscriber-1.0
+PKGCONFIG = gstreamer-pbutils-0.10 libcanberra
LIBS += -L../lib/ -lqtcamera
#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)) {
// 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() {
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;
}
}
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;
}
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();
+ }
+}
#include <canberra.h>
class QDBusServiceWatcher;
-class ContextProperty;
class Sounds : public QObject {
Q_OBJECT
private slots:
void serviceOwnerChanged(const QString& serviceName, const QString& oldOwner,
const QString& newOwner);
- void audioConnectionChanged();
private:
void cache(const QString& path, const char *id);
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;
}
}
+ 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
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
--- /dev/null
+// -*- 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();
+}
--- /dev/null
+// -*- 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 */
#include "filenaming.h"
#ifdef HARMATTAN
#include "quillitem.h"
+#include "soundvolumecontrol.h"
#endif
#include "displaystate.h"
#include "fsmonitor.h"
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");