Don't disable GPS when we are obscured by location-ui or conndlgs
authorMohammed Sameer <msameer@foolab.org>
Sun, 8 Sep 2013 17:52:21 +0000 (20:52 +0300)
committerMohammed Sameer <msameer@foolab.org>
Sun, 8 Sep 2013 17:52:21 +0000 (20:52 +0300)
Achieved by adding a PlatformQuirks QML component which takes care of
forcing camera to be on.

On Harmattan it forces on when we are obscured by location-ui (for positioning terms)
or conndlgs (for connection establishment).

As a side effect, we now prevent display dimming while playing a video in post capture

12 files changed:
qml/CameraView.qml
qml/ImageOverlay.qml
qml/MainPage.qml
qml/PostCaptureView.qml
qml/SettingsView.qml
qml/VideoOverlay.qml
src/harmattan/displaystate.cpp
src/harmattan/displaystate.h
src/harmattan/harmattan.pri
src/harmattan/platformquirks.cpp [new file with mode: 0644]
src/harmattan/platformquirks.h [new file with mode: 0644]
src/main.cpp

index 58821a5..9268f5c 100644 (file)
@@ -29,6 +29,7 @@ Viewfinder {
     property bool pressed: focusReticle.locked || preview.animationRunning
         || (loader.item ? loader.item.pressed : false)
     property int policyMode: loader.item ? loader.item.policyMode : CameraResources.None
+    property bool inhibitDim: loader.item ? loader.item.inhibitDim : false
 
     camera: cam
     cameraConfig: cam.cameraConfig
index f191b35..ec1ee83 100644 (file)
@@ -33,6 +33,7 @@ Item {
     property bool pressed: capture.pressed || zoomSlider.pressed || modeButton.pressed
     property bool controlsVisible: imageMode.canCapture && cam.running && !animationRunning
         && dimmer.opacity == 0.0 && !cameraMode.busy
+    property bool inhibitDim: false
 
     signal previewAvailable(string uri)
 
index 731b334..82d914e 100644 (file)
@@ -151,12 +151,19 @@ CameraPage {
     }
 
     property alias dimmer: camDimmer
+
+    PlatformQuirks {
+        id: platformQuirks
+    }
+
+    DisplayState {
+        id: displayState
+        inhibitDim: mainView.currentItem != null ? mainView.currentItem.inhibitDim : false
+    }
+
     CameraPositionSource {
         id: positionSource
-        active: settings.useGps
-        // TODO: we cannot bind to cam.running because camera will stop
-        // when the connection dialog pops up and we end up with an infinite loop
-        // active: cam.running && settings.useGps
+        active: (viewfinder.camera.running || platformQuirks.forceOn) && settings.useGps && displayState.isOn
         onPositionChanged: geocode.search(position.coordinate.longitude, position.coordinate.latitude)
     }
 
@@ -195,7 +202,7 @@ CameraPage {
 
     ReverseGeocode {
         id: geocode
-        active: viewfinder.camera.running && settings.useGps && settings.useGeotags
+        active: (viewfinder.camera.running || platformQuirks.forceOn) && settings.useGps && settings.useGeotags && displayState.isOn
     }
 
     DeviceInfo {
index ea7df23..2dd6f29 100644 (file)
@@ -32,6 +32,7 @@ Item {
     property int policyMode: view.currentItem && view.currentItem.playing ?
         CameraResources.Player : settings.mode == Camera.VideoMode ? CameraResources.Video :
         CameraResources.Image
+    property bool inhibitDim: pressed
 
     property bool isCurrent: mainView.currentIndex == 2 && !mainView.moving
     property bool inCameraMode: root.inCaptureMode && !mainView.moving
index 73897d5..150d8b8 100644 (file)
@@ -28,6 +28,8 @@ Item {
     property Camera camera: null
     property int policyMode: settings.mode == Camera.VideoMode ? CameraResources.Video
         : CameraResources.Image
+    property bool pressed: false
+    property bool inhibitDim: false
 
     Loader {
         id: loader
index 164ebae..7cd62e6 100644 (file)
@@ -35,6 +35,7 @@ Item {
         && dimmer.opacity == 0.0 && !cameraMode.busy
     property bool pressed: overlay.recording || capture.pressed ||
         zoomSlider.pressed || modeButton.pressed
+    property bool inhibitDim: recording
 
     signal previewAvailable(string uri)
 
@@ -203,10 +204,6 @@ Item {
         }
     }
 
-    DisplayState {
-        inhibitDim: overlay.recording
-    }
-
     Connections {
         target: Qt.application
         onActiveChanged: {
index cb612bc..a4ce3fc 100644 (file)
 #include <QDebug>
 
 DisplayState::DisplayState(QObject *parent) :
-  QObject(parent), m_state(new MeeGo::QmDisplayState(this)), m_timer(new QTimer(this)) {
+  QObject(parent),
+  m_state(new MeeGo::QmDisplayState(this)),
+  m_timer(new QTimer(this)) {
 
   m_timer->setSingleShot(false);
   m_timer->setInterval(50 * 1000);
 
   QObject::connect(m_timer, SIGNAL(timeout()), this, SLOT(timeout()));
+
+  QObject::connect(m_state, SIGNAL(displayStateChanged(MeeGo::QmDisplayState::DisplayState)),
+                  this, SLOT(displayStateChanged()));
 }
 
 DisplayState::~DisplayState() {
@@ -69,3 +74,11 @@ void DisplayState::timeout() {
     qWarning() << "Failed to inhibit display dimming!";
   }
 }
+
+bool DisplayState::isOn() {
+  return m_state->get() == MeeGo::QmDisplayState::On;
+}
+
+void DisplayState::displayStateChanged() {
+  emit isOnChanged();
+}
index 4fd527e..076b204 100644 (file)
@@ -33,6 +33,7 @@ namespace MeeGo {
 class DisplayState : public QObject {
   Q_OBJECT
   Q_PROPERTY(bool inhibitDim READ isDimInhibited WRITE setInhibitDim NOTIFY inhibitDimChanged);
+  Q_PROPERTY(bool isOn READ isOn NOTIFY isOnChanged);
 
 public:
   DisplayState(QObject *parent = 0);
@@ -41,11 +42,15 @@ public:
   bool isDimInhibited() const;
   void setInhibitDim(bool inhibit);
 
+  bool isOn();
+
 signals:
   void inhibitDimChanged();
+  void isOnChanged();
 
 private slots:
   void timeout();
+  void displayStateChanged();
 
 private:
   MeeGo::QmDisplayState *m_state;
index 4c148ad..71ea401 100644 (file)
@@ -5,8 +5,10 @@ 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 phoneprofile.h
+          displaystate.h fsmonitor.h orientation.h phoneprofile.h \
+           platformquirks.h
 
 SOURCES += quillitem.cpp soundvolumecontrol.cpp deviceinfo.cpp geocode.cpp \
           batteryinfo.cpp compass.cpp devicekeys.cpp \
-          displaystate.cpp fsmonitor.cpp orientation.cpp phoneprofile.cpp
+          displaystate.cpp fsmonitor.cpp orientation.cpp phoneprofile.cpp \
+           platformquirks.cpp
diff --git a/src/harmattan/platformquirks.cpp b/src/harmattan/platformquirks.cpp
new file mode 100644 (file)
index 0000000..afe8f1e
--- /dev/null
@@ -0,0 +1,77 @@
+// -*- 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 "platformquirks.h"
+#include <QApplication>
+#include <QEvent>
+#include <QX11Info>
+#include <X11/Xlib.h>
+
+PlatformQuirks::PlatformQuirks(QObject *parent) :
+  QObject(parent),
+  m_state(false),
+  m_check(true) {
+
+  qApp->installEventFilter(this);
+}
+
+PlatformQuirks::~PlatformQuirks() {
+
+}
+
+bool PlatformQuirks::isOnForced() {
+  if (!m_check) {
+    return m_state;
+  }
+
+  int param = 0;
+  char *winName = 0;
+  Window winFocus;
+
+  Display *d = QX11Info::display();
+
+  XGetInputFocus(d, &winFocus, &param);
+  XFetchName(d, winFocus, &winName);
+
+  m_state = (QLatin1String(winName) == "location-ui" || QLatin1String(winName) == "conndlgs");
+  XFree(winName);
+
+  m_check = false;
+  return m_state;
+}
+
+bool PlatformQuirks::eventFilter(QObject *obj, QEvent *event) {
+  if (event->type() == QEvent::ApplicationActivate) {
+    m_check = false;
+
+    if (!m_state) {
+      m_state = true;
+      emit forceOnChanged();
+    }
+  }
+  else if (event->type() == QEvent::ApplicationDeactivate) {
+    m_check = true;
+    emit forceOnChanged();
+  }
+
+  return QObject::eventFilter(obj, event);
+}
diff --git a/src/harmattan/platformquirks.h b/src/harmattan/platformquirks.h
new file mode 100644 (file)
index 0000000..f6ebf3c
--- /dev/null
@@ -0,0 +1,49 @@
+// -*- 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 PLATFORM_QUIRKS_H
+#define PLATFORM_QUIRKS_H
+
+#include <QObject>
+
+class PlatformQuirks : public QObject {
+  Q_OBJECT
+  Q_PROPERTY(bool forceOn READ isOnForced NOTIFY forceOnChanged);
+
+public:
+  PlatformQuirks(QObject *parent = 0);
+  ~PlatformQuirks();
+
+  bool isOnForced();
+
+protected:
+  bool eventFilter(QObject *obj, QEvent *event);
+
+signals:
+  void forceOnChanged();
+
+private:
+  bool m_state;
+  bool m_check;
+};
+
+#endif /* PLATFORM_QUIRKS_H */
index 7921138..278e475 100644 (file)
@@ -57,6 +57,7 @@
 #include "platformsettings.h"
 #include "dbusservice.h"
 #include "phoneprofile.h"
+#include "platformquirks.h"
 #include <MDeclarativeCache>
 
 #ifdef QMLJSDEBUGGER
@@ -138,6 +139,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) {
   qmlRegisterType<DeviceKeys>("CameraPlus", 1, 0, "DeviceKeys");
   qmlRegisterType<PlatformSettings>("CameraPlus", 1, 0, "PlatformSettings");
   qmlRegisterType<PhoneProfile>("CameraPlus", 1, 0, "PhoneProfile");
+  qmlRegisterType<PlatformQuirks>("CameraPlus", 1, 0, "PlatformQuirks");
 
   view->setSource(QUrl("qrc:/qml/main.qml"));