Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2019-2020 by Savoir-faire Linux |
| 3 | * Author: Yang Wang <yang.wang@savoirfairelinux.com> |
| 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.15 |
| 21 | import QtQuick.Controls 2.15 |
| 22 | import QtQuick.Controls.Universal 2.12 |
| 23 | import QtQuick.Layouts 1.3 |
| 24 | import QtGraphicalEffects 1.14 |
| 25 | import QtQuick.Controls.Styles 1.4 |
| 26 | import net.jami.Models 1.0 |
| 27 | |
| 28 | import "../../commoncomponents" |
| 29 | |
| 30 | ItemDelegate { |
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 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 33 | enum Type { |
| 34 | LIST, |
| 35 | USERLIST, |
| 36 | DEFAULT |
| 37 | } |
| 38 | |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 39 | property string preferenceName: "" |
| 40 | property string preferenceSummary: "" |
| 41 | property int preferenceType: -1 |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 42 | property string preferenceCurrentValue: "" |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 43 | property string preferenceNewValue: "" |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 44 | property string pluginId: "" |
| 45 | property PluginListPreferenceModel pluginListPreferenceModel |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 46 | |
| 47 | signal btnPreferenceClicked |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 48 | signal preferenceAdded |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 49 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 50 | function getNewPreferenceValueSlot(index){ |
| 51 | pluginListPreferenceModel.idx = index |
| 52 | preferenceNewValue = pluginListPreferenceModel.preferenceNewValue |
| 53 | switch (preferenceType){ |
| 54 | case PreferenceItemDelegate.LIST: |
| 55 | btnPreferenceClicked() |
| 56 | break |
| 57 | case PreferenceItemDelegate.USERLIST: |
| 58 | if(index == 0){ |
| 59 | preferenceFilePathDialog.pluginListPreferenceModel = pluginListPreferenceModel |
| 60 | preferenceFilePathDialog.title = qsTr("Select An Image to " + preferenceName) |
| 61 | preferenceFilePathDialog.nameFilters = [qsTr("PNG Files") + " (*.png)", qsTr( |
| 62 | "All files") + " (*)"] |
| 63 | preferenceFilePathDialog.preferenceKey = pluginListPreferenceModel.preferenceKey |
| 64 | preferenceFilePathDialog.open() |
| 65 | } |
| 66 | else |
| 67 | btnPreferenceClicked() |
| 68 | break |
| 69 | default: |
| 70 | break |
| 71 | } |
| 72 | } |
| 73 | |
| 74 | JamiFileDialog { |
| 75 | id: preferenceFilePathDialog |
| 76 | |
| 77 | property string preferenceKey: "" |
| 78 | property PluginListPreferenceModel pluginListPreferenceModel |
| 79 | |
| 80 | mode: JamiFileDialog.OpenFile |
| 81 | folder: StandardPaths.writableLocation(StandardPaths.DownloadLocation) |
| 82 | |
| 83 | onRejected: preferenceAdded() |
| 84 | |
| 85 | onAccepted: { |
| 86 | var url = ClientWrapper.utilsAdaptor.getAbsPath(file.toString()) |
| 87 | ClientWrapper.pluginModel.addValueToPreference(pluginId, preferenceKey, url) |
| 88 | pluginListPreferenceModel.populateLists() |
| 89 | pluginListPreferenceModel.getCurrentSettingIndex() |
| 90 | preferenceAdded() |
| 91 | } |
| 92 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 93 | |
| 94 | RowLayout{ |
| 95 | anchors.fill: parent |
| 96 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 97 | Label{ |
| 98 | visible: preferenceType === PreferenceItemDelegate.DEFAULT |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 99 | Layout.fillWidth: true |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 100 | Layout.alignment: Qt.AlingVCenter | Qt.AligntLeft |
| 101 | Layout.leftMargin: 8 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 102 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 103 | font.pointSize: JamiTheme.settingsFontSize |
| 104 | font.kerning: true |
| 105 | font.bold: true |
| 106 | text: pluginName === "" ? pluginId : pluginName |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 107 | } |
| 108 | |
| 109 | HoverableRadiusButton{ |
| 110 | id: btnPreference |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 111 | visible: preferenceType === PreferenceItemDelegate.DEFAULT |
| 112 | backgroundColor: "white" |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 113 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 114 | Layout.alignment: Qt.AlignRight | Qt.AlingVCenter |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 115 | Layout.rightMargin: 7 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 116 | Layout.preferredWidth: 30 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 117 | Layout.preferredHeight: 30 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 118 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 119 | buttonImageHeight: 20 |
| 120 | buttonImageWidth: 20 |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 121 | |
| 122 | source:{ |
| 123 | return "qrc:/images/icons/round-settings-24px.svg" |
| 124 | } |
| 125 | |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 126 | ToolTip.visible: hovered |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 127 | ToolTip.text: { |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 128 | return qsTr("Edit preference") |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | onClicked: { |
| 132 | btnPreferenceClicked() |
| 133 | } |
| 134 | } |
agsantos | 78726ec | 2020-08-18 17:41:05 -0400 | [diff] [blame] | 135 | |
| 136 | Label { |
| 137 | visible: preferenceType === PreferenceItemDelegate.LIST |
| 138 | Layout.preferredWidth: root.width / 2 |
| 139 | Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter |
| 140 | Layout.leftMargin: 8 |
| 141 | |
| 142 | text: preferenceName |
| 143 | font.pointSize: JamiTheme.settingsFontSize |
| 144 | ToolTip.visible: hovered |
| 145 | ToolTip.text: preferenceSummary |
| 146 | } |
| 147 | |
| 148 | |
| 149 | SettingParaCombobox { |
| 150 | id: listPreferenceComboBox |
| 151 | visible: preferenceType === PreferenceItemDelegate.LIST |
| 152 | Layout.preferredWidth: root.width / 2 - 8 |
| 153 | Layout.alignment: Qt.AlignRight | Qt.AlignVCenter |
| 154 | Layout.rightMargin: 8 |
| 155 | |
| 156 | font.pointSize: JamiTheme.settingsFontSize |
| 157 | font.kerning: true |
| 158 | |
| 159 | model: pluginListPreferenceModel |
| 160 | currentIndex: pluginListPreferenceModel.getCurrentSettingIndex() |
| 161 | textRole: qsTr("PreferenceValue") |
| 162 | tooltipText: qsTr("Choose the preference") |
| 163 | onActivated: { |
| 164 | getNewPreferenceValueSlot(index) |
| 165 | } |
| 166 | } |
| 167 | |
| 168 | Label { |
| 169 | visible: preferenceType === PreferenceItemDelegate.USERLIST |
| 170 | Layout.preferredWidth: root.width / 2 |
| 171 | Layout.leftMargin: 8 |
| 172 | Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter |
| 173 | |
| 174 | text: preferenceName |
| 175 | font.pointSize: JamiTheme.settingsFontSize |
| 176 | ToolTip.visible: hovered |
| 177 | ToolTip.text: preferenceSummary |
| 178 | } |
| 179 | |
| 180 | |
| 181 | SettingParaCombobox { |
| 182 | id: userListPreferenceComboBox |
| 183 | visible: preferenceType === PreferenceItemDelegate.USERLIST |
| 184 | Layout.preferredWidth: root.width / 2 - 8 |
| 185 | Layout.alignment: Qt.AlignRight | Qt.AlignVCenter |
| 186 | Layout.rightMargin: 8 |
| 187 | |
| 188 | font.pointSize: JamiTheme.settingsFontSize |
| 189 | font.kerning: true |
| 190 | |
| 191 | model: pluginListPreferenceModel |
| 192 | currentIndex: pluginListPreferenceModel.getCurrentSettingIndex() |
| 193 | textRole: qsTr("PreferenceValue") |
| 194 | tooltipText: qsTr("Choose the preference") |
| 195 | onActivated: { |
| 196 | getNewPreferenceValueSlot(index) |
| 197 | } |
| 198 | } |
Sébastien Blin | 1f91576 | 2020-08-03 13:27:42 -0400 | [diff] [blame] | 199 | } |
| 200 | } |