diff --git a/src/port.cpp b/src/port.cpp index e09fc33..779e1f1 100644 --- a/src/port.cpp +++ b/src/port.cpp @@ -1,41 +1,35 @@ /* 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_availability(Unknown) { } Port::~Port() { } -Port::Availability Port::availability() const -{ - return m_availability; -} - } // QPulseAudio diff --git a/src/port.h b/src/port.h index b1b473e..8a8126e 100644 --- a/src/port.h +++ b/src/port.h @@ -1,79 +1,49 @@ /* 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 Port : public Profile { Q_OBJECT - 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); - - 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(); - } } - - Availability availability() const; - -signals: - void availabilityChanged(); - -private: - Availability m_availability; }; } // QPulseAudio #endif // PORT_H diff --git a/src/profile.cpp b/src/profile.cpp index b7da133..ec48db6 100644 --- a/src/profile.cpp +++ b/src/profile.cpp @@ -1,53 +1,59 @@ /* 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 "profile.h" namespace QPulseAudio { Profile::Profile(QObject *parent) : QObject(parent) , m_name() , m_description() , m_priority(0) + , m_availability(Unknown) { } Profile::~Profile() { } QString Profile::name() const { return m_name; } QString Profile::description() const { return m_description; } quint32 Profile::priority() const { return m_priority; } +Profile::Availability Profile::availability() const +{ + return m_availability; +} + } // QPulseAudio diff --git a/src/profile.h b/src/profile.h index fba28d9..d8188a2 100644 --- a/src/profile.h +++ b/src/profile.h @@ -1,80 +1,98 @@ /* 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 PROFILE_H #define PROFILE_H #include #include namespace QPulseAudio { class Profile : public QObject { Q_OBJECT Q_PROPERTY(QString name READ name NOTIFY nameChanged) Q_PROPERTY(QString description READ description NOTIFY descriptionChanged) Q_PROPERTY(quint32 priority READ priority NOTIFY priorityChanged) + Q_PROPERTY(Availability availability READ availability NOTIFY availabilityChanged) public: + + enum Availability { + Unknown, + Available, + Unavailable + }; + Q_ENUM(Availability) + Profile(QObject *parent); virtual ~Profile(); template void setInfo(const PAInfo *info) { // Description is optional. Name not so much as we need some ID. Q_ASSERT(info->name); QString infoName = QString::fromUtf8(info->name); if (m_name != infoName) { m_name = infoName; emit nameChanged(); } if (info->description) { QString infoDescription = QString::fromUtf8(info->description); if (m_description != infoDescription) { m_description = infoDescription; emit descriptionChanged(); } } if (m_priority != info->priority) { m_priority = info->priority; emit priorityChanged(); } + + Availability newAvailability = info->available ? Available : Unavailable; + if (m_availability != newAvailability) { + m_availability = newAvailability; + emit availabilityChanged(); + } } QString name() const; QString description() const; quint32 priority() const; + Availability availability() const; signals: void nameChanged(); void descriptionChanged(); void priorityChanged(); + void availabilityChanged(); private: QString m_name; QString m_description; quint32 m_priority; + Availability m_availability; }; } // QPulseAudio #endif // PROFILE_H diff --git a/src/qml/plugin.cpp b/src/qml/plugin.cpp index 2126c3f..fc79094 100644 --- a/src/qml/plugin.cpp +++ b/src/qml/plugin.cpp @@ -1,68 +1,68 @@ /* 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 "profile.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"); qmlRegisterType(uri, 0, 1, "ModuleModel"); - qmlRegisterUncreatableType(uri, 0, 1, "Port", QString()); + qmlRegisterUncreatableType(uri, 0, 1, "Profile", 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(); }