KContacts

sound.cpp
1 /*
2  This file is part of the KContacts framework.
3  SPDX-FileCopyrightText: 2002 Tobias Koenig <[email protected]>
4 
5  SPDX-License-Identifier: LGPL-2.0-or-later
6 */
7 
8 #include "sound.h"
9 
10 #include <QDataStream>
11 #include <QSharedData>
12 
13 using namespace KContacts;
14 
15 class Q_DECL_HIDDEN Sound::Private : public QSharedData
16 {
17 public:
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 
55 Sound::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 
73 bool 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 
92 bool Sound::operator!=(const Sound &other) const
93 {
94  return !(other == *this);
95 }
96 
98 {
99  d->mIntern = false;
100  d->mUrl = url;
101 }
102 
104 {
105  d->mIntern = true;
106  d->mData = data;
107 }
108 
109 bool Sound::isIntern() const
110 {
111  return d->mIntern;
112 }
113 
114 bool Sound::isEmpty() const
115 {
116  return
117  (d->mIntern && d->mData.isEmpty()) || (!d->mIntern && d->mUrl.isEmpty());
118 }
119 
121 {
122  return d->mUrl;
123 }
124 
126 {
127  return d->mData;
128 }
129 
131 {
132  QString str = QLatin1String("Sound {\n");
133  str += QStringLiteral(" IsIntern: %1\n").
134  arg(d->mIntern ? QStringLiteral("true") : QStringLiteral("false"));
135  if (d->mIntern) {
136  str += QStringLiteral(" Data: %1\n").
137  arg(QString::fromLatin1(d->mData.toBase64()));
138  } else {
139  str += QStringLiteral(" Url: %1\n").arg(d->mUrl);
140  }
141  str += QLatin1String("}\n");
142 
143  return str;
144 }
145 
146 QDataStream &KContacts::operator<<(QDataStream &s, const Sound &sound)
147 {
148  return s << sound.d->mIntern << sound.d->mUrl << sound.d->mData;
149 }
150 
151 QDataStream &KContacts::operator>>(QDataStream &s, Sound &sound)
152 {
153  s >> sound.d->mIntern >> sound.d->mUrl >> sound.d->mData;
154 
155  return s;
156 }
bool operator==(const Sound &other) const
Equality operator.
Definition: sound.cpp:73
~Sound()
Destroys the sound object.
Definition: sound.cpp:60
QByteArray data() const
Returns the raw data of this sound.
Definition: sound.cpp:125
bool isEmpty() const
Returns true, if the sound object is empty.
Definition: sound.cpp:114
Sound & operator=(const Sound &other)
Assignment operator.
Definition: sound.cpp:64
bool operator!=(const Sound &other) const
Not-Equal operator.
Definition: sound.cpp:92
Sound()
Creates an empty sound object.
Definition: sound.cpp:37
void setData(const QByteArray &data)
Sets the raw data of the sound.
Definition: sound.cpp:103
Class that holds a Sound clip for a contact.
Definition: sound.h:44
QString url() const
Returns the location URL of this sound.
Definition: sound.cpp:120
QString arg(qlonglong a, int fieldWidth, int base, QChar fillChar) const const
QString fromLatin1(const char *str, int size)
bool isIntern() const
Returns whether the sound is described by a URL (extern) or by the raw data (intern).
Definition: sound.cpp:109
QString toString() const
Returns string representation of the sound.
Definition: sound.cpp:130
void setUrl(const QString &url)
Sets a URL for the location of the sound file.
Definition: sound.cpp:97
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Jul 4 2020 22:55:11 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.