Changed the old code to work as a daemon
authorDanilo Luvizotto <danilo.luvizotto@gmail.com>
Sat, 15 Jan 2011 23:20:28 +0000 (21:20 -0200)
committerDanilo Luvizotto <traysh@japune.square>
Sat, 15 Jan 2011 23:20:28 +0000 (21:20 -0200)
Implemented dbus (adaptor and client)
Added a settings plugin to the system settings with various options
Maybe more

39 files changed:
data/glupdater [new file with mode: 0644]
data/googlelatitude.desktop
data/libglsettingsplugin.desktop [new file with mode: 0644]
debian/changelog
debian/googlelatitude.install
googlelatitude.pro
src/common/dbusclient.cpp [new file with mode: 0644]
src/common/dbusclient.h [new file with mode: 0644]
src/daemon/customuseragentpage.h [new file with mode: 0644]
src/daemon/daemon.pro [new file with mode: 0644]
src/daemon/dbusadaptor.cpp [new file with mode: 0644]
src/daemon/dbusadaptor.h [new file with mode: 0644]
src/daemon/glatitude.cpp [new file with mode: 0644]
src/daemon/glatitude.h [new file with mode: 0644]
src/daemon/gps.cpp [new file with mode: 0644]
src/daemon/gps.h [new file with mode: 0644]
src/daemon/latitude-backup.cpp [new file with mode: 0644]
src/daemon/latitude-backup.h [new file with mode: 0644]
src/daemon/latitude.cpp [new file with mode: 0644]
src/daemon/latitude.h [new file with mode: 0644]
src/daemon/main.cpp [new file with mode: 0644]
src/daemon/qwebviewselectionsuppressor.h [new file with mode: 0644]
src/glatitude.cpp [deleted file]
src/glatitude.h [deleted file]
src/gps.cpp [deleted file]
src/gps.h [deleted file]
src/latitude.cpp [deleted file]
src/latitude.h [deleted file]
src/main.cpp [deleted file]
src/settings/main.cpp [new file with mode: 0644]
src/settings/settings.cpp [new file with mode: 0644]
src/settings/settings.h [new file with mode: 0644]
src/settings/settings.pro [new file with mode: 0644]
src/settings/settings.ui [new file with mode: 0644]
src/settings/ui_settings.h [new file with mode: 0644]
src/settingsplugin/.directory [new file with mode: 0644]
src/settingsplugin/settingsplugin.c [new file with mode: 0644]
src/settingsplugin/settingsplugin.pro [new file with mode: 0644]
src/src.pro [new file with mode: 0644]

diff --git a/data/glupdater b/data/glupdater
new file mode 100644 (file)
index 0000000..54d7055
--- /dev/null
@@ -0,0 +1,12 @@
+author "Danilo Luvizotto <danilo.luvizotto@gmail.com>"
+description "Google Latitude Updater Daemon"
+
+start on started hildon-desktop
+
+console output
+
+post-stop script
+    killall -9 googlelatitude-daemon
+end script
+
+exec /bin/su - user -c "/opt/linfati.com/googlelatitude-daemon -s"
index 80f40a7..8879ef5 100644 (file)
@@ -3,7 +3,7 @@ Encoding=UTF-8
 Version=1.0
 Type=Application
 Name=Google Latitude Update
-Exec=/opt/linfati.com/googlelatitude
+Exec=/opt/linfati.com/googlelatitude-daemon
 Icon=googlelatitude
 X-HildonDesk-ShowInToolbar=true
 X-Osso-Type=application/x-executable
diff --git a/data/libglsettingsplugin.desktop b/data/libglsettingsplugin.desktop
new file mode 100644 (file)
index 0000000..dbd3f3a
--- /dev/null
@@ -0,0 +1,10 @@
+[Desktop Entry] 
+Encoding=UTF-8
+Version=1.0
+Name=Google Latitude Updater
+Comment=Google Latitude Updater Settings
+Type=HildonControlPanelPlugin
+Icon=googlelatitude
+X-control-panel-plugin=libglsettingsplugin.so
+Categories=connectivity
+
index e8581be..c2147d3 100644 (file)
@@ -1,3 +1,12 @@
+googlelatitude (0.5-0) unstable; urgency=low
+
+  * Changed the old code to work as a daemon
+  * Implemented dbus (adaptor and client)
+  * Added a settings plugin to the system settings with various options
+  * Maybe more
+
+ -- Danilo Luvizotto <danilo.luvizotto@gmail.com>  Thu, 06 Jan 2011 18:34:12 +0200
+
 googlelatitude (0.4-0) unstable; urgency=low
 
   * Bump version
index 51f5a6a..3d3c273 100644 (file)
@@ -1,3 +1,7 @@
 data/googlelatitude.desktop usr/share/applications/hildon
 data/googlelatitude.png usr/share/icons/hicolor/64x64/apps
-build/googlelatitude opt/linfati.com
+data/libglsettingsplugin.desktop usr/share/applications/hildon-control-panel
+data/glupdater etc/event.d
+src/daemon/build/googlelatitude-daemon opt/linfati.com
+src/settings/build/googlelatitude-settings opt/linfati.com
+src/settingsplugin/build/libglsettingsplugin.so usr/lib/hildon-control-panel
index 8eb75e0..d97061d 100644 (file)
@@ -1,16 +1,8 @@
-TARGET      = googlelatitude
-HEADERS    += src/latitude.h src/glatitude.h src/gps.h
-SOURCES    += src/main.cpp src/latitude.cpp src/glatitude.cpp src/gps.cpp
-
-OBJECTS_DIR = build
-MOC_DIR     = build
-DESTDIR     = build
-
-TEMPLATE    = app
-QT         += network webkit
-
-contains(QT_CONFIG, maemo5) {
-    QT          += maemo5
-    CONFIG      += link_pkgconfig
-    PKGCONFIG   += glib-2.0 liblocation
+QMAKEVERSION = $$[QMAKE_VERSION]
+ISQT4 = $$find(QMAKEVERSION, ^[2-9])
+isEmpty( ISQT4 ) {
+error("Use the qmake include with Qt4.4 or greater, on Debian that is qmake-qt4");
 }
+
+TEMPLATE = subdirs
+SUBDIRS  = src
diff --git a/src/common/dbusclient.cpp b/src/common/dbusclient.cpp
new file mode 100644 (file)
index 0000000..870af53
--- /dev/null
@@ -0,0 +1,62 @@
+#include "dbusclient.h"
+
+#ifdef Q_WS_MAEMO_5
+#include <QDebug>
+#include <QDBusReply>
+#include <icd/dbus_api.h>
+
+QDBusConnection DBusClient::system_bus(QDBusConnection::systemBus());
+QDBusConnection DBusClient::session_bus(QDBusConnection::sessionBus());
+QDBusInterface* DBusClient::icd_interface = new QDBusInterface(ICD_DBUS_API_INTERFACE,
+                                                              ICD_DBUS_API_PATH,
+                                                              ICD_DBUS_API_INTERFACE,
+                                                              system_bus);
+QDBusInterface* DBusClient::gl_interface = new QDBusInterface("com.linfati.GoogleLatitude",
+                                                              "/",
+                                                              "com.linfati.GoogleLatitude",
+                                                              session_bus);
+
+DBusClient::DBusClient(QObject *parent) :
+    QObject(parent)
+{
+    QDBusConnection::systemBus().connect(ICD_DBUS_API_INTERFACE,
+                                         ICD_DBUS_API_PATH,
+                                         ICD_DBUS_API_INTERFACE,
+                                         ICD_DBUS_API_CONNECT_SIG,
+                                         this,
+                                         SLOT(networkStateChanged()));
+}
+
+bool DBusClient::daemonRunning()
+{
+    return ((QDBusReply<bool>)gl_interface->call("running")).value();
+}
+
+bool DBusClient::networkConnected()
+{
+    QDBusReply<uint> reply = icd_interface->call(ICD_DBUS_API_STATE_REQ);
+
+    return (reply.value() > 0) ? true : false;
+}
+
+void DBusClient::networkStateChanged()
+{
+    networkConnected() ? emit sigNetworkConnected() : sigNetworkDisconnected();
+}
+
+
+void DBusClient::quitDaemon()
+{
+    gl_interface->call("quit");
+}
+
+void DBusClient::reloadDaemonConfig()
+{
+    gl_interface->call("reparseConfiguration");
+}
+
+void DBusClient::showWindow()
+{
+    gl_interface->call("show");
+}
+#endif
diff --git a/src/common/dbusclient.h b/src/common/dbusclient.h
new file mode 100644 (file)
index 0000000..5408554
--- /dev/null
@@ -0,0 +1,36 @@
+#ifndef DBUSCLIENT_H
+#define DBUSCLIENT_H
+
+
+#include <QObject>
+#ifdef Q_WS_MAEMO_5
+#include <QDBusMessage>
+#include <QDBusInterface>
+
+class DBusClient : public QObject
+{
+    Q_OBJECT
+public:
+    explicit DBusClient(QObject *parent = 0);
+    static bool daemonRunning();
+    static bool networkConnected();
+    static void quitDaemon();
+    static void reloadDaemonConfig();
+    static void showWindow();
+
+signals:
+    void sigNetworkConnected();
+    void sigNetworkDisconnected();
+
+public slots:
+    void networkStateChanged();
+
+private:
+    static QDBusConnection system_bus;
+    static QDBusConnection session_bus;
+    static QDBusInterface *icd_interface;
+    static QDBusInterface *gl_interface;
+};
+
+#endif //Q_WS_MAEMO_5
+#endif // DBUSCLIENT_H
diff --git a/src/daemon/customuseragentpage.h b/src/daemon/customuseragentpage.h
new file mode 100644 (file)
index 0000000..6dddd1d
--- /dev/null
@@ -0,0 +1,19 @@
+#ifndef CUSTOMUSERAGENTPAGE_H
+#define CUSTOMUSERAGENTPAGE_H
+
+#include <QWebPage>
+
+class customUAPage : public QWebPage
+{
+    Q_OBJECT
+
+public:
+    customUAPage(QObject* parent = 0) : QWebPage(parent) {}
+
+protected:
+    QString userAgentForUrl(const QUrl &url ) const
+        {return QString("Mozilla/5.0 (%Platform%; %Security%; %Subplatform%; %Locale%) AppleWebKit/%WebKitVersion% (KHTML, like Gecko) %AppVersion Mobile");}
+
+};
+
+#endif // CUSTOMUSERAGENTPAGE_H
diff --git a/src/daemon/daemon.pro b/src/daemon/daemon.pro
new file mode 100644 (file)
index 0000000..a31f517
--- /dev/null
@@ -0,0 +1,49 @@
+TARGET      = googlelatitude-daemon
+HEADERS    += latitude.h glatitude.h gps.h \
+    dbusadaptor.h ../common/dbusclient.h \
+    qwebviewselectionsuppressor.h \
+    customuseragentpage.h
+SOURCES    += main.cpp latitude.cpp glatitude.cpp gps.cpp \
+    dbusadaptor.cpp ../common/dbusclient.cpp
+
+OBJECTS_DIR = build
+MOC_DIR     = build
+DESTDIR     = build
+
+TEMPLATE    = app
+QT         += network webkit dbus
+
+contains(QT_CONFIG, maemo5) {
+    QT          += maemo5
+    CONFIG      += link_pkgconfig
+    PKGCONFIG   += glib-2.0 liblocation
+}
+
+unix {
+  #VARIABLES
+  isEmpty(PREFIX) {
+    PREFIX = /usr
+  }
+  BINDIR = $$PREFIX/bin
+  DATADIR =$$PREFIX/share
+
+  DEFINES += DATADIR=\\\"$$DATADIR\\\" PKGDATADIR=\\\"$$PKGDATADIR\\\"
+
+  #MAKE INSTALL
+
+  INSTALLS += target desktop icon64 updater
+  target.path =$$BINDIR
+
+  #service.path = $$DATADIR/dbus-1/services
+  #service.files += $${TARGET}.service
+
+  desktop.path = $$DATADIR/applications/hildon
+  desktop.files += ../../data/googlelatitude.desktop
+
+  icon64.path = $$DATADIR/icons/hicolor/64x64/apps
+  icon64.files += ../../data/googlelatitude.png
+
+  updater.path = /etc/event.d
+  updater.files += ../../data/glupdater
+}
+
diff --git a/src/daemon/dbusadaptor.cpp b/src/daemon/dbusadaptor.cpp
new file mode 100644 (file)
index 0000000..159df5d
--- /dev/null
@@ -0,0 +1,32 @@
+#include "dbusadaptor.h"
+
+#include <QDBusConnection>
+
+DBusAdaptor::DBusAdaptor(QApplication *application) :
+    QDBusAbstractAdaptor(application), app(application)
+{}
+
+void DBusAdaptor::quit()
+{
+    exit(0);
+}
+
+void DBusAdaptor::reparseConfiguration()
+{
+    daemon->reparseConfiguration();
+}
+
+bool DBusAdaptor::running()
+{
+    return true;
+}
+
+void DBusAdaptor::setDaemon(LatitudeGUI* d)
+{
+    daemon = d;
+}
+
+void DBusAdaptor::show()
+{
+    daemon->show();
+}
diff --git a/src/daemon/dbusadaptor.h b/src/daemon/dbusadaptor.h
new file mode 100644 (file)
index 0000000..5465015
--- /dev/null
@@ -0,0 +1,33 @@
+#ifndef DBUSADAPTOR_H
+#define DBUSADAPTOR_H
+
+#include <QDBusAbstractAdaptor>
+#include <QApplication>
+#include <QWidget>
+#include <QDebug>
+
+#include "latitude.h"
+
+class DBusAdaptor : public QDBusAbstractAdaptor
+{
+    Q_OBJECT
+    Q_CLASSINFO("D-Bus Interface", "com.linfati.GoogleLatitude")
+
+public:
+    explicit DBusAdaptor(QApplication *application);
+    void setDaemon(LatitudeGUI* d);
+
+signals:
+
+public slots:
+    Q_NOREPLY void quit();
+    Q_NOREPLY void show();
+    bool running();
+    void reparseConfiguration();
+
+private:
+    QApplication *app;
+    LatitudeGUI *daemon;
+};
+
+#endif // DBUSADAPTOR_H
diff --git a/src/daemon/glatitude.cpp b/src/daemon/glatitude.cpp
new file mode 100644 (file)
index 0000000..11dfd03
--- /dev/null
@@ -0,0 +1,76 @@
+#include "glatitude.h"
+
+GoogleLatitude::GoogleLatitude(QObject *parent) :
+        QObject(parent)
+{
+    user = "";
+    pass = "";
+    latitude = 0.;
+    longitude = 0.;
+    accuracy = 0.;
+
+    worker = new QNetworkAccessManager();
+    connect(worker, SIGNAL(finished(QNetworkReply *)), this, SLOT(finishedreply(QNetworkReply *)));
+
+    urllogin = QUrl::fromEncoded("https://www.google.com/accounts/ServiceLogin?service=friendview");
+    urldologin = QUrl::fromEncoded("https://www.google.com/accounts/ServiceLoginAuth?service=friendview");
+    urlupdate = QUrl::fromEncoded("http://maps.google.com/glm/mmap/mwmfr?hl=en");
+    on = true;
+}
+
+void GoogleLatitude::login(QString u, QString p) {
+    if ( !u.contains('@') ) u.append("@gmail.com");
+    user = u;
+    pass = p;
+}
+
+void GoogleLatitude::set(double la, double lo, double ac) {
+    latitude = la;
+    longitude = lo;
+    accuracy = ac;
+
+    if (la*lo == 0) return;
+    if (!on) return;
+    worker->get(QNetworkRequest(urllogin));
+}
+
+void GoogleLatitude::finishedreply(QNetworkReply *r) {
+    if ( r->url() == urllogin ) {
+        QString aidis = r->readAll();
+        QRegExp regexp ("type=\"hidden\".*name=\"GALX\".*value=\"(.*)\"");
+        regexp.setMinimal(1);
+        regexp.indexIn(aidis, 1);
+        QString googleGALX = regexp.capturedTexts().last();
+
+        QByteArray datalogin;
+        datalogin += "&service=friendview";
+        datalogin += "&GALX=" + googleGALX;
+        datalogin += "&Email=" + user;
+        datalogin += "&Passwd=" + pass;
+        worker->post(QNetworkRequest(urldologin), datalogin);
+    } else if ( r->url() == urldologin ) {
+        QByteArray datagps;
+        datagps += "t=ul";
+        datagps += "&lat=" + QString::number(latitude);
+        datagps += "&lng=" + QString::number(longitude);
+        datagps += "&accuracy=" + QString::number(accuracy);
+
+        QNetworkRequest request(urlupdate);
+        request.setRawHeader("X-ManualHeader", QString("true").toAscii() );
+        worker->post(request, datagps);
+    } else if ( r->url() == urlupdate ) {
+        QString output = r->readAll();
+        QRegExp regexp ("Authentication required");
+        if (regexp.indexIn(output, 1) != -1) {
+            emit ERROR();
+        } else {
+            emit OK();
+        }
+        qDebug() << output;
+    } else {
+        qDebug() << "Error";
+        qDebug() << "url:" << r->url();
+        qDebug() << r->rawHeaderList();
+        qDebug() << r->readAll();
+    }
+}
diff --git a/src/daemon/glatitude.h b/src/daemon/glatitude.h
new file mode 100644 (file)
index 0000000..0085504
--- /dev/null
@@ -0,0 +1,45 @@
+#ifndef GLATITUDE_H
+#define GLATITUDE_H
+
+#include <QtNetwork>
+
+class GoogleLatitude : public QObject {
+    Q_OBJECT
+
+signals:
+    void OK();
+    void ERROR();
+
+public:
+    GoogleLatitude(QObject *parent = 0);
+    void login(QString username, QString password);
+    void set(double latitude, double longitude, double accuracy=1000.);
+    double get_lat() { return latitude; }
+    double get_lon() { return longitude; }
+    double get_acc() { return accuracy; }
+
+public slots:
+    void disableUpdates() { on = false; }
+    void enableUpdates() { on = true; }
+    void setUpdates(bool u) { on = u; }
+
+private slots:
+    void finishedreply(QNetworkReply *r);
+
+private:
+    // info
+    bool networkConnected();
+    QString user;
+    QString pass;
+    double latitude;
+    double longitude;
+    double accuracy;
+    // stuff
+    QNetworkAccessManager *worker;
+    QUrl urllogin;
+    QUrl urldologin;
+    QUrl urlupdate;
+    bool on;
+};
+
+#endif // GLATITUDE_H
diff --git a/src/daemon/gps.cpp b/src/daemon/gps.cpp
new file mode 100644 (file)
index 0000000..0d28d98
--- /dev/null
@@ -0,0 +1,73 @@
+#include "gps.h"
+
+#include <QDebug>
+
+#ifdef Q_WS_MAEMO_5
+
+bool ValidQReal(qreal value);
+
+GpsMaemo5::GpsMaemo5(LocationGPSDControlInterval location_interval,
+                     LocationGPSDControlMethod location_method,
+                     QObject *parent) :
+           QObject(parent)
+{
+    latitude = 0;
+    longitude = 0;
+    accuracy = 0;
+
+    control = location_gpsd_control_get_default();
+    device = (LocationGPSDevice*) g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
+
+    updateGPSConfig (location_interval, location_method);
+
+    g_signal_connect(device, "changed", G_CALLBACK(GpsMaemo5_changed), this);
+}
+
+void GpsMaemo5::enable()
+{
+    location_gpsd_control_start(control);
+}
+void GpsMaemo5::disable()
+{
+    location_gpsd_control_stop(control);
+}
+
+void GpsMaemo5::updateGPSConfig (LocationGPSDControlInterval location_interval,
+                                LocationGPSDControlMethod location_method)
+{
+    g_object_set(G_OBJECT(control), "preferred-interval", location_interval, NULL);
+    g_object_set(G_OBJECT(control), "preferred-method", location_method, NULL);
+    qDebug() << "preferred-interval: " << location_interval;
+    qDebug() << "preferred-method: " << location_method;
+}
+
+void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps) {
+    if (device->fix) {
+        if (device->fix->fields) {
+            if ( !ValidQReal(gps->device->fix->eph/100.) )
+                return;
+            g_print("lat = %f, long = %f, eph = %f\n", gps->device->fix->latitude, gps->device->fix->longitude, gps->device->fix->eph/100.);
+            gps->latitude = gps->device->fix->latitude;
+            gps->longitude = gps->device->fix->longitude;
+            gps->accuracy = gps->device->fix->eph/100.;
+            emit gps->fix();
+        }
+    }
+}
+
+bool ValidQReal(qreal value)
+{
+    if (value != value){
+        return false;
+    }
+    else if (value > std::numeric_limits<qreal>::max()){
+        return false;
+    }
+    else if (value < -std::numeric_limits<qreal>::max()){
+        return false;
+    }
+    else
+        return true;
+}
+
+#endif // Q_WS_MAEMO_5
diff --git a/src/daemon/gps.h b/src/daemon/gps.h
new file mode 100644 (file)
index 0000000..e16c2fb
--- /dev/null
@@ -0,0 +1,63 @@
+#ifndef GPS_H
+#define GPS_H
+
+#include <QObject>
+
+#ifdef Q_WS_MAEMO_5
+
+extern "C" {
+#include <location/location-gps-device.h>
+#include <location/location-gpsd-control.h>
+}
+
+class GpsMaemo5 : public QObject {
+    Q_OBJECT
+
+signals:
+    void fix();
+
+public:
+    GpsMaemo5(LocationGPSDControlInterval location_interval,
+              LocationGPSDControlMethod location_method,
+              QObject *parent = 0);
+    double get_lat() { return latitude; }
+    double get_lon() { return longitude; }
+    double get_acc() { return accuracy; }
+    friend void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps);
+    void updateGPSConfig (LocationGPSDControlInterval interval,
+                          LocationGPSDControlMethod method);
+
+public slots:
+    void enable();
+    void disable();
+
+private:
+    double latitude;
+    double longitude;
+    double accuracy;
+
+    GMainLoop *loop;
+    LocationGPSDControl *control;
+    LocationGPSDevice *device;
+};
+
+void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps);
+
+#else // Q_WS_MAEMO_5
+
+class GpsMaemo5 : public QObject {
+    Q_OBJECT
+
+signals:
+    void fix();
+
+public:
+    GpsMaemo5(QObject *parent = 0) { Q_UNUSED(parent); }
+    double get_lat() { return 0; }
+    double get_lon() { return 0; }
+    double get_acc() { return 0; }
+};
+
+#endif // Q_WS_MAEMO_5
+
+#endif // GPS_H
diff --git a/src/daemon/latitude-backup.cpp b/src/daemon/latitude-backup.cpp
new file mode 100644 (file)
index 0000000..40327a5
--- /dev/null
@@ -0,0 +1,101 @@
+#include "latitude.h"
+
+LatitudeGUI::LatitudeGUI(QObject *parent) : QObject(parent) {
+#ifdef Q_WS_MAEMO_5
+    //setAttribute(Qt::WA_Maemo5AutoOrientation, true);
+#endif
+    setting = new QSettings();
+
+    //TODO: move to settings
+    // login input
+    /*
+    QDialog *dialoglogin = new QDialog();
+    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);
+    QFormLayout *layout_login = new QFormLayout();
+    layout_login->addRow(tr("&Username"), login_user);
+    layout_login->addRow(tr("&Password"), login_pass);
+    connect(login_user, SIGNAL(textEdited(QString)), this, SLOT(save_user(QString)));
+    connect(login_pass, SIGNAL(textEdited(QString)), this, SLOT(save_pass(QString)));
+    connect(login_user, SIGNAL(returnPressed()), login_pass, SLOT(setFocus()));
+    connect(login_pass, SIGNAL(returnPressed()), dialoglogin, SLOT(accept()));
+    dialoglogin->setLayout(layout_login);
+    dialoglogin->exec();
+    */
+
+    // 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(url);
+    //menuBar()->addAction(tr("&Latitude"), this, SLOT(mode_latitude()));
+    //menuBar()->addAction(tr("&Buzz"), this, SLOT(mode_buzz()));
+
+    // 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()));
+
+    // show it
+    //setCentralWidget(maps);
+}
+
+void LatitudeGUI::set() {
+#ifdef Q_WS_MAEMO_5
+    //QMaemo5InformationBox::information(this, "new position...", 1000);
+#else
+    qDebug() << "new position...";
+#endif
+    glatitude->login(setting->value("user","my_username").toString(),
+                     setting->value("pass","my_password").toString());
+    glatitude->set(gps->get_lat(),
+                   gps->get_lon(),
+                   gps->get_acc());
+}
+
+void LatitudeGUI::latitude_OK() {
+#ifdef Q_WS_MAEMO_5
+    //QMaemo5InformationBox::information(this, "...location Sent!", 1000);
+#else
+    qDebug() << "...location Sent!";
+#endif
+}
+
+void LatitudeGUI::latitude_ERROR() {
+#ifdef Q_WS_MAEMO_5
+    //QMaemo5InformationBox::information(this, "Error in Authentification !", 3000);
+#else
+    qDebug() << "Error in Authentification !";
+#endif
+}
+
+void LatitudeGUI::save_user(QString _user) {
+    setting->setValue("user", _user);
+}
+void LatitudeGUI::save_pass(QString _pass) {
+    setting->setValue("pass", _pass);
+}
+
+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::maps_login() {
+    if ( maps->url() == url ) {
+        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();");
+    }
+}
diff --git a/src/daemon/latitude-backup.h b/src/daemon/latitude-backup.h
new file mode 100644 (file)
index 0000000..13aa6ea
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef LATITUDE_H
+#define LATITUDE_H
+
+#include <QtGui>
+#include <QtWebKit>
+#include "glatitude.h"
+#include "gps.h"
+#ifdef Q_WS_MAEMO_5
+#include <QtMaemo5>
+#endif
+
+class LatitudeGUI : public QObject {
+    Q_OBJECT
+
+signals:
+    void newpos();
+
+public:
+    LatitudeGUI(QObject *parent = 0);
+
+private slots:
+    void set();
+    void latitude_OK();
+    void latitude_ERROR();
+    void save_user(QString);
+    void save_pass(QString);
+    void maps_login();
+    void mode_buzz();
+    void mode_latitude();
+
+private:
+    GoogleLatitude *glatitude;
+    GpsMaemo5 *gps;
+    QSettings *setting;
+    QWebView *maps;
+    QUrl url;
+};
+
+#endif // LATITUDE_H
diff --git a/src/daemon/latitude.cpp b/src/daemon/latitude.cpp
new file mode 100644 (file)
index 0000000..dd1c6d7
--- /dev/null
@@ -0,0 +1,161 @@
+#include "latitude.h"
+#include "qwebviewselectionsuppressor.h"
+#include "../common/dbusclient.h"
+#include "customuseragentpage.h"
+
+#include <QTimer>
+
+LatitudeGUI::LatitudeGUI(QSettings *set, QWidget *parent) : QMainWindow(parent)
+{
+#ifdef Q_WS_MAEMO_5
+    setAttribute(Qt::WA_Maemo5AutoOrientation, true);
+    DBusClient* dbcli = new DBusClient(this);
+#endif
+    loginOk = false;
+    settings = set;
+    loadSettings();
+
+    // 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->setPage(new customUAPage(this));
+    maps->settings()->enablePersistentStorage();
+    maps->setZoomFactor(1.4);
+    maps->settings()->setAttribute(QWebSettings::PluginsEnabled, true);
+    maps->setContextMenuPolicy(Qt::NoContextMenu);
+    connect(maps, SIGNAL(loadFinished(bool)), this, SLOT(maps_login()));
+    maps->load(url);
+    new QWebViewSelectionSuppressor(maps);
+    menuBar()->addAction(tr("&Latitude"), this, SLOT(mode_latitude()));
+    menuBar()->addAction(tr("&Buzz"), this, SLOT(mode_buzz()));
+
+    // updater
+    glatitude = new GoogleLatitude(this);
+#ifdef Q_WS_MAEMO_5
+    gps = new GpsMaemo5(location_interval, location_method, this);
+    enableServices();
+
+    connect(gps, SIGNAL(fix()), this, SLOT(set()));
+    connect(dbcli, SIGNAL(sigNetworkConnected()),
+            this, SLOT(enableServices()));
+    connect(dbcli, SIGNAL(sigNetworkDisconnected()),
+            this, SLOT(disableServices()));
+
+#endif
+    connect(glatitude, SIGNAL(OK()), this, SLOT(latitude_OK()));
+    connect(glatitude, SIGNAL(ERROR()), this, SLOT(latitude_ERROR()));
+
+    // show it
+    setCentralWidget(maps);
+}
+
+#ifdef Q_WS_MAEMO_5
+void LatitudeGUI::enableServices() {
+    if (!DBusClient::networkConnected())
+        return;
+
+    gps->enable();
+    glatitude->enableUpdates();
+}
+void LatitudeGUI::disableServices() {
+    gps->disable();
+    glatitude->disableUpdates();
+}
+#endif
+
+void LatitudeGUI::set() {
+#ifdef Q_WS_MAEMO_5
+    //QMaemo5InformationBox::information(this, "new position...", 1000);
+#else
+    qDebug() << "new position...";
+#endif
+    glatitude->login(settings->value("user","my_username").toString(),
+                     settings->value("pass","my_password").toString());
+    glatitude->set(gps->get_lat(),
+                   gps->get_lon(),
+                   gps->get_acc());
+    glatitude->disableUpdates();
+#ifdef Q_WS_MAEMO_5
+    QTimer::singleShot(location_interval*100, glatitude, SLOT(enableUpdates()));
+#endif
+}
+
+void LatitudeGUI::latitude_OK() {    
+    loginOk = true; //We could login at least once!
+    //TODO: REMOVE THIS
+    qDebug() << maps->url();
+#ifdef Q_WS_MAEMO_5
+    //QMaemo5InformationBox::information(this, "...location Sent!", 1000);
+#else
+    qDebug() << "...location Sent!";
+#endif
+}
+
+void LatitudeGUI::latitude_ERROR() {
+    //Errors in authentication may occur frequently due to transmition or
+    //reception problems in low signal situations, so we will only alert the
+    //user if we can't login at least once
+    if (loginOk)
+        return;
+
+#ifdef Q_WS_MAEMO_5
+    disableServices();
+    QString error_message = tr("<b>Error in Authentification!</b><br><br> ") +
+                            tr("Plese verify your login details<br>");
+    QMaemo5InformationBox::information(this, error_message,
+                                       QMaemo5InformationBox::NoTimeout);
+    system("/usr/bin/googlelatitude-settings");
+    enableServices();
+#else
+    qDebug() << "Error in Authentification!";
+#endif
+}
+
+void LatitudeGUI::loadSettings()
+{
+    settings->sync();
+#ifdef Q_WS_MAEMO_5
+    location_method = (LocationGPSDControlMethod) settings->value("location", LOCATION_METHOD_GNSS).toInt();
+    location_interval = (LocationGPSDControlInterval) settings->value("interval", LOCATION_INTERVAL_20S).toUInt();
+#endif
+}
+
+void LatitudeGUI::maps_login() {
+    if ( maps->url() == url ) {
+        maps->page()->mainFrame()->evaluateJavaScript(
+                QString("document.getElementById('Email').value = \"%1\";").arg(
+                        settings->value("user").toString()));
+        maps->page()->mainFrame()->evaluateJavaScript(
+                QString("document.getElementById('Passwd').value = \"%1\";").arg(
+                        settings->value("pass").toString()));
+        maps->page()->mainFrame()->evaluateJavaScript("document.getElementById('gaia_loginform').submit();");
+    }
+}
+
+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::reparseConfiguration()
+{
+#ifdef Q_WS_MAEMO_5
+    disableServices();
+    loadSettings();
+    gps->updateGPSConfig(location_interval, location_method);
+    enableServices();
+    QMaemo5InformationBox::information(this,
+                                       tr("Google Latitude daemon updated"),
+                                       2000);
+#endif
+}
+
+void LatitudeGUI::save_user(QString _user) {
+    settings->setValue("user", _user);
+}
+void LatitudeGUI::save_pass(QString _pass) {
+    settings->setValue("pass", _pass);
+}
diff --git a/src/daemon/latitude.h b/src/daemon/latitude.h
new file mode 100644 (file)
index 0000000..cdc41d5
--- /dev/null
@@ -0,0 +1,52 @@
+#ifndef LATITUDE_H
+#define LATITUDE_H
+
+#include <QtGui>
+#include <QtWebKit>
+#include "glatitude.h"
+#include "gps.h"
+#ifdef Q_WS_MAEMO_5
+#include <QtMaemo5>
+#endif
+
+class LatitudeGUI : public QMainWindow {
+    Q_OBJECT
+
+signals:
+    void newpos();
+
+public:
+    LatitudeGUI(QSettings *set, QWidget *parent = 0);
+    void reparseConfiguration();
+
+protected:
+    void loadSettings();
+
+private slots:
+#ifdef Q_WS_MAEMO_5
+    void enableServices();
+    void disableServices();
+#endif
+    void set();
+    void latitude_OK();
+    void latitude_ERROR();
+    void save_user(QString);
+    void save_pass(QString);
+    void maps_login();
+    void mode_buzz();
+    void mode_latitude();
+
+private:
+    GoogleLatitude *glatitude;
+    GpsMaemo5 *gps;
+    QSettings *settings;
+    QWebView *maps;
+    QUrl url;
+#ifdef Q_WS_MAEMO_5
+    LocationGPSDControlInterval location_interval;
+    LocationGPSDControlMethod location_method;
+#endif
+    bool loginOk;
+};
+
+#endif // LATITUDE_H
diff --git a/src/daemon/main.cpp b/src/daemon/main.cpp
new file mode 100644 (file)
index 0000000..a45c48f
--- /dev/null
@@ -0,0 +1,42 @@
+#include "latitude.h"
+#include "dbusadaptor.h"
+#include "../common/dbusclient.h"
+
+#include <QDBusConnection>
+#include <QDebug>
+
+int main(int argc, char *argv[]) {
+    QApplication app(argc, argv);
+    DBusAdaptor* adaptor = new DBusAdaptor(&app);
+    QCoreApplication::setOrganizationName("linfati");
+    QCoreApplication::setOrganizationDomain("linfati.com");
+    QCoreApplication::setApplicationName("GoogleLatitude");
+    if (!QDBusConnection::sessionBus().registerService("com.linfati.GoogleLatitude")) {
+#ifdef Q_WS_MAEMO_5
+        DBusClient::showWindow();
+#endif
+        return 0; //The application is already running
+    }
+    QDBusConnection::sessionBus().registerObject("/", &app);
+
+    QSettings* settings = new QSettings();
+
+    if(app.arguments().contains(QString("-s")) ||
+       app.arguments().contains(QString("--startup")))
+        if (!settings->value("autolaunch",false).toBool())
+            return 0;
+
+    app.setQuitOnLastWindowClosed(false);
+    LatitudeGUI *gui = new LatitudeGUI(settings);
+    adaptor->setDaemon(gui);
+
+    return app.exec();
+}
+
+/*
+ TODO:
+ on auth error -> stop gps
+ on new pos, only set it
+ send new pos every 120s, only if is diferent
+ no n900 -> por ip
+ */
diff --git a/src/daemon/qwebviewselectionsuppressor.h b/src/daemon/qwebviewselectionsuppressor.h
new file mode 100644 (file)
index 0000000..7b96441
--- /dev/null
@@ -0,0 +1,110 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the examples of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file.  Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights.  These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QWEBVIEWSELECTIONSUPPRESSOR_H
+#define QWEBVIEWSELECTIONSUPPRESSOR_H
+
+#include <QtWebKit/qwebview.h>
+#include <QtGui/qevent.h>
+
+class QWebViewSelectionSuppressor : public QObject
+{
+    Q_OBJECT
+public:
+    QWebViewSelectionSuppressor(QWebView *v)
+        : QObject(v), view(v), enabled(false), mousePressed(false)
+    {
+        Q_ASSERT(view);
+        enable();
+    }
+
+    inline void enable()
+    {
+        if (enabled)
+            return;
+        view->installEventFilter(this);
+        enabled = true;
+    }
+
+    inline void disable()
+    {
+        if (!enabled)
+            return;
+        view->removeEventFilter(this);
+        enabled = false;
+    }
+
+    inline bool isEnabled() const
+    {
+        return enabled;
+    }
+
+protected:
+    inline bool eventFilter(QObject *, QEvent *e);
+
+private:
+    QWebView *view;
+    bool enabled;
+    bool mousePressed;
+};
+
+bool QWebViewSelectionSuppressor::eventFilter(QObject *, QEvent *e)
+{
+    switch (e->type()) {
+    case QEvent::MouseButtonPress:
+        if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
+            mousePressed = true;
+        break;
+    case QEvent::MouseButtonRelease:
+        if (static_cast<QMouseEvent *>(e)->button() == Qt::LeftButton)
+            mousePressed = false;
+        break;
+    case QEvent::MouseMove:
+        if (mousePressed)
+            return true;
+        break;
+    default:
+        break;
+    }
+    return false;
+}
+
+#endif
diff --git a/src/glatitude.cpp b/src/glatitude.cpp
deleted file mode 100644 (file)
index a00f7c9..0000000
+++ /dev/null
@@ -1,72 +0,0 @@
-#include "glatitude.h"
-
-GoogleLatitude::GoogleLatitude(QObject *parent) : QObject(parent) {
-    user = "";
-    pass = "";
-    latitude = 0.;
-    longitude = 0.;
-    accuracy = 0.;
-
-    worker = new QNetworkAccessManager();
-    connect(worker, SIGNAL(finished(QNetworkReply *)), this, SLOT(finishedreply(QNetworkReply *)));
-
-    urllogin = QUrl::fromEncoded("https://www.google.com/accounts/ServiceLogin?service=friendview");
-    urldologin = QUrl::fromEncoded("https://www.google.com/accounts/ServiceLoginAuth?service=friendview");
-    urlupdate = QUrl::fromEncoded("http://maps.google.com/glm/mmap/mwmfr?hl=en");
-}
-
-void GoogleLatitude::login(QString u, QString p) {
-    if ( !u.contains('@') ) u.append("@gmail.com");
-    user = u;
-    pass = p;
-}
-
-void GoogleLatitude::set(double la, double lo, double ac) {
-    latitude = la;
-    longitude = lo;
-    accuracy = ac;
-
-    if (la*lo == 0) return;
-    worker->get(QNetworkRequest(urllogin));
-}
-
-void GoogleLatitude::finishedreply(QNetworkReply *r) {
-    if ( r->url() == urllogin ) {
-        QString aidis = r->readAll();
-        QRegExp regexp ("type=\"hidden\".*name=\"GALX\".*value=\"(.*)\"");
-        regexp.setMinimal(1);
-        regexp.indexIn(aidis, 1);
-        QString googleGALX = regexp.capturedTexts().last();
-
-        QByteArray datalogin;
-        datalogin += "&service=friendview";
-        datalogin += "&GALX=" + googleGALX;
-        datalogin += "&Email=" + user;
-        datalogin += "&Passwd=" + pass;
-        worker->post(QNetworkRequest(urldologin), datalogin);
-    } else if ( r->url() == urldologin ) {
-        QByteArray datagps;
-        datagps += "t=ul";
-        datagps += "&lat=" + QString::number(latitude);
-        datagps += "&lng=" + QString::number(longitude);
-        datagps += "&accuracy=" + QString::number(accuracy);
-
-        QNetworkRequest request(urlupdate);
-        request.setRawHeader("X-ManualHeader", QString("true").toAscii() );
-        worker->post(request, datagps);
-    } else if ( r->url() == urlupdate ) {
-        QString output = r->readAll();
-        QRegExp regexp ("Authentication required");
-        if (regexp.indexIn(output, 1) != -1) {
-            emit ERROR();
-        } else {
-            emit OK();
-        }
-        qDebug() << output;
-    } else {
-        qDebug() << "Error";
-        qDebug() << "url:" << r->url();
-        qDebug() << r->rawHeaderList();
-        qDebug() << r->readAll();
-    }
-}
diff --git a/src/glatitude.h b/src/glatitude.h
deleted file mode 100644 (file)
index 3083696..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-#ifndef GLATITUDE_H
-#define GLATITUDE_H
-
-#include <QtNetwork>
-
-class GoogleLatitude : public QObject {
-    Q_OBJECT
-
-signals:
-    void OK();
-    void ERROR();
-
-public:
-    GoogleLatitude(QObject *parent = 0);
-    void login(QString username, QString password);
-    void set(double latitude, double longitude, double accuracy=1000.);
-    double get_lat() { return latitude; }
-    double get_lon() { return longitude; }
-    double get_acc() { return accuracy; }
-
-private slots:
-    void finishedreply(QNetworkReply *r);
-
-private:
-    // info
-    QString user;
-    QString pass;
-    double latitude;
-    double longitude;
-    double accuracy;
-    // stuff
-    QNetworkAccessManager *worker;
-    QUrl urllogin;
-    QUrl urldologin;
-    QUrl urlupdate;
-};
-
-#endif // GLATITUDE_H
diff --git a/src/gps.cpp b/src/gps.cpp
deleted file mode 100644 (file)
index 0fb4ba7..0000000
+++ /dev/null
@@ -1,32 +0,0 @@
-#include "gps.h"
-
-#ifdef Q_WS_MAEMO_5
-
-GpsMaemo5::GpsMaemo5(QObject *parent) : QObject(parent) {
-    latitude = 0;
-    longitude = 0;
-    accuracy = 0;
-
-    control = location_gpsd_control_get_default();
-    device = (LocationGPSDevice*) g_object_new(LOCATION_TYPE_GPS_DEVICE, NULL);
-
-    g_signal_connect(device, "changed", G_CALLBACK(GpsMaemo5_changed), this);
-    g_object_set(G_OBJECT(control), "preferred-method", LOCATION_METHOD_ACWP, NULL);
-    g_object_set(G_OBJECT(control), "preferred-interval", LOCATION_INTERVAL_120S, NULL);
-
-    location_gpsd_control_start(control);
-}
-
-void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps) {
-    if (device->fix) {
-        if (device->fix->fields) {
-            g_print("lat = %f, long = %f, eph = %f\n", gps->device->fix->latitude, gps->device->fix->longitude, gps->device->fix->eph/100.);
-            gps->latitude = gps->device->fix->latitude;
-            gps->longitude = gps->device->fix->longitude;
-            gps->accuracy = gps->device->fix->eph/100.;
-            emit gps->fix();
-        }
-    }
-}
-
-#endif // Q_WS_MAEMO_5
diff --git a/src/gps.h b/src/gps.h
deleted file mode 100644 (file)
index 2d9cfdf..0000000
--- a/src/gps.h
+++ /dev/null
@@ -1,55 +0,0 @@
-#ifndef GPS_H
-#define GPS_H
-
-#include <QObject>
-
-#ifdef Q_WS_MAEMO_5
-
-extern "C" {
-#include <location/location-gps-device.h>
-#include <location/location-gpsd-control.h>
-}
-
-class GpsMaemo5 : public QObject {
-    Q_OBJECT
-
-signals:
-    void fix();
-
-public:
-    GpsMaemo5(QObject *parent = 0);
-    double get_lat() { return latitude; }
-    double get_lon() { return longitude; }
-    double get_acc() { return accuracy; }
-    friend void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps);
-
-private:
-    double latitude;
-    double longitude;
-    double accuracy;
-
-    GMainLoop *loop;
-    LocationGPSDControl *control;
-    LocationGPSDevice *device;
-};
-
-void GpsMaemo5_changed(LocationGPSDevice *device, GpsMaemo5 *gps);
-
-#else // Q_WS_MAEMO_5
-
-class GpsMaemo5 : public QObject {
-    Q_OBJECT
-
-signals:
-    void fix();
-
-public:
-    GpsMaemo5(QObject *parent = 0) { Q_UNUSED(parent); }
-    double get_lat() { return 0; }
-    double get_lon() { return 0; }
-    double get_acc() { return 0; }
-};
-
-#endif // Q_WS_MAEMO_5
-
-#endif // GPS_H
diff --git a/src/latitude.cpp b/src/latitude.cpp
deleted file mode 100644 (file)
index 864f5c0..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-#include "latitude.h"
-
-LatitudeGUI::LatitudeGUI(QMainWindow *parent) : QMainWindow(parent) {
-#ifdef Q_WS_MAEMO_5
-    setAttribute(Qt::WA_Maemo5AutoOrientation, true);
-#endif
-    setWindowTitle(tr("Latitude & Buzz"));
-
-    setting = new QSettings();
-
-    // login input
-    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);
-    QFormLayout *layout_login = new QFormLayout();
-    layout_login->addRow(tr("&Username"), login_user);
-    layout_login->addRow(tr("&Password"), login_pass);
-    connect(login_user, SIGNAL(textEdited(QString)), this, SLOT(save_user(QString)));
-    connect(login_pass, SIGNAL(textEdited(QString)), this, SLOT(save_pass(QString)));
-    connect(login_user, SIGNAL(returnPressed()), login_pass, SLOT(setFocus()));
-    connect(login_pass, SIGNAL(returnPressed()), dialoglogin, SLOT(accept()));
-    dialoglogin->setLayout(layout_login);
-    dialoglogin->exec();
-
-    // 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(url);
-    menuBar()->addAction(tr("&Latitude"), this, SLOT(mode_latitude()));
-    menuBar()->addAction(tr("&Buzz"), this, SLOT(mode_buzz()));
-
-    // 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()));
-
-    // show it
-    setCentralWidget(maps);
-}
-
-void LatitudeGUI::set() {
-#ifdef Q_WS_MAEMO_5
-    QMaemo5InformationBox::information(this, "new position...", 1000);
-#else
-    qDebug() << "new position...";
-#endif
-    glatitude->login(setting->value("user","my_username").toString(),
-                     setting->value("pass","my_password").toString());
-    glatitude->set(gps->get_lat(),
-                   gps->get_lon(),
-                   gps->get_acc());
-}
-
-void LatitudeGUI::latitude_OK() {
-#ifdef Q_WS_MAEMO_5
-    QMaemo5InformationBox::information(this, "...location Sent!", 1000);
-#else
-    qDebug() << "...location Sent!";
-#endif
-}
-
-void LatitudeGUI::latitude_ERROR() {
-#ifdef Q_WS_MAEMO_5
-    QMaemo5InformationBox::information(this, "Error in Authentification !", 3000);
-#else
-    qDebug() << "Error in Authentification !";
-#endif
-}
-
-void LatitudeGUI::save_user(QString _user) {
-    setting->setValue("user", _user);
-}
-void LatitudeGUI::save_pass(QString _pass) {
-    setting->setValue("pass", _pass);
-}
-
-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::maps_login() {
-    if ( maps->url() == url ) {
-        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();");
-    }
-}
diff --git a/src/latitude.h b/src/latitude.h
deleted file mode 100644 (file)
index 4f2362d..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#ifndef LATITUDE_H
-#define LATITUDE_H
-
-#include <QtGui>
-#include <QtWebKit>
-#include "glatitude.h"
-#include "gps.h"
-#ifdef Q_WS_MAEMO_5
-#include <QtMaemo5>
-#endif
-
-class LatitudeGUI : public QMainWindow {
-    Q_OBJECT
-
-signals:
-    void newpos();
-
-public:
-    LatitudeGUI(QMainWindow *parent = 0);
-
-private slots:
-    void set();
-    void latitude_OK();
-    void latitude_ERROR();
-    void save_user(QString);
-    void save_pass(QString);
-    void maps_login();
-    void mode_buzz();
-    void mode_latitude();
-
-private:
-    GoogleLatitude *glatitude;
-    GpsMaemo5 *gps;
-    QSettings *setting;
-    QWebView *maps;
-    QUrl url;
-};
-
-#endif // LATITUDE_H
diff --git a/src/main.cpp b/src/main.cpp
deleted file mode 100644 (file)
index fd38f35..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-#include "latitude.h"
-
-int main(int argc, char *argv[]) {
-    QApplication app(argc, argv);
-    QCoreApplication::setOrganizationName("linfati");
-    QCoreApplication::setOrganizationDomain("linfati.com");
-    QCoreApplication::setApplicationName("GoogleLatitude");
-
-    LatitudeGUI *gui = new LatitudeGUI();
-    gui->show();
-
-    return app.exec();
-}
-
-/*
- TODO:
- on auth error -> stop gps
- on new pos, only set it
- send new pos every 120s, only if is diferent
- no n900 -> por ip
- */
diff --git a/src/settings/main.cpp b/src/settings/main.cpp
new file mode 100644 (file)
index 0000000..6a0cb8c
--- /dev/null
@@ -0,0 +1,25 @@
+#include <QApplication>
+
+#include "settings.h"
+
+int main(int argc, char *argv[]) {
+    QApplication app(argc, argv);
+    QCoreApplication::setOrganizationName("linfati");
+    QCoreApplication::setOrganizationDomain("linfati.com");
+    QCoreApplication::setApplicationName("GoogleLatitude");
+
+    Settings *settings = new Settings();
+    settings->setWindowModality(Qt::ApplicationModal);
+    settings->show();
+
+    return app.exec();
+}
+
+/*
+ TODO:
+ on auth error -> stop gps
+ on new pos, only set it
+ send new pos every 120s, only if is diferent
+ no n900 -> por ip
+ */
+
diff --git a/src/settings/settings.cpp b/src/settings/settings.cpp
new file mode 100644 (file)
index 0000000..55f36db
--- /dev/null
@@ -0,0 +1,217 @@
+#include "settings.h"
+#include "ui_settings.h"
+#include "../common/dbusclient.h"
+
+#include <QProcess>
+#include <QDebug>
+
+Settings::Settings(QWidget *parent) :
+    QWidget(parent),
+    ui(new Ui::Settings)
+{
+    intervals << tr("1 second") << tr("2 seconds") << tr("5 seconds") <<
+                 tr("10 seconds") << tr("20 seconds") << tr("30 seconds") <<
+                 tr("60 seconds") << tr("120 seconds");
+
+    ui->setupUi(this);
+    addUIElements();   //Add Maemo 5 Specific widgets
+
+    settings = new QSettings();
+    loadSettings();
+
+    //Make the window a modal panel
+    setWindowFlags(Qt::Dialog);
+    setWindowModality(Qt::ApplicationModal);
+
+    connect(ui->login_user, SIGNAL(returnPressed()), ui->login_pass, SLOT(setFocus()));
+    connect(ui->login_pass, SIGNAL(returnPressed()), SLOT(close()));
+    connect(ui->ok_button, SIGNAL(clicked()), SLOT(close()));
+
+}
+
+Settings::~Settings()
+{
+#ifdef Q_WS_MAEMO_5
+    delete interval_button;
+    delete interval_selector;
+    delete interval_model;
+#endif
+    delete ui;
+    delete settings;
+}
+
+void Settings::addUIElements()
+{
+    QVBoxLayout* ui_layout = (QVBoxLayout*)ui->scrollArea->widget()->layout();
+#ifdef Q_WS_MAEMO_5
+    interval_button = new QMaemo5ValueButton("Update Interval",ui->scrollArea->widget());
+    interval_button->setValueLayout(QMaemo5ValueButton::ValueBesideText);
+    interval_selector = new QMaemo5ListPickSelector;
+    interval_model = new QStandardItemModel(0, 1);
+    populateListModel(interval_model);
+    interval_selector->setModel(interval_model);
+    interval_button->setPickSelector(interval_selector);
+    ui_layout->insertWidget(4, interval_button);
+#endif
+}
+
+void Settings::closeEvent(QCloseEvent *event)
+{
+    storeSettings();
+    settings->sync();
+#ifdef Q_WS_MAEMO_5
+    updateDaemon();
+#endif
+    event->accept();
+}
+
+void Settings::loadSettings()
+{
+    unsigned short location;
+    unsigned short interval;
+
+    ui->connectIfNecessary->setChecked( settings->value("autoconnect",true).toBool() );
+    ui->launchOnPowerOn->setChecked( settings->value("autolaunch",false).toBool() );
+#ifdef Q_WS_MAEMO_5
+    location = settings->value("location", LOCATION_METHOD_GNSS).toInt();
+#endif
+    ui->login_user->setText(settings->value("user","my_username").toString());
+    ui->login_pass->setText(settings->value("pass","my_password").toString());
+#ifdef Q_WS_MAEMO_5
+    switch(settings->value("interval", LOCATION_INTERVAL_20S).toInt()) {
+        case LOCATION_INTERVAL_1S:
+            interval = 0;
+            break;
+        case LOCATION_INTERVAL_2S:
+            interval = 1;
+            break;
+        case LOCATION_INTERVAL_5S:
+            interval = 2;
+            break;
+        case LOCATION_INTERVAL_10S:
+            interval = 3;
+            break;
+        case LOCATION_INTERVAL_20S:
+            interval = 4;
+            break;
+        case LOCATION_INTERVAL_30S:
+            interval = 5;
+            break;
+        case LOCATION_INTERVAL_60S:
+            interval = 6;
+            break;
+        case LOCATION_INTERVAL_120S:
+            interval = 7;
+            break;
+    }
+    interval_selector->setCurrentIndex(interval);
+
+
+    if (DBusClient::daemonRunning())
+        ui->status_on->setChecked(true);
+    else
+        ui->status_off->setChecked(true);
+
+
+    switch (location) {
+        case LOCATION_METHOD_GNSS:
+            ui->location_gps->setChecked(true);
+            break;
+        case LOCATION_METHOD_AGNSS | LOCATION_METHOD_ACWP:
+            ui->location_gps_network->setChecked(true);
+            break;
+        case LOCATION_METHOD_ACWP:
+            ui->location_network->setChecked(true);
+            break;
+    }
+#endif
+}
+
+void Settings::populateListModel(QStandardItemModel *model)
+{
+    for(int i = 0; i < intervals.size(); ++i) {
+        QStandardItem *item = new QStandardItem(intervals.at(i));
+        item->setTextAlignment(Qt::AlignCenter); // the Maemo 5 design spec recommends this.
+        item->setEditable(false); // prevent editing of the item
+        model->appendRow(item);
+    }
+}
+
+void Settings::storeSettings()
+{
+    unsigned short status;
+    unsigned short location;
+    unsigned short interval;
+
+    settings->setValue("autoconnect", ui->connectIfNecessary->checkState());
+    settings->setValue("autolaunch", ui->launchOnPowerOn->checkState());
+    settings->setValue("user", ui->login_user->text());
+    settings->setValue("pass", ui->login_pass->text());
+#ifdef Q_WS_MAEMO_5
+    switch(interval_selector->currentIndex()) {
+        case 0:
+            interval = LOCATION_INTERVAL_1S;
+            break;
+        case 1:
+            interval = LOCATION_INTERVAL_2S;
+            break;
+        case 2:
+            interval = LOCATION_INTERVAL_5S;
+            break;
+        case 3:
+            interval = LOCATION_INTERVAL_10S;
+            break;
+        case 4:
+            interval = LOCATION_INTERVAL_20S;
+            break;
+        case 5:
+            interval = LOCATION_INTERVAL_30S;
+            break;
+        case 6:
+            interval = LOCATION_INTERVAL_60S;
+            break;
+        case 7:
+            interval = LOCATION_INTERVAL_120S;
+            break;
+    }
+    settings->setValue("interval", interval);
+
+    if (ui->location_gps->isChecked())
+        location = LOCATION_METHOD_GNSS;
+    else if (ui->location_gps_network->isChecked())
+        location = LOCATION_METHOD_AGNSS | LOCATION_METHOD_ACWP;
+    else if (ui->location_network->isChecked())
+        location = LOCATION_METHOD_ACWP;
+    settings->setValue("location", location);
+#endif
+
+    settings->setValue("status", status);
+}
+
+#ifdef Q_WS_MAEMO_5
+void Settings::updateDaemon()
+{
+    if (ui->status_on->isChecked()) {
+        if (DBusClient::daemonRunning())
+            DBusClient::reloadDaemonConfig();
+        else
+            (new QProcess())->start(QString("/opt/linfati.com/googlelatitude-daemon"));
+    }
+    else if (ui->status_off->isChecked())
+        DBusClient::quitDaemon();
+    //else if (ui->status_hide->isChecked())
+    //    status = STATUS_HIDE;
+}
+#endif
+
+void Settings::changeEvent(QEvent *e)
+{
+    QWidget::changeEvent(e);
+    switch (e->type()) {
+    case QEvent::LanguageChange:
+        ui->retranslateUi(this);
+        break;
+    default:
+        break;
+    }
+}
diff --git a/src/settings/settings.h b/src/settings/settings.h
new file mode 100644 (file)
index 0000000..bd25d29
--- /dev/null
@@ -0,0 +1,55 @@
+#ifndef SETTINGS_H
+#define SETTINGS_H
+
+#include <QWidget>
+#include <QStandardItemModel>
+#include <QSettings>
+#include <QPushButton>
+#include <QCloseEvent>
+#include <QLineEdit>
+#include <QFormLayout>
+#ifdef Q_WS_MAEMO_5
+#include <QMaemo5ValueButton>
+#include <QMaemo5ListPickSelector>
+#include <QStandardItemModel>
+extern "C" {
+#include <location/location-gps-device.h>
+#include <location/location-gpsd-control.h>
+}
+#endif
+namespace Ui {
+    class Settings;
+}
+
+class Settings : public QWidget
+{
+    Q_OBJECT
+
+public:
+    explicit Settings(QWidget *parent = 0);
+    ~Settings();
+
+protected:
+    void changeEvent(QEvent *e);
+    void closeEvent(QCloseEvent *e);
+
+private:
+#ifdef Q_WS_MAEMO_5
+    void updateDaemon();
+#endif
+    void addUIElements();
+    void loadSettings();
+    void storeSettings();
+    void populateListModel(QStandardItemModel *model);
+    enum statuses { STATUS_ON, STATUS_OFF, STATUS_HIDE };
+    Ui::Settings *ui;
+    QStringList intervals;
+    QSettings *settings;
+#ifdef Q_WS_MAEMO_5
+    QMaemo5ValueButton *interval_button;
+    QMaemo5ListPickSelector *interval_selector;
+    QStandardItemModel* interval_model;
+#endif
+};
+
+#endif // SETTINGS_H
diff --git a/src/settings/settings.pro b/src/settings/settings.pro
new file mode 100644 (file)
index 0000000..3ce86cc
--- /dev/null
@@ -0,0 +1,34 @@
+TARGET      = googlelatitude-settings
+HEADERS    += settings.h ../common/dbusclient.h
+SOURCES    += main.cpp settings.cpp ../common/dbusclient.cpp
+
+OBJECTS_DIR = build
+MOC_DIR     = build
+DESTDIR     = build
+
+TEMPLATE    = app
+
+contains(QT_CONFIG, maemo5) {
+    QT          += maemo5 dbus
+    CONFIG      += link_pkgconfig
+    PKGCONFIG   += glib-2.0 liblocation
+}
+
+FORMS += \
+    settings.ui
+
+unix {
+  #VARIABLES
+  isEmpty(PREFIX) {
+    PREFIX = /usr
+  }
+  BINDIR = $$PREFIX/bin
+  DATADIR =$$PREFIX/share
+
+  DEFINES += DATADIR=\\\"$$DATADIR\\\" PKGDATADIR=\\\"$$PKGDATADIR\\\"
+
+  #MAKE INSTALL
+
+  INSTALLS += target
+  target.path =$$BINDIR
+}
diff --git a/src/settings/settings.ui b/src/settings/settings.ui
new file mode 100644 (file)
index 0000000..4ae43a5
--- /dev/null
@@ -0,0 +1,206 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<ui version="4.0">
+ <class>Settings</class>
+ <widget class="QWidget" name="Settings">
+  <property name="geometry">
+   <rect>
+    <x>0</x>
+    <y>0</y>
+    <width>640</width>
+    <height>480</height>
+   </rect>
+  </property>
+  <property name="windowTitle">
+   <string>Settings</string>
+  </property>
+  <layout class="QVBoxLayout" name="verticalLayout">
+   <item>
+    <widget class="QScrollArea" name="scrollArea">
+     <property name="horizontalScrollBarPolicy">
+      <enum>Qt::ScrollBarAlwaysOff</enum>
+     </property>
+     <property name="widgetResizable">
+      <bool>true</bool>
+     </property>
+     <widget class="QWidget" name="widget">
+      <property name="geometry">
+       <rect>
+        <x>0</x>
+        <y>0</y>
+        <width>618</width>
+        <height>458</height>
+       </rect>
+      </property>
+      <layout class="QVBoxLayout" name="verticalLayout_2">
+       <item>
+        <widget class="QGroupBox" name="groupBox">
+         <property name="title">
+          <string>Latitude Status</string>
+         </property>
+         <layout class="QHBoxLayout" name="horizontalLayout">
+          <property name="spacing">
+           <number>0</number>
+          </property>
+          <property name="margin">
+           <number>0</number>
+          </property>
+          <item>
+           <widget class="QRadioButton" name="status_on">
+            <property name="text">
+             <string>On</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QRadioButton" name="status_off">
+            <property name="text">
+             <string>Off</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QRadioButton" name="status_hide">
+            <property name="enabled">
+             <bool>false</bool>
+            </property>
+            <property name="text">
+             <string>Hide</string>
+            </property>
+           </widget>
+          </item>
+         </layout>
+        </widget>
+       </item>
+       <item>
+        <widget class="QGroupBox" name="groupBox_2">
+         <property name="title">
+          <string>Location Mode</string>
+         </property>
+         <layout class="QHBoxLayout" name="horizontalLayout_2">
+          <property name="spacing">
+           <number>0</number>
+          </property>
+          <property name="margin">
+           <number>0</number>
+          </property>
+          <item>
+           <widget class="QRadioButton" name="location_gps">
+            <property name="text">
+             <string>GPS Only</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QRadioButton" name="location_gps_network">
+            <property name="text">
+             <string>GPS + Mobile Network</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QRadioButton" name="location_network">
+            <property name="text">
+             <string>Mobile Network</string>
+            </property>
+           </widget>
+          </item>
+         </layout>
+        </widget>
+       </item>
+       <item>
+        <widget class="QCheckBox" name="launchOnPowerOn">
+         <property name="text">
+          <string>Launch on power on</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QCheckBox" name="connectIfNecessary">
+         <property name="enabled">
+          <bool>false</bool>
+         </property>
+         <property name="text">
+          <string>Connect to network if necessary</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QGroupBox" name="groupBox_3">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Preferred" vsizetype="Maximum">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="title">
+          <string>Google Login</string>
+         </property>
+         <layout class="QFormLayout" name="formLayout">
+          <property name="fieldGrowthPolicy">
+           <enum>QFormLayout::ExpandingFieldsGrow</enum>
+          </property>
+          <item row="0" column="0">
+           <widget class="QLabel" name="label">
+            <property name="text">
+             <string>Login</string>
+            </property>
+           </widget>
+          </item>
+          <item row="0" column="1">
+           <widget class="QLineEdit" name="login_user"/>
+          </item>
+          <item row="2" column="0">
+           <widget class="QLabel" name="label_2">
+            <property name="text">
+             <string>Password</string>
+            </property>
+           </widget>
+          </item>
+          <item row="2" column="1">
+           <widget class="QLineEdit" name="login_pass">
+            <property name="echoMode">
+             <enum>QLineEdit::Password</enum>
+            </property>
+           </widget>
+          </item>
+         </layout>
+        </widget>
+       </item>
+       <item>
+        <widget class="QWidget" name="widget_2" native="true">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Preferred" vsizetype="Maximum">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <layout class="QHBoxLayout" name="horizontalLayout_3">
+          <item>
+           <widget class="QPushButton" name="about_button">
+            <property name="enabled">
+             <bool>false</bool>
+            </property>
+            <property name="text">
+             <string>About...</string>
+            </property>
+           </widget>
+          </item>
+          <item>
+           <widget class="QPushButton" name="ok_button">
+            <property name="text">
+             <string>Ok</string>
+            </property>
+           </widget>
+          </item>
+         </layout>
+        </widget>
+       </item>
+      </layout>
+     </widget>
+    </widget>
+   </item>
+  </layout>
+ </widget>
+ <resources/>
+ <connections/>
+</ui>
diff --git a/src/settings/ui_settings.h b/src/settings/ui_settings.h
new file mode 100644 (file)
index 0000000..b5e6604
--- /dev/null
@@ -0,0 +1,230 @@
+/********************************************************************************
+** Form generated from reading UI file 'settings.ui'
+**
+** Created: Thu Jan 6 21:00:12 2011
+**      by: Qt User Interface Compiler version 4.7.0
+**
+** WARNING! All changes made in this file will be lost when recompiling UI file!
+********************************************************************************/
+
+#ifndef UI_SETTINGS_H
+#define UI_SETTINGS_H
+
+#include <QtCore/QVariant>
+#include <QtGui/QAction>
+#include <QtGui/QApplication>
+#include <QtGui/QButtonGroup>
+#include <QtGui/QCheckBox>
+#include <QtGui/QFormLayout>
+#include <QtGui/QGroupBox>
+#include <QtGui/QHBoxLayout>
+#include <QtGui/QHeaderView>
+#include <QtGui/QLabel>
+#include <QtGui/QLineEdit>
+#include <QtGui/QPushButton>
+#include <QtGui/QRadioButton>
+#include <QtGui/QScrollArea>
+#include <QtGui/QVBoxLayout>
+#include <QtGui/QWidget>
+
+QT_BEGIN_NAMESPACE
+
+class Ui_Settings
+{
+public:
+    QVBoxLayout *verticalLayout;
+    QScrollArea *scrollArea;
+    QWidget *widget;
+    QVBoxLayout *verticalLayout_2;
+    QGroupBox *groupBox;
+    QHBoxLayout *horizontalLayout;
+    QRadioButton *status_on;
+    QRadioButton *status_off;
+    QRadioButton *status_hide;
+    QGroupBox *groupBox_2;
+    QHBoxLayout *horizontalLayout_2;
+    QRadioButton *location_gps;
+    QRadioButton *location_gps_network;
+    QRadioButton *location_network;
+    QCheckBox *launchOnPowerOn;
+    QCheckBox *connectIfNecessary;
+    QGroupBox *groupBox_3;
+    QFormLayout *formLayout;
+    QLabel *label;
+    QLineEdit *login_user;
+    QLabel *label_2;
+    QLineEdit *login_pass;
+    QWidget *widget_2;
+    QHBoxLayout *horizontalLayout_3;
+    QPushButton *about_button;
+    QPushButton *ok_button;
+
+    void setupUi(QWidget *Settings)
+    {
+        if (Settings->objectName().isEmpty())
+            Settings->setObjectName(QString::fromUtf8("Settings"));
+        Settings->resize(640, 480);
+        verticalLayout = new QVBoxLayout(Settings);
+        verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));
+        scrollArea = new QScrollArea(Settings);
+        scrollArea->setObjectName(QString::fromUtf8("scrollArea"));
+        scrollArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
+        scrollArea->setWidgetResizable(true);
+        widget = new QWidget();
+        widget->setObjectName(QString::fromUtf8("widget"));
+        widget->setGeometry(QRect(0, 0, 618, 458));
+        verticalLayout_2 = new QVBoxLayout(widget);
+        verticalLayout_2->setObjectName(QString::fromUtf8("verticalLayout_2"));
+        groupBox = new QGroupBox(widget);
+        groupBox->setObjectName(QString::fromUtf8("groupBox"));
+        horizontalLayout = new QHBoxLayout(groupBox);
+        horizontalLayout->setSpacing(0);
+        horizontalLayout->setContentsMargins(0, 0, 0, 0);
+        horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));
+        status_on = new QRadioButton(groupBox);
+        status_on->setObjectName(QString::fromUtf8("status_on"));
+
+        horizontalLayout->addWidget(status_on);
+
+        status_off = new QRadioButton(groupBox);
+        status_off->setObjectName(QString::fromUtf8("status_off"));
+
+        horizontalLayout->addWidget(status_off);
+
+        status_hide = new QRadioButton(groupBox);
+        status_hide->setObjectName(QString::fromUtf8("status_hide"));
+        status_hide->setEnabled(false);
+
+        horizontalLayout->addWidget(status_hide);
+
+
+        verticalLayout_2->addWidget(groupBox);
+
+        groupBox_2 = new QGroupBox(widget);
+        groupBox_2->setObjectName(QString::fromUtf8("groupBox_2"));
+        horizontalLayout_2 = new QHBoxLayout(groupBox_2);
+        horizontalLayout_2->setSpacing(0);
+        horizontalLayout_2->setContentsMargins(0, 0, 0, 0);
+        horizontalLayout_2->setObjectName(QString::fromUtf8("horizontalLayout_2"));
+        location_gps = new QRadioButton(groupBox_2);
+        location_gps->setObjectName(QString::fromUtf8("location_gps"));
+
+        horizontalLayout_2->addWidget(location_gps);
+
+        location_gps_network = new QRadioButton(groupBox_2);
+        location_gps_network->setObjectName(QString::fromUtf8("location_gps_network"));
+
+        horizontalLayout_2->addWidget(location_gps_network);
+
+        location_network = new QRadioButton(groupBox_2);
+        location_network->setObjectName(QString::fromUtf8("location_network"));
+
+        horizontalLayout_2->addWidget(location_network);
+
+
+        verticalLayout_2->addWidget(groupBox_2);
+
+        launchOnPowerOn = new QCheckBox(widget);
+        launchOnPowerOn->setObjectName(QString::fromUtf8("launchOnPowerOn"));
+
+        verticalLayout_2->addWidget(launchOnPowerOn);
+
+        connectIfNecessary = new QCheckBox(widget);
+        connectIfNecessary->setObjectName(QString::fromUtf8("connectIfNecessary"));
+        connectIfNecessary->setEnabled(false);
+
+        verticalLayout_2->addWidget(connectIfNecessary);
+
+        groupBox_3 = new QGroupBox(widget);
+        groupBox_3->setObjectName(QString::fromUtf8("groupBox_3"));
+        QSizePolicy sizePolicy(QSizePolicy::Preferred, QSizePolicy::Maximum);
+        sizePolicy.setHorizontalStretch(0);
+        sizePolicy.setVerticalStretch(0);
+        sizePolicy.setHeightForWidth(groupBox_3->sizePolicy().hasHeightForWidth());
+        groupBox_3->setSizePolicy(sizePolicy);
+        formLayout = new QFormLayout(groupBox_3);
+        formLayout->setObjectName(QString::fromUtf8("formLayout"));
+        formLayout->setFieldGrowthPolicy(QFormLayout::ExpandingFieldsGrow);
+        label = new QLabel(groupBox_3);
+        label->setObjectName(QString::fromUtf8("label"));
+
+        formLayout->setWidget(0, QFormLayout::LabelRole, label);
+
+        login_user = new QLineEdit(groupBox_3);
+        login_user->setObjectName(QString::fromUtf8("login_user"));
+
+        formLayout->setWidget(0, QFormLayout::FieldRole, login_user);
+
+        label_2 = new QLabel(groupBox_3);
+        label_2->setObjectName(QString::fromUtf8("label_2"));
+
+        formLayout->setWidget(2, QFormLayout::LabelRole, label_2);
+
+        login_pass = new QLineEdit(groupBox_3);
+        login_pass->setObjectName(QString::fromUtf8("login_pass"));
+        login_pass->setEchoMode(QLineEdit::Password);
+
+        formLayout->setWidget(2, QFormLayout::FieldRole, login_pass);
+
+
+        verticalLayout_2->addWidget(groupBox_3);
+
+        widget_2 = new QWidget(widget);
+        widget_2->setObjectName(QString::fromUtf8("widget_2"));
+        sizePolicy.setHeightForWidth(widget_2->sizePolicy().hasHeightForWidth());
+        widget_2->setSizePolicy(sizePolicy);
+        horizontalLayout_3 = new QHBoxLayout(widget_2);
+        horizontalLayout_3->setObjectName(QString::fromUtf8("horizontalLayout_3"));
+        about_button = new QPushButton(widget_2);
+        about_button->setObjectName(QString::fromUtf8("about_button"));
+        about_button->setEnabled(false);
+
+        horizontalLayout_3->addWidget(about_button);
+
+        ok_button = new QPushButton(widget_2);
+        ok_button->setObjectName(QString::fromUtf8("ok_button"));
+
+        horizontalLayout_3->addWidget(ok_button);
+
+
+        verticalLayout_2->addWidget(widget_2);
+
+        scrollArea->setWidget(widget);
+
+        verticalLayout->addWidget(scrollArea);
+
+
+        retranslateUi(Settings);
+
+        QMetaObject::connectSlotsByName(Settings);
+    } // setupUi
+
+    void retranslateUi(QWidget *Settings)
+    {
+        Settings->setWindowTitle(QApplication::translate("Settings", "Settings", 0, QApplication::UnicodeUTF8));
+        groupBox->setTitle(QApplication::translate("Settings", "Latitude Status", 0, QApplication::UnicodeUTF8));
+        status_on->setText(QApplication::translate("Settings", "On", 0, QApplication::UnicodeUTF8));
+        status_off->setText(QApplication::translate("Settings", "Off", 0, QApplication::UnicodeUTF8));
+        status_hide->setText(QApplication::translate("Settings", "Hide", 0, QApplication::UnicodeUTF8));
+        groupBox_2->setTitle(QApplication::translate("Settings", "Location Mode", 0, QApplication::UnicodeUTF8));
+        location_gps->setText(QApplication::translate("Settings", "GPS Only", 0, QApplication::UnicodeUTF8));
+        location_gps_network->setText(QApplication::translate("Settings", "GPS + Mobile Network", 0, QApplication::UnicodeUTF8));
+        location_network->setText(QApplication::translate("Settings", "Mobile Network", 0, QApplication::UnicodeUTF8));
+        launchOnPowerOn->setText(QApplication::translate("Settings", "Launch on power on", 0, QApplication::UnicodeUTF8));
+        connectIfNecessary->setText(QApplication::translate("Settings", "Connect to network if necessary", 0, QApplication::UnicodeUTF8));
+        groupBox_3->setTitle(QApplication::translate("Settings", "Google Login", 0, QApplication::UnicodeUTF8));
+        label->setText(QApplication::translate("Settings", "Login", 0, QApplication::UnicodeUTF8));
+        label_2->setText(QApplication::translate("Settings", "Password", 0, QApplication::UnicodeUTF8));
+        about_button->setText(QApplication::translate("Settings", "About...", 0, QApplication::UnicodeUTF8));
+        ok_button->setText(QApplication::translate("Settings", "Ok", 0, QApplication::UnicodeUTF8));
+    } // retranslateUi
+
+};
+
+namespace Ui {
+    class Settings: public Ui_Settings {};
+} // namespace Ui
+
+QT_END_NAMESPACE
+
+#endif // UI_SETTINGS_H
diff --git a/src/settingsplugin/.directory b/src/settingsplugin/.directory
new file mode 100644 (file)
index 0000000..9ffe6b1
--- /dev/null
@@ -0,0 +1,7 @@
+[Dolphin]
+AdditionalInfo=3
+CategorizedSorting=true
+ShowPreview=true
+Sorting=6
+Timestamp=2010,12,23,20,40,38
+ViewMode=1
diff --git a/src/settingsplugin/settingsplugin.c b/src/settingsplugin/settingsplugin.c
new file mode 100644 (file)
index 0000000..ca9aa4c
--- /dev/null
@@ -0,0 +1,34 @@
+#include <string.h>
+#include <stdlib.h>
+#include <X11/Xlib.h>
+#include <gdk/gdkx.h>
+#include <gtk/gtk.h>
+
+#ifdef MAEMO_CHANGES
+#include <libosso.h>
+
+static const char binary[] = "/opt/linfati.com/googlelatitude-settings";
+
+osso_return_t execute(osso_context_t *osso_context, gpointer parent, gboolean user_activated)
+{
+    char args[sizeof(binary) + 64];
+    Window id = None;
+
+    (void) osso_context;
+
+    if (parent && GTK_WIDGET(parent) && GTK_WIDGET(parent)->window)
+        id = gdk_x11_drawable_get_xid(GTK_WIDGET(parent)->window);
+
+    sprintf(args, "%s --parent 0x%08x%s", binary, (unsigned int) id, user_activated ? " --user" : "");
+    return system(args);
+}
+
+osso_return_t save_state(osso_context_t *osso_context, gpointer parent)
+{
+    (void) osso_context;
+    (void) parent;
+
+    return OSSO_OK;
+}
+
+#endif
diff --git a/src/settingsplugin/settingsplugin.pro b/src/settingsplugin/settingsplugin.pro
new file mode 100644 (file)
index 0000000..ad8b78f
--- /dev/null
@@ -0,0 +1,31 @@
+TARGET      = glsettingsplugin
+TEMPLATE = lib
+SOURCES = settingsplugin.c
+
+OBJECTS_DIR = build
+MOC_DIR     = build
+DESTDIR     = build
+
+CONFIG += plugin link_pkgconfig
+PKGCONFIG += gtk+-2.0 libosso
+
+unix {
+  #VARIABLES
+  isEmpty(PREFIX) {
+    PREFIX = /usr
+  }
+  BINDIR = $$PREFIX/bin
+  DATADIR =$$PREFIX/share
+
+  DEFINES += DATADIR=\\\"$$DATADIR\\\" PKGDATADIR=\\\"$$PKGDATADIR\\\"
+
+  #MAKE INSTALL
+
+  INSTALLS += target desktop
+
+  target.path = $$system(pkg-config hildon-control-panel --variable=pluginlibdir)
+
+  desktop.path = $$system(pkg-config hildon-control-panel --variable=plugindesktopentrydir)
+  desktop.files = ../../data/libglsettingsplugin.desktop
+}
+
diff --git a/src/src.pro b/src/src.pro
new file mode 100644 (file)
index 0000000..69564ca
--- /dev/null
@@ -0,0 +1,8 @@
+QMAKEVERSION = $$[QMAKE_VERSION]
+ISQT4 = $$find(QMAKEVERSION, ^[2-9])
+isEmpty( ISQT4 ) {
+error("Use the qmake include with Qt4.4 or greater, on Debian that is qmake-qt4");
+}
+
+TEMPLATE = subdirs
+SUBDIRS  = daemon settings settingsplugin