KABC::Sound Class Reference

Class that holds a Sound clip for a contact. More...

#include <sound.h>

List of all members.


Public Member Functions

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

Friends

KABC_EXPORT QDataStreamoperator<< (QDataStream &, const Sound &)
KABC_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()->writeBlock( sound.data() );
      tmp.close();
      KAudioPlayer::play( tmp.name() );
    } else if(!sound.url().isEmpty()) {
      QString tmpFile;
      if(!KIO::NetAccess::download(KURL(themeURL.url()), tmpFile, NULL))
      {
        KMessageBox::error(0L,
                           KIO::NetAccess::lastErrorString(),
                           i18n("Failed to download sound file"),
                           KMessageBox::Notify
                          );
        return;
      }
      KAudioPlayer::play( tmpFile ); 
    }

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

Definition at line 59 of file sound.h.


Constructor & Destructor Documentation

Sound::Sound (  ) 

Consturctor.

Creates an empty object.

Definition at line 27 of file sound.cpp.

Sound::Sound ( const QString url  ) 

Consturctor.

Parameters:
url A URL that describes the position of the sound file.

Definition at line 32 of file sound.cpp.

Sound::Sound ( const QByteArray data  ) 

Consturctor.

Parameters:
data The raw data of the sound.

Definition at line 37 of file sound.cpp.

Sound::~Sound (  ) 

Destructor.

Definition at line 42 of file sound.cpp.


Member Function Documentation

QString Sound::asString (  )  const

Returns string representation of the sound.

Definition at line 99 of file sound.cpp.

QByteArray Sound::data (  )  const

Returns the raw data of this sound.

Definition at line 94 of file sound.cpp.

bool Sound::isEmpty (  )  const

Test if this sound file has been set.

Just does: !isIntern() && url.isEmpty()

Since:
3.4

Definition at line 83 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 78 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:
data The raw data of the sound.

Definition at line 72 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:
url The location URL of the sound file.

Definition at line 66 of file sound.cpp.

QString Sound::url (  )  const

Returns the location URL of this sound.

Definition at line 89 of file sound.cpp.


The documentation for this class was generated from the following files:
KDE Home | KDE Accessibility Home | Description of Access Keys