Changed GPS and automatic update buttons slots
authorSami Rämö <sami.ramo@ixonos.com>
Thu, 20 May 2010 12:17:34 +0000 (15:17 +0300)
committerSami Rämö <sami.ramo@ixonos.com>
Thu, 20 May 2010 12:17:34 +0000 (15:17 +0300)
 - Changed GPS & auto centering signals so that actions are not
   dependent on menu button signals anymore, which weren't emitted
   at startup when states were set but didn't change from buttons
   default states

 - changed messages so that they are displayed only at startup
   and when automatic centering is disabled because user have
   scrolled the map

 - some sorting

 - changed MapEngine GPS and automatic centering settings change
   methods to public

src/engine/engine.cpp
src/engine/engine.h
src/map/mapengine.cpp
src/map/mapengine.h
src/ui/mainwindow.cpp
src/ui/mainwindow.h

index 1bdac7b..11a2e0f 100644 (file)
@@ -95,8 +95,15 @@ SituareEngine::SituareEngine(QMainWindow *parent)
     QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
     QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
 
-    m_ui->setGPS(gpsEnabled.toBool());
-    m_ui->setAutoCentering(autoCenteringEnabled.toBool());
+    // set features on / off based on settings
+    changeAutoCenteringSetting(autoCenteringEnabled.toBool());
+    enableGPS(gpsEnabled.toBool());
+
+    // show messages at startup if features are enabled automatically
+    if (gpsEnabled.toBool())
+        m_ui->showMaemoInformationBox(tr("GPS enabled"));
+    if (gpsEnabled.toBool() && autoCenteringEnabled.toBool())
+        m_ui->showMaemoInformationBox(tr("Auto centering enabled"));
 
     m_mapEngine->init();
 
@@ -115,6 +122,107 @@ SituareEngine::~SituareEngine()
     settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
 }
 
+void SituareEngine::changeAutoCenteringSetting(bool enabled)
+{
+    m_autoCenteringEnabled = enabled;
+    enableAutoCentering(enabled);
+}
+
+void SituareEngine::disableAutoCentering()
+{
+    changeAutoCenteringSetting(false);
+    m_ui->showMaemoInformationBox(tr("Auto centering disabled"));
+}
+
+void SituareEngine::enableAutoCentering(bool enabled)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_ui->setAutoCenteringButtonEnabled(enabled);
+    m_mapEngine->setAutoCentering(enabled);
+
+    if (enabled)
+        m_gps->requestLastPosition();
+}
+
+void SituareEngine::enableGPS(bool enabled)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_ui->setGPSButtonEnabled(enabled);
+    m_mapEngine->setGPSEnabled(enabled);
+
+    if (enabled) {
+        m_gps->start();
+        enableAutoCentering(m_autoCenteringEnabled);
+        m_gps->requestLastPosition();
+    }
+    else {
+        m_gps->stop();
+        enableAutoCentering(false);
+    }
+}
+
+void SituareEngine::error(const QString &error)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+    qDebug() << error;
+    // ToDo: signal UI?
+}
+
+void SituareEngine::loginOk()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_ui->show();
+    m_situareService->fetchLocations(); // request user locations
+}
+
+void SituareEngine::loginProcessCancelled()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_ui->toggleProgressIndicator(false);
+    //ToDo: do something
+}
+
+void SituareEngine::refreshUserData()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_ui->toggleProgressIndicator(true);
+
+    m_situareService->fetchLocations();
+}
+
+void SituareEngine::requestAddress()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (m_gps->isRunning()) {
+        m_latestLocation = m_gps->lastPosition();
+        m_situareService->reverseGeo(m_latestLocation);
+    }
+    else {
+        m_situareService->reverseGeo(m_mapEngine->centerGeoCoordinate());
+    }
+}
+
+void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_ui->toggleProgressIndicator(true);
+
+    if (m_gps->isRunning()) {
+        m_latestLocation = m_gps->lastPosition();
+        m_situareService->updateLocation(m_latestLocation, status, publish);
+    }
+    else {
+        m_situareService->updateLocation(m_mapEngine->centerGeoCoordinate(), status, publish);
+    }
+}
+
 void SituareEngine::signalsFromGPS()
 {
     connect(m_gps, SIGNAL(position(QPointF,qreal)),
@@ -153,16 +261,10 @@ void SituareEngine::signalsFromMainWindow()
 
     // signals from menu buttons
 
-    connect(m_ui, SIGNAL(autoCenteringToggled(bool)),
-            m_mapEngine, SLOT(setAutoCentering(bool)));
-
-    connect(m_ui, SIGNAL(autoCenteringToggled(bool)),
-            this, SLOT(enableAutoCentering(bool)));
+    connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
+            this, SLOT(changeAutoCenteringSetting(bool)));
 
-    connect(m_ui, SIGNAL(gpsToggled(bool)),
-            m_mapEngine, SLOT(gpsEnabled(bool)));
-
-    connect(m_ui, SIGNAL(gpsToggled(bool)),
+    connect(m_ui, SIGNAL(gpsTriggered(bool)),
             this, SLOT(enableGPS(bool)));
 
     //signals from dialogs
@@ -229,62 +331,6 @@ void SituareEngine::signalsFromSituareService()
             m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
 }
 
-void SituareEngine::disableAutoCentering()
-{
-    m_ui->setAutoCentering(false);
-}
-
-void SituareEngine::loginProcessCancelled()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_ui->toggleProgressIndicator(false);
-    //ToDo: do something
-}
-
-void SituareEngine::error(const QString &error)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-    qDebug() << error;
-    // ToDo: signal UI?
-}
-
-void SituareEngine::loginOk()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_ui->show();
-    m_situareService->fetchLocations(); // request user locations
-}
-
-void SituareEngine::requestAddress()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    if (m_gps->isRunning()) {
-        m_latestLocation = m_gps->lastPosition();
-        m_situareService->reverseGeo(m_latestLocation);
-    }
-    else {
-        m_situareService->reverseGeo(m_mapEngine->centerGeoCoordinate());
-    }
-}
-
-void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_ui->toggleProgressIndicator(true);
-
-    if (m_gps->isRunning()) {
-        m_latestLocation = m_gps->lastPosition();
-        m_situareService->updateLocation(m_latestLocation, status, publish);
-    }
-    else {
-        m_situareService->updateLocation(m_mapEngine->centerGeoCoordinate(), status, publish);
-    }
-}
-
 void SituareEngine::updateWasSuccessful()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -292,15 +338,6 @@ void SituareEngine::updateWasSuccessful()
     m_situareService->fetchLocations();
 }
 
-void SituareEngine::refreshUserData()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_ui->toggleProgressIndicator(true);
-
-    m_situareService->fetchLocations();
-}
-
 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -310,27 +347,3 @@ void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
     emit userLocationReady(user);
     emit friendsLocationsReady(friendsList);
 }
-
-void SituareEngine::enableGPS(bool enabled)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    if (enabled) {
-        /// @todo is this required?
-        // m_gps->requestLastPosition();
-        m_gps->start();
-    }
-    else {
-        m_gps->stop();
-    }
-}
-
-void SituareEngine::enableAutoCentering(bool enabled)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_autoCenteringEnabled = enabled;
-
-    if (enabled)
-        m_gps->requestLastPosition();
-}
index c6962b3..95dd972 100644 (file)
@@ -130,6 +130,9 @@ public slots:
     void loginProcessCancelled();
 
 private slots:
+
+    void changeAutoCenteringSetting(bool enabled);
+
     /**
       * @brief Slot for disabling automatic centering when map is scrolled manually
       */
index 100037f..c6b340e 100644 (file)
@@ -339,6 +339,8 @@ void MapEngine::receiveOwnLocation(User *user)
 
 void MapEngine::gpsPositionUpdate(QPointF position, qreal accuracy)
 {
+    qDebug() << __PRETTY_FUNCTION__;
+
     m_gpsLocationItem->updatePosition(convertLatLonToSceneCoordinate(position), accuracy);
 
     if (m_autoCenteringEnabled)
@@ -375,7 +377,7 @@ void MapEngine::setAutoCentering(bool enabled)
 }
 
 
-void MapEngine::gpsEnabled(bool enabled)
+void MapEngine::setGPSEnabled(bool enabled)
 {
     m_gpsLocationItem->setEnabled(enabled);
 }
index 9134804..d9ddbfb 100644 (file)
@@ -127,6 +127,22 @@ public:
 
 public slots:
     /**
+    * @brief Set auto centering.
+    *
+    * @param enabled true if enabled, false otherwise
+    */
+    void setAutoCentering(bool enabled);
+
+    /**
+      * @brief Slot for enabling / disabling GPS
+      *
+      * GPS location item is disabled or enabled based on GPS state
+      *
+      * @param enabled True is GPS is enabled, otherwise false
+      */
+    void setGPSEnabled(bool enabled);
+
+    /**
     * @brief Slot for setting current view location
     *
     * Emits locationChanged signal.
@@ -224,15 +240,6 @@ private:
 
 private slots:
     /**
-      * @brief Slot for enabling / disabling GPS
-      *
-      * GPS location item is disabled or enabled based on GPS state
-      *
-      * @param enabled True is GPS is enabled, otherwise false
-      */
-    void gpsEnabled(bool enabled);
-
-    /**
       * @brief Slot for GPS position updates
       *
       * GPS location item is updated and map centered to new location (if automatic
@@ -255,13 +262,6 @@ private slots:
     void mapImageReceived(int zoomLevel, int x, int y, const QPixmap &image);
 
     /**
-    * @brief Set auto centering.
-    *
-    * @param enabled true if enabled, false otherwise
-    */
-    void setAutoCentering(bool enabled);
-
-    /**
     * @brief Slot for actions after view zoom is finished
     *
     * Does run removeOutOfViewTiles
index 5e8ed2a..f60c9ab 100644 (file)
@@ -96,14 +96,6 @@ MainWindow::~MainWindow()
         delete m_webView;
 }
 
-void MainWindow::autoCenteringToggledActions(bool enabled)
-{
-    if (enabled)
-        showMaemoInformationBox(tr("Auto centering enabled"));
-    else
-        showMaemoInformationBox(tr("Auto centering disabled"));
-}
-
 void MainWindow::buildFriendListPanel()
 {
     m_friendsListPanel = new FriendListPanel(this);
@@ -234,18 +226,14 @@ void MainWindow::createMenus()
     m_gpsToggleAct = new QAction(tr("GPS"), this);
     m_gpsToggleAct->setCheckable(true);
 
-    connect(m_gpsToggleAct, SIGNAL(toggled(bool)),
-            this, SIGNAL(gpsToggled(bool)));
-    connect(m_gpsToggleAct, SIGNAL(toggled(bool)),
-            this, SLOT(gpsToggledActions(bool)));
+    connect(m_gpsToggleAct, SIGNAL(triggered(bool)),
+            this, SIGNAL(gpsTriggered(bool)));
 
     // automatic centering
     m_autoCenteringAct = new QAction(tr("Auto centering"), this);
     m_autoCenteringAct->setCheckable(true);
-    connect(m_autoCenteringAct, SIGNAL(toggled(bool)),
-        this, SIGNAL(autoCenteringToggled(bool)));
-    connect(m_autoCenteringAct, SIGNAL(toggled(bool)),
-            this, SLOT(autoCenteringToggledActions(bool)));
+    connect(m_autoCenteringAct, SIGNAL(triggered(bool)),
+        this, SIGNAL(autoCenteringTriggered(bool)));
 
     // build the actual menu
     m_viewMenu = menuBar()->addMenu(tr("Main"));
@@ -286,20 +274,6 @@ void MainWindow::gpsTimeout()
     showMaemoInformationBox(tr("GPS timeout"));
 }
 
-void MainWindow::gpsToggledActions(bool enabled)
-{
-    if (enabled) {
-        showMaemoInformationBox(tr("GPS enabled"));
-        setOwnLocationCrosshairVisibility(false);
-    }
-    else {
-        showMaemoInformationBox(tr("GPS disabled"));
-        setOwnLocationCrosshairVisibility(true);
-    }
-
-    m_autoCenteringAct->setVisible(enabled);
-}
-
 void MainWindow::grabZoomKeys(bool grab)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -436,18 +410,25 @@ void MainWindow::openSettingsDialog()
     dialog->show();
 }
 
-void MainWindow::setAutoCentering(bool enabled)
+void MainWindow::setAutoCenteringButtonEnabled(bool enabled)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     m_autoCenteringAct->setChecked(enabled);
 }
 
-void MainWindow::setGPS(bool enabled)
+void MainWindow::setGPSButtonEnabled(bool enabled)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     m_gpsToggleAct->setChecked(enabled);
+
+    if (enabled)
+        setOwnLocationCrosshairVisibility(false);
+    else
+        setOwnLocationCrosshairVisibility(true);
+
+    m_autoCenteringAct->setVisible(enabled);
 }
 
 void MainWindow::setMapViewScene(QGraphicsScene *scene)
index 6007876..1650ce8 100644 (file)
@@ -87,7 +87,7 @@ public:
     *
     * @param enabled true if shoud be enabled, false otherwise
     */
-    void setAutoCentering(bool enabled);
+    void setAutoCenteringButtonEnabled(bool enabled);
 
     /**
     * @brief Enable / disable GPS.
@@ -97,7 +97,7 @@ public:
     *
     * @param enabled true if enabled, false otherwise
     */
-    void setGPS(bool enabled);
+    void setGPSButtonEnabled(bool enabled);
 
     /**
       * @brief Set scene for MapView
@@ -106,6 +106,13 @@ public:
       */
     void setMapViewScene(QGraphicsScene *scene);
 
+    /**
+    * @brief Show Maemo information box with message.
+    *
+    * @brief message information message
+    */
+    void showMaemoInformationBox(const QString &message);
+
 public slots:
     /**
     * @brief Slot to intercept signal when user has pressed connect button from loginDialog
@@ -176,15 +183,8 @@ private:
     */
     void setOwnLocationCrosshairVisibility(bool visible);
 
-    /**
-    * @brief Show Maemo information box with message.
-    *
-    * @brief message information message
-    */
-    void showMaemoInformationBox(const QString &message);
-
 private slots:
-    void autoCenteringToggledActions(bool enabled);
+//    void autoCenteringToggledActions(bool enabled);
 
     /**
     * @brief Slot for drawing the Open Street Map license text
@@ -216,7 +216,7 @@ private slots:
     */
     void gpsTimeout();
 
-    void gpsToggledActions(bool enabled);
+//    void gpsToggledActions(bool enabled);
 
     /**
     * @brief Slot to intercept signal when webview has finished loading webpage
@@ -251,6 +251,13 @@ signals:
     void autoCenteringToggled(bool enabled);
 
     /**
+    * @brief Automatic centering setting changed by user
+    *
+    * @param enabled True if automatic centering is enabled, otherwise false
+    */
+    void autoCenteringTriggered(bool enabled);
+
+    /**
     * @brief View should be centered to new location
     *
     * @param sceneCoordinate Scene coordinates of the new center point
@@ -262,7 +269,7 @@ signals:
     *
     * @param enabled True if GPS is enabled, otherwise false
     */
-    void gpsToggled(bool enabled);
+    void gpsTriggered(bool enabled);
 
 //     /**
 //    * @brief Signal for auto centering enabling.