blob: 2bce00218540a3175c69aa0996a46e517012ed74 [file] [log] [blame]
agsantos655d8e22020-08-10 17:36:47 -04001/**
2 * Copyright (C) 2020 by Savoir-faire Linux
3 * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
Sébastien Blin1f915762020-08-03 13:27:42 -04004 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19import QtQuick 2.15
20import QtQuick.Window 2.14
21import QtQuick.Controls 2.14
22import QtQuick.Controls.Universal 2.12
23import QtQuick.Layouts 1.3
24import Qt.labs.platform 1.1
25import QtGraphicalEffects 1.14
26import net.jami.Models 1.0
27import "../../commoncomponents"
28
29Rectangle {
30 id: pluginListPreferencesViewRect
31
32 enum Type {
33 LIST,
34 DEFAULT
35 }
36
37 signal updatePluginList
38
39 property string pluginName: ""
40 property string pluginIcon: ""
41 property string pluginId: ""
42 property bool isLoaded: false
43 property int size: 0
44
45 visible: false
46
47 function updatePreferenceListDisplayed(show){
48 // settings
49 getSize(pluginId, show)
50 preferenceItemListModel.pluginId = pluginId
51 preferenceItemListModel.reset()
52 }
53
54 function resetPluginSlot(){
55 resetPluginMessageBox.open()
56 }
57
58 function resetPlugin(){
59 ClientWrapper.pluginModel.resetPluginPreferencesValues(pluginId, isLoaded)
60 updatePluginList()
61 }
62
63 function uninstallPluginSlot(){
64 uninstallPluginMessageBox.open()
65 }
66
67 function uninstallPlugin(){
68 ClientWrapper.pluginModel.uninstallPlugin(pluginId)
69 updatePluginList()
70 }
71
72 function getSize(pluginId, show){
73 size = 50 * ClientWrapper.pluginModel.getPluginPreferences(pluginId).length
74 if (show) {
agsantos655d8e22020-08-10 17:36:47 -040075 height = 200 + size
Sébastien Blin1f915762020-08-03 13:27:42 -040076 pluginPreferenceView.height = size
77 } else {
78 height = 25
79 }
80 }
81
82 function editPreferenceSlot(preferenceType, preferenceName, preferenceEntryValues){
83 switch (preferenceType){
84 case PluginListPreferencesView.LIST:
85 console.log("LIST")
86 editListMessageBox.preferenceName = preferenceName
87 editListMessageBox.preferenceEntryValues = preferenceEntryValues
88 editListMessageBox.open()
89 break
90 case PluginListPreferencesView.DEFAULT:
91 console.log("Unrecognizable Type")
92 break
93 default:
94 console.log("Unrecognizable Type")
95 break
96 }
97 }
98
99 function setPreference(pluginId, preferenceKey, preferenceNewValue)
100 {
101 ClientWrapper.pluginModel.setPluginPreferences(pluginId, preferenceKey, preferenceNewValue, isLoaded)
102 preferenceItemListModel.reset()
103 }
104
105 MessageBox{
106 id: uninstallPluginMessageBox
107
108 title:qsTr("Uninstall plugin")
109 text :qsTr("Are you sure you wish to uninstall " + pluginName + " ?")
110 standardButtons: StandardButton.Ok | StandardButton.Cancel
111
112 onYes: {
113 accepted()
114 }
115
116 onNo:{
117 rejected()
118 }
119
120 onDiscard: {
121 rejected()
122 }
123
124 onAccepted: {
125 uninstallPlugin()
126 pluginListPreferencesViewRect.visible = false
127 }
128
129 onRejected: {}
130 }
131
132 MessageBox{
133 id: resetPluginMessageBox
134
135 title:qsTr("Reset preferences")
136 text :qsTr("Are you sure you wish to reset "+ pluginName + " preferences?")
137
138 standardButtons: StandardButton.Ok | StandardButton.Cancel
139
140 onYes: {
141 accepted()
142 }
143
144 onNo:{
145 rejected()
146 }
147
148 onDiscard: {
149 rejected()
150 }
151
152 onAccepted: {
153 resetPlugin()
154 }
155
156 onRejected: {}
157 }
158
159 MessageBox{
160 id: editListMessageBox
161
162 property string preferenceName: ""
163 property var preferenceEntryValues: []
164
165 title:qsTr("Edit " + preferenceName)
166 text :qsTr(preferenceName + " options: " + preferenceEntryValues)
167
168 standardButtons: StandardButton.Ok | StandardButton.Cancel
169
170 onYes: {
171 accepted()
172 }
173
174 onNo:{
175 rejected()
176 }
177
178 onDiscard: {
179 rejected()
180 }
181
182 onAccepted: {
183 // setPreference(pluginId, preferenceItemDelegate.preferenceKey, preferenceItemDelegate.preferenceNewValue)
184 }
185
186 onRejected: {}
187 }
188
189 PreferenceItemListModel {
190 id: preferenceItemListModel
191 }
192
193 Layout.fillHeight: true
194 Layout.fillWidth: true
195
196 ColumnLayout {
197 spacing: 6
198 Layout.fillHeight: true
199 Layout.maximumWidth: 580
200 Layout.preferredWidth: 580
201 Layout.minimumWidth: 580
202
203 Label{
204 Layout.alignment: Qt.AlignHCenter
205
206 Layout.minimumWidth: 30
207 Layout.preferredWidth: 30
208 Layout.maximumWidth: 30
209 Layout.minimumHeight: 30
210 Layout.preferredHeight: 30
211 Layout.maximumHeight: 30
212
213 background: Rectangle{
214 anchors.fill: parent
215 Image {
216 anchors.fill: parent
217 source: "file:"+pluginIcon
218 }
219 }
220 }
221
222 Label {
223 Layout.alignment: Qt.AlignHCenter
224 Layout.topMargin: 10
225 Layout.fillWidth: true
226 Layout.minimumHeight: 25
227 Layout.preferredHeight: 25
228 Layout.maximumHeight: 25
229
230 text: qsTr(pluginName + "\npreferences")
231 font.pointSize: 13
232 font.kerning: true
233
234 horizontalAlignment: Text.AlignHCenter
235 verticalAlignment: Text.AlignVCenter
236 }
237
238 RowLayout {
239 spacing: 6
240 Layout.fillWidth: true
241 Layout.topMargin: 10
242 Layout.maximumHeight: 30
243 Layout.preferredHeight: 30
244 Layout.minimumHeight: 30
245
246 HoverableRadiusButton {
247 id: resetButton
248
249 Layout.maximumWidth: 157
250 Layout.preferredWidth: 157
251 Layout.minimumWidth: 157
252
253 Layout.fillHeight: true
254
255 radius: height / 2
256
257 icon.source: "qrc:/images/icons/settings_backup_restore-black-18dp.svg"
258 icon.height: 24
259 icon.width: 24
260
261 text: qsTr("Reset")
262 fontPointSize: 10
263 font.kerning: true
264
265 onClicked: {
266 resetPluginSlot()
267 }
268 }
269
270 HoverableRadiusButton {
271 id: uninstallButton
272
273 Layout.maximumWidth: 157
274 Layout.preferredWidth: 157
275 Layout.minimumWidth: 157
276
277 Layout.fillHeight: true
278
279 radius: height / 2
280
281 icon.source: "qrc:/images/icons/ic_delete_black_18dp_2x.png"
282 icon.height: 24
283 icon.width: 24
284
285 text: qsTr("Uninstall")
286 fontPointSize: 10
287 font.kerning: true
288
289 onClicked: {
290 uninstallPluginSlot()
291 }
292 }
293 }
294
295 ListViewJami {
296 id: pluginPreferenceView
297
298 Layout.minimumWidth: 320
299 Layout.preferredWidth: 320
300 Layout.maximumWidth: 320
301
302 Layout.minimumHeight: 0
303 Layout.preferredHeight: height
304 Layout.maximumHeight: 1000
305
306 model: preferenceItemListModel
307
308 delegate: PreferenceItemDelegate{
309 id: preferenceItemDelegate
310
311 width: pluginPreferenceView.width
312 height: 50
313
314 preferenceKey : PreferenceKey
315 preferenceName: PreferenceName
316 preferenceSummary: PreferenceSummary
317 preferenceType: PreferenceType
318 preferenceDefaultValue: PreferenceDefaultValue
319 preferenceEntries: PreferenceEntries
320 preferenceEntryValues: PreferenceEntryValues
321
322 onClicked: {
323 pluginPreferenceView.currentIndex = index
324 }
325 onBtnPreferenceClicked: {
326 console.log("edit preference ", preferenceName)
327 console.log("preference type ", preferenceType)
328 console.log("preference entry values ", preferenceEntryValues.length)
329 editPreferenceSlot(preferenceType, preferenceName, preferenceEntryValues)
330 }
331 }
332 }
333 }
334}