#include "glatitude.h"
-GoogleLatitude::GoogleLatitude(QObject *parent) : QObject(parent) {
- user = "";
- pass = "";
- latitude = 0.;
- longitude = 0.;
- accuracy = 0.;
- interval = 120;
+GoogleLatitude::GoogleLatitude(QObject *parent) :
+ QObject(parent),
+ user(""), pass(""), login_error(false),
+ latitude(0), longitude(0), accuracy(0) {
worker = new QNetworkAccessManager();
- connect(worker, SIGNAL(finished(QNetworkReply *)), this, SLOT(finishedreply(QNetworkReply *)));
+ connect(worker, SIGNAL(finished(QNetworkReply *)), this, SLOT(glat_reply(QNetworkReply *)));
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) {
+void GoogleLatitude::set_login(QString u, QString p) {
+ qDebug() << "GoogleLatitude: set_login";
if ( !u.contains('@') ) u.append("@gmail.com");
user = u;
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>100000? 100000 : ac;
-
- qDebug() << "GoogleLatitude: set la" << la << "lo" << lo << "ac" << ac << "current" << QDateTime::currentDateTime().toUTC().toTime_t();
+void GoogleLatitude::update(double la, double lo, double ac) {
if (login_error) return;
- if (la*lo == 0) return;
- if (!accuracy) return;
- if ( QDateTime::currentDateTime().toUTC().toTime_t() < lastupdate + interval ) return;
+ if (!la) return;
+ if (!lo) return;
+ if (!ac) return;
#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
QNetworkConfigurationManager mgr;
}
#endif
+ qDebug() << "GoogleLatitude: update";
+
+ latitude = la;
+ longitude = lo;
+ accuracy = ac;
+
worker->get(QNetworkRequest(urllogin));
}
-void GoogleLatitude::finishedreply(QNetworkReply *r) {
+void GoogleLatitude::reset() {
+ qDebug() << "GoogleLatitude: reset";
+ login_error = false;
+ update(latitude, longitude, accuracy);
+}
+
+void GoogleLatitude::glat_reply(QNetworkReply *r) {
if ( r->url() == urllogin ) {
qDebug() << "GoogleLatitude: login";
QString aidis = r->readAll();
if (regexp.indexIn(output, 1) != -1) {
qDebug() << "GoogleLatitude: update error auth";
login_error = true;
- emit ERROR();
+ emit glat_error();
} else {
- lastupdate = QDateTime::currentDateTime().toUTC().toTime_t();
- qDebug() << "GoogleLatitude: update ok" << "lastupdate" << lastupdate;
+ qDebug() << "GoogleLatitude: update ok";
qDebug() << output;
- emit OK();
+ emit glat_ok();
}
} else {
qDebug() << "GoogleLatitude Error url" << r->url();