#include "map/mapengine.h"
#include "situareservice/situareservice.h"
#include "ui/mainwindow.h"
+#include "mce.h"
#include <cmath>
#include "engine.h"
+
const QString SETTINGS_GPS_ENABLED = "GPS_ENABLED"; ///< GPS setting
const QString SETTINGS_AUTO_CENTERING_ENABLED = "AUTO_CENTERING_ENABLED";///< Auto centering setting
const int DEFAULT_ZOOM_LEVEL_WHEN_GPS_IS_AVAILABLE = 12; ///< Default zoom level when GPS available
: QObject(parent),
m_autoCenteringEnabled(false),
m_automaticUpdateFirstStart(true),
- m_loggedIn(false),
+ m_automaticUpdateRequest(false),
m_userMoved(false),
- m_automaticUpdateEnabled(false),
m_automaticUpdateIntervalTimer(0),
m_lastUpdatedGPSPosition(QPointF())
{
qDebug() << __PRETTY_FUNCTION__;
m_ui = new MainWindow;
- m_ui->updateItemVisibility(m_loggedIn);
+ m_ui->updateItemVisibility();
// build MapEngine
m_mapEngine = new MapEngine(this);
m_automaticUpdateIntervalTimer = new QTimer(this);
connect(m_automaticUpdateIntervalTimer, SIGNAL(timeout()),
- this, SLOT(automaticUpdateIntervalTimerTimeout()));
+ this, SLOT(startAutomaticUpdate()));
// signals connected, now it's time to show the main window
// but init the MapEngine before so starting location is set
m_gps->setMode(GPSPosition::Default);
initializeGpsAndAutocentering();
+
+ m_mce = new MCE(this);
+ connect(m_mce, SIGNAL(displayStateChanged(bool)), this, SLOT(displayStateChanged(bool)));
}
SituareEngine::~SituareEngine()
settings.setValue(SETTINGS_AUTO_CENTERING_ENABLED, m_autoCenteringEnabled);
}
-void SituareEngine::automaticUpdateIntervalTimerTimeout()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- if (m_gps->isRunning() && m_userMoved) {
- requestUpdateLocation();
- m_userMoved = false;
- }
-}
-
void SituareEngine::changeAutoCenteringSetting(bool enabled)
{
qDebug() << __PRETTY_FUNCTION__;
m_ui->buildInformationBox(tr("Auto centering disabled"));
}
+void SituareEngine::displayStateChanged(bool enabled)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_gps->enablePowerSave(!enabled);
+
+ if (m_autoCenteringEnabled)
+ enableAutoCentering(enabled);
+}
+
void SituareEngine::enableAutoCentering(bool enabled)
{
qDebug() << __PRETTY_FUNCTION__;
{
qDebug() << __PRETTY_FUNCTION__;
+ m_ui->setOwnLocationCrosshairVisibility(!enabled);
+
if (m_gps->isInitialized()) {
m_ui->setGPSButtonEnabled(enabled);
m_mapEngine->setGPSEnabled(enabled);
enableAutoCentering(m_autoCenteringEnabled);
m_gps->requestLastPosition();
- if (!m_automaticUpdateEnabled && m_loggedIn)
- m_ui->requestAutomaticLocationUpdateSettings();
+ if(m_ui->loginState())
+ m_ui->readAutomaticLocationUpdateSettings();
}
else if (!enabled && m_gps->isRunning()) {
m_gps->stop();
{
qDebug() << __PRETTY_FUNCTION__;
- m_automaticUpdateEnabled = enabled;
-
//Show automatic update confirmation dialog
- if (m_automaticUpdateFirstStart && m_gps->isRunning() && m_automaticUpdateEnabled) {
+ if (m_automaticUpdateFirstStart && m_gps->isRunning() && enabled) {
m_ui->showEnableAutomaticUpdateLocationDialog(
tr("Do you want to enable automatic location update with %1 min update interval?")
.arg(updateIntervalMsecs/1000/60));
m_automaticUpdateFirstStart = false;
} else {
- if (m_automaticUpdateEnabled && m_gps->isRunning()) {
+ if (enabled && m_gps->isRunning()) {
m_ui->buildInformationBox(tr("Automatic location update enabled"));
if (updateIntervalMsecs < MIN_UPDATE_INTERVAL_MSECS)
m_automaticUpdateIntervalTimer->setInterval(MIN_UPDATE_INTERVAL_MSECS);
else
m_automaticUpdateIntervalTimer->setInterval(updateIntervalMsecs);
+ connect(m_gps, SIGNAL(position(QPointF,qreal)),
+ this, SLOT(requestAutomaticUpdateIfMoved(QPointF)));
+
m_automaticUpdateIntervalTimer->start();
} else {
+ disconnect(m_gps, SIGNAL(position(QPointF,qreal)),
+ this, SLOT(requestAutomaticUpdateIfMoved(QPointF)));
+
m_automaticUpdateIntervalTimer->stop();
}
}
switch(error)
{
case QNetworkReply::ConnectionRefusedError:
+ m_ui->toggleProgressIndicator(false);
m_ui->buildInformationBox(tr("Connection refused by the server"), true);
break;
case QNetworkReply::RemoteHostClosedError:
+ m_ui->toggleProgressIndicator(false);
m_ui->buildInformationBox(tr("Connection closed by the server"), true);
break;
case QNetworkReply::HostNotFoundError:
+ m_ui->toggleProgressIndicator(false);
m_ui->buildInformationBox(tr("Remote server not found"), true);
break;
case QNetworkReply::TimeoutError:
+ m_ui->toggleProgressIndicator(false);
m_ui->buildInformationBox(tr("Connection timed out"), true);
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();
break;
case SituareError::UPDATE_FAILED:
+ m_ui->toggleProgressIndicator(false);
m_ui->buildInformationBox(tr("Update failed, please try again"), true);
break;
case SituareError::DATA_RETRIEVAL_FAILED:
+ m_ui->toggleProgressIndicator(false);
m_ui->buildInformationBox(tr("Data retrieval failed, please try again"), true);
break;
case SituareError::ADDRESS_RETRIEVAL_FAILED:
m_ui->buildInformationBox(tr("GPS initialization failed"), true);
break;
case SituareError::UNKNOWN_REPLY:
+ m_ui->toggleProgressIndicator(false);
m_ui->buildInformationBox(tr("Unknown server response"), true);
break;
+ case SituareError::INVALID_JSON:
+ m_ui->buildInformationBox(tr("Malformatted reply from server"), true);
+ m_ui->loggedIn(false);
+ m_facebookAuthenticator->clearAccountInformation(false); // clean all
+ break;
default:
+ m_ui->toggleProgressIndicator(false);
qCritical() << "QNetworkReply::NetworkError :" << error;
break;
}
}
}
-bool SituareEngine::isUserMoved()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- return m_userMoved;
-}
-
void SituareEngine::loginActionPressed()
{
qDebug() << __PRETTY_FUNCTION__;
- if(m_loggedIn) {
+ if(m_ui->loginState()) {
logout();
m_situareService->clearUserData();
- }
- else {
+ } else {
m_facebookAuthenticator->start();
}
}
{
qDebug() << __PRETTY_FUNCTION__;
- m_loggedIn = true;
- m_ui->loggedIn(m_loggedIn);
+ m_ui->loggedIn(true);
m_ui->show();
m_situareService->fetchLocations(); // request user locations
if (m_gps->isRunning())
- m_ui->requestAutomaticLocationUpdateSettings();
+ m_ui->readAutomaticLocationUpdateSettings();
}
void SituareEngine::loginProcessCancelled()
qDebug() << __PRETTY_FUNCTION__;
m_ui->toggleProgressIndicator(false);
- m_ui->updateItemVisibility(m_loggedIn);
+ m_ui->updateItemVisibility();
}
void SituareEngine::logout()
{
qDebug() << __PRETTY_FUNCTION__;
- m_loggedIn = false;
- m_ui->loggedIn(m_loggedIn);
+ 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_automaticUpdateEnabled = false;
m_automaticUpdateFirstStart = true;
}
m_situareService->updateLocation(m_mapEngine->centerGeoCoordinate(), status, publish);
}
-void SituareEngine::saveGPSPosition(QPointF position)
+void SituareEngine::requestAutomaticUpdateIfMoved(QPointF position)
{
qDebug() << __PRETTY_FUNCTION__;
m_lastUpdatedGPSPosition = position;
m_userMoved = true;
}
+
+ if (m_automaticUpdateRequest && m_userMoved) {
+ requestUpdateLocation(tr("Automatic location update."));
+ m_automaticUpdateRequest = false;
+ m_userMoved = false;
+ }
}
void SituareEngine::setFirstStartZoomLevel(QPointF latLonCoordinate, qreal accuracy)
connect(m_facebookAuthenticator, SIGNAL(newLoginRequest()),
m_ui, SLOT(startLoginProcess()));
- connect(m_facebookAuthenticator, SIGNAL(loginFailure()),
- m_ui, SLOT(loginFailed()));
-
connect(m_facebookAuthenticator, SIGNAL(saveCookiesRequest()),
m_ui, SLOT(saveCookies()));
connect(m_gps, SIGNAL(error(int)),
this, SLOT(error(int)));
-
- connect(m_gps, SIGNAL(position(QPointF,qreal)),
- this, SLOT(saveGPSPosition(QPointF)));
}
void SituareEngine::signalsFromMainWindow()
connect(m_situareService, SIGNAL(error(int)),
this, SLOT(error(int)));
+ connect(m_situareService, SIGNAL(error(int)),
+ m_ui, SIGNAL(messageSendingFailed(int)));
+
connect(m_situareService, SIGNAL(reverseGeoReady(QString)),
m_ui, SIGNAL(reverseGeoReady(QString)));
this, SLOT(updateWasSuccessful()));
connect(m_situareService, SIGNAL(updateWasSuccessful()),
- m_ui, SIGNAL(updateWasSuccessful()));
+ m_ui, SIGNAL(clearUpdateLocationDialogData()));
+}
- connect(m_situareService, SIGNAL(error(int)),
- m_ui, SIGNAL(messageSendingFailed(int)));
+void SituareEngine::startAutomaticUpdate()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_gps->requestUpdate();
+ m_automaticUpdateRequest = true;
}
void SituareEngine::updateWasSuccessful()
qDebug() << __PRETTY_FUNCTION__;
m_ui->toggleProgressIndicator(false);
+ m_ui->showPanels();
emit userLocationReady(user);
emit friendsLocationsReady(friendsList);