X-Git-Url: http://git.maemo.org/git/?p=googlelatitude;a=blobdiff_plain;f=src%2Flatitude.cpp;h=c782c2f40fd8de2cd89a2b44ed14b7b6e941ed63;hp=e56d1981eaef68a8e1460ad59a5992daeadb59ec;hb=016de1e3a5f9819bf2662e9a9e89868472149a56;hpb=e54b8298b5782a42c123e21578f75df74415cdae diff --git a/src/latitude.cpp b/src/latitude.cpp index e56d198..c782c2f 100644 --- a/src/latitude.cpp +++ b/src/latitude.cpp @@ -3,46 +3,44 @@ LatitudeGUI::LatitudeGUI(QMainWindow *parent) : QMainWindow(parent) { glatitude = new GoogleLatitude(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(); - - // 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())); + connect(glatitude, SIGNAL(getOK()), this, SLOT(get_loc())); + connect(glatitude, SIGNAL(setOK()), this, SLOT(set_OK())); + connect(glatitude, SIGNAL(setERROR()), this, SLOT(set_ERROR())); } -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); } +void LatitudeGUI::get_cell() { + statusBar()->showMessage(tr("Using cell... TODO"),2000); +} + +void LatitudeGUI::get_gps() { + statusBar()->showMessage(tr("Using gps... TODO"),2000); +} + 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() { +void LatitudeGUI::set_OK() { statusBar()->showMessage(tr("Location Updated !"),5000); } -void LatitudeGUI::gsetERROR() { + +void LatitudeGUI::set_ERROR() { statusBar()->showMessage(tr("Error in Authentification !"),5000); } @@ -51,49 +49,92 @@ void LatitudeGUI::save() { setting->setValue("pass", login_pass->text()); } -void LatitudeGUI::showmap() { +void LatitudeGUI::show_map() { + // webkit magic + maps = new QWebView(); + connect(maps, SIGNAL(loadFinished(bool)), this, SLOT(maps_login())); + maps->load(urllogin); + + // set widget setCentralWidget(maps); setWindowTitle(tr("Google Maps")); -} -void LatitudeGUI::showlat() { - glatitude->get(); - setCentralWidget(location); - setWindowTitle(tr("Google Latitude Updater")); + // menu + menuBar()->clear(); + menuBar()->addAction(tr("&Latitude") ,this, SLOT(show_lat())); + setStatusBar(0); } -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() { +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("&Update Location")); + // 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("&loc")); + QPushButton *source_cell = new QPushButton(tr("&cell")); + QPushButton *source_gps = new QPushButton(tr("&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()), this, SLOT(get_cell())); + connect(source_gps, SIGNAL(clicked()), this, SLOT(get_gps())); + + // main layout + location = new QWidget(); + QHBoxLayout *layout_form = new QHBoxLayout(); + layout_form->addLayout(layout_login); + layout_form->addLayout(layout_location); + QVBoxLayout *layout = new QVBoxLayout(); + layout->addLayout(layout_form); + 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())); + statusBar()->showMessage(tr("Ready")); +} - 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();"); + } }