#include "application.h"
#include "common.h"
-#include "error.h"
+#include "contactmanager.h"
+#include "../error.h"
#include "facebookservice/facebookauthentication.h"
#include "gps/gpsposition.h"
#include "map/mapengine.h"
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_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!
m_mapEngine->init();
m_ui->show();
- m_facebookAuthenticator->start();
-
m_gps->setMode(GPSPosition::Default);
initializeGpsAndAutocentering();
m_mce = new MCE(this);
connect(m_mce, SIGNAL(displayOff(bool)), this, SLOT(setPowerSaving(bool)));
+
+ m_contactManager = new ContactManager(this);
+ m_contactManager->requestContactGuids();
+
+ m_facebookAuthenticator->login();
}
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);
}
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);
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;
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);
qCritical() << __PRETTY_FUNCTION__ << "QNetworkReply::NetworkError: " << error;
else
qCritical() << __PRETTY_FUNCTION__ << "Unknown error: " << error;
-
break;
}
}
-void SituareEngine::fetchUsernameFromSettings()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- m_ui->setUsername(m_facebookAuthenticator->loadUsername());
-}
-
void SituareEngine::imageReady(User *user)
{
qDebug() << __PRETTY_FUNCTION__;
{
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);
{
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__;
m_ui->loggedIn(false);
-
- // signal to clear locationUpdateDialog's data
- connect(this, SIGNAL(clearUpdateLocationDialogData()),
- m_ui, SIGNAL(clearUpdateLocationDialogData()));
- emit clearUpdateLocationDialogData();
-
- m_facebookAuthenticator->clearAccountInformation(); // clear all
+ m_situareService->updateSession(""); // empty session string means logged out
m_automaticUpdateFirstStart = true;
}
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_gps->start();
m_gps->requestLastPosition();
- if(m_ui->loginState())
+ if(m_facebookAuthenticator->isLoggedIn())
m_ui->readAutomaticLocationUpdateSettings();
}
else if (!enabled && m_gps->isRunning()) {
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()
{
qDebug() << __PRETTY_FUNCTION__;
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(credentialsReady(FacebookCredentials)),
- this, SLOT(loginOk()));
-
- connect(m_facebookAuthenticator, SIGNAL(newLoginRequest()),
- m_ui, SLOT(startLoginProcess()));
+ connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString, bool)),
+ m_situareService, SLOT(updateSession(QString)));
- connect(m_facebookAuthenticator, SIGNAL(saveCookiesRequest()),
- m_ui, SLOT(saveCookies()));
+ connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString, bool)),
+ this, SLOT(onLogin()));
- connect(m_facebookAuthenticator, SIGNAL(loginUsingCookies()),
- m_ui, SLOT(loginUsingCookies()));
+ connect(m_facebookAuthenticator, SIGNAL(loggedOut()), this, SLOT(onLogout()));
}
void SituareEngine::signalsFromGeocodingService()
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()
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(SceneCoordinate)),
m_mapEngine, SLOT(setCenterPosition(SceneCoordinate)));
connect(m_ui, SIGNAL(gpsTriggered(bool)),
this, SLOT(setGPS(bool)));
- //signals from dialogs
- connect(m_ui, SIGNAL(cancelLoginProcess()),
- this, SLOT(loginProcessCancelled()));
-
connect(m_ui, SIGNAL(requestReverseGeo()),
this, SLOT(requestAddress()));
- connect(m_ui, SIGNAL(statusUpdate(QString,bool)),
+ connect(m_ui, SIGNAL(locationUpdate(QString,bool)),
this, SLOT(requestUpdateLocation(QString,bool)));
connect(m_ui, SIGNAL(enableAutomaticLocationUpdate(bool, int)),
connect(m_ui, SIGNAL(centerToCoordinates(GeoCoordinate)),
m_mapEngine, SLOT(centerToCoordinates(GeoCoordinate)));
- // signals from routing tab
+ // 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&)));
- // signals from distence indicator button
+ 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(searchForLocation(QString)),
- this, SLOT(locationSearch(QString)));
-
connect(m_ui, SIGNAL(draggingModeTriggered()),
this, SLOT(draggingModeTriggered()));
- connect(m_ui, SIGNAL(routeTo(const GeoCoordinate&)),
- this, SLOT(routeTo(const GeoCoordinate&)));
+ // 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()
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()
this, SLOT(updateWasSuccessful()));
connect(m_situareService, SIGNAL(updateWasSuccessful()),
- m_ui, SIGNAL(clearUpdateLocationDialogData()));
+ m_ui, SIGNAL(updateWasSuccessful()));
}
void SituareEngine::startAutomaticUpdate()
qDebug() << __PRETTY_FUNCTION__;
m_ui->toggleProgressIndicator(false);
- m_ui->showPanels();
emit userLocationReady(user);
emit friendsLocationsReady(friendsList);