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 <QtCore/QTimer>
21 #include "speedalarm.h"
24 #include "poialerts.h"
25 #include "mediaplayer.h"
28 SpeedAlarm::SpeedAlarm(): QObject(0), loaded_(false),
29 enabled_(false), isOver_(false), timer_(0)
33 SpeedAlarm::~SpeedAlarm()
38 SpeedAlarm& SpeedAlarm::instance()
40 static SpeedAlarm instance;
44 void SpeedAlarm::start()
53 connect(&(Odometer::instance()), SIGNAL(dataUpdated()), this, SLOT(onDataUpdated()));
58 void SpeedAlarm::loadConfig()
62 bool enabled = Settings::instance().value("alarm_enabled", false).toBool();
68 QString sound = Settings::instance().value("alarm_sound", "").toString();
76 QString soundDir = MediaPlayer::getSoundDir();
78 if(QFile::exists(soundDir + sound))
80 soundFile_ = soundDir + sound;
82 else if(QFile::exists(MediaPlayer::getLocalSoundDir() + sound))
84 soundFile_ = MediaPlayer::getLocalSoundDir() + sound;
92 threshold_ = Settings::instance().value("alarm_threshold", 0).toDouble();
103 void SpeedAlarm::end()
107 disconnect(&(Odometer::instance()), SIGNAL(dataUpdated()), this, SLOT(onDataUpdated()));
111 void SpeedAlarm::onDataUpdated()
113 if(Odometer::instance().getLatestFix().kmSpeed > threshold_)
117 MediaPlayer::play(soundFile_);
119 emit speedExceedChanged(true);
127 emit speedExceedChanged(false);
134 void SpeedAlarm::startAlarmTimer()
144 timer_->setInterval(ALARM_INTERVAL * 1000);
145 connect(timer_, SIGNAL(timeout()), this, SLOT(playAlarmSound()));
149 void SpeedAlarm::playAlarmSound()
153 MediaPlayer::play(soundFile_);