Phonon  4.7.0
 All Classes Namespaces Functions Variables Enumerations Enumerator Properties Pages
objectdescription.h
1 /*
2  Copyright (C) 2006-2007 Matthias Kretz <kretz@kde.org>
3  Copyright (C) 2011 Harald Sitter <sitter@kde.org>
4 
5  This library is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Lesser General Public
7  License as published by the Free Software Foundation; either
8  version 2.1 of the License, or (at your option) version 3, or any
9  later version accepted by the membership of KDE e.V. (or its
10  successor approved by the membership of KDE e.V.), Nokia Corporation
11  (or its successors, if any) and the KDE Free Qt Foundation, which shall
12  act as a proxy defined in Section 6 of version 3 of the license.
13 
14  This library is distributed in the hope that it will be useful,
15  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  Lesser General Public License for more details.
18 
19  You should have received a copy of the GNU Lesser General Public
20  License along with this library. If not, see <http://www.gnu.org/licenses/>.
21 */
22 
23 #ifndef PHONON_OBJECTDESCRIPTION_H
24 #define PHONON_OBJECTDESCRIPTION_H
25 
26 #include "phonon_export.h"
27 
28 #include <QtCore/QExplicitlySharedDataPointer>
29 #include <QtCore/QtDebug>
30 #include <QtCore/QList>
31 #include <QtCore/QSharedData>
32 #include <QtCore/QString>
33 #include <QtCore/QVariant>
34 
35 
36 namespace Phonon
37 {
38  class ObjectDescriptionPrivate;
39 
46  enum ObjectDescriptionType
47  {
58  AudioOutputDeviceType,
59 
63  EffectType,
64  AudioChannelType,
65  SubtitleType,
66 
77  AudioCaptureDeviceType,
78 
82  VideoCaptureDeviceType
83 
84  //VideoOutputDeviceType,
85  //AudioCodecType,
86  //VideoCodecType,
87  //ContainerFormatType,
88  //VisualizationType,
89  };
90 
98 class PHONON_EXPORT ObjectDescriptionData : public QSharedData //krazy:exclude=dpointer (it's protected, which should be fine for this type of class)
99 {
100  public:
105  bool operator==(const ObjectDescriptionData &otherDescription) const;
106 
113  QString name() const;
114 
122  QString description() const;
123 
131  QVariant property(const char *name) const;
132 
138  QList<QByteArray> propertyNames() const;
139 
144  bool isValid() const;
145 
152  int index() const;
153 
154  static ObjectDescriptionData *fromIndex(ObjectDescriptionType type, int index);
155 
157 
158  ObjectDescriptionData(ObjectDescriptionPrivate * = 0);
159  ObjectDescriptionData(int index, const QHash<QByteArray, QVariant> &properties);
160 
161  protected:
162  ObjectDescriptionPrivate *const d;
163 
164  private:
165  ObjectDescriptionData &operator=(const ObjectDescriptionData &rhs);
166 };
167 
168 template<ObjectDescriptionType T> class ObjectDescriptionModel;
169 
181 template<ObjectDescriptionType T>
183 {
184  public:
189  static inline ObjectDescription<T> fromIndex(int index) { //krazy:exclude=inline
190  return ObjectDescription<T>(QExplicitlySharedDataPointer<ObjectDescriptionData>(ObjectDescriptionData::fromIndex(T, index)));
191  }
192 
197  inline bool operator==(const ObjectDescription &otherDescription) const { //krazy:exclude=inline
198  return *d == *otherDescription.d;
199  }
200 
205  inline bool operator!=(const ObjectDescription &otherDescription) const { //krazy:exclude=inline
206  return !operator==(otherDescription);
207  }
208 
215  inline QString name() const { return d->name(); } //krazy:exclude=inline
216 
224  inline QString description() const { return d->description(); } //krazy:exclude=inline
225 
233  inline QVariant property(const char *name) const { return d->property(name); } //krazy:exclude=inline
234 
240  inline QList<QByteArray> propertyNames() const { return d->propertyNames(); } //krazy:exclude=inline
241 
246  inline bool isValid() const { return d->isValid(); } //krazy:exclude=inline
247 
254  inline int index() const { return d->index(); } //krazy:exclude=inline
255 
257  ObjectDescription(int index, const QHash<QByteArray, QVariant> &properties) : d(new ObjectDescriptionData(index, properties)) {}
258 
259  protected:
260  friend class ObjectDescriptionModel<T>;
261  ObjectDescription(const QExplicitlySharedDataPointer<ObjectDescriptionData> &dd) : d(dd) {}
262  QExplicitlySharedDataPointer<ObjectDescriptionData> d;
263 };
264 
265 template<ObjectDescriptionType T>
266 QDebug operator<<(QDebug dbg, const ObjectDescription<T> &d)
267 {
268  dbg.nospace() << "\n{\n";
269  dbg.nospace() << " index: " << d.index() << "\n";
270  Q_FOREACH (const QByteArray &propertyName, d.propertyNames()) {
271  dbg.nospace() << " " << propertyName << ": " <<
272  d.property(propertyName).toString() << "\n";
273  }
274  dbg.nospace() << "}\n";
275 
276  return dbg.space();
277 }
278 
282 typedef ObjectDescription<AudioOutputDeviceType> AudioOutputDevice;
286 #ifndef PHONON_NO_AUDIOCAPTURE
287 typedef ObjectDescription<AudioCaptureDeviceType> AudioCaptureDevice;
288 #endif //PHONON_NO_AUDIOCAPTURE
289 
292 //typedef ObjectDescription<VideoOutputDeviceType> VideoOutputDevice;
296 #ifndef PHONON_NO_VIDEOCAPTURE
297 typedef ObjectDescription<VideoCaptureDeviceType> VideoCaptureDevice;
298 #endif
299 
302 #ifndef QT_NO_PHONON_EFFECT
303 typedef ObjectDescription<EffectType> EffectDescription;
304 #endif //QT_NO_PHONON_EFFECT
305 
309 //typedef ObjectDescription<AudioCodecType> AudioCodecDescription;
313 //typedef ObjectDescription<VideoCodecType> VideoCodecDescription;
317 //typedef ObjectDescription<ContainerFormatType> ContainerFormatDescription;
321 //typedef ObjectDescription<VisualizationType> VisualizationDescription;
322 #ifndef QT_NO_PHONON_MEDIACONTROLLER
323 typedef ObjectDescription<AudioChannelType> AudioChannelDescription;
324 typedef ObjectDescription<SubtitleType> SubtitleDescription;
325 #endif //QT_NO_PHONON_MEDIACONTROLLER
326 
337 typedef QPair<QByteArray, QString> DeviceAccess;
338 
353 typedef QList<DeviceAccess> DeviceAccessList;
354 
355 void PHONON_EXPORT_DEPRECATED registerMetaTypes();
356 
357 } //namespace Phonon
358 
359 Q_DECLARE_METATYPE(Phonon::AudioOutputDevice)
360 Q_DECLARE_METATYPE(QList<Phonon::AudioOutputDevice>)
361 
362 #ifndef PHONON_NO_AUDIOCAPTURE
363 Q_DECLARE_METATYPE(Phonon::AudioCaptureDevice)
364 Q_DECLARE_METATYPE(QList<Phonon::AudioCaptureDevice>)
365 #endif //PHONON_NO_AUDIOCAPTURE
366 
367 #ifndef PHONON_NO_VIDEOCAPTURE
368 Q_DECLARE_METATYPE(Phonon::VideoCaptureDevice)
369 Q_DECLARE_METATYPE(QList<Phonon::VideoCaptureDevice>)
370 #endif //PHONON_NO_VIDEOCAPTURE
371 
372 #ifndef QT_NO_PHONON_EFFECT
373 Q_DECLARE_METATYPE(QList<Phonon::EffectDescription>)
374 Q_DECLARE_METATYPE(Phonon::EffectDescription)
375 #endif //QT_NO_PHONON_EFFECT
376 
377 
378 #ifndef QT_NO_PHONON_MEDIACONTROLLER
379 Q_DECLARE_METATYPE(Phonon::AudioChannelDescription)
380 Q_DECLARE_METATYPE(Phonon::SubtitleDescription)
381 Q_DECLARE_METATYPE(QList<Phonon::AudioChannelDescription>)
382 Q_DECLARE_METATYPE(QList<Phonon::SubtitleDescription>)
383 #endif //QT_NO_PHONON_MEDIACONTROLLER
384 
385 Q_DECLARE_METATYPE(Phonon::DeviceAccess)
386 Q_DECLARE_METATYPE(Phonon::DeviceAccessList)
387 
388 
389 
390 #endif // PHONON_OBJECTDESCRIPTION_H