Changed the old code to work as a daemon
[googlelatitude] / src / daemon / main.cpp
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
+ */