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): QHBoxLayout(parent)
27 selector_ = new FileSelector(tr("Sound"));
28 QPushButton* playButton = new QPushButton(tr("Play"));
29 connect(playButton, SIGNAL(clicked(bool)), this, SLOT(playSound()));
30 addWidget(selector_, Qt::AlignLeft);
31 addWidget(playButton);
34 void SoundSelector::playSound()
36 QString sound = selector_->value().toString();
43 QString soundDir = MediaPlayer::getSoundDir();
44 QString localDir = MediaPlayer::getLocalSoundDir();
46 if(QFile::exists(soundDir + sound))
48 MediaPlayer::play(soundDir + sound);
50 else if(QFile::exists(localDir + sound))
52 MediaPlayer::play(localDir + sound);
56 void SoundSelector::load()
58 QString currentValue = selector_->value().toString();
60 QStringList patterns = MediaPlayer::getFormatPatterns();
61 selector_->loadFiles(MediaPlayer::getLocalSoundDir(), patterns, true);
62 selector_->loadFiles(MediaPlayer::getSoundDir(), patterns, true);
63 setValue(currentValue);
66 void SoundSelector::setValue(QString const& value)
68 selector_->selectByValue(value);
71 QString SoundSelector::value() const
73 return selector_->value().toString();