Commit 204f0ca4 authored by Nicolas Fella's avatar Nicolas Fella Committed by Bhushan Shah
Browse files

Expose port type

Wrap it in our own enum to avoid libpulse types leaking into the API.

type is only availabe from 14.0 on, show unknown otherwise.
parent f38043f9
......@@ -27,4 +27,9 @@ PortPrivate::~PortPrivate()
{
}
Port::Type Port::type() const
{
return d->m_type;
}
} // PulseAudioQt
......@@ -18,10 +18,43 @@ namespace PulseAudioQt
class PULSEAUDIOQT_EXPORT Port : public Profile
{
Q_OBJECT
Q_PROPERTY(Type type READ type NOTIFY typeChanged)
public:
~Port();
enum Type {
Unknown,
AUX,
Speaker,
Headphones,
Line,
Mic,
Headset,
Handset,
Earpiece,
SPDIF,
HDMI,
TV,
Radio,
Video,
USB,
Bluetooth,
Portable,
Handsfree,
Car,
HiFi,
Phone,
Network,
Analog,
};
Q_ENUM(Type)
Type type() const;
Q_SIGNALS:
void typeChanged();
protected:
/** @private */
explicit Port(QObject *parent);
......
......@@ -19,6 +19,7 @@ public:
virtual ~PortPrivate();
Port *q;
Port::Type m_type = Port::Type::Unknown;
template<typename PAInfo>
void setInfo(const PAInfo *info)
......@@ -34,6 +35,12 @@ public:
default:
newAvailability = Profile::Unknown;
}
#if PA_CHECK_VERSION(14, 0, 0)
m_type = static_cast<Port::Type>(info->type);
#endif
Q_EMIT q->typeChanged();
q->Profile::d->setCommonInfo(info, newAvailability);
}
};
......
......@@ -32,6 +32,8 @@ Kirigami.FormLayout {
PropertiesItem {}
PortsItem {}
function availabilityToString(availability) {
if (availability === 0) {
return "Unknown"
......@@ -53,15 +55,4 @@ Kirigami.FormLayout {
}
}
}
Column {
Kirigami.FormData.label: "Ports:"
Repeater {
model: Ports
delegate: Label {
text: modelData.name + ": " + modelData.description + ", Priority: " + modelData.priority + ", Availability: " + availabilityToString(modelData.availability)
}
}
}
}
......@@ -50,6 +50,7 @@ Kirigami.FormLayout {
text: VolumeWritable
}
PortsItem {}
PropertiesItem {}
}
/*
SPDX-FileCopyrightText: 2021 Nicolas Fella <nicolas.fella@gmx.de>
SPDX-License-Identifier: LGPL-2.1-only OR LGPL-3.0-only OR LicenseRef-KDE-Accepted-LGPL
*/
import QtQuick 2.7
import QtQuick.Layouts 1.3
import QtQuick.Controls 2.2
import org.kde.kirigami 2.10 as Kirigami
import org.kde.pulseaudioqt.painspector 1.0
Column {
Kirigami.FormData.label: "Ports:"
function availabilityToString(availability) {
if (availability === 0) {
return "Unknown"
}
if (availability === 1) {
return "Available"
}
if (availability === 2) {
return "Unavailable"
}
}
Repeater {
model: Ports
delegate: Label {
text: modelData.name + ": " + modelData.description + ", Priority: " + modelData.priority + ", Type: " + Enums.portTypeToString(modelData.type) + ", Availability: " + availabilityToString(modelData.availability)
}
}
}
......@@ -7,6 +7,20 @@
#include <QQmlApplicationEngine>
#include "models.h"
#include "port.h"
class Enums : public QObject
{
Q_OBJECT
public:
Q_INVOKABLE QString portTypeToString(int type)
{
QMetaObject metaObject = PulseAudioQt::Port::staticMetaObject;
QMetaEnum metaEnum = metaObject.enumerator(metaObject.indexOfEnumerator("Type"));
return QString(metaEnum.valueToKey(type));
}
};
int main(int argc, char *argv[])
{
......@@ -22,6 +36,11 @@ int main(int argc, char *argv[])
qmlRegisterType<PulseAudioQt::StreamRestoreModel>(uri, 0, 1, "StreamRestoreModel");
qmlRegisterType<PulseAudioQt::ModuleModel>(uri, 0, 1, "ModuleModel");
Enums e;
qmlRegisterSingletonInstance("org.kde.pulseaudioqt.painspector", 1, 0, "Enums", &e);
QQmlApplicationEngine engine(QUrl(QStringLiteral("qrc:/main.qml")));
return app.exec();
}
#include "main.moc"
......@@ -7,6 +7,7 @@
<file>ModuleDelegate.qml</file>
<file>Header.qml</file>
<file>PropertiesItem.qml</file>
<file>PortsItem.qml</file>
<file>PAPage.qml</file>
</qresource>
</RCC>
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment