Changed the old code to work as a daemon
[googlelatitude] / src / daemon / main.cpp
1 #include "latitude.h"
2 #include "dbusadaptor.h"
3 #include "../common/dbusclient.h"
4
5 #include <QDBusConnection>
6 #include <QDebug>
7
8 int main(int argc, char *argv[]) {
9     QApplication app(argc, argv);
10     DBusAdaptor* adaptor = new DBusAdaptor(&app);
11     QCoreApplication::setOrganizationName("linfati");
12     QCoreApplication::setOrganizationDomain("linfati.com");
13     QCoreApplication::setApplicationName("GoogleLatitude");
14     if (!QDBusConnection::sessionBus().registerService("com.linfati.GoogleLatitude")) {
15 #ifdef Q_WS_MAEMO_5
16         DBusClient::showWindow();
17 #endif
18         return 0; //The application is already running
19     }
20     QDBusConnection::sessionBus().registerObject("/", &app);
21
22     QSettings* settings = new QSettings();
23
24     if(app.arguments().contains(QString("-s")) ||
25        app.arguments().contains(QString("--startup")))
26         if (!settings->value("autolaunch",false).toBool())
27             return 0;
28
29     app.setQuitOnLastWindowClosed(false);
30     LatitudeGUI *gui = new LatitudeGUI(settings);
31     adaptor->setDaemon(gui);
32
33     return app.exec();
34 }
35
36 /*
37  TODO:
38  on auth error -> stop gps
39  on new pos, only set it
40  send new pos every 120s, only if is diferent
41  no n900 -> por ip
42  */