Added dialogs to change home and work locations.
[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   currentLocation(0)
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   delete currentLocation;
29   currentLocation = 0;
30 }
31
32 void GpsController::updateLocation( QGeoPositionInfo positionInfo )
33 {
34   qDebug() << "new GPS position";
35
36   delete currentLocation;
37   currentLocation = new Location( positionInfo );
38
39   qDebug() << "from location changed";
40   emit locationChanged( currentLocation );
41 }
42
43 void GpsController::startGps()
44 {
45   if ( currentLocation != 0 ) {
46     emit locationChanged( currentLocation );
47   }
48 }