parley
audiowidget.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016 #include "audiowidget.h"
00017
00018 #include <Phonon/MediaObject>
00019
00020 #include <keduvocexpression.h>
00021
00022 #include <KIcon>
00023 #include <kdebug.h>
00024
00025
00026 AudioWidget::AudioWidget(QWidget *parent) : QWidget(parent)
00027 {
00028 setupUi(this);
00029 m_currentTranslation = -1;
00030 m_player = 0;
00031
00032 connect(audioUrlRequester, SIGNAL(textChanged(const QString&)), SLOT(slotAudioFileChanged(const QString&)));
00033 connect(playButton, SIGNAL(clicked()), SLOT(playAudio()));
00034
00035
00036 playButton->setEnabled(false);
00037 playButton->setIcon(KIcon("media-playback-start"));
00038 recordButton->setVisible(false);
00039
00040
00041 audioUrlRequester->setEnabled(false);
00042 }
00043
00044 void AudioWidget::setTranslation(KEduVocExpression* entry, int translation)
00045 {
00046 m_currentTranslation = translation;
00047 m_entry = entry;
00048
00049 if (m_entry) {
00050 recordButton->setEnabled(true);
00051 audioUrlRequester->setEnabled(true);
00052 audioUrlRequester->setUrl(m_entry->translation(m_currentTranslation)->soundUrl().toLocalFile());
00053 } else {
00054 recordButton->setEnabled(false);
00055 audioUrlRequester->setEnabled(false);
00056 if (m_player) {
00057 if (m_player->state() == Phonon::PlayingState) {
00058 playButton->setEnabled(true);
00059 } else {
00060 playButton->setEnabled(false);
00061 }
00062 }
00063 audioUrlRequester->clear();
00064 }
00065 }
00066
00067 void AudioWidget::slotAudioFileChanged(const QString & url)
00068 {
00069 kDebug() << "Setting sound " << url;
00070 m_entry->translation(m_currentTranslation)->setSoundUrl( KUrl(url) );
00071 playButton->setEnabled(!url.isEmpty());
00072 }
00073
00074 void AudioWidget::playAudio()
00075 {
00076 KUrl soundFile = m_entry->translation(m_currentTranslation)->soundUrl();
00077 kDebug() << "sound file: " << soundFile.url();
00078
00079 if (!m_player)
00080 {
00081 m_player = Phonon::createPlayer(Phonon::NotificationCategory, soundFile);
00082 m_player->setParent(this);
00083 connect(m_player, SIGNAL(finished()), SLOT(slotPlaybackFinished()));
00084 } else {
00085 if (m_player->state() == Phonon::PlayingState) {
00086 m_player->stop();
00087 slotPlaybackFinished();
00088 return;
00089 }
00090 m_player->setCurrentSource(soundFile);
00091 }
00092 playButton->setIcon(KIcon("media-playback-stop"));
00093 m_player->play();
00094 }
00095
00096
00097
00098
00100
00101
00102
00103 void AudioWidget::slotPlaybackFinished()
00104 {
00105 playButton->setIcon(KIcon("media-playback-start"));
00106 playButton->setEnabled(!audioUrlRequester->url().isEmpty());
00107 }
00108
00109 #include "audiowidget.moc"