#include "common.h"
#include "contactmanager.h"
#include "../error.h"
-#include "ui/facebookloginbrowser.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!
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);
{
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);
m_geocodingService->requestLocation(location);
}
-void SituareEngine::loggedIn()
-{
- qWarning() << __PRETTY_FUNCTION__;
-
- m_ui->destroyFacebookLoginBrowser();
-
- loginOk();
-}
-
void SituareEngine::loginActionPressed()
{
qDebug() << __PRETTY_FUNCTION__;
- if (m_networkAccessManager->isConnected()) {
- if(m_ui->loginState()) {
- logout();
- m_situareService->clearUserData();
- } else {
- m_facebookAuthenticator->login();
- }
- }
- 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()
{
- /// @ OLD CODE, REFACTOR! loggedIn -> FB authenticator etc.
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, SIGNAL(clearUpdateLocationDialogData()));
emit clearUpdateLocationDialogData();
- m_facebookAuthenticator->clearAccountInformation(); // clear all
+ m_situareService->updateSession(""); // empty session string means logged out
+
m_automaticUpdateFirstStart = true;
}
m_gps->start();
m_gps->requestLastPosition();
- if(m_ui->loginState())
+ if(m_facebookAuthenticator->isLoggedIn())
m_ui->readAutomaticLocationUpdateSettings();
}
else if (!enabled && m_gps->isRunning()) {
connect(m_facebookAuthenticator, SIGNAL(error(int, int)),
this, SLOT(error(int, int)));
- connect(m_facebookAuthenticator, SIGNAL(buildLoginBrowser()),
- m_ui, SLOT(buildFacebookLoginBrowser()));
-
- connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString)),
+ connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString, bool)),
m_situareService, SLOT(updateSession(QString)));
- connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString)),
- this, SLOT(loggedIn()));
+ connect(m_facebookAuthenticator, SIGNAL(loggedIn(QString, bool)),
+ this, SLOT(onLogin()));
+
+ connect(m_facebookAuthenticator, SIGNAL(loggedOut()), this, SLOT(onLogout()));
}
void SituareEngine::signalsFromGeocodingService()
connect(m_ui, SIGNAL(loginActionPressed()),
this, SLOT(loginActionPressed()));
- connect(m_ui, SIGNAL(loginBrowserCreated(FacebookLoginBrowser*)),
- m_facebookAuthenticator, SLOT(setBrowser(FacebookLoginBrowser*)));
-
// 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()));