81eb70bfbc3e17514e67b7adee8e35c2b19c857f
[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 &name, const QString &desc, const quint32 &type, const quint32 &channel, const QString &cdesc, const quint32 &volume);
28
29                 quint32 cindex() const;
30                 QString name() const;
31                 QString desc() const;
32                 quint32 type() const;
33                 quint32 channel() const;
34                 QString cdesc() const;
35                 quint32 volume() const;
36                 void setCIndex(const QVariant&);
37                 void setName(const QVariant&);
38                 void setDesc(const QVariant&);
39                 void setType(const QVariant&);
40                 void setChannel(const QVariant&);
41                 void setCDesc(const QVariant&);
42                 void setVolume(PaControlModel *, const QVariant&);
43
44         private:
45                 quint32 m_cindex;
46                 QString m_name;
47                 QString m_desc;
48                 quint32 m_type;
49                 quint32 m_channel;
50                 QString m_cdesc;
51                 quint32 m_volume;
52 };
53
54 class PaControlModel : public QAbstractListModel
55 {
56         Q_OBJECT
57         public:
58                 enum PaControlRoles {
59                         CIndexRole = Qt::UserRole + 1,
60                         NameRole,
61                         DescRole,
62                         TypeRole,
63                         ChannelRole,
64                         CDescRole,
65                         VolumeRole
66                 };
67
68                 PaControlModel(QObject *parent = 0);
69
70                 void addControl(const PaControl &control);
71
72                 int rowCount(const QModelIndex &parent = QModelIndex()) const;
73
74                 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
75
76                 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
77
78                 Qt::ItemFlags flags(const QModelIndex &index) const;
79
80         public slots:
81                 void addOneControl(int cindex, QString name, QString desc, int type, int channel, const char *cdesc, int volume);
82                 void changeExternalVolume(uint32_t type, uint32_t cindex, uint32_t chan, uint32_t volume);
83
84         signals:
85                 void volumeChanged(uint32_t type, uint32_t index, uint32_t channel, uint32_t volume);
86
87         protected:
88                 QHash<int, QByteArray> roleNames() const;
89         private:
90                 QList<PaControl> m_controls;
91                 pa_context *pa_ctx;
92 };