#include "glatitude.h"
-GoogleLatitude::GoogleLatitude(QObject *parent) : QObject(parent) {
- user = "";
- pass = "";
- latitude = 0.;
- longitude = 0.;
- accuracy = 0.;
+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");
}
-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::set(double la, double lo, double ac) {
+void GoogleLatitude::update(double la, double lo, double ac) {
+ if (login_error) return;
+ if (!la) return;
+ if (!lo) return;
+ if (!ac) return;
+
+#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0)
+ QNetworkConfigurationManager mgr;
+ if (!mgr.isOnline()) {
+ qDebug() << "GoogleLatitude: offline";
+ return;
+ }
+#endif
+
+ qDebug() << "GoogleLatitude: update";
+
latitude = la;
longitude = lo;
accuracy = ac;
- if (la*lo == 0) return;
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();
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) {
- emit ERROR();
+ qDebug() << "GoogleLatitude: update error auth";
+ login_error = true;
+ emit glat_error();
} else {
- emit OK();
+ qDebug() << "GoogleLatitude: update ok";
+ qDebug() << output;
+ emit glat_ok();
}
- qDebug() << output;
} else {
- qDebug() << "Error";
- qDebug() << "url:" << r->url();
+ qDebug() << "GoogleLatitude Error url" << r->url();
qDebug() << r->rawHeaderList();
qDebug() << r->readAll();
}