KContacts::Sound

KContacts::Sound Class Reference

#include <sound.h>

Public Types

typedef QVector< SoundList
 

Public Member Functions

 Sound ()
 
 Sound (const QString &url)
 
 Sound (const QByteArray &data)
 
 Sound (const Sound &other)
 
 ~Sound ()
 
QByteArray data () const
 
bool isEmpty () const
 
bool isIntern () const
 
bool operator!= (const Sound &other) const
 
Soundoperator= (const Sound &other)
 
bool operator== (const Sound &other) const
 
void setData (const QByteArray &data)
 
void setUrl (const QString &url)
 
QString toString () const
 
QString url () const
 

Friends

KCONTACTS_EXPORT QDataStreamoperator<< (QDataStream &, const Sound &)
 
KCONTACTS_EXPORT QDataStreamoperator>> (QDataStream &, Sound &)
 

Detailed Description

Class that holds a Sound clip for a contact.

The sound can be played doing something like this:

KTempFile tmp;
if ( sound.isIntern() ) {
tmp.file()->write( sound.data() );
tmp.close();
KAudioPlayer::play( tmp.name() );
} else if( !sound.url().isEmpty() ) {
QString tmpFile;
if ( !KIO::NetAccess::download( QUrl( themeURL.url() ), tmpFile, 0 ) ) {
i18n( "Failed to download sound file" ),
);
return;
}
KAudioPlayer::play( tmpFile );
}

Unfortunately, KAudioPlayer::play is ASync, so to delete the temporary file the best you can really do is set a timer.

Definition at line 44 of file sound.h.

Constructor & Destructor Documentation

Sound::Sound ( )

Creates an empty sound object.

Definition at line 37 of file sound.cpp.

Sound::Sound ( const QString url)

Creates a sound object for the given url.

Parameters
urlA url that describes the position of the sound file.

Definition at line 42 of file sound.cpp.

Sound::Sound ( const QByteArray data)

Creates a sound object for the given data.

Parameters
dataThe raw data of the sound.

Definition at line 48 of file sound.cpp.

Sound::Sound ( const Sound other)

Copy constructor.

Definition at line 55 of file sound.cpp.

Sound::~Sound ( )

Destroys the sound object.

Definition at line 60 of file sound.cpp.

Member Function Documentation

QByteArray Sound::data ( ) const

Returns the raw data of this sound.

Definition at line 125 of file sound.cpp.

bool Sound::isEmpty ( ) const

Returns true, if the sound object is empty.

Definition at line 114 of file sound.cpp.

bool Sound::isIntern ( ) const

Returns whether the sound is described by a URL (extern) or by the raw data (intern).

When this method returns 'true' you can use data() to get the raw data. Otherwise you can request the URL of this sound by url() and load the raw data from that location.

Definition at line 109 of file sound.cpp.

bool Sound::operator!= ( const Sound other) const

Not-Equal operator.

Parameters
otherThe object to compare with
Returns
true if the two objects are not equal, otherwise false

Definition at line 92 of file sound.cpp.

Sound & Sound::operator= ( const Sound other)

Assignment operator.

Parameters
otherThe sound object to assign to this

Definition at line 64 of file sound.cpp.

bool Sound::operator== ( const Sound other) const

Equality operator.

Parameters
otherThe object to compare with
Returns
true if the two objects are equal, otherwise false

Definition at line 73 of file sound.cpp.

void Sound::setData ( const QByteArray data)

Sets the raw data of the sound.

When using this function, isIntern() will return 'true' until you use setUrl().

Parameters
dataThe raw data of the sound.

Definition at line 103 of file sound.cpp.

void Sound::setUrl ( const QString url)

Sets a URL for the location of the sound file.

When using this function, isIntern() will return 'false' until you use setData().

Parameters
urlThe location URL of the sound file.

Definition at line 97 of file sound.cpp.

QString Sound::toString ( ) const

Returns string representation of the sound.

Definition at line 130 of file sound.cpp.

QString Sound::url ( ) const

Returns the location URL of this sound.

Definition at line 120 of file sound.cpp.

Friends And Related Function Documentation

KCONTACTS_EXPORT QDataStream& operator<< ( QDataStream ,
const Sound  
)
friend

Serializes the sound object into the stream.

KCONTACTS_EXPORT QDataStream& operator>> ( QDataStream ,
Sound  
)
friend

Initializes the sound object from the stream.


The documentation for this class was generated from the following files:
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Fri Nov 27 2020 22:56:36 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.