2020-08-03 13:27:42 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2019-2020 by Savoir-faire Linux
|
|
|
|
* Author: Yang Wang <yang.wang@savoirfairelinux.com>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
import QtQuick 2.15
|
|
|
|
import QtQuick.Window 2.15
|
|
|
|
import QtQuick.Controls 2.15
|
|
|
|
import QtQuick.Controls.Universal 2.12
|
|
|
|
import QtQuick.Layouts 1.3
|
|
|
|
import QtGraphicalEffects 1.14
|
|
|
|
import QtQuick.Controls.Styles 1.4
|
|
|
|
import net.jami.Models 1.0
|
|
|
|
|
|
|
|
import "../../commoncomponents"
|
|
|
|
|
|
|
|
ItemDelegate {
|
2020-08-18 17:41:05 -04:00
|
|
|
id: root
|
|
|
|
|
|
|
|
enum Type {
|
|
|
|
LIST,
|
|
|
|
USERLIST,
|
|
|
|
DEFAULT
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
property string preferenceName: ""
|
|
|
|
property string preferenceSummary: ""
|
|
|
|
property int preferenceType: -1
|
2020-08-18 17:41:05 -04:00
|
|
|
property string preferenceCurrentValue: ""
|
2020-08-03 13:27:42 -04:00
|
|
|
property string preferenceNewValue: ""
|
2020-08-18 17:41:05 -04:00
|
|
|
property string pluginId: ""
|
|
|
|
property PluginListPreferenceModel pluginListPreferenceModel
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
signal btnPreferenceClicked
|
2020-08-18 17:41:05 -04:00
|
|
|
signal preferenceAdded
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-08-18 17:41:05 -04:00
|
|
|
function getNewPreferenceValueSlot(index){
|
|
|
|
pluginListPreferenceModel.idx = index
|
|
|
|
preferenceNewValue = pluginListPreferenceModel.preferenceNewValue
|
|
|
|
switch (preferenceType){
|
|
|
|
case PreferenceItemDelegate.LIST:
|
|
|
|
btnPreferenceClicked()
|
|
|
|
break
|
|
|
|
case PreferenceItemDelegate.USERLIST:
|
|
|
|
if(index == 0){
|
|
|
|
preferenceFilePathDialog.pluginListPreferenceModel = pluginListPreferenceModel
|
|
|
|
preferenceFilePathDialog.title = qsTr("Select An Image to " + preferenceName)
|
|
|
|
preferenceFilePathDialog.nameFilters = [qsTr("PNG Files") + " (*.png)", qsTr(
|
|
|
|
"All files") + " (*)"]
|
|
|
|
preferenceFilePathDialog.preferenceKey = pluginListPreferenceModel.preferenceKey
|
|
|
|
preferenceFilePathDialog.open()
|
|
|
|
}
|
|
|
|
else
|
|
|
|
btnPreferenceClicked()
|
|
|
|
break
|
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-08-18 17:41:05 -04:00
|
|
|
JamiFileDialog {
|
|
|
|
id: preferenceFilePathDialog
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-08-18 17:41:05 -04:00
|
|
|
property string preferenceKey: ""
|
|
|
|
property PluginListPreferenceModel pluginListPreferenceModel
|
|
|
|
|
|
|
|
mode: JamiFileDialog.OpenFile
|
|
|
|
folder: StandardPaths.writableLocation(StandardPaths.DownloadLocation)
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-08-18 17:41:05 -04:00
|
|
|
onRejected: preferenceAdded()
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-08-18 17:41:05 -04:00
|
|
|
onAccepted: {
|
|
|
|
var url = ClientWrapper.utilsAdaptor.getAbsPath(file.toString())
|
|
|
|
ClientWrapper.pluginModel.addValueToPreference(pluginId, preferenceKey, url)
|
|
|
|
pluginListPreferenceModel.populateLists()
|
|
|
|
pluginListPreferenceModel.getCurrentSettingIndex()
|
|
|
|
preferenceAdded()
|
|
|
|
}
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-08-18 17:41:05 -04:00
|
|
|
RowLayout{
|
|
|
|
anchors.fill: parent
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-08-18 17:41:05 -04:00
|
|
|
Label{
|
|
|
|
visible: preferenceType === PreferenceItemDelegate.DEFAULT
|
|
|
|
Layout.fillWidth: true
|
|
|
|
Layout.alignment: Qt.AlingVCenter | Qt.AligntLeft
|
|
|
|
Layout.leftMargin: 8
|
|
|
|
|
|
|
|
font.pointSize: JamiTheme.settingsFontSize
|
|
|
|
font.kerning: true
|
|
|
|
font.bold: true
|
|
|
|
text: pluginName === "" ? pluginId : pluginName
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
HoverableRadiusButton{
|
|
|
|
id: btnPreference
|
2020-08-18 17:41:05 -04:00
|
|
|
visible: preferenceType === PreferenceItemDelegate.DEFAULT
|
|
|
|
backgroundColor: "white"
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-08-18 17:41:05 -04:00
|
|
|
Layout.alignment: Qt.AlignRight | Qt.AlingVCenter
|
2020-08-03 13:27:42 -04:00
|
|
|
Layout.rightMargin: 7
|
|
|
|
Layout.preferredWidth: 30
|
|
|
|
Layout.preferredHeight: 30
|
|
|
|
|
2020-08-18 17:41:05 -04:00
|
|
|
buttonImageHeight: 20
|
|
|
|
buttonImageWidth: 20
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
source:{
|
|
|
|
return "qrc:/images/icons/round-settings-24px.svg"
|
|
|
|
}
|
|
|
|
|
2020-08-18 17:41:05 -04:00
|
|
|
ToolTip.visible: hovered
|
2020-08-03 13:27:42 -04:00
|
|
|
ToolTip.text: {
|
2020-08-18 17:41:05 -04:00
|
|
|
return qsTr("Edit preference")
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
onClicked: {
|
|
|
|
btnPreferenceClicked()
|
|
|
|
}
|
|
|
|
}
|
2020-08-18 17:41:05 -04:00
|
|
|
|
|
|
|
Label {
|
|
|
|
visible: preferenceType === PreferenceItemDelegate.LIST
|
|
|
|
Layout.preferredWidth: root.width / 2
|
|
|
|
Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
|
|
|
|
Layout.leftMargin: 8
|
|
|
|
|
|
|
|
text: preferenceName
|
|
|
|
font.pointSize: JamiTheme.settingsFontSize
|
|
|
|
ToolTip.visible: hovered
|
|
|
|
ToolTip.text: preferenceSummary
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SettingParaCombobox {
|
|
|
|
id: listPreferenceComboBox
|
|
|
|
visible: preferenceType === PreferenceItemDelegate.LIST
|
|
|
|
Layout.preferredWidth: root.width / 2 - 8
|
|
|
|
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
|
|
|
|
Layout.rightMargin: 8
|
|
|
|
|
|
|
|
font.pointSize: JamiTheme.settingsFontSize
|
|
|
|
font.kerning: true
|
|
|
|
|
|
|
|
model: pluginListPreferenceModel
|
|
|
|
currentIndex: pluginListPreferenceModel.getCurrentSettingIndex()
|
|
|
|
textRole: qsTr("PreferenceValue")
|
|
|
|
tooltipText: qsTr("Choose the preference")
|
|
|
|
onActivated: {
|
|
|
|
getNewPreferenceValueSlot(index)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Label {
|
|
|
|
visible: preferenceType === PreferenceItemDelegate.USERLIST
|
|
|
|
Layout.preferredWidth: root.width / 2
|
|
|
|
Layout.leftMargin: 8
|
|
|
|
Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
|
|
|
|
|
|
|
|
text: preferenceName
|
|
|
|
font.pointSize: JamiTheme.settingsFontSize
|
|
|
|
ToolTip.visible: hovered
|
|
|
|
ToolTip.text: preferenceSummary
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
SettingParaCombobox {
|
|
|
|
id: userListPreferenceComboBox
|
|
|
|
visible: preferenceType === PreferenceItemDelegate.USERLIST
|
|
|
|
Layout.preferredWidth: root.width / 2 - 8
|
|
|
|
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
|
|
|
|
Layout.rightMargin: 8
|
|
|
|
|
|
|
|
font.pointSize: JamiTheme.settingsFontSize
|
|
|
|
font.kerning: true
|
|
|
|
|
|
|
|
model: pluginListPreferenceModel
|
|
|
|
currentIndex: pluginListPreferenceModel.getCurrentSettingIndex()
|
|
|
|
textRole: qsTr("PreferenceValue")
|
|
|
|
tooltipText: qsTr("Choose the preference")
|
|
|
|
onActivated: {
|
|
|
|
getNewPreferenceValueSlot(index)
|
|
|
|
}
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
}
|