summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Rosca <[email protected]>2017-02-23 11:02:35 +0100
committerDavid Rosca <[email protected]>2017-02-24 16:21:13 +0100
commitfc4ee177396e1d6f06fed3b6f7b4b16e11b3fe54 (patch)
treed229d0c353f7a7c29d909447fc6e4d7beb6f2010
parentdaeafed202f5a68a3f56090f6ab62b6fad4d04af (diff)
Port: Expose port availability to QML
Replaces old available property, which is not used anywhere and also was completely wrong. Differential Revision: https://phabricator.kde.org/D4736
-rw-r--r--src/port.cpp6
-rw-r--r--src/port.h35
-rw-r--r--src/qml/plugin.cpp2
3 files changed, 33 insertions, 10 deletions
diff --git a/src/port.cpp b/src/port.cpp
index a816d4a..e09fc33 100644
--- a/src/port.cpp
+++ b/src/port.cpp
@@ -25,7 +25,7 @@ namespace QPulseAudio
Port::Port(QObject *parent)
: Profile(parent)
- , m_isAvailable(false)
+ , m_availability(Unknown)
{
}
@@ -33,9 +33,9 @@ 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
@@ -23,14 +23,23 @@
#include "profile.h"
+#include <pulse/def.h>
+
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();
@@ -38,19 +47,31 @@ public:
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
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
@@ -28,6 +28,7 @@
#include "source.h"
#include "context.h"
#include "modulemanager.h"
+#include "port.h"
#include "globalactioncollection.h"
#include "volumeosd.h"
@@ -53,6 +54,7 @@ void Plugin::registerTypes(const char* uri)
qmlRegisterType<QPulseAudio::ModuleManager>(uri, 0, 1, "ModuleManager");
qmlRegisterType<QPulseAudio::SourceOutputModel>(uri, 0, 1, "SourceOutputModel");
qmlRegisterType<QPulseAudio::StreamRestoreModel>(uri, 0, 1, "StreamRestoreModel");
+ qmlRegisterUncreatableType<QPulseAudio::Port>(uri, 0, 1, "Port", QString());
qmlRegisterType<GlobalAction>(uri, 0, 1, "GlobalAction");
qmlRegisterType<GlobalActionCollection>(uri, 0, 1, "GlobalActionCollection");
qmlRegisterType<VolumeOSD>(uri, 0, 1, "VolumeOSD");