#include "map/mapengine.h"
#include "situareservice/situareservice.h"
#include "ui/mainwindow.h"
+#include "mce.h"
#include <cmath>
#include "engine.h"
: QObject(parent),
m_autoCenteringEnabled(false),
m_automaticUpdateFirstStart(true),
+ m_automaticUpdateRequest(false),
m_userMoved(false),
m_automaticUpdateIntervalTimer(0),
m_lastUpdatedGPSPosition(QPointF())
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__;
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();
}
}
}
}
-bool SituareEngine::isUserMoved()
-{
- qDebug() << __PRETTY_FUNCTION__;
-
- return m_userMoved;
-}
-
void SituareEngine::loginActionPressed()
{
qDebug() << __PRETTY_FUNCTION__;
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_gps, SIGNAL(error(int, int)),
this, SLOT(error(int, int)));
-
- connect(m_gps, SIGNAL(position(QPointF,qreal)),
- this, SLOT(saveGPSPosition(QPointF)));
}
void SituareEngine::signalsFromMainWindow()
m_ui, SIGNAL(clearUpdateLocationDialogData()));
}
+void SituareEngine::startAutomaticUpdate()
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ m_gps->requestUpdate();
+ m_automaticUpdateRequest = true;
+}
+
void SituareEngine::updateWasSuccessful()
{
qDebug() << __PRETTY_FUNCTION__;