Changeset View
Changeset View
Standalone View
Standalone View
src/port.h
Show All 17 Lines | 1 | /* | |||
---|---|---|---|---|---|
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | 18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | 19 | */ | ||
20 | 20 | | |||
21 | #ifndef PORT_H | 21 | #ifndef PORT_H | ||
22 | #define PORT_H | 22 | #define PORT_H | ||
23 | 23 | | |||
24 | #include "profile.h" | 24 | #include "profile.h" | ||
25 | 25 | | |||
26 | #include <pulse/def.h> | ||||
27 | | ||||
26 | namespace QPulseAudio | 28 | namespace QPulseAudio | ||
27 | { | 29 | { | ||
28 | 30 | | |||
29 | class Q_DECL_EXPORT Port : public Profile | 31 | class Q_DECL_EXPORT Port : public Profile | ||
30 | { | 32 | { | ||
31 | Q_OBJECT | 33 | Q_OBJECT | ||
32 | Q_PROPERTY(bool available READ isAvailable NOTIFY availableChanged) | 34 | Q_PROPERTY(Availability availability READ availability NOTIFY availabilityChanged) | ||
33 | public: | 35 | public: | ||
36 | enum Availability { | ||||
37 | Unknown, | ||||
broulik: Not needed, perhaps even
```
enum Availability {
Unknown = -1,
Unavailable… | |||||
drosca: It matches the PA enum values (not that it is actually used though). | |||||
38 | Available, | ||||
39 | Unavailable | ||||
40 | }; | ||||
41 | Q_ENUM(Availability) | ||||
42 | | ||||
34 | Port(QObject *parent); | 43 | Port(QObject *parent); | ||
35 | virtual ~Port(); | 44 | virtual ~Port(); | ||
36 | 45 | | |||
37 | template<typename PAInfo> | 46 | template<typename PAInfo> | ||
38 | void setInfo(const PAInfo *info) | 47 | void setInfo(const PAInfo *info) | ||
39 | { | 48 | { | ||
40 | Profile::setInfo(info); | 49 | Profile::setInfo(info); | ||
41 | if (m_isAvailable != info->available) { | 50 | | ||
42 | m_isAvailable = info->available; | 51 | Availability newAvailability; | ||
43 | emit availableChanged(); | 52 | switch (info->available) { | ||
53 | case PA_PORT_AVAILABLE_NO: | ||||
54 | newAvailability = Unavailable; | ||||
55 | break; | ||||
56 | case PA_PORT_AVAILABLE_YES: | ||||
57 | newAvailability = Available; | ||||
58 | break; | ||||
59 | default: | ||||
60 | newAvailability = Unknown; | ||||
61 | } | ||||
62 | if (m_availability != newAvailability) { | ||||
63 | m_availability = newAvailability; | ||||
64 | emit availabilityChanged(); | ||||
44 | } | 65 | } | ||
45 | } | 66 | } | ||
romangg: Better put the definition of this long method in the cpp file. | |||||
This is templated function, so that's why the definition is in header. drosca: This is templated function, so that's why the definition is in header. | |||||
romangg: There is a way around it, but probably doesn't make sense here. So ok. | |||||
46 | 67 | | |||
47 | bool isAvailable() const; | 68 | Availability availability() const; | ||
48 | 69 | | |||
49 | signals: | 70 | signals: | ||
50 | void availableChanged(); | 71 | void availabilityChanged(); | ||
51 | 72 | | |||
52 | private: | 73 | private: | ||
53 | bool m_isAvailable; | 74 | Availability m_availability; | ||
54 | }; | 75 | }; | ||
55 | 76 | | |||
56 | } // QPulseAudio | 77 | } // QPulseAudio | ||
57 | 78 | | |||
58 | #endif // PORT_H | 79 | #endif // PORT_H |
Not needed, perhaps even