• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdepim API Reference
  • KDE Home
  • Contact Us
 

mailcommon

  • sources
  • kde-4.12
  • kdepim
  • mailcommon
  • filter
soundtestwidget.cpp
Go to the documentation of this file.
1 /*
2  Copyright (c) 2001 Marc Mutz <mutz@kde.org>
3 
4  This program 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 2 of the License, or
7  (at your option) any later version.
8 
9  This program 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 along
15  with this program; if not, write to the Free Software Foundation, Inc.,
16  51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 */
18 
19 #include "soundtestwidget.h"
20 
21 #include <KFileDialog>
22 #include <KIconLoader>
23 #include <KLocalizedString>
24 #include <KStandardDirs>
25 #include <KUrlRequester>
26 
27 #include <QHBoxLayout>
28 #include <QPushButton>
29 
30 #include <phonon/mediaobject.h>
31 
32 using namespace MailCommon;
33 
34 SoundTestWidget::SoundTestWidget( QWidget *parent )
35  : QWidget( parent )
36 {
37  QHBoxLayout *layout = new QHBoxLayout( this );
38  layout->setMargin( 0 );
39 
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 );
45 
46  m_urlRequester = new KUrlRequester( this );
47  layout->addWidget( m_urlRequester );
48 
49  connect( m_playButton, SIGNAL(clicked()),
50  SLOT(playSound()) );
51  connect( m_urlRequester, SIGNAL(openFileDialog(KUrlRequester*)),
52  SLOT(openSoundDialog(KUrlRequester*)) );
53  connect( m_urlRequester->lineEdit(), SIGNAL(textChanged(QString)),
54  SLOT(slotUrlChanged(QString)) );
55 
56  slotUrlChanged( m_urlRequester->lineEdit()->text() );
57 }
58 
59 SoundTestWidget::~SoundTestWidget()
60 {
61 }
62 
63 void SoundTestWidget::slotUrlChanged( const QString &url )
64 {
65  m_playButton->setEnabled( !url.isEmpty() );
66  emit textChanged( url );
67 }
68 
69 void SoundTestWidget::openSoundDialog( KUrlRequester * )
70 {
71  static bool init = true;
72  if ( !init ) {
73  return;
74  }
75 
76  init = false;
77 
78  KFileDialog *fileDialog = m_urlRequester->fileDialog();
79  fileDialog->setCaption( i18n( "Select Sound File" ) );
80 
81  QStringList filters;
82  filters << QLatin1String("audio/x-wav")
83  << QLatin1String("audio/mpeg")
84  << QLatin1String("application/ogg")
85  << QLatin1String("audio/x-adpcm");
86 
87  fileDialog->setMimeFilter( filters );
88 
89  const QStringList soundDirs = KGlobal::dirs()->resourceDirs( "sound" );
90 
91  if ( !soundDirs.isEmpty() ) {
92  KUrl soundURL;
93  QDir dir;
94  dir.setFilter( QDir::Files | QDir::Readable );
95 
96  foreach ( const QString &soundDir, soundDirs ) {
97  dir = soundDir;
98  if ( dir.isReadable() && dir.count() > 2 ) {
99  soundURL.setPath( soundDir );
100  fileDialog->setUrl( soundURL );
101  break;
102  }
103  }
104  }
105 }
106 
107 void SoundTestWidget::playSound()
108 {
109  const QString parameter = m_urlRequester->lineEdit()->text();
110  if ( parameter.isEmpty() ) {
111  return ;
112  }
113 
114  const QString file = QLatin1String( "file:" );
115  const QString play = ( parameter.startsWith( file ) ?
116  parameter.mid( file.length() ) :
117  parameter );
118 
119  Phonon::MediaObject *player = Phonon::createPlayer( Phonon::NotificationCategory, QUrl::fromLocalFile(play) );
120  player->play();
121  connect( player, SIGNAL(finished()), player, SLOT(deleteLater()) );
122 }
123 
124 QString SoundTestWidget::url() const
125 {
126  return m_urlRequester->lineEdit()->text();
127 }
128 
129 void SoundTestWidget::setUrl( const QString &url )
130 {
131  m_urlRequester->lineEdit()->setText(url);
132 }
133 
134 void SoundTestWidget::clear()
135 {
136  m_urlRequester->lineEdit()->clear();
137 }
138 
139 #include "soundtestwidget.moc"
MailCommon::SoundTestWidget::url
QString url() const
Returns the url of the sound file to play.
Definition: soundtestwidget.cpp:124
MailCommon::SoundTestWidget::~SoundTestWidget
~SoundTestWidget()
Destroys the sound test widget.
Definition: soundtestwidget.cpp:59
soundtestwidget.h
QWidget
MailCommon::SoundTestWidget::SoundTestWidget
SoundTestWidget(QWidget *parent=0)
Creates a new sound test widget.
Definition: soundtestwidget.cpp:34
MailCommon::SoundTestWidget::setUrl
void setUrl(const QString &url)
Sets the url of the sound file to play.
Definition: soundtestwidget.cpp:129
MailCommon::SoundTestWidget::textChanged
void textChanged(const QString &)
This signal is emitted when the user enters a new URL.
MailCommon::SoundTestWidget::clear
void clear()
Clears the url of the sound file to play.
Definition: soundtestwidget.cpp:134
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:55:15 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

mailcommon

Skip menu "mailcommon"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdepim API Reference

Skip menu "kdepim API Reference"
  • akonadi_next
  • akregator
  • blogilo
  • calendarsupport
  • console
  •   kabcclient
  •   konsolekalendar
  • kaddressbook
  • kalarm
  •   lib
  • kdgantt2
  • kjots
  • kleopatra
  • kmail
  • knode
  • knotes
  • kontact
  • korgac
  • korganizer
  • ktimetracker
  • libkdepim
  • libkleo
  • libkpgp
  • mailcommon
  • messagelist
  • messageviewer

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal