From 6b2767c11982f90df6d12657af252a4d35e11fd7 Mon Sep 17 00:00:00 2001 From: Rodrigo Linfati Date: Fri, 1 Jan 2010 16:29:35 +0100 Subject: [PATCH 1/1] version 0.3, initial support to liblocation --- debian/changelog | 6 ++++++ debian/control | 2 +- src/glatitude.cpp | 1 + src/gps.cpp | 44 ++++++++++++++++++++++++++++++++++++++------ src/gps.h | 27 +++++++++++++++++++++------ src/latitude.cpp | 34 ++++++++++++++++++++++++++-------- src/latitude.h | 6 ++++-- src/src.pro | 4 ++-- 8 files changed, 99 insertions(+), 25 deletions(-) diff --git a/debian/changelog b/debian/changelog index a11e395..60fe31c 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +googlelatitude (0.3-1) unstable; urgency=low + + * initial support to liblocation + + -- Rodrigo Linfati Fri, 01 Jan 2010 16:20:56 +0100 + googlelatitude (0.2-2) unstable; urgency=low * minor change in gui diff --git a/debian/control b/debian/control index 6e7e64c..09c6888 100644 --- a/debian/control +++ b/debian/control @@ -2,7 +2,7 @@ Source: googlelatitude Section: user/navigation Priority: optional Maintainer: Rodrigo Linfati -Build-Depends: debhelper (>= 5), libqt4-maemo5-dev, libgconf2-dev +Build-Depends: debhelper (>= 5), libqt4-maemo5-dev, libgconf2-dev, liblocation-dev # Build-Depends: debhelper (>= 5), libqt4-dev Standards-Version: 3.7.2 diff --git a/src/glatitude.cpp b/src/glatitude.cpp index 8a91f3d..68b626f 100644 --- a/src/glatitude.cpp +++ b/src/glatitude.cpp @@ -76,6 +76,7 @@ void GoogleLatitude::finishedreply(QNetworkReply *r) { longitude = regexp.capturedTexts().at(2).toDouble(); accuracy = regexp.capturedTexts().at(3).toDouble(); emit getOK(); + qDebug() << "lat = " + QString::number(latitude) + " lng = " + QString::number(longitude) + " acc = " + QString::number(accuracy); } else { qDebug() << "Error"; qDebug() << "url:" << r->url(); diff --git a/src/gps.cpp b/src/gps.cpp index f01639a..a326498 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -1,22 +1,54 @@ #include "gps.h" -gps::gps(QObject *parent) : QObject(parent) { +GpsMaemo5::GpsMaemo5(QObject *parent) : QObject(parent) { latitude = 0; longitude = 0; accuracy = 0; + usegps = -1; + + control = location_gpsd_control_get_default(); + device = (LocationGPSDevice*) g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL); + g_signal_connect(device, "changed", G_CALLBACK(GpsMaemo5_changed), this); } -void gps::get() { +void GpsMaemo5::get_acwp() { + g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_ACWP, NULL); + usegps = 0; + restart(); } -void gps::set_acwp() { +void GpsMaemo5::get_agnss() { + g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_AGNSS, NULL); + usegps = 1; + restart(); } -void gps::set_agnss() { +void GpsMaemo5::stop() { + location_gpsd_control_stop(control); } -void gps::start() { +void GpsMaemo5::restart() { + location_gpsd_control_stop(control); + location_gpsd_control_start(control); } -void gps::stop() { +void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps) { + if (device->fix) { + if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) { + g_print("lat = %f, long = %f, eph = %f\n", device->fix->latitude, device->fix->longitude, device->fix->eph/100.); + gps->latitude = device->fix->latitude; + gps->longitude = device->fix->longitude; + gps->accuracy = device->fix->eph/100.; + + if ( gps->usegps == 0) { + emit gps->getOK_acwp(); + } else if ( gps->usegps == 1 ) { + if ( gps->device->satellites_in_use > 0 ) { + emit gps->getOK_agnss(); + } + } else { + emit gps->getOK(); + } + } + } } diff --git a/src/gps.h b/src/gps.h index 3cf513a..e3de44a 100644 --- a/src/gps.h +++ b/src/gps.h @@ -1,31 +1,46 @@ #ifndef GPS_H #define GPS_H +extern "C" { +#include +#include +} #include -class gps : public QObject { +class GpsMaemo5 : public QObject { Q_OBJECT signals: void getOK(); + void getOK_acwp(); + void getOK_agnss(); public slots: - void get(); + void get_acwp(); + void get_agnss(); public: - gps(QObject *parent = 0); + GpsMaemo5(QObject *parent = 0); double get_lat() { return latitude; } double get_lon() { return longitude; } double get_acc() { return accuracy; } - void set_acwp(); - void set_agnss(); - void start(); void stop(); + void restart(); + friend void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps); private: double latitude; double longitude; double accuracy; + + int usegps; + + GMainLoop *loop; + LocationGPSDControl *control; + LocationGPSDevice *device; + }; +void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps); + #endif // GPS_H diff --git a/src/latitude.cpp b/src/latitude.cpp index 00e7243..2661345 100644 --- a/src/latitude.cpp +++ b/src/latitude.cpp @@ -2,29 +2,47 @@ LatitudeGUI::LatitudeGUI(QMainWindow *parent) : QMainWindow(parent) { glatitude = new GoogleLatitude(this); + gps = new GpsMaemo5(this); setting = new QSettings(); urllogin = QUrl::fromEncoded("https://www.google.com/accounts/ServiceLogin?service=friendview&continue=http://www.google.com/maps/m?mode=latitude"); show_lat(); connect(glatitude, SIGNAL(getOK()), this, SLOT(get_loc())); + connect(gps, SIGNAL(getOK()), this, SLOT(get_maemo5())); + connect(gps, SIGNAL(getOK_acwp()), this, SLOT(get_acwp())); + connect(gps, SIGNAL(getOK_agnss()), this, SLOT(get_agnss())); connect(glatitude, SIGNAL(setOK()), this, SLOT(set_OK())); connect(glatitude, SIGNAL(setERROR()), this, SLOT(set_ERROR())); + } void LatitudeGUI::get_loc() { location_lat->setText(QString::number(glatitude->get_lat())); location_lon->setText(QString::number(glatitude->get_lon())); location_acc->setText(QString::number(glatitude->get_acc())); - status->setText(tr("Using google.com/loc")); + status->setText(tr("Using google.com/loc, ip-based")); +} + +void LatitudeGUI::get_maemo5() { + location_lat->setText(QString::number(gps->get_lat())); + location_lon->setText(QString::number(gps->get_lon())); + location_acc->setText(QString::number(gps->get_acc())); + status->setText(tr("Using liblocation")); } -void LatitudeGUI::get_cell() { - status->setText(tr("Using cell... TODO")); +void LatitudeGUI::get_acwp() { + location_lat->setText(QString::number(gps->get_lat())); + location_lon->setText(QString::number(gps->get_lon())); + location_acc->setText(QString::number(gps->get_acc())); + status->setText(tr("Using acwp, cell-based ")); } -void LatitudeGUI::get_gps() { - status->setText(tr("Using gps... TODO")); +void LatitudeGUI::get_agnss() { + location_lat->setText(QString::number(gps->get_lat())); + location_lon->setText(QString::number(gps->get_lon())); + location_acc->setText(QString::number(gps->get_acc())); + status->setText(tr("Using agnss, gps-based ")); } void LatitudeGUI::set() { @@ -37,7 +55,7 @@ void LatitudeGUI::set() { } void LatitudeGUI::set_OK() { - status->setText(tr("Location Updated !")); + status->setText(tr("Updated Location !")); } void LatitudeGUI::set_ERROR() { @@ -103,8 +121,8 @@ void LatitudeGUI::show_lat() { layout_source->addWidget(source_gps); // source connect connect(source_loc, SIGNAL(clicked()), glatitude, SLOT(get())); - connect(source_cell, SIGNAL(clicked()), this, SLOT(get_cell())); - connect(source_gps, SIGNAL(clicked()), this, SLOT(get_gps())); + connect(source_cell, SIGNAL(clicked()), gps, SLOT(get_acwp())); + connect(source_gps, SIGNAL(clicked()), gps, SLOT(get_agnss())); // main layout location = new QWidget(); diff --git a/src/latitude.h b/src/latitude.h index 2225a64..c986d30 100644 --- a/src/latitude.h +++ b/src/latitude.h @@ -16,8 +16,9 @@ public: private slots: void get_loc(); - void get_cell(); - void get_gps(); + void get_acwp(); + void get_agnss(); + void get_maemo5(); void set(); void set_OK(); void set_ERROR(); @@ -28,6 +29,7 @@ private slots: private: GoogleLatitude *glatitude; + GpsMaemo5 *gps; QSettings *setting; QWebView *maps; QWidget *location; diff --git a/src/src.pro b/src/src.pro index 4daf92d..12dfc2d 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,6 +1,7 @@ QT += network QT += webkit - +CONFIG += link_pkgconfig +PKGCONFIG += glib-2.0 liblocation TARGET = GoogleLatitude TEMPLATE = app SOURCES += main.cpp \ @@ -10,7 +11,6 @@ SOURCES += main.cpp \ HEADERS += latitude.h \ glatitude.h \ gps.h - unix { isEmpty(PREFIX):PREFIX = /usr/local BINDIR = $$PREFIX/bin -- 1.7.9.5