X-Git-Url: http://git.maemo.org/git/?p=googlelatitude;a=blobdiff_plain;f=src%2Flatitude.cpp;h=b1b89c1681c8ce4b7bedf7d05f7219b81ee6d17a;hp=32f76cc6367cba2960a38ccdaaca4ffe96afb93a;hb=02be583c183b90011cf9eb4b3f9a069ab2b6a8b7;hpb=14e23ff7dcbc3dbfbc4377880c4f7f4a5e8a1586 diff --git a/src/latitude.cpp b/src/latitude.cpp index 32f76cc..b1b89c1 100644 --- a/src/latitude.cpp +++ b/src/latitude.cpp @@ -1,99 +1,180 @@ #include "latitude.h" LatitudeGUI::LatitudeGUI(QMainWindow *parent) : QMainWindow(parent) { - glatitude = new GoogleLatitude(this); setting = new QSettings(); + gps = new GpsMaemo5(this); + glatitude = new GoogleLatitude(this); + + connect(gps, SIGNAL(fix()), this, SLOT(set())); + connect(glatitude, SIGNAL(glat_ok()), this, SLOT(latitude_ok())); + connect(glatitude, SIGNAL(glat_error()), this, SLOT(latitude_error())); + + set_config(); + if ( 0 ) gps->config(15, 3, 0); + + gps->refresh(); + +#ifdef Q_WS_MAEMO_5 + setAttribute(Qt::WA_Maemo5AutoOrientation, true); +#endif + setWindowTitle(tr("Latitude & Buzz")); + 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())); -} + connect(maps, SIGNAL(loadFinished(bool)), this, SLOT(maps_login())); + + maps->settings()->setAttribute(QWebSettings::PluginsEnabled, true); + maps->load(QUrl::fromEncoded("https://www.google.com/accounts/ServiceLogin?service=friendview&continue=http://www.google.com/maps/m?mode=latitude")); + + setCentralWidget(maps); -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); + menuBar()->addAction(tr("&Latitude"), this, SLOT(mode_latitude())); + menuBar()->addAction(tr("&Buzz"), this, SLOT(mode_buzz())); + menuBar()->addAction(tr("&Config"), this, SLOT(config())); + + demonio = new QAction(this); + if ( system("killall -0 GoogleLatitudeDaemon 2> /dev/null" ) ) { + demonio->setText(tr("&Start Daemon")); + } else { + demonio->setText(tr("&Stop Daemon")); + } + connect(demonio, SIGNAL(triggered()), this, SLOT(mode_demonio())); + menuBar()->addAction(demonio); } void LatitudeGUI::set() { - glatitude->login(login_user->text(), - login_pass->text()); - glatitude->set(location_lat->text().toDouble(), - location_lon->text().toDouble(), - location_acc->text().toDouble()); - statusBar()->showMessage(tr("Setting location..."),2000); + qDebug() << "LatitudeGUI: set"; + glatitude->update(gps->get_lat(), + gps->get_lon(), + gps->get_acc()); } -void LatitudeGUI::gsetOK() { - statusBar()->showMessage(tr("Location Updated !"),5000); -} -void LatitudeGUI::gsetERROR() { - statusBar()->showMessage(tr("Error in Authentification !"),5000); -} +void LatitudeGUI::set_config() { + qDebug() << "LatitudeGUI: set_config"; + glatitude->set_login(setting->value("user","my_username").toString(), + setting->value("pass","my_password").toString()); -void LatitudeGUI::save() { - setting->setValue("user", login_user->text()); - setting->setValue("pass", login_pass->text()); + gps->config(setting->value("interval",1800).toInt(), + setting->value("wait",30).toInt(), + setting->value("usegps",false).toBool()); } -void LatitudeGUI::showmap() { - setCentralWidget(maps); - setWindowTitle(tr("Google Maps")); +void LatitudeGUI::latitude_ok() { + qDebug() << "LatitudeGUI: ok"; } -void LatitudeGUI::showlat() { - glatitude->get(); - setCentralWidget(location); - setWindowTitle(tr("Google Latitude Updater")); +void LatitudeGUI::latitude_error() { +#ifdef Q_WS_MAEMO_5 + QString error_message = tr("Error in Authentification!

") + + tr("Plese verify your login details
"); + QMaemo5InformationBox::information(this, error_message, + QMaemo5InformationBox::NoTimeout); +#endif + qDebug() << "LatitudeGUI: no auth"; + config(); } -void LatitudeGUI::do_maps() { - maps->load(QUrl("http://www.google.com/maps/m")); +void LatitudeGUI::maps_login() { + if ( maps->url() == QUrl::fromEncoded("https://www.google.com/accounts/ServiceLogin?service=friendview&continue=http://www.google.com/maps/m?mode=latitude") ) { + 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();"); + } + if ( maps->url() == QUrl::fromEncoded("https://www.google.com/accounts/ServiceLoginAuth") ) { + latitude_error(); + } } -void LatitudeGUI::do_main() { - QHBoxLayout *layout = new QHBoxLayout(); - layout->addLayout(do_login()); - layout->addLayout(do_location()); - location->setLayout(layout); +void LatitudeGUI::mode_buzz() { + maps->load(QUrl::fromEncoded("http://www.google.com/maps/m?l-view=map&l-lci=m,com.google.latitudepublicupdates&ac=f,s,l")); } -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); +void LatitudeGUI::mode_latitude() { + maps->load(QUrl::fromEncoded("https://www.google.com/accounts/ServiceLogin?service=friendview&continue=http://www.google.com/maps/m?mode=latitude")); +} - return layout; +void LatitudeGUI::mode_demonio() { + if ( ! system("killall -0 GoogleLatitudeDaemon 2> /dev/null" ) ) { + system("killall GoogleLatitudeDaemon 2> /dev/null"); + demonio->setText(tr("&Start Daemon")); + } else { + QProcess *cli = new QProcess(this); + cli->start(QCoreApplication::applicationDirPath()+QDir::separator()+"GoogleLatitudeDaemon"); + qDebug() << "LatitudeGUI: demonio" << QCoreApplication::applicationDirPath()+"/GoogleLatitudeDaemon"; + if ( ! system("killall -0 GoogleLatitudeDaemon 2> /dev/null" ) ) { + demonio->setText(tr("&Stop Daemon")); + } + } } -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)); +void LatitudeGUI::config() { + gps->forcestop(); - QFormLayout *layout = new QFormLayout(); - layout->addRow(tr("lat :"), location_lat); - layout->addRow(tr("lon :"), location_lon); - layout->addRow(tr("acc :"), location_acc); + QDialog *dialoglogin = new QDialog(this); - return layout; + QLineEdit *login_user = new QLineEdit(setting->value("user","my_username").toString()); + QLineEdit *login_pass = new QLineEdit(setting->value("pass","my_password").toString()); + login_pass->setEchoMode(QLineEdit::Password); + + QLineEdit *gps_interval = new QLineEdit(setting->value("interval",1800).toString()); + QLineEdit *gps_wait = new QLineEdit(setting->value("wait",30).toString()); + QCheckBox *gps_use = new QCheckBox(); + if ( setting->value("usegps",false).toBool() ) { + gps_use->setCheckState(Qt::Checked); + } else { + gps_use->setCheckState(Qt::Unchecked); + } + + QCheckBox *daemon_use = new QCheckBox(); + if ( setting->value("daemon",false).toBool() ) { + daemon_use->setCheckState(Qt::Checked); + } else { + daemon_use->setCheckState(Qt::Unchecked); + } + + QFormLayout *layout_config = new QFormLayout(); + layout_config->addRow(tr("&Username"), login_user); + layout_config->addRow(tr("&Password"), login_pass); + layout_config->addRow(tr("&Interval for Updates"), gps_interval); + layout_config->addRow(tr("&Wait for a Fix"), gps_wait); + layout_config->addRow(tr("&Use Gps"), gps_use); + layout_config->addRow(tr("&Daemon at Boot"), daemon_use); + + connect(login_user, SIGNAL(textEdited(QString)), this, SLOT(save_user(QString))); + connect(login_user, SIGNAL(returnPressed()), login_pass, SLOT(setFocus())); + connect(login_pass, SIGNAL(textEdited(QString)), this, SLOT(save_pass(QString))); + connect(login_pass, SIGNAL(returnPressed()), dialoglogin, SLOT(accept())); + + connect(gps_interval, SIGNAL(textEdited(QString)), this, SLOT(save_interval(QString))); + connect(gps_wait, SIGNAL(textEdited(QString)), this, SLOT(save_wait(QString))); + connect(gps_use, SIGNAL(stateChanged(int)), this, SLOT(save_gps(int))); + connect(daemon_use, SIGNAL(stateChanged(int)), this, SLOT(save_daemon(int))); + + dialoglogin->setLayout(layout_config); + dialoglogin->exec(); + + if ( setting->value("interval",1800).toInt() < 300 ) + setting->setValue("interval", 300); + if ( setting->value("interval",1800).toInt() > 3600 ) + setting->setValue("interval", 3600); + + if ( setting->value("usegps",false).toBool() ) { + if ( setting->value("wait",30).toInt() < 15 ) + setting->setValue("wait", 15); + } else { + if ( setting->value("wait",30).toInt() < 5 ) + setting->setValue("wait", 5); + } + if ( setting->value("wait",30).toInt() > 120 ) + setting->setValue("wait", 120); + + set_config(); + glatitude->reset(); + gps->refresh(); + + mode_latitude(); } +