blob: 6e3f58433f24f8d01d5946b0d84208b7ffad641d [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
agsantos78726ec2020-08-18 17:41:05 -040025import QtQuick.Dialogs 1.3
Sébastien Blin1f915762020-08-03 13:27:42 -040026import QtGraphicalEffects 1.14
27import net.jami.Models 1.0
28import "../../commoncomponents"
29
30Rectangle {
agsantos78726ec2020-08-18 17:41:05 -040031 id: root
Sébastien Blin1f915762020-08-03 13:27:42 -040032
33 enum Type {
34 LIST,
agsantos78726ec2020-08-18 17:41:05 -040035 USERLIST,
Sébastien Blin1f915762020-08-03 13:27:42 -040036 DEFAULT
37 }
38
39 signal updatePluginList
40
41 property string pluginName: ""
42 property string pluginIcon: ""
43 property string pluginId: ""
44 property bool isLoaded: false
Sébastien Blin1f915762020-08-03 13:27:42 -040045
46 visible: false
47
agsantos78726ec2020-08-18 17:41:05 -040048 function updatePreferenceListDisplayed(){
Sébastien Blin1f915762020-08-03 13:27:42 -040049 // settings
Sébastien Blin1f915762020-08-03 13:27:42 -040050 preferenceItemListModel.pluginId = pluginId
51 preferenceItemListModel.reset()
agsantos78726ec2020-08-18 17:41:05 -040052 var size = 50 * preferenceItemListModel.preferencesCount
53 pluginPreferenceView.height = size
Sébastien Blin1f915762020-08-03 13:27:42 -040054 }
55
56 function resetPluginSlot(){
57 resetPluginMessageBox.open()
58 }
59
60 function resetPlugin(){
agsantos78726ec2020-08-18 17:41:05 -040061 if (isLoaded){
62 ClientWrapper.pluginModel.unloadPlugin(pluginId)
63 ClientWrapper.pluginModel.resetPluginPreferencesValues(pluginId)
64 ClientWrapper.pluginModel.loadPlugin(pluginId)
65 } else {
66 ClientWrapper.pluginModel.resetPluginPreferencesValues(pluginId)
67 }
Sébastien Blin1f915762020-08-03 13:27:42 -040068 updatePluginList()
agsantos78726ec2020-08-18 17:41:05 -040069 updatePreferenceListDisplayed()
Sébastien Blin1f915762020-08-03 13:27:42 -040070 }
71
72 function uninstallPluginSlot(){
73 uninstallPluginMessageBox.open()
74 }
75
76 function uninstallPlugin(){
77 ClientWrapper.pluginModel.uninstallPlugin(pluginId)
78 updatePluginList()
79 }
80
Sébastien Blin1f915762020-08-03 13:27:42 -040081 function setPreference(pluginId, preferenceKey, preferenceNewValue)
82 {
agsantos78726ec2020-08-18 17:41:05 -040083 if (isLoaded){
84 ClientWrapper.pluginModel.unloadPlugin(pluginId)
85 ClientWrapper.pluginModel.setPluginPreference(pluginId, preferenceKey, preferenceNewValue)
86 ClientWrapper.pluginModel.loadPlugin(pluginId)
87 }
88 else {
89 ClientWrapper.pluginModel.setPluginPreference(pluginId, preferenceKey, preferenceNewValue)
90 }
Sébastien Blin1f915762020-08-03 13:27:42 -040091 }
92
agsantos78726ec2020-08-18 17:41:05 -040093 MessageDialog{
Sébastien Blin1f915762020-08-03 13:27:42 -040094 id: uninstallPluginMessageBox
95
96 title:qsTr("Uninstall plugin")
97 text :qsTr("Are you sure you wish to uninstall " + pluginName + " ?")
agsantos78726ec2020-08-18 17:41:05 -040098 icon: StandardIcon.Warning
Sébastien Blin1f915762020-08-03 13:27:42 -040099 standardButtons: StandardButton.Ok | StandardButton.Cancel
100
Sébastien Blin1f915762020-08-03 13:27:42 -0400101 onAccepted: {
102 uninstallPlugin()
agsantos78726ec2020-08-18 17:41:05 -0400103 root.visible = false
Sébastien Blin1f915762020-08-03 13:27:42 -0400104 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400105 }
106
agsantos78726ec2020-08-18 17:41:05 -0400107 MessageDialog{
Sébastien Blin1f915762020-08-03 13:27:42 -0400108 id: resetPluginMessageBox
109
110 title:qsTr("Reset preferences")
111 text :qsTr("Are you sure you wish to reset "+ pluginName + " preferences?")
agsantos78726ec2020-08-18 17:41:05 -0400112 icon: StandardIcon.Warning
Sébastien Blin1f915762020-08-03 13:27:42 -0400113 standardButtons: StandardButton.Ok | StandardButton.Cancel
114
agsantos78726ec2020-08-18 17:41:05 -0400115 onAccepted: resetPlugin()
Sébastien Blin1f915762020-08-03 13:27:42 -0400116 }
117
118 PreferenceItemListModel {
119 id: preferenceItemListModel
120 }
121
Sébastien Blin1f915762020-08-03 13:27:42 -0400122 ColumnLayout {
agsantos78726ec2020-08-18 17:41:05 -0400123 anchors.left: root.left
124 anchors.right: root.right
Sébastien Blin1f915762020-08-03 13:27:42 -0400125
126 Label{
127 Layout.alignment: Qt.AlignHCenter
Sébastien Blin1f915762020-08-03 13:27:42 -0400128 background: Rectangle{
Sébastien Blin1f915762020-08-03 13:27:42 -0400129 Image {
agsantos78726ec2020-08-18 17:41:05 -0400130 anchors.centerIn: parent
Sébastien Blin1f915762020-08-03 13:27:42 -0400131 source: "file:"+pluginIcon
agsantos78726ec2020-08-18 17:41:05 -0400132 height: 35
133 width: 35
Sébastien Blin1f915762020-08-03 13:27:42 -0400134 }
135 }
136 }
137
138 Label {
139 Layout.alignment: Qt.AlignHCenter
140 Layout.topMargin: 10
Sébastien Blin1f915762020-08-03 13:27:42 -0400141
142 text: qsTr(pluginName + "\npreferences")
agsantos78726ec2020-08-18 17:41:05 -0400143 font.pointSize: JamiTheme.headerFontSize
Sébastien Blin1f915762020-08-03 13:27:42 -0400144 font.kerning: true
145
146 horizontalAlignment: Text.AlignHCenter
147 verticalAlignment: Text.AlignVCenter
148 }
149
150 RowLayout {
Sébastien Blin1f915762020-08-03 13:27:42 -0400151 Layout.topMargin: 10
agsantos78726ec2020-08-18 17:41:05 -0400152 height: 30
Sébastien Blin1f915762020-08-03 13:27:42 -0400153
154 HoverableRadiusButton {
155 id: resetButton
agsantos78726ec2020-08-18 17:41:05 -0400156 Layout.fillWidth: true
Sébastien Blin1f915762020-08-03 13:27:42 -0400157
158 radius: height / 2
159
160 icon.source: "qrc:/images/icons/settings_backup_restore-black-18dp.svg"
161 icon.height: 24
162 icon.width: 24
163
agsantos78726ec2020-08-18 17:41:05 -0400164 text: qsTr(" Reset ")
165 fontPointSize: JamiTheme.settingsFontSize
Sébastien Blin1f915762020-08-03 13:27:42 -0400166 font.kerning: true
167
168 onClicked: {
169 resetPluginSlot()
170 }
171 }
172
173 HoverableRadiusButton {
174 id: uninstallButton
agsantos78726ec2020-08-18 17:41:05 -0400175 Layout.fillWidth: true
Sébastien Blin1f915762020-08-03 13:27:42 -0400176
177 radius: height / 2
178
179 icon.source: "qrc:/images/icons/ic_delete_black_18dp_2x.png"
180 icon.height: 24
181 icon.width: 24
182
183 text: qsTr("Uninstall")
agsantos78726ec2020-08-18 17:41:05 -0400184 fontPointSize: JamiTheme.settingsFontSize
Sébastien Blin1f915762020-08-03 13:27:42 -0400185 font.kerning: true
186
agsantos78726ec2020-08-18 17:41:05 -0400187 onClicked: uninstallPluginSlot()
Sébastien Blin1f915762020-08-03 13:27:42 -0400188 }
189 }
190
agsantos78726ec2020-08-18 17:41:05 -0400191 ListView {
Sébastien Blin1f915762020-08-03 13:27:42 -0400192 id: pluginPreferenceView
193
agsantos78726ec2020-08-18 17:41:05 -0400194 Layout.fillWidth: true
Sébastien Blin1f915762020-08-03 13:27:42 -0400195 Layout.minimumHeight: 0
agsantos78726ec2020-08-18 17:41:05 -0400196 Layout.preferredHeight: childrenRect.height + 30
Sébastien Blin1f915762020-08-03 13:27:42 -0400197
198 model: preferenceItemListModel
199
200 delegate: PreferenceItemDelegate{
201 id: preferenceItemDelegate
202
203 width: pluginPreferenceView.width
204 height: 50
205
Sébastien Blin1f915762020-08-03 13:27:42 -0400206 preferenceName: PreferenceName
207 preferenceSummary: PreferenceSummary
208 preferenceType: PreferenceType
agsantos78726ec2020-08-18 17:41:05 -0400209 preferenceCurrentValue: PreferenceCurrentValue
210 pluginId: PluginId
211 pluginListPreferenceModel: PluginListPreferenceModel{
212 id: pluginListPreferenceModel
213 preferenceKey : PreferenceKey
214 pluginId: PluginId
215 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400216
217 onClicked: {
218 pluginPreferenceView.currentIndex = index
219 }
220 onBtnPreferenceClicked: {
agsantos78726ec2020-08-18 17:41:05 -0400221 setPreference(pluginListPreferenceModel.pluginId,
222 pluginListPreferenceModel.preferenceKey,
223 pluginListPreferenceModel.preferenceNewValue)
224 updatePreferenceListDisplayed()
Sébastien Blin1f915762020-08-03 13:27:42 -0400225 }
agsantos78726ec2020-08-18 17:41:05 -0400226 onPreferenceAdded: preferenceItemListModel.reset()
Sébastien Blin1f915762020-08-03 13:27:42 -0400227 }
228 }
229 }
230}