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

mailcommon

  • sources
  • kde-4.14
  • 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 <KUrlRequester>
25 #include <KLineEdit>
26 #include <KStandardDirs>
27 
28 #include <QHBoxLayout>
29 #include <QPushButton>
30 
31 #include <phonon/mediaobject.h>
32 
33 using namespace MailCommon;
34 
35 SoundTestWidget::SoundTestWidget( QWidget *parent )
36  : QWidget( parent )
37 {
38  QHBoxLayout *layout = new QHBoxLayout( this );
39  layout->setMargin( 0 );
40 
41  m_playButton = new QPushButton( this );
42  m_playButton->setIcon( KIcon( QLatin1String("arrow-right") ) );
43  m_playButton->setIconSize( QSize( KIconLoader::SizeSmall, KIconLoader::SizeSmall ) );
44  m_playButton->setToolTip(i18n("Play"));
45  layout->addWidget( m_playButton );
46 
47  m_urlRequester = new KUrlRequester( this );
48  layout->addWidget( m_urlRequester );
49 
50  connect( m_playButton, SIGNAL(clicked()),
51  SLOT(playSound()) );
52  connect( m_urlRequester, SIGNAL(openFileDialog(KUrlRequester*)),
53  SLOT(openSoundDialog(KUrlRequester*)) );
54  connect( m_urlRequester->lineEdit(), SIGNAL(textChanged(QString)),
55  SLOT(slotUrlChanged(QString)) );
56 
57  slotUrlChanged( m_urlRequester->lineEdit()->text() );
58 }
59 
60 SoundTestWidget::~SoundTestWidget()
61 {
62 }
63 
64 void SoundTestWidget::slotUrlChanged( const QString &url )
65 {
66  m_playButton->setEnabled( !url.isEmpty() );
67  emit textChanged( url );
68 }
69 
70 void SoundTestWidget::openSoundDialog( KUrlRequester * )
71 {
72  static bool init = true;
73  if ( !init ) {
74  return;
75  }
76 
77  init = false;
78 
79  KFileDialog *fileDialog = m_urlRequester->fileDialog();
80  fileDialog->setCaption( i18n( "Select Sound File" ) );
81 
82  QStringList filters;
83  filters << QLatin1String("audio/x-wav")
84  << QLatin1String("audio/mpeg")
85  << QLatin1String("application/ogg")
86  << QLatin1String("audio/x-adpcm");
87 
88  fileDialog->setMimeFilter( filters );
89 
90  const QStringList soundDirs = KGlobal::dirs()->resourceDirs( "sound" );
91 
92  if ( !soundDirs.isEmpty() ) {
93  KUrl soundURL;
94  QDir dir;
95  dir.setFilter( QDir::Files | QDir::Readable );
96 
97  foreach ( const QString &soundDir, soundDirs ) {
98  dir = soundDir;
99  if ( dir.isReadable() && dir.count() > 2 ) {
100  soundURL.setPath( soundDir );
101  fileDialog->setUrl( soundURL );
102  break;
103  }
104  }
105  }
106 }
107 
108 void SoundTestWidget::playSound()
109 {
110  const QString parameter = m_urlRequester->lineEdit()->text();
111  if ( parameter.isEmpty() ) {
112  return ;
113  }
114 
115  const QString file = QLatin1String( "file:" );
116  const QString play = ( parameter.startsWith( file ) ?
117  parameter.mid( file.length() ) :
118  parameter );
119 
120  Phonon::MediaObject *player = Phonon::createPlayer( Phonon::NotificationCategory, QUrl::fromLocalFile(play) );
121  player->play();
122  connect( player, SIGNAL(finished()), player, SLOT(deleteLater()) );
123 }
124 
125 QString SoundTestWidget::url() const
126 {
127  return m_urlRequester->lineEdit()->text();
128 }
129 
130 void SoundTestWidget::setUrl( const QString &url )
131 {
132  m_urlRequester->lineEdit()->setText(url);
133 }
134 
135 void SoundTestWidget::clear()
136 {
137  m_urlRequester->lineEdit()->clear();
138 }
139 
QWidget::layout
QLayout * layout() const
MailCommon::SoundTestWidget::url
QString url() const
Returns the url of the sound file to play.
Definition: soundtestwidget.cpp:125
QWidget
MailCommon::SoundTestWidget::~SoundTestWidget
~SoundTestWidget()
Destroys the sound test widget.
Definition: soundtestwidget.cpp:60
soundtestwidget.h
Phonon::MediaObject::play
void play()
MailCommon::SoundTestWidget::SoundTestWidget
SoundTestWidget(QWidget *parent=0)
Creates a new sound test widget.
Definition: soundtestwidget.cpp:35
QHBoxLayout
QDir::isReadable
bool isReadable() const
Phonon::createPlayer
MediaObject * createPlayer(Phonon::Category category, const MediaSource &source)
QAbstractButton::setIcon
void setIcon(const QIcon &icon)
QDir::count
uint count() const
QDir::setFilter
void setFilter(QFlags< QDir::Filter > filters)
QWidget::setEnabled
void setEnabled(bool)
QBoxLayout::addWidget
void addWidget(QWidget *widget, int stretch, QFlags< Qt::AlignmentFlag > alignment)
Phonon::MediaObject
QAbstractButton::setIconSize
void setIconSize(const QSize &size)
QList::isEmpty
bool isEmpty() const
QString::isEmpty
bool isEmpty() const
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const
QObject::deleteLater
void deleteLater()
QString
QLayout::setMargin
void setMargin(int margin)
QStringList
MailCommon::SoundTestWidget::setUrl
void setUrl(const QString &url)
Sets the url of the sound file to play.
Definition: soundtestwidget.cpp:130
QSize
QDir
QString::mid
QString mid(int position, int n) const
MailCommon::SoundTestWidget::textChanged
void textChanged(const QString &)
This signal is emitted when the user enters a new URL.
QLatin1String
QString::length
int length() const
QPushButton
QWidget::setToolTip
void setToolTip(const QString &)
QObject::connect
bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *method, Qt::ConnectionType type)
MailCommon::SoundTestWidget::clear
void clear()
Clears the url of the sound file to play.
Definition: soundtestwidget.cpp:135
QUrl::fromLocalFile
QUrl fromLocalFile(const QString &localFile)
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:31:41 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
  • pimprint

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