Enable Daemon Option, submit for testing
authorRodrigo Linfati <rodrigo@linfati.cl>
Wed, 27 Jul 2011 18:58:02 +0000 (20:58 +0200)
committerRodrigo Linfati <rodrigo@linfati.cl>
Wed, 27 Jul 2011 18:58:02 +0000 (20:58 +0200)
LatitudeUpdaterDaemon.desktop [deleted file]
LatitudeUpdaterDaemon.png [deleted file]
latitudeqml.cpp
latitudeqml.h
latitudewidget.cpp
latitudewidget.h
main-daemon.cpp
main-qml.cpp
main-widget.cpp
qml/MainPage.qml

diff --git a/LatitudeUpdaterDaemon.desktop b/LatitudeUpdaterDaemon.desktop
deleted file mode 100644 (file)
index 901b786..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-[Desktop Entry]
-Encoding=UTF-8
-Version=1.0
-Type=Application
-Terminal=true
-Name=LatitudeDaemon
-Exec=/opt/LatitudeUpdaterDaemon/bin/LatitudeUpdaterDaemon
-Icon=LatitudeUpdaterDaDaemon
-X-Window-Icon=
-X-HildonDesk-ShowInToolbar=true
-X-Osso-Type=application/x-executable
diff --git a/LatitudeUpdaterDaemon.png b/LatitudeUpdaterDaemon.png
deleted file mode 100644 (file)
index d98268f..0000000
Binary files a/LatitudeUpdaterDaemon.png and /dev/null differ
index 0dd7af1..3ae61c0 100644 (file)
@@ -4,11 +4,17 @@
 LatitudeQML::LatitudeQML(QDeclarativeView *parent) :
     QDeclarativeView(parent),
     latitude(this),
-    gps(this) {
+    gps(this),
+    demonioOpt("/opt/LatitudeUpdaterDaemon/bin/LatitudeUpdaterDaemon"),
+    demonioSdk(QCoreApplication::applicationDirPath()+
+        QDir::separator()+
+        "LatitudeUpdaterDaemon"),
+    cli(this) {
     qDebug() << "* LatitudeQML::LatitudeQML";
 
     rootContext()->setContextProperty("latitude", &latitude);
     rootContext()->setContextProperty("gps", &gps);
+    rootContext()->setContextProperty("demonio", this);
     setSource(QUrl("qrc:/qml/main.qml"));
 
     latitude.getAccess();
index 13c8b27..c868551 100644 (file)
@@ -3,6 +3,10 @@
 
 #include <QObject>
 #include <QtDeclarative/QDeclarativeView>
+#include <QtCore/QProcess>
+#include <QtCore/QCoreApplication>
+#include <QtCore/QDir>
+#include <QtCore/QFile>
 #include "googlelatitude.h"
 #include "gpscontrol.h"
 
@@ -14,12 +18,45 @@ public:
 signals:
 
 public slots:
+    bool demonio_status() {
+        qDebug() << "LatitudeQML::demonio_status";
+        if (system("killall -0 LatitudeUpdaterDaemon 2> /dev/null" )) {
+            return false;
+        }
+        return true;
+    }
+    bool demonio_start() {
+        qDebug() << "LatitudeQML::demonio_start";
+        if (demonioOpt.exists()) {
+            qDebug() << "LatitudeQML:: demonio opt";
+            cli.startDetached(demonioOpt.fileName());
+            return true;
+        }
+        if (demonioSdk.exists()) {
+            qDebug() << "LatitudeQML:: demonio sdk";
+            cli.startDetached(demonioSdk.fileName());
+            return true;
+        }
+        qDebug() << "LatitudeQML:: demonio none";
+        return false;
+    }
+    bool demonio_stop() {
+        qDebug() << "LatitudeQML::demonio_stop";
+        if (demonioOpt.exists() || demonioSdk.exists() ) {
+            qDebug() << "LatitudeQML:: demonio kill" << system("killall LatitudeUpdaterDaemon 2> /dev/null");
+            return true;
+        }
+        return false;
+    }
 
 private slots:
 
 private:
     GoogleLatitude latitude;
     GpsControl gps;
+    QFile demonioOpt;
+    QFile demonioSdk;
+    QProcess cli;
 };
 
 #endif // LatitudeQML_H
index f81b786..6b754d9 100644 (file)
@@ -3,7 +3,12 @@
 LatitudeGUI::LatitudeGUI(QWidget *parent) :
     QWidget(parent),
     latitude(this),
-    gps(this) {
+    gps(this),
+    demonioOpt("/opt/LatitudeUpdaterDaemon/bin/LatitudeUpdaterDaemon"),
+    demonioSdk(QCoreApplication::applicationDirPath()+
+        QDir::separator()+
+        "LatitudeUpdaterDaemon"),
+    cli(this) {
     qDebug() << "* LatitudeGUI::LatitudeGUI";
     setWindowTitle(tr("LatitudeUpdater"));
 
@@ -28,32 +33,10 @@ LatitudeGUI::LatitudeGUI(QWidget *parent) :
     connect(&latitude, SIGNAL(notToken()), this, SLOT(gl_NotToken()) );
     connect(&latitude, SIGNAL(needAuth()), this, SLOT(gl_needAuth()) );
 
-    latitude.getAccess();
+    connect(&gps, SIGNAL(gotFix()), this, SLOT(set_latitude()) );
 
     // row 2
     layout_row2 = new QHBoxLayout();
-    pos_label = new QLabel("Position");
-    pos_lat = new QLineEdit("lat");
-    pos_lon = new QLineEdit("lon");
-    pos_acc = new QLineEdit("acc");
-    pos_tis = new QLineEdit("tis");
-
-    pos_lat->setReadOnly(true);
-    pos_lon->setReadOnly(true);
-    pos_acc->setReadOnly(true);
-    pos_tis->setReadOnly(true);
-
-    layout_row2->addWidget(pos_label);
-    layout_row2->addWidget(pos_lat);
-    layout_row2->addWidget(pos_lon);
-    layout_row2->addWidget(pos_acc);
-    layout_row2->addWidget(pos_tis);
-
-    connect(&gps, SIGNAL(gotUpdate()), this, SLOT(get_gps()) );
-    connect(&gps, SIGNAL(gotFix()), this, SLOT(set_latitude()) );
-
-    // row 3
-    layout_row3 = new QHBoxLayout();
     gps_group = new QButtonGroup();
     gps_method = new QLabel("Method");
     gps_cell = new QRadioButton("Cell Tower");
@@ -62,10 +45,10 @@ LatitudeGUI::LatitudeGUI(QWidget *parent) :
     gps_group->addButton(gps_cell);
     gps_group->addButton(gps_both);
     gps_group->addButton(gps_agps);
-    layout_row3->addWidget(gps_method);
-    layout_row3->addWidget(gps_cell);
-    layout_row3->addWidget(gps_both);
-    layout_row3->addWidget(gps_agps);
+    layout_row2->addWidget(gps_method);
+    layout_row2->addWidget(gps_cell);
+    layout_row2->addWidget(gps_both);
+    layout_row2->addWidget(gps_agps);
 
     if ( gps.getPositioningMethod() == "gps" ) gps_agps->setChecked(true);
     if ( gps.getPositioningMethod() == "cell" ) gps_cell->setChecked(true);
@@ -75,22 +58,22 @@ LatitudeGUI::LatitudeGUI(QWidget *parent) :
     connect(gps_both, SIGNAL(clicked()), this, SLOT(set_method()) );
     connect(gps_agps, SIGNAL(clicked()), this, SLOT(set_method()) );
 
-    // row 4
-    layout_row4 = new QHBoxLayout();
+    // row 3
+    layout_row3 = new QHBoxLayout();
     gps_to_label = new QLabel("Time Out");
     gps_to_slider = new QSlider(Qt::Horizontal);
     gps_to_slider->setSingleStep(5);
     gps_to_slider->setRange(5, 120);
     gps_to_slider->setValue(gps.getTimeOut());
     gps_to_slider_value = new QLabel(QString("%1 sec.").arg(gps_to_slider->value()));
-    layout_row4->addWidget(gps_to_label);
-    layout_row4->addWidget(gps_to_slider);
-    layout_row4->addWidget(gps_to_slider_value);
+    layout_row3->addWidget(gps_to_label);
+    layout_row3->addWidget(gps_to_slider);
+    layout_row3->addWidget(gps_to_slider_value);
 
     connect(gps_to_slider, SIGNAL(valueChanged(int)), this, SLOT(set_to(int)) );
 
-    // row 5
-    layout_row5 = new QHBoxLayout();
+    // row 4
+    layout_row4 = new QHBoxLayout();
     gps_i_label = new QLabel("Interval");
 
     gps_i_slider = new QSlider(Qt::Horizontal);
@@ -98,23 +81,23 @@ LatitudeGUI::LatitudeGUI(QWidget *parent) :
     gps_i_slider->setRange(5, 60);
     gps_i_slider->setValue(gps.getInterval()/60);
     gps_i_slider_value = new QLabel(QString("%1 min.").arg(gps_i_slider->value()));
-    layout_row5->addWidget(gps_i_label);
-    layout_row5->addWidget(gps_i_slider);
-    layout_row5->addWidget(gps_i_slider_value);
+    layout_row4->addWidget(gps_i_label);
+    layout_row4->addWidget(gps_i_slider);
+    layout_row4->addWidget(gps_i_slider_value);
 
     connect(gps_i_slider, SIGNAL(valueChanged(int)), this, SLOT(set_i(int)) );
 
-    // row 6
-    layout_row6 = new QHBoxLayout();
+    // row 5
+    layout_row5 = new QHBoxLayout();
     gps_ac_group = new QButtonGroup();
     gps_ac_label = new QLabel("Auto Connect");
     gps_ac_yes = new QRadioButton("Yes");
     gps_ac_not = new QRadioButton("No");
     gps_ac_group->addButton(gps_ac_yes);
     gps_ac_group->addButton(gps_ac_not);
-    layout_row6->addWidget(gps_ac_label);
-    layout_row6->addWidget(gps_ac_yes);
-    layout_row6->addWidget(gps_ac_not);
+    layout_row5->addWidget(gps_ac_label);
+    layout_row5->addWidget(gps_ac_yes);
+    layout_row5->addWidget(gps_ac_not);
 
     if ( latitude.getAutoConnect() == true ) gps_ac_yes->setChecked(true);
     if ( latitude.getAutoConnect() == false ) gps_ac_not->setChecked(true);
@@ -129,8 +112,8 @@ LatitudeGUI::LatitudeGUI(QWidget *parent) :
     layout_gui->addLayout(layout_row3);
     layout_gui->addLayout(layout_row4);
     layout_gui->addLayout(layout_row5);
-    layout_gui->addLayout(layout_row6);
 
     setLayout(layout_gui);
+    latitude.getAccess();
 }
 
index 26bb749..b4e6e8a 100644 (file)
@@ -3,14 +3,17 @@
 
 #include <QtGui/QWidget>
 #include <QtGui/QPushButton>
-#include <QtGui/QLineEdit>
 #include <QtGui/QLabel>
-#include <QtGui/QVBoxLayout>
-#include <QtGui/QHBoxLayout>
-#include <QtGui/QRadioButton>
 #include <QtGui/QButtonGroup>
+#include <QtGui/QRadioButton>
 #include <QtGui/QSlider>
+#include <QtGui/QVBoxLayout>
+#include <QtGui/QHBoxLayout>
 #include <QtGui/QDesktopServices>
+#include <QtCore/QProcess>
+#include <QtCore/QCoreApplication>
+#include <QtCore/QDir>
+#include <QtCore/QFile>
 #include "googlelatitude.h"
 #include "gpscontrol.h"
 
@@ -27,8 +30,13 @@ private slots:
     void gl_GotToken() {
         qDebug() << "LatitudeGUI::gl_GotToken";
         do_oauth->setDisabled(true);
-        do_start->setEnabled(true);
-        do_stop->setDisabled(true);
+        if (system("killall -0 LatitudeUpdaterDaemon 2> /dev/null" )) {
+            do_start->setEnabled(true);
+            do_stop->setDisabled(true);
+        } else {
+            do_start->setDisabled(true);
+            do_stop->setEnabled(true);
+        }
     }
     void gl_NotToken() {
         qDebug() << "LatitudeGUI::gl_NotToken";
@@ -49,26 +57,32 @@ private slots:
         qDebug() << "LatitudeGUI::gps_start";
         do_start->setDisabled(true);
         do_stop->setEnabled(true);
-        gps.startUpdates();
+        if (demonioOpt.exists()) {
+            qDebug() << "LatitudeGUI:: demonio opt";
+            cli.startDetached(demonioOpt.fileName());
+        } else if (demonioSdk.exists()) {
+            qDebug() << "LatitudeGUI:: demonio sdk";
+            cli.startDetached(demonioSdk.fileName());
+        } else {
+            qDebug() << "LatitudeGUI:: demonio none";
+            gps.startUpdates();
+        }
     }
     void gps_stop() {
         qDebug() << "LatitudeGUI::gps_stop";
         do_start->setEnabled(true);
         do_stop->setDisabled(true);
-        gps.stopUpdates(true);
-    }
-    void get_gps()  {
-        qDebug() << "LatitudeGUI::get_gps";
-        pos_lat->setText(QString("%1").arg(gps.getCurrentLatitude()));
-        pos_lon->setText(QString("%1").arg(gps.getCurrentLongitude()));
-        pos_acc->setText(QString("%1").arg(gps.getCurrentAccuracy()));
-        pos_tis->setText(QString("%1").arg(gps.getCurrentTimestamp()));
+        if (demonioOpt.exists() || demonioSdk.exists() ) {
+            qDebug() << "LatitudeGUI:: demonio kill" << system("killall LatitudeUpdaterDaemon 2> /dev/null");
+        } else {
+            gps.stopUpdates(true);
+        }
     }
     void set_latitude() {
         qDebug() << "LatitudeGUI::set_latitude";
-        latitude.setCurrentLocation(pos_lat->text().toDouble(),
-                                    pos_lon->text().toDouble(),
-                                    pos_acc->text().toDouble());
+        latitude.setCurrentLocation(gps.getCurrentLatitude(),
+                                    gps.getCurrentLongitude(),
+                                    gps.getCurrentAccuracy());
         latitude.sendCurrentLocation();
     }
     void set_method() {
@@ -100,6 +114,9 @@ private slots:
 private:
     GoogleLatitude latitude;
     GpsControl gps;
+    QFile demonioOpt;
+    QFile demonioSdk;
+    QProcess cli;
 
     QHBoxLayout *layout_row1;
     QPushButton *do_oauth;
@@ -107,30 +124,23 @@ private:
     QPushButton *do_stop;
 
     QHBoxLayout *layout_row2;
-    QLabel *pos_label;
-    QLineEdit *pos_lat;
-    QLineEdit *pos_lon;
-    QLineEdit *pos_acc;
-    QLineEdit *pos_tis;
-
-    QHBoxLayout *layout_row3;
     QLabel *gps_method;
     QButtonGroup *gps_group;
     QRadioButton *gps_cell;
     QRadioButton *gps_both;
     QRadioButton *gps_agps;
 
-    QHBoxLayout *layout_row4;
+    QHBoxLayout *layout_row3;
     QLabel *gps_to_label;
     QSlider *gps_to_slider;
     QLabel *gps_to_slider_value;
 
-    QHBoxLayout *layout_row5;
+    QHBoxLayout *layout_row4;
     QLabel *gps_i_label;
     QSlider *gps_i_slider;
     QLabel *gps_i_slider_value;
 
-    QHBoxLayout *layout_row6;
+    QHBoxLayout *layout_row5;
     QLabel *gps_ac_label;
     QButtonGroup *gps_ac_group;
     QRadioButton *gps_ac_yes;
@@ -140,3 +150,4 @@ private:
 };
 
 #endif // LATITUDEGUI_H
+
index be44174..2ca44e4 100644 (file)
@@ -2,7 +2,7 @@
 #include "latitudedaemon.h"
 
 int main(int argc, char *argv[]) {
-    qDebug() << "* main";
+    qDebug() << "* Main Daemon";
     QCoreApplication::setOrganizationName("linfati.com");
     QCoreApplication::setOrganizationDomain("linfati.com");
     QCoreApplication::setApplicationName("latitudeupdater");
index 1b6b9eb..98828f7 100644 (file)
@@ -2,7 +2,7 @@
 #include "latitudeqml.h"
 
 int main(int argc, char *argv[]) {
-    qDebug() << "* main";
+    qDebug() << "* Main QML";
     QCoreApplication::setOrganizationName("linfati.com");
     QCoreApplication::setOrganizationDomain("linfati.com");
     QCoreApplication::setApplicationName("latitudeupdater");
index 111498a..b3d2ba9 100644 (file)
@@ -2,7 +2,7 @@
 #include "latitudewidget.h"
 
 int main(int argc, char *argv[]) {
-    qDebug() << "* main";
+    qDebug() << "* Main Widget";
     QCoreApplication::setOrganizationName("linfati.com");
     QCoreApplication::setOrganizationDomain("linfati.com");
     QCoreApplication::setApplicationName("latitudeupdater");
index 17f9154..8decc23 100644 (file)
@@ -24,7 +24,9 @@ Page {
                 onClicked: {
                     do_start.enabled = false;
                     do_stop.enabled = true;
-                    gps.startUpdates()
+                    if (!demonio.demonio_start()) {
+                        gps.startUpdates()
+                    }
                 }
             }
             Button {
@@ -35,44 +37,9 @@ Page {
                 onClicked: {
                     do_start.enabled = true;
                     do_stop.enabled = false;
-                    gps.stopUpdates(true)
-                }
-            }
-        }
-        Row {
-            width: rootWindow.width
-            Label {
-                id: pos_label
-                text: "Position"
-                width: rootWindow.width / 4
-                anchors.verticalCenter: position.verticalCenter
-            }
-            Row {
-                id: position
-                width: rootWindow.width * 3 / 4
-                TextField  {
-                    id: pos_lat
-                    width: parent / 4
-                    placeholderText: "pos_lat"
-                    readOnly: true
-                }
-                TextField {
-                    id: pos_lon
-                    width: parent / 4
-                    placeholderText: "pos_lon"
-                    readOnly: true
-                }
-                TextField {
-                    id: pos_acc
-                    width: parent / 4
-                    placeholderText: "pos_acc"
-                    readOnly: true
-                }
-                TextField {
-                    id: pos_tis
-                    width: parent / 4
-                    placeholderText: "pos_tis"
-                    readOnly: true
+                    if (!demonio.demonio_stop()) {
+                        gps.stopUpdates(true)
+                    }
                 }
             }
         }
@@ -194,8 +161,13 @@ Page {
             target: latitude
             onGotToken: {
                 do_auth.enabled = false;
-                do_start.enabled = true;
-                do_stop.enabled = false;
+                if (demonio.demonio_status()) {
+                    do_start.enabled = false;
+                    do_stop.enabled = true;
+                } else {
+                    do_start.enabled = true;
+                    do_stop.enabled = false;
+                }
             }
         }
         Connections {
@@ -204,7 +176,9 @@ Page {
                 do_auth.enabled = true;
                 do_start.enabled = false;
                 do_stop.enabled = false;
-                gps.stopUpdates(true)
+                if (!demonio.demonio_stop()) {
+                    gps.stopUpdates(true)
+                }
             }
         }
         Connections {
@@ -216,21 +190,10 @@ Page {
 
         Connections {
             target: gps
-            onGotUpdate: {
-                pos_lat.text = gps.getCurrentLatitude()
-                pos_lon.text = gps.getCurrentLongitude()
-                pos_acc.text = gps.getCurrentAccuracy()
-                pos_tis.text = gps.getCurrentTimestamp()
-            }
-        }
-        Connections {
-            target: gps
             onGotFix: {
-                pos_lat.text = gps.getCurrentLatitude()
-                pos_lon.text = gps.getCurrentLongitude()
-                pos_acc.text = gps.getCurrentAccuracy()
-                pos_tis.text = gps.getCurrentTimestamp()
-                latitude.setCurrentLocation(pos_lat.text, pos_lon.text, pos_acc.text)
+                latitude.setCurrentLocation(gps.getCurrentLatitude(),
+                                            gps.getCurrentLongitude(),
+                                            gps.getCurrentAccuracy())
                 latitude.sendCurrentLocation()
             }
         }