Added unit tests.
[situare] / src / engine / engine.cpp
index f729a8e..d4064c7 100644 (file)
     USA.
  */
 
+#include <cmath>
+
 #include <QMessageBox>
 #include <QNetworkReply>
 
-#ifdef Q_WS_MAEMO_5
 #include "application.h"
-#endif
 #include "common.h"
+#include "contactmanager.h"
+#include "../error.h"
 #include "facebookservice/facebookauthentication.h"
 #include "gps/gpsposition.h"
 #include "map/mapengine.h"
+#include "routing/geocodingservice.h"
 #include "routing/routingservice.h"
+#include "mce.h"
+#include "network/networkaccessmanager.h"
 #include "situareservice/situareservice.h"
 #include "ui/mainwindow.h"
-#include "network/networkaccessmanager.h"
-#include "mce.h"
-#include <cmath>
 
 #include "engine.h"
 
@@ -54,22 +56,20 @@ SituareEngine::SituareEngine()
       m_automaticUpdateRequest(false),
       m_userMoved(false),
       m_automaticUpdateIntervalTimer(0),
-      m_lastUpdatedGPSPosition(QPointF())
+      m_lastUpdatedGPSPosition(GeoCoordinate())
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     m_ui = new MainWindow;
     m_ui->updateItemVisibility();
 
-#ifdef Q_WS_MAEMO_5
-    m_app = static_cast<Application *>(qApp);
-    m_app->registerWindow(m_ui->winId());
+    Application *application = static_cast<Application *>(qApp);
+    application->registerWindow(m_ui->winId());
 
-    connect(m_app, SIGNAL(topmostChanged(bool)),
-            this, SLOT(enablePowerSave(bool)));
-#endif
+    connect(application, SIGNAL(topmostWindowChanged(bool)),
+            this, SLOT(topmostWindowChanged(bool)));
 
-    m_networkAccessManager = NetworkAccessManager::instance();
+    m_networkAccessManager = new NetworkAccessManager(this);
 
     // build MapEngine
     m_mapEngine = new MapEngine(this);
@@ -79,19 +79,23 @@ SituareEngine::SituareEngine()
     m_gps = new GPSPosition(this);
 
     // build SituareService
-    m_situareService = new SituareService(this);
+    m_situareService = new SituareService(m_networkAccessManager,
+                                          new ImageFetcher(m_networkAccessManager, this), this);
 
     // build FacebookAuthenticator
     m_facebookAuthenticator = new FacebookAuthentication(this);
 
     // build routing service
     m_routingService = new RoutingService(this); // create this when needed, not in constructor!
-    connect(m_routingService, SIGNAL(routeParsed(Route)),
-            m_mapEngine, SLOT(setRoute(Route)));
+
+    // build geocoding service
+    m_geocodingService = new GeocodingService(this);
 
     // connect signals
     signalsFromMapEngine();
+    signalsFromGeocodingService();
     signalsFromGPS();
+    signalsFromRoutingService();
     signalsFromSituareService();
     signalsFromMainWindow();
     signalsFromFacebookAuthenticator();
@@ -108,11 +112,14 @@ SituareEngine::SituareEngine()
     connect(this, SIGNAL(friendsLocationsReady(QList<User*>&)),
             m_mapEngine, SIGNAL(friendsLocationsReady(QList<User*>&)));
 
-    connect(this, SIGNAL(friendImageReady(User*)),
-            m_ui, SIGNAL(friendImageReady(User*)));
+    connect(this, SIGNAL(userImageReady(QString,QPixmap)),
+            m_ui, SIGNAL(userImageReady(QString,QPixmap)));
+
+    connect(this, SIGNAL(friendImageReady(QString,QPixmap)),
+            m_ui, SIGNAL(friendImageReady(QString,QPixmap)));
 
-    connect(this, SIGNAL(friendImageReady(User*)),
-            m_mapEngine, SIGNAL(friendImageReady(User*)));
+    connect(this, SIGNAL(friendImageReady(QString,QPixmap)),
+            m_mapEngine, SIGNAL(friendImageReady(QString,QPixmap)));
 
     m_automaticUpdateIntervalTimer = new QTimer(this);
     connect(m_automaticUpdateIntervalTimer, SIGNAL(timeout()),
@@ -129,10 +136,10 @@ SituareEngine::SituareEngine()
     initializeGpsAndAutocentering();
 
     m_mce = new MCE(this);
-    connect(m_mce, SIGNAL(displayOff(bool)), this, SLOT(enablePowerSave(bool)));
-
-    /// @todo for testing, remove after real route start and end points are available
-    m_routingService->fetchRoute(QPointF(65.010193,25.509859), QPointF(65.015152, 25.46645));
+    connect(m_mce, SIGNAL(displayOff(bool)), this, SLOT(setPowerSaving(bool)));
+    
+    m_contactManager = new ContactManager(this);
+    m_contactManager->requestContactGuids();
 }
 
 SituareEngine::~SituareEngine()
@@ -148,10 +155,10 @@ SituareEngine::~SituareEngine()
 
 void SituareEngine::changeAutoCenteringSetting(bool enabled)
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__ << enabled;
 
     m_autoCenteringEnabled = enabled;
-    enableAutoCentering(enabled);
+    setAutoCentering(enabled);
 }
 
 void SituareEngine::disableAutoCentering()
@@ -159,50 +166,14 @@ void SituareEngine::disableAutoCentering()
     qDebug() << __PRETTY_FUNCTION__;
 
     changeAutoCenteringSetting(false);
-    m_ui->buildInformationBox(tr("Auto centering disabled"));
 }
 
-void SituareEngine::enableAutoCentering(bool enabled)
+void SituareEngine::draggingModeTriggered()
 {
     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->setOwnLocationCrosshairVisibility(!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(m_ui->loginState())
-                m_ui->readAutomaticLocationUpdateSettings();
-        }
-        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);
-    }
+    if (m_mce)
+        m_mce->vibrationFeedback();
 }
 
 void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateIntervalMsecs)
@@ -223,30 +194,20 @@ void SituareEngine::enableAutomaticLocationUpdate(bool enabled, int updateInterv
             else
                 m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
 
-            connect(m_gps, SIGNAL(position(QPointF,qreal)),
-                    this, SLOT(requestAutomaticUpdateIfMoved(QPointF)));
+            connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
+                    this, SLOT(requestAutomaticUpdateIfMoved(GeoCoordinate)));
 
             m_automaticUpdateIntervalTimer->start();
 
         } else {
-            disconnect(m_gps, SIGNAL(position(QPointF,qreal)),
-                    this, SLOT(requestAutomaticUpdateIfMoved(QPointF)));
+            disconnect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
+                    this, SLOT(requestAutomaticUpdateIfMoved(GeoCoordinate)));
 
             m_automaticUpdateIntervalTimer->stop();
         }
     }
 }
 
-void SituareEngine::enablePowerSave(bool enabled)
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_gps->enablePowerSave(enabled);
-
-    if(m_autoCenteringEnabled)
-        m_mapEngine->setAutoCentering(!enabled);
-}
-
 void SituareEngine::error(const int context, const int error)
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -312,8 +273,6 @@ void SituareEngine::error(const int context, const int error)
         m_ui->buildInformationBox(tr("Data retrieval failed, please try again"), true);
         break;
     case SituareError::ADDRESS_RETRIEVAL_FAILED:
-    case SituareError::ERROR_GEOLOCATION_REQUEST_FAIL:
-    case SituareError::ERROR_GEOLOCATION_LONLAT_INVALID:
         m_ui->toggleProgressIndicator(false);
         m_ui->buildInformationBox(tr("Address retrieval failed"), true);
         break;
@@ -324,7 +283,7 @@ void SituareEngine::error(const int context, const int error)
         m_ui->buildInformationBox(tr("Map image download failed"), true);
         break;
     case SituareError::GPS_INITIALIZATION_FAILED:
-        enableGPS(false);
+        setGPS(false);
         m_ui->buildInformationBox(tr("GPS initialization failed"), true);
         break;
     case SituareError::INVALID_JSON:
@@ -332,17 +291,19 @@ void SituareEngine::error(const int context, const int error)
         m_ui->loggedIn(false);
         m_facebookAuthenticator->clearAccountInformation(false); // clean all
         break;
-    case SituareError::ERROR_GEOLOCATION_SERVER_UNAVAILABLE:
+    case SituareError::ERROR_ROUTING_FAILED:
         m_ui->toggleProgressIndicator(false);
-        m_ui->buildInformationBox(tr("Address server not responding"), true);
+        m_ui->buildInformationBox(tr("Routing failed"), true);
+        break;
+    case SituareError::ERROR_LOCATION_SEARCH_FAILED:
+        m_ui->buildInformationBox(tr("No results found"), true);
         break;
     default:
         m_ui->toggleProgressIndicator(false);
         if(context == ErrorContext::NETWORK)
-            qCritical() << "QNetworkReply::NetworkError: " << error;
+            qCritical() << __PRETTY_FUNCTION__ << "QNetworkReply::NetworkError: " << error;
         else
-            qCritical() << "Unknown error: " << error;
-
+            qCritical() << __PRETTY_FUNCTION__ << "Unknown error: " << error;
         break;
     }
 }
@@ -354,14 +315,14 @@ void SituareEngine::fetchUsernameFromSettings()
     m_ui->setUsername(m_facebookAuthenticator->loadUsername());
 }
 
-void SituareEngine::imageReady(User *user)
+void SituareEngine::imageReady(const QString &id, const QPixmap &image)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if(user->type())
-        emit userLocationReady(user);
+    if(m_facebookAuthenticator->loginCredentials().userID() == id)
+        emit userImageReady(id, image);
     else
-        emit friendImageReady(user);
+        emit friendImageReady(id, image);
 }
 
 void SituareEngine::initializeGpsAndAutocentering()
@@ -376,30 +337,34 @@ void SituareEngine::initializeGpsAndAutocentering()
 
         if (gpsEnabled.toString().isEmpty()) { // First start. Situare.conf file does not exists
 
-            connect(m_gps, SIGNAL(position(QPointF,qreal)),
-                    this, SLOT(setFirstStartZoomLevel(QPointF,qreal)));
+            connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
+                    this, SLOT(setFirstStartZoomLevel()));
 
             changeAutoCenteringSetting(true);
-            enableGPS(true);
+            setGPS(true);
 
             m_ui->buildInformationBox(tr("GPS enabled"));
-            m_ui->buildInformationBox(tr("Auto centering enabled"));
 
         } else { // Normal start
             changeAutoCenteringSetting(autoCenteringEnabled.toBool());
-            enableGPS(gpsEnabled.toBool());
+            setGPS(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);
+        setGPS(false);
     }
 }
 
+void SituareEngine::locationSearch(QString location)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if(!location.isEmpty())
+        m_geocodingService->requestLocation(location);
+}
+
 void SituareEngine::loginActionPressed()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -498,13 +463,13 @@ void SituareEngine::requestUpdateLocation(const QString &status, bool publish)
     }
 }
 
-void SituareEngine::requestAutomaticUpdateIfMoved(QPointF position)
+void SituareEngine::requestAutomaticUpdateIfMoved(GeoCoordinate position)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if ((fabs(m_lastUpdatedGPSPosition.x() - position.x()) >
+    if ((fabs(m_lastUpdatedGPSPosition.longitude() - position.longitude()) >
          USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE) ||
-        (fabs(m_lastUpdatedGPSPosition.y() - position.y()) >
+        (fabs(m_lastUpdatedGPSPosition.latitude() - position.latitude()) >
          USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE)) {
 
         m_lastUpdatedGPSPosition = position;
@@ -518,18 +483,140 @@ void SituareEngine::requestAutomaticUpdateIfMoved(QPointF position)
     }
 }
 
-void SituareEngine::setFirstStartZoomLevel(QPointF latLonCoordinate, qreal accuracy)
+void SituareEngine::requestInterestingPeople()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    Q_UNUSED(latLonCoordinate);
-    Q_UNUSED(accuracy);
+    QRectF currentSceneRect = m_mapEngine->currentViewSceneRect();
+    SceneCoordinate bottomLeftSceneCoordinate(currentSceneRect.left(), currentSceneRect.bottom());
+    SceneCoordinate topRightSceneCoordinate(currentSceneRect.right(), currentSceneRect.top());
+
+    m_situareService->fetchPeopleWithSimilarInterest(GeoCoordinate(bottomLeftSceneCoordinate),
+                                                     GeoCoordinate(topRightSceneCoordinate));
+}
+
+void SituareEngine::requestSendMessage(const QString &receiverId, const QString &message,
+                                bool addCoordinates)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    if (addCoordinates)
+        m_situareService->sendMessage(receiverId, message, m_mapEngine->centerGeoCoordinate());
+    else
+        m_situareService->sendMessage(receiverId, message);
+}
+
+
+void SituareEngine::routeParsed(Route &route)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    Q_UNUSED(route);
+
+    m_ui->toggleProgressIndicator(false);
+}
+
+void SituareEngine::routeTo(const GeoCoordinate &endPointCoordinates)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_ui->toggleProgressIndicator(true);
+
+    if (m_gps->isRunning())
+        m_routingService->requestRoute(m_gps->lastPosition(), endPointCoordinates);
+    else
+        m_routingService->requestRoute(m_mapEngine->centerGeoCoordinate(), endPointCoordinates);
+}
+
+void SituareEngine::routeToCursor()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    routeTo(m_mapEngine->centerGeoCoordinate());
+}
+
+void SituareEngine::setAutoCentering(bool enabled)
+{
+    qDebug() << __PRETTY_FUNCTION__ << enabled;
+
+    m_ui->setIndicatorButtonEnabled(enabled);
+    m_mapEngine->setAutoCentering(enabled);
+    m_ui->setCrosshairVisibility(!enabled);
+
+    if (enabled) {
+        setGPS(true);
+        m_gps->requestLastPosition();
+    }
+}
+
+void SituareEngine::setFirstStartZoomLevel()
+{
+    qDebug() << __PRETTY_FUNCTION__;
 
     if (m_autoCenteringEnabled) // autocentering is disabled when map is scrolled
         m_mapEngine->setZoomLevel(DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE);
 
-    disconnect(m_gps, SIGNAL(position(QPointF,qreal)),
-               this, SLOT(setFirstStartZoomLevel(QPointF,qreal)));
+    disconnect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
+               this, SLOT(setFirstStartZoomLevel()));
+}
+
+void SituareEngine::setGPS(bool enabled)
+{
+    qDebug() << __PRETTY_FUNCTION__ << enabled;
+
+    if (m_gps->isInitialized()) {
+        m_ui->setGPSButtonEnabled(enabled);
+        m_mapEngine->setGPSEnabled(enabled);
+
+        if (enabled && !m_gps->isRunning()) {
+            m_gps->start();
+            m_gps->requestLastPosition();
+
+            if(m_ui->loginState())
+                m_ui->readAutomaticLocationUpdateSettings();
+        }
+        else if (!enabled && m_gps->isRunning()) {
+            m_gps->stop();
+            changeAutoCenteringSetting(false);
+            enableAutomaticLocationUpdate(false);
+        }
+    }
+    else {
+        if (enabled)
+            m_ui->buildInformationBox(tr("Unable to start GPS"));
+        m_ui->setGPSButtonEnabled(false);
+        m_mapEngine->setGPSEnabled(false);
+    }
+}
+
+void SituareEngine::setPowerSaving(bool enabled)
+{
+    qDebug() << __PRETTY_FUNCTION__ << enabled;
+
+    m_gps->enablePowerSave(enabled);
+
+    if(m_autoCenteringEnabled)
+        m_mapEngine->setAutoCentering(!enabled);
+}
+
+void SituareEngine::showContactDialog(const QString &facebookId)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    QString guid = m_contactManager->contactGuid(facebookId);
+
+    if (!guid.isEmpty())
+        m_ui->showContactDialog(guid);
+    else
+        m_ui->buildInformationBox(tr("Unable to find contact.\nAdd Facebook IM "
+                                     "account from Conversations to use this feature."), true);
+}
+
+void SituareEngine::showMessageDialog(const QPair<QString, QString> &receiver)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    m_ui->showMessageDialog(receiver);
 }
 
 void SituareEngine::signalsFromFacebookAuthenticator()
@@ -555,12 +642,23 @@ void SituareEngine::signalsFromFacebookAuthenticator()
             m_ui, SLOT(loginUsingCookies()));
 }
 
+void SituareEngine::signalsFromGeocodingService()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    connect(m_geocodingService, SIGNAL(locationDataParsed(const QList<Location>&)),
+            m_ui, SIGNAL(locationDataParsed(const QList<Location>&)));
+
+    connect(m_geocodingService, SIGNAL(error(int, int)),
+            this, SLOT(error(int, int)));
+}
+
 void SituareEngine::signalsFromGPS()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    connect(m_gps, SIGNAL(position(QPointF,qreal)),
-            m_mapEngine, SLOT(gpsPositionUpdate(QPointF,qreal)));
+    connect(m_gps, SIGNAL(position(GeoCoordinate, qreal)),
+            m_mapEngine, SLOT(gpsPositionUpdate(GeoCoordinate, qreal)));
 
     connect(m_gps, SIGNAL(timeout()),
             m_ui, SLOT(gpsTimeout()));
@@ -589,8 +687,8 @@ void SituareEngine::signalsFromMainWindow()
             m_facebookAuthenticator, SLOT(updateCredentials(QUrl)));
 
     // signals from map view
-    connect(m_ui, SIGNAL(mapViewScrolled(QPoint)),
-            m_mapEngine, SLOT(setCenterPosition(QPoint)));
+    connect(m_ui, SIGNAL(mapViewScrolled(SceneCoordinate)),
+            m_mapEngine, SLOT(setCenterPosition(SceneCoordinate)));
 
     connect(m_ui, SIGNAL(mapViewResized(QSize)),
             m_mapEngine, SLOT(viewResized(QSize)));
@@ -606,11 +704,8 @@ void SituareEngine::signalsFromMainWindow()
             m_mapEngine, SLOT(zoomOut()));
 
     // signals from menu buttons
-    connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
-            this, SLOT(changeAutoCenteringSetting(bool)));
-
     connect(m_ui, SIGNAL(gpsTriggered(bool)),
-            this, SLOT(enableGPS(bool)));
+            this, SLOT(setGPS(bool)));
 
     //signals from dialogs
     connect(m_ui, SIGNAL(cancelLoginProcess()),
@@ -625,16 +720,75 @@ void SituareEngine::signalsFromMainWindow()
     connect(m_ui, SIGNAL(enableAutomaticLocationUpdate(bool, int)),
             this, SLOT(enableAutomaticLocationUpdate(bool, int)));
 
+    connect(m_ui, SIGNAL(addTags(QStringList)),
+            m_situareService, SLOT(addTags(QStringList)));
+
+    connect(m_ui, SIGNAL(removeTags(QStringList)),
+            m_situareService, SLOT(removeTags(QStringList)));
+
     // signals from user info tab
     connect(m_ui, SIGNAL(refreshUserData()),
             this, SLOT(refreshUserData()));
 
-    connect(m_ui, SIGNAL(findUser(QPointF)),
-            m_mapEngine, SLOT(centerToCoordinates(QPointF)));
+    connect(m_ui, SIGNAL(centerToCoordinates(GeoCoordinate)),
+            m_mapEngine, SLOT(centerToCoordinates(GeoCoordinate)));
+
+    connect(m_ui, SIGNAL(requestPopularTags()),
+            m_situareService, SLOT(fetchPopularTags()));
+
+    // routing signal from friend list tab & search location tab
+    connect(m_ui, SIGNAL(routeTo(const GeoCoordinate&)),
+            this, SLOT(routeTo(const GeoCoordinate&)));
+
+    connect(m_ui, SIGNAL(requestContactDialog(const QString &)),
+            this, SLOT(showContactDialog(const QString &)));
+
+    // signals from location search panel
+    connect(m_ui,
+            SIGNAL(locationItemClicked(const GeoCoordinate&, const GeoCoordinate&)),
+            m_mapEngine,
+            SLOT(showMapArea(const GeoCoordinate&, const GeoCoordinate&)));
+
+    connect(m_ui, SIGNAL(searchHistoryItemClicked(QString)),
+            this, SLOT(locationSearch(QString)));
+
+    // signals from routing tab
+    connect(m_ui, SIGNAL(clearRoute()),
+            m_mapEngine, SLOT(clearRoute()));
+
+    connect(m_ui, SIGNAL(routeToCursor()),
+            this, SLOT(routeToCursor()));
+
+    // signals from distance indicator button
+    connect(m_ui, SIGNAL(autoCenteringTriggered(bool)),
+            this, SLOT(changeAutoCenteringSetting(bool)));
+
+    connect(m_ui, SIGNAL(draggingModeTriggered()),
+            this, SLOT(draggingModeTriggered()));
+
+    // signal from search search dialogs
+    connect(m_ui, SIGNAL(searchForLocation(QString)),
+            this, SLOT(locationSearch(QString)));
+
+    connect(m_ui, SIGNAL(requestSearchPeopleByTag(QString)),
+            m_situareService, SLOT(searchPeopleByTag(QString)));
+
+    // signals from meet people panel
+    connect(m_ui, SIGNAL(requestInterestingPeople()),
+            this, SLOT(requestInterestingPeople()));
+
+    connect(m_ui, SIGNAL(requestMessageDialog(QPair<QString, QString>)),
+            this, SLOT(showMessageDialog(QPair<QString, QString>)));
 
-    // signals from friend list tab
-    connect(m_ui, SIGNAL(findFriend(QPointF)),
-            m_mapEngine, SLOT(centerToCoordinates(QPointF)));
+    connect(m_ui, SIGNAL(sendMessage(QString,QString,bool)),
+            this, SLOT(requestSendMessage(QString,QString,bool)));
+
+    // signals from message panel
+    connect(m_ui, SIGNAL(requestMessages()),
+            m_situareService, SLOT(fetchMessages()));
+
+    connect(m_ui, SIGNAL(requestRemoveMessage(QString)),
+            m_situareService, SLOT(removeMessage(QString)));
 }
 
 void SituareEngine::signalsFromMapEngine()
@@ -644,8 +798,8 @@ void SituareEngine::signalsFromMapEngine()
     connect(m_mapEngine, SIGNAL(error(int, int)),
             this, SLOT(error(int, int)));
 
-    connect(m_mapEngine, SIGNAL(locationChanged(QPoint)),
-            m_ui, SIGNAL(centerToSceneCoordinates(QPoint)));
+    connect(m_mapEngine, SIGNAL(locationChanged(SceneCoordinate)),
+            m_ui, SIGNAL(centerToSceneCoordinates(SceneCoordinate)));
 
     connect(m_mapEngine, SIGNAL(zoomLevelChanged(int)),
             m_ui, SIGNAL(zoomLevelChanged(int)));
@@ -664,6 +818,26 @@ void SituareEngine::signalsFromMapEngine()
 
     connect(m_mapEngine, SIGNAL(newMapResolution(qreal)),
             m_ui, SIGNAL(newMapResolution(qreal)));
+
+    connect(m_mapEngine, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)),
+            m_ui, SIGNAL(directionIndicatorValuesUpdate(qreal, qreal, bool)));
+}
+
+void SituareEngine::signalsFromRoutingService()
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    connect(m_routingService, SIGNAL(routeParsed(Route&)),
+            this, SLOT(routeParsed(Route&)));
+
+    connect(m_routingService, SIGNAL(routeParsed(Route&)),
+            m_mapEngine, SLOT(setRoute(Route&)));
+
+    connect(m_routingService, SIGNAL(routeParsed(Route&)),
+            m_ui, SIGNAL(routeParsed(Route&)));
+
+    connect(m_routingService, SIGNAL(error(int, int)),
+            this, SLOT(error(int, int)));
 }
 
 void SituareEngine::signalsFromSituareService()
@@ -673,8 +847,8 @@ void SituareEngine::signalsFromSituareService()
     connect(m_situareService, SIGNAL(error(int, int)),
             this, SLOT(error(int, int)));
 
-    connect(m_situareService, SIGNAL(imageReady(User*)),
-            this, SLOT(imageReady(User*)));
+    connect(m_situareService, SIGNAL(imageReady(QString,QPixmap)),
+            this, SLOT(imageReady(QString,QPixmap)));
 
     connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
             m_ui, SIGNAL(reverseGeoReady(QString)));
@@ -682,11 +856,20 @@ void SituareEngine::signalsFromSituareService()
     connect(m_situareService, SIGNAL(userDataChanged(User*, QList<User*>&)),
             this, SLOT(userDataChanged(User*, QList<User*>&)));
 
-    connect(m_situareService, SIGNAL(updateWasSuccessful()),
-            this, SLOT(updateWasSuccessful()));
+    connect(m_situareService, SIGNAL(updateWasSuccessful(SituareService::SuccessfulMethod)),
+            this, SLOT(updateWasSuccessful(SituareService::SuccessfulMethod)));
 
-    connect(m_situareService, SIGNAL(updateWasSuccessful()),
+    connect(m_situareService, SIGNAL(updateWasSuccessful(SituareService::SuccessfulMethod)),
             m_ui, SIGNAL(clearUpdateLocationDialogData()));
+
+    connect(m_situareService, SIGNAL(interestingPeopleReceived(QList<User>&,QList<User>&)),
+            m_ui, SIGNAL(interestingPeopleReceived(QList<User>&,QList<User>&)));
+
+    connect(m_situareService, SIGNAL(messagesReceived(QList<Message>&, QList<Message> &)),
+            m_ui, SIGNAL(messagesReceived(QList<Message>&, QList<Message>&)));
+
+    connect(m_situareService, SIGNAL(popularTagsReceived(QHash<QString,QString>&)),
+            m_ui, SIGNAL(popularTagsReceived(QHash<QString,QString>&)));
 }
 
 void SituareEngine::startAutomaticUpdate()
@@ -697,14 +880,29 @@ void SituareEngine::startAutomaticUpdate()
     m_automaticUpdateRequest = true;
 }
 
-void SituareEngine::updateWasSuccessful()
+void SituareEngine::topmostWindowChanged(bool isMainWindow)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    if (m_networkAccessManager->isConnected())
-        m_situareService->fetchLocations();
-    else
+    setPowerSaving(!isMainWindow);
+}
+
+void SituareEngine::updateWasSuccessful(SituareService::SuccessfulMethod successfulMethod)
+{
+    qWarning() << __PRETTY_FUNCTION__;
+
+    if (m_networkAccessManager->isConnected()) {
+        if (successfulMethod == SituareService::SuccessfulUpdateLocation)
+            m_situareService->fetchLocations();
+        else  if ((successfulMethod == SituareService::SuccessfulRemoveMessage) ||
+                  (successfulMethod == SituareService::SuccessfulSendMessage))
+            m_situareService->fetchMessages();
+        else if ((successfulMethod == SituareService::SuccessfulAddTags) ||
+                 (successfulMethod == SituareService::SuccessfulRemoveTags))
+            m_situareService->fetchLocations();
+    } else {
         error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
+    }
 }
 
 void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
@@ -712,7 +910,6 @@ void SituareEngine::userDataChanged(User *user, QList<User *> &friendsList)
     qDebug() << __PRETTY_FUNCTION__;
 
     m_ui->toggleProgressIndicator(false);
-    m_ui->showPanels();
 
     emit userLocationReady(user);
     emit friendsLocationsReady(friendsList);