aa34a79e83f9a9ee140e12516ae6a35989704774
[apps/mixer.git] / app / pacontrolmodel.h
1 /*
2  * Copyright (C) 2016 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 #ifndef __cplusplus
20 extern void add_one_control(void *ctx, int, const char *, int, int, const char *, int);
21 #else
22 extern "C" void add_one_control(void *ctx, int, const char *, int, int, const char *, int);
23
24 #include <QAbstractListModel>
25 #include <QStringList>
26
27 class PaControlModel;
28
29 class PaControl
30 {
31         public:
32                 PaControl(const quint32 &index, const QString &desc, const quint32 &type, const quint32 &channel, const QString &cdesc, const quint32 &volume);
33
34                 quint32 cindex() const;
35                 QString desc() const;
36                 quint32 type() const;
37                 quint32 channel() const;
38                 QString cdesc() const;
39                 quint32 volume() const;
40                 void setCIndex(const QVariant&);
41                 void setDesc(const QVariant&);
42                 void setType(const QVariant&);
43                 void setChannel(const QVariant&);
44                 void setCDesc(const QVariant&);
45                 void setVolume(pa_context *, const QVariant&);
46
47         private:
48                 quint32 m_cindex;
49                 QString m_desc;
50                 quint32 m_type;
51                 quint32 m_channel;
52                 QString m_cdesc;
53                 quint32 m_volume;
54 };
55
56 class PaControlModel : public QAbstractListModel
57 {
58         Q_OBJECT
59         public:
60                 enum PaControlRoles {
61                         CIndexRole = Qt::UserRole + 1,
62                         DescRole,
63                         TypeRole,
64                         ChannelRole,
65                         CDescRole,
66                         VolumeRole
67                 };
68
69                 PaControlModel(QObject *parent = 0);
70
71                 void addControl(const PaControl &control);
72
73                 int rowCount(const QModelIndex &parent = QModelIndex()) const;
74
75                 QVariant data(const QModelIndex &index, int role = Qt::DisplayRole) const;
76
77                 bool setData(const QModelIndex &index, const QVariant &value, int role = Qt::EditRole);
78
79                 Qt::ItemFlags flags(const QModelIndex &index) const;
80
81         protected:
82                 QHash<int, QByteArray> roleNames() const;
83         private:
84                 QList<PaControl> m_controls;
85                 pa_context *pa_ctx;
86 };
87 #endif // __cplusplus