Web page updated.
[jspeed] / src / soundselector.cpp
1 /*
2  * This file is part of jSpeed.
3  *
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.
8  *
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.
13  *
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/>.
16  *
17  */
18
19 #include <QtCore/QFile>
20 #include <QtGui/QHBoxLayout>
21 #include "soundselector.h"
22 #include "fileselector.h"
23 #include "mediaplayer.h"
24
25 SoundSelector::SoundSelector(QWidget* parent): QHBoxLayout(parent)
26 {
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);
32 }
33
34 void SoundSelector::playSound()
35 {
36     QString sound = selector_->value().toString();
37
38     if(sound.isEmpty())
39     {
40         return;
41     }
42
43     QString soundDir = MediaPlayer::getSoundDir();
44     QString localDir = MediaPlayer::getLocalSoundDir();
45
46     if(QFile::exists(soundDir + sound))
47     {
48         MediaPlayer::play(soundDir + sound);
49     }
50     else if(QFile::exists(localDir + sound))
51     {
52         MediaPlayer::play(localDir + sound);
53     }
54 }
55
56 void SoundSelector::load()
57 {
58     QString currentValue = selector_->value().toString();
59     selector_->clear();
60     QStringList patterns = MediaPlayer::getFormatPatterns();
61     selector_->loadFiles(MediaPlayer::getLocalSoundDir(), patterns, true);
62     selector_->loadFiles(MediaPlayer::getSoundDir(), patterns, true);
63     setValue(currentValue);
64 }
65
66 void SoundSelector::setValue(QString const& value)
67 {
68     selector_->selectByValue(value);
69 }
70
71 QString SoundSelector::value() const
72 {
73     return selector_->value().toString();
74 }