3 GpsMaemo5::GpsMaemo5(QObject *parent) :
5 latitude(0), longitude(0), accuracy(0),
6 interval(1800), wait(30), usegps(false),
7 emitfix(false), stopgps(true) {
9 control = location_gpsd_control_get_default();
10 device = (LocationGPSDevice*) g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
11 g_signal_connect(device, "changed", G_CALLBACK(GpsMaemo5_changed), this);
13 urlloc = QUrl::fromEncoded("http://www.google.com/loc/json");
14 worker = new QNetworkAccessManager();
15 connect(worker, SIGNAL(finished(QNetworkReply *)), this, SLOT(gloc_reply(QNetworkReply *)));
16 #endif // Q_WS_MAEMO_5
19 void GpsMaemo5::refresh() {
20 if ( stopgps ) return;
21 qDebug() << "GpsMaemo5: refresh";
23 QTimer::singleShot(interval*1000, this, SLOT(refresh()));
24 QTimer::singleShot(wait*1000, this, SLOT(stop()));
26 #if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
27 QNetworkConfigurationManager mgr;
28 if (!mgr.isOnline()) {
29 qDebug() << "GpsMaemo5: offline";
35 g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_ACWP, NULL);
37 g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_AGNSS, NULL);
39 location_gpsd_control_start(control);
41 worker->post(QNetworkRequest(urlloc), QByteArray("{version:\"1.1.0\"}"));
42 #endif // Q_WS_MAEMO_5
45 void GpsMaemo5::stop() {
46 qDebug() << "GpsMaemo5: stop";
48 location_gpsd_control_stop(control);
50 #endif // Q_WS_MAEMO_5
57 void GpsMaemo5::forcestop() {
58 qDebug() << "GpsMaemo5: forcestop";
64 int GpsMaemo5::config(int i, int w, bool g) {
65 qDebug() << "GpsMaemo5: config";
74 void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps) {
76 if (device->fix->fields) {
77 if ( isnan(gps->device->fix->eph) ) return;
78 g_print("GpsMaemo5 lat %f lon %f eph %f\n", gps->device->fix->latitude, gps->device->fix->longitude, gps->device->fix->eph/100.);
79 gps->latitude = gps->device->fix->latitude;
80 gps->longitude = gps->device->fix->longitude;
81 gps->accuracy = gps->device->fix->eph/100.;
87 void GpsMaemo5::gloc_reply(QNetworkReply *r) {
88 if ( r->url() == urlloc ) {
89 QString loc = r->readAll();
90 QRegExp regexp ("\\{\"latitude\":(.*),\"longitude\":(.*),\"accuracy\":(.*)\\}");
92 regexp.indexIn(loc, 1);
93 latitude = regexp.capturedTexts().at(1).toDouble();
94 longitude = regexp.capturedTexts().at(2).toDouble();
95 accuracy = regexp.capturedTexts().at(3).toDouble();
96 if ( accuracy > 100000 ) accuracy = 100000;
97 qDebug() << "GpsIP lat" << latitude << "lon" << longitude << "acc" << accuracy;
100 qDebug() << "GpsIP Error url" << r->url();
101 qDebug() << r->rawHeaderList();
102 qDebug() << r->readAll();
105 #endif // Q_WS_MAEMO_5