Removed file types from sound selector and poi selector.
[jspeed] / src / poisettings.cpp
index 09a4043..2388d5f 100644 (file)
 #include <QtGui/QLineEdit>
 #include <QtGui/QIntValidator>
 #include <QMaemo5InformationBox>
+#include <math.h>
 #include "poisettings.h"
 #include "fileselector.h"
 #include "poialerts.h"
 #include "settings.h"
-#include "mediaplayer.h"
 #include "poireader.h"
 #include "buttonbox.h"
 #include "soundselector.h"
+#include "odometer.h"
 
 
 PoiSettings::PoiSettings(QWidget* parent): QDialog(parent)
@@ -55,25 +56,24 @@ PoiSettings::PoiSettings(QWidget* parent): QDialog(parent)
 
     soundSelector_ = new SoundSelector;
 
-    QLabel* distanceLabel = new QLabel(tr("Alert distance"));
+    distanceLabel_ = new QLabel;
     distance_ = new QLineEdit;
-    distance_->setText(QString::number(Settings::instance().value("alert_distance", 300).toInt()));
     distance_->setValidator(new QIntValidator(0, 5000, this));
     QHBoxLayout* distance = new QHBoxLayout;
-    distance->addWidget(distanceLabel);
+    distance->addWidget(distanceLabel_);
     distance->addWidget(distance_);
-    onlyOnRoute_ = new QCheckBox(tr("Alert only if poi is in route"));
+    onlyOnRoute_ = new QCheckBox(tr("Alert only if poi is on route"));
     onlyOnRoute_->setChecked(Settings::instance().value("alert_only_on_route", true).toBool());
 
     ButtonBox* buttons = new ButtonBox;
-    buttons->addButton(tr("Save"), this, SLOT(saveSettings()), QDialogButtonBox::AcceptRole);
+    connect(buttons->addButton(tr("Save"), QDialogButtonBox::AcceptRole), SIGNAL(clicked(bool)), this, SLOT(saveSettings()));
 
     QHBoxLayout* layout = new QHBoxLayout;
     QVBoxLayout* left = new QVBoxLayout;
 
     left->addWidget(enabled_);
     left->addLayout(poiLayout);
-    left->addWidget(soundSelector_);
+    left->addLayout(soundSelector_);
     left->addLayout(distance);
     left->addWidget(onlyOnRoute_);
 
@@ -97,14 +97,19 @@ void PoiSettings::importFile()
 
 void PoiSettings::loadFiles()
 {
+    distanceLabel_->setText((tr("Alert distance (%1)").arg(Odometer::getMeterUnit())));
+    int speedValue = round(Settings::instance().value("alert_distance", 300).toDouble() * Odometer::getMeterMultiplier());
+    distance_->setText(QString::number(speedValue));
+
     QDir poiDir(PoiAlerts::getPoiDir());
 
     QString selectedSound = Settings::instance().value("alert_sound", "").toString();
+    soundSelector_->load();
     soundSelector_->setValue(selectedSound);
 
     poiFileSelector_->clear();
     QString selectedPoi = Settings::instance().value("alert_poi_file", "").toString();
-    poiFileSelector_->loadFiles(PoiAlerts::getPoiDir(), PoiReader::getFormatPattern());
+    poiFileSelector_->loadFiles(PoiAlerts::getPoiDir(), PoiReader::getFormatPattern(), true);
     poiFileSelector_->selectByValue(selectedPoi);
 
 }
@@ -127,17 +132,21 @@ void PoiSettings::saveSettings()
         return;
     }
 
+    double distance = distance_->text().toInt() / Odometer::getMeterMultiplier();
+
     Settings::instance().setValue("alert_enabled", enabled_->isChecked());
     Settings::instance().setValue("alert_only_on_route", onlyOnRoute_->isChecked());
-    Settings::instance().setValue("alert_distance", distance_->text().toInt());
+    Settings::instance().setValue("alert_distance", distance);
     Settings::instance().setValue("alert_sound", soundSelector_->value());
     Settings::instance().setValue("alert_poi_file", poiFileSelector_->value());
 
-    hide();
-
     if(!PoiAlerts::instance().loadConfig())
     {
-        QMaemo5InformationBox::information(0, tr("Unable to load poi file: %1.").arg(PoiAlerts::instance().error()),
+        QMaemo5InformationBox::information(this, tr("Unable to load poi file: %1.").arg(PoiAlerts::instance().error()),
                                            QMaemo5InformationBox::NoTimeout);
     }
+    else
+    {
+        hide();
+    }
 }