Version 0.6-2, use of cell+gps, fix "start daemon"
[googlelatitude] / src / gps.cpp
index cd87f24..e5c8869 100644 (file)
@@ -3,7 +3,7 @@
 GpsMaemo5::GpsMaemo5(QObject *parent) :
         QObject(parent),
         latitude(0), longitude(0), accuracy(0),
-        interval(1800), wait(30), usegps(false),
+        interval(1800), wait(30), method("cell"),
         emitfix(false), stopgps(true) {
 #ifdef Q_WS_MAEMO_5
     control = location_gpsd_control_get_default();
@@ -23,10 +23,23 @@ void 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
-    g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_ACWP, NULL);
-    if (usegps) {
+    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
@@ -49,14 +62,16 @@ void GpsMaemo5::stop() {
 void GpsMaemo5::forcestop() {
     qDebug() << "GpsMaemo5: forcestop";
     stopgps = true;
+    emitfix = false;
+    stop();
 }
 
-int GpsMaemo5::config(int i, int w, bool g) {
+int GpsMaemo5::config(int i, int w, QString m) {
     qDebug() << "GpsMaemo5: config";
     stopgps = false;
     interval = i;
     wait = w;
-    usegps = g;
+    method = m;
     return 0;
 }
 
@@ -64,6 +79,7 @@ int GpsMaemo5::config(int i, int w, bool g) {
 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;