Changes: Changed the route table to a layout of buttons and tamed the layouts a bit.
[ptas] / zouba / src / gpscontroller.cpp
index e4de9b4..32568b0 100644 (file)
@@ -27,23 +27,36 @@ GpsController::~GpsController()
 
 void GpsController::getGps()
 {
-  if ( q->currentLocation() != 0 ) {
-    emit locationChanged( q->currentLocation() );
+  Location *location;
+
+  if ( q->useFakeLocation() ) {
+    location = q->fakeLocation();
+  } else {
+    location = q->liveLocation();
   }
+
+  emit locationChanged( location );
 }
 
 void GpsController::useLiveGps()
 {
   q->setUseFakeLocation( false );
-  q->setCurrentLocation( new Location( "livegps" ) );
   q->startGps();
+  emit locationChanged( q->liveLocation() );
 }
 
-void GpsController::useFakeGps( Location *fakeLocation )
+void GpsController::useFakeGps( const QString &fakeLocationLabel )
 {
-  qDebug() << "using fake gps (" << fakeLocation->label() << ")";
-  q->stopGps();
-  q->setUseFakeLocation( true );
-  q->setCurrentLocation( fakeLocation );
-  emit locationChanged( q->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 );
+  }
 }