21 #include <KFileDialog>
22 #include <KIconLoader>
23 #include <KLocalizedString>
24 #include <KStandardDirs>
25 #include <KUrlRequester>
27 #include <QHBoxLayout>
28 #include <QPushButton>
30 #include <phonon/mediaobject.h>
32 using namespace MailCommon;
37 QHBoxLayout *layout =
new QHBoxLayout(
this );
38 layout->setMargin( 0 );
40 m_playButton =
new QPushButton(
this );
41 m_playButton->setIcon( KIcon( QLatin1String(
"arrow-right") ) );
42 m_playButton->setIconSize( QSize( KIconLoader::SizeSmall, KIconLoader::SizeSmall ) );
43 m_playButton->setToolTip(i18n(
"Play"));
44 layout->addWidget( m_playButton );
46 m_urlRequester =
new KUrlRequester(
this );
47 layout->addWidget( m_urlRequester );
49 connect( m_playButton, SIGNAL(clicked()),
51 connect( m_urlRequester, SIGNAL(openFileDialog(KUrlRequester*)),
52 SLOT(openSoundDialog(KUrlRequester*)) );
53 connect( m_urlRequester->lineEdit(), SIGNAL(
textChanged(QString)),
54 SLOT(slotUrlChanged(QString)) );
56 slotUrlChanged( m_urlRequester->lineEdit()->text() );
63 void SoundTestWidget::slotUrlChanged(
const QString &url )
65 m_playButton->setEnabled( !url.isEmpty() );
69 void SoundTestWidget::openSoundDialog( KUrlRequester * )
71 static bool init =
true;
78 KFileDialog *fileDialog = m_urlRequester->fileDialog();
79 fileDialog->setCaption( i18n(
"Select Sound File" ) );
82 filters << QLatin1String(
"audio/x-wav")
83 << QLatin1String(
"audio/mpeg")
84 << QLatin1String(
"application/ogg")
85 << QLatin1String(
"audio/x-adpcm");
87 fileDialog->setMimeFilter( filters );
89 const QStringList soundDirs = KGlobal::dirs()->resourceDirs(
"sound" );
91 if ( !soundDirs.isEmpty() ) {
94 dir.setFilter( QDir::Files | QDir::Readable );
96 foreach (
const QString &soundDir, soundDirs ) {
98 if ( dir.isReadable() && dir.count() > 2 ) {
99 soundURL.setPath( soundDir );
100 fileDialog->setUrl( soundURL );
107 void SoundTestWidget::playSound()
109 const QString parameter = m_urlRequester->lineEdit()->text();
110 if ( parameter.isEmpty() ) {
114 const QString file = QLatin1String(
"file:" );
115 const QString play = ( parameter.startsWith( file ) ?
116 parameter.mid( file.length() ) :
119 Phonon::MediaObject *player = Phonon::createPlayer( Phonon::NotificationCategory, QUrl::fromLocalFile(play) );
121 connect( player, SIGNAL(finished()), player, SLOT(deleteLater()) );
126 return m_urlRequester->lineEdit()->text();
131 m_urlRequester->lineEdit()->setText(url);
136 m_urlRequester->lineEdit()->clear();
139 #include "soundtestwidget.moc"