Locations editing made possible
[ptas] / zouba / src / gpscontroller.cpp
1 #include "gpscontroller.h"
2 #include "locations.h"
3
4 #include <QObject>
5 #include <QGeoPositionInfo>
6 #include <QGeoPositionInfoSource>
7 #include <QDebug>
8
9 GpsController::GpsController(bool started) :
10         m_gps(QGeoPositionInfoSource::createDefaultSource(this)),
11         m_started(started)
12 {   
13     m_gps->setUpdateInterval(20000);
14     connect(m_gps, SIGNAL(positionUpdated(QGeoPositionInfo)),
15             this, SLOT(updateLocation(QGeoPositionInfo)));
16     connect(m_gps, SIGNAL(updateTimeout()),
17             this, SLOT(timeoutRequested()));
18     if (m_started) m_gps->startUpdates();
19 }
20
21 GpsController::~GpsController()
22 {
23     delete m_gps;
24 }
25
26 void GpsController::useGPS( bool use)
27 {
28     if (use) m_gps->startUpdates();
29     else m_gps->stopUpdates();
30 }
31
32 bool GpsController::isStarted() const
33 {
34     return m_started;
35 }
36
37 QGeoPositionInfoSource *GpsController::gps() const
38 {
39     return m_gps;
40 }
41
42 void GpsController::updateLocation( QGeoPositionInfo positionInfo )
43 {
44     qDebug() << "GPS location update received";
45     Locations *locations = Locations::GetInstance();
46
47     //DEBUG
48     /*if (locations == 0)
49         qDebug() << "Null locations received from getInstance";
50     else
51         qDebug() << "Locations is not null";
52     Location* gpsLoc = locations->getGpsLocation();
53     if (gpsLoc == 0)
54         qDebug() << "Null gpsLocation received from locations";
55     else
56         qDebug() << "GPS location is not null.";*/
57     //DEBUG ENDED
58
59     locations->getGpsLocation()->setLocation(positionInfo);
60     //emit(gpsLocationChanged(m_location));
61 }
62
63 void GpsController::timeoutRequested()
64 {
65     qDebug() << "GPS sent timeout requested.";
66 }