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()));
27 g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_ACWP, NULL);
29 g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_AGNSS, NULL);
31 location_gpsd_control_start(control);
33 worker->post(QNetworkRequest(urlloc), QByteArray("{version:\"1.1.0\"}"));
34 #endif // Q_WS_MAEMO_5
37 void GpsMaemo5::stop() {
38 qDebug() << "GpsMaemo5: stop";
40 location_gpsd_control_stop(control);
42 #endif // Q_WS_MAEMO_5
49 void GpsMaemo5::forcestop() {
50 qDebug() << "GpsMaemo5: forcestop";
56 int GpsMaemo5::config(int i, int w, bool g) {
57 qDebug() << "GpsMaemo5: config";
66 void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps) {
68 if (device->fix->fields) {
69 if ( isnan(gps->device->fix->eph) ) return;
70 g_print("GpsMaemo5 lat %f lon %f eph %f\n", gps->device->fix->latitude, gps->device->fix->longitude, gps->device->fix->eph/100.);
71 gps->latitude = gps->device->fix->latitude;
72 gps->longitude = gps->device->fix->longitude;
73 gps->accuracy = gps->device->fix->eph/100.;
79 void GpsMaemo5::gloc_reply(QNetworkReply *r) {
80 if ( r->url() == urlloc ) {
81 QString loc = r->readAll();
82 QRegExp regexp ("\\{\"latitude\":(.*),\"longitude\":(.*),\"accuracy\":(.*)\\}");
84 regexp.indexIn(loc, 1);
85 latitude = regexp.capturedTexts().at(1).toDouble();
86 longitude = regexp.capturedTexts().at(2).toDouble();
87 accuracy = regexp.capturedTexts().at(3).toDouble();
88 if ( accuracy > 100000 ) accuracy = 100000;
89 qDebug() << "GpsIP lat" << latitude << "lon" << longitude << "acc" << accuracy;
92 qDebug() << "GpsIP Error url" << r->url();
93 qDebug() << r->rawHeaderList();
94 qDebug() << r->readAll();
97 #endif // Q_WS_MAEMO_5