diff --git a/src/port.cpp b/src/port.cpp index a816d4a..e09fc33 100644 --- a/src/port.cpp +++ b/src/port.cpp @@ -1,41 +1,41 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "port.h" namespace QPulseAudio { Port::Port(QObject *parent) : Profile(parent) - , m_isAvailable(false) + , m_availability(Unknown) { } Port::~Port() { } -bool Port::isAvailable() const +Port::Availability Port::availability() const { - return m_isAvailable; + return m_availability; } } // QPulseAudio diff --git a/src/port.h b/src/port.h index 819ff62..a009788 100644 --- a/src/port.h +++ b/src/port.h @@ -1,58 +1,79 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #ifndef PORT_H #define PORT_H #include "profile.h" +#include + namespace QPulseAudio { class Q_DECL_EXPORT Port : public Profile { Q_OBJECT - Q_PROPERTY(bool available READ isAvailable NOTIFY availableChanged) + Q_PROPERTY(Availability availability READ availability NOTIFY availabilityChanged) public: + enum Availability { + Unknown, + Available, + Unavailable + }; + Q_ENUM(Availability) + Port(QObject *parent); virtual ~Port(); template void setInfo(const PAInfo *info) { Profile::setInfo(info); - if (m_isAvailable != info->available) { - m_isAvailable = info->available; - emit availableChanged(); + + Availability newAvailability; + switch (info->available) { + case PA_PORT_AVAILABLE_NO: + newAvailability = Unavailable; + break; + case PA_PORT_AVAILABLE_YES: + newAvailability = Available; + break; + default: + newAvailability = Unknown; + } + if (m_availability != newAvailability) { + m_availability = newAvailability; + emit availabilityChanged(); } } - bool isAvailable() const; + Availability availability() const; signals: - void availableChanged(); + void availabilityChanged(); private: - bool m_isAvailable; + Availability m_availability; }; } // QPulseAudio #endif // PORT_H diff --git a/src/qml/plugin.cpp b/src/qml/plugin.cpp index e4604df..9cbfc56 100644 --- a/src/qml/plugin.cpp +++ b/src/qml/plugin.cpp @@ -1,65 +1,67 @@ /* Copyright 2014-2015 Harald Sitter This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) version 3, or any later version accepted by the membership of KDE e.V. (or its successor approved by the membership of KDE e.V.), which shall act as a proxy defined in Section 6 of version 3 of the license. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library. If not, see . */ #include "plugin.h" #include #include "pulseaudio.h" #include "client.h" #include "sink.h" #include "source.h" #include "context.h" #include "modulemanager.h" +#include "port.h" #include "globalactioncollection.h" #include "volumeosd.h" #include "volumefeedback.h" static QJSValue pulseaudio_singleton(QQmlEngine *engine, QJSEngine *scriptEngine) { Q_UNUSED(engine) QJSValue object = scriptEngine->newObject(); object.setProperty(QStringLiteral("NormalVolume"), (double) QPulseAudio::Context::NormalVolume); object.setProperty(QStringLiteral("MinimalVolume"), (double) QPulseAudio::Context::MinimalVolume); object.setProperty(QStringLiteral("MaximalVolume"), (double) QPulseAudio::Context::MaximalVolume); return object; } void Plugin::registerTypes(const char* uri) { qmlRegisterType(uri, 0, 1, "CardModel"); qmlRegisterType(uri, 0, 1, "SinkModel"); qmlRegisterType(uri, 0, 1, "SinkInputModel"); qmlRegisterType(uri, 0, 1, "SourceModel"); qmlRegisterType(uri, 0, 1, "ModuleManager"); qmlRegisterType(uri, 0, 1, "SourceOutputModel"); qmlRegisterType(uri, 0, 1, "StreamRestoreModel"); + qmlRegisterUncreatableType(uri, 0, 1, "Port", QString()); qmlRegisterType(uri, 0, 1, "GlobalAction"); qmlRegisterType(uri, 0, 1, "GlobalActionCollection"); qmlRegisterType(uri, 0, 1, "VolumeOSD"); qmlRegisterType(uri, 0, 1, "VolumeFeedback"); qmlRegisterSingletonType(uri, 0, 1, "PulseAudio", pulseaudio_singleton); qmlRegisterType(); qmlRegisterType(); qmlRegisterType(); }