Changes: gps controller uses labels for fake gps
authorMax Waterman <david.waterman@nokia.com>
Tue, 20 Apr 2010 04:30:49 +0000 (07:30 +0300)
committerMax Waterman <david.waterman@nokia.com>
Tue, 20 Apr 2010 04:30:49 +0000 (07:30 +0300)
12 files changed:
zouba/debian/changelog
zouba/debian/files
zouba/src/gpscontroller.cpp
zouba/src/gpscontroller.h
zouba/src/gpscontroller_p.cpp
zouba/src/gpscontroller_p.h
zouba/src/location.cpp
zouba/src/location.h
zouba/src/main.cpp
zouba/src/ui.cpp
zouba/src/ui.h
zouba/tests/ut_gpscontroller/ut_gpscontroller

index 81a5e73..de6c4dc 100644 (file)
@@ -1,3 +1,9 @@
+zouba (0.7) unstable; urgency=low
+
+  * Changed gps controller to use labels for fake gps instead of a new Location instance.
+
+ -- Max Waterman <davidmaxwaterman@fastmail.co.uk>  Mon, 20 Apr 2010 06:27:00 +0200
+
 zouba (0.6) unstable; urgency=low
 
   * Changed layout in preparation for multiple routes
index 7f196be..8ea7a7a 100644 (file)
@@ -1 +1 @@
-zouba_0.6_armel.deb user/navigation extra
+zouba_0.7_armel.deb user/navigation extra
index e4de9b4..abecb2d 100644 (file)
@@ -1,6 +1,8 @@
 #include "gpscontroller.h"
 #include "gpscontroller_p.h"
 
+#include "locations.h"
+
 #include <QObject>
 #include <QGeoPositionInfo>
 #include <QGeoPositionInfoSource>
@@ -27,23 +29,38 @@ GpsController::~GpsController()
 
 void GpsController::getGps()
 {
-  if ( q->currentLocation() != 0 ) {
-    emit locationChanged( q->currentLocation() );
+  Location *location;
+
+  if ( q->useFakeLocation() ) {
+    Locations *locations = Locations::instance();
+    location = locations->location( q->fakeLocationLabel() );
+  } 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 << ")";
+
+  Locations *locations = Locations::instance();
+  Location  *fakeLocation = locations->location( fakeLocationLabel );
+
+  if ( fakeLocation == 0 ) {
+    qDebug() << "invalid fake location label; cannot use fake location";
+  } else {
+    q->stopGps();
+    q->setUseFakeLocation( true );
+    q->setFakeLocationLabel( fakeLocationLabel );
+    emit locationChanged( fakeLocation );
+  }
 }
index 886ffd5..438b3f8 100644 (file)
@@ -23,7 +23,7 @@ public:
 
 public Q_SLOTS:
   void getGps();
-  void useFakeGps( Location *fakeLocation );
+  void useFakeGps( const QString &fakeLocationLabel );
   void useLiveGps();
 
 Q_SIGNALS:
index c654146..ff60837 100644 (file)
@@ -11,7 +11,8 @@ QTM_USE_NAMESPACE
 
 GpsControllerPrivate::GpsControllerPrivate() :
   m_gps(0),
-  m_currentLocation(0),
+  m_liveLocation( new Location( "livegps" ) ),
+  m_fakeLocationLabel(),
   m_useFakeLocation(false)
 {
 }
@@ -20,8 +21,8 @@ GpsControllerPrivate::~GpsControllerPrivate()
 {
   delete m_gps;
   m_gps = 0;
-  delete m_currentLocation;
-  m_currentLocation = 0;
+  delete m_liveLocation;
+  m_liveLocation = 0;
 }
 
 void GpsControllerPrivate::init()
@@ -53,18 +54,19 @@ void GpsControllerPrivate::setGps( QGeoPositionInfoSource *gps )
   m_gps = gps;
 }
 
-Location *GpsControllerPrivate::currentLocation()
+Location *GpsControllerPrivate::liveLocation()
 {
-  return m_currentLocation;
+  return m_liveLocation;
 }
 
-void GpsControllerPrivate::setCurrentLocation( Location *location )
+QString GpsControllerPrivate::fakeLocationLabel()
 {
-  if ( m_currentLocation && m_currentLocation->label() == "livegps" ) {
-    delete m_currentLocation;
-    m_currentLocation=0;
-  }
-  m_currentLocation = location;
+  return m_fakeLocationLabel;
+}
+
+void GpsControllerPrivate::setFakeLocationLabel( const QString &label )
+{
+  m_fakeLocationLabel = label;
 }
 
 bool GpsControllerPrivate::useFakeLocation()
@@ -74,19 +76,11 @@ bool GpsControllerPrivate::useFakeLocation()
 
 void GpsControllerPrivate::setUseFakeLocation( bool useFake )
 {
-  // delete previous GPS if it was live and we're switching to fake
-  if ( m_currentLocation && m_currentLocation->label() == "livegps" ) {
-    delete m_currentLocation;
-    m_currentLocation = 0;
-  }
   m_useFakeLocation = useFake;
 }
 
 void GpsControllerPrivate::updateLocation( QGeoPositionInfo positionInfo )
 {
-  if ( m_currentLocation && m_currentLocation->label() == "livegps" ) {
-    delete m_currentLocation;
-  }
-  m_currentLocation = new Location( positionInfo, "livegps" );
+  m_liveLocation->setLocation( positionInfo );
 }
 
index 4a38216..8958d90 100644 (file)
@@ -21,19 +21,21 @@ public:
     virtual void stopGps();
 
     virtual void setGps( QGeoPositionInfoSource *gps );
-    virtual void setCurrentLocation( Location *location );
+    virtual void setFakeLocationLabel( const QString &label );
     virtual void setUseFakeLocation( bool useFake );
 
     virtual QGeoPositionInfoSource *gps();
-    virtual Location *currentLocation();
-    virtual bool useFakeLocation();
+    virtual Location               *liveLocation();
+    virtual QString                 fakeLocationLabel();
+    virtual bool                    useFakeLocation();
 
 private Q_SLOTS:
     virtual void updateLocation( QGeoPositionInfo positionInfo );
 
 private:
     QGeoPositionInfoSource *m_gps;
-    Location               *m_currentLocation;
+    Location               *m_liveLocation;
+    QString                 m_fakeLocationLabel;
     bool                    m_useFakeLocation;
 };
 
index 90f71c4..95f7c8a 100644 (file)
@@ -44,7 +44,11 @@ Location::Location( const QGeoPositionInfo &positionInfo, const QString &label )
   q( new LocationPrivate( label ) ),
   manager(0)
 {
-  qDebug() << "Location::Location( QGeoPositionInfo, label=" << label << " )";
+  setLocation( positionInfo );
+}
+
+void Location::setLocation( const QGeoPositionInfo &positionInfo )
+{
   qreal latitude = positionInfo.coordinate().latitude();
   qreal longitude = positionInfo.coordinate().longitude();
 
index 30c1aea..ae501c1 100644 (file)
@@ -29,6 +29,8 @@ public:
 
   QString y() const;
 
+  void setLocation( const QGeoPositionInfo &positionInfo );
+
   void setAddress( const QString &address ) const;
   QString address() const;
 
@@ -47,6 +49,7 @@ private Q_SLOTS:
   void replyFinished( QNetworkReply * reply );
 
 private:
+
   LocationPrivate *q;
   QNetworkAccessManager *manager;
 
index 5361a10..ffe72e3 100644 (file)
@@ -15,7 +15,7 @@
 
 int main(int argc, char *argv[] )
 {
-  qInstallMsgHandler( messageHandler );
+  //qInstallMsgHandler( messageHandler );
   QApplication app(argc, argv);
 
   QMainWindow *mainWindow = new QMainWindow;
@@ -47,8 +47,8 @@ int main(int argc, char *argv[] )
     );
 
   QObject::connect(
-      ui, SIGNAL( fakeGpsPressed( Location* ) ),
-      gpsController, SLOT( useFakeGps( Location* ) )
+      ui, SIGNAL( fakeGpsPressed( const QString & ) ),
+      gpsController, SLOT( useFakeGps( const QString & ) )
     );
 
   QObject::connect(
index 7b7c3e8..aea68b6 100644 (file)
@@ -27,13 +27,8 @@ Ui::Ui() :
   routeTable(0),
   usingFakeGps( false ),
   messagesShown( false ),
-  fakeLocation()
+  fakeLocationLabel( "work" )
 {
-  Locations *locations = Locations::instance();
-  Location *workLocation = locations->location( "work" );
-  fakeLocation = new Location();
-  *fakeLocation = *workLocation;
-  fakeLocation->setLabel( "fakegps" );
 }
 
 Ui::~Ui()
@@ -161,7 +156,7 @@ void Ui::toggleFakeGps()
 
 void Ui::useFakeGps()
 {
-  emit fakeGpsPressed( fakeLocation );
+  emit fakeGpsPressed( fakeLocationLabel );
   toggleFakeGpsAction->setText( "Use Live GPS" );
 }
 
index 318ceb1..c64d869 100644 (file)
@@ -46,12 +46,12 @@ public:
   QAction     *useLiveGpsAction;
   bool        usingFakeGps;
   bool        messagesShown;
-  Location    *fakeLocation;
+  QString     fakeLocationLabel;
 
 Q_SIGNALS:
   void homeAddressChanged( QString address );
   void workAddressChanged( QString address );
-  void fakeGpsPressed( Location * );
+  void fakeGpsPressed( const QString &fakeLocationLabel );
   void liveGpsPressed();
 
 private Q_SLOTS:
index 5ea456f..5a810c2 100755 (executable)
Binary files a/zouba/tests/ut_gpscontroller/ut_gpscontroller and b/zouba/tests/ut_gpscontroller/ut_gpscontroller differ