Backport of QGeo*InfoSourceMaemo5 and others fixes
[googlelatitude] / gpscontrol.cpp
index 8df1cc1..2b900c9 100644 (file)
@@ -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();
         }
     }