version 0.3, initial support to liblocation
authorRodrigo Linfati <rodrigo@linfati.cl>
Fri, 1 Jan 2010 15:29:35 +0000 (16:29 +0100)
committerRodrigo Linfati <rodrigo@linfati.cl>
Fri, 1 Jan 2010 15:29:35 +0000 (16:29 +0100)
debian/changelog
debian/control
src/glatitude.cpp
src/gps.cpp
src/gps.h
src/latitude.cpp
src/latitude.h
src/src.pro

index a11e395..60fe31c 100644 (file)
@@ -1,3 +1,9 @@
+googlelatitude (0.3-1) unstable; urgency=low
+
+  * initial support to liblocation
+
+ -- Rodrigo Linfati <rodrigo@linfati.cl>  Fri, 01 Jan 2010 16:20:56 +0100
+
 googlelatitude (0.2-2) unstable; urgency=low
 
   * minor change in gui
 googlelatitude (0.2-2) unstable; urgency=low
 
   * minor change in gui
index 6e7e64c..09c6888 100644 (file)
@@ -2,7 +2,7 @@ Source: googlelatitude
 Section: user/navigation
 Priority: optional
 Maintainer: Rodrigo Linfati <rodrigo@linfati.cl>
 Section: user/navigation
 Priority: optional
 Maintainer: Rodrigo Linfati <rodrigo@linfati.cl>
-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
 
 # Build-Depends: debhelper (>= 5), libqt4-dev
 Standards-Version: 3.7.2
 
index 8a91f3d..68b626f 100644 (file)
@@ -76,6 +76,7 @@ void GoogleLatitude::finishedreply(QNetworkReply *r) {
         longitude = regexp.capturedTexts().at(2).toDouble();
         accuracy = regexp.capturedTexts().at(3).toDouble();
         emit getOK();
         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();
     } else {
         qDebug() << "Error";
         qDebug() << "url:" << r->url();
index f01639a..a326498 100644 (file)
@@ -1,22 +1,54 @@
 #include "gps.h"
 
 #include "gps.h"
 
-gps::gps(QObject *parent) : QObject(parent) {
+GpsMaemo5::GpsMaemo5(QObject *parent) : QObject(parent) {
     latitude = 0;
     longitude = 0;
     accuracy = 0;
     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();
+            }
+        }
+    }
 }
 }
index 3cf513a..e3de44a 100644 (file)
--- a/src/gps.h
+++ b/src/gps.h
@@ -1,31 +1,46 @@
 #ifndef GPS_H
 #define GPS_H
 
 #ifndef GPS_H
 #define GPS_H
 
+extern "C" {
+#include <location/location-gps-device.h>
+#include <location/location-gpsd-control.h>
+}
 #include <QObject>
 
 #include <QObject>
 
-class gps : public QObject {
+class GpsMaemo5 : public QObject {
     Q_OBJECT
 
 signals:
     void getOK();
     Q_OBJECT
 
 signals:
     void getOK();
+    void getOK_acwp();
+    void getOK_agnss();
 
 public slots:
 
 public slots:
-    void get();
+    void get_acwp();
+    void get_agnss();
 
 public:
 
 public:
-    gps(QObject *parent = 0);
+    GpsMaemo5(QObject *parent = 0);
     double get_lat() { return latitude; }
     double get_lon() { return longitude; }
     double get_acc() { return accuracy; }
     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 stop();
+    void restart();
+    friend void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps);
 
 private:
     double latitude;
     double longitude;
     double accuracy;
 
 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
 #endif // GPS_H
index 00e7243..2661345 100644 (file)
@@ -2,29 +2,47 @@
 
 LatitudeGUI::LatitudeGUI(QMainWindow *parent) : QMainWindow(parent) {
     glatitude = new GoogleLatitude(this);
 
 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()));
     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()));
     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()));
 }
 
 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() {
 }
 
 void LatitudeGUI::set() {
@@ -37,7 +55,7 @@ void LatitudeGUI::set() {
 }
 
 void LatitudeGUI::set_OK() {
 }
 
 void LatitudeGUI::set_OK() {
-    status->setText(tr("Location Updated !"));
+    status->setText(tr("Updated Location !"));
 }
 
 void LatitudeGUI::set_ERROR() {
 }
 
 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()));
     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();
 
     // main layout
     location = new QWidget();
index 2225a64..c986d30 100644 (file)
@@ -16,8 +16,9 @@ public:
 
 private slots:
     void get_loc();
 
 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();
     void set();
     void set_OK();
     void set_ERROR();
@@ -28,6 +29,7 @@ private slots:
 
 private:
     GoogleLatitude *glatitude;
 
 private:
     GoogleLatitude *glatitude;
+    GpsMaemo5 *gps;
     QSettings *setting;
     QWebView *maps;
     QWidget *location;
     QSettings *setting;
     QWebView *maps;
     QWidget *location;
index 4daf92d..12dfc2d 100644 (file)
@@ -1,6 +1,7 @@
 QT += network
 QT += webkit
 QT += network
 QT += webkit
-
+CONFIG += link_pkgconfig
+PKGCONFIG += glib-2.0 liblocation
 TARGET = GoogleLatitude
 TEMPLATE = app
 SOURCES += main.cpp \
 TARGET = GoogleLatitude
 TEMPLATE = app
 SOURCES += main.cpp \
@@ -10,7 +11,6 @@ SOURCES += main.cpp \
 HEADERS += latitude.h \
     glatitude.h \
     gps.h
 HEADERS += latitude.h \
     glatitude.h \
     gps.h
-
 unix { 
     isEmpty(PREFIX):PREFIX = /usr/local
     BINDIR = $$PREFIX/bin
 unix { 
     isEmpty(PREFIX):PREFIX = /usr/local
     BINDIR = $$PREFIX/bin