-
Notifications
You must be signed in to change notification settings - Fork 0
/
sink.h
73 lines (60 loc) · 1.44 KB
/
sink.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef _sink_h
#define _sink_h
#include "sinkport.h"
class cPulseSink : public cPulseObject {
private:
cList<cPulseSinkPort> _ports;
const cPulseSinkPort *_active_port;
public:
cPulseSink(uint32_t index, const char *name)
:cPulseObject(index, name)
,_active_port(NULL)
{
}
cPulseSink(const cPulseSink &sink)
:cPulseObject(sink)
,_active_port(NULL)
{
cListHelper<cPulseSinkPort>::Copy(sink.Ports(), _ports);
if (sink.ActivePort())
_active_port = cListHelper<cPulseSinkPort>::Find(_ports, sink.ActivePort()->Name());
}
virtual ~cPulseSink(void)
{
}
virtual cString MenuItemText(void) const
{
return cString::sprintf("%s (%s)", *cPulseObject::MenuItemText(), PluggedText());
}
void AddPort(cPulseSinkPort *port, bool isactive)
{
if (isactive)
_active_port = port;
_ports.Add(port);
}
const cPulseSinkPort *ActivePort(void) const
{
return _active_port;
}
const cList<cPulseSinkPort> &Ports(void) const
{
return _ports;
}
const char *PluggedText() const
{
bool hasNo = false;
bool hasOther = false;
for (const cPulseSinkPort *port = Ports().First(); port; port = Ports().Next(port)) {
if (port->Available() == PA_PORT_AVAILABLE_NO)
hasNo = true;
else {
hasOther = true;
break;
}
}
if (hasNo && !hasOther)
return "unplugged";
return "plugged in";
}
};
#endif