X-Git-Url: http://git.maemo.org/git/?p=googlelatitude;a=blobdiff_plain;f=src%2Flatitude.cpp;h=5f6038a01bee3c3ca287ff13df52c20d5e9d7fe8;hp=00e7243cfde6e82402bec51832f48aaed3233204;hb=f66076c2991b0519cde383b2d09167333d55f5d6;hpb=af7af90b9dab32ebb788a5b598ee8a61cdff5315 diff --git a/src/latitude.cpp b/src/latitude.cpp index 00e7243..5f6038a 100644 --- a/src/latitude.cpp +++ b/src/latitude.cpp @@ -1,136 +1,80 @@ #include "latitude.h" LatitudeGUI::LatitudeGUI(QMainWindow *parent) : QMainWindow(parent) { - glatitude = new GoogleLatitude(this); setting = new QSettings(); - urllogin = QUrl::fromEncoded("https://www.google.com/accounts/ServiceLogin?service=friendview&continue=http://www.google.com/maps/m?mode=latitude"); + gps = new GpsMaemo5(this); + glatitude = new GoogleLatitude(this); - show_lat(); + 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())); - connect(glatitude, SIGNAL(getOK()), this, SLOT(get_loc())); - connect(glatitude, SIGNAL(setOK()), this, SLOT(set_OK())); - connect(glatitude, SIGNAL(setERROR()), this, SLOT(set_ERROR())); -} + set_config(); + if ( 0 ) gps->config(15, 3, 0); -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())); - status->setText(tr("Using google.com/loc")); -} + gps->refresh(); -void LatitudeGUI::get_cell() { - status->setText(tr("Using cell... TODO")); -} +#ifdef Q_WS_MAEMO_5 + setAttribute(Qt::WA_Maemo5AutoOrientation, true); +#endif + setWindowTitle(tr("Latitude & Buzz")); -void LatitudeGUI::get_gps() { - status->setText(tr("Using gps... TODO")); -} + maps = new QWebView(); + connect(maps, SIGNAL(loadFinished(bool)), this, SLOT(maps_login())); -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()); - status->setText(tr("Setting location...")); -} + 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")); -void LatitudeGUI::set_OK() { - status->setText(tr("Location Updated !")); -} + setCentralWidget(maps); -void LatitudeGUI::set_ERROR() { - status->setText(tr("Error in Authentification !")); + 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::save() { - setting->setValue("user", login_user->text()); - setting->setValue("pass", login_pass->text()); +void LatitudeGUI::set() { + qDebug() << "LatitudeGUI: set"; + glatitude->update(gps->get_lat(), + gps->get_lon(), + gps->get_acc()); } -void LatitudeGUI::show_map() { - // webkit magic - maps = new QWebView(); - connect(maps, SIGNAL(loadFinished(bool)), this, SLOT(maps_login())); - maps->load(urllogin); +void LatitudeGUI::set_config() { + qDebug() << "LatitudeGUI: set_config"; + glatitude->set_login(setting->value("user","my_username").toString(), + setting->value("pass","my_password").toString()); - // set widget - setCentralWidget(maps); - setWindowTitle(tr("Google Maps")); + gps->config(setting->value("interval",1800).toInt(), + setting->value("wait",30).toInt(), + setting->value("method","cell").toString()); +} - // menu - menuBar()->clear(); - menuBar()->addAction(tr("&Latitude") ,this, SLOT(show_lat())); +void LatitudeGUI::latitude_ok() { + qDebug() << "LatitudeGUI: ok"; } -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())); - - // 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(); - status = new QLineEdit("Ready"); - status->setReadOnly(true); - status->setDisabled(true); - layout->addLayout(layout_form); - layout->addWidget(status); - layout->addLayout(layout_source); - location->setLayout(layout); - - // set widget - setCentralWidget(location); - setWindowTitle(tr("Google Latitude Updater")); - - // menu - menuBar()->clear(); - menuBar()->addAction(tr("&Maps") ,this, SLOT(show_map())); +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::maps_login() { - if ( maps->url() == urllogin ) { + 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())); @@ -139,4 +83,114 @@ void LatitudeGUI::maps_login() { 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::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")); +} + +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")); +} + +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->startDetached(QCoreApplication::applicationDirPath()+QDir::separator()+"GoogleLatitudeDaemon"); + qDebug() << "LatitudeGUI: demonio" << QCoreApplication::applicationDirPath()+QDir::separator()+"GoogleLatitudeDaemon"; + if ( ! system("killall -0 GoogleLatitudeDaemon 2> /dev/null" ) ) { + demonio->setText(tr("&Stop Daemon")); + } + } } + +void LatitudeGUI::config() { + gps->forcestop(); + + QDialog *dialoglogin = new QDialog(this); + + 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 *daemon_use = new QCheckBox(); + if ( setting->value("daemon",false).toBool() ) { + daemon_use->setCheckState(Qt::Checked); + } else { + daemon_use->setCheckState(Qt::Unchecked); + } + + QRadioButton *gps_cell = new QRadioButton(tr("&Cell Tower")); + QRadioButton *gps_both = new QRadioButton(tr("&Both")); + QRadioButton *gps_agps = new QRadioButton(tr("Only &Gps")); + + QString gps_setting = setting->value("method","cell").toString(); + if ( gps_setting == QString("cell") ) { + gps_cell->setChecked(true); + } else if ( gps_setting == QString("both") ) { + gps_both->setChecked(true); + } else if ( gps_setting == QString("agps") ) { + gps_agps->setChecked(true); + } else { + gps_cell->setChecked(true); + } + + QFormLayout *layout_form = new QFormLayout(); + + layout_form->addRow(tr("&Username"), login_user); + layout_form->addRow(tr("&Password"), login_pass); + 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())); + + layout_form->addRow(tr("&Interval for Updates"), gps_interval); + layout_form->addRow(tr("&Wait for a Fix"), gps_wait); + layout_form->addRow(tr("&Daemon at Boot"), daemon_use); + connect(gps_interval, SIGNAL(textEdited(QString)), this, SLOT(save_interval(QString))); + connect(gps_wait, SIGNAL(textEdited(QString)), this, SLOT(save_wait(QString))); + connect(daemon_use, SIGNAL(stateChanged(int)), this, SLOT(save_daemon(int))); + + QHBoxLayout *layout_gps = new QHBoxLayout; + layout_gps->addWidget(gps_cell); + layout_gps->addWidget(gps_both); + layout_gps->addWidget(gps_agps); + layout_form->addRow(layout_gps); + connect(gps_cell, SIGNAL(clicked()), this, SLOT(save_gps_cell())); + connect(gps_both, SIGNAL(clicked()), this, SLOT(save_gps_both())); + connect(gps_agps, SIGNAL(clicked()), this, SLOT(save_gps_agps())); + + dialoglogin->setLayout(layout_form); + 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 ( QString("agps") == setting->value("method","cell").toString() ) { + 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(); +} +