From: Mohammed Sameer Date: Sun, 8 Sep 2013 17:52:21 +0000 (+0300) Subject: Don't disable GPS when we are obscured by location-ui or conndlgs X-Git-Url: http://cgit.sxemacs.org/?p=harmattan%2Fcameraplus;a=commitdiff_plain;h=b12f938a7e89a6fd7d363def86c9390da0e47b17 Don't disable GPS when we are obscured by location-ui or conndlgs 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 --- diff --git a/qml/CameraView.qml b/qml/CameraView.qml index 58821a5..9268f5c 100644 --- a/qml/CameraView.qml +++ b/qml/CameraView.qml @@ -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 diff --git a/qml/ImageOverlay.qml b/qml/ImageOverlay.qml index f191b35..ec1ee83 100644 --- a/qml/ImageOverlay.qml +++ b/qml/ImageOverlay.qml @@ -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) diff --git a/qml/MainPage.qml b/qml/MainPage.qml index 731b334..82d914e 100644 --- a/qml/MainPage.qml +++ b/qml/MainPage.qml @@ -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 { diff --git a/qml/PostCaptureView.qml b/qml/PostCaptureView.qml index ea7df23..2dd6f29 100644 --- a/qml/PostCaptureView.qml +++ b/qml/PostCaptureView.qml @@ -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 diff --git a/qml/SettingsView.qml b/qml/SettingsView.qml index 73897d5..150d8b8 100644 --- a/qml/SettingsView.qml +++ b/qml/SettingsView.qml @@ -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 diff --git a/qml/VideoOverlay.qml b/qml/VideoOverlay.qml index 164ebae..7cd62e6 100644 --- a/qml/VideoOverlay.qml +++ b/qml/VideoOverlay.qml @@ -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: { diff --git a/src/harmattan/displaystate.cpp b/src/harmattan/displaystate.cpp index cb612bc..a4ce3fc 100644 --- a/src/harmattan/displaystate.cpp +++ b/src/harmattan/displaystate.cpp @@ -24,12 +24,17 @@ #include 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(); +} diff --git a/src/harmattan/displaystate.h b/src/harmattan/displaystate.h index 4fd527e..076b204 100644 --- a/src/harmattan/displaystate.h +++ b/src/harmattan/displaystate.h @@ -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; diff --git a/src/harmattan/harmattan.pri b/src/harmattan/harmattan.pri index 4c148ad..71ea401 100644 --- a/src/harmattan/harmattan.pri +++ b/src/harmattan/harmattan.pri @@ -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 index 0000000..afe8f1e --- /dev/null +++ b/src/harmattan/platformquirks.cpp @@ -0,0 +1,77 @@ +// -*- 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 "platformquirks.h" +#include +#include +#include +#include + +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, ¶m); + 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 index 0000000..f6ebf3c --- /dev/null +++ b/src/harmattan/platformquirks.h @@ -0,0 +1,49 @@ +// -*- 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 PLATFORM_QUIRKS_H +#define PLATFORM_QUIRKS_H + +#include + +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 */ diff --git a/src/main.cpp b/src/main.cpp index 7921138..278e475 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,6 +57,7 @@ #include "platformsettings.h" #include "dbusservice.h" #include "phoneprofile.h" +#include "platformquirks.h" #include #ifdef QMLJSDEBUGGER @@ -138,6 +139,7 @@ Q_DECL_EXPORT int main(int argc, char *argv[]) { qmlRegisterType("CameraPlus", 1, 0, "DeviceKeys"); qmlRegisterType("CameraPlus", 1, 0, "PlatformSettings"); qmlRegisterType("CameraPlus", 1, 0, "PhoneProfile"); + qmlRegisterType("CameraPlus", 1, 0, "PlatformQuirks"); view->setSource(QUrl("qrc:/qml/main.qml"));