Version 0.6-2, use of cell+gps, fix "start daemon"
[googlelatitude] / src / latitude.cpp
index 7708be8..5f6038a 100644 (file)
@@ -43,7 +43,6 @@ LatitudeGUI::LatitudeGUI(QMainWindow *parent) : QMainWindow(parent) {
 
 void LatitudeGUI::set() {
     qDebug() << "LatitudeGUI: set";
-    set_config();
     glatitude->update(gps->get_lat(),
                       gps->get_lon(),
                       gps->get_acc());
@@ -56,7 +55,7 @@ void LatitudeGUI::set_config() {
 
     gps->config(setting->value("interval",1800).toInt(),
                 setting->value("wait",30).toInt(),
-                setting->value("usegps",false).toBool());
+                setting->value("method","cell").toString());
 }
 
 void LatitudeGUI::latitude_ok() {
@@ -103,8 +102,8 @@ void LatitudeGUI::mode_demonio() {
         demonio->setText(tr("&Start Daemon"));
     } else {
         QProcess *cli = new QProcess(this);
-        cli->start(QCoreApplication::applicationDirPath()+QDir::separator()+"GoogleLatitudeDaemon");
-        qDebug() << "LatitudeGUI: demonio" << QCoreApplication::applicationDirPath()+"/GoogleLatitudeDaemon";
+        cli->startDetached(QCoreApplication::applicationDirPath()+QDir::separator()+"GoogleLatitudeDaemon");
+        qDebug() << "LatitudeGUI: demonio" << QCoreApplication::applicationDirPath()+QDir::separator()+"GoogleLatitudeDaemon";
         if ( ! system("killall -0 GoogleLatitudeDaemon 2> /dev/null" ) ) {
             demonio->setText(tr("&Stop Daemon"));
         }
@@ -122,12 +121,6 @@ void LatitudeGUI::config() {
 
     QLineEdit *gps_interval = new QLineEdit(setting->value("interval",1800).toString());
     QLineEdit *gps_wait = new QLineEdit(setting->value("wait",30).toString());
-    QCheckBox *gps_use = new QCheckBox();
-    if ( setting->value("usegps",false).toBool() ) {
-        gps_use->setCheckState(Qt::Checked);
-    } else {
-        gps_use->setCheckState(Qt::Unchecked);
-    }
 
     QCheckBox *daemon_use = new QCheckBox();
     if ( setting->value("daemon",false).toBool() ) {
@@ -136,25 +129,47 @@ void LatitudeGUI::config() {
         daemon_use->setCheckState(Qt::Unchecked);
     }
 
-    QFormLayout *layout_config = new QFormLayout();
-    layout_config->addRow(tr("&Username"), login_user);
-    layout_config->addRow(tr("&Password"), login_pass);
-    layout_config->addRow(tr("&Interval for Updates"), gps_interval);
-    layout_config->addRow(tr("&Wait for a Fix"), gps_wait);
-    layout_config->addRow(tr("&Use Gps"), gps_use);
-    layout_config->addRow(tr("&Daemon at Boot"), daemon_use);
+    QRadioButton *gps_cell = new QRadioButton(tr("&Cell Tower"));
+    QRadioButton *gps_both = new QRadioButton(tr("&Both"));
+    QRadioButton *gps_agps = new QRadioButton(tr("Only &Gps"));
+
+    QString gps_setting = setting->value("method","cell").toString();
+    if ( gps_setting == QString("cell") ) {
+        gps_cell->setChecked(true);
+    } else if ( gps_setting == QString("both") ) {
+        gps_both->setChecked(true);
+    } else if ( gps_setting == QString("agps") ) {
+        gps_agps->setChecked(true);
+    } else {
+        gps_cell->setChecked(true);
+    }
+
+    QFormLayout *layout_form = new QFormLayout();
 
+    layout_form->addRow(tr("&Username"), login_user);
+    layout_form->addRow(tr("&Password"), login_pass);
     connect(login_user, SIGNAL(textEdited(QString)), this, SLOT(save_user(QString)));
     connect(login_user, SIGNAL(returnPressed()), login_pass, SLOT(setFocus()));
     connect(login_pass, SIGNAL(textEdited(QString)), this, SLOT(save_pass(QString)));
     connect(login_pass, SIGNAL(returnPressed()), dialoglogin, SLOT(accept()));
 
+    layout_form->addRow(tr("&Interval for Updates"), gps_interval);
+    layout_form->addRow(tr("&Wait for a Fix"), gps_wait);
+    layout_form->addRow(tr("&Daemon at Boot"), daemon_use);
     connect(gps_interval, SIGNAL(textEdited(QString)), this, SLOT(save_interval(QString)));
     connect(gps_wait, SIGNAL(textEdited(QString)), this, SLOT(save_wait(QString)));
-    connect(gps_use, SIGNAL(stateChanged(int)), this, SLOT(save_gps(int)));
     connect(daemon_use, SIGNAL(stateChanged(int)), this, SLOT(save_daemon(int)));
 
-    dialoglogin->setLayout(layout_config);
+    QHBoxLayout *layout_gps = new QHBoxLayout;
+    layout_gps->addWidget(gps_cell);
+    layout_gps->addWidget(gps_both);
+    layout_gps->addWidget(gps_agps);
+    layout_form->addRow(layout_gps);
+    connect(gps_cell, SIGNAL(clicked()), this, SLOT(save_gps_cell()));
+    connect(gps_both, SIGNAL(clicked()), this, SLOT(save_gps_both()));
+    connect(gps_agps, SIGNAL(clicked()), this, SLOT(save_gps_agps()));
+
+    dialoglogin->setLayout(layout_form);
     dialoglogin->exec();
 
     if ( setting->value("interval",1800).toInt() < 300 )
@@ -162,7 +177,7 @@ void LatitudeGUI::config() {
     if ( setting->value("interval",1800).toInt() > 3600 )
         setting->setValue("interval", 3600);
 
-    if ( setting->value("usegps",false).toBool() ) {
+    if ( QString("agps") == setting->value("method","cell").toString() ) {
         if ( setting->value("wait",30).toInt() < 15 )
             setting->setValue("wait", 15);
     } else {