This repository has been archived on 2021-06-24. You can view files and clone it, but cannot push or open issues or pull requests.
ui/qml/panes/PeerSettingsPane.qml

163 lines
5.2 KiB
QML

import QtGraphicalEffects 1.0
import QtQuick 2.7
import QtQuick.Controls 2.4
import QtQuick.Controls.Material 2.0
import QtQuick.Layouts 1.3
import QtQuick.Window 2.11
import QtQuick.Controls 1.4
import QtQuick.Controls.Styles 1.4
import "../opaque" as Opaque
import "../opaque/styles"
import "../opaque/theme"
import "../const"
Opaque.SettingsList { // settingsPane
id: root
anchors.fill: parent
anchors.topMargin: 20
width: parent.width
height: parent.height
contentHeight: peerSettings.height + 20
property string authorization
property string saveHistory
Column {
id: peerSettings
anchors.horizontalCenter: parent.horizontalCenter
width:parent.width -20
parent: root.contentItem
Opaque.Setting {
inline: false
label: qsTr("address-label")
field: Opaque.ButtonTextField {
id: txtOnion
readOnly: true
button_text: qsTr("copy-btn")
dropShadowColor: Theme.dropShadowPaneColor
onClicked: {
//: notification: copied to clipboard
gcd.popup(qsTr("copied-to-clipboard-notification"))
txtOnion.selectAll()
txtOnion.copy()
}
}
}
Opaque.Setting {
inline: false
label: qsTr("display-name-label")
field: Opaque.ButtonTextField {
id: txtDisplayName
button_text: qsTr("save-btn")
dropShadowColor: Theme.dropShadowPaneColor
onClicked: {
gcd.savePeerSettings(txtOnion.text, txtDisplayName.text)
toolbar.setTitle(txtDisplayName.text)
theStack.pane = theStack.messagePane
}
}
}
Opaque.Setting {
label: qsTr("block-btn")
field: Opaque.ToggleSwitch {
anchors.right: parent.right
isToggled: root.authorization == Const.auth_blocked
onToggled: function() {
console.log("peer block toddle for " + txtOnion.text + " currently: " + root.authorization)
if (root.authorization == Const.auth_blocked) {
root.authorization = Const.auth_unknown
console.log("setPeerAuthorization to " + Const.auth_unknown + " for " + txtOnion.text)
gcd.setPeerAuthorization(txtOnion.text, Const.auth_unknown)
} else {
root.authorization = Const.auth_blocked
console.log("setPeerAuthorization to " + Const.auth_blocked + " for " + txtOnion.text)
gcd.setPeerAuthorization(txtOnion.text, Const.auth_blocked)
}
isToggled = root.authorization == Const.auth_blocked
}
}
}
Opaque.Setting {
//: Save Peer History
label: qsTr("save-peer-history")
description: qsTr("save-peer-history-description")
field: Opaque.ComboBox {
id: cbSaveHistory
anchors.right: parent.right
anchors.left: parent.left
model: ListModel {
id: cbSaveHistoryItems
ListElement { text: qsTr("dont-save-peer-history"); value: "DeleteHistoryConfirmed" }
ListElement { text: qsTr("save-peer-history"); value: "SaveHistory" }
}
onActivated: {
var item = cbSaveHistoryItems.get(cbSaveHistory.currentIndex)
if (item["value"] == "SaveHistory") {
gcd.storeHistoryForPeer(txtOnion.text)
} else {
gcd.deleteHistoryForPeer(txtOnion.text)
}
}
}
}
Column {
width:parent.width * 0.95
anchors.horizontalCenter: parent.horizontalCenter
Opaque.Button {
icon: "regular/trash-alt"
text: qsTr("delete-btn")
anchors.right: parent.right
onClicked: {
gcd.deleteContact(txtOnion.text)
theStack.pane = theStack.emptyPane
}
}
}
}
Connections {
target: gcd
onSupplyPeerSettings: function(onion, nick, authorization, saveHistory) {
txtOnion.text = onion
txtDisplayName.text = nick
root.authorization = authorization
root.saveHistory = saveHistory
// This will not set the value in the default case where saveHistory = DefaultDeleteHistory and thus
// the combobox will default to showing DeleteHistoryConfirmed
for (var i=0; i < cbSaveHistoryItems.count; i++) {
var item = cbSaveHistoryItems.get(i)
if (item["value"] == root.saveHistory || (root.saveHistory == "DefaultDeleteHistory" && item["value"] == "DeleteHistoryConfirmed")) {
cbSaveHistory.currentIndex = i
break
}
}
}
}
}