KContacts::Sound Class

class KContacts::Sound

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

Header: #include <KContacts/Sound>
CMake: find_package(KF6 REQUIRED COMPONENTS Contacts)
target_link_libraries(mytarget PRIVATE KF6::Contacts)

Public Types

Public Functions

Sound()
Sound(const QByteArray &data)
Sound(const QString &url)
QByteArray data() const
bool isEmpty() const
bool isIntern() const
void setData(const QByteArray &data)
void setUrl(const QString &url)
QString toString() const
QString url() const
bool operator!=(const KContacts::Sound &other) const
KContacts::Sound &operator=(const KContacts::Sound &other)
bool operator==(const KContacts::Sound &other) const
QDataStream &operator<<(QDataStream &stream, const KContacts::Sound &sound)
QDataStream &operator>>(QDataStream &stream, KContacts::Sound &sound)

Detailed Description

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 ) ) {
    KMessageBox::error( 0,
                        KIO::NetAccess::lastErrorString(),
                        i18n( "Failed to download sound file" ),
                        KMessageBox::Notify
                      );
    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.

Member Type Documentation

Sound::List

Member Function Documentation

Sound::Sound()

Creates an empty sound object.

Sound::Sound(const QByteArray &data)

Creates a sound object for the given data.

data The raw data of the sound.

Sound::Sound(const QString &url)

Creates a sound object for the given url.

url A url that describes the position of the sound file.

QByteArray Sound::data() const

Returns the raw data of this sound.

See also setData().

bool Sound::isEmpty() const

Returns true, if the sound object is empty.

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.

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().

data The raw data of the sound.

See also data().

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().

url The location URL of the sound file.

See also url().

QString Sound::toString() const

Returns string representation of the sound.

QString Sound::url() const

Returns the location URL of this sound.

See also setUrl().

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

Not-Equal operator.

other The object to compare with

Returns true if the two objects are not equal, otherwise false

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

Assignment operator.

other The sound object to assign to this

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

Equality operator.

other The object to compare with

Returns true if the two objects are equal, otherwise false

Related Non-Members

QDataStream &operator<<(QDataStream &stream, const KContacts::Sound &sound)

Serializes the sound object into the stream.

QDataStream &operator>>(QDataStream &stream, KContacts::Sound &sound)

Initializes the sound object from the stream.