2 * This file is part of jSpeed.
4 * jSpeed is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * jSpeed is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with jSpeed. If not, see <http://www.gnu.org/licenses/>.
19 #include <QtCore/QFile>
20 #include <QMediaPlayer>
21 #include "speedalarm.h"
24 #include "poialerts.h"
25 #include "mediaplayer.h"
27 SpeedAlarm::SpeedAlarm(): QObject(0), loaded_(false), enabled_(false), isOver_(false)
31 SpeedAlarm& SpeedAlarm::instance()
33 static SpeedAlarm instance;
37 void SpeedAlarm::start()
46 connect(&(Odometer::instance()), SIGNAL(dataUpdated()), this, SLOT(onDataUpdated()));
51 void SpeedAlarm::loadConfig()
55 bool enabled = Settings::instance().value("alarm_enabled", false).toBool();
61 QString sound = Settings::instance().value("alarm_sound", "").toString();
69 QString soundDir = MediaPlayer::getSoundDir();
71 if(QFile::exists(soundDir + sound))
73 soundFile_ = soundDir + sound;
75 else if(QFile::exists(MediaPlayer::getLocalSoundDir() + sound))
77 soundFile_ = MediaPlayer::getLocalSoundDir() + sound;
85 threshold_ = Settings::instance().value("alarm_threshold", 0).toInt();
96 void SpeedAlarm::end()
100 disconnect(&(Odometer::instance()), SIGNAL(dataUpdated()), this, SLOT(onDataUpdated()));
104 void SpeedAlarm::onDataUpdated()
106 if(Odometer::instance().getLatestFix().kmSpeed > threshold_)
110 MediaPlayer::play(soundFile_);