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 | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 35 | USERLIST, |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 36 | 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 Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 45 | |
| 46 | visible: false |
| 47 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 48 | function updatePreferenceListDisplayed(){ |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 49 | // settings |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 50 | preferenceItemListModel.pluginId = pluginId |
| 51 | preferenceItemListModel.reset() |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 52 | var size = 50 * preferenceItemListModel.preferencesCount |
| 53 | pluginPreferenceView.height = size |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | function resetPluginSlot(){ |
| 57 | resetPluginMessageBox.open() |
| 58 | } |
| 59 | |
| 60 | function resetPlugin(){ |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 61 | 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 Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 68 | updatePluginList() |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 69 | updatePreferenceListDisplayed() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 70 | } |
| 71 | |
| 72 | function uninstallPluginSlot(){ |
| 73 | uninstallPluginMessageBox.open() |
| 74 | } |
| 75 | |
| 76 | function uninstallPlugin(){ |
| 77 | ClientWrapper.pluginModel.uninstallPlugin(pluginId) |
| 78 | updatePluginList() |
| 79 | } |
| 80 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 81 | function setPreference(pluginId, preferenceKey, preferenceNewValue) |
| 82 | { |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 83 | 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 Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 91 | } |
| 92 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 93 | MessageDialog{ |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 94 | id: uninstallPluginMessageBox |
| 95 | |
| 96 | title:qsTr("Uninstall plugin") |
| 97 | text :qsTr("Are you sure you wish to uninstall " + pluginName + " ?") |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 98 | icon: StandardIcon.Warning |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 99 | standardButtons: StandardButton.Ok | StandardButton.Cancel |
| 100 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 101 | onAccepted: { |
| 102 | uninstallPlugin() |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 103 | root.visible = false |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 104 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 105 | } |
| 106 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 107 | MessageDialog{ |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 108 | id: resetPluginMessageBox |
| 109 | |
| 110 | title:qsTr("Reset preferences") |
| 111 | text :qsTr("Are you sure you wish to reset "+ pluginName + " preferences?") |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 112 | icon: StandardIcon.Warning |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 113 | standardButtons: StandardButton.Ok | StandardButton.Cancel |
| 114 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 115 | onAccepted: resetPlugin() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | PreferenceItemListModel { |
| 119 | id: preferenceItemListModel |
| 120 | } |
| 121 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 122 | ColumnLayout { |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 123 | anchors.left: root.left |
| 124 | anchors.right: root.right |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 125 | |
| 126 | Label{ |
| 127 | Layout.alignment: Qt.AlignHCenter |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 128 | background: Rectangle{ |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 129 | Image { |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 130 | anchors.centerIn: parent |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 131 | source: "file:"+pluginIcon |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 132 | height: 35 |
| 133 | width: 35 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 134 | } |
| 135 | } |
| 136 | } |
| 137 | |
| 138 | Label { |
| 139 | Layout.alignment: Qt.AlignHCenter |
| 140 | Layout.topMargin: 10 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 141 | |
| 142 | text: qsTr(pluginName + "\npreferences") |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 143 | font.pointSize: JamiTheme.headerFontSize |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 144 | font.kerning: true |
| 145 | |
| 146 | horizontalAlignment: Text.AlignHCenter |
| 147 | verticalAlignment: Text.AlignVCenter |
| 148 | } |
| 149 | |
| 150 | RowLayout { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 151 | Layout.topMargin: 10 |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 152 | height: 30 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 153 | |
| 154 | HoverableRadiusButton { |
| 155 | id: resetButton |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 156 | Layout.fillWidth: true |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 157 | |
| 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 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 164 | text: qsTr(" Reset ") |
| 165 | fontPointSize: JamiTheme.settingsFontSize |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 166 | font.kerning: true |
| 167 | |
| 168 | onClicked: { |
| 169 | resetPluginSlot() |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | HoverableRadiusButton { |
| 174 | id: uninstallButton |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 175 | Layout.fillWidth: true |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 176 | |
| 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") |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 184 | fontPointSize: JamiTheme.settingsFontSize |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 185 | font.kerning: true |
| 186 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 187 | onClicked: uninstallPluginSlot() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 188 | } |
| 189 | } |
| 190 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 191 | ListView { |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 192 | id: pluginPreferenceView |
| 193 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 194 | Layout.fillWidth: true |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 195 | Layout.minimumHeight: 0 |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 196 | Layout.preferredHeight: childrenRect.height + 30 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 197 | |
| 198 | model: preferenceItemListModel |
| 199 | |
| 200 | delegate: PreferenceItemDelegate{ |
| 201 | id: preferenceItemDelegate |
| 202 | |
| 203 | width: pluginPreferenceView.width |
| 204 | height: 50 |
| 205 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 206 | preferenceName: PreferenceName |
| 207 | preferenceSummary: PreferenceSummary |
| 208 | preferenceType: PreferenceType |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 209 | preferenceCurrentValue: PreferenceCurrentValue |
| 210 | pluginId: PluginId |
| 211 | pluginListPreferenceModel: PluginListPreferenceModel{ |
| 212 | id: pluginListPreferenceModel |
| 213 | preferenceKey : PreferenceKey |
| 214 | pluginId: PluginId |
| 215 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 216 | |
| 217 | onClicked: { |
| 218 | pluginPreferenceView.currentIndex = index |
| 219 | } |
| 220 | onBtnPreferenceClicked: { |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 221 | setPreference(pluginListPreferenceModel.pluginId, |
| 222 | pluginListPreferenceModel.preferenceKey, |
| 223 | pluginListPreferenceModel.preferenceNewValue) |
| 224 | updatePreferenceListDisplayed() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 225 | } |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 226 | onPreferenceAdded: preferenceItemListModel.reset() |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 227 | } |
| 228 | } |
| 229 | } |
| 230 | } |