From: Rodrigo Linfati Date: Sat, 22 Jan 2011 17:53:06 +0000 (+0100) Subject: daemon mode and bugs fixes X-Git-Url: http://git.maemo.org/git/?p=googlelatitude;a=commitdiff_plain;h=e98468d19d7c7f3b2e068e3bebcc5ff47dd61d9b daemon mode and bugs fixes --- diff --git a/debian/changelog b/debian/changelog index e8581be..68eb0ba 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,10 @@ +googlelatitude (0.4-5) unstable; urgency=low + + * New daemon mode + * bugs fix + + -- Rodrigo Linfati Sat, 22 Jan 2011 18:51:23 +0100 + googlelatitude (0.4-0) unstable; urgency=low * Bump version diff --git a/debian/control b/debian/control index 4561672..f692c71 100644 --- a/debian/control +++ b/debian/control @@ -17,6 +17,7 @@ Description: Google Latitude and Buzz - 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. @@ -25,7 +26,8 @@ XB-Description: Google Latitude and Buzz Client - 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 diff --git a/googlelatitude.pro b/googlelatitude.pro index 8eb75e0..cceb79f 100644 --- a/googlelatitude.pro +++ b/googlelatitude.pro @@ -1,13 +1,13 @@ 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 diff --git a/src/daemon.cpp b/src/daemon.cpp new file mode 100644 index 0000000..7e9886d --- /dev/null +++ b/src/daemon.cpp @@ -0,0 +1,27 @@ +#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"; +} diff --git a/src/daemon.h b/src/daemon.h new file mode 100644 index 0000000..9744577 --- /dev/null +++ b/src/daemon.h @@ -0,0 +1,26 @@ +#ifndef DAEMON_H +#define DAEMON_H + +#include +#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 diff --git a/src/glatitude.cpp b/src/glatitude.cpp index a00f7c9..be927e9 100644 --- a/src/glatitude.cpp +++ b/src/glatitude.cpp @@ -13,6 +13,9 @@ GoogleLatitude::GoogleLatitude(QObject *parent) : QObject(parent) { 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) { @@ -26,12 +29,17 @@ void GoogleLatitude::set(double la, double lo, double ac) { 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); @@ -45,6 +53,7 @@ void GoogleLatitude::finishedreply(QNetworkReply *r) { 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); @@ -58,14 +67,16 @@ void GoogleLatitude::finishedreply(QNetworkReply *r) { 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(); } diff --git a/src/glatitude.h b/src/glatitude.h index 3083696..7e2e3ed 100644 --- a/src/glatitude.h +++ b/src/glatitude.h @@ -33,6 +33,8 @@ private: QUrl urllogin; QUrl urldologin; QUrl urlupdate; + qint64 lastupdate; + bool login_error; }; #endif // GLATITUDE_H diff --git a/src/gps.cpp b/src/gps.cpp index 0fb4ba7..7c9eead 100644 --- a/src/gps.cpp +++ b/src/gps.cpp @@ -1,12 +1,10 @@ #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); @@ -15,12 +13,20 @@ GpsMaemo5::GpsMaemo5(QObject *parent) : QObject(parent) { 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.; @@ -28,5 +34,22 @@ void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps) { } } } - +#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 diff --git a/src/gps.h b/src/gps.h index 2d9cfdf..9f1cac9 100644 --- a/src/gps.h +++ b/src/gps.h @@ -4,11 +4,13 @@ #include #ifdef Q_WS_MAEMO_5 - extern "C" { #include #include } +#else +#include +#endif // Q_WS_MAEMO_5 class GpsMaemo5 : public QObject { Q_OBJECT @@ -21,35 +23,33 @@ public: 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 diff --git a/src/latitude.cpp b/src/latitude.cpp index 864f5c0..7bdc14a 100644 --- a/src/latitude.cpp +++ b/src/latitude.cpp @@ -44,11 +44,7 @@ LatitudeGUI::LatitudeGUI(QMainWindow *parent) : QMainWindow(parent) { } 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(), @@ -57,19 +53,17 @@ void LatitudeGUI::set() { } 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("Error in Authentification!

") + + tr("Plese verify your login details
"); + QMaemo5InformationBox::information(this, error_message, + QMaemo5InformationBox::NoTimeout); #endif + qDebug() << "LatitudeGUI: no auth"; } void LatitudeGUI::save_user(QString _user) { diff --git a/src/latitude.h b/src/latitude.h index 4f2362d..395b00d 100644 --- a/src/latitude.h +++ b/src/latitude.h @@ -12,9 +12,6 @@ class LatitudeGUI : public QMainWindow { Q_OBJECT -signals: - void newpos(); - public: LatitudeGUI(QMainWindow *parent = 0); diff --git a/src/main.cpp b/src/main.cpp index fd38f35..42eebdd 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,21 +1,31 @@ #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 - */