fix the maximal unstable
[googlelatitude] / src / latitude.cpp
index 33e8719..1aaae62 100644 (file)
@@ -17,6 +17,15 @@ LatitudeGUI::LatitudeGUI(QMainWindow *parent) : QMainWindow(parent) {
     menuBar()->addAction(tr("&Buzz"), this, SLOT(mode_buzz()));
     menuBar()->addAction(tr("&Config"), this, SLOT(config()));
 
+    demonio = new QAction(this);
+    if ( system("killall -0 GoogleLatitudeDaemon 2> /dev/null" ) ) {
+        demonio->setText(tr("&Start Daemon"));
+    } else {
+        demonio->setText(tr("&Stop Daemon"));
+    }
+    connect(demonio, SIGNAL(triggered()), this, SLOT(mode_demonio()));
+    menuBar()->addAction(demonio);
+
     // updater
     glatitude = new GoogleLatitude(this);
     gps = new GpsMaemo5(this);
@@ -107,3 +116,17 @@ void LatitudeGUI::maps_login() {
         maps->page()->mainFrame()->evaluateJavaScript("document.getElementById('gaia_loginform').submit();");
     }
 }
+
+void LatitudeGUI::mode_demonio() {
+    if ( ! system("killall -0 GoogleLatitudeDaemon 2> /dev/null" ) ) {
+        system("killall GoogleLatitudeDaemon 2> /dev/null");
+        demonio->setText(tr("&Start Daemon"));
+    } else {
+        QProcess *cli = new QProcess(this);
+        cli->start(QCoreApplication::applicationDirPath()+QDir::separator()+"GoogleLatitudeDaemon");
+        qDebug() << "LatitudeGUI: demonio" << QCoreApplication::applicationDirPath()+"/GoogleLatitudeDaemon";
+        if ( ! system("killall -0 GoogleLatitudeDaemon 2> /dev/null" ) ) {
+            demonio->setText(tr("&Stop Daemon"));
+        }
+    }
+}