2 #include "qwebviewselectionsuppressor.h"
3 #include "../common/dbusclient.h"
4 #include "customuseragentpage.h"
8 LatitudeGUI::LatitudeGUI(QSettings *set, QWidget *parent) : QMainWindow(parent)
11 setAttribute(Qt::WA_Maemo5AutoOrientation, true);
12 DBusClient* dbcli = new DBusClient(this);
19 url = QUrl::fromEncoded("https://www.google.com/accounts/ServiceLogin?service=friendview&continue=http://www.google.com/maps/m?mode=latitude");
20 maps = new QWebView();
21 maps->setPage(new customUAPage(this));
22 maps->settings()->enablePersistentStorage();
23 maps->setZoomFactor(1.4);
24 maps->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
25 maps->setContextMenuPolicy(Qt::NoContextMenu);
26 connect(maps, SIGNAL(loadFinished(bool)), this, SLOT(maps_login()));
28 new QWebViewSelectionSuppressor(maps);
29 menuBar()->addAction(tr("&Latitude"), this, SLOT(mode_latitude()));
30 menuBar()->addAction(tr("&Buzz"), this, SLOT(mode_buzz()));
33 glatitude = new GoogleLatitude(this);
35 gps = new GpsMaemo5(location_interval, location_method, this);
38 connect(gps, SIGNAL(fix()), this, SLOT(set()));
39 connect(dbcli, SIGNAL(sigNetworkConnected()),
40 this, SLOT(enableServices()));
41 connect(dbcli, SIGNAL(sigNetworkDisconnected()),
42 this, SLOT(disableServices()));
45 connect(glatitude, SIGNAL(OK()), this, SLOT(latitude_OK()));
46 connect(glatitude, SIGNAL(ERROR()), this, SLOT(latitude_ERROR()));
49 setCentralWidget(maps);
53 void LatitudeGUI::enableServices() {
54 if (!DBusClient::networkConnected())
58 glatitude->enableUpdates();
60 void LatitudeGUI::disableServices() {
62 glatitude->disableUpdates();
66 void LatitudeGUI::set() {
68 //QMaemo5InformationBox::information(this, "new position...", 1000);
70 qDebug() << "new position...";
72 glatitude->login(settings->value("user","my_username").toString(),
73 settings->value("pass","my_password").toString());
74 glatitude->set(gps->get_lat(),
77 glatitude->disableUpdates();
79 QTimer::singleShot(location_interval*100, glatitude, SLOT(enableUpdates()));
83 void LatitudeGUI::latitude_OK() {
84 loginOk = true; //We could login at least once!
86 qDebug() << maps->url();
88 //QMaemo5InformationBox::information(this, "...location Sent!", 1000);
90 qDebug() << "...location Sent!";
94 void LatitudeGUI::latitude_ERROR() {
95 //Errors in authentication may occur frequently due to transmition or
96 //reception problems in low signal situations, so we will only alert the
97 //user if we can't login at least once
103 QString error_message = tr("<b>Error in Authentification!</b><br><br> ") +
104 tr("Plese verify your login details<br>");
105 QMaemo5InformationBox::information(this, error_message,
106 QMaemo5InformationBox::NoTimeout);
107 system("/usr/bin/googlelatitude-settings");
110 qDebug() << "Error in Authentification!";
114 void LatitudeGUI::loadSettings()
118 location_method = (LocationGPSDControlMethod) settings->value("location", LOCATION_METHOD_GNSS).toInt();
119 location_interval = (LocationGPSDControlInterval) settings->value("interval", LOCATION_INTERVAL_20S).toUInt();
123 void LatitudeGUI::maps_login() {
124 if ( maps->url() == url ) {
125 maps->page()->mainFrame()->evaluateJavaScript(
126 QString("document.getElementById('Email').value = \"%1\";").arg(
127 settings->value("user").toString()));
128 maps->page()->mainFrame()->evaluateJavaScript(
129 QString("document.getElementById('Passwd').value = \"%1\";").arg(
130 settings->value("pass").toString()));
131 maps->page()->mainFrame()->evaluateJavaScript("document.getElementById('gaia_loginform').submit();");
135 void LatitudeGUI::mode_buzz() {
136 maps->load(QUrl::fromEncoded("http://www.google.com/maps/m?l-view=map&l-lci=m,com.google.latitudepublicupdates&ac=f,s,l"));
139 void LatitudeGUI::mode_latitude() {
140 maps->load(QUrl::fromEncoded("https://www.google.com/accounts/ServiceLogin?service=friendview&continue=http://www.google.com/maps/m?mode=latitude"));
143 void LatitudeGUI::reparseConfiguration()
148 gps->updateGPSConfig(location_interval, location_method);
150 QMaemo5InformationBox::information(this,
151 tr("Google Latitude daemon updated"),
156 void LatitudeGUI::save_user(QString _user) {
157 settings->setValue("user", _user);
159 void LatitudeGUI::save_pass(QString _pass) {
160 settings->setValue("pass", _pass);