blob: 9d0eb1cf1f94eff3c08973257be3597b5655025a [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,
agsantos90a1dbc2020-09-01 18:19:22 -040035 PATH,
Sébastien Blin1f915762020-08-03 13:27:42 -040036 DEFAULT
37 }
38
Sébastien Blin1f915762020-08-03 13:27:42 -040039 property string pluginName: ""
40 property string pluginIcon: ""
41 property string pluginId: ""
42 property bool isLoaded: false
Sébastien Blin1f915762020-08-03 13:27:42 -040043
44 visible: false
45
Sébastien Blin1f915762020-08-03 13:27:42 -040046 function resetPluginSlot(){
47 resetPluginMessageBox.open()
48 }
49
50 function resetPlugin(){
agsantos78726ec2020-08-18 17:41:05 -040051 if (isLoaded){
52 ClientWrapper.pluginModel.unloadPlugin(pluginId)
53 ClientWrapper.pluginModel.resetPluginPreferencesValues(pluginId)
54 ClientWrapper.pluginModel.loadPlugin(pluginId)
55 } else {
56 ClientWrapper.pluginModel.resetPluginPreferencesValues(pluginId)
57 }
agsantos90a1dbc2020-09-01 18:19:22 -040058 pluginPreferenceView.model = PluginAdapter.getPluginPreferencesModel(pluginId)
Sébastien Blin1f915762020-08-03 13:27:42 -040059 }
60
61 function uninstallPluginSlot(){
62 uninstallPluginMessageBox.open()
63 }
64
65 function uninstallPlugin(){
66 ClientWrapper.pluginModel.uninstallPlugin(pluginId)
Sébastien Blin1f915762020-08-03 13:27:42 -040067 }
68
Sébastien Blin1f915762020-08-03 13:27:42 -040069 function setPreference(pluginId, preferenceKey, preferenceNewValue)
70 {
agsantos78726ec2020-08-18 17:41:05 -040071 if (isLoaded){
72 ClientWrapper.pluginModel.unloadPlugin(pluginId)
73 ClientWrapper.pluginModel.setPluginPreference(pluginId, preferenceKey, preferenceNewValue)
74 ClientWrapper.pluginModel.loadPlugin(pluginId)
75 }
76 else {
77 ClientWrapper.pluginModel.setPluginPreference(pluginId, preferenceKey, preferenceNewValue)
78 }
Sébastien Blin1f915762020-08-03 13:27:42 -040079 }
80
agsantos78726ec2020-08-18 17:41:05 -040081 MessageDialog{
Sébastien Blin1f915762020-08-03 13:27:42 -040082 id: uninstallPluginMessageBox
83
84 title:qsTr("Uninstall plugin")
85 text :qsTr("Are you sure you wish to uninstall " + pluginName + " ?")
agsantos78726ec2020-08-18 17:41:05 -040086 icon: StandardIcon.Warning
Sébastien Blin1f915762020-08-03 13:27:42 -040087 standardButtons: StandardButton.Ok | StandardButton.Cancel
88
Sébastien Blin1f915762020-08-03 13:27:42 -040089 onAccepted: {
90 uninstallPlugin()
agsantos78726ec2020-08-18 17:41:05 -040091 root.visible = false
Sébastien Blin1f915762020-08-03 13:27:42 -040092 }
Sébastien Blin1f915762020-08-03 13:27:42 -040093 }
94
agsantos78726ec2020-08-18 17:41:05 -040095 MessageDialog{
Sébastien Blin1f915762020-08-03 13:27:42 -040096 id: resetPluginMessageBox
97
98 title:qsTr("Reset preferences")
99 text :qsTr("Are you sure you wish to reset "+ pluginName + " preferences?")
agsantos78726ec2020-08-18 17:41:05 -0400100 icon: StandardIcon.Warning
Sébastien Blin1f915762020-08-03 13:27:42 -0400101 standardButtons: StandardButton.Ok | StandardButton.Cancel
102
agsantos78726ec2020-08-18 17:41:05 -0400103 onAccepted: resetPlugin()
Sébastien Blin1f915762020-08-03 13:27:42 -0400104 }
105
Sébastien Blin1f915762020-08-03 13:27:42 -0400106 ColumnLayout {
agsantos78726ec2020-08-18 17:41:05 -0400107 anchors.left: root.left
108 anchors.right: root.right
Sébastien Blin1f915762020-08-03 13:27:42 -0400109
110 Label{
111 Layout.alignment: Qt.AlignHCenter
Sébastien Blin1f915762020-08-03 13:27:42 -0400112 background: Rectangle{
Sébastien Blin1f915762020-08-03 13:27:42 -0400113 Image {
agsantos78726ec2020-08-18 17:41:05 -0400114 anchors.centerIn: parent
Sébastien Blin1f915762020-08-03 13:27:42 -0400115 source: "file:"+pluginIcon
agsantos78726ec2020-08-18 17:41:05 -0400116 height: 35
117 width: 35
Sébastien Blin1f915762020-08-03 13:27:42 -0400118 }
119 }
120 }
121
122 Label {
123 Layout.alignment: Qt.AlignHCenter
124 Layout.topMargin: 10
Sébastien Blin1f915762020-08-03 13:27:42 -0400125
126 text: qsTr(pluginName + "\npreferences")
agsantos78726ec2020-08-18 17:41:05 -0400127 font.pointSize: JamiTheme.headerFontSize
Sébastien Blin1f915762020-08-03 13:27:42 -0400128 font.kerning: true
129
130 horizontalAlignment: Text.AlignHCenter
131 verticalAlignment: Text.AlignVCenter
132 }
133
134 RowLayout {
Sébastien Blin1f915762020-08-03 13:27:42 -0400135 Layout.topMargin: 10
agsantos78726ec2020-08-18 17:41:05 -0400136 height: 30
Sébastien Blin1f915762020-08-03 13:27:42 -0400137
138 HoverableRadiusButton {
139 id: resetButton
agsantos78726ec2020-08-18 17:41:05 -0400140 Layout.fillWidth: true
Sébastien Blin1f915762020-08-03 13:27:42 -0400141
142 radius: height / 2
143
144 icon.source: "qrc:/images/icons/settings_backup_restore-black-18dp.svg"
145 icon.height: 24
146 icon.width: 24
147
agsantos78726ec2020-08-18 17:41:05 -0400148 text: qsTr(" Reset ")
149 fontPointSize: JamiTheme.settingsFontSize
Sébastien Blin1f915762020-08-03 13:27:42 -0400150 font.kerning: true
151
152 onClicked: {
153 resetPluginSlot()
154 }
155 }
156
157 HoverableRadiusButton {
158 id: uninstallButton
agsantos78726ec2020-08-18 17:41:05 -0400159 Layout.fillWidth: true
Sébastien Blin1f915762020-08-03 13:27:42 -0400160
161 radius: height / 2
162
163 icon.source: "qrc:/images/icons/ic_delete_black_18dp_2x.png"
164 icon.height: 24
165 icon.width: 24
166
167 text: qsTr("Uninstall")
agsantos78726ec2020-08-18 17:41:05 -0400168 fontPointSize: JamiTheme.settingsFontSize
Sébastien Blin1f915762020-08-03 13:27:42 -0400169 font.kerning: true
170
agsantos78726ec2020-08-18 17:41:05 -0400171 onClicked: uninstallPluginSlot()
Sébastien Blin1f915762020-08-03 13:27:42 -0400172 }
173 }
174
agsantos78726ec2020-08-18 17:41:05 -0400175 ListView {
Sébastien Blin1f915762020-08-03 13:27:42 -0400176 id: pluginPreferenceView
177
agsantos78726ec2020-08-18 17:41:05 -0400178 Layout.fillWidth: true
Sébastien Blin1f915762020-08-03 13:27:42 -0400179 Layout.minimumHeight: 0
agsantos78726ec2020-08-18 17:41:05 -0400180 Layout.preferredHeight: childrenRect.height + 30
Sébastien Blin1f915762020-08-03 13:27:42 -0400181
agsantos90a1dbc2020-09-01 18:19:22 -0400182 model: PluginAdapter.getPluginPreferencesModel(pluginId)
Sébastien Blin1f915762020-08-03 13:27:42 -0400183
184 delegate: PreferenceItemDelegate{
185 id: preferenceItemDelegate
186
187 width: pluginPreferenceView.width
agsantos90a1dbc2020-09-01 18:19:22 -0400188 height: childrenRect.height
Sébastien Blin1f915762020-08-03 13:27:42 -0400189
Sébastien Blin1f915762020-08-03 13:27:42 -0400190 preferenceName: PreferenceName
191 preferenceSummary: PreferenceSummary
192 preferenceType: PreferenceType
agsantos78726ec2020-08-18 17:41:05 -0400193 preferenceCurrentValue: PreferenceCurrentValue
194 pluginId: PluginId
agsantos90a1dbc2020-09-01 18:19:22 -0400195 currentPath: CurrentPath
196 preferenceKey: PreferenceKey
197 fileFilters: FileFilters
198 isImage: IsImage
agsantos78726ec2020-08-18 17:41:05 -0400199 pluginListPreferenceModel: PluginListPreferenceModel{
200 id: pluginListPreferenceModel
201 preferenceKey : PreferenceKey
202 pluginId: PluginId
203 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400204
205 onClicked: {
206 pluginPreferenceView.currentIndex = index
207 }
208 onBtnPreferenceClicked: {
agsantos90a1dbc2020-09-01 18:19:22 -0400209 setPreference(pluginId, preferenceKey, preferenceNewValue)
210 pluginPreferenceView.model = PluginAdapter.getPluginPreferencesModel(pluginId)
Sébastien Blin1f915762020-08-03 13:27:42 -0400211 }
Sébastien Blin1f915762020-08-03 13:27:42 -0400212 }
213 }
214 }
215}