3 LatitudeGUI::LatitudeGUI(QMainWindow *parent) : QMainWindow(parent) {
4 setting = new QSettings();
5 gps = new GpsMaemo5(this);
6 glatitude = new GoogleLatitude(this);
8 connect(gps, SIGNAL(fix()), this, SLOT(set()));
9 connect(glatitude, SIGNAL(glat_ok()), this, SLOT(latitude_ok()));
10 connect(glatitude, SIGNAL(glat_error()), this, SLOT(latitude_error()));
13 if ( 0 ) gps->config(15, 3, 0);
18 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
20 setWindowTitle(tr("Latitude & Buzz"));
22 maps = new QWebView();
23 connect(maps, SIGNAL(loadFinished(bool)), this, SLOT(maps_login()));
25 maps->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
26 maps->load(QUrl::fromEncoded("https://www.google.com/accounts/ServiceLogin?service=friendview&continue=http://www.google.com/maps/m?mode=latitude"));
28 setCentralWidget(maps);
30 menuBar()->addAction(tr("&Latitude"), this, SLOT(mode_latitude()));
31 menuBar()->addAction(tr("&Buzz"), this, SLOT(mode_buzz()));
32 menuBar()->addAction(tr("&Config"), this, SLOT(config()));
34 demonio = new QAction(this);
35 if ( system("killall -0 GoogleLatitudeDaemon 2> /dev/null" ) ) {
36 demonio->setText(tr("&Start Daemon"));
38 demonio->setText(tr("&Stop Daemon"));
40 connect(demonio, SIGNAL(triggered()), this, SLOT(mode_demonio()));
41 menuBar()->addAction(demonio);
44 void LatitudeGUI::set() {
45 qDebug() << "LatitudeGUI: set";
46 glatitude->update(gps->get_lat(),
51 void LatitudeGUI::set_config() {
52 qDebug() << "LatitudeGUI: set_config";
53 glatitude->set_login(setting->value("user","my_username").toString(),
54 setting->value("pass","my_password").toString());
56 gps->config(setting->value("interval",1800).toInt(),
57 setting->value("wait",30).toInt(),
58 setting->value("method","cell").toString());
61 void LatitudeGUI::latitude_ok() {
62 qDebug() << "LatitudeGUI: ok";
65 void LatitudeGUI::latitude_error() {
67 QString error_message = tr("<b>Error in Authentification!</b><br><br>") +
68 tr("Plese verify your login details<br>");
69 QMaemo5InformationBox::information(this, error_message,
70 QMaemo5InformationBox::NoTimeout);
72 qDebug() << "LatitudeGUI: no auth";
76 void LatitudeGUI::maps_login() {
77 if ( maps->url() == QUrl::fromEncoded("https://www.google.com/accounts/ServiceLogin?service=friendview&continue=http://www.google.com/maps/m?mode=latitude") ) {
78 maps->page()->mainFrame()->evaluateJavaScript(
79 QString("document.getElementById('Email').value = \"%1\";").arg(
80 setting->value("user").toString()));
81 maps->page()->mainFrame()->evaluateJavaScript(
82 QString("document.getElementById('Passwd').value = \"%1\";").arg(
83 setting->value("pass").toString()));
84 maps->page()->mainFrame()->evaluateJavaScript("document.getElementById('gaia_loginform').submit();");
86 if ( maps->url() == QUrl::fromEncoded("https://www.google.com/accounts/ServiceLoginAuth") ) {
91 void LatitudeGUI::mode_buzz() {
92 maps->load(QUrl::fromEncoded("http://www.google.com/maps/m?l-view=map&l-lci=m,com.google.latitudepublicupdates&ac=f,s,l"));
95 void LatitudeGUI::mode_latitude() {
96 maps->load(QUrl::fromEncoded("https://www.google.com/accounts/ServiceLogin?service=friendview&continue=http://www.google.com/maps/m?mode=latitude"));
99 void LatitudeGUI::mode_demonio() {
100 if ( ! system("killall -0 GoogleLatitudeDaemon 2> /dev/null" ) ) {
101 system("killall GoogleLatitudeDaemon 2> /dev/null");
102 demonio->setText(tr("&Start Daemon"));
104 QProcess *cli = new QProcess(this);
105 cli->startDetached(QCoreApplication::applicationDirPath()+QDir::separator()+"GoogleLatitudeDaemon");
106 qDebug() << "LatitudeGUI: demonio" << QCoreApplication::applicationDirPath()+QDir::separator()+"GoogleLatitudeDaemon";
107 if ( ! system("killall -0 GoogleLatitudeDaemon 2> /dev/null" ) ) {
108 demonio->setText(tr("&Stop Daemon"));
113 void LatitudeGUI::config() {
116 QDialog *dialoglogin = new QDialog(this);
118 QLineEdit *login_user = new QLineEdit(setting->value("user","my_username").toString());
119 QLineEdit *login_pass = new QLineEdit(setting->value("pass","my_password").toString());
120 login_pass->setEchoMode(QLineEdit::Password);
122 QLineEdit *gps_interval = new QLineEdit(setting->value("interval",1800).toString());
123 QLineEdit *gps_wait = new QLineEdit(setting->value("wait",30).toString());
125 QCheckBox *daemon_use = new QCheckBox();
126 if ( setting->value("daemon",false).toBool() ) {
127 daemon_use->setCheckState(Qt::Checked);
129 daemon_use->setCheckState(Qt::Unchecked);
132 QRadioButton *gps_cell = new QRadioButton(tr("&Cell Tower"));
133 QRadioButton *gps_both = new QRadioButton(tr("&Both"));
134 QRadioButton *gps_agps = new QRadioButton(tr("Only &Gps"));
136 QString gps_setting = setting->value("method","cell").toString();
137 if ( gps_setting == QString("cell") ) {
138 gps_cell->setChecked(true);
139 } else if ( gps_setting == QString("both") ) {
140 gps_both->setChecked(true);
141 } else if ( gps_setting == QString("agps") ) {
142 gps_agps->setChecked(true);
144 gps_cell->setChecked(true);
147 QFormLayout *layout_form = new QFormLayout();
149 layout_form->addRow(tr("&Username"), login_user);
150 layout_form->addRow(tr("&Password"), login_pass);
151 connect(login_user, SIGNAL(textEdited(QString)), this, SLOT(save_user(QString)));
152 connect(login_user, SIGNAL(returnPressed()), login_pass, SLOT(setFocus()));
153 connect(login_pass, SIGNAL(textEdited(QString)), this, SLOT(save_pass(QString)));
154 connect(login_pass, SIGNAL(returnPressed()), dialoglogin, SLOT(accept()));
156 layout_form->addRow(tr("&Interval for Updates"), gps_interval);
157 layout_form->addRow(tr("&Wait for a Fix"), gps_wait);
158 layout_form->addRow(tr("&Daemon at Boot"), daemon_use);
159 connect(gps_interval, SIGNAL(textEdited(QString)), this, SLOT(save_interval(QString)));
160 connect(gps_wait, SIGNAL(textEdited(QString)), this, SLOT(save_wait(QString)));
161 connect(daemon_use, SIGNAL(stateChanged(int)), this, SLOT(save_daemon(int)));
163 QHBoxLayout *layout_gps = new QHBoxLayout;
164 layout_gps->addWidget(gps_cell);
165 layout_gps->addWidget(gps_both);
166 layout_gps->addWidget(gps_agps);
167 layout_form->addRow(layout_gps);
168 connect(gps_cell, SIGNAL(clicked()), this, SLOT(save_gps_cell()));
169 connect(gps_both, SIGNAL(clicked()), this, SLOT(save_gps_both()));
170 connect(gps_agps, SIGNAL(clicked()), this, SLOT(save_gps_agps()));
172 dialoglogin->setLayout(layout_form);
175 if ( setting->value("interval",1800).toInt() < 300 )
176 setting->setValue("interval", 300);
177 if ( setting->value("interval",1800).toInt() > 3600 )
178 setting->setValue("interval", 3600);
180 if ( QString("agps") == setting->value("method","cell").toString() ) {
181 if ( setting->value("wait",30).toInt() < 15 )
182 setting->setValue("wait", 15);
184 if ( setting->value("wait",30).toInt() < 5 )
185 setting->setValue("wait", 5);
187 if ( setting->value("wait",30).toInt() > 120 )
188 setting->setValue("wait", 120);