Merge branch 'master' into error_procedur
[situare] / src / engine / engine.cpp
index 7929783..5f5c23a 100644 (file)
@@ -155,21 +155,29 @@ void SituareEngine::enableGPS(bool enabled)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_ui->setGPSButtonEnabled(enabled);
-    m_mapEngine->setGPSEnabled(enabled);
+    if (m_gps->isInitialized()) {
+        m_ui->setGPSButtonEnabled(enabled);
+        m_mapEngine->setGPSEnabled(enabled);
 
-    if (enabled && !m_gps->isRunning()) {
-        m_gps->start();
-        enableAutoCentering(m_autoCenteringEnabled);
-        m_gps->requestLastPosition();
+        if (enabled && !m_gps->isRunning()) {
+            m_gps->start();
+            enableAutoCentering(m_autoCenteringEnabled);
+            m_gps->requestLastPosition();
 
-        if (!m_automaticUpdateEnabled && m_loggedIn)
-            m_ui->requestAutomaticLocationUpdateSettings();
+            if (!m_automaticUpdateEnabled && m_loggedIn)
+                m_ui->requestAutomaticLocationUpdateSettings();
+        }
+        else if (!enabled && m_gps->isRunning()) {
+            m_gps->stop();
+            enableAutoCentering(false);
+            enableAutomaticLocationUpdate(false);
+        }
     }
-    else if (!enabled && m_gps->isRunning()) {
-        m_gps->stop();
-        enableAutoCentering(false);
-        enableAutomaticLocationUpdate(false);
+    else {
+        if (enabled)
+            m_ui->buildInformationBox(tr("Unable to start GPS"));
+        m_ui->setGPSButtonEnabled(false);
+        m_mapEngine->setGPSEnabled(false);
     }
 }
 
@@ -266,28 +274,33 @@ void SituareEngine::initializeGpsAndAutocentering()
 
     QSettings settings(DIRECTORY_NAME, FILE_NAME);
     QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
-    QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);     
-
-    if (gpsEnabled.toString().isEmpty()) { // First start. Situare.conf file does not exists
+    QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
 
-        connect(m_gps, SIGNAL(position(QPointF,qreal)),
-                this, SLOT(setFirstStartZoomLevel(QPointF,qreal)));
+    if (m_gps->isInitialized()) {
 
-        changeAutoCenteringSetting(true);
-        enableGPS(true);
+        if (gpsEnabled.toString().isEmpty()) { // First start. Situare.conf file does not exists
 
-        m_ui->buildInformationBox(tr("GPS enabled"));
-        m_ui->buildInformationBox(tr("Auto centering enabled"));
+            connect(m_gps, SIGNAL(position(QPointF,qreal)),
+                    this, SLOT(setFirstStartZoomLevel(QPointF,qreal)));
 
-    } else { // Normal start
-        changeAutoCenteringSetting(autoCenteringEnabled.toBool());
-        enableGPS(gpsEnabled.toBool());
+            changeAutoCenteringSetting(true);
+            enableGPS(true);
 
-        if (gpsEnabled.toBool())
             m_ui->buildInformationBox(tr("GPS enabled"));
-
-        if (gpsEnabled.toBool() && autoCenteringEnabled.toBool())
             m_ui->buildInformationBox(tr("Auto centering enabled"));
+
+        } else { // Normal start
+            changeAutoCenteringSetting(autoCenteringEnabled.toBool());
+            enableGPS(gpsEnabled.toBool());
+
+            if (gpsEnabled.toBool())
+                m_ui->buildInformationBox(tr("GPS enabled"));
+
+            if (gpsEnabled.toBool() && autoCenteringEnabled.toBool())
+                m_ui->buildInformationBox(tr("Auto centering enabled"));
+        }
+    } else {
+        enableGPS(false);
     }
 }