c65414607167824585749183734ee0f67b967dbc
[ptas] / zouba / src / gpscontroller_p.cpp
1 #include "gpscontroller_p.h"
2
3 #include "location.h"
4
5 #include <QObject>
6 #include <QGeoPositionInfo>
7 #include <QGeoPositionInfoSource>
8 #include <QDebug>
9
10 QTM_USE_NAMESPACE
11
12 GpsControllerPrivate::GpsControllerPrivate() :
13   m_gps(0),
14   m_currentLocation(0),
15   m_useFakeLocation(false)
16 {
17 }
18
19 GpsControllerPrivate::~GpsControllerPrivate()
20 {
21   delete m_gps;
22   m_gps = 0;
23   delete m_currentLocation;
24   m_currentLocation = 0;
25 }
26
27 void GpsControllerPrivate::init()
28 {
29   m_gps = QGeoPositionInfoSource::createDefaultSource(this);
30   connect(
31       m_gps, SIGNAL( positionUpdated( QGeoPositionInfo ) ),
32       this, SLOT( updateLocation( QGeoPositionInfo ) )
33   );
34 }
35
36 void GpsControllerPrivate::startGps()
37 {
38   m_gps->startUpdates();
39 }
40
41 void GpsControllerPrivate::stopGps()
42 {
43   m_gps->stopUpdates();
44 }
45
46 QGeoPositionInfoSource *GpsControllerPrivate::gps()
47 {
48   return m_gps;
49 }
50
51 void GpsControllerPrivate::setGps( QGeoPositionInfoSource *gps )
52 {
53   m_gps = gps;
54 }
55
56 Location *GpsControllerPrivate::currentLocation()
57 {
58   return m_currentLocation;
59 }
60
61 void GpsControllerPrivate::setCurrentLocation( Location *location )
62 {
63   if ( m_currentLocation && m_currentLocation->label() == "livegps" ) {
64     delete m_currentLocation;
65     m_currentLocation=0;
66   }
67   m_currentLocation = location;
68 }
69
70 bool GpsControllerPrivate::useFakeLocation()
71 {
72   return m_useFakeLocation;
73 }
74
75 void GpsControllerPrivate::setUseFakeLocation( bool useFake )
76 {
77   // delete previous GPS if it was live and we're switching to fake
78   if ( m_currentLocation && m_currentLocation->label() == "livegps" ) {
79     delete m_currentLocation;
80     m_currentLocation = 0;
81   }
82   m_useFakeLocation = useFake;
83 }
84
85 void GpsControllerPrivate::updateLocation( QGeoPositionInfo positionInfo )
86 {
87   if ( m_currentLocation && m_currentLocation->label() == "livegps" ) {
88     delete m_currentLocation;
89   }
90   m_currentLocation = new Location( positionInfo, "livegps" );
91 }
92