b031b6181c4d62a9f7575b73235cfbfe106911d6
[ptas] / zouba / gpscontroller.cpp
1 #include "gpscontroller.h"
2
3 #include <QObject>
4 #include <QGeoPositionInfo>
5 #include <QGeoPositionInfoSource>
6 #include <QDebug>
7
8 QTM_USE_NAMESPACE
9
10 GpsController::GpsController() :
11   m_location( QGeoPositionInfoSource::createDefaultSource(this) ),
12   updatesEnabled(false)
13 {
14   m_location->setUpdateInterval( 1*60*1000 );
15
16   connect( 
17       m_location, SIGNAL( positionUpdated( QGeoPositionInfo ) ),
18       this, SLOT( updateLocation( QGeoPositionInfo ) )
19   );
20
21   m_location->startUpdates();
22 }
23
24 GpsController::~GpsController()
25 {
26   delete m_location;
27   m_location = 0;
28 }
29
30 void GpsController::updateLocation( QGeoPositionInfo positionInfo )
31 {
32   qDebug() << "new GPS position";
33
34   Location newLocation( positionInfo );
35
36   if ( updatesEnabled ) {
37     qDebug() << "from location changed";
38     emit locationChanged( newLocation );
39     updatesEnabled = false;
40     m_location->setUpdateInterval( 1*60*1000 );
41   }
42 }
43
44 void GpsController::startGps()
45 {
46   updatesEnabled = true;
47   m_location->setUpdateInterval( 1 );
48 }