X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=zouba%2Fsrc%2Fgpscontroller.cpp;h=32568b02c4d17c703788a5a17233413a10e433b1;hb=c32bda4f974f19d525fa9bf430fd8f86fd7221f8;hp=3ca884713e7b11e86bfa4ed7df6c67cd8dfeb914;hpb=93c6dfe0c9a31745192d99e329acf791feb0b706;p=ptas diff --git a/zouba/src/gpscontroller.cpp b/zouba/src/gpscontroller.cpp index 3ca8847..32568b0 100644 --- a/zouba/src/gpscontroller.cpp +++ b/zouba/src/gpscontroller.cpp @@ -1,58 +1,62 @@ #include "gpscontroller.h" +#include "gpscontroller_p.h" #include #include #include #include -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 ); + } }