From: Rodrigo Linfati Date: Tue, 29 Dec 2009 11:59:23 +0000 (+0100) Subject: version 0.2 X-Git-Url: http://git.maemo.org/git/?p=googlelatitude;a=commitdiff_plain;h=e54b8298b5782a42c123e21578f75df74415cdae version 0.2 --- diff --git a/debian/changelog b/debian/changelog index 75123ed..b301d48 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +googlelatitude (0.2-0) unstable; urgency=low + + * Google Maps via WebKit + + -- Rodrigo Linfati Tue, 29 Dec 2009 12:58:25 +0100 + googlelatitude (0.1-4) unstable; urgency=low * add libgconf2-dev depend... ¿why? diff --git a/debian/control b/debian/control index 8732594..6e7e64c 100644 --- a/debian/control +++ b/debian/control @@ -3,6 +3,7 @@ Section: user/navigation Priority: optional Maintainer: Rodrigo Linfati Build-Depends: debhelper (>= 5), libqt4-maemo5-dev, libgconf2-dev +# Build-Depends: debhelper (>= 5), libqt4-dev Standards-Version: 3.7.2 Package: googlelatitude diff --git a/debian/rules b/debian/rules index 1f7b7fe..ad1ab6f 100755 --- a/debian/rules +++ b/debian/rules @@ -24,6 +24,7 @@ builddir: builddir/Makefile: builddir cd builddir && /opt/qt4-maemo5/bin/qmake-qt4 PREFIX=/usr ../$(APPNAME).pro +# cd builddir && qmake-qt4 PREFIX=/usr ../$(APPNAME).pro build: build-stamp build-stamp: builddir/Makefile diff --git a/src/glatitude.cpp b/src/glatitude.cpp new file mode 100644 index 0000000..4627ac5 --- /dev/null +++ b/src/glatitude.cpp @@ -0,0 +1,84 @@ +#include "glatitude.h" + +GoogleLatitude::GoogleLatitude(QObject *parent) : QObject(parent) { + user = ""; + pass = ""; + latitude = 0.; + longitude = 0.; + accuracy = 0.; + + worker = new QNetworkAccessManager(); + connect(worker, SIGNAL(finished(QNetworkReply *)), this, SLOT(finishedreply(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"); + urlloc = QUrl::fromEncoded("http://www.google.com/loc/json"); +} + +void GoogleLatitude::login(QString u, QString p) { + if ( !u.contains('@') ) u.append("@gmail.com"); + user = u; + pass = p; +} + +void GoogleLatitude::set(double la, double lo, double ac) { + latitude = la; + longitude = lo; + accuracy = ac; + worker->get(QNetworkRequest(urllogin)); +} + +void GoogleLatitude::get() { + QByteArray postloc = QByteArray("{version:\"1.1.0\"}"); + worker->post(QNetworkRequest(urlloc),postloc); +} + +void GoogleLatitude::finishedreply(QNetworkReply *r) { + if ( r->url() == urllogin ) { + QString aidis = r->readAll(); + QRegExp regexp ("type=\"hidden\".*name=\"GALX\".*value=\"(.*)\""); + regexp.setMinimal(1); + regexp.indexIn(aidis, 1); + QString googleGALX = regexp.capturedTexts().last(); + + QByteArray datalogin; + datalogin += "&service=friendview"; + datalogin += "&GALX=" + googleGALX; + datalogin += "&Email=" + user; + datalogin += "&Passwd=" + pass; + worker->post(QNetworkRequest(urldologin), datalogin); + } else if ( r->url() == urldologin ) { + QByteArray datagps; + datagps += "t=ul"; + datagps += "&lat=" + QString::number(latitude); + datagps += "&lng=" + QString::number(longitude); + datagps += "&accuracy=" + QString::number(accuracy); + + QNetworkRequest request(urlupdate); + request.setRawHeader("X-ManualHeader", QString("true").toAscii() ); + worker->post(request, datagps); + } else if ( r->url() == urlupdate ) { + QString output = r->readAll(); + QRegExp regexp ("Authentication required"); + if (regexp.indexIn(output, 1) != -1) { + emit setERROR(); + } else { + emit setOK(); + } + } else 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(); + emit getOK(); + } else { + qDebug() << "Error"; + qDebug() << "url:" << r->url(); + qDebug() << r->rawHeaderList(); + qDebug() << r->readAll(); + } +} diff --git a/src/glatitude.h b/src/glatitude.h new file mode 100644 index 0000000..c3c3273 --- /dev/null +++ b/src/glatitude.h @@ -0,0 +1,43 @@ +#ifndef GLATITUDE_H +#define GLATITUDE_H + +#include + +class GoogleLatitude : public QObject { + Q_OBJECT + +signals: + void setOK(); + void setERROR(); + void getOK(); + +public slots: + void get(); + +public: + GoogleLatitude(QObject *parent = 0); + void login(QString username, QString password); + void set(double latitude, double longitude, double accuracy=1000.); + double get_lat() { return latitude; } + double get_lon() { return longitude; } + double get_acc() { return accuracy; } + +private slots: + void finishedreply(QNetworkReply *r); + +private: + // info + QString user; + QString pass; + double latitude; + double longitude; + double accuracy; + // stuff + QNetworkAccessManager *worker; + QUrl urllogin; + QUrl urldologin; + QUrl urlupdate; + QUrl urlloc; +}; + +#endif // GLATITUDE_H diff --git a/src/googlelatitude.cpp b/src/googlelatitude.cpp deleted file mode 100644 index 3dbb04f..0000000 --- a/src/googlelatitude.cpp +++ /dev/null @@ -1,84 +0,0 @@ -#include "googlelatitude.h" - -GoogleLatitude::GoogleLatitude() { - user = ""; - pass = ""; - latitude = 0.; - longitude = 0.; - accuracy = 0.; - - worker = new QNetworkAccessManager(); - connect(worker, SIGNAL(finished(QNetworkReply *)), this, SLOT(finishedreply(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"); - urlloc = QUrl::fromEncoded("http://www.google.com/loc/json"); -} - -void GoogleLatitude::login(QString u, QString p) { - if ( !u.contains('@') ) u.append("@gmail.com"); - user = u; - pass = p; -} - -void GoogleLatitude::set(double la, double lo, double ac) { - latitude = la; - longitude = lo; - accuracy = ac; - worker->get(QNetworkRequest(urllogin)); -} - -void GoogleLatitude::get() { - QByteArray postloc = QByteArray("{version:\"1.1.0\"}"); - worker->post(QNetworkRequest(urlloc),postloc); -} - -void GoogleLatitude::finishedreply(QNetworkReply *r) { - if ( r->url() == urllogin ) { - QString aidis = r->readAll(); - QRegExp regexp ("type=\"hidden\".*name=\"GALX\".*value=\"(.*)\""); - regexp.setMinimal(1); - regexp.indexIn(aidis, 1); - QString googleGALX = regexp.capturedTexts().last(); - - QByteArray datalogin; - datalogin += "&service=friendview"; - datalogin += "&GALX=" + googleGALX; - datalogin += "&Email=" + user; - datalogin += "&Passwd=" + pass; - worker->post(QNetworkRequest(urldologin), datalogin); - } else if ( r->url() == urldologin ) { - QByteArray datagps; - datagps += "t=ul"; - datagps += "&lat=" + QString::number(latitude); - datagps += "&lng=" + QString::number(longitude); - datagps += "&accuracy=" + QString::number(accuracy); - - QNetworkRequest request(urlupdate); - request.setRawHeader("X-ManualHeader", QString("true").toAscii() ); - worker->post(request, datagps); - } else if ( r->url() == urlupdate ) { - QString output = r->readAll(); - QRegExp regexp ("Authentication required"); - if (regexp.indexIn(output, 1) != -1) { - emit setERROR(); - } else { - emit setOK(); - } - } else 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(); - emit getOK(); - } else { - qDebug() << "Error"; - qDebug() << "url:" << r->url(); - qDebug() << r->rawHeaderList(); - qDebug() << r->readAll(); - } -} diff --git a/src/googlelatitude.h b/src/googlelatitude.h deleted file mode 100644 index 0aebc82..0000000 --- a/src/googlelatitude.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef GOOGLELATITUDE_H -#define GOOGLELATITUDE_H - -#include -#include -#include -#include -#include -#include -#include - -class GoogleLatitude : public QObject { - Q_OBJECT - -signals: - void setOK(); - void setERROR(); - void getOK(); - -public slots: - void get(); - -public: - GoogleLatitude(); - void login(QString username, QString password); - void set(double latitude, double longitude, double accuracy=1000.); - double get_lat() { return latitude; } - double get_lon() { return longitude; } - double get_acc() { return accuracy; } - -private slots: - void finishedreply(QNetworkReply *r); - -private: - // info - QString user; - QString pass; - double latitude; - double longitude; - double accuracy; - // stuff - QNetworkAccessManager *worker; - QUrl urllogin; - QUrl urldologin; - QUrl urlupdate; - QUrl urlloc; -}; - -#endif // GOOGLELATITUDE_H diff --git a/src/latitude.cpp b/src/latitude.cpp new file mode 100644 index 0000000..e56d198 --- /dev/null +++ b/src/latitude.cpp @@ -0,0 +1,99 @@ +#include "latitude.h" + +LatitudeGUI::LatitudeGUI(QMainWindow *parent) : QMainWindow(parent) { + glatitude = new GoogleLatitude(this); + setting = new QSettings(); + maps = new QWebView(); + location = new QWidget(); + + menuBar()->addAction(tr("&Maps") ,this, SLOT(showmap())); + menuBar()->addAction(tr("&Latitude") ,this, SLOT(showlat())); + menuBar()->addAction(tr("&Update"), this, SLOT(set())); + menuBar()->addAction(tr("&loc") ,glatitude, SLOT(get())); + + do_maps(); + do_main(); + showlat(); + + // connects + connect(login_user, SIGNAL(editingFinished()), this, SLOT(save())); + connect(login_pass, SIGNAL(editingFinished()), this, SLOT(save())); + connect(glatitude, SIGNAL(getOK()), this, SLOT(get())); + connect(glatitude, SIGNAL(setOK()), this, SLOT(gsetOK())); + connect(glatitude, SIGNAL(setERROR()), this, SLOT(gsetERROR())); +} + +void LatitudeGUI::get() { + location_lat->setText(QString::number(glatitude->get_lat())); + location_lon->setText(QString::number(glatitude->get_lon())); + location_acc->setText(QString::number(glatitude->get_acc())); + statusBar()->showMessage(tr("Using google.com/loc"),2000); +} + +void LatitudeGUI::set() { + glatitude->login(login_user->text(), + login_pass->text()); + glatitude->set(location_lon->text().toDouble(), + location_lat->text().toDouble(), + location_acc->text().toDouble()); + statusBar()->showMessage(tr("Setting location..."),2000); +} + +void LatitudeGUI::gsetOK() { + statusBar()->showMessage(tr("Location Updated !"),5000); +} +void LatitudeGUI::gsetERROR() { + statusBar()->showMessage(tr("Error in Authentification !"),5000); +} + +void LatitudeGUI::save() { + setting->setValue("user", login_user->text()); + setting->setValue("pass", login_pass->text()); +} + +void LatitudeGUI::showmap() { + setCentralWidget(maps); + setWindowTitle(tr("Google Maps")); +} + +void LatitudeGUI::showlat() { + glatitude->get(); + setCentralWidget(location); + setWindowTitle(tr("Google Latitude Updater")); +} + +void LatitudeGUI::do_maps() { + maps->load(QUrl("http://www.google.com/maps/m")); +} + +void LatitudeGUI::do_main() { + QHBoxLayout *layout = new QHBoxLayout(); + layout->addLayout(do_login()); + layout->addLayout(do_location()); + location->setLayout(layout); +} + +QFormLayout *LatitudeGUI::do_login() { + login_user = new QLineEdit(setting->value("user","my_username").toString()); + login_pass = new QLineEdit(setting->value("pass","my_password").toString()); + login_pass->setEchoMode(QLineEdit::Password); + + QFormLayout *layout = new QFormLayout(); + layout->addRow(tr("&Username"), login_user); + layout->addRow(tr("&Password"), login_pass); + + return layout; +} + +QFormLayout *LatitudeGUI::do_location() { + location_lat = new QLineEdit(QString::number(0)); + location_lon = new QLineEdit(QString::number(0)); + location_acc = new QLineEdit(QString::number(0)); + + QFormLayout *layout = new QFormLayout(); + layout->addRow(tr("lat :"), location_lat); + layout->addRow(tr("lon :"), location_lon); + layout->addRow(tr("acc :"), location_acc); + + return layout; +} diff --git a/src/latitude.h b/src/latitude.h new file mode 100644 index 0000000..5cee90a --- /dev/null +++ b/src/latitude.h @@ -0,0 +1,43 @@ +#ifndef LATITUDE_H +#define LATITUDE_H + +#include +#include +#include "glatitude.h" + +class LatitudeGUI : public QMainWindow { + Q_OBJECT + +public slots: + +public: + LatitudeGUI(QMainWindow *parent = 0); + +private slots: + void get(); + void gsetOK(); + void gsetERROR(); + void set(); + void showmap(); + void showlat(); + void save(); + +private: + GoogleLatitude *glatitude; + QSettings *setting; + QWebView *maps; + QWidget *location; + + QLineEdit *login_user; + QLineEdit *login_pass; + QLineEdit *location_lat; + QLineEdit *location_lon; + QLineEdit *location_acc; + + void do_maps(); + QFormLayout *do_login(); + QFormLayout *do_location(); + void do_main(); +}; + +#endif // LATITUDE_H diff --git a/src/latitudewidget.cpp b/src/latitudewidget.cpp deleted file mode 100644 index 1647fb9..0000000 --- a/src/latitudewidget.cpp +++ /dev/null @@ -1,102 +0,0 @@ -#include "latitudewidget.h" - -LatitudeWidget::LatitudeWidget() { - load(); - glatitude.get(); - timer = new QTimer(); - // login - login_user = new QLineEdit(); - login_user->setText(user); - login_pass = new QLineEdit(); - login_pass->setText(pass); - login_pass->setEchoMode(QLineEdit::Password); - login_up = new QPushButton(tr("&Update Location")); - login_layout = new QFormLayout(); - login_layout->addRow(tr("&Username"), login_user); - login_layout->addRow(tr("&Password"), login_pass); - login_layout->addRow(login_up); - // location - location_lat = new QLineEdit(); - location_lat ->setText(QString::number(latitude)); - location_lon = new QLineEdit(); - location_lon->setText(QString::number(longitude)); - location_acc = new QLineEdit(); - location_acc->setText(QString::number(accuracy)); - location_layout = new QFormLayout(); - location_layout->addRow(tr("lat :"), location_lat); - location_layout->addRow(tr("lon :"), location_lon); - location_layout->addRow(tr("acc :"), location_acc); - // window - menu = new QWidget(); - menu->setWindowTitle(tr("Google Latitude Updater")); - menu_layout = new QHBoxLayout(); - menu_layout->addLayout(login_layout); - menu_layout->addLayout(location_layout); - menu->setLayout(menu_layout); - menu->show(); - - connect(login_up, SIGNAL(clicked()), this, SLOT(set())); - connect(timer, SIGNAL(timeout()), this, SLOT(gset())); - connect(&glatitude, SIGNAL(getOK()), this, SLOT(get())); - connect(&glatitude, SIGNAL(setOK()), this, SLOT(gsetOK())); - connect(&glatitude, SIGNAL(setERROR()), this, SLOT(gsetERROR())); -} - -void LatitudeWidget::get() { - location_lat->setText(QString::number(glatitude.get_lat())); - location_lon->setText(QString::number(glatitude.get_lon())); - location_acc->setText(QString::number(glatitude.get_acc())); -} - -void LatitudeWidget::set() { - save(); - glatitude.login(user, pass); - glatitude.set(latitude, longitude, accuracy); -} - -void LatitudeWidget::gsetOK() { - login_up->setText(tr("Location Updated !")); - timer->start(5000); -} -void LatitudeWidget::gsetERROR() { - login_up->setText(tr("Error in Authentification !")); - timer->start(2000); -} - -void LatitudeWidget::gset() { - login_up->setText(tr("&Update Location")); -} - -void LatitudeWidget::load() { - // from file - if ( QFile::exists(QDir::homePath()+"/.glatitude") ) { - QFile *config = new QFile(QDir::homePath()+"/.glatitude"); - config->open(QIODevice::ReadOnly); - QTextStream sconfig(config); - sconfig >> user >> pass; - sconfig >> latitude >> longitude >> accuracy; - config->close(); - } else { - user = "my_username"; - pass = "my_password"; - latitude = 0.; - longitude = 0.; - accuracy = 0.; - } -} - -void LatitudeWidget::save() { - // extract info - user = login_user->text(); - pass = login_pass->text(); - latitude = location_lat->text().toDouble(); - longitude = location_lon->text().toDouble(); - accuracy = location_acc->text().toDouble(); - // to file - QFile *config = new QFile(QDir::homePath()+"/.glatitude"); - config->open(QIODevice::WriteOnly); - QTextStream sconfig(config); - sconfig << user << " " << pass << " "; - sconfig << latitude << " " << longitude << " " << accuracy; - config->close(); -} diff --git a/src/latitudewidget.h b/src/latitudewidget.h deleted file mode 100644 index 6921a14..0000000 --- a/src/latitudewidget.h +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef LATITUDEWIDGET_H -#define LATITUDEWIDGET_H - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "googlelatitude.h" - -class LatitudeWidget : public QObject { - Q_OBJECT - -public slots: - void get(); - void gsetOK(); - void gsetERROR(); - void gset(); - -public: - LatitudeWidget(); - -private slots: - void set(); - void save(); - void load(); - -private: - GoogleLatitude glatitude; - // info - QString user; - QString pass; - double latitude; - double longitude; - double accuracy; - // gui - QWidget *menu; - QHBoxLayout *menu_layout; - // login - QFormLayout *login_layout; - QLineEdit *login_user; - QLineEdit *login_pass; - QPushButton *login_up; - // location - QFormLayout *location_layout; - QLineEdit *location_lat; - QLineEdit *location_lon; - QLineEdit *location_acc; - // stuff - QTimer *timer; -}; - -#endif // LATITUDEWIDGET_H diff --git a/src/main.cpp b/src/main.cpp index 3d4f8e0..a80b29c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,10 +1,13 @@ -#include -#include "latitudewidget.h" +#include "latitude.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); + QCoreApplication::setOrganizationName("linfati"); + QCoreApplication::setOrganizationDomain("linfati.com"); + QCoreApplication::setApplicationName("GoogleLatitude"); - LatitudeWidget gui; + LatitudeGUI *gui = new LatitudeGUI(); + gui->show(); return app.exec(); } diff --git a/src/src.pro b/src/src.pro index a2062b9..553e763 100644 --- a/src/src.pro +++ b/src/src.pro @@ -1,31 +1,34 @@ QT += network +QT += webkit + TARGET = GoogleLatitude TEMPLATE = app SOURCES += main.cpp \ - latitudewidget.cpp \ - googlelatitude.cpp -HEADERS += latitudewidget.h \ - googlelatitude.h - -unix { - isEmpty(PREFIX) { - PREFIX = /usr/local - } - BINDIR = $$PREFIX/bin - DATADIR = $$PREFIX/share - DEFINES += DATADIR=\"$$DATADIR\" PKGDATADIR=\"$$PKGDATADIR\" - - INSTALLS += target desktop iconxpm icon26 icon40 icon64 - target.path = $$BINDIR - desktop.path = $$DATADIR/applications/hildon - desktop.files += $${TARGET}.desktop - iconxpm.path = $$DATADIR/pixmap - iconxpm.files += ../data/maemo/$${TARGET}.xpm - icon26.path = $$DATADIR/icons/hicolor/26x26/apps - icon26.files += ../data/26x26/$${TARGET}.png - icon40.path = $$DATADIR/icons/hicolor/40x40/apps - icon40.files += ../data/40x40/$${TARGET}.png - icon64.path = $$DATADIR/icons/hicolor/64x64/apps - icon64.files += ../data/64x64/$${TARGET}.png + latitude.cpp \ + glatitude.cpp +HEADERS += latitude.h \ + glatitude.h +unix { + isEmpty(PREFIX):PREFIX = /usr/local + BINDIR = $$PREFIX/bin + DATADIR = $$PREFIX/share + DEFINES += DATADIR=\"$$DATADIR\" \ + PKGDATADIR=\"$$PKGDATADIR\" + INSTALLS += target \ + desktop \ + iconxpm \ + icon26 \ + icon40 \ + icon64 + target.path = $$BINDIR + desktop.path = $$DATADIR/applications/hildon + desktop.files += $${TARGET}.desktop + iconxpm.path = $$DATADIR/pixmap + iconxpm.files += ../data/maemo/$${TARGET}.xpm + icon26.path = $$DATADIR/icons/hicolor/26x26/apps + icon26.files += ../data/26x26/$${TARGET}.png + icon40.path = $$DATADIR/icons/hicolor/40x40/apps + icon40.files += ../data/40x40/$${TARGET}.png + icon64.path = $$DATADIR/icons/hicolor/64x64/apps + icon64.files += ../data/64x64/$${TARGET}.png } -