X-Git-Url: http://git.maemo.org/git/?p=googlelatitude;a=blobdiff_plain;f=src%2Fglatitude.cpp;h=a4da3b64f69e19dc82faefcaf892f237f67a68e2;hp=2f9dcacf50656a62c683a68e828ecef9417af5c3;hb=b80c04a8938fa73c45b5d8a17a1c2b2aab5eab3b;hpb=5a837906fe9cee9952da7c38e0987857b214d63d diff --git a/src/glatitude.cpp b/src/glatitude.cpp index 2f9dcac..a4da3b6 100644 --- a/src/glatitude.cpp +++ b/src/glatitude.cpp @@ -1,54 +1,55 @@ #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::update(double la, double lo, double ac) { + if (login_error) return; + if (!la) return; + if (!lo) return; + if (!ac) return; -void GoogleLatitude::reset() { - lastupdate = 0; - login_error = false; - set(latitude, longitude, accuracy); -} +#if QT_VERSION >= QT_VERSION_CHECK(4, 7, 0) + QNetworkConfigurationManager mgr; + if (!mgr.isOnline()) { + qDebug() << "GoogleLatitude: offline"; + return; + } +#endif + + qDebug() << "GoogleLatitude: update"; -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) { +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(); @@ -78,16 +79,16 @@ void GoogleLatitude::finishedreply(QNetworkReply *r) { QString output = r->readAll(); QRegExp regexp ("Authentication required"); if (regexp.indexIn(output, 1) != -1) { - qDebug() << "GoogleLatitude: update error"; + 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; - emit OK(); + qDebug() << "GoogleLatitude: update ok"; + qDebug() << output; + emit glat_ok(); } } else { - qDebug() << "GoogleLatitude Error url:" << r->url(); + qDebug() << "GoogleLatitude Error url" << r->url(); qDebug() << r->rawHeaderList(); qDebug() << r->readAll(); }