Add support for handling external sink/source volume change events
[apps/mixer.git] / app / pacontrolmodel.h
1 /*
2  * Copyright (C) 2016,2017 Konsulko Group
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #include <pulse/pulseaudio.h>
18
19 #include <QtCore/QAbstractListModel>
20 #include <QtCore/QList>
21
22 class PaControlModel;
23
24 class PaControl
25 {
26         public:
27                 PaControl(const quint32 &index, const QString &desc, const quint32 &type, const quint32 &channel, const QString &cdesc, const quint32 &volume);
28
29                 quint32 cindex() const;
30                 QString desc() const;
31                 quint32 type() const;
32                 quint32 channel() const;
33                 QString cdesc() const;
34                 quint32 volume() const;
35                 void setCIndex(const QVariant&);
36                 void setDesc(const QVariant&);
37                 void setType(const QVariant&);
38                 void setChannel(const QVariant&);
39                 void setCDesc(const QVariant&);
40                 void setVolume(PaControlModel *, const QVariant&);
41
42         private:
43                 quint32 m_cindex;
44                 QString m_desc;
45                 quint32 m_type;
46                 quint32 m_channel;
47                 QString m_cdesc;
48                 quint32 m_volume;
49 };
50
51 class PaControlModel : public QAbstractListModel
52 {
53         Q_OBJECT
54         public:
55                 enum PaControlRoles {
56                         CIndexRole = Qt::UserRole + 1,
57                         DescRole,
58                         TypeRole,
59                         ChannelRole,
60                         CDescRole,
61                         VolumeRole
62                 };
63
64                 PaControlModel(QObject *parent = 0);
65
66                 void addControl(const PaControl &control);
67
68                 int rowCount(const QModelIndex &parent = QModelIndex()) const;
69
70                 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
71
72                 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
73
74                 Qt::ItemFlags flags(const QModelIndex &index) const;
75
76         public slots:
77                 void addOneControl(int cindex, QString desc, int type, int channel, const char *cdesc, int volume);
78                 void changeExternalVolume(uint32_t type, uint32_t cindex, uint32_t chan, uint32_t volume);
79
80         signals:
81                 void volumeChanged(uint32_t type, uint32_t index, uint32_t channel, uint32_t volume);
82
83         protected:
84                 QHash<int, QByteArray> roleNames() const;
85         private:
86                 QList<PaControl> m_controls;
87                 pa_context *pa_ctx;
88 };