Make sure we don't play camera sounds in silent profile
authorMohammed Sameer <msameer@foolab.org>
Mon, 19 Aug 2013 23:10:49 +0000 (02:10 +0300)
committerMohammed Sameer <msameer@foolab.org>
Mon, 19 Aug 2013 23:10:49 +0000 (02:10 +0300)
debian/control
qml/CameraView.qml
src/harmattan/harmattan.pri
src/harmattan/phoneprofile.cpp [new file with mode: 0644]
src/harmattan/phoneprofile.h [new file with mode: 0644]
src/main.cpp
src/sailfish/phoneprofile.cpp [new file with mode: 0644]
src/sailfish/phoneprofile.h [new file with mode: 0644]
src/sailfish/sailfish.pri

index 0336d0c..341b457 100644 (file)
@@ -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
index 0cb80c1..58821a5 100644 (file)
@@ -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
index 8569111..4c148ad 100644 (file)
@@ -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 (file)
index 0000000..083a991
--- /dev/null
@@ -0,0 +1,54 @@
+// -*- 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 "phoneprofile.h"
+#include <contextsubscriber/contextproperty.h>
+
+#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 (file)
index 0000000..58cc42c
--- /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 PHONE_PROFILE_H
+#define PHONE_PROFILE_H
+
+#include <QObject>
+
+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 */
index c16eb46..7921138 100644 (file)
@@ -56,6 +56,7 @@
 #include "devicekeys.h"
 #include "platformsettings.h"
 #include "dbusservice.h"
+#include "phoneprofile.h"
 #include <MDeclarativeCache>
 
 #ifdef QMLJSDEBUGGER
@@ -136,6 +137,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) {
   qmlRegisterType<GridLines>("CameraPlus", 1, 0, "GridLines");
   qmlRegisterType<DeviceKeys>("CameraPlus", 1, 0, "DeviceKeys");
   qmlRegisterType<PlatformSettings>("CameraPlus", 1, 0, "PlatformSettings");
+  qmlRegisterType<PhoneProfile>("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 (file)
index 0000000..b59d823
--- /dev/null
@@ -0,0 +1,38 @@
+// -*- 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 "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 (file)
index 0000000..8f655e3
--- /dev/null
@@ -0,0 +1,46 @@
+// -*- 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 PHONE_PROFILE_H
+#define PHONE_PROFILE_H
+
+#include <QObject>
+
+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 */
index 56695ae..15abc30 100644 (file)
@@ -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