X-Git-Url: http://git.maemo.org/git/?p=googlelatitude;a=blobdiff_plain;f=src%2Flatitude.cpp;h=40a0a13a064a424880216cbcbdfb1cb45cee667f;hp=e56d1981eaef68a8e1460ad59a5992daeadb59ec;hb=040c0c504442b8b73b29d04c5e7931968de50f09;hpb=e54b8298b5782a42c123e21578f75df74415cdae diff --git a/src/latitude.cpp b/src/latitude.cpp index e56d198..40a0a13 100644 --- a/src/latitude.cpp +++ b/src/latitude.cpp @@ -2,48 +2,68 @@ LatitudeGUI::LatitudeGUI(QMainWindow *parent) : QMainWindow(parent) { glatitude = new GoogleLatitude(this); + gps = new GpsMaemo5(this); setting = new QSettings(); - maps = new QWebView(); - location = new QWidget(); + urllogin = QUrl::fromEncoded("https://www.google.com/accounts/ServiceLogin?service=friendview&continue=http://www.google.com/maps/m?mode=latitude"); - 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())); + show_lat(); - do_maps(); - do_main(); - showlat(); + connect(glatitude, SIGNAL(getOK()), this, SLOT(get_loc())); + connect(gps, SIGNAL(getOK()), this, SLOT(get_maemo5())); + connect(gps, SIGNAL(getOK_acwp()), this, SLOT(get_acwp())); + connect(gps, SIGNAL(getOK_agnss()), this, SLOT(get_agnss())); + connect(glatitude, SIGNAL(setOK()), this, SLOT(set_OK())); + connect(glatitude, SIGNAL(setERROR()), this, SLOT(set_ERROR())); + connect(this, SIGNAL(newpos()), this, SLOT(set())); - // 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() { +void LatitudeGUI::get_loc() { 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); + status->setText(tr("Using google.com/loc, ip-based" )); + emit newpos(); +} + +void LatitudeGUI::get_maemo5() { + location_lat->setText(QString::number(gps->get_lat())); + location_lon->setText(QString::number(gps->get_lon())); + location_acc->setText(QString::number(gps->get_acc())); + status->setText(tr("Using liblocation ")); + emit newpos(); +} + +void LatitudeGUI::get_acwp() { + location_lat->setText(QString::number(gps->get_lat())); + location_lon->setText(QString::number(gps->get_lon())); + location_acc->setText(QString::number(gps->get_acc())); + status->setText(tr("Using acwp, cell-based ")); + emit newpos(); +} + +void LatitudeGUI::get_agnss() { + location_lat->setText(QString::number(gps->get_lat())); + location_lon->setText(QString::number(gps->get_lon())); + location_acc->setText(QString::number(gps->get_acc())); + status->setText(tr("Using agnss, gps-based ")); + emit newpos(); } void LatitudeGUI::set() { glatitude->login(login_user->text(), login_pass->text()); - glatitude->set(location_lon->text().toDouble(), - location_lat->text().toDouble(), + glatitude->set(location_lat->text().toDouble(), + location_lon->text().toDouble(), location_acc->text().toDouble()); - statusBar()->showMessage(tr("Setting location..."),2000); } -void LatitudeGUI::gsetOK() { - statusBar()->showMessage(tr("Location Updated !"),5000); +void LatitudeGUI::set_OK() { + status->setText(tr("Updated Location !")); } -void LatitudeGUI::gsetERROR() { - statusBar()->showMessage(tr("Error in Authentification !"),5000); + +void LatitudeGUI::set_ERROR() { + status->setText(tr("Error in Authentification !")); } void LatitudeGUI::save() { @@ -51,49 +71,103 @@ void LatitudeGUI::save() { setting->setValue("pass", login_pass->text()); } -void LatitudeGUI::showmap() { - setCentralWidget(maps); - setWindowTitle(tr("Google Maps")); -} +void LatitudeGUI::show_map() { + // no scrash and stop gps + location_lat = new QLineEdit(QString::number(0)); + location_lon = new QLineEdit(QString::number(0)); + location_acc = new QLineEdit(QString::number(0)); + status = new QLineEdit("Ready"); + login_user = new QLineEdit(setting->value("user","my_username").toString()); + login_pass = new QLineEdit(setting->value("pass","my_password").toString()); + gps->stop(); -void LatitudeGUI::showlat() { - glatitude->get(); - setCentralWidget(location); - setWindowTitle(tr("Google Latitude Updater")); -} + // webkit magic + maps = new QWebView(); + connect(maps, SIGNAL(loadFinished(bool)), this, SLOT(maps_login())); + maps->load(urllogin); -void LatitudeGUI::do_maps() { - maps->load(QUrl("http://www.google.com/maps/m")); -} + // set widget + setCentralWidget(maps); + setWindowTitle(tr("Google Maps")); -void LatitudeGUI::do_main() { - QHBoxLayout *layout = new QHBoxLayout(); - layout->addLayout(do_login()); - layout->addLayout(do_location()); - location->setLayout(layout); + // menu + menuBar()->clear(); + menuBar()->addAction(tr("&Latitude") ,this, SLOT(show_lat())); } -QFormLayout *LatitudeGUI::do_login() { +void LatitudeGUI::show_lat() { + // login input 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); + QPushButton *button_update = new QPushButton(tr("Manual &Update")); + // login layout + QFormLayout *layout_login = new QFormLayout(); + layout_login->addRow(tr("&Username"), login_user); + layout_login->addRow(tr("&Password"), login_pass); + layout_login->addRow(button_update); + // login connect + connect(login_user, SIGNAL(editingFinished()), this, SLOT(save())); + connect(login_pass, SIGNAL(editingFinished()), this, SLOT(save())); + connect(login_user, SIGNAL(returnPressed()), login_pass, SLOT(setFocus())); + connect(login_pass, SIGNAL(returnPressed()), this, SLOT(set())); + connect(button_update, SIGNAL(clicked()), this, SLOT(set())); - QFormLayout *layout = new QFormLayout(); - layout->addRow(tr("&Username"), login_user); - layout->addRow(tr("&Password"), login_pass); - - return layout; -} - -QFormLayout *LatitudeGUI::do_location() { + // location input location_lat = new QLineEdit(QString::number(0)); location_lon = new QLineEdit(QString::number(0)); location_acc = new QLineEdit(QString::number(0)); + // location layout + QFormLayout *layout_location = new QFormLayout(); + layout_location->addRow(tr("lat :"), location_lat); + layout_location->addRow(tr("lon :"), location_lon); + layout_location->addRow(tr("acc :"), location_acc); + + // source button + QPushButton *source_loc = new QPushButton(tr("Update with &IP")); + QPushButton *source_cell = new QPushButton(tr("Update with &Cell")); + QPushButton *source_gps = new QPushButton(tr("Update with &Gps")); + // source layout + QHBoxLayout *layout_source = new QHBoxLayout(); + layout_source->addWidget(source_loc); + layout_source->addWidget(source_cell); + layout_source->addWidget(source_gps); + // source connect + connect(source_loc, SIGNAL(clicked()), glatitude, SLOT(get())); + connect(source_cell, SIGNAL(clicked()), gps, SLOT(get_acwp())); + connect(source_gps, SIGNAL(clicked()), gps, SLOT(get_agnss())); + + // main layout + location = new QWidget(); + QHBoxLayout *layout_form = new QHBoxLayout(); + layout_form->addLayout(layout_login); + layout_form->addLayout(layout_location); + QVBoxLayout *layout = new QVBoxLayout(); + status = new QLineEdit("Ready"); + status->setReadOnly(true); + status->setDisabled(true); + layout->addLayout(layout_form); + layout->addWidget(status); + layout->addLayout(layout_source); + location->setLayout(layout); - QFormLayout *layout = new QFormLayout(); - layout->addRow(tr("lat :"), location_lat); - layout->addRow(tr("lon :"), location_lon); - layout->addRow(tr("acc :"), location_acc); + // set widget + setCentralWidget(location); + setWindowTitle(tr("Google Latitude Updater")); + + // menu + menuBar()->clear(); + menuBar()->addAction(tr("&Maps") ,this, SLOT(show_map())); +} - return layout; +void LatitudeGUI::maps_login() { + if ( maps->url() == urllogin ) { + maps->page()->mainFrame()->evaluateJavaScript( + QString("document.getElementById('Email').value = \"%1\";").arg( + setting->value("user").toString())); + maps->page()->mainFrame()->evaluateJavaScript( + QString("document.getElementById('Passwd').value = \"%1\";").arg( + setting->value("pass").toString())); + maps->page()->mainFrame()->evaluateJavaScript("document.getElementById('gaia_loginform').submit();"); + } }