From 29aaea2d80a9eb1715b6cddfac2d2aacf76358bd Mon Sep 17 00:00:00 2001 From: Andrew Branson Date: Thu, 11 Feb 2016 23:55:16 +0100 Subject: launchpad ~mzanetti/rockwork/trunk r87 --- rockworkd/libpebble/jskit/jskitgeolocation.h | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 rockworkd/libpebble/jskit/jskitgeolocation.h (limited to 'rockworkd/libpebble/jskit/jskitgeolocation.h') diff --git a/rockworkd/libpebble/jskit/jskitgeolocation.h b/rockworkd/libpebble/jskit/jskitgeolocation.h new file mode 100644 index 0000000..582ab32 --- /dev/null +++ b/rockworkd/libpebble/jskit/jskitgeolocation.h @@ -0,0 +1,66 @@ +#ifndef JSKITGEOLOCATION_H +#define JSKITGEOLOCATION_H + +#include +#include +#include +#include +#include + +class JSKitGeolocation : public QObject +{ + Q_OBJECT + QLoggingCategory l; + + struct Watcher; + +public: + explicit JSKitGeolocation(QJSEngine *engine); + + enum PositionError { + PERMISSION_DENIED = 1, + POSITION_UNAVAILABLE = 2, + TIMEOUT = 3 + }; + Q_ENUMS(PositionError); + + Q_INVOKABLE void getCurrentPosition(const QJSValue &successCallback, const QJSValue &errorCallback = QJSValue(), const QVariantMap &options = QVariantMap()); + Q_INVOKABLE int watchPosition(const QJSValue &successCallback, const QJSValue &errorCallback = QJSValue(), const QVariantMap &options = QVariantMap()); + Q_INVOKABLE void clearWatch(int watcherId); + +private slots: + void handleError(const QGeoPositionInfoSource::Error error); + void handlePosition(const QGeoPositionInfo &pos); + void handleTimeout(); + void updateTimeouts(); + +private: + int setupWatcher(const QJSValue &successCallback, const QJSValue &errorCallback, const QVariantMap &options, bool once); + void removeWatcher(int watcherId); + + QJSValue buildPositionObject(const QGeoPositionInfo &pos); + QJSValue buildPositionErrorObject(PositionError error, const QString &message = QString()); + QJSValue buildPositionErrorObject(const QGeoPositionInfoSource::Error error); + void invokeCallback(QJSValue callback, QJSValue event); + void stopAndRemove(); + +private: + QJSEngine *m_engine; + QGeoPositionInfoSource *m_source; + + struct Watcher { + QJSValue successCallback; + QJSValue errorCallback; + int watcherId; + bool once; + bool highAccuracy; + int timeout; + QElapsedTimer timer; + qlonglong maximumAge; + }; + + QList m_watchers; + int m_lastWatcherId; +}; + +#endif // JSKITGEOLOCATION_H -- cgit v1.2.3