~mateo-salta/uvolman/uvolman

« back to all changes in this revision

Viewing changes to uVolMan/Main.qml

  • Committer: Devid Antonio Filoni
  • Date: 2016-07-29 19:40:57 UTC
  • Revision ID: git-v1:cdfff2c72a8eb5247b10da7d60874d8a3f600168
Initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * This file is part of uvolman.dfiloni
 
3
 *
 
4
 * Copyright (C) 2016 Devid Antonio Filoni https://launchpad.net/~d.filoni
 
5
 *
 
6
 * This program is free software: you can redistribute it and/or modify
 
7
 * it under the terms of the GNU General Public License as published by
 
8
 * the Free Software Foundation, either version 3 of the License, or
 
9
 * (at your option) any later version.
 
10
 *
 
11
 * This program is distributed in the hope that it will be useful,
 
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 * GNU General Public License for more details.
 
15
 *
 
16
 * You should have received a copy of the GNU General Public License
 
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
18
 */
 
19
 
 
20
import QtQuick 2.4
 
21
import Ubuntu.Components 1.3
 
22
import UVolMan 1.0
 
23
/*!
 
24
    \brief MainView with a Label and Button elements.
 
25
*/
 
26
 
 
27
MainView {
 
28
    // objectName for functional testing purposes (autopilot-qt5)
 
29
    id: uVolMan
 
30
    objectName: "mainView"
 
31
 
 
32
    // Note! applicationName needs to match the "name" field of the click manifest
 
33
    applicationName: "uvolman.dfiloni"
 
34
    property string applicationVersion: "0.1"
 
35
 
 
36
    width: units.gu(100)
 
37
    height: units.gu(75)
 
38
 
 
39
    PageStack {
 
40
        id: mainStack
 
41
        Component.onCompleted: push(mainPage)
 
42
 
 
43
        Page {
 
44
            id: mainPage
 
45
            visible: false
 
46
 
 
47
            header: PageHeader {
 
48
                anchors.top: mainPage.top
 
49
                id: pageHeader
 
50
                title: i18n.tr("uVolMan")
 
51
                StyleHints {
 
52
                    foregroundColor: UbuntuColors.orange
 
53
                    backgroundColor: UbuntuColors.porcelain
 
54
                    dividerColor: UbuntuColors.warmGrey//UbuntuColors.slate
 
55
                }
 
56
                trailingActionBar {
 
57
                    actions: [
 
58
                        Action {
 
59
                            iconName: "info"
 
60
                            text: i18n.tr("About")
 
61
                            onTriggered: mainStack.push(Qt.resolvedUrl("AboutPage.qml"))
 
62
                        }
 
63
                   ]
 
64
                   numberOfSlots: 1
 
65
                }
 
66
            }
 
67
 
 
68
            IndicatorSoundService {
 
69
                id: indicatorSoundService
 
70
                property real cachedVolume: indicatorSoundService.getVolume();
 
71
                property real cachedMicVolume: indicatorSoundService.getMicVolume();
 
72
                onVolumeChanged: {
 
73
                    if (cachedVolume !== newValue)
 
74
                    {
 
75
                        cachedVolume = newValue;
 
76
                        if (volumeSlider.slider.value !== cachedVolume)
 
77
                            volumeSlider.slider.value = cachedVolume;
 
78
                    }
 
79
                }
 
80
                onMicVolumeChanged: {
 
81
                    if (cachedMicVolume !== newValue)
 
82
                    {
 
83
                        cachedMicVolume = newValue;
 
84
                        if (micVolumeSlider.slider.value !== cachedMicVolume)
 
85
                            micVolumeSlider.slider.value = cachedMicVolume;
 
86
                    }
 
87
                }
 
88
            }
 
89
 
 
90
            PulseStreamRestore {
 
91
                id: pulseStreamRestore
 
92
            }
 
93
 
 
94
            Flickable {
 
95
                anchors.top: pageHeader.bottom
 
96
                anchors.left: parent.left
 
97
                anchors.right: parent.right
 
98
                height: parent.height-pageHeader.height
 
99
                contentHeight: mainColumn.height
 
100
                flickableDirection: Flickable.VerticalFlick
 
101
 
 
102
                Column {
 
103
                    id: mainColumn
 
104
                    anchors.left: parent.left
 
105
                    anchors.right: parent.right
 
106
                    anchors.top: parent.top
 
107
 
 
108
                    ListItem {
 
109
                        id: indicatorSoundLabel
 
110
                        Label {
 
111
                            anchors {
 
112
                                fill: parent
 
113
                                leftMargin: units.gu(2)
 
114
                                topMargin: units.gu(3);
 
115
                                bottomMargin: units.gu(2);
 
116
                            }
 
117
                            horizontalAlignment: Text.AlignLeft
 
118
                            text: i18n.tr("Indicator.Sound")
 
119
                            font.pixelSize: units.gu(2);
 
120
                        }
 
121
                        divider.visible: false
 
122
                    }
 
123
 
 
124
                    VolSlider {
 
125
                        id: volumeSlider
 
126
                        property bool firstValueChange: false
 
127
                        labelText: i18n.tr("Speakers")
 
128
                        slider.value: indicatorSoundService.cachedVolume
 
129
                        slider.onValueChanged: {
 
130
                            if (indicatorSoundService.cachedVolume !== slider.value)
 
131
                                indicatorSoundService.setVolume(slider.value);
 
132
                        }
 
133
                        enabled: (indicatorSoundService.cachedVolume != -1)
 
134
                        divider.visible: (indicatorSoundService.cachedVolume != -1)
 
135
                    }
 
136
                    ListItem {
 
137
                        id: volumeSliderError
 
138
                        visible: (indicatorSoundService.cachedVolume == -1)
 
139
                        height: visible ? units.gu(3) : 0
 
140
                        Text {
 
141
                            anchors {
 
142
                                top: parent.top
 
143
                                left: parent.left
 
144
                                leftMargin: units.gu(2)
 
145
                            }
 
146
                            horizontalAlignment: Text.AlignLeft
 
147
                            text: i18n.tr("Speakers configuration not available!")
 
148
                        }
 
149
                    }
 
150
 
 
151
                    VolSlider {
 
152
                        id: micVolumeSlider
 
153
                        property bool firstValueChange: false
 
154
                        labelText: i18n.tr("Microphone")
 
155
                        slider.value: indicatorSoundService.cachedMicVolume
 
156
                        slider.onValueChanged: {
 
157
                            if (indicatorSoundService.cachedMicVolume !== slider.value)
 
158
                                indicatorSoundService.setMicVolume(slider.value);
 
159
                        }
 
160
                        enabled: (indicatorSoundService.cachedMicVolume != -1)
 
161
                        divider.visible: (indicatorSoundService.cachedMicVolume != -1)
 
162
                    }
 
163
                    ListItem {
 
164
                        id: micVolumeSliderError
 
165
                        visible: (indicatorSoundService.cachedMicVolume == -1)
 
166
                        height: visible ? units.gu(3) : 0
 
167
                        Text {
 
168
                            anchors {
 
169
                                top: parent.top
 
170
                                left: parent.left
 
171
                                leftMargin: units.gu(2)
 
172
                            }
 
173
                            horizontalAlignment: Text.AlignLeft
 
174
                            text: i18n.tr("Microphone configuration not available!")
 
175
                        }
 
176
                    }
 
177
 
 
178
 
 
179
 
 
180
                    ListItem {
 
181
                        id: streamRestoreEntriesLabel
 
182
                        anchors.left: parent.left
 
183
                        anchors.right: parent.right
 
184
 
 
185
                        Label {
 
186
                            anchors {
 
187
                                fill: parent
 
188
                                leftMargin: units.gu(2)
 
189
                                topMargin: units.gu(3);
 
190
                                bottomMargin: units.gu(2);
 
191
                            }
 
192
                            horizontalAlignment: Text.AlignLeft
 
193
                            text: i18n.tr("PulseAudio.Ext.StreamRestore1")
 
194
                            font.pixelSize: units.gu(2);
 
195
                        }
 
196
 
 
197
                        Button {
 
198
                            id: streamRestoreEntriesCheckbox
 
199
                            property bool checked: false
 
200
                            onClicked: checked = !checked;
 
201
 
 
202
                            Icon {
 
203
                                anchors.fill: parent
 
204
                                anchors.margins: units.gu(0.1);
 
205
                                name: "compose"
 
206
                                color:  streamRestoreEntriesCheckbox.checked ? "white" : "#808080"
 
207
                            }
 
208
 
 
209
                            anchors {
 
210
                                right: parent.right
 
211
                                top: parent.top
 
212
                                rightMargin: units.gu(2);
 
213
                                topMargin: units.gu(2.75);
 
214
                            }
 
215
                            width: height
 
216
                            height: units.gu(3)
 
217
                            StyleHints {
 
218
                                defaultColor: streamRestoreEntriesCheckbox.checked ? "#808080" : "white"
 
219
                            }
 
220
                            visible: (pulseStreamRestore.isConnected())
 
221
                        }
 
222
                        /* Switch {
 
223
                            id: streamRestoreEntriesCheckbox
 
224
                            checked: false
 
225
                            anchors {
 
226
                                right: parent.right
 
227
                                top: parent.top
 
228
                                rightMargin: units.gu(2);
 
229
                                topMargin: units.gu(3);
 
230
                            }
 
231
                            visible: (pulseStreamRestore.isConnected())
 
232
                        } */
 
233
 
 
234
                        divider.visible: false
 
235
                    }
 
236
 
 
237
                    Column {
 
238
                        id: streamRestoreEntriesList
 
239
                        anchors.left: parent.left
 
240
                        anchors.right: parent.right
 
241
 
 
242
                        function extractEntriesKeys()
 
243
                        {
 
244
                            var keys = [];
 
245
                            for (var entry in pulseStreamRestore.getEntries())
 
246
                                keys.push(entry);
 
247
                            return keys;
 
248
                        }
 
249
 
 
250
                        Repeater {
 
251
                            model: streamRestoreEntriesList.extractEntriesKeys()
 
252
                            VolSlider {
 
253
                                property variant entryObj: false
 
254
                                slider.onValueChanged: {
 
255
                                    entryObj.setVolume(slider.value);
 
256
                                }
 
257
 
 
258
                                Connections {
 
259
                                    target: entryObj
 
260
                                    ignoreUnknownSignals: true
 
261
                                    onVolumeChanged: {
 
262
                                        slider.value = newValue;
 
263
                                    }
 
264
                                }
 
265
                            }
 
266
                            onItemAdded: {
 
267
                                var entries = pulseStreamRestore.getEntries();
 
268
                                var entries_keys = streamRestoreEntriesList.extractEntriesKeys();
 
269
                                item.entryObj = entries[entries_keys[index]];
 
270
                                item.labelText = item.entryObj.getName();
 
271
                                item.slider.value = item.entryObj.getVolume();
 
272
                            }
 
273
                        }
 
274
                        enabled: (pulseStreamRestore.isConnected() && streamRestoreEntriesCheckbox.checked)
 
275
                        visible: pulseStreamRestore.isConnected()
 
276
                    }
 
277
                    ListItem {
 
278
                        id: streamRestoreEntriesListError
 
279
                        height: units.gu(4)
 
280
                        Text {
 
281
                            anchors {
 
282
                                top: parent.top
 
283
                                left: parent.left
 
284
                                topMargin: units.gu(1)
 
285
                                leftMargin: units.gu(2)
 
286
                            }
 
287
                            horizontalAlignment: Text.AlignLeft
 
288
                            text: i18n.tr("StreamRestore1 configuration not available!")
 
289
                            visible: (!pulseStreamRestore.isConnected())
 
290
                        }
 
291
                        divider.visible: (!pulseStreamRestore.isConnected())
 
292
                    }
 
293
                }
 
294
            }
 
295
        }
 
296
    }
 
297
}
 
298
 
 
299
 
 
300