X-Git-Url: http://git.maemo.org/git/?p=googlelatitude;a=blobdiff_plain;f=src%2Flatitude.cpp;h=2d70baa85d024b644ea6a8a0c7eb73b824affece;hp=47e08e1cf58c0da5df1fb44507587f3ed379b055;hb=4c9db197ce7c6a18405695885e4ce59d10bddf05;hpb=dff93640a9b80a22d26ceeea520270cdf31a49e2 diff --git a/src/latitude.cpp b/src/latitude.cpp index 47e08e1..2d70baa 100644 --- a/src/latitude.cpp +++ b/src/latitude.cpp @@ -1,173 +1,112 @@ #include "latitude.h" LatitudeGUI::LatitudeGUI(QMainWindow *parent) : QMainWindow(parent) { - glatitude = new GoogleLatitude(this); - gps = new GpsMaemo5(this); +#ifdef Q_WS_MAEMO_5 + setAttribute(Qt::WA_Maemo5AutoOrientation, true); +#endif + setWindowTitle(tr("Latitude & Buzz")); setting = new QSettings(); - urllogin = QUrl::fromEncoded("https://www.google.com/accounts/ServiceLogin?service=friendview&continue=http://www.google.com/maps/m?mode=latitude"); - - show_lat(); - - 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())); - -} - -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, 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_lat->text().toDouble(), - location_lon->text().toDouble(), - location_acc->text().toDouble()); -} - -void LatitudeGUI::set_OK() { - status->setText(tr("Updated Location !")); -} - -void LatitudeGUI::set_ERROR() { - status->setText(tr("Error in Authentification !")); -} - -void LatitudeGUI::save() { - setting->setValue("user", login_user->text()); - setting->setValue("pass", login_pass->text()); -} -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(); - - // webkit magic + // GUI + url = QUrl::fromEncoded("https://www.google.com/accounts/ServiceLogin?service=friendview&continue=http://www.google.com/maps/m?mode=latitude"); maps = new QWebView(); + maps->settings()->setAttribute(QWebSettings::PluginsEnabled, true); connect(maps, SIGNAL(loadFinished(bool)), this, SLOT(maps_login())); - maps->load(urllogin); + maps->load(url); + 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); - // set widget - setCentralWidget(maps); - setWindowTitle(tr("Google Maps")); + // updater + glatitude = new GoogleLatitude(this); + gps = new GpsMaemo5(this); + connect(gps, SIGNAL(fix()), this, SLOT(set())); + connect(glatitude, SIGNAL(OK()), this, SLOT(latitude_OK())); + connect(glatitude, SIGNAL(ERROR()), this, SLOT(latitude_ERROR())); - // menu - menuBar()->clear(); - menuBar()->addAction(tr("&Latitude") ,this, SLOT(show_lat())); + // show it + setCentralWidget(maps); } -void LatitudeGUI::show_lat() { +void LatitudeGUI::config() { // login input - login_user = new QLineEdit(setting->value("user","my_username").toString()); - login_pass = new QLineEdit(setting->value("pass","my_password").toString()); + 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); - QPushButton *button_update = new QPushButton(tr("Manual &Update")); - // login layout + QLineEdit *login_freq = new QLineEdit(setting->value("freq","120").toString()); 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())); + layout_login->addRow(tr("&Interval"), login_freq); + connect(login_user, SIGNAL(textEdited(QString)), this, SLOT(save_user(QString))); + connect(login_pass, SIGNAL(textEdited(QString)), this, SLOT(save_pass(QString))); + connect(login_freq, SIGNAL(textEdited(QString)), this, SLOT(save_freq(QString))); 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())); + connect(login_pass, SIGNAL(returnPressed()), login_freq, SLOT(setFocus())); + connect(login_freq, SIGNAL(returnPressed()), dialoglogin, SLOT(accept())); + dialoglogin->setLayout(layout_login); + dialoglogin->exec(); + + set(); + mode_latitude(); + glatitude->reset(); +} - // 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())); +void LatitudeGUI::set() { + qDebug() << "LatitudeGUI: set"; + glatitude->login(setting->value("user","my_username").toString(), + setting->value("pass","my_password").toString()); + glatitude->freq(setting->value("freq","120").toInt()); + glatitude->set(gps->get_lat(), + gps->get_lon(), + gps->get_acc()); +} - // 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); +void LatitudeGUI::latitude_OK() { + qDebug() << "LatitudeGUI: send"; +} - // gps enable only on maemo5 -#ifndef Q_WS_MAEMO_5 - source_cell->setDisabled(1); - source_gps->setDisabled(1); +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(); +} - // set widget - setCentralWidget(location); - setWindowTitle(tr("Google Latitude Updater")); +void LatitudeGUI::save_user(QString _user) { + setting->setValue("user", _user); +} +void LatitudeGUI::save_pass(QString _pass) { + setting->setValue("pass", _pass); +} +void LatitudeGUI::save_freq(QString _freq) { + setting->setValue("freq", _freq); +} +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")); +} - // menu - menuBar()->clear(); - menuBar()->addAction(tr("&Maps") ,this, SLOT(show_map())); +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::maps_login() { - if ( maps->url() == urllogin ) { + if ( maps->url() == url ) { maps->page()->mainFrame()->evaluateJavaScript( QString("document.getElementById('Email').value = \"%1\";").arg( setting->value("user").toString())); @@ -177,3 +116,17 @@ void LatitudeGUI::maps_login() { maps->page()->mainFrame()->evaluateJavaScript("document.getElementById('gaia_loginform').submit();"); } } + +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()+"/GoogleLatitudeDaemon"); + qDebug() << "LatitudeGUI: demonio" << QCoreApplication::applicationDirPath()+"/GoogleLatitudeDaemon"; + if ( ! system("killall -0 GoogleLatitudeDaemon 2> /dev/null" ) ) { + demonio->setText(tr("&Stop Daemon")); + } + } +}