#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();
+ }
+ }
+ }
}
#ifndef GPS_H
#define GPS_H
+extern "C" {
+#include <location/location-gps-device.h>
+#include <location/location-gpsd-control.h>
+}
#include <QObject>
-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
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() {
}
void LatitudeGUI::set_OK() {
- status->setText(tr("Location Updated !"));
+ status->setText(tr("Updated Location !"));
}
void LatitudeGUI::set_ERROR() {
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();