support to no liblocation
[googlelatitude] / src / gps.cpp
1 #include "gps.h"
2
3 #ifdef Q_WS_MAEMO_5
4
5 GpsMaemo5::GpsMaemo5(QObject *parent) : QObject(parent) {
6     latitude = 0;
7     longitude = 0;
8     accuracy = 0;
9     usegps = -1;
10
11     control = location_gpsd_control_get_default();
12     device = (LocationGPSDevice*) g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
13     g_signal_connect(device, "changed", G_CALLBACK(GpsMaemo5_changed), this);
14 }
15
16 void GpsMaemo5::get_acwp() {
17     g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_ACWP, NULL);
18     usegps = 0;
19     restart();
20 }
21
22 void GpsMaemo5::get_agnss() {
23     g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_AGNSS, NULL);
24     usegps = 1;
25     restart();
26 }
27
28 void GpsMaemo5::stop() {
29     location_gpsd_control_stop(control);
30 }
31
32 void GpsMaemo5::restart() {
33     location_gpsd_control_stop(control);
34     location_gpsd_control_start(control);
35 }
36
37 void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps) {
38     if (device->fix) {
39         if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) {
40             g_print("lat = %f, long = %f, eph = %f\n", device->fix->latitude, device->fix->longitude, device->fix->eph/100.);
41             gps->latitude = device->fix->latitude;
42             gps->longitude = device->fix->longitude;
43             gps->accuracy = device->fix->eph/100.;
44
45             if ( gps->usegps == 0) {
46                 emit gps->getOK_acwp();
47             } else if ( gps->usegps == 1 ) {
48                 if ( gps->device->satellites_in_use > 0 ) {
49                     emit gps->getOK_agnss();
50                 }
51             } else {
52                 emit gps->getOK();
53             }
54         }
55     }
56 }
57
58 #endif