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 |
| 25 | import QtGraphicalEffects 1.14 |
| 26 | import net.jami.Models 1.0 |
| 27 | import "../../commoncomponents" |
| 28 | |
| 29 | Rectangle { |
| 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) { |
agsantos | 655d8e2 | 2020-08-10 17:36:47 -0400 | [diff] [blame^] | 75 | height = 200 + size |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 76 | 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 | } |