Added dialogs to change home and work locations.
[ptas] / zouba / gpscontroller.cpp
index 932c0cf..c8226ac 100644 (file)
@@ -7,37 +7,42 @@
 
 QTM_USE_NAMESPACE
 
-GpsController::~GpsController()
-{
-  qDebug() << __PRETTY_FUNCTION__;
-  delete m_location;
-  m_location = 0;
-}
-
 GpsController::GpsController() :
-  m_location( QGeoPositionInfoSource::createDefaultSource(this) )
+  m_location( QGeoPositionInfoSource::createDefaultSource(this) ),
+  currentLocation(0)
 {
-  qDebug() << __PRETTY_FUNCTION__;
   m_location->setUpdateInterval( 1*60*1000 );
 
   connect( 
       m_location, SIGNAL( positionUpdated( QGeoPositionInfo ) ),
       this, SLOT( updateLocation( QGeoPositionInfo ) )
-      );
+  );
 
-  m_location->stopUpdates();
+  m_location->startUpdates();
+}
+
+GpsController::~GpsController()
+{
+  delete m_location;
+  m_location = 0;
+  delete currentLocation;
+  currentLocation = 0;
 }
 
 void GpsController::updateLocation( QGeoPositionInfo positionInfo )
 {
-  qDebug() << __PRETTY_FUNCTION__;
-  Location newLocation( positionInfo );
+  qDebug() << "new GPS position";
+
+  delete currentLocation;
+  currentLocation = new Location( positionInfo );
 
-  emit locationChanged( newLocation );
+  qDebug() << "from location changed";
+  emit locationChanged( currentLocation );
 }
 
 void GpsController::startGps()
 {
-  qDebug() << __PRETTY_FUNCTION__;
-  m_location->startUpdates();
+  if ( currentLocation != 0 ) {
+    emit locationChanged( currentLocation );
+  }
 }