Added wallPostPermission parameter to loggedIn signal
[situare] / src / engine / engine.cpp
index 64fa07f..9b82514 100644 (file)
     USA.
  */
 
+#include <cmath>
+
 #include <QMessageBox>
 #include <QNetworkReply>
 
+#include "application.h"
 #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"
 
@@ -44,20 +50,26 @@ const qreal USER_MOVEMENT_MINIMUM_LONGITUDE_DIFFERENCE = 0.003;///< Min value fo
 const qreal USER_MOVEMENT_MINIMUM_LATITUDE_DIFFERENCE = 0.001;///< Min value for user move longitude
 const int MIN_UPDATE_INTERVAL_MSECS = 5*60*1000;
 
-SituareEngine::SituareEngine(QMainWindow *parent)
-    : QObject(parent),
-      m_autoCenteringEnabled(false),
+SituareEngine::SituareEngine()
+    : m_autoCenteringEnabled(false),
       m_automaticUpdateFirstStart(true),
       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();
+    m_ui->updateItemVisibility(false);
+
+    Application *application = static_cast<Application *>(qApp);
+    application->registerWindow(m_ui->winId());
 
-    m_networkAccessManager = NetworkAccessManager::instance();
+    connect(application, SIGNAL(topmostWindowChanged(bool)),
+            this, SLOT(topmostWindowChanged(bool)));
+
+    m_networkAccessManager = new NetworkAccessManager(this);
 
     // build MapEngine
     m_mapEngine = new MapEngine(this);
@@ -70,11 +82,19 @@ SituareEngine::SituareEngine(QMainWindow *parent)
     m_situareService = new SituareService(this);
 
     // build FacebookAuthenticator
-    m_facebookAuthenticator = new FacebookAuthentication(this);
+    m_facebookAuthenticator = new FacebookAuthentication(m_ui, this);
+
+    // build routing service
+    m_routingService = new RoutingService(this); // create this when needed, not in constructor!
+
+    // build geocoding service
+    m_geocodingService = new GeocodingService(this);
 
     // connect signals
     signalsFromMapEngine();
+    signalsFromGeocodingService();
     signalsFromGPS();
+    signalsFromRoutingService();
     signalsFromSituareService();
     signalsFromMainWindow();
     signalsFromFacebookAuthenticator();
@@ -91,6 +111,12 @@ SituareEngine::SituareEngine(QMainWindow *parent)
     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(friendImageReady(User*)),
+            m_mapEngine, SIGNAL(friendImageReady(User*)));
+
     m_automaticUpdateIntervalTimer = new QTimer(this);
     connect(m_automaticUpdateIntervalTimer, SIGNAL(timeout()),
             this, SLOT(startAutomaticUpdate()));
@@ -100,13 +126,16 @@ SituareEngine::SituareEngine(QMainWindow *parent)
     m_mapEngine->init();
     m_ui->show();
 
-    m_facebookAuthenticator->start();
-
     m_gps->setMode(GPSPosition::Default);
     initializeGpsAndAutocentering();
 
     m_mce = new MCE(this);
-    connect(m_mce, SIGNAL(displayStateChanged(bool)), this, SLOT(displayStateChanged(bool)));
+    connect(m_mce, SIGNAL(displayOff(bool)), this, SLOT(setPowerSaving(bool)));
+
+    m_contactManager = new ContactManager(this);
+    m_contactManager->requestContactGuids();
+
+    m_facebookAuthenticator->login();
 }
 
 SituareEngine::~SituareEngine()
@@ -115,17 +144,17 @@ SituareEngine::~SituareEngine()
 
     delete m_ui;
 
-    QSettings settings(DIRECTORY_NAME, FILE_NAME);
+    QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
     settings.setValue(SETTINGS_GPS_ENABLED, m_gps->isRunning());
     settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
 }
 
 void SituareEngine::changeAutoCenteringSetting(bool enabled)
 {
-    qDebug() << __PRETTY_FUNCTION__;
+    qDebug() << __PRETTY_FUNCTION__ << enabled;
 
     m_autoCenteringEnabled = enabled;
-    enableAutoCentering(enabled);
+    setAutoCentering(enabled);
 }
 
 void SituareEngine::disableAutoCentering()
@@ -133,60 +162,14 @@ void SituareEngine::disableAutoCentering()
     qDebug() << __PRETTY_FUNCTION__;
 
     changeAutoCenteringSetting(false);
-    m_ui->buildInformationBox(tr("Auto centering disabled"));
 }
 
-void SituareEngine::displayStateChanged(bool enabled)
+void SituareEngine::draggingModeTriggered()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_gps->enablePowerSave(!enabled);
-
-    if (m_autoCenteringEnabled)
-        enableAutoCentering(enabled);
-}
-
-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->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)
@@ -207,14 +190,14 @@ 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();
         }
@@ -233,10 +216,10 @@ void SituareEngine::error(const int context, const int error)
             m_ui->buildInformationBox(tr("Unknown server error"), true);
         }
         break;
-    case SituareError::ERROR_MISSING_ARGUMENT | QNetworkReply::ConnectionRefusedError :
+    case 1: //errors: SituareError::ERROR_MISSING_ARGUMENT and QNetworkReply::ConnectionRefusedError
         m_ui->toggleProgressIndicator(false);
         if(context == ErrorContext::SITUARE) {
-            m_ui->buildInformationBox(tr("Missing argument from request"), true);
+            m_ui->buildInformationBox(tr("Missing parameter from request"), true);
         } else if(context == ErrorContext::NETWORK) {
             m_ui->buildInformationBox(tr("Connection refused by the server"), true);
         }
@@ -267,15 +250,8 @@ void SituareEngine::error(const int context, const int error)
         break;
     case SituareError::SESSION_EXPIRED:
         m_ui->buildInformationBox(tr("Session expired. Please login again"), true);
-        m_facebookAuthenticator->clearAccountInformation(true); // keep username = true
-        m_situareService->clearUserData();
-        m_ui->loggedIn(false);
-        m_ui->loginFailed();
-        break;
-    case SituareError::LOGIN_FAILED:
-        m_ui->toggleProgressIndicator(false);
-        m_ui->buildInformationBox(tr("Invalid E-mail address or password"), true);
-        m_ui->loginFailed();
+        m_facebookAuthenticator->logOut();
+        m_facebookAuthenticator->login();
         break;
     case SituareError::UPDATE_FAILED:
         m_ui->toggleProgressIndicator(false);
@@ -286,6 +262,7 @@ 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:
+        m_ui->toggleProgressIndicator(false);
         m_ui->buildInformationBox(tr("Address retrieval failed"), true);
         break;
     case SituareError::IMAGE_DOWNLOAD_FAILED:
@@ -295,7 +272,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:
@@ -303,41 +280,38 @@ 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("Geolocation server not responding"), true);
+        m_ui->buildInformationBox(tr("Routing failed"), true);
         break;
-    case SituareError::ERROR_GEOLOCATION_REQUEST_FAIL:
-        m_ui->toggleProgressIndicator(false);
-        m_ui->buildInformationBox(tr("Geolocation request failed, please try again"), true);
-        break;
-    case SituareError::ERROR_GEOLOCATION_LONLAT_INVALID:
-        m_ui->toggleProgressIndicator(false);
-        m_ui->buildInformationBox(tr("Invalid lat/lon value, please try again"), true);
+    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;
     }
 }
 
-void SituareEngine::fetchUsernameFromSettings()
+void SituareEngine::imageReady(User *user)
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    m_ui->setUsername(m_facebookAuthenticator->loadUsername());
+    if(user->type())
+        emit userLocationReady(user);
+    else
+        emit friendImageReady(user);
 }
 
 void SituareEngine::initializeGpsAndAutocentering()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
-    QSettings settings(DIRECTORY_NAME, FILE_NAME);
+    QSettings settings(SETTINGS_ORGANIZATION_NAME, SETTINGS_APPLICATION_NAME);
     QVariant gpsEnabled = settings.value(SETTINGS_GPS_ENABLED);
     QVariant autoCenteringEnabled = settings.value(SETTINGS_AUTO_CENTERING_ENABLED);
 
@@ -345,69 +319,59 @@ 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__;
 
-    if (m_networkAccessManager->isConnected()) {
-        if(m_ui->loginState()) {
-            logout();
-            m_situareService->clearUserData();
-        } else {
-            m_facebookAuthenticator->start();
-        }
-    }
-    else {
+    if (m_facebookAuthenticator->isLoggedIn())
+        m_facebookAuthenticator->logOut(true);
+    else if (m_networkAccessManager->isConnected())
+        m_facebookAuthenticator->login();
+    else
         error(ErrorContext::NETWORK, QNetworkReply::UnknownNetworkError);
-    }
 }
 
-void SituareEngine::loginOk()
+void SituareEngine::onLogin()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
     m_ui->loggedIn(true);
 
-    m_ui->show();
-    m_situareService->fetchLocations(); // request user locations
+    m_situareService->fetchLocations();
 
     if (m_gps->isRunning())
         m_ui->readAutomaticLocationUpdateSettings();
 }
 
-void SituareEngine::loginProcessCancelled()
-{
-    qDebug() << __PRETTY_FUNCTION__;
-
-    m_ui->toggleProgressIndicator(false);
-    m_ui->updateItemVisibility();
-}
-
-void SituareEngine::logout()
+void SituareEngine::onLogout()
 {
     qDebug() << __PRETTY_FUNCTION__;
 
@@ -418,7 +382,8 @@ void SituareEngine::logout()
             m_ui, SIGNAL(clearUpdateLocationDialogData()));
     emit clearUpdateLocationDialogData();
 
-    m_facebookAuthenticator->clearAccountInformation(); // clear all
+    m_situareService->updateSession(""); // empty session string means logged out
+
     m_automaticUpdateFirstStart = true;
 }
 
@@ -467,13 +432,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;
@@ -481,24 +446,115 @@ void SituareEngine::requestAutomaticUpdateIfMoved(QPointF position)
     }
 
     if (m_automaticUpdateRequest && m_userMoved) {
-        requestUpdateLocation(tr("Automatic location update."));
+        requestUpdateLocation(tr("Automatic location update"));
         m_automaticUpdateRequest = false;
         m_userMoved = false;
     }
 }
 
-void SituareEngine::setFirstStartZoomLevel(QPointF latLonCoordinate, qreal accuracy)
+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__;
 
-    Q_UNUSED(latLonCoordinate);
-    Q_UNUSED(accuracy);
+    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_facebookAuthenticator->isLoggedIn())
+                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::signalsFromFacebookAuthenticator()
@@ -508,28 +564,32 @@ void SituareEngine::signalsFromFacebookAuthenticator()
     connect(m_facebookAuthenticator, SIGNAL(error(int, int)),
             this, SLOT(error(int, int)));
 
-    connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
-            m_situareService, SLOT(credentialsReady(FacebookCredentials)));
+    connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString, bool)),
+            m_situareService, SLOT(updateSession(QString)));
+
+    connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString, bool)),
+            this, SLOT(onLogin()));
 
-    connect(m_facebookAuthenticator, SIGNAL(credentialsReady(FacebookCredentials)),
-            this, SLOT(loginOk()));
+    connect(m_facebookAuthenticator, SIGNAL(loggedOut()), this, SLOT(onLogout()));
+}
 
-    connect(m_facebookAuthenticator, SIGNAL(newLoginRequest()),
-            m_ui, SLOT(startLoginProcess()));
+void SituareEngine::signalsFromGeocodingService()
+{
+    qDebug() << __PRETTY_FUNCTION__;
 
-    connect(m_facebookAuthenticator, SIGNAL(saveCookiesRequest()),
-            m_ui, SLOT(saveCookies()));
+    connect(m_geocodingService, SIGNAL(locationDataParsed(const QList<Location>&)),
+            m_ui, SIGNAL(locationDataParsed(const QList<Location>&)));
 
-    connect(m_facebookAuthenticator, SIGNAL(loginUsingCookies()),
-            m_ui, SLOT(loginUsingCookies()));
+    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()));
@@ -545,21 +605,12 @@ void SituareEngine::signalsFromMainWindow()
     connect(m_ui, SIGNAL(error(int, int)),
             this, SLOT(error(int, int)));
 
-    connect(m_ui, SIGNAL(fetchUsernameFromSettings()),
-            this, SLOT(fetchUsernameFromSettings()));
-
     connect(m_ui, SIGNAL(loginActionPressed()),
             this, SLOT(loginActionPressed()));
 
-    connect(m_ui, SIGNAL(saveUsername(QString)),
-            m_facebookAuthenticator, SLOT(saveUsername(QString)));
-
-    connect(m_ui, SIGNAL(updateCredentials(QUrl)),
-            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)));
@@ -575,15 +626,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)));
-
-    //signals from dialogs
-    connect(m_ui, SIGNAL(cancelLoginProcess()),
-            this, SLOT(loginProcessCancelled()));
+            this, SLOT(setGPS(bool)));
 
     connect(m_ui, SIGNAL(requestReverseGeo()),
             this, SLOT(requestAddress()));
@@ -598,12 +642,43 @@ void SituareEngine::signalsFromMainWindow()
     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)));
+
+    // routing signal from friend list tab & search location tab
+    connect(m_ui, SIGNAL(routeTo(const GeoCoordinate&)),
+            this, SLOT(routeTo(const GeoCoordinate&)));
+
+    // 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 friend list tab
-    connect(m_ui, SIGNAL(findFriend(QPointF)),
-            m_mapEngine, SLOT(centerToCoordinates(QPointF)));
+    // 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 location dialog
+    connect(m_ui, SIGNAL(searchForLocation(QString)),
+            this, SLOT(locationSearch(QString)));
+
+    // signal from friend list panel
+    connect(m_ui, SIGNAL(requestContactDialog(const QString &)),
+            this, SLOT(showContactDialog(const QString &)));
 }
 
 void SituareEngine::signalsFromMapEngine()
@@ -613,8 +688,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)));
@@ -633,6 +708,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()
@@ -642,8 +737,8 @@ void SituareEngine::signalsFromSituareService()
     connect(m_situareService, SIGNAL(error(int, int)),
             this, SLOT(error(int, int)));
 
-    connect(m_situareService, SIGNAL(error(int, int)),
-            m_ui, SIGNAL(messageSendingFailed(int)));
+    connect(m_situareService, SIGNAL(imageReady(User*)),
+            this, SLOT(imageReady(User*)));
 
     connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
             m_ui, SIGNAL(reverseGeoReady(QString)));
@@ -666,6 +761,13 @@ void SituareEngine::startAutomaticUpdate()
     m_automaticUpdateRequest = true;
 }
 
+void SituareEngine::topmostWindowChanged(bool isMainWindow)
+{
+    qDebug() << __PRETTY_FUNCTION__;
+
+    setPowerSaving(!isMainWindow);
+}
+
 void SituareEngine::updateWasSuccessful()
 {
     qDebug() << __PRETTY_FUNCTION__;
@@ -681,7 +783,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);