Locations editing made possible
[ptas] / zouba / src / gpscontroller.cpp
index d924564..aab676d 100644 (file)
@@ -1,65 +1,66 @@
 #include "gpscontroller.h"
-#include "gpscontroller_p.h"
+#include "locations.h"
 
 #include <QObject>
 #include <QGeoPositionInfo>
 #include <QGeoPositionInfoSource>
 #include <QDebug>
 
-GpsController::GpsController() :
-  q( new GpsControllerPrivate() )
-{
-  q->init();
-  q->startGps();
+GpsController::GpsController(bool started) :
+        m_gps(QGeoPositionInfoSource::createDefaultSource(this)),
+        m_started(started)
+{   
+    m_gps->setUpdateInterval(20000);
+    connect(m_gps, SIGNAL(positionUpdated(QGeoPositionInfo)),
+            this, SLOT(updateLocation(QGeoPositionInfo)));
+    connect(m_gps, SIGNAL(updateTimeout()),
+            this, SLOT(timeoutRequested()));
+    if (m_started) m_gps->startUpdates();
 }
 
-GpsController::GpsController( GpsControllerPrivate *gpsControllerPrivate ) :
-  q( gpsControllerPrivate )
+GpsController::~GpsController()
 {
-  q->init();
-  q->startGps();
+    delete m_gps;
 }
 
-GpsController::~GpsController()
+void GpsController::useGPS( bool use)
 {
-  delete q;
+    if (use) m_gps->startUpdates();
+    else m_gps->stopUpdates();
 }
 
-void GpsController::getGps()
+bool GpsController::isStarted() const
 {
-  Location *location;
-  Location *previousLocation = q->mostRecentlyReportedLocation();
-
-  if ( q->useFakeLocation() ) {
-    location = q->fakeLocation();
-  } else {
-    location = q->liveLocation();
-  }
-
-  if ( location != previousLocation ) {
-    emit locationChanged( location );
-  }
+    return m_started;
 }
 
-void GpsController::useLiveGps()
+QGeoPositionInfoSource *GpsController::gps() const
 {
-  q->setUseFakeLocation( false );
-  q->startGps();
-  emit locationChanged( q->liveLocation() );
+    return m_gps;
 }
 
-void GpsController::useFakeGps( const QString &fakeLocationLabel )
+void GpsController::updateLocation( QGeoPositionInfo positionInfo )
 {
-  qDebug() << "using fake gps (" << fakeLocationLabel << ")";
+    qDebug() << "GPS location update received";
+    Locations *locations = Locations::GetInstance();
+
+    //DEBUG
+    /*if (locations == 0)
+        qDebug() << "Null locations received from getInstance";
+    else
+        qDebug() << "Locations is not null";
+    Location* gpsLoc = locations->getGpsLocation();
+    if (gpsLoc == 0)
+        qDebug() << "Null gpsLocation received from locations";
+    else
+        qDebug() << "GPS location is not null.";*/
+    //DEBUG ENDED
 
-  q->setFakeLocationLabel( fakeLocationLabel );
-  Location  *fakeLocation = q->fakeLocation();
+    locations->getGpsLocation()->setLocation(positionInfo);
+    //emit(gpsLocationChanged(m_location));
+}
 
-  if ( fakeLocation == 0 ) {
-    qDebug() << "invalid fake location label; cannot use fake location";
-  } else {
-    q->stopGps();
-    q->setUseFakeLocation( true );
-    emit locationChanged( fakeLocation );
-  }
+void GpsController::timeoutRequested()
+{
+    qDebug() << "GPS sent timeout requested.";
 }