2020-09-03 21:19:10 -04:00
|
|
|
/*
|
2020-08-28 12:04:45 -04:00
|
|
|
* Copyright (C) 2020 by Savoir-faire Linux
|
|
|
|
* Author: Aline Gondim Santos <aline.gondimsantos@savoirfairelinux.com>
|
2020-08-03 13:27:42 -04:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2020-08-28 12:04:45 -04:00
|
|
|
import QtQuick 2.14
|
2020-10-06 13:58:44 +02:00
|
|
|
import QtQuick.Controls 2.14
|
|
|
|
import QtQuick.Controls.Universal 2.14
|
|
|
|
import QtQuick.Layouts 1.14
|
2020-08-03 13:27:42 -04:00
|
|
|
import QtGraphicalEffects 1.14
|
|
|
|
import QtQuick.Controls.Styles 1.4
|
2020-08-28 12:04:45 -04:00
|
|
|
import Qt.labs.platform 1.1
|
|
|
|
import QtQuick.Dialogs 1.3
|
2020-08-03 13:27:42 -04:00
|
|
|
import net.jami.Models 1.0
|
2020-09-04 17:53:24 -04:00
|
|
|
import net.jami.Adapters 1.0
|
2020-12-05 14:05:57 +01:00
|
|
|
import net.jami.Constants 1.0
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-08-28 12:04:45 -04:00
|
|
|
import "../commoncomponents"
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
ItemDelegate {
|
2020-08-18 17:41:05 -04:00
|
|
|
id: root
|
|
|
|
|
|
|
|
enum Type {
|
|
|
|
LIST,
|
2020-09-01 18:19:22 -04:00
|
|
|
PATH,
|
2020-12-10 19:31:53 -05:00
|
|
|
EDITTEXT,
|
2021-01-25 16:48:17 -05:00
|
|
|
SWITCH,
|
2020-08-18 17:41:05 -04:00
|
|
|
DEFAULT
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
property string preferenceName: ""
|
|
|
|
property string preferenceSummary: ""
|
2020-09-01 18:19:22 -04:00
|
|
|
property string preferenceKey: ""
|
2020-08-03 13:27:42 -04:00
|
|
|
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: ""
|
2020-09-01 18:19:22 -04:00
|
|
|
property string currentPath: ""
|
|
|
|
property bool isImage: false
|
|
|
|
property var fileFilters: []
|
2020-08-18 17:41:05 -04:00
|
|
|
property PluginListPreferenceModel pluginListPreferenceModel
|
2020-08-03 13:27:42 -04:00
|
|
|
|
|
|
|
signal btnPreferenceClicked
|
|
|
|
|
2020-12-10 19:31:53 -05:00
|
|
|
function getNewPreferenceValueSlot(index) {
|
|
|
|
switch (preferenceType) {
|
2020-08-18 17:41:05 -04:00
|
|
|
case PreferenceItemDelegate.LIST:
|
2020-09-01 18:19:22 -04:00
|
|
|
pluginListPreferenceModel.idx = index
|
|
|
|
preferenceNewValue = pluginListPreferenceModel.preferenceNewValue
|
2020-08-18 17:41:05 -04:00
|
|
|
btnPreferenceClicked()
|
|
|
|
break
|
2020-09-01 18:19:22 -04:00
|
|
|
case PreferenceItemDelegate.PATH:
|
2020-12-10 19:31:53 -05:00
|
|
|
if (index === 0) {
|
2020-08-18 17:41:05 -04:00
|
|
|
preferenceFilePathDialog.title = qsTr("Select An Image to " + preferenceName)
|
2020-09-01 18:19:22 -04:00
|
|
|
preferenceFilePathDialog.nameFilters = fileFilters
|
2020-12-11 15:41:20 -05:00
|
|
|
preferenceFilePathDialog.selectedNameFilter.index = fileFilters.length - 1
|
2020-08-18 17:41:05 -04:00
|
|
|
preferenceFilePathDialog.open()
|
|
|
|
}
|
|
|
|
else
|
|
|
|
btnPreferenceClicked()
|
|
|
|
break
|
2020-12-10 19:31:53 -05:00
|
|
|
case PreferenceItemDelegate.EDITTEXT:
|
|
|
|
preferenceNewValue = editTextPreference.text
|
|
|
|
btnPreferenceClicked()
|
|
|
|
break
|
2021-01-25 16:48:17 -05:00
|
|
|
case PreferenceItemDelegate.SWITCH:
|
|
|
|
preferenceNewValue = index ? "1" : "0"
|
|
|
|
btnPreferenceClicked()
|
|
|
|
break
|
2020-08-18 17:41:05 -04:00
|
|
|
default:
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-01-25 16:48:17 -05:00
|
|
|
JamiFileDialog {
|
2020-08-18 17:41:05 -04:00
|
|
|
id: preferenceFilePathDialog
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-09-11 17:30:46 -04:00
|
|
|
title: JamiStrings.selectFile
|
2020-09-30 13:39:21 -04:00
|
|
|
folder: "file:///" + currentPath
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-08-18 17:41:05 -04:00
|
|
|
onAccepted: {
|
2021-01-25 16:48:17 -05:00
|
|
|
var url = UtilsAdapter.getAbsPath(file.toString())
|
2020-09-01 18:19:22 -04:00
|
|
|
preferenceNewValue = url
|
|
|
|
btnPreferenceClicked()
|
2020-08-18 17:41:05 -04:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2021-01-25 16:48:17 -05:00
|
|
|
Text {
|
|
|
|
id: prefLlabel
|
|
|
|
Layout.fillWidth: true
|
2020-09-01 18:19:22 -04:00
|
|
|
Layout.alignment: Qt.AlignLeft | Qt.AlignVCenter
|
2020-08-18 17:41:05 -04:00
|
|
|
Layout.leftMargin: 8
|
|
|
|
|
2020-08-28 12:04:45 -04:00
|
|
|
text: preferenceName
|
2020-11-28 16:14:25 -05:00
|
|
|
color: JamiTheme.textColor
|
2021-01-25 16:48:17 -05:00
|
|
|
elide: Text.ElideRight
|
2020-09-01 18:19:22 -04:00
|
|
|
font.pointSize: JamiTheme.settingsFontSize
|
|
|
|
ToolTip.visible: hovered
|
|
|
|
ToolTip.text: preferenceSummary
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
|
2020-10-06 16:59:29 -04:00
|
|
|
PushButton {
|
2021-01-25 16:48:17 -05:00
|
|
|
id: btnPreferenceDefault
|
2020-10-06 16:59:29 -04:00
|
|
|
|
2020-08-18 17:41:05 -04:00
|
|
|
visible: preferenceType === PreferenceItemDelegate.DEFAULT
|
2020-10-06 16:59:29 -04:00
|
|
|
normalColor: JamiTheme.primaryBackgroundColor
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-08-18 17:41:05 -04:00
|
|
|
Layout.alignment: Qt.AlignRight | Qt.AlingVCenter
|
2020-10-06 16:59:29 -04:00
|
|
|
Layout.rightMargin: 8
|
|
|
|
Layout.preferredWidth: preferredSize
|
|
|
|
Layout.preferredHeight: preferredSize
|
2020-11-28 16:14:25 -05:00
|
|
|
imageColor: JamiTheme.textColor
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-10-06 16:59:29 -04:00
|
|
|
source: "qrc:/images/icons/round-settings-24px.svg"
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2020-10-06 16:59:29 -04:00
|
|
|
toolTipText: qsTr("Edit preference")
|
2021-01-25 16:48:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
Switch {
|
|
|
|
id: btnPreferenceSwitch
|
2020-08-03 13:27:42 -04:00
|
|
|
|
2021-01-25 16:48:17 -05:00
|
|
|
visible: preferenceType === PreferenceItemDelegate.SWITCH
|
|
|
|
Layout.alignment: Qt.AlignRight | Qt.AlingVCenter
|
|
|
|
Layout.rightMargin: 16
|
|
|
|
Layout.preferredHeight: 30
|
|
|
|
Layout.preferredWidth: 30
|
|
|
|
checked: preferenceCurrentValue === "1"
|
|
|
|
|
|
|
|
onToggled: getNewPreferenceValueSlot(checked)
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
2020-08-18 17:41:05 -04:00
|
|
|
|
|
|
|
SettingParaCombobox {
|
|
|
|
id: listPreferenceComboBox
|
2020-10-06 16:59:29 -04:00
|
|
|
|
2020-08-18 17:41:05 -04:00
|
|
|
visible: preferenceType === PreferenceItemDelegate.LIST
|
|
|
|
Layout.preferredWidth: root.width / 2 - 8
|
|
|
|
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
|
2021-01-25 16:48:17 -05:00
|
|
|
Layout.rightMargin: 4
|
2020-08-18 17:41:05 -04:00
|
|
|
|
|
|
|
font.pointSize: JamiTheme.settingsFontSize
|
|
|
|
font.kerning: true
|
|
|
|
|
|
|
|
model: pluginListPreferenceModel
|
|
|
|
currentIndex: pluginListPreferenceModel.getCurrentSettingIndex()
|
2020-09-11 17:30:46 -04:00
|
|
|
textRole: "PreferenceValue"
|
2020-09-18 13:33:08 -04:00
|
|
|
tooltipText: JamiStrings.select
|
2020-10-07 15:46:41 -04:00
|
|
|
onActivated: getNewPreferenceValueSlot(index)
|
2020-08-18 17:41:05 -04:00
|
|
|
}
|
|
|
|
|
2020-10-07 15:46:41 -04:00
|
|
|
MaterialButton {
|
2020-09-01 18:19:22 -04:00
|
|
|
id: pathPreferenceButton
|
2020-10-06 16:59:29 -04:00
|
|
|
|
2020-09-01 18:19:22 -04:00
|
|
|
visible: preferenceType === PreferenceItemDelegate.PATH
|
2020-12-10 19:31:53 -05:00
|
|
|
width: root.width / 2 - 8
|
2020-10-06 16:59:29 -04:00
|
|
|
Layout.preferredWidth: width
|
2020-10-07 15:46:41 -04:00
|
|
|
Layout.preferredHeight: 30
|
|
|
|
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
|
2021-01-25 16:48:17 -05:00
|
|
|
Layout.rightMargin: 4
|
2020-08-18 17:41:05 -04:00
|
|
|
|
2020-10-07 15:46:41 -04:00
|
|
|
text: UtilsAdapter.fileName(preferenceCurrentValue)
|
2020-09-18 13:33:08 -04:00
|
|
|
toolTipText: JamiStrings.chooseImageFile
|
2020-10-07 15:46:41 -04:00
|
|
|
source: "qrc:/images/icons/round-folder-24px.svg"
|
|
|
|
color: JamiTheme.buttonTintedGrey
|
|
|
|
hoveredColor: JamiTheme.buttonTintedGreyHovered
|
|
|
|
pressedColor: JamiTheme.buttonTintedGreyPressed
|
2020-08-18 17:41:05 -04:00
|
|
|
|
2020-10-07 15:46:41 -04:00
|
|
|
onClicked: getNewPreferenceValueSlot(0)
|
2020-08-18 17:41:05 -04:00
|
|
|
}
|
2020-12-10 19:31:53 -05:00
|
|
|
|
|
|
|
MaterialLineEdit {
|
|
|
|
id: editTextPreference
|
|
|
|
|
|
|
|
visible: preferenceType === PreferenceItemDelegate.EDITTEXT
|
|
|
|
width: root.width / 2 - 8
|
|
|
|
Layout.preferredWidth: root.width / 2 - 8
|
|
|
|
Layout.preferredHeight: 30
|
|
|
|
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
|
2021-01-25 16:48:17 -05:00
|
|
|
Layout.rightMargin: 4
|
2020-12-10 19:31:53 -05:00
|
|
|
|
|
|
|
selectByMouse: true
|
|
|
|
text: preferenceCurrentValue
|
|
|
|
|
|
|
|
font.pointSize: JamiTheme.settingsFontSize
|
|
|
|
padding: 8
|
|
|
|
wrapMode: Text.NoWrap
|
|
|
|
|
|
|
|
onEditingFinished: getNewPreferenceValueSlot(0)
|
|
|
|
}
|
2020-08-03 13:27:42 -04:00
|
|
|
}
|
|
|
|
}
|