Changes: Changed the route table to a layout of buttons and tamed the layouts a bit.
[ptas] / zouba / src / gpscontroller.cpp
index 3ca8847..32568b0 100644 (file)
@@ -1,58 +1,62 @@
 #include "gpscontroller.h"
+#include "gpscontroller_p.h"
 
 #include <QObject>
 #include <QGeoPositionInfo>
 #include <QGeoPositionInfoSource>
 #include <QDebug>
 
-QTM_USE_NAMESPACE
-
 GpsController::GpsController() :
-  m_location( QGeoPositionInfoSource::createDefaultSource(this) ),
-  m_currentLocation(0),
-  m_useFakeLocation(false)
+  q( new GpsControllerPrivate() )
 {
-  connect( 
-      m_location, SIGNAL( positionUpdated( QGeoPositionInfo ) ),
-      this, SLOT( updateLocation( QGeoPositionInfo ) )
-  );
-
-  m_location->startUpdates();
+  q->init();
+  q->startGps();
 }
 
-GpsController::~GpsController()
+GpsController::GpsController( GpsControllerPrivate *gpsControllerPrivate ) :
+  q( gpsControllerPrivate )
 {
-  delete m_location;
-  m_location = 0;
-  delete m_currentLocation;
-  m_currentLocation = 0;
+  q->init();
+  q->startGps();
 }
 
-void GpsController::updateLocation( QGeoPositionInfo positionInfo )
+GpsController::~GpsController()
 {
-  delete m_currentLocation;
-  m_currentLocation = new Location( positionInfo );
+  delete q;
 }
 
 void GpsController::getGps()
 {
-  if ( m_currentLocation != 0 ) {
-    emit locationChanged( m_currentLocation );
+  Location *location;
+
+  if ( q->useFakeLocation() ) {
+    location = q->fakeLocation();
+  } else {
+    location = q->liveLocation();
   }
+
+  emit locationChanged( location );
 }
 
 void GpsController::useLiveGps()
 {
-  m_location->startUpdates();
-  m_useFakeLocation=false;
-  m_currentLocation=0;
+  q->setUseFakeLocation( false );
+  q->startGps();
+  emit locationChanged( q->liveLocation() );
 }
 
-void GpsController::useFakeGps( Location *fakeLocation )
+void GpsController::useFakeGps( const QString &fakeLocationLabel )
 {
-  m_location->stopUpdates();
-  m_useFakeLocation=true;
-  delete m_currentLocation;
-  m_currentLocation = new Location( *fakeLocation );
-  emit locationChanged( m_currentLocation );
+  qDebug() << "using fake gps (" << fakeLocationLabel << ")";
+
+  q->setFakeLocationLabel( fakeLocationLabel );
+  Location  *fakeLocation = q->fakeLocation();
+
+  if ( fakeLocation == 0 ) {
+    qDebug() << "invalid fake location label; cannot use fake location";
+  } else {
+    q->stopGps();
+    q->setUseFakeLocation( true );
+    emit locationChanged( fakeLocation );
+  }
 }