+googlelatitude (0.4-5) unstable; urgency=low
+
+ * New daemon mode
+ * bugs fix
+
+ -- Rodrigo Linfati <rodrigo@linfati.cl> Sat, 22 Jan 2011 18:51:23 +0100
+
googlelatitude (0.4-0) unstable; urgency=low
* Bump version
- View Location of Friends
- View Buzz of Friends
- View and Search on Google Maps
+ - Run as Daemon
XB-Maemo-Display-Name: Google Latitude and Buzz
XB-Description: Google Latitude and Buzz Client
Google Latitude Updater is written in QT4.
- View Location of Friends
- View Buzz of Friends
- View and Search on Google Maps
-XB-Maemo-Icon-26:
+ - Run as Daemon
+XB-Maemo-Icon-26:
iVBORw0KGgoAAAANSUhEUgAAADAAAAAwCAYAAAEgBckRAAAAB3RJTUUH2gEC
ARA3G6WpuwAAAAlwSFlzAAAN1gAADdYBkG95nAAAAARnQU1BAACxjwv8YQUA
AAp3SURBVHjaxVl5UBRXGv91zwwMoEBQRAMqi2gsgqxZ1ERF44VnrZTrkcRo
TARGET = googlelatitude
-HEADERS += src/latitude.h src/glatitude.h src/gps.h
-SOURCES += src/main.cpp src/latitude.cpp src/glatitude.cpp src/gps.cpp
+HEADERS += src/latitude.h src/glatitude.h src/gps.h src/daemon.h
+SOURCES += src/main.cpp src/latitude.cpp src/glatitude.cpp src/gps.cpp src/daemon.cpp
OBJECTS_DIR = build
MOC_DIR = build
DESTDIR = build
TEMPLATE = app
-QT += network webkit
+QT += core gui network webkit
contains(QT_CONFIG, maemo5) {
QT += maemo5
--- /dev/null
+#include "daemon.h"
+
+Daemon::Daemon(QObject *parent) : QObject(parent) {
+ setting = new QSettings();
+ glatitude = new GoogleLatitude(this);
+ gps = new GpsMaemo5(this);
+ connect(gps, SIGNAL(fix()), this, SLOT(set()));
+ connect(glatitude, SIGNAL(OK()), this, SLOT(daemon_OK()));
+ connect(glatitude, SIGNAL(ERROR()), this, SLOT(daemon_ERROR()));
+}
+
+void Daemon::set() {
+ qDebug() << "Daemon: set";
+ glatitude->login(setting->value("user","my_username").toString(),
+ setting->value("pass","my_password").toString());
+ glatitude->set(gps->get_lat(),
+ gps->get_lon(),
+ gps->get_acc());
+}
+
+void Daemon::daemon_OK() {
+ qDebug() << "Daemon: send";
+}
+
+void Daemon::daemon_ERROR() {
+ qDebug() << "Daemon: no auth";
+}
--- /dev/null
+#ifndef DAEMON_H
+#define DAEMON_H
+
+#include <QObject>
+#include "glatitude.h"
+#include "gps.h"
+
+class Daemon : public QObject {
+ Q_OBJECT
+
+public:
+ Daemon(QObject *parent = 0);
+
+private slots:
+ void set();
+ void daemon_OK();
+ void daemon_ERROR();
+
+private:
+ GoogleLatitude *glatitude;
+ GpsMaemo5 *gps;
+ QSettings *setting;
+
+};
+
+#endif // DAEMON_H
urllogin = QUrl::fromEncoded("https://www.google.com/accounts/ServiceLogin?service=friendview");
urldologin = QUrl::fromEncoded("https://www.google.com/accounts/ServiceLoginAuth?service=friendview");
urlupdate = QUrl::fromEncoded("http://maps.google.com/glm/mmap/mwmfr?hl=en");
+
+ lastupdate = 0;
+ login_error = false;
}
void GoogleLatitude::login(QString u, QString p) {
longitude = lo;
accuracy = ac;
+ qDebug() << "GoogleLatitude: set la = " << la << " lo = " << lo << " ac = " << ac;
+ qDebug() << "GoogleLatitude: set lastupdate = " << lastupdate << " current = " << QDateTime::currentMSecsSinceEpoch();
+ if (login_error) return;
if (la*lo == 0) return;
+ if ( QDateTime::currentMSecsSinceEpoch() < lastupdate + 120*1000 ) return;
worker->get(QNetworkRequest(urllogin));
}
void GoogleLatitude::finishedreply(QNetworkReply *r) {
if ( r->url() == urllogin ) {
+ qDebug() << "GoogleLatitude: login";
QString aidis = r->readAll();
QRegExp regexp ("type=\"hidden\".*name=\"GALX\".*value=\"(.*)\"");
regexp.setMinimal(1);
datalogin += "&Passwd=" + pass;
worker->post(QNetworkRequest(urldologin), datalogin);
} else if ( r->url() == urldologin ) {
+ qDebug() << "GoogleLatitude: dologin";
QByteArray datagps;
datagps += "t=ul";
datagps += "&lat=" + QString::number(latitude);
QString output = r->readAll();
QRegExp regexp ("Authentication required");
if (regexp.indexIn(output, 1) != -1) {
+ qDebug() << "GoogleLatitude: update error";
+ login_error = true;
emit ERROR();
} else {
+ lastupdate = QDateTime::currentMSecsSinceEpoch();
+ qDebug() << "GoogleLatitude: update ok " << " lastupdate = " << lastupdate;
emit OK();
}
- qDebug() << output;
} else {
- qDebug() << "Error";
- qDebug() << "url:" << r->url();
+ qDebug() << "GoogleLatitude Error url:" << r->url();
qDebug() << r->rawHeaderList();
qDebug() << r->readAll();
}
QUrl urllogin;
QUrl urldologin;
QUrl urlupdate;
+ qint64 lastupdate;
+ bool login_error;
};
#endif // GLATITUDE_H
#include "gps.h"
-#ifdef Q_WS_MAEMO_5
-
GpsMaemo5::GpsMaemo5(QObject *parent) : QObject(parent) {
latitude = 0;
longitude = 0;
accuracy = 0;
-
+#ifdef Q_WS_MAEMO_5
control = location_gpsd_control_get_default();
device = (LocationGPSDevice*) g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
g_object_set(G_OBJECT(control), "preferred-interval", LOCATION_INTERVAL_120S, NULL);
location_gpsd_control_start(control);
+#else
+ urlloc = QUrl::fromEncoded("http://www.google.com/loc/json");
+ worker = new QNetworkAccessManager();
+ connect(worker, SIGNAL(finished(QNetworkReply *)), this, SLOT(finishedreply(QNetworkReply *)));
+
+ worker->post(QNetworkRequest(urlloc), QByteArray("{version:\"1.1.0\"}"));
+#endif // Q_WS_MAEMO_5
}
+#ifdef Q_WS_MAEMO_5
void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps) {
if (device->fix) {
if (device->fix->fields) {
- g_print("lat = %f, long = %f, eph = %f\n", gps->device->fix->latitude, gps->device->fix->longitude, gps->device->fix->eph/100.);
+ g_print("GpsMaemo5 lat = %f, long = %f, eph = %f\n", gps->device->fix->latitude, gps->device->fix->longitude, gps->device->fix->eph/100.);
gps->latitude = gps->device->fix->latitude;
gps->longitude = gps->device->fix->longitude;
gps->accuracy = gps->device->fix->eph/100.;
}
}
}
-
+#else
+void GpsMaemo5::finishedreply(QNetworkReply *r) {
+ if ( r->url() == urlloc ) {
+ QString loc = r->readAll();
+ QRegExp regexp ("\\{\"latitude\":(.*),\"longitude\":(.*),\"accuracy\":(.*)\\}");
+ regexp.setMinimal(1);
+ regexp.indexIn(loc, 1);
+ latitude = regexp.capturedTexts().at(1).toDouble();
+ longitude = regexp.capturedTexts().at(2).toDouble();
+ accuracy = regexp.capturedTexts().at(3).toDouble();
+ qDebug() << "GpsMaemo5 lat = " << latitude << " long = " << longitude << " acc = " << accuracy;
+ emit fix();
+ } else {
+ qDebug() << "GpsMaemo5 Error url:" << r->url();
+ qDebug() << r->rawHeaderList();
+ qDebug() << r->readAll();
+ }
+}
#endif // Q_WS_MAEMO_5
#include <QObject>
#ifdef Q_WS_MAEMO_5
-
extern "C" {
#include <location/location-gps-device.h>
#include <location/location-gpsd-control.h>
}
+#else
+#include <QtNetwork>
+#endif // Q_WS_MAEMO_5
class GpsMaemo5 : public QObject {
Q_OBJECT
double get_lat() { return latitude; }
double get_lon() { return longitude; }
double get_acc() { return accuracy; }
+#ifdef Q_WS_MAEMO_5
friend void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps);
+#endif // Q_WS_MAEMO_5
+
+#ifdef Q_WS_MAEMO_5
+#else
+private slots:
+ void finishedreply(QNetworkReply *r);
+#endif // Q_WS_MAEMO_5
private:
double latitude;
double longitude;
double accuracy;
-
+#ifdef Q_WS_MAEMO_5
GMainLoop *loop;
LocationGPSDControl *control;
LocationGPSDevice *device;
-};
-
-void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps);
-
-#else // Q_WS_MAEMO_5
-
-class GpsMaemo5 : public QObject {
- Q_OBJECT
-
-signals:
- void fix();
+#else
+ QUrl urlloc;
+ QNetworkAccessManager *worker;
+#endif // Q_WS_MAEMO_5
-public:
- GpsMaemo5(QObject *parent = 0) { Q_UNUSED(parent); }
- double get_lat() { return 0; }
- double get_lon() { return 0; }
- double get_acc() { return 0; }
};
+#ifdef Q_WS_MAEMO_5
+void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps);
#endif // Q_WS_MAEMO_5
#endif // GPS_H
}
void LatitudeGUI::set() {
-#ifdef Q_WS_MAEMO_5
- QMaemo5InformationBox::information(this, "new position...", 1000);
-#else
- qDebug() << "new position...";
-#endif
+ qDebug() << "LatitudeGUI: set";
glatitude->login(setting->value("user","my_username").toString(),
setting->value("pass","my_password").toString());
glatitude->set(gps->get_lat(),
}
void LatitudeGUI::latitude_OK() {
-#ifdef Q_WS_MAEMO_5
- QMaemo5InformationBox::information(this, "...location Sent!", 1000);
-#else
- qDebug() << "...location Sent!";
-#endif
+ qDebug() << "LatitudeGUI: send";
}
void LatitudeGUI::latitude_ERROR() {
#ifdef Q_WS_MAEMO_5
- QMaemo5InformationBox::information(this, "Error in Authentification !", 3000);
-#else
- qDebug() << "Error in Authentification !";
+ QString error_message = tr("<b>Error in Authentification!</b><br><br>") +
+ tr("Plese verify your login details<br>");
+ QMaemo5InformationBox::information(this, error_message,
+ QMaemo5InformationBox::NoTimeout);
#endif
+ qDebug() << "LatitudeGUI: no auth";
}
void LatitudeGUI::save_user(QString _user) {
class LatitudeGUI : public QMainWindow {
Q_OBJECT
-signals:
- void newpos();
-
public:
LatitudeGUI(QMainWindow *parent = 0);
#include "latitude.h"
+#include "daemon.h"
int main(int argc, char *argv[]) {
- QApplication app(argc, argv);
QCoreApplication::setOrganizationName("linfati");
QCoreApplication::setOrganizationDomain("linfati.com");
QCoreApplication::setApplicationName("GoogleLatitude");
+ QCoreApplication::setApplicationVersion("0.4.5");
- LatitudeGUI *gui = new LatitudeGUI();
- gui->show();
+ if ( QString(argv[0]).contains("GoogleLatitudeDaemon") ) {
+ QCoreApplication app(argc, argv);
+ qDebug() << "main: Daemon";
+ Daemon *demonio;
+ demonio = new Daemon();
+ app.exec();
+ } else if ( QString(argv[0]).contains("GoogleLatitudeGUI") ) {
+ QApplication app(argc, argv);
+ qDebug() << "main: GUI";
+ LatitudeGUI *gui = new LatitudeGUI();
+ gui->show();
+ app.exec();
+ } else {
+ QApplication app(argc, argv);
+ qDebug() << "main: default";
+ LatitudeGUI *gui = new LatitudeGUI();
+ gui->show();
+ app.exec();
+ }
- return app.exec();
+ return 0;
}
-
-/*
- TODO:
- on auth error -> stop gps
- on new pos, only set it
- send new pos every 120s, only if is diferent
- no n900 -> por ip
- */