Added GPSPosition::isInitialized method.
authorJussi Laitinen <jupe@l3l7588.ixonos.local>
Thu, 10 Jun 2010 12:01:01 +0000 (15:01 +0300)
committerJussi Laitinen <jupe@l3l7588.ixonos.local>
Thu, 10 Jun 2010 12:01:01 +0000 (15:01 +0300)
Reviewed by: Henri Lampela.

src/engine/engine.cpp
src/gps/gpsposition.cpp
src/gps/gpsposition.h
src/gps/gpspositionprivate.cpp
src/gps/gpspositionprivate.h
src/gps/gpspositionprivateliblocation.cpp
src/gps/gpspositionprivateliblocation.h
src/gps/gpspositionprivatestub.cpp
src/gps/gpspositionprivatestub.h

index 82391cc..bf396bb 100644 (file)
@@ -154,21 +154,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);
     }
 }
 
@@ -226,28 +234,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);
     }
 }
 
index 5762ca3..48dd60a 100644 (file)
@@ -40,6 +40,13 @@ GPSPosition::GPSPosition(QObject *parent)
     m_gpsPositionPrivate = new GPSPositionPrivate(this);
 }
 
+bool GPSPosition::isInitialized()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_gpsPositionPrivate->isInitialized();
+}
+
 bool GPSPosition::isRunning()
 {
     qDebug() << __PRETTY_FUNCTION__;
index ffbc394..387e3ae 100644 (file)
@@ -57,6 +57,13 @@ public:
 ******************************************************************************/
 public:
     /**
+    * @brief Returns is GPS initialized.
+    *
+    * @return true if initialized, false otherwise
+    */
+    bool isInitialized();
+
+    /**
     * @brief Checks if GPS is running.
     *
     * @return true if GPS running, false otherwise
index fb5c04f..68791b8 100644 (file)
@@ -32,6 +32,7 @@
 GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
     : QObject(parent),
       m_gpsSource(0),
+      m_initialized(false),
       m_running(false),
       m_updateInterval(DEFAULT_UPDATE_INTERVAL)
 {
@@ -40,6 +41,13 @@ GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
     m_parent = static_cast<GPSPosition*>(parent);
 }
 
+bool GPSPositionPrivate::isInitialized()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_initialized;
+}
+
 void GPSPositionPrivate::setMode(GPSPosition::Mode mode, const QString &filePath)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -53,6 +61,7 @@ void GPSPositionPrivate::setMode(GPSPosition::Mode mode, const QString &filePath
         m_gpsSource = QGeoPositionInfoSource::createDefaultSource(this);
 
         if (!m_gpsSource) {
+            m_initialized = false;
             emit m_parent->error(123);
             return;
         }
@@ -67,6 +76,7 @@ void GPSPositionPrivate::setMode(GPSPosition::Mode mode, const QString &filePath
     }
 
     if (m_gpsSource) {
+        m_initialized = true;
         connect(m_gpsSource, SIGNAL(positionUpdated(const QGeoPositionInfo &)),
                 this, SLOT(positionUpdated(const QGeoPositionInfo &)));
         connect(m_gpsSource, SIGNAL(updateTimeout()), this, SLOT(updateTimeout()));
@@ -79,7 +89,7 @@ void GPSPositionPrivate::start()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (m_gpsSource && !isRunning()) {
+    if (m_initialized && !isRunning()) {
         m_gpsSource->startUpdates();
         m_running = true;
     }
@@ -89,7 +99,7 @@ void GPSPositionPrivate::stop()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (m_gpsSource && isRunning()) {
+    if (m_initialized && isRunning()) {
         m_gpsSource->stopUpdates();
         m_running = false;
     }
index c0b0bb5..63f6e73 100644 (file)
@@ -52,6 +52,13 @@ public:
 ******************************************************************************/
 public:
     /**
+    * @brief Returns is GPS initialized.
+    *
+    * @return true if initialized, false otherwise
+    */
+    bool isInitialized();
+
+    /**
     * @brief Checks if GPS is running.
     *
     * @return true if GPS running, false otherwise
@@ -126,6 +133,7 @@ private slots:
 private:
     QGeoPositionInfoSource *m_gpsSource;        ///< GPS position info source
     GPSPosition *m_parent;                      ///< Parent object
+    bool m_initialized;                         ///< GPS is initialized
     bool m_running;                             ///< GPS is running
     int m_updateInterval;                       ///< GPS update interval
 };
index e0af1ae..2590fa1 100644 (file)
@@ -33,6 +33,7 @@
 GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
     : QObject(parent),
       m_liblocationWrapper(0),
+      m_initialized(false),
       m_running(false),
       m_updateInterval(DEFAULT_UPDATE_INTERVAL)
 {
@@ -41,6 +42,13 @@ GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
     m_parent = static_cast<GPSPosition*>(parent);
 }
 
+bool GPSPositionPrivate::isInitialized()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return m_initialized;
+}
+
 void GPSPositionPrivate::setMode(GPSPosition::Mode mode, const QString &filePath)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -56,12 +64,14 @@ void GPSPositionPrivate::setMode(GPSPosition::Mode mode, const QString &filePath
         m_liblocationWrapper = new LiblocationWrapper(this);
 
         if (!m_liblocationWrapper) {
+            m_initialized = false;
             emit m_parent->error(123);  ///Change to correct error code
             return;
         }
     }
 
     if (m_liblocationWrapper) {
+        m_initialized = true;
         m_liblocationWrapper->init(m_updateInterval);
 
         connect(m_liblocationWrapper, SIGNAL(locationChanged(const GeoPositionInfo &)),
@@ -75,7 +85,7 @@ void GPSPositionPrivate::start()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (m_liblocationWrapper && !isRunning()) {
+    if (m_initialized && !isRunning()) {
         m_liblocationWrapper->startUpdates();
         m_running = true;
     }
@@ -85,7 +95,7 @@ void GPSPositionPrivate::stop()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (m_liblocationWrapper && isRunning()) {
+    if (m_initialized && isRunning()) {
         m_liblocationWrapper->stopUpdates();
         m_running = false;
     }
index 89dfa2e..3192ff5 100644 (file)
@@ -49,6 +49,13 @@ public:
 ******************************************************************************/
 public:
     /**
+    * @brief Returns is GPS initialized.
+    *
+    * @return true if initialized, false otherwise
+    */
+    bool isInitialized();
+
+    /**
     * @brief Checks if GPS is running.
     *
     * @return true if GPS running, false otherwise
@@ -123,6 +130,7 @@ private slots:
 private:
     LiblocationWrapper *m_liblocationWrapper;    ///< Liblocation wrapper object
     GPSPosition *m_parent;                      ///< Parent object
+    bool m_initialized;                         ///< GPS is initialized
     bool m_running;                             ///< GPS is running
     int m_updateInterval;                       ///< GPS update interval
 };
index 6a5ed40..41f6a59 100644 (file)
@@ -32,6 +32,13 @@ GPSPositionPrivate::GPSPositionPrivate(QObject *parent)
     m_parent = static_cast<GPSPosition*>(parent);
 }
 
+bool GPSPositionPrivate::isInitialized()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    return false;
+}
+
 bool GPSPositionPrivate::isRunning()
 {
     qDebug() << __PRETTY_FUNCTION__;
index 169976e..e697266 100644 (file)
@@ -51,6 +51,14 @@ public:
 ******************************************************************************/
 public:
     /**
+    * @brief Returns is GPS initialized.
+    *
+    * RETURNS FALSE
+    * @return true if initialized, false otherwise
+    */
+    bool isInitialized();
+
+    /**
     * @brief Checks if GPS is running.
     *
     * RETURNS FALSE.