X-Git-Url: http://git.maemo.org/git/?p=googlelatitude;a=blobdiff_plain;f=src%2Fglatitude.cpp;h=2f9dcacf50656a62c683a68e828ecef9417af5c3;hp=a00f7c9250d65a52ead6c0aea2dbde7594a27a90;hb=5a837906fe9cee9952da7c38e0987857b214d63d;hpb=b5c1cf9c738640b0be7d4d0a8545116a97012319 diff --git a/src/glatitude.cpp b/src/glatitude.cpp index a00f7c9..2f9dcac 100644 --- a/src/glatitude.cpp +++ b/src/glatitude.cpp @@ -6,6 +6,7 @@ GoogleLatitude::GoogleLatitude(QObject *parent) : QObject(parent) { latitude = 0.; longitude = 0.; accuracy = 0.; + interval = 120; worker = new QNetworkAccessManager(); connect(worker, SIGNAL(finished(QNetworkReply *)), this, SLOT(finishedreply(QNetworkReply *))); @@ -13,6 +14,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) { @@ -21,17 +25,32 @@ void GoogleLatitude::login(QString u, QString p) { pass = p; } +void GoogleLatitude::freq(int f) { + interval = f; +} + +void GoogleLatitude::reset() { + lastupdate = 0; + login_error = false; + set(latitude, longitude, accuracy); +} + void GoogleLatitude::set(double la, double lo, double ac) { latitude = la; longitude = lo; accuracy = ac; + qDebug() << "GoogleLatitude: set la = " << la << " lo = " << lo << " ac = " << ac; + qDebug() << "GoogleLatitude: set lastupdate = " << lastupdate << " current = " << QDateTime::currentDateTime().toUTC().toTime_t(); + if (login_error) return; if (la*lo == 0) return; + if ( QDateTime::currentDateTime().toUTC().toTime_t() < lastupdate + interval ) 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 +64,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 +78,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::currentDateTime().toUTC().toTime_t(); + 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(); }