Changes: gps controller uses labels for fake gps
[ptas] / zouba / src / gpscontroller.cpp
1 #include "gpscontroller.h"
2 #include "gpscontroller_p.h"
3
4 #include "locations.h"
5
6 #include <QObject>
7 #include <QGeoPositionInfo>
8 #include <QGeoPositionInfoSource>
9 #include <QDebug>
10
11 GpsController::GpsController() :
12   q( new GpsControllerPrivate() )
13 {
14   q->init();
15   q->startGps();
16 }
17
18 GpsController::GpsController( GpsControllerPrivate *gpsControllerPrivate ) :
19   q( gpsControllerPrivate )
20 {
21   q->init();
22   q->startGps();
23 }
24
25 GpsController::~GpsController()
26 {
27   delete q;
28 }
29
30 void GpsController::getGps()
31 {
32   Location *location;
33
34   if ( q->useFakeLocation() ) {
35     Locations *locations = Locations::instance();
36     location = locations->location( q->fakeLocationLabel() );
37   } else {
38     location = q->liveLocation();
39   }
40
41   emit locationChanged( location );
42 }
43
44 void GpsController::useLiveGps()
45 {
46   q->setUseFakeLocation( false );
47   q->startGps();
48   emit locationChanged( q->liveLocation() );
49 }
50
51 void GpsController::useFakeGps( const QString &fakeLocationLabel )
52 {
53   qDebug() << "using fake gps (" << fakeLocationLabel << ")";
54
55   Locations *locations = Locations::instance();
56   Location  *fakeLocation = locations->location( fakeLocationLabel );
57
58   if ( fakeLocation == 0 ) {
59     qDebug() << "invalid fake location label; cannot use fake location";
60   } else {
61     q->stopGps();
62     q->setUseFakeLocation( true );
63     q->setFakeLocationLabel( fakeLocationLabel );
64     emit locationChanged( fakeLocation );
65   }
66 }