From 2646e153daa301fe3c3b1c33ac87c158c5b82bf5 Mon Sep 17 00:00:00 2001 From: Mohammed Sameer Date: Tue, 20 Aug 2013 02:10:49 +0300 Subject: [PATCH] Make sure we don't play camera sounds in silent profile --- debian/control | 2 +- qml/CameraView.qml | 6 +++- src/harmattan/harmattan.pri | 4 +-- src/harmattan/phoneprofile.cpp | 54 ++++++++++++++++++++++++++++++++++ src/harmattan/phoneprofile.h | 52 ++++++++++++++++++++++++++++++++ src/main.cpp | 2 ++ src/sailfish/phoneprofile.cpp | 38 ++++++++++++++++++++++++ src/sailfish/phoneprofile.h | 46 +++++++++++++++++++++++++++++ src/sailfish/sailfish.pri | 6 ++-- 9 files changed, 204 insertions(+), 6 deletions(-) create mode 100644 src/harmattan/phoneprofile.cpp create mode 100644 src/harmattan/phoneprofile.h create mode 100644 src/sailfish/phoneprofile.cpp create mode 100644 src/sailfish/phoneprofile.h diff --git a/debian/control b/debian/control index 0336d0c..341b457 100644 --- a/debian/control +++ b/debian/control @@ -12,7 +12,7 @@ Standards-Version: 3.9.1 Package: cameraplus Architecture: any -Depends: ${misc:Depends}, ${shlibs:Depends} +Depends: ${misc:Depends}, ${shlibs:Depends}, context-profile XB-Maemo-Display-Name: Camera+ XB-Maemo-Flags: visible XB-Meego-Desktop-Entry-Filename: cameraplus diff --git a/qml/CameraView.qml b/qml/CameraView.qml index 0cb80c1..58821a5 100644 --- a/qml/CameraView.qml +++ b/qml/CameraView.qml @@ -44,11 +44,15 @@ Viewfinder { visible: settings.gridEnabled } + PhoneProfile { + id: phoneProfile + } + Camera { id: cam sounds: Sounds { id: sounds - mute: !settings.soundEnabled + mute: !settings.soundEnabled || phoneProfile.isSilent volume: volumeControl.fullVolume ? Sounds.VolumeHigh : Sounds.VolumeLow imageCaptureStart: platformSettings.imageCaptureStartedSound imageCaptureEnd: platformSettings.imageCaptureEndedSound diff --git a/src/harmattan/harmattan.pri b/src/harmattan/harmattan.pri index 8569111..4c148ad 100644 --- a/src/harmattan/harmattan.pri +++ b/src/harmattan/harmattan.pri @@ -5,8 +5,8 @@ PKGCONFIG += quill contextsubscriber-1.0 QtLocation QtSystemInfo HEADERS += quillitem.h soundvolumecontrol.h deviceinfo.h geocode.h \ batteryinfo.h compass.h devicekeys.h \ - displaystate.h fsmonitor.h orientation.h + displaystate.h fsmonitor.h orientation.h phoneprofile.h SOURCES += quillitem.cpp soundvolumecontrol.cpp deviceinfo.cpp geocode.cpp \ batteryinfo.cpp compass.cpp devicekeys.cpp \ - displaystate.cpp fsmonitor.cpp orientation.cpp + displaystate.cpp fsmonitor.cpp orientation.cpp phoneprofile.cpp diff --git a/src/harmattan/phoneprofile.cpp b/src/harmattan/phoneprofile.cpp new file mode 100644 index 0000000..083a991 --- /dev/null +++ b/src/harmattan/phoneprofile.cpp @@ -0,0 +1,54 @@ +// -*- c++ -*- + +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012-2013 Mohammed Sameer + * + * 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 "phoneprofile.h" +#include + +#define PHONE_PROFILE_PROPERTY "Profile.Name" +#define SILENT_PROFILE_NAME "silent" + +PhoneProfile::PhoneProfile(QObject *parent) : + QObject(parent), + m_profile(new ContextProperty(PHONE_PROFILE_PROPERTY, this)), + m_isSilent(false) { + + QObject::connect(m_profile, SIGNAL(valueChanged()), this, SLOT(phoneProfileChanged())); + m_profile->waitForSubscription(true); + phoneProfileChanged(); +} + +PhoneProfile::~PhoneProfile() { + +} + +bool PhoneProfile::isSilent() { + return m_isSilent; +} + +void PhoneProfile::phoneProfileChanged() { + bool silent = (m_profile->value().toString() == QLatin1String(SILENT_PROFILE_NAME)); + + if (silent != m_isSilent) { + m_isSilent = silent; + emit isSilentChanged(); + } +} diff --git a/src/harmattan/phoneprofile.h b/src/harmattan/phoneprofile.h new file mode 100644 index 0000000..58cc42c --- /dev/null +++ b/src/harmattan/phoneprofile.h @@ -0,0 +1,52 @@ +// -*- c++ -*- + +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012-2013 Mohammed Sameer + * + * 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 PHONE_PROFILE_H +#define PHONE_PROFILE_H + +#include + +class ContextProperty; + +class PhoneProfile : public QObject { + Q_OBJECT + + Q_PROPERTY(bool isSilent READ isSilent NOTIFY isSilentChanged); + +public: + PhoneProfile(QObject *parent = 0); + ~PhoneProfile(); + + bool isSilent(); + +signals: + void isSilentChanged(); + +private slots: + void phoneProfileChanged(); + +private: + ContextProperty *m_profile; + bool m_isSilent; +}; + +#endif /* PHONE_PROFILE_H */ diff --git a/src/main.cpp b/src/main.cpp index c16eb46..7921138 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,6 +56,7 @@ #include "devicekeys.h" #include "platformsettings.h" #include "dbusservice.h" +#include "phoneprofile.h" #include #ifdef QMLJSDEBUGGER @@ -136,6 +137,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) { qmlRegisterType("CameraPlus", 1, 0, "GridLines"); qmlRegisterType("CameraPlus", 1, 0, "DeviceKeys"); qmlRegisterType("CameraPlus", 1, 0, "PlatformSettings"); + qmlRegisterType("CameraPlus", 1, 0, "PhoneProfile"); view->setSource(QUrl("qrc:/qml/main.qml")); diff --git a/src/sailfish/phoneprofile.cpp b/src/sailfish/phoneprofile.cpp new file mode 100644 index 0000000..b59d823 --- /dev/null +++ b/src/sailfish/phoneprofile.cpp @@ -0,0 +1,38 @@ +// -*- c++ -*- + +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012-2013 Mohammed Sameer + * + * 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 "phoneprofile.h" + +// TODO: +PhoneProfile::PhoneProfile(QObject *parent) : + QObject(parent), + m_isSilent(false) { + +} + +PhoneProfile::~PhoneProfile() { + +} + +bool PhoneProfile::isSilent() { + return m_isSilent; +} diff --git a/src/sailfish/phoneprofile.h b/src/sailfish/phoneprofile.h new file mode 100644 index 0000000..8f655e3 --- /dev/null +++ b/src/sailfish/phoneprofile.h @@ -0,0 +1,46 @@ +// -*- c++ -*- + +/*! + * This file is part of CameraPlus. + * + * Copyright (C) 2012-2013 Mohammed Sameer + * + * 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 PHONE_PROFILE_H +#define PHONE_PROFILE_H + +#include + +class PhoneProfile : public QObject { + Q_OBJECT + + Q_PROPERTY(bool isSilent READ isSilent NOTIFY isSilentChanged); + +public: + PhoneProfile(QObject *parent = 0); + ~PhoneProfile(); + + bool isSilent(); + +signals: + void isSilentChanged(); + +private: + bool m_isSilent; +}; + +#endif /* PHONE_PROFILE_H */ diff --git a/src/sailfish/sailfish.pri b/src/sailfish/sailfish.pri index 56695ae..15abc30 100644 --- a/src/sailfish/sailfish.pri +++ b/src/sailfish/sailfish.pri @@ -11,7 +11,8 @@ HEADERS += sailfish/soundvolumecontrol.h \ sailfish/compass.h \ sailfish/orientation.h \ sailfish/batteryinfo.h \ - sailfish/devicekeys.h + sailfish/devicekeys.h \ + sailfish/phoneprofile.h SOURCES += sailfish/soundvolumecontrol.cpp \ sailfish/deviceinfo.cpp \ @@ -21,4 +22,5 @@ SOURCES += sailfish/soundvolumecontrol.cpp \ sailfish/compass.cpp \ sailfish/orientation.cpp \ sailfish/batteryinfo.cpp \ - sailfish/devicekeys.cpp + sailfish/devicekeys.cpp \ + sailfish/phoneprofile.cpp -- 2.34.1