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