From 2aa05505684373ac4aeff3547adf16c17ba9934f Mon Sep 17 00:00:00 2001 From: Rodrigo Linfati Date: Thu, 28 Jul 2011 03:42:20 +0200 Subject: [PATCH] Backport of QGeo*InfoSourceMaemo5 and others fixes --- LatitudeUpdater-common.pri | 18 +- LatitudeUpdater.pro | 28 +- googlelatitude.cpp | 10 +- gpscontrol.cpp | 44 +-- latitudewidget.h | 32 +- liblocationmaemo5/gconfitem.cpp | 364 +++++++++++++++++++ liblocationmaemo5/gconfitem_p.h | 166 +++++++++ liblocationmaemo5/liblocationwrapper.cpp | 379 ++++++++++++++++++++ liblocationmaemo5/liblocationwrapper_p.h | 121 +++++++ .../qgeopositioninfosource_maemo5.cpp | 370 +++++++++++++++++++ .../qgeopositioninfosource_maemo5_p.h | 129 +++++++ .../qgeosatelliteinfosource_maemo5.cpp | 246 +++++++++++++ .../qgeosatelliteinfosource_maemo5_p.h | 119 ++++++ not_used/glupdater | 13 - not_used/gpsmaemo5.cpp | 110 ------ not_used/gpsmaemo5.h | 63 ---- 16 files changed, 1976 insertions(+), 236 deletions(-) create mode 100644 liblocationmaemo5/gconfitem.cpp create mode 100644 liblocationmaemo5/gconfitem_p.h create mode 100644 liblocationmaemo5/liblocationwrapper.cpp create mode 100644 liblocationmaemo5/liblocationwrapper_p.h create mode 100644 liblocationmaemo5/qgeopositioninfosource_maemo5.cpp create mode 100644 liblocationmaemo5/qgeopositioninfosource_maemo5_p.h create mode 100644 liblocationmaemo5/qgeosatelliteinfosource_maemo5.cpp create mode 100644 liblocationmaemo5/qgeosatelliteinfosource_maemo5_p.h delete mode 100644 not_used/glupdater delete mode 100644 not_used/gpsmaemo5.cpp delete mode 100644 not_used/gpsmaemo5.h diff --git a/LatitudeUpdater-common.pri b/LatitudeUpdater-common.pri index 08adb36..a8a781d 100644 --- a/LatitudeUpdater-common.pri +++ b/LatitudeUpdater-common.pri @@ -1,5 +1,5 @@ -QT += network -CONFIG += mobility +QT += network +CONFIG += mobility MOBILITY += location SOURCES += gpscontrol.cpp googlelatitude.cpp @@ -18,22 +18,30 @@ libkqoauth/kqoauthmanager.cpp \ libkqoauth/kqoauthrequest_xauth.cpp \ libkqoauth/kqoauthrequest_1.cpp \ libkqoauth/kqoauthutils.cpp - PUBLIC_HEADERS += libkqoauth/kqoauthmanager.h \ libkqoauth/kqoauthrequest.h \ libkqoauth/kqoauthrequest_1.h \ libkqoauth/kqoauthrequest_xauth.h \ libkqoauth/kqoauthglobals.h - PRIVATE_HEADERS += libkqoauth/kqoauthrequest_p.h \ libkqoauth/kqoauthmanager_p.h \ libkqoauth/kqoauthauthreplyserver.h \ libkqoauth/kqoauthauthreplyserver_p.h \ libkqoauth/kqoauthutils.h \ libkqoauth/kqoauthrequest_xauth_p.h - HEADERS += $$PUBLIC_HEADERS $$PRIVATE_HEADERS +contains(QT_CONFIG, maemo5): { + SOURCES += liblocationmaemo5/gconfitem.cpp \ + liblocationmaemo5/liblocationwrapper.cpp \ + liblocationmaemo5/qgeopositioninfosource_maemo5.cpp \ + liblocationmaemo5/qgeosatelliteinfosource_maemo5.cpp + HEADERS += liblocationmaemo5/gconfitem_p.h \ + liblocationmaemo5/liblocationwrapper_p.h \ + liblocationmaemo5/qgeopositioninfosource_maemo5_p.h \ + liblocationmaemo5/qgeosatelliteinfosource_maemo5_p.h +} + # Please do not modify the following two lines. Required for deployment. include(deployment.pri) qtcAddDeployment() diff --git a/LatitudeUpdater.pro b/LatitudeUpdater.pro index e104265..c5df4ec 100644 --- a/LatitudeUpdater.pro +++ b/LatitudeUpdater.pro @@ -1,4 +1,26 @@ TEMPLATE = subdirs -SUBDIRS += LatitudeUpdater-daemon.pro -SUBDIRS += LatitudeUpdater-qml.pro -SUBDIRS += LatitudeUpdater-widget.pro + +exists($$QMAKE_INCDIR_QT"/../qmsystem2/qmkeys.h"):!contains(MEEGO_EDITION,harmattan): { + MEEGO_VERSION_MAJOR = 1 + MEEGO_VERSION_MINOR = 2 + MEEGO_VERSION_PATCH = 0 + MEEGO_EDITION = harmattan + DEFINES += MEEGO_EDITION_HARMATTAN +} + +contains(MEEGO_EDITION,harmattan): { + SUBDIRS += LatitudeUpdater-daemon.pro + SUBDIRS += LatitudeUpdater-qml.pro +} + +contains(QT_CONFIG, maemo5): { + SUBDIRS += LatitudeUpdater-daemon.pro + SUBDIRS += LatitudeUpdater-widget.pro +} + +!contains(MEEGO_EDITION,harmattan):!contains(QT_CONFIG, maemo5): { + SUBDIRS += LatitudeUpdater-daemon.pro + SUBDIRS += LatitudeUpdater-qml.pro + SUBDIRS += LatitudeUpdater-widget.pro +} + diff --git a/googlelatitude.cpp b/googlelatitude.cpp index 81b1d5b..47e90c5 100644 --- a/googlelatitude.cpp +++ b/googlelatitude.cpp @@ -95,12 +95,10 @@ void GoogleLatitude::sendCurrentLocation() { if (abs(CurrentLongitude) <= 0.01) return; if (abs(CurrentAccuracy) <= 0.01) return; - if (!OauthSettings.value("net_auto").toBool()) { - QNetworkConfigurationManager mgr; - if (!mgr.isOnline()) { - qDebug() << "* GoogleLatitude::sendCurrentLocation" << "offline"; - return; - } + QNetworkConfigurationManager mgr; + if (!OauthSettings.value("net_auto").toBool() && !mgr.isOnline()) { + qDebug() << "* GoogleLatitude::sendCurrentLocation" << "offline"; + return; } QByteArray json_location; diff --git a/gpscontrol.cpp b/gpscontrol.cpp index 8df1cc1..2b900c9 100644 --- a/gpscontrol.cpp +++ b/gpscontrol.cpp @@ -19,8 +19,8 @@ GpsControl::GpsControl(QObject *parent) : if (!GpsSource) qDebug() << "* GpsControl::GpsControl" << "Not GpsSource"; - connect(GpsSource, SIGNAL(positionUpdated(QGeoPositionInfo)), - this, SLOT(setCurrentLocation(QGeoPositionInfo))); + if (GpsSource) connect(GpsSource, SIGNAL(positionUpdated(QGeoPositionInfo)), + this, SLOT(setCurrentLocation(QGeoPositionInfo))); connect(this, SIGNAL(gotUpdate()), this, SLOT(onGotUpdate())); @@ -54,45 +54,49 @@ void GpsControl::setPositioningMethod(QString method) { qDebug() << "* GpsControl::setPositioningMethod" << method; if (method == "gps") { GpsSettings.setValue("gps_method", method); - if (GpsSource) GpsSource->setPreferredPositioningMethods(QGeoPositionInfoSource::SatellitePositioningMethods); + if (GpsSource) GpsSource->setPreferredPositioningMethods( + QGeoPositionInfoSource::SatellitePositioningMethods); } if (method == "cell") { GpsSettings.setValue("gps_method", method); - if (GpsSource) GpsSource->setPreferredPositioningMethods(QGeoPositionInfoSource::NonSatellitePositioningMethods); + if (GpsSource) GpsSource->setPreferredPositioningMethods( + QGeoPositionInfoSource::NonSatellitePositioningMethods); } if (method == "all") { GpsSettings.setValue("gps_method", method); - if (GpsSource) GpsSource->setPreferredPositioningMethods(QGeoPositionInfoSource::AllPositioningMethods); + if (GpsSource) GpsSource->setPreferredPositioningMethods( + QGeoPositionInfoSource::AllPositioningMethods); } } void GpsControl::startUpdates() { - qDebug() << "* GpsControl::start"; - if (!GpsSettings.value("net_auto").toBool()) { - QNetworkConfigurationManager mgr; - if (!mgr.isOnline()) { - qDebug() << "* GpsControl::start" << "offline"; - return; - } - } + qDebug() << "* GpsControl::startUpdates"; - if (!GpsSource) return; + GpsTimeout.singleShot(GpsSettings.value("gps_timeout").toInt()*1000, + this, SLOT(stopUpdates())); + GpsInterval.singleShot(GpsSettings.value("gps_interval").toInt()*1000, + this, SLOT(startUpdates())); - GpsTimeout.singleShot(GpsSettings.value("gps_timeout").toInt()*1000, this, SLOT(stopUpdates())); - GpsInterval.singleShot(GpsSettings.value("gps_interval").toInt()*1000, this, SLOT(startUpdates())); - GpsSource->startUpdates(); + QNetworkConfigurationManager mgr; + if (!GpsSettings.value("net_auto").toBool() && !mgr.isOnline()) { + qDebug() << "* GpsControl::startUpdates" << "offline"; + return; + } + + if (GpsSource) GpsSource->startUpdates(); } void GpsControl::stopUpdates(bool force) { qDebug() << "* GpsControl::stopUpdates" << force; - if (!GpsSource) return; - GpsSource->stopUpdates(); + + if (GpsSource) GpsSource->stopUpdates(); if (force) { GpsTimeout.stop(); GpsInterval.stop(); } else { - if (GpsSource->lastKnownPosition(GpsSettings.value("gps_method") == "gps"?true:false).isValid() ) { + if (GpsSource && GpsSource->lastKnownPosition(GpsSettings.value("gps_method") + == "gps" ? true : false).isValid() ) { emit gotFix(); } } diff --git a/latitudewidget.h b/latitudewidget.h index b4e6e8a..d626f6f 100644 --- a/latitudewidget.h +++ b/latitudewidget.h @@ -28,7 +28,7 @@ public slots: private slots: void gl_GotToken() { - qDebug() << "LatitudeGUI::gl_GotToken"; + qDebug() << "* LatitudeGUI::gl_GotToken"; do_oauth->setDisabled(true); if (system("killall -0 LatitudeUpdaterDaemon 2> /dev/null" )) { do_start->setEnabled(true); @@ -39,75 +39,75 @@ private slots: } } void gl_NotToken() { - qDebug() << "LatitudeGUI::gl_NotToken"; + qDebug() << "* LatitudeGUI::gl_NotToken"; do_oauth->setEnabled(true); do_start->setDisabled(true); do_stop->setDisabled(true); gps.stopUpdates(true); } void gl_needAuth() { - qDebug() << "LatitudeGUI::gl_needAuth"; + qDebug() << "* LatitudeGUI::gl_needAuth"; do_oauth->setEnabled(true); } void gl_webauth() { - qDebug() << "LatitudeGUI::gl_webauth"; + qDebug() << "* LatitudeGUI::gl_webauth"; QDesktopServices::openUrl(latitude.getUserAuthorization()); } void gps_start() { - qDebug() << "LatitudeGUI::gps_start"; + qDebug() << "* LatitudeGUI::gps_start"; do_start->setDisabled(true); do_stop->setEnabled(true); if (demonioOpt.exists()) { - qDebug() << "LatitudeGUI:: demonio opt"; + qDebug() << "* LatitudeGUI:: demonio opt"; cli.startDetached(demonioOpt.fileName()); } else if (demonioSdk.exists()) { - qDebug() << "LatitudeGUI:: demonio sdk"; + qDebug() << "* LatitudeGUI:: demonio sdk"; cli.startDetached(demonioSdk.fileName()); } else { - qDebug() << "LatitudeGUI:: demonio none"; + qDebug() << "* LatitudeGUI:: demonio none"; gps.startUpdates(); } } void gps_stop() { - qDebug() << "LatitudeGUI::gps_stop"; + qDebug() << "* LatitudeGUI::gps_stop"; do_start->setEnabled(true); do_stop->setDisabled(true); if (demonioOpt.exists() || demonioSdk.exists() ) { - qDebug() << "LatitudeGUI:: demonio kill" << system("killall LatitudeUpdaterDaemon 2> /dev/null"); + qDebug() << "* LatitudeGUI:: demonio kill" << system("killall LatitudeUpdaterDaemon 2> /dev/null"); } else { gps.stopUpdates(true); } } void set_latitude() { - qDebug() << "LatitudeGUI::set_latitude"; + qDebug() << "* LatitudeGUI::set_latitude"; latitude.setCurrentLocation(gps.getCurrentLatitude(), gps.getCurrentLongitude(), gps.getCurrentAccuracy()); latitude.sendCurrentLocation(); } void set_method() { - qDebug() << "LatitudeGUI::set_method"; + qDebug() << "* LatitudeGUI::set_method"; if (gps_cell->isChecked()) gps.setPositioningMethod("cell"); if (gps_both->isChecked()) gps.setPositioningMethod("all"); if (gps_agps->isChecked()) gps.setPositioningMethod("gps"); } void set_to(int value) { - qDebug() << "LatitudeGUI::set_to()" << value; + qDebug() << "* LatitudeGUI::set_to()" << value; gps.setTimeOut(value); gps_to_slider_value->setText(QString("%1 sec.").arg(value)); } void set_i(int value) { - qDebug() << "LatitudeGUI::set_i()" << value; + qDebug() << "* LatitudeGUI::set_i()" << value; gps.setInterval(value*60); gps_i_slider_value->setText(QString("%1 min.").arg(value)); } void set_ac_yes() { - qDebug() << "LatitudeGUI::set_ac_yes"; + qDebug() << "* LatitudeGUI::set_ac_yes"; latitude.setAutoConnect(true); } void set_ac_not() { - qDebug() << "LatitudeGUI::set_ac_not"; + qDebug() << "* LatitudeGUI::set_ac_not"; latitude.setAutoConnect(false); } diff --git a/liblocationmaemo5/gconfitem.cpp b/liblocationmaemo5/gconfitem.cpp new file mode 100644 index 0000000..508d766 --- /dev/null +++ b/liblocationmaemo5/gconfitem.cpp @@ -0,0 +1,364 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include + +#include "gconfitem_p.h" + +#include +#include +#include + +struct GConfItemPrivate { + QString key; + QVariant value; + guint notify_id; + + static void notify_trampoline(GConfClient*, guint, GConfEntry *, gpointer); +}; + +#define withClient(c) for(GConfClient *c = (g_type_init(), gconf_client_get_default()); c; g_object_unref(c), c=NULL) + +static QByteArray convertKey(QString key) +{ + if (key.startsWith('/')) + return key.toUtf8(); + else { + qWarning() << "Using dot-separated key names with GConfItem is deprecated."; + qWarning() << "Please use" << '/' + key.replace('.', '/') << "instead of" << key; + return '/' + key.replace('.', '/').toUtf8(); + } +} + +static QString convertKey(const char *key) +{ + return QString::fromUtf8(key); +} + +static QVariant convertValue(GConfValue *src) +{ + if (!src) { + return QVariant(); + } else { + switch (src->type) { + case GCONF_VALUE_INVALID: + return QVariant(QVariant::Invalid); + case GCONF_VALUE_BOOL: + return QVariant((bool)gconf_value_get_bool(src)); + case GCONF_VALUE_INT: + return QVariant(gconf_value_get_int(src)); + case GCONF_VALUE_FLOAT: + return QVariant(gconf_value_get_float(src)); + case GCONF_VALUE_STRING: + return QVariant(QString::fromUtf8(gconf_value_get_string(src))); + case GCONF_VALUE_LIST: + switch (gconf_value_get_list_type(src)) { + case GCONF_VALUE_STRING: { + QStringList result; + for (GSList *elts = gconf_value_get_list(src); elts; elts = elts->next) + result.append(QString::fromUtf8(gconf_value_get_string((GConfValue *)elts->data))); + return QVariant(result); + } + default: { + QList result; + for (GSList *elts = gconf_value_get_list(src); elts; elts = elts->next) + result.append(convertValue((GConfValue *)elts->data)); + return QVariant(result); + } + } + case GCONF_VALUE_SCHEMA: + default: + return QVariant(); + } + } +} + +static GConfValue *convertString(const QString &str) +{ + GConfValue *v = gconf_value_new(GCONF_VALUE_STRING); + gconf_value_set_string(v, str.toUtf8().data()); + return v; +} + +static GConfValueType primitiveType(const QVariant &elt) +{ + switch (elt.type()) { + case QVariant::String: + return GCONF_VALUE_STRING; + case QVariant::Int: + return GCONF_VALUE_INT; + case QVariant::Double: + return GCONF_VALUE_FLOAT; + case QVariant::Bool: + return GCONF_VALUE_BOOL; + default: + return GCONF_VALUE_INVALID; + } +} + +static GConfValueType uniformType(const QList &list) +{ + GConfValueType result = GCONF_VALUE_INVALID; + + foreach(const QVariant &elt, list) { + GConfValueType elt_type = primitiveType(elt); + + if (elt_type == GCONF_VALUE_INVALID) + return GCONF_VALUE_INVALID; + + if (result == GCONF_VALUE_INVALID) + result = elt_type; + else if (result != elt_type) + return GCONF_VALUE_INVALID; + } + + if (result == GCONF_VALUE_INVALID) + return GCONF_VALUE_STRING; // empty list. + else + return result; +} + +static int convertValue(const QVariant &src, GConfValue **valp) +{ + GConfValue *v; + + switch (src.type()) { + case QVariant::Invalid: + v = NULL; + break; + case QVariant::Bool: + v = gconf_value_new(GCONF_VALUE_BOOL); + gconf_value_set_bool(v, src.toBool()); + break; + case QVariant::Int: + v = gconf_value_new(GCONF_VALUE_INT); + gconf_value_set_int(v, src.toInt()); + break; + case QVariant::Double: + v = gconf_value_new(GCONF_VALUE_FLOAT); + gconf_value_set_float(v, src.toDouble()); + break; + case QVariant::String: + v = convertString(src.toString()); + break; + case QVariant::StringList: { + GSList *elts = NULL; + v = gconf_value_new(GCONF_VALUE_LIST); + gconf_value_set_list_type(v, GCONF_VALUE_STRING); + foreach(const QString &str, src.toStringList()) + elts = g_slist_prepend(elts, convertString(str)); + gconf_value_set_list_nocopy(v, g_slist_reverse(elts)); + break; + } + case QVariant::List: { + GConfValueType elt_type = uniformType(src.toList()); + if (elt_type == GCONF_VALUE_INVALID) + v = NULL; + else { + GSList *elts = NULL; + v = gconf_value_new(GCONF_VALUE_LIST); + gconf_value_set_list_type(v, elt_type); + foreach(const QVariant &elt, src.toList()) { + GConfValue *val = NULL; + convertValue(elt, &val); // guaranteed to succeed. + elts = g_slist_prepend(elts, val); + } + gconf_value_set_list_nocopy(v, g_slist_reverse(elts)); + } + break; + } + default: + return 0; + } + + *valp = v; + return 1; +} + +void GConfItemPrivate::notify_trampoline(GConfClient*, + guint, + GConfEntry *, + gpointer data) +{ + GConfItem *item = (GConfItem *)data; + item->update_value(true); +} + +void GConfItem::update_value(bool emit_signal) +{ + QVariant new_value; + + withClient(client) { + GError *error = NULL; + QByteArray k = convertKey(priv->key); + GConfValue *v = gconf_client_get(client, k.data(), &error); + + if (error) { + qWarning() << error->message; + g_error_free(error); + new_value = priv->value; + } else { + new_value = convertValue(v); + if (v) + gconf_value_free(v); + } + } + + if (new_value != priv->value) { + priv->value = new_value; + if (emit_signal) + emit valueChanged(); + } +} + +QString GConfItem::key() const +{ + return priv->key; +} + +QVariant GConfItem::value() const +{ + return priv->value; +} + +QVariant GConfItem::value(const QVariant &def) const +{ + if (priv->value.isNull()) + return def; + else + return priv->value; +} + +void GConfItem::set(const QVariant &val) +{ + withClient(client) { + QByteArray k = convertKey(priv->key); + GConfValue *v; + if (convertValue(val, &v)) { + GError *error = NULL; + + if (v) { + gconf_client_set(client, k.data(), v, &error); + gconf_value_free(v); + } else { + gconf_client_unset(client, k.data(), &error); + } + + if (error) { + qWarning() << error->message; + g_error_free(error); + } else if (priv->value != val) { + priv->value = val; + emit valueChanged(); + } + + } else + qWarning() << "Can't store a" << val.typeName(); + } +} + +void GConfItem::unset() +{ + set(QVariant()); +} + +QList GConfItem::listDirs() const +{ + QList children; + + withClient(client) { + QByteArray k = convertKey(priv->key); + GSList *dirs = gconf_client_all_dirs(client, k.data(), NULL); + for (GSList *d = dirs; d; d = d->next) { + children.append(convertKey((char *)d->data)); + g_free(d->data); + } + g_slist_free(dirs); + } + + return children; +} + +QList GConfItem::listEntries() const +{ + QList children; + + withClient(client) { + QByteArray k = convertKey(priv->key); + GSList *entries = gconf_client_all_entries(client, k.data(), NULL); + for (GSList *e = entries; e; e = e->next) { + children.append(convertKey(((GConfEntry *)e->data)->key)); + gconf_entry_free((GConfEntry *)e->data); + } + g_slist_free(entries); + } + + return children; +} + +GConfItem::GConfItem(const QString &key, QObject *parent) + : QObject(parent) +{ + priv = new GConfItemPrivate; + priv->key = key; + withClient(client) { + update_value(false); + QByteArray k = convertKey(priv->key); + gconf_client_add_dir(client, k.data(), GCONF_CLIENT_PRELOAD_ONELEVEL, NULL); + priv->notify_id = gconf_client_notify_add(client, k.data(), + GConfItemPrivate::notify_trampoline, this, + NULL, NULL); + } +} + +GConfItem::~GConfItem() +{ + withClient(client) { + QByteArray k = convertKey(priv->key); + gconf_client_notify_remove(client, priv->notify_id); + gconf_client_remove_dir(client, k.data(), NULL); + } + delete priv; +} diff --git a/liblocationmaemo5/gconfitem_p.h b/liblocationmaemo5/gconfitem_p.h new file mode 100644 index 0000000..ba4c8d6 --- /dev/null +++ b/liblocationmaemo5/gconfitem_p.h @@ -0,0 +1,166 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef GCONFITEM_H +#define GCONFITEM_H + +#include +#include +#include + +/*! + + \brief GConfItem is a simple C++ wrapper for GConf. + + Creating a GConfItem instance gives you access to a single GConf + key. You can get and set its value, and connect to its + valueChanged() signal to be notified about changes. + + The value of a GConf key is returned to you as a QVariant, and you + pass in a QVariant when setting the value. GConfItem converts + between a QVariant and GConf values as needed, and according to the + following rules: + + - A QVariant of type QVariant::Invalid denotes an unset GConf key. + + - QVariant::Int, QVariant::Double, QVariant::Bool are converted to + and from the obvious equivalents. + + - QVariant::String is converted to/from a GConf string and always + uses the UTF-8 encoding. No other encoding is supported. + + - QVariant::StringList is converted to a list of UTF-8 strings. + + - QVariant::List (which denotes a QList) is converted + to/from a GConf list. All elements of such a list must have the + same type, and that type must be one of QVariant::Int, + QVariant::Double, QVariant::Bool, or QVariant::String. (A list of + strings is returned as a QVariant::StringList, however, when you + get it back.) + + - Any other QVariant or GConf value is essentially ignored. + + \warning GConfItem is as thread-safe as GConf. + +*/ + +class GConfItem : public QObject +{ + Q_OBJECT + +public: + /*! Initializes a GConfItem to access the GConf key denoted by + \a key. Key names should follow the normal GConf conventions + like "/myapp/settings/first". + + \param key The name of the key. + \param parent Parent object + */ + explicit GConfItem(const QString &key, QObject *parent = 0); + + /*! Finalizes a GConfItem. + */ + virtual ~GConfItem(); + + /*! Returns the key of this item, as given to the constructor. + */ + QString key() const; + + /*! Returns the current value of this item, as a QVariant. + */ + QVariant value() const; + + /*! Returns the current value of this item, as a QVariant. If + * there is no value for this item, return \a def instead. + */ + QVariant value(const QVariant &def) const; + + /*! Set the value of this item to \a val. If \a val can not be + represented in GConf or GConf refuses to accept it for other + reasons, the current value is not changed and nothing happens. + + When the new value is different from the old value, the + changedValue() signal is emitted on this GConfItem as part + of calling set(), but other GConfItem:s for the same key do + only receive a notification once the main loop runs. + + \param val The new value. + */ + void set(const QVariant &val); + + /*! Unset this item. This is equivalent to + + \code + item.set(QVariant(QVariant::Invalid)); + \endcode + */ + void unset(); + + /*! Return a list of the directories below this item. The + returned strings are absolute key names like + "/myapp/settings". + + A directory is a key that has children. The same key might + also have a value, but that is confusing and best avoided. + */ + QList listDirs() const; + + /*! Return a list of entries below this item. The returned + strings are absolute key names like "/myapp/settings/first". + + A entry is a key that has a value. The same key might also + have children, but that is confusing and is best avoided. + */ + QList listEntries() const; + +signals: + /*! Emitted when the value of this item has changed. + */ + void valueChanged(); + +private: + friend struct GConfItemPrivate; + struct GConfItemPrivate *priv; + + void update_value(bool emit_signal); +}; + +#endif // GCONFITEM_H diff --git a/liblocationmaemo5/liblocationwrapper.cpp b/liblocationmaemo5/liblocationwrapper.cpp new file mode 100644 index 0000000..9d31299 --- /dev/null +++ b/liblocationmaemo5/liblocationwrapper.cpp @@ -0,0 +1,379 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "liblocationwrapper_p.h" + +#include + +using namespace std; + +QTM_BEGIN_NAMESPACE + +Q_GLOBAL_STATIC(LiblocationWrapper, LocationEngine) + +LiblocationWrapper *LiblocationWrapper::instance() +{ + return LocationEngine(); +} + +LiblocationWrapper::LiblocationWrapper() + : file(NULL), + locationControl(NULL), + locationDevice(NULL), + errorHandlerId(0), + posChangedId(0), + origUpdateInterval(0), + startcounter(0), + validLastUpdate(false), + validLastSatUpdate(false), + locationState(LiblocationWrapper::Undefined) { + qDebug() << "* LiblocationWrapper Fremantle Backport"; +} + +LiblocationWrapper::~LiblocationWrapper() +{ + if (locationDevice) + g_object_unref(locationDevice); + if (locationControl) + g_object_unref(locationControl); +} + +bool LiblocationWrapper::inited() +{ + int retval = false; + if (!(locationState & LiblocationWrapper::Inited)) { + g_type_init(); + + locationControl = location_gpsd_control_get_default(); + + if (locationControl) { + g_object_set(G_OBJECT(locationControl), + "preferred-method", LOCATION_METHOD_USER_SELECTED, + "preferred-interval", LOCATION_INTERVAL_1S, + NULL); + locationDevice = + (LocationGPSDevice*)g_object_new(LOCATION_TYPE_GPS_DEVICE, + NULL); + + if (locationDevice) { + errorHandlerId = + g_signal_connect(G_OBJECT(locationControl), "error-verbose", + G_CALLBACK(&locationError), + static_cast(this)); + posChangedId = + g_signal_connect(G_OBJECT(locationDevice), "changed", + G_CALLBACK(&locationChanged), + static_cast(this)); + locationState = LiblocationWrapper::Inited; + retval = true; + startcounter = 0; + } + } + } else { + retval = true; + } + return retval; +} + +void LiblocationWrapper::locationError(LocationGPSDevice *device, + gint errorCode, gpointer data) +{ + Q_UNUSED(device); + QString locationError; + + switch (errorCode) { + case LOCATION_ERROR_USER_REJECTED_DIALOG: + locationError = "User didn't enable requested methods"; + break; + case LOCATION_ERROR_USER_REJECTED_SETTINGS: + locationError = "User changed settings, which disabled location."; + break; + case LOCATION_ERROR_BT_GPS_NOT_AVAILABLE: + locationError = "Problems with BT GPS"; + break; + case LOCATION_ERROR_METHOD_NOT_ALLOWED_IN_OFFLINE_MODE: + locationError = "Requested method is not allowed in offline mode"; + break; + case LOCATION_ERROR_SYSTEM: + locationError = "System error."; + break; + default: + locationError = "Unknown error."; + } + + qDebug() << "Location error:" << locationError; + + LiblocationWrapper *object; + object = (LiblocationWrapper *)data; + emit object->error(); +} + +void LiblocationWrapper::locationChanged(LocationGPSDevice *device, + gpointer data) +{ + QGeoPositionInfo posInfo; + QGeoCoordinate coordinate; + QGeoSatelliteInfo satInfo; + int satellitesInUseCount = 0; + LiblocationWrapper *object; + + if (!data || !device) { + return; + } + + object = (LiblocationWrapper *)data; + + if (device) { + if (device->fix) { + if (device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) { + posInfo.setTimestamp(QDateTime::fromTime_t(device->fix->time)); + } + + if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) { + coordinate.setLatitude(device->fix->latitude); + coordinate.setLongitude(device->fix->longitude); + posInfo.setAttribute(QGeoPositionInfo::HorizontalAccuracy, + device->fix->eph / 100.0); + posInfo.setAttribute(QGeoPositionInfo::VerticalAccuracy, + device->fix->epv); + } + + if (device->fix->fields & LOCATION_GPS_DEVICE_ALTITUDE_SET) { + coordinate.setAltitude(device->fix->altitude); + } + + if (device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET) { + posInfo.setAttribute(QGeoPositionInfo::GroundSpeed, + device->fix->speed / 3.6); + } + + if (device->fix->fields & LOCATION_GPS_DEVICE_CLIMB_SET) { + posInfo.setAttribute(QGeoPositionInfo::VerticalSpeed, + device->fix->climb); + } + + if (device->fix->fields & LOCATION_GPS_DEVICE_TRACK_SET) { + posInfo.setAttribute(QGeoPositionInfo::Direction, + device->fix->track); + } + } + + if (device->satellites_in_view) { + QList satsInView; + QList satsInUse; + unsigned int i; + for (i = 0;i < device->satellites->len;i++) { + LocationGPSDeviceSatellite *satData = + (LocationGPSDeviceSatellite *)g_ptr_array_index(device->satellites, + i); + satInfo.setSignalStrength(satData->signal_strength); + satInfo.setPrnNumber(satData->prn); + satInfo.setAttribute(QGeoSatelliteInfo::Elevation, + satData->elevation); + satInfo.setAttribute(QGeoSatelliteInfo::Azimuth, + satData->azimuth); + + satsInView.append(satInfo); + if (satData->in_use) { + satellitesInUseCount++; + satsInUse.append(satInfo); + } + } + + if (!satsInView.isEmpty()) + object->satellitesInViewUpdated(satsInView); + + if (!satsInUse.isEmpty()) + object->satellitesInUseUpdated(satsInUse); + } + } + + posInfo.setCoordinate(coordinate); + + emit object->positionUpdated(posInfo); +} + +QGeoPositionInfo LiblocationWrapper::lastKnownPosition(bool fromSatellitePositioningMethodsOnly) const +{ + QGeoPositionInfo posInfo; + QGeoCoordinate coordinate; + double time; + double latitude; + double longitude; + double altitude; + double speed; + double track; + double climb; + + GConfItem lastKnownPositionTime("/system/nokia/location/lastknown/time"); + GConfItem lastKnownPositionLatitude("/system/nokia/location/lastknown/latitude"); + GConfItem lastKnownPositionLongitude("/system/nokia/location/lastknown/longitude"); + GConfItem lastKnownPositionAltitude("/system/nokia/location/lastknown/altitude"); + GConfItem lastKnownPositionSpeed("/system/nokia/location/lastknown/speed"); + GConfItem lastKnownPositionTrack("/system/nokia/location/lastknown/track"); + GConfItem lastKnownPositionClimb("/system/nokia/location/lastknown/climb"); + + if (validLastSatUpdate) + return lastSatUpdate; + + if (!fromSatellitePositioningMethodsOnly) + if (validLastUpdate) + return lastUpdate; + + time = lastKnownPositionTime.value().toDouble(); + latitude = lastKnownPositionLatitude.value().toDouble(); + longitude = lastKnownPositionLongitude.value().toDouble(); + altitude = lastKnownPositionAltitude.value().toDouble(); + speed = lastKnownPositionSpeed.value().toDouble(); + track = lastKnownPositionTrack.value().toDouble(); + climb = lastKnownPositionClimb.value().toDouble(); + + if (longitude && latitude) { + coordinate.setLongitude(longitude); + coordinate.setLatitude(latitude); + if (altitude) { + coordinate.setAltitude(altitude); + } + posInfo.setCoordinate(coordinate); + } + + if (speed) { + posInfo.setAttribute(QGeoPositionInfo::GroundSpeed, speed); + } + + if (track) { + posInfo.setAttribute(QGeoPositionInfo::Direction, track); + } + + if (climb) { + posInfo.setAttribute(QGeoPositionInfo::VerticalSpeed, climb); + } + + // Only positions with time (3D) are provided. + if (time) { + posInfo.setTimestamp(QDateTime::fromTime_t(time)); + return posInfo; + } + + return QGeoPositionInfo(); +} + +void LiblocationWrapper::satellitesInViewUpdated(const QList &satellites) +{ + satsInView = satellites; +} + +void LiblocationWrapper::satellitesInUseUpdated(const QList &satellites) +{ + satsInUse = satellites; +} + +QList LiblocationWrapper::satellitesInView() +{ + return satsInView; +} + +QList LiblocationWrapper::satellitesInUse() +{ + return satsInUse; +} + +void LiblocationWrapper::start() { + startcounter++; + + if ((locationState & LiblocationWrapper::Inited) && + !(locationState & LiblocationWrapper::Started)) { + if (!errorHandlerId) { + errorHandlerId = + g_signal_connect(G_OBJECT(locationControl), "error-verbose", + G_CALLBACK(&locationError), + static_cast(this)); + } + + if (!posChangedId) { + posChangedId = + g_signal_connect(G_OBJECT(locationDevice), "changed", + G_CALLBACK(&locationChanged), + static_cast(this)); + } + + location_gpsd_control_start(locationControl); + + locationState |= LiblocationWrapper::Started; + locationState &= ~LiblocationWrapper::Stopped; + } +} + +void LiblocationWrapper::stop() { + startcounter--; + + if (startcounter > 0) + return; + + if ((locationState & (LiblocationWrapper::Started | + LiblocationWrapper::Inited)) && + !(locationState & LiblocationWrapper::Stopped)) { + if (errorHandlerId) + g_signal_handler_disconnect(G_OBJECT(locationControl), + errorHandlerId); + if (posChangedId) + g_signal_handler_disconnect(G_OBJECT(locationDevice), + posChangedId); + errorHandlerId = 0; + posChangedId = 0; + startcounter = 0; + location_gpsd_control_stop(locationControl); + + locationState &= ~LiblocationWrapper::Started; + locationState |= LiblocationWrapper::Stopped; + } +} + +bool LiblocationWrapper::isActive() { + if (locationState & LiblocationWrapper::Started) + return true; + else + return false; +} + +#include "moc_liblocationwrapper_p.cpp" +QTM_END_NAMESPACE + diff --git a/liblocationmaemo5/liblocationwrapper_p.h b/liblocationmaemo5/liblocationwrapper_p.h new file mode 100644 index 0000000..287ff5d --- /dev/null +++ b/liblocationmaemo5/liblocationwrapper_p.h @@ -0,0 +1,121 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef LIBLOCATIONWRAPPER_H +#define LIBLOCATINWRAPPER_H + +// INCLUDES +#include +#include + +#include "qgeocoordinate.h" +#include "qgeopositioninfo.h" +#include "qgeosatelliteinfo.h" + +#include "gconfitem_p.h" + +extern "C" { + #include + #include + #include + #include + #include +} + +QTM_BEGIN_NAMESPACE + +class LiblocationWrapper : public QObject +{ + Q_OBJECT + +public: + static LiblocationWrapper *instance(); + LiblocationWrapper(); + ~LiblocationWrapper(); + + void start(); + void stop(); + QGeoPositionInfo lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const; + bool inited(); + bool isActive(); + QList satellitesInView(); + QList satellitesInUse(); + +private: + QFile *file; + LocationGPSDControl *locationControl; + LocationGPSDevice *locationDevice; + + static void locationError(LocationGPSDevice *device, gint code, gpointer data); + static void locationChanged(LocationGPSDevice *device, gpointer data); + + int errorHandlerId; + int posChangedId; + int origUpdateInterval; + int startcounter; + QGeoPositionInfo lastUpdate; + QGeoPositionInfo lastSatUpdate; + bool validLastUpdate; + bool validLastSatUpdate; + bool fromSatellite; + + void satellitesInViewUpdated(const QList &satellites); + void satellitesInUseUpdated(const QList &satellites); + QList satsInView; + QList satsInUse; + + enum LocationState { + Undefined = 0, + Inited = 1, + Started = 2, + Stopped = 4, + RequestActive = 8, + RequestSingleShot = 16 + }; + int locationState; + +signals: + void positionUpdated(const QGeoPositionInfo &position); + void error(); +}; + +QTM_END_NAMESPACE +#endif // LIBLOCATIONWRAPPER_H diff --git a/liblocationmaemo5/qgeopositioninfosource_maemo5.cpp b/liblocationmaemo5/qgeopositioninfosource_maemo5.cpp new file mode 100644 index 0000000..60023d6 --- /dev/null +++ b/liblocationmaemo5/qgeopositioninfosource_maemo5.cpp @@ -0,0 +1,370 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeopositioninfosource_maemo5_p.h" +#include "liblocationwrapper_p.h" +#include + +using namespace std; + +QTM_BEGIN_NAMESPACE + +QGeoPositionInfoSourceMaemo::QGeoPositionInfoSourceMaemo(QObject *parent) + : QGeoPositionInfoSource(parent) +{ + qDebug() << "* QGeoPositionInfoSourceMaemo Fremantle Backport"; + // default values + timerInterval = DEFAULT_UPDATE_INTERVAL; + updateTimer = new QTimer(this); + updateTimer->setSingleShot(true); + connect(updateTimer, SIGNAL(timeout()), this, SLOT(updateTimeoutElapsed())); + + requestTimer = new QTimer(this); + requestTimer->setSingleShot(true); + connect(requestTimer, SIGNAL(timeout()), this, SLOT(requestTimeoutElapsed())); + + connect(LiblocationWrapper::instance(), SIGNAL(positionUpdated(QGeoPositionInfo)), this, SLOT(newPositionUpdate(QGeoPositionInfo))); + + errorOccurred = false; + errorSent = false; + + positionInfoState = QGeoPositionInfoSourceMaemo::Undefined; +} + +int QGeoPositionInfoSourceMaemo::init() +{ + if (LiblocationWrapper::instance()->inited()) { + connect(LiblocationWrapper::instance(), SIGNAL(error()), this, SLOT(error())); + return INIT_OK; + } else { + return INIT_FAILED; + } +} + +QGeoPositionInfo QGeoPositionInfoSourceMaemo::lastKnownPosition(bool fromSatellitePositioningMethodsOnly) const +{ + return (LiblocationWrapper::instance()->lastKnownPosition(fromSatellitePositioningMethodsOnly)); +} + +QGeoPositionInfoSource::PositioningMethods QGeoPositionInfoSourceMaemo::supportedPositioningMethods() const +{ + QGeoPositionInfoSource::PositioningMethods methods; + + if (!GConfItem("/system/nokia/location/gps-disabled").value().toBool()) + methods |= SatellitePositioningMethods; + if (!GConfItem("/system/nokia/location/network-disabled").value().toBool()) + methods |= NonSatellitePositioningMethods; + if (methods.testFlag(SatellitePositioningMethods) && methods.testFlag(NonSatellitePositioningMethods)) + methods |= AllPositioningMethods; + + return methods; +} + +void QGeoPositionInfoSourceMaemo::setUpdateInterval(int msec) +{ + bool updateTimerInterval = false; + + if (positionInfoState & QGeoPositionInfoSourceMaemo::PowersaveActive) + if (positionInfoState & QGeoPositionInfoSourceMaemo::Stopped) + updateTimerInterval = true; + + if (!msec) { + timerInterval = MINIMUM_UPDATE_INTERVAL; + QGeoPositionInfoSource::setUpdateInterval(0); + } else { + timerInterval = (msec < MINIMUM_UPDATE_INTERVAL) ? MINIMUM_UPDATE_INTERVAL : msec; + QGeoPositionInfoSource::setUpdateInterval(timerInterval); + } + + if (timerInterval >= POWERSAVE_THRESHOLD) + positionInfoState |= QGeoPositionInfoSourceMaemo::PowersaveActive; + else + positionInfoState &= ~QGeoPositionInfoSourceMaemo::PowersaveActive; + + // If powersave has been active when new update interval has been set, + // ensure that timer is started. + if (updateTimerInterval) + startLocationDaemon(); + + // Ensure that new timer interval is taken into use immediately. + activateTimer(); +} + +void QGeoPositionInfoSourceMaemo::setPreferredPositioningMethods(PositioningMethods methods) +{ + QGeoPositionInfoSource::setPreferredPositioningMethods(methods); +} + +int QGeoPositionInfoSourceMaemo::minimumUpdateInterval() const +{ + return MINIMUM_UPDATE_INTERVAL; +} + +// public slots: +void QGeoPositionInfoSourceMaemo::startUpdates() +{ + startLocationDaemon(); + + // Ensure that powersave is selected, if stopUpdates() has been called, + // but selected update interval is still greater than POWERSAVE_THRESHOLD. + if (timerInterval >= POWERSAVE_THRESHOLD) + positionInfoState |= QGeoPositionInfoSourceMaemo::PowersaveActive; + + activateTimer(); +} + +void QGeoPositionInfoSourceMaemo::stopUpdates() +{ + positionInfoState &= ~QGeoPositionInfoSourceMaemo::PowersaveActive; + + if (!(positionInfoState & QGeoPositionInfoSourceMaemo::RequestActive)) { + updateTimer->stop(); + if (LiblocationWrapper::instance()->isActive()) + LiblocationWrapper::instance()->stop(); + } + + errorOccurred = false; + errorSent = false; + + positionInfoState &= ~QGeoPositionInfoSourceMaemo::Started; + positionInfoState |= QGeoPositionInfoSourceMaemo::Stopped; +} + +void QGeoPositionInfoSourceMaemo::requestUpdate(int timeout) +{ + int timeoutForRequest = 0; + + if (!timeout) { + if (LiblocationWrapper::instance()->isActive()) + // If GPS is active, assume quick fix. + timeoutForRequest = DEFAULT_UPDATE_INTERVAL; + else + // Otherwise reserve longer time to get a fix. + timeoutForRequest = POWERSAVE_POWERON_PERIOD; + } else if (timeout < MINIMUM_UPDATE_INTERVAL) { + if (positionInfoState & QGeoPositionInfoSourceMaemo::RequestActive) + return; + + emit updateTimeout(); + return; + } else { + timeoutForRequest = timeout; + } + + positionInfoState |= QGeoPositionInfoSourceMaemo::RequestActive; + + if (!(LiblocationWrapper::instance()->isActive())) + LiblocationWrapper::instance()->start(); + + activateTimer(); + requestTimer->start(timeoutForRequest); +} + +void QGeoPositionInfoSourceMaemo::newPositionUpdate(const QGeoPositionInfo &position) +{ + /* + Invalid fixes have NaN for horizontal accuracy regardless of + whether they come from satellite or non-satellite position methods. + + Satellite fixes always have LOCATION_GPS_DEVICE_TIME_SET. + If this is not set and we have a numeric value for horizontal + accuracy then we are dealing with a non-satellite based positioning + method. + + Since QGeoPositionInfo instances are only considered valid if + they have a valid coordinate and a valid timestamp, we use + the current date and time as the timestamp for the network based + positioning. This will help in the case where someone wants to + reply a journey from a log file. + + Based on some logging it looks like satellite and non-satellite + methods can be distinguished (after the initial fix) by whether + the time has been set and / or whether the horizontal accuracy + is above or below around 500 metres. Using the timestamp + appears to be more definitive than using the accuracy. + */ + + const bool horizontalAccuracyDefined = !qIsNaN(position.attribute(QGeoPositionInfo::HorizontalAccuracy)); + const bool hasTimeStamp = !position.timestamp().isNull(); + + if (horizontalAccuracyDefined) { + if (hasTimeStamp) { + //Valid satellite fix + lastUpdateFromSatellite = position; + } else { + //Valid non-satellite fix + QGeoPositionInfo networkPosition(position); + networkPosition.setTimestamp(QDateTime::currentDateTime()); + lastUpdateFromNetwork = networkPosition; + } + } else { + //Invalid position update + if (hasTimeStamp) { + lastUpdateFromSatellite = QGeoPositionInfo(); + } else { + lastUpdateFromNetwork = QGeoPositionInfo(); + } + } +} + +void QGeoPositionInfoSourceMaemo::updateTimeoutElapsed() +{ + QGeoPositionInfo position; + + QGeoPositionInfoSource::PositioningMethods methods = preferredPositioningMethods(); + + if (methods.testFlag(AllPositioningMethods)) { + methods |= SatellitePositioningMethods; + methods |= NonSatellitePositioningMethods; + } + + if (methods.testFlag(SatellitePositioningMethods) && !methods.testFlag(NonSatellitePositioningMethods)) { + //only SatellitePositioningMethods preferred + position = lastUpdateFromSatellite; + } else if (methods.testFlag(NonSatellitePositioningMethods) && !methods.testFlag(SatellitePositioningMethods)) { + //only NonSatellitePositioningMethods preferred + position = lastUpdateFromNetwork; + } else { + //AllPositioningMethods or none preferred + if (lastUpdateFromSatellite.isValid()) + position = lastUpdateFromSatellite; + else + position = lastUpdateFromNetwork; + } + + if (position.isValid()) { + errorOccurred = false; + errorSent = false; + + if (positionInfoState & QGeoPositionInfoSourceMaemo::RequestActive) { + positionInfoState &= ~QGeoPositionInfoSourceMaemo::RequestActive; + requestTimer->stop(); + + if (positionInfoState & QGeoPositionInfoSourceMaemo::Stopped) + if (LiblocationWrapper::instance()->isActive()) + LiblocationWrapper::instance()->stop(); + + // Ensure that requested position fix is emitted even though + // powersave is active and GPS would normally be off. + if ((positionInfoState & QGeoPositionInfoSourceMaemo::PowersaveActive) && + (positionInfoState & QGeoPositionInfoSourceMaemo::Stopped)) { + emit positionUpdated(position); + } + } + + // Make sure that if update is triggered when waking up, there + // is no false position update. + if (!((positionInfoState & QGeoPositionInfoSourceMaemo::PowersaveActive) && + (positionInfoState & QGeoPositionInfoSourceMaemo::Stopped))) + emit positionUpdated(position); + } else { + // if an error occurs when we are updating periodically and we haven't + // sent an error since the last fix... + if (!(positionInfoState & QGeoPositionInfoSourceMaemo::RequestActive) && + errorOccurred && !errorSent) { + errorSent = true; + // we need to emit the updateTimeout signal + emit updateTimeout(); + } + } + activateTimer(); +} + +void QGeoPositionInfoSourceMaemo::requestTimeoutElapsed() +{ + updateTimer->stop(); + emit updateTimeout(); + + positionInfoState &= ~QGeoPositionInfoSourceMaemo::RequestActive; + + if (positionInfoState & QGeoPositionInfoSourceMaemo::Stopped) + if (LiblocationWrapper::instance()->isActive()) + LiblocationWrapper::instance()->stop(); + + activateTimer(); +} + +void QGeoPositionInfoSourceMaemo::error() +{ + errorOccurred = true; +} + +void QGeoPositionInfoSourceMaemo::activateTimer() +{ + if (positionInfoState & QGeoPositionInfoSourceMaemo::RequestActive) { + updateTimer->start(MINIMUM_UPDATE_INTERVAL); + return; + } + + if (positionInfoState & QGeoPositionInfoSourceMaemo::PowersaveActive) { + if (positionInfoState & QGeoPositionInfoSourceMaemo::Started) { + // Cannot call stopUpdates() here since we want to keep powersave + // active. + if (LiblocationWrapper::instance()->isActive()) + LiblocationWrapper::instance()->stop(); + updateTimer->start(timerInterval - POWERSAVE_POWERON_PERIOD); + errorOccurred = false; + errorSent = false; + + positionInfoState &= ~QGeoPositionInfoSourceMaemo::Started; + positionInfoState |= QGeoPositionInfoSourceMaemo::Stopped; + } else if (positionInfoState & QGeoPositionInfoSourceMaemo::Stopped) { + startLocationDaemon(); + updateTimer->start(POWERSAVE_POWERON_PERIOD); + } + return; + } + + if (positionInfoState & QGeoPositionInfoSourceMaemo::Started) + updateTimer->start(timerInterval); +} + +void QGeoPositionInfoSourceMaemo::startLocationDaemon() +{ + if (!(LiblocationWrapper::instance()->isActive())) + LiblocationWrapper::instance()->start(); + positionInfoState |= QGeoPositionInfoSourceMaemo::Started; + positionInfoState &= ~QGeoPositionInfoSourceMaemo::Stopped; +} + +#include "moc_qgeopositioninfosource_maemo5_p.cpp" +QTM_END_NAMESPACE + diff --git a/liblocationmaemo5/qgeopositioninfosource_maemo5_p.h b/liblocationmaemo5/qgeopositioninfosource_maemo5_p.h new file mode 100644 index 0000000..c7c022b --- /dev/null +++ b/liblocationmaemo5/qgeopositioninfosource_maemo5_p.h @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOPOSITIONINFOSOURCEMAEMO5_H +#define QGEOPOSITIONINFOSOURCEMAEMO5_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include "qgeopositioninfosource.h" + +#define INIT_OK 0 +#define INIT_FAILED -1 +#define MINIMUM_UPDATE_INTERVAL 1000 +#define DEFAULT_UPDATE_INTERVAL 5000 +#define POWERSAVE_THRESHOLD 180000 +#define POWERSAVE_POWERON_PERIOD 120000 + +QTM_BEGIN_NAMESPACE + +class LiblocationWrapper; + +class QGeoPositionInfoSourceMaemo : public QGeoPositionInfoSource +{ + Q_OBJECT + +public: + + QGeoPositionInfoSourceMaemo(QObject *parent = 0); + + int init(); + + virtual void setUpdateInterval(int interval); + virtual void setPreferredPositioningMethods(PositioningMethods methods); + virtual QGeoPositionInfo lastKnownPosition(bool fromSatellitePositioningMethodsOnly = false) const; + virtual PositioningMethods supportedPositioningMethods() const; + virtual int minimumUpdateInterval() const; + +private: + bool positionInited; + QTimer *updateTimer; + QTimer *requestTimer; + int timerInterval; + bool errorOccurred; + bool errorSent; + + void activateTimer(); + void startLocationDaemon(); + + enum PositionInfoState { + Undefined = 0, + Started = 1, + Stopped = 2, + RequestActive = 4, + PowersaveActive = 8 + }; + int positionInfoState; + + QGeoPositionInfo lastUpdateFromSatellite; + QGeoPositionInfo lastUpdateFromNetwork; + +signals: + void positionUpdated(const QGeoPositionInfo &update); + +public slots: + void startUpdates(); + void stopUpdates(); + void requestUpdate(int timeout = DEFAULT_UPDATE_INTERVAL); + +private slots: + void requestTimeoutElapsed(); + void error(); + void newPositionUpdate(const QGeoPositionInfo &position); + void updateTimeoutElapsed(); + +private: + Q_DISABLE_COPY(QGeoPositionInfoSourceMaemo) +}; + +QTM_END_NAMESPACE + +#endif // QGEOPOSITIONINFOSOURCEMAEMO5_H diff --git a/liblocationmaemo5/qgeosatelliteinfosource_maemo5.cpp b/liblocationmaemo5/qgeosatelliteinfosource_maemo5.cpp new file mode 100644 index 0000000..0074d28 --- /dev/null +++ b/liblocationmaemo5/qgeosatelliteinfosource_maemo5.cpp @@ -0,0 +1,246 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qgeosatelliteinfosource_maemo5_p.h" +#include "liblocationwrapper_p.h" + +QTM_BEGIN_NAMESPACE + +QGeoSatelliteInfoSourceMaemo::QGeoSatelliteInfoSourceMaemo(QObject *parent) + : QGeoSatelliteInfoSource(parent) +{ + qDebug() << "* QGeoSatelliteInfoSourceMaemo Fremantle Backport"; + client_id_ = -1; + timerInterval = DEFAULT_UPDATE_INTERVAL; + updateTimer = new QTimer(this); + updateTimer->setSingleShot(true); + connect(updateTimer, SIGNAL(timeout()), this, SLOT(satelliteStatus())); + + requestTimer = new QTimer(this); + requestTimer->setSingleShot(true); + connect(requestTimer, SIGNAL(timeout()), this, SLOT(requestTimeoutElapsed())); + + satelliteInfoState = QGeoSatelliteInfoSourceMaemo::Undefined; +} + +int QGeoSatelliteInfoSourceMaemo::init() +{ + if (LiblocationWrapper::instance()->inited()) + return INIT_OK; + else + return INIT_FAILED; +} + +void QGeoSatelliteInfoSourceMaemo::setUpdateInterval(int msec) +{ + bool updateTimerInterval = false; + + if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::PowersaveActive) + if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Stopped) + updateTimerInterval = true; + + timerInterval = (msec < MINIMUM_UPDATE_INTERVAL) ? MINIMUM_UPDATE_INTERVAL : msec; + + if (timerInterval >= POWERSAVE_THRESHOLD) + satelliteInfoState |= QGeoSatelliteInfoSourceMaemo::PowersaveActive; + else + satelliteInfoState &= ~QGeoSatelliteInfoSourceMaemo::PowersaveActive; + + // If powersave has been active when new update interval has been set, + // ensure that timer is started. + if (updateTimerInterval) + startLocationDaemon(); + + // Ensure that new timer interval is taken into use immediately. + activateTimer(); +} + +void QGeoSatelliteInfoSourceMaemo::startUpdates() +{ + startLocationDaemon(); + + // Ensure that powersave is selected, if stopUpdates() has been called, + // but selected update interval is still greater than POWERSAVE_THRESHOLD. + if (timerInterval >= POWERSAVE_THRESHOLD) + satelliteInfoState |= QGeoSatelliteInfoSourceMaemo::PowersaveActive; + + activateTimer(); +} + +void QGeoSatelliteInfoSourceMaemo::stopUpdates() +{ + satelliteInfoState &= ~QGeoSatelliteInfoSourceMaemo::PowersaveActive; + + if (!(satelliteInfoState & QGeoSatelliteInfoSourceMaemo::RequestActive)) { + updateTimer->stop(); + if (LiblocationWrapper::instance()->isActive()) + LiblocationWrapper::instance()->stop(); + } + + satelliteInfoState &= ~QGeoSatelliteInfoSourceMaemo::Started; + satelliteInfoState |= QGeoSatelliteInfoSourceMaemo::Stopped; +} + +void QGeoSatelliteInfoSourceMaemo::requestUpdate(int timeout) +{ + int timeoutForRequest = 0; + + if (!timeout) { + if (LiblocationWrapper::instance()->isActive()) + // If GPS is active, assume quick fix. + timeoutForRequest = DEFAULT_UPDATE_INTERVAL; + else + // Otherwise reserve longer time to get a fix. + timeoutForRequest = POWERSAVE_POWERON_PERIOD; + } else if (timeout < MINIMUM_UPDATE_INTERVAL) { + if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::RequestActive) + return; + + emit requestTimeout(); + return; + } else { + timeoutForRequest = timeout; + } + + satelliteInfoState |= QGeoSatelliteInfoSourceMaemo::RequestActive; + + if (!(LiblocationWrapper::instance()->isActive())) + LiblocationWrapper::instance()->start(); + + activateTimer(); + requestTimer->start(timeoutForRequest); +} + +void QGeoSatelliteInfoSourceMaemo::satelliteStatus() +{ + QList satellitesInView = + LiblocationWrapper::instance()->satellitesInView(); + QList satellitesInUse = + LiblocationWrapper::instance()->satellitesInUse(); + + if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::RequestActive) { + satelliteInfoState &= ~QGeoSatelliteInfoSourceMaemo::RequestActive; + + requestTimer->stop(); + + if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Stopped) { + if (LiblocationWrapper::instance()->isActive()) { + LiblocationWrapper::instance()->stop(); + } + } + + // Ensure that requested satellite info is emitted even though + // powersave is active and GPS would normally be off. + if ((satelliteInfoState & QGeoSatelliteInfoSourceMaemo::PowersaveActive) && + (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Stopped)) { + if (satellitesInView.length()) { + emit satellitesInViewUpdated(satellitesInView); + emit satellitesInUseUpdated(satellitesInUse); + } + } + } + + // Make sure that if update is triggered when waking up, there + // is no false position update. + if (!((satelliteInfoState & QGeoSatelliteInfoSourceMaemo::PowersaveActive) && + (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Stopped))) { + if (satellitesInView.length()) { + emit satellitesInViewUpdated(satellitesInView); + emit satellitesInUseUpdated(satellitesInUse); + } + } + + activateTimer(); +} + +void QGeoSatelliteInfoSourceMaemo::requestTimeoutElapsed() +{ + updateTimer->stop(); + emit requestTimeout(); + + satelliteInfoState &= ~QGeoSatelliteInfoSourceMaemo::RequestActive; + + if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Stopped) + if (LiblocationWrapper::instance()->isActive()) + LiblocationWrapper::instance()->stop(); + + activateTimer(); +} + +void QGeoSatelliteInfoSourceMaemo::activateTimer() +{ + if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::RequestActive) { + updateTimer->start(MINIMUM_UPDATE_INTERVAL); + return; + } + + if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::PowersaveActive) { + if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Started) { + // Cannot call stopUpdates() here since we want to keep powersave + // active. + if (LiblocationWrapper::instance()->isActive()) + LiblocationWrapper::instance()->stop(); + updateTimer->start(timerInterval - POWERSAVE_POWERON_PERIOD); + + satelliteInfoState &= ~QGeoSatelliteInfoSourceMaemo::Started; + satelliteInfoState |= QGeoSatelliteInfoSourceMaemo::Stopped; + } else if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Stopped) { + startLocationDaemon(); + updateTimer->start(POWERSAVE_POWERON_PERIOD); + } + return; + } + + if (satelliteInfoState & QGeoSatelliteInfoSourceMaemo::Started) + updateTimer->start(timerInterval); +} + +void QGeoSatelliteInfoSourceMaemo::startLocationDaemon() +{ + if (!(LiblocationWrapper::instance()->isActive())) + LiblocationWrapper::instance()->start(); + satelliteInfoState |= QGeoSatelliteInfoSourceMaemo::Started; + satelliteInfoState &= ~QGeoSatelliteInfoSourceMaemo::Stopped; +} + +#include "moc_qgeosatelliteinfosource_maemo5_p.cpp" +QTM_END_NAMESPACE + diff --git a/liblocationmaemo5/qgeosatelliteinfosource_maemo5_p.h b/liblocationmaemo5/qgeosatelliteinfosource_maemo5_p.h new file mode 100644 index 0000000..71c4c91 --- /dev/null +++ b/liblocationmaemo5/qgeosatelliteinfosource_maemo5_p.h @@ -0,0 +1,119 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** This file may be used under the terms of the GNU Lesser General Public +** License version 2.1 as published by the Free Software Foundation and +** appearing in the file LICENSE.LGPL included in the packaging of this +** file. Please review the following information to ensure the GNU Lesser +** General Public License version 2.1 requirements will be met: +** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU General +** Public License version 3.0 as published by the Free Software Foundation +** and appearing in the file LICENSE.GPL included in the packaging of this +** file. Please review the following information to ensure the GNU General +** Public License version 3.0 requirements will be met: +** http://www.gnu.org/copyleft/gpl.html. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QGEOSATELLITEINFOSOURCE_MAEMO5_H +#define QGEOSATELLITEINFOSOURCE_MAEMO5_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include +#include "qgeosatelliteinfosource.h" +#include "qgeosatelliteinfo.h" + +#define INIT_OK 0 +#define INIT_FAILED -1 +#define MINIMUM_UPDATE_INTERVAL 1000 +#define DEFAULT_UPDATE_INTERVAL 5000 +#define POWERSAVE_THRESHOLD 180000 +#define POWERSAVE_POWERON_PERIOD 120000 + +QTM_BEGIN_NAMESPACE + +class LiblocationWrapper; + +class QGeoSatelliteInfoSourceMaemo : public QGeoSatelliteInfoSource +{ + Q_OBJECT + +public: + explicit QGeoSatelliteInfoSourceMaemo(QObject *parent = 0); + + int init(); + +private: + int client_id_; + void setUpdateInterval(int interval); + QTimer *updateTimer; + QTimer *requestTimer; + int timerInterval; + void activateTimer(); + void startLocationDaemon(); + + enum SatelliteInfoState { + Undefined = 0, + Started = 1, + Stopped = 2, + RequestActive = 4, + PowersaveActive = 8 + }; + int satelliteInfoState; + +public slots: + virtual void startUpdates(); + void stopUpdates(); + void requestUpdate(int timeout = 5000); + void satelliteStatus(); + +signals: + void satellitesInViewUpdated(const QList &satellites); + void satellitesInUseUpdated(const QList &satellites); + void requestTimeout(); + +private slots: + void requestTimeoutElapsed(); + +private: + Q_DISABLE_COPY(QGeoSatelliteInfoSourceMaemo) +}; + +QTM_END_NAMESPACE + +#endif // QGEOSATELLITEINFOSOURCE_MAEMO5_H + diff --git a/not_used/glupdater b/not_used/glupdater deleted file mode 100644 index 62c9362..0000000 --- a/not_used/glupdater +++ /dev/null @@ -1,13 +0,0 @@ -author "Danilo Luvizotto " -description "Google Latitude Updater Daemon" - -start on started hildon-desktop - -console output - -post-stop script - killall -9 GoogleLatitudeDaemon -end script - -exec /bin/su - user -c "/opt/linfati.com/GoogleLatitudeDaemon --init" - diff --git a/not_used/gpsmaemo5.cpp b/not_used/gpsmaemo5.cpp deleted file mode 100644 index e5c8869..0000000 --- a/not_used/gpsmaemo5.cpp +++ /dev/null @@ -1,110 +0,0 @@ -#include "gps.h" - -GpsMaemo5::GpsMaemo5(QObject *parent) : - QObject(parent), - latitude(0), longitude(0), accuracy(0), - interval(1800), wait(30), method("cell"), - emitfix(false), stopgps(true) { -#ifdef Q_WS_MAEMO_5 - control = location_gpsd_control_get_default(); - device = (LocationGPSDevice*) g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL); - g_signal_connect(device, "changed", G_CALLBACK(GpsMaemo5_changed), this); -#else - urlloc = QUrl::fromEncoded("http://www.google.com/loc/json"); - worker = new QNetworkAccessManager(); - connect(worker, SIGNAL(finished(QNetworkReply *)), this, SLOT(gloc_reply(QNetworkReply *))); -#endif // Q_WS_MAEMO_5 -} - -void GpsMaemo5::refresh() { - if ( stopgps ) return; - qDebug() << "GpsMaemo5: refresh"; - - QTimer::singleShot(interval*1000, this, SLOT(refresh())); - QTimer::singleShot(wait*1000, this, SLOT(stop())); - -#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) - QNetworkConfigurationManager mgr; - if (!mgr.isOnline()) { - qDebug() << "GpsMaemo5: offline"; - return; - } -#endif - -#ifdef Q_WS_MAEMO_5 - if ( method == QString("cell") ) { - g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_ACWP, NULL); - } else if ( method == QString("both") ) { - g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_USER_SELECTED, NULL); - } else if ( method == QString("agps") ) { - g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_AGNSS, NULL); - } else { - g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_ACWP, NULL); - } - location_gpsd_control_start(control); -#else - worker->post(QNetworkRequest(urlloc), QByteArray("{version:\"1.1.0\"}")); -#endif // Q_WS_MAEMO_5 -} - -void GpsMaemo5::stop() { - qDebug() << "GpsMaemo5: stop"; -#ifdef Q_WS_MAEMO_5 - location_gpsd_control_stop(control); -#else -#endif // Q_WS_MAEMO_5 - if (emitfix) { - emitfix = false; - emit fix(); - } -} - -void GpsMaemo5::forcestop() { - qDebug() << "GpsMaemo5: forcestop"; - stopgps = true; - emitfix = false; - stop(); -} - -int GpsMaemo5::config(int i, int w, QString m) { - qDebug() << "GpsMaemo5: config"; - stopgps = false; - interval = i; - wait = w; - method = m; - return 0; -} - -#ifdef Q_WS_MAEMO_5 -void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps) { - if (device->fix) { - if (device->fix->fields) { - if ( isnan(gps->device->fix->eph) ) return; - g_print("GpsMaemo5 lat %f lon %f eph %f\n", gps->device->fix->latitude, gps->device->fix->longitude, gps->device->fix->eph/100.); - gps->latitude = gps->device->fix->latitude; - gps->longitude = gps->device->fix->longitude; - gps->accuracy = gps->device->fix->eph/100.; - gps->emitfix = true; - } - } -} -#else -void GpsMaemo5::gloc_reply(QNetworkReply *r) { - if ( r->url() == urlloc ) { - QString loc = r->readAll(); - QRegExp regexp ("\\{\"latitude\":(.*),\"longitude\":(.*),\"accuracy\":(.*)\\}"); - regexp.setMinimal(1); - regexp.indexIn(loc, 1); - latitude = regexp.capturedTexts().at(1).toDouble(); - longitude = regexp.capturedTexts().at(2).toDouble(); - accuracy = regexp.capturedTexts().at(3).toDouble(); - if ( accuracy > 100000 ) accuracy = 100000; - qDebug() << "GpsIP lat" << latitude << "lon" << longitude << "acc" << accuracy; - emitfix = true; - } else { - qDebug() << "GpsIP Error url" << r->url(); - qDebug() << r->rawHeaderList(); - qDebug() << r->readAll(); - } -} -#endif // Q_WS_MAEMO_5 diff --git a/not_used/gpsmaemo5.h b/not_used/gpsmaemo5.h deleted file mode 100644 index c0ba709..0000000 --- a/not_used/gpsmaemo5.h +++ /dev/null @@ -1,63 +0,0 @@ -#ifndef GPS_H -#define GPS_H - -#include -#include - -#ifdef Q_WS_MAEMO_5 -extern "C" { -#include -#include -} -#else -#include -#endif // Q_WS_MAEMO_5 - -class GpsMaemo5 : public QObject { - Q_OBJECT - -signals: - void fix(); - -public: - GpsMaemo5(QObject *parent = 0); - double get_lat() { return latitude; } - double get_lon() { return longitude; } - double get_acc() { return accuracy; } - -public slots: - void refresh(); - void stop(); - void forcestop(); - int config(int i, int w, QString m); - -private slots: -#ifdef Q_WS_MAEMO_5 - friend void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps); -#else - void gloc_reply(QNetworkReply *r); -#endif // Q_WS_MAEMO_5 - -private: - double latitude; - double longitude; - double accuracy; - int interval; - int wait; - QString method; - bool emitfix; - bool stopgps; -#ifdef Q_WS_MAEMO_5 - LocationGPSDControl *control; - LocationGPSDevice *device; -#else - QUrl urlloc; - QNetworkAccessManager *worker; -#endif // Q_WS_MAEMO_5 -}; - -#ifdef Q_WS_MAEMO_5 -void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps); -#endif // Q_WS_MAEMO_5 - -#endif // GPS_H -- 1.7.9.5