agsantos | 655d8e2 | 2020-08-10 17:36:47 -0400 | [diff] [blame] | 1 | /** |
| 2 | * Copyright (C) 2020 by Savoir-faire Linux |
| 3 | * Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com> |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 4 | * |
| 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 | |
| 19 | import QtQuick 2.15 |
| 20 | import QtQuick.Window 2.14 |
| 21 | import QtQuick.Controls 2.14 |
| 22 | import QtQuick.Controls.Universal 2.12 |
| 23 | import QtQuick.Layouts 1.3 |
| 24 | import Qt.labs.platform 1.1 |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 25 | import QtQuick.Dialogs 1.3 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 26 | import QtGraphicalEffects 1.14 |
| 27 | import net.jami.Models 1.0 |
| 28 | import "../../commoncomponents" |
| 29 | |
| 30 | Rectangle { |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 31 | id: root |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 32 | |
| 33 | enum Type { |
| 34 | LIST, |
agsantos | 90a1dbc | 2020-09-01 18:19:22 -0400 | [diff] [blame^] | 35 | PATH, |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 36 | DEFAULT |
| 37 | } |
| 38 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 39 | property string pluginName: "" |
| 40 | property string pluginIcon: "" |
| 41 | property string pluginId: "" |
| 42 | property bool isLoaded: false |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 43 | |
| 44 | visible: false |
| 45 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 46 | function resetPluginSlot(){ |
| 47 | resetPluginMessageBox.open() |
| 48 | } |
| 49 | |
| 50 | function resetPlugin(){ |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 51 | 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 | } |
agsantos | 90a1dbc | 2020-09-01 18:19:22 -0400 | [diff] [blame^] | 58 | pluginPreferenceView.model = PluginAdapter.getPluginPreferencesModel(pluginId) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | function uninstallPluginSlot(){ |
| 62 | uninstallPluginMessageBox.open() |
| 63 | } |
| 64 | |
| 65 | function uninstallPlugin(){ |
| 66 | ClientWrapper.pluginModel.uninstallPlugin(pluginId) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 67 | } |
| 68 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 69 | function setPreference(pluginId, preferenceKey, preferenceNewValue) |
| 70 | { |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 71 | 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 Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 79 | } |
| 80 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 81 | MessageDialog{ |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 82 | id: uninstallPluginMessageBox |
| 83 | |
| 84 | title:qsTr("Uninstall plugin") |
| 85 | text :qsTr("Are you sure you wish to uninstall " + pluginName + " ?") |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 86 | icon: StandardIcon.Warning |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 87 | standardButtons: StandardButton.Ok | StandardButton.Cancel |
| 88 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 89 | onAccepted: { |
| 90 | uninstallPlugin() |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 91 | root.visible = false |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 92 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 93 | } |
| 94 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 95 | MessageDialog{ |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 96 | id: resetPluginMessageBox |
| 97 | |
| 98 | title:qsTr("Reset preferences") |
| 99 | text :qsTr("Are you sure you wish to reset "+ pluginName + " preferences?") |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 100 | icon: StandardIcon.Warning |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 101 | standardButtons: StandardButton.Ok | StandardButton.Cancel |
| 102 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 103 | onAccepted: resetPlugin() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 104 | } |
| 105 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 106 | ColumnLayout { |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 107 | anchors.left: root.left |
| 108 | anchors.right: root.right |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 109 | |
| 110 | Label{ |
| 111 | Layout.alignment: Qt.AlignHCenter |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 112 | background: Rectangle{ |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 113 | Image { |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 114 | anchors.centerIn: parent |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 115 | source: "file:"+pluginIcon |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 116 | height: 35 |
| 117 | width: 35 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | } |
| 121 | |
| 122 | Label { |
| 123 | Layout.alignment: Qt.AlignHCenter |
| 124 | Layout.topMargin: 10 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 125 | |
| 126 | text: qsTr(pluginName + "\npreferences") |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 127 | font.pointSize: JamiTheme.headerFontSize |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 128 | font.kerning: true |
| 129 | |
| 130 | horizontalAlignment: Text.AlignHCenter |
| 131 | verticalAlignment: Text.AlignVCenter |
| 132 | } |
| 133 | |
| 134 | RowLayout { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 135 | Layout.topMargin: 10 |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 136 | height: 30 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 137 | |
| 138 | HoverableRadiusButton { |
| 139 | id: resetButton |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 140 | Layout.fillWidth: true |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 141 | |
| 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 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 148 | text: qsTr(" Reset ") |
| 149 | fontPointSize: JamiTheme.settingsFontSize |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 150 | font.kerning: true |
| 151 | |
| 152 | onClicked: { |
| 153 | resetPluginSlot() |
| 154 | } |
| 155 | } |
| 156 | |
| 157 | HoverableRadiusButton { |
| 158 | id: uninstallButton |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 159 | Layout.fillWidth: true |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 160 | |
| 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") |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 168 | fontPointSize: JamiTheme.settingsFontSize |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 169 | font.kerning: true |
| 170 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 171 | onClicked: uninstallPluginSlot() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 172 | } |
| 173 | } |
| 174 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 175 | ListView { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 176 | id: pluginPreferenceView |
| 177 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 178 | Layout.fillWidth: true |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 179 | Layout.minimumHeight: 0 |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 180 | Layout.preferredHeight: childrenRect.height + 30 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 181 | |
agsantos | 90a1dbc | 2020-09-01 18:19:22 -0400 | [diff] [blame^] | 182 | model: PluginAdapter.getPluginPreferencesModel(pluginId) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 183 | |
| 184 | delegate: PreferenceItemDelegate{ |
| 185 | id: preferenceItemDelegate |
| 186 | |
| 187 | width: pluginPreferenceView.width |
agsantos | 90a1dbc | 2020-09-01 18:19:22 -0400 | [diff] [blame^] | 188 | height: childrenRect.height |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 189 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 190 | preferenceName: PreferenceName |
| 191 | preferenceSummary: PreferenceSummary |
| 192 | preferenceType: PreferenceType |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 193 | preferenceCurrentValue: PreferenceCurrentValue |
| 194 | pluginId: PluginId |
agsantos | 90a1dbc | 2020-09-01 18:19:22 -0400 | [diff] [blame^] | 195 | currentPath: CurrentPath |
| 196 | preferenceKey: PreferenceKey |
| 197 | fileFilters: FileFilters |
| 198 | isImage: IsImage |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 199 | pluginListPreferenceModel: PluginListPreferenceModel{ |
| 200 | id: pluginListPreferenceModel |
| 201 | preferenceKey : PreferenceKey |
| 202 | pluginId: PluginId |
| 203 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 204 | |
| 205 | onClicked: { |
| 206 | pluginPreferenceView.currentIndex = index |
| 207 | } |
| 208 | onBtnPreferenceClicked: { |
agsantos | 90a1dbc | 2020-09-01 18:19:22 -0400 | [diff] [blame^] | 209 | setPreference(pluginId, preferenceKey, preferenceNewValue) |
| 210 | pluginPreferenceView.model = PluginAdapter.getPluginPreferencesModel(pluginId) |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 211 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | } |
| 215 | } |