Changeset View
Changeset View
Standalone View
Standalone View
plugins/systemvolume/volumeobject.h
- This file was added.
1 | /* | ||||
---|---|---|---|---|---|
2 | Copyright 2014-2015 Harald Sitter <sitter@kde.org> | ||||
3 | | ||||
4 | This library is free software; you can redistribute it and/or | ||||
5 | modify it under the terms of the GNU Lesser General Public | ||||
6 | License as published by the Free Software Foundation; either | ||||
7 | version 2.1 of the License, or (at your option) version 3, or any | ||||
8 | later version accepted by the membership of KDE e.V. (or its | ||||
9 | successor approved by the membership of KDE e.V.), which shall | ||||
10 | act as a proxy defined in Section 6 of version 3 of the license. | ||||
11 | | ||||
12 | This library is distributed in the hope that it will be useful, | ||||
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||||
15 | Lesser General Public License for more details. | ||||
16 | | ||||
17 | You should have received a copy of the GNU Lesser General Public | ||||
18 | License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||||
19 | */ | ||||
20 | | ||||
21 | #ifndef VOLUMEOBJECT_H | ||||
22 | #define VOLUMEOBJECT_H | ||||
23 | | ||||
24 | #include <pulse/volume.h> | ||||
25 | | ||||
26 | #include "pulseobject.h" | ||||
27 | | ||||
28 | namespace QPulseAudio | ||||
29 | { | ||||
30 | | ||||
31 | class VolumeObject : public PulseObject | ||||
32 | { | ||||
33 | Q_OBJECT | ||||
34 | Q_PROPERTY(qint64 volume READ volume WRITE setVolume NOTIFY volumeChanged) | ||||
35 | Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged) | ||||
36 | Q_PROPERTY(bool hasVolume READ hasVolume NOTIFY hasVolumeChanged) | ||||
37 | Q_PROPERTY(bool volumeWritable READ isVolumeWritable NOTIFY isVolumeWritableChanged) | ||||
38 | Q_PROPERTY(QStringList channels READ channels NOTIFY channelsChanged) | ||||
39 | Q_PROPERTY(QList<qreal> channelVolumes READ channelVolumes NOTIFY channelVolumesChanged) | ||||
40 | public: | ||||
41 | VolumeObject(QObject *parent); | ||||
42 | virtual ~VolumeObject(); | ||||
43 | | ||||
44 | template <typename PAInfo> | ||||
45 | void updateVolumeObject(PAInfo *info) | ||||
46 | { | ||||
47 | updatePulseObject(info); | ||||
48 | if (m_muted != info->mute) { | ||||
49 | m_muted = info->mute; | ||||
50 | emit mutedChanged(); | ||||
51 | } | ||||
52 | if (!pa_cvolume_equal(&m_volume, &info->volume)) { | ||||
53 | m_volume = info->volume; | ||||
54 | emit volumeChanged(); | ||||
55 | emit channelVolumesChanged(); | ||||
56 | } | ||||
57 | QStringList infoChannels; | ||||
58 | infoChannels.reserve(info->channel_map.channels); | ||||
59 | for (int i = 0; i < info->channel_map.channels; ++i) { | ||||
60 | infoChannels << QString::fromUtf8(pa_channel_position_to_pretty_string(info->channel_map.map[i])); | ||||
61 | } | ||||
62 | if (m_channels != infoChannels) { | ||||
63 | m_channels = infoChannels; | ||||
64 | emit channelsChanged(); | ||||
65 | } | ||||
66 | } | ||||
67 | | ||||
68 | qint64 volume() const; | ||||
69 | virtual void setVolume(qint64 volume) = 0; | ||||
70 | | ||||
71 | bool isMuted() const; | ||||
72 | virtual void setMuted(bool muted) = 0; | ||||
73 | | ||||
74 | bool hasVolume() const; | ||||
75 | bool isVolumeWritable() const; | ||||
76 | | ||||
77 | QStringList channels() const; | ||||
78 | QList<qreal> channelVolumes() const; | ||||
79 | Q_INVOKABLE virtual void setChannelVolume(int channel, qint64 volume) = 0; | ||||
80 | | ||||
81 | signals: | ||||
82 | void volumeChanged(); | ||||
83 | void mutedChanged(); | ||||
84 | void hasVolumeChanged(); | ||||
85 | void isVolumeWritableChanged(); | ||||
86 | void channelsChanged(); | ||||
87 | void channelVolumesChanged(); | ||||
88 | | ||||
89 | protected: | ||||
90 | pa_cvolume cvolume() const; | ||||
91 | | ||||
92 | pa_cvolume m_volume; | ||||
93 | bool m_muted; | ||||
94 | bool m_hasVolume; | ||||
95 | bool m_volumeWritable; | ||||
96 | QStringList m_channels; | ||||
97 | }; | ||||
98 | | ||||
99 | } // QPulseAudio | ||||
100 | | ||||
101 | #endif // VOLUMEOBJECT_H |