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 <QtGui/QHBoxLayout>
21 #include "soundselector.h"
22 #include "fileselector.h"
23 #include "mediaplayer.h"
25 SoundSelector::SoundSelector(QWidget* parent): QWidget(parent)
27 selector_ = new FileSelector(tr("Sound"));
28 QPushButton* playButton = new QPushButton(tr("Play"));
29 connect(playButton, SIGNAL(clicked(bool)), this, SLOT(playSound()));
30 QHBoxLayout* layout = new QHBoxLayout;
31 layout->addWidget(selector_, Qt::AlignLeft);
32 layout->addWidget(playButton);
36 void SoundSelector::playSound()
38 QString sound = selector_->value().toString();
45 QString soundDir = MediaPlayer::getSoundDir();
46 QString localDir = MediaPlayer::getLocalSoundDir();
48 if(QFile::exists(soundDir + sound))
50 MediaPlayer::play(soundDir + sound);
52 else if(QFile::exists(localDir + sound))
54 MediaPlayer::play(localDir + sound);
58 void SoundSelector::setVisible(bool visible)
62 QString currentValue = selector_->value().toString();
64 QString pattern = MediaPlayer::getFormatPattern();
65 selector_->loadFiles(MediaPlayer::getLocalSoundDir(), pattern);
66 selector_->loadFiles(MediaPlayer::getSoundDir(), pattern);
67 setValue(currentValue);
70 QWidget::setVisible(visible);
73 void SoundSelector::setValue(QString const& value)
75 selector_->selectByValue(value);
78 QString SoundSelector::value() const
80 return selector_->value().toString();