test
[hikingdiary] / src / maemo5locationprivate.cpp
1 #include "maemo5locationprivate.h"
2 #include <QMessageBox>
3
4 /**
5   *Default constructor of this class.
6   *@param Maemo5Location pointer to public interface.
7   */
8 Maemo5LocationPrivate::Maemo5LocationPrivate(Maemo5Location* location):QObject(location)
9 {
10     //Initialize variables
11     latitude = 0;
12     longitude = 0;
13     usegps = -1;
14     //Get gps control object
15     control = location_gpsd_control_get_default();
16     //create gps device
17     device = (LocationGPSDevice*) g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
18     g_signal_connect(device, "changed", G_CALLBACK(gps_data_changed), this);
19     g_signal_connect(device, "connected", G_CALLBACK(gps_data_connected), this);
20 }
21 /**
22   *Destructor of this class. Should be used to release all allocated resources.
23   */
24 Maemo5LocationPrivate::~Maemo5LocationPrivate()
25 {
26 }
27
28 /**
29   *This function is used to start to poll with gprs
30   */
31 void Maemo5LocationPrivate::get_acwp()
32 {
33     g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_ACWP, NULL);
34     usegps = 0;
35     restart();
36 }
37
38 /**
39   *This function starts to poll via gps interface
40   */
41 void Maemo5LocationPrivate::get_agnss()
42 {
43     g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_AGNSS, NULL);
44     usegps = 1;
45     restart();
46 }
47
48 /**
49   *Stop pollling
50   */
51 void Maemo5LocationPrivate::stop()
52 {
53     location_gpsd_control_stop(control);
54 }
55
56 /**
57   *Stop and restart polling
58   */
59 void Maemo5LocationPrivate::restart()
60 {
61     location_gpsd_control_stop(control);
62     location_gpsd_control_start(control);
63 }
64
65 void gps_data_connected(LocationGPSDevice *device, Maemo5LocationPrivate *gps)
66 {
67     emit gps->connected();
68 }
69 /**
70   *Callback function to catch gps signals
71   */
72 void gps_data_changed(LocationGPSDevice *device, Maemo5LocationPrivate *gps)
73 {
74     //First check that LocationGpsDeviceFix can be found...this data structure contains the location info.
75     if(gps->device->fix)
76     {
77         //Check that there are fields
78         if(gps->device->fix->fields)
79         {
80             //Store values and emit signal
81             gps->latitude = gps->device->fix->latitude;
82             gps->longitude = gps->device->fix->longitude;
83             if(gps->usegps == 0)
84             {
85                 emit gps->awcp();
86             }
87             else if(gps->usegps == 1)
88             {
89                 emit gps->agnss();
90             }
91             else
92             {
93                 emit gps->locationUpdated();
94             }
95         }
96     }
97
98 }