blob: 256749a6eed0aa2ef38718a13d3be75d92d2e68e [file] [log] [blame]
Sébastien Blin1f915762020-08-03 13:27:42 -04001/*
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
19import QtQuick 2.15
20import QtQuick.Window 2.15
21import QtQuick.Controls 2.15
22import QtQuick.Controls.Universal 2.12
23import QtQuick.Layouts 1.3
24import QtGraphicalEffects 1.14
25import QtQuick.Controls.Styles 1.4
26import net.jami.Models 1.0
27
28import "../../commoncomponents"
29
30ItemDelegate {
agsantos78726ec2020-08-18 17:41:05 -040031 id: root
Sébastien Blin1f915762020-08-03 13:27:42 -040032
agsantos78726ec2020-08-18 17:41:05 -040033 enum Type {
34 LIST,
35 USERLIST,
36 DEFAULT
37 }
38
Sébastien Blin1f915762020-08-03 13:27:42 -040039 property string preferenceName: ""
40 property string preferenceSummary: ""
41 property int preferenceType: -1
agsantos78726ec2020-08-18 17:41:05 -040042 property string preferenceCurrentValue: ""
Sébastien Blin1f915762020-08-03 13:27:42 -040043 property string preferenceNewValue: ""
agsantos78726ec2020-08-18 17:41:05 -040044 property string pluginId: ""
45 property PluginListPreferenceModel pluginListPreferenceModel
Sébastien Blin1f915762020-08-03 13:27:42 -040046
47 signal btnPreferenceClicked
agsantos78726ec2020-08-18 17:41:05 -040048 signal preferenceAdded
Sébastien Blin1f915762020-08-03 13:27:42 -040049
agsantos78726ec2020-08-18 17:41:05 -040050 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 Blin1f915762020-08-03 13:27:42 -040093
94 RowLayout{
95 anchors.fill: parent
96
agsantos78726ec2020-08-18 17:41:05 -040097 Label{
98 visible: preferenceType === PreferenceItemDelegate.DEFAULT
Sébastien Blin1f915762020-08-03 13:27:42 -040099 Layout.fillWidth: true
agsantos78726ec2020-08-18 17:41:05 -0400100 Layout.alignment: Qt.AlingVCenter | Qt.AligntLeft
101 Layout.leftMargin: 8
Sébastien Blin1f915762020-08-03 13:27:42 -0400102
agsantos78726ec2020-08-18 17:41:05 -0400103 font.pointSize: JamiTheme.settingsFontSize
104 font.kerning: true
105 font.bold: true
106 text: pluginName === "" ? pluginId : pluginName
Sébastien Blin1f915762020-08-03 13:27:42 -0400107 }
108
109 HoverableRadiusButton{
110 id: btnPreference
agsantos78726ec2020-08-18 17:41:05 -0400111 visible: preferenceType === PreferenceItemDelegate.DEFAULT
112 backgroundColor: "white"
Sébastien Blin1f915762020-08-03 13:27:42 -0400113
agsantos78726ec2020-08-18 17:41:05 -0400114 Layout.alignment: Qt.AlignRight | Qt.AlingVCenter
Sébastien Blin1f915762020-08-03 13:27:42 -0400115 Layout.rightMargin: 7
Sébastien Blin1f915762020-08-03 13:27:42 -0400116 Layout.preferredWidth: 30
Sébastien Blin1f915762020-08-03 13:27:42 -0400117 Layout.preferredHeight: 30
Sébastien Blin1f915762020-08-03 13:27:42 -0400118
agsantos78726ec2020-08-18 17:41:05 -0400119 buttonImageHeight: 20
120 buttonImageWidth: 20
Sébastien Blin1f915762020-08-03 13:27:42 -0400121
122 source:{
123 return "qrc:/images/icons/round-settings-24px.svg"
124 }
125
agsantos78726ec2020-08-18 17:41:05 -0400126 ToolTip.visible: hovered
Sébastien Blin1f915762020-08-03 13:27:42 -0400127 ToolTip.text: {
agsantos78726ec2020-08-18 17:41:05 -0400128 return qsTr("Edit preference")
Sébastien Blin1f915762020-08-03 13:27:42 -0400129 }
130
131 onClicked: {
132 btnPreferenceClicked()
133 }
134 }
agsantos78726ec2020-08-18 17:41:05 -0400135
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 Blin1f915762020-08-03 13:27:42 -0400199 }
200}