PluginConfig.qml
9.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
/* Webcamoid, webcam capture application.
* Copyright (C) 2016 Gonzalo Exequiel Pedone
*
* Webcamoid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Webcamoid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Webcamoid. If not, see <http://www.gnu.org/licenses/>.
*
* Web-Site: http://webcamoid.github.io/
*/
import QtQuick
import Qt.labs.platform as LABS
import QtQuick.Controls
import QtQuick.Layouts
import Ak
Page {
ColumnLayout {
anchors.fill: parent
TabBar {
id: tabBar
Layout.fillWidth: true
TabButton {
text: qsTr("Paths")
}
TabButton {
text: qsTr("Plugins")
}
}
StackLayout {
id: stack
Layout.fillWidth: true
Layout.fillHeight: true
currentIndex: tabBar.currentIndex
function fillSearchPaths()
{
searchPathsTable.minHeight = 0
for (let i = searchPathsTable.count - 1; i >= 0; i--)
searchPathsTable.removeItem(searchPathsTable.itemAt(i))
let searchPaths = AkPluginManager.searchPaths
for (let path in searchPaths) {
let component = Qt.createComponent("PluginsPathItem.qml")
if (component.status !== Component.Ready)
continue
let obj = component.createObject(searchPathsTable)
obj.text = searchPaths[path]
searchPathsTable.minHeight += obj.height
obj.onPathRemoved.connect(function (item) {
let index = -1
for (let i in searchPathsTable.contentChildren)
if (searchPathsTable.contentChildren[i] == item) {
index = i
break
}
let searchPaths = AkPluginManager.searchPaths
let sp = []
for (let i in searchPaths)
if (i != index)
sp.push(searchPaths[i])
AkPluginManager.setSearchPaths(sp)
searchPathsTable.removeItem(item)
stack.refreshCache()
})
}
}
function fillPluginList()
{
pluginsTable.minHeight = 0
for (let i = pluginsTable.count - 1; i >= 0; i--)
pluginsTable.removeItem(pluginsTable.itemAt(i))
let plugins = AkPluginManager.listPlugins()
plugins.sort(function(a, b) {
if (a < b)
return -1
else if (a > b)
return 1
return 0
})
for (let plugin in plugins) {
let component = Qt.createComponent("PluginItem.qml")
if (component.status !== Component.Ready)
continue
let obj = component.createObject(pluginsTable)
obj.text = plugins[plugin]
obj.pluginId = plugins[plugin]
obj.checked = AkPluginManager.pluginStatus(plugins[plugin]) == AkPluginManager.Enabled
pluginsTable.minHeight += obj.height
obj.onToggled.connect((item => function () {
let enabledPlugins =
AkPluginManager.listPlugins("",
[],
AkPluginManager.FilterEnabled)
let disabledPlugins =
AkPluginManager.listPlugins("",
[],
AkPluginManager.FilterDisabled)
let enabledIndex = enabledPlugins.indexOf(item.pluginId)
let disabledIndex = disabledPlugins.indexOf(item.pluginId)
if (item.checked) {
if (enabledIndex < 0)
enabledPlugins.push(item.pluginId)
if (disabledIndex >= 0)
disabledPlugins.splice(disabledIndex, 1)
} else {
if (enabledIndex >= 0)
enabledPlugins.splice(enabledIndex, 1)
if (disabledIndex < 0)
disabledPlugins.push(item.pluginId)
}
AkPluginManager.setPluginsStatus(enabledPlugins,
AkPluginManager.Enabled)
AkPluginManager.setPluginsStatus(disabledPlugins,
AkPluginManager.Disabled)
pluginConfigs.saveProperties()
})(obj))
}
}
function refreshCache()
{
AkPluginManager.setCachedPlugins([])
AkPluginManager.scanPlugins()
fillPluginList()
pluginConfigs.saveProperties()
}
function refreshAll()
{
fillSearchPaths()
refreshCache()
}
Component.onCompleted: {
fillSearchPaths()
fillPluginList()
}
// Paths tab
ScrollView {
id: pathsScrollView
contentHeight: pathsConfigs.height
clip: true
ColumnLayout {
id: pathsConfigs
width: pathsScrollView.width
Switch {
text: qsTr("Search plugins in subfolders")
checked: AkPluginManager.recursiveSearch
onCheckedChanged: {
AkPluginManager.recursiveSearch = checked
stack.refreshCache()
}
}
Button {
text: qsTr("Add path")
icon.source: "image://icons/add"
flat: true
onClicked: fileDialog.open()
}
OptionList {
id: searchPathsTable
enableHighlight: false
Layout.fillWidth: true
Layout.minimumHeight: minHeight
clip: true
property int minHeight: 0
onActiveFocusChanged:
if (activeFocus && count > 0)
itemAt(currentIndex).forceActiveFocus()
Keys.onUpPressed:
itemAt(currentIndex).forceActiveFocus()
Keys.onDownPressed:
itemAt(currentIndex).forceActiveFocus()
Keys.onLeftPressed:
itemAt(currentIndex).swipe.open(SwipeDelegate.Right)
Keys.onRightPressed:
itemAt(currentIndex).swipe.close()
}
}
}
// Plugins tabs
ScrollView {
id: pluginsScrollView
contentHeight: pluginConfigsLayout.height
clip: true
ColumnLayout {
id: pluginConfigsLayout
width: pluginsScrollView.width
Button {
text: qsTr("Update")
Accessible.description: qsTr("Update plugins list")
icon.source: "image://icons/reset"
flat: true
onClicked: stack.refreshCache()
}
OptionList {
id: pluginsTable
enableHighlight: false
Layout.fillWidth: true
Layout.minimumHeight: minHeight
clip: true
property int minHeight: 0
onActiveFocusChanged:
if (activeFocus && count > 0)
itemAt(currentIndex).forceActiveFocus()
Keys.onUpPressed:
itemAt(currentIndex).forceActiveFocus()
Keys.onDownPressed:
itemAt(currentIndex).forceActiveFocus()
}
}
}
}
}
LABS.FolderDialog {
id: fileDialog
title: qsTr("Add plugins search path")
onAccepted: {
let path = mediaTools.urlToLocalFile(folder)
AkPluginManager.addSearchPath(path)
stack.refreshAll()
}
}
}