1/* Webcamoid, webcam capture application.
2 * Copyright (C) 2016  Gonzalo Exequiel Pedone
3 *
4 * Webcamoid is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * Webcamoid is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with Webcamoid. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Web-Site: http://webcamoid.github.io/
18 */
19
20import QtQuick 2.7
21import QtQuick.Controls 2.0
22import QtQuick.Layouts 1.3
23
24GridLayout {
25    columns: 2
26    property bool updating: false
27
28    Component.onCompleted: updateOptions()
29    Connections {
30        target: MultiSrc
31
32        onMediaChanged: updateOptions()
33    }
34
35    function updateOptions()
36    {
37        updating = true
38
39        lstAudioTracks.clear()
40        lstVideoTracks.clear()
41        lstSubtitlesTracks.clear()
42
43        var stream
44        var lang
45        var description
46        var streams = MultiSrc.listTracks("audio/x-raw")
47        lstAudioTracks.append({stream: -1, language: "None"})
48
49        for (stream in streams) {
50            lang = MultiSrc.streamLanguage(streams[stream])
51            description = String(streams[stream])
52
53            if (lang)
54                description += " (" + lang + ")"
55
56            lstAudioTracks.append({stream: streams[stream], language: description})
57        }
58
59        streams = MultiSrc.listTracks("video/x-raw")
60        lstVideoTracks.append({stream: -1, language: "None"})
61
62        for (stream in streams) {
63            lang = MultiSrc.streamLanguage(streams[stream])
64            description = String(streams[stream])
65
66            if (lang)
67                description += " (" + lang + ")"
68
69            lstVideoTracks.append({stream: streams[stream], language: description})
70        }
71
72        streams = MultiSrc.listTracks("text/x-raw")
73        lstSubtitlesTracks.append({stream: -1, language: "None"})
74
75        for (stream in streams) {
76            lang = MultiSrc.streamLanguage(streams[stream])
77            description = String(streams[stream])
78
79            if (lang)
80                description += " (" + lang + ")"
81
82            lstSubtitlesTracks.append({stream: streams[stream], language: description})
83        }
84
85        cbxAudioTracks.currentIndex = lstAudioTracks.count > 1? 1: 0
86        cbxVideoTracks.currentIndex = lstVideoTracks.count > 1? 1: 0
87        cbxSubtitlesTracks.currentIndex = lstSubtitlesTracks.count > 1? 1: 0
88        MultiSrc.streams = [MultiSrc.defaultStream("audio/x-raw"),
89                            MultiSrc.defaultStream("video/x-raw")]
90
91        updating = false
92    }
93
94    function updateStreams()
95    {
96        if (updating)
97            return
98
99        var streams = []
100        var item = lstAudioTracks.get(cbxAudioTracks.currentIndex)
101
102        if (item && item.stream >= 0)
103            streams.push(item.stream)
104
105        item = lstVideoTracks.get(cbxVideoTracks.currentIndex)
106
107        if (item && item.stream >= 0)
108            streams.push(item.stream)
109
110        item = lstSubtitlesTracks.get(cbxSubtitlesTracks.currentIndex)
111
112        if (item && item.stream >= 0)
113            streams.push(item.stream)
114
115        MultiSrc.streams = streams.length < 1? [-1]: streams
116    }
117
118    Label {
119        text: qsTr("Video track")
120    }
121    ComboBox {
122        id: cbxVideoTracks
123        textRole: "language"
124        model: ListModel {
125            id: lstVideoTracks
126        }
127        Layout.fillWidth: true
128        onCurrentIndexChanged: updateStreams()
129    }
130
131    Label {
132        text: qsTr("Audio track")
133    }
134    ComboBox {
135        id: cbxAudioTracks
136        textRole: "language"
137        model: ListModel {
138            id: lstAudioTracks
139        }
140        Layout.fillWidth: true
141        onCurrentIndexChanged: updateStreams()
142    }
143
144    Label {
145        text: qsTr("Subtitles track")
146    }
147    ComboBox {
148        id: cbxSubtitlesTracks
149        textRole: "language"
150        model: ListModel {
151            id: lstSubtitlesTracks
152        }
153        Layout.fillWidth: true
154        onCurrentIndexChanged: updateStreams()
155    }
156}
157