PulseAudio Qt Bindings

pulseobject.cpp
1/*
2 SPDX-FileCopyrightText: 2014-2015 Harald Sitter <sitter@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
5*/
6
7#include "pulseobject.h"
8#include "pulseobject_p.h"
9
10#include "context.h"
11
12#include <QIcon>
13#include <QMetaProperty>
14
15using namespace Qt::StringLiterals;
16
17namespace PulseAudioQt
18{
19PulseObject::PulseObject(QObject *parent)
20 : QObject(parent)
21 , d(new PulseObjectPrivate(this))
22{
23}
24
25PulseObject::~PulseObject()
26{
27}
28
29PulseObjectPrivate::PulseObjectPrivate(PulseObject *q)
30 : q(q)
31{
32}
33
34PulseObjectPrivate::~PulseObjectPrivate()
35{
36}
37
38QString PulseObject::name() const
39{
40 return d->m_name;
41}
42
43QString PulseObject::iconName() const
44{
45 QString name = d->m_properties.value(QStringLiteral("device.icon_name")).toString();
46 if (!name.isEmpty() && QIcon::hasThemeIcon(name)) {
47 return name;
48 }
49
50 name = d->m_properties.value(QStringLiteral("media.icon_name")).toString();
51 if (!name.isEmpty() && QIcon::hasThemeIcon(name)) {
52 return name;
53 }
54
55 name = d->m_properties.value(QStringLiteral("window.icon_name")).toString();
56 if (!name.isEmpty() && QIcon::hasThemeIcon(name)) {
57 return name;
58 }
59
60 name = d->m_properties.value(QStringLiteral("application.icon_name")).toString();
61 if (!name.isEmpty() && QIcon::hasThemeIcon(name)) {
62 return name;
63 }
64
65 name = d->m_properties.value(QStringLiteral("application.process.binary")).toString();
66 if (!name.isEmpty() && QIcon::hasThemeIcon(name)) {
67 return name;
68 }
69
70 name = d->m_properties.value(QStringLiteral("application.name")).toString();
71 if (!name.isEmpty() && QIcon::hasThemeIcon(name)) {
72 return name;
73 }
74
75 name = d->m_properties.value(QStringLiteral("pipewire.access.portal.app_id")).toString();
76 if (!name.isEmpty() && QIcon::hasThemeIcon(name)) {
77 return name;
78 }
79
80 name = property("name").toString();
81 if (!name.isEmpty() && QIcon::hasThemeIcon(name)) {
82 return name;
83 }
84
85 return QString();
86}
87
88QVariantMap PulseObject::properties() const
89{
90 return d->m_properties;
91}
92
93} // PulseAudioQt
94
95QDebug operator<<(QDebug dbg, PulseAudioQt::PulseObjectPrivate const *d)
96{
97 QDebugStateSaver saver(dbg);
98
99 auto mo = d->q->metaObject();
100
101 QStringList superClasses;
102 auto superClass = mo;
103 while ((superClass = superClass->superClass())) {
104 superClasses.append(QString::fromLatin1(superClass->className()));
105 }
106
107 dbg.nospace().noquote() << '\n' << mo->className() << '{' << superClasses.join(u", "_s) << '}';
108 dbg.nospace() << "(\n";
109
110 auto indent = QLatin1String(" ");
111
112 for (int i = 0; i < mo->propertyCount(); i++) {
113 auto property = mo->property(i);
114 auto propertyValue = property.read(d->q);
115 if (propertyValue.canConvert<QVariantMap>()) {
116 dbg.nospace() << indent << property.name() << ":\n";
117 const auto properties = propertyValue.value<QVariantMap>();
118 for (auto it = properties.cbegin(); it != properties.cend(); ++it) {
119 auto &key = it.key();
120 auto &value = it.value();
121 dbg.nospace() << indent << indent << key << ": " << value << '\n';
122 }
123 } else {
124 dbg.nospace() << indent << property.name() << ": " << propertyValue << '\n';
125 }
126 }
127
128 dbg.nospace() << ')';
129
130 return dbg;
131}
KGuiItem properties()
The primary namespace of PulseAudioQt.
Definition card.cpp:17
QDebug & noquote()
QDebug & nospace()
bool hasThemeIcon(const QString &name)
void append(QList< T > &&value)
QString fromLatin1(QByteArrayView str)
bool isEmpty() const const
QString join(QChar separator) const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 29 2024 11:50:05 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.