KContacts

sound.cpp
1/*
2 This file is part of the KContacts framework.
3 SPDX-FileCopyrightText: 2002 Tobias Koenig <tokoe@kde.org>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "sound.h"
9
10#include <QDataStream>
11#include <QSharedData>
12
13using namespace KContacts;
14
15class Q_DECL_HIDDEN Sound::Private : public QSharedData
16{
17public:
18 Private()
19 : mIntern(false)
20 {
21 }
22
23 Private(const Private &other)
24 : QSharedData(other)
25 {
26 mUrl = other.mUrl;
27 mData = other.mData;
28 mIntern = other.mIntern;
29 }
30
31 QString mUrl;
32 QByteArray mData;
33
34 bool mIntern;
35};
36
38 : d(new Private)
39{
40}
41
43 : d(new Private)
44{
45 d->mUrl = url;
46}
47
49 : d(new Private)
50{
51 d->mIntern = true;
52 d->mData = data;
53}
54
55Sound::Sound(const Sound &other)
56 : d(other.d)
57{
58}
59
61{
62}
63
65{
66 if (this != &other) {
67 d = other.d;
68 }
69
70 return *this;
71}
72
73bool Sound::operator==(const Sound &other) const
74{
75 if (d->mIntern != other.d->mIntern) {
76 return false;
77 }
78
79 if (d->mIntern) {
80 if (d->mData != other.d->mData) {
81 return false;
82 }
83 } else {
84 if (d->mUrl != other.d->mUrl) {
85 return false;
86 }
87 }
88
89 return true;
90}
91
92bool Sound::operator!=(const Sound &other) const
93{
94 return !(other == *this);
95}
96
97void Sound::setUrl(const QString &url)
98{
99 d->mIntern = false;
100 d->mUrl = url;
101}
102
103void Sound::setData(const QByteArray &data)
104{
105 d->mIntern = true;
106 d->mData = data;
107}
108
109bool Sound::isIntern() const
110{
111 return d->mIntern;
112}
113
114bool Sound::isEmpty() const
115{
116 return (d->mIntern && d->mData.isEmpty()) || (!d->mIntern && d->mUrl.isEmpty());
117}
118
120{
121 return d->mUrl;
122}
123
125{
126 return d->mData;
127}
128
130{
131 QString str = QLatin1String("Sound {\n");
132 str += QStringLiteral(" IsIntern: %1\n").arg(d->mIntern ? QStringLiteral("true") : QStringLiteral("false"));
133 if (d->mIntern) {
134 str += QStringLiteral(" Data: %1\n").arg(QString::fromLatin1(d->mData.toBase64()));
135 } else {
136 str += QStringLiteral(" Url: %1\n").arg(d->mUrl);
137 }
138 str += QLatin1String("}\n");
139
140 return str;
141}
142
143QDataStream &KContacts::operator<<(QDataStream &s, const Sound &sound)
144{
145 return s << sound.d->mIntern << sound.d->mUrl << sound.d->mData;
146}
147
148QDataStream &KContacts::operator>>(QDataStream &s, Sound &sound)
149{
150 s >> sound.d->mIntern >> sound.d->mUrl >> sound.d->mData;
151
152 return s;
153}
Class that holds a Sound clip for a contact.
Definition sound.h:46
~Sound()
Destroys the sound object.
Definition sound.cpp:60
QByteArray data() const
Returns the raw data of this sound.
Definition sound.cpp:124
void setData(const QByteArray &data)
Sets the raw data of the sound.
Definition sound.cpp:103
bool operator!=(const Sound &other) const
Not-Equal operator.
Definition sound.cpp:92
Sound()
Creates an empty sound object.
Definition sound.cpp:37
QString url() const
Returns the location URL of this sound.
Definition sound.cpp:119
QString toString() const
Returns string representation of the sound.
Definition sound.cpp:129
void setUrl(const QString &url)
Sets a URL for the location of the sound file.
Definition sound.cpp:97
bool isIntern() const
Returns whether the sound is described by a URL (extern) or by the raw data (intern).
Definition sound.cpp:109
Sound & operator=(const Sound &other)
Assignment operator.
Definition sound.cpp:64
bool operator==(const Sound &other) const
Equality operator.
Definition sound.cpp:73
bool isEmpty() const
Returns true, if the sound object is empty.
Definition sound.cpp:114
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromLatin1(const char *str, int size)
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Sun Feb 25 2024 18:39:36 by doxygen 1.10.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.