Added theme scheduler, poi support and speed alarm features.
[jspeed] / src / soundselector.cpp
diff --git a/src/soundselector.cpp b/src/soundselector.cpp
new file mode 100644 (file)
index 0000000..1d80dbf
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * This file is part of jSpeed.
+ *
+ * jSpeed is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * jSpeed is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with jSpeed.  If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <QtCore/QFile>
+#include <QtGui/QHBoxLayout>
+#include "soundselector.h"
+#include "fileselector.h"
+#include "mediaplayer.h"
+
+SoundSelector::SoundSelector(QWidget* parent): QWidget(parent)
+{
+    selector_ = new FileSelector(tr("Sound"));
+    QPushButton* playButton = new QPushButton(tr("Play"));
+    connect(playButton, SIGNAL(clicked(bool)), this, SLOT(playSound()));
+    QHBoxLayout* layout = new QHBoxLayout;
+    layout->addWidget(selector_, Qt::AlignLeft);
+    layout->addWidget(playButton);
+    setLayout(layout);
+}
+
+void SoundSelector::playSound()
+{
+    QString sound = selector_->value().toString();
+
+    if(sound.isEmpty())
+    {
+        return;
+    }
+
+    QString soundDir = MediaPlayer::getSoundDir();
+    QString localDir = MediaPlayer::getLocalSoundDir();
+
+    if(QFile::exists(soundDir + sound))
+    {
+        MediaPlayer::play(soundDir + sound);
+    }
+    else if(QFile::exists(localDir + sound))
+    {
+        MediaPlayer::play(localDir + sound);
+    }
+}
+
+void SoundSelector::setVisible(bool visible)
+{
+    if(visible)
+    {
+        QString currentValue = selector_->value().toString();
+        selector_->clear();
+        QString pattern = MediaPlayer::getFormatPattern();
+        selector_->loadFiles(MediaPlayer::getLocalSoundDir(), pattern);
+        selector_->loadFiles(MediaPlayer::getSoundDir(), pattern);
+        setValue(currentValue);
+    }
+
+    QWidget::setVisible(visible);
+}
+
+void SoundSelector::setValue(QString const& value)
+{
+    selector_->selectByValue(value);
+}
+
+QString SoundSelector::value() const
+{
+    return selector_->value().toString();
+}