2021-01-18 20:25:20 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
2021-09-28 15:04:06 +00:00
|
|
|
|
|
|
|
import utils 1.0
|
2021-01-18 20:25:20 +00:00
|
|
|
import "../../../../shared"
|
2021-10-14 11:33:34 +00:00
|
|
|
import "../../../../shared/popups"
|
2021-10-14 12:14:11 +00:00
|
|
|
import "../../../../shared/panels"
|
2021-01-18 20:25:20 +00:00
|
|
|
import "../../../../shared/status"
|
|
|
|
|
2021-10-14 11:33:34 +00:00
|
|
|
// TODO: replace with StatusModal
|
2021-01-18 20:25:20 +00:00
|
|
|
ModalPopup {
|
|
|
|
id: popup
|
|
|
|
|
2021-02-18 16:36:05 +00:00
|
|
|
//% "Chat link previews"
|
|
|
|
title: qsTrId("chat-link-previews")
|
2021-01-18 20:25:20 +00:00
|
|
|
|
|
|
|
onClosed: {
|
|
|
|
destroy()
|
|
|
|
}
|
|
|
|
|
|
|
|
function populatePreviewableSites() {
|
|
|
|
let whitelist = JSON.parse(profileModel.getLinkPreviewWhitelist())
|
|
|
|
whitelist.forEach(entry => {
|
|
|
|
entry.isWhitelisted = appSettings.whitelistedUnfurlingSites[entry.address] || false
|
|
|
|
previewableSites.append(entry)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
onOpened: {
|
|
|
|
populatePreviewableSites()
|
|
|
|
}
|
|
|
|
|
2021-03-16 15:19:36 +00:00
|
|
|
Item {
|
2021-01-18 20:25:20 +00:00
|
|
|
anchors.fill: parent
|
|
|
|
|
|
|
|
StatusSectionHeadline {
|
|
|
|
id: labelWebsites
|
2021-02-18 16:36:05 +00:00
|
|
|
//% "Websites"
|
|
|
|
text: qsTrId("websites")
|
2021-01-18 20:25:20 +00:00
|
|
|
width: parent.width
|
|
|
|
|
|
|
|
StatusButton {
|
2021-02-18 16:36:05 +00:00
|
|
|
//% "Enable all"
|
|
|
|
text: qsTrId("enable-all")
|
2021-01-18 20:25:20 +00:00
|
|
|
type: "secondary"
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
flat: true
|
|
|
|
onClicked: {
|
|
|
|
const count = sitesListView.count
|
|
|
|
for (let i = 0; i < count; i++) {
|
|
|
|
sitesListView.itemAtIndex(i).toggleSetting(true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
ListModel {
|
|
|
|
id: previewableSites
|
|
|
|
}
|
|
|
|
|
|
|
|
Connections {
|
2021-02-18 19:14:31 +00:00
|
|
|
target: appMain
|
2021-01-18 20:25:20 +00:00
|
|
|
onSettingsLoaded: {
|
|
|
|
popup.populatePreviewableSites()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 15:19:36 +00:00
|
|
|
ScrollView {
|
2021-01-18 20:25:20 +00:00
|
|
|
width: parent.width
|
2021-03-16 15:19:36 +00:00
|
|
|
anchors.top: labelWebsites.bottom
|
|
|
|
anchors.topMargin: Style.current.bigPadding
|
|
|
|
anchors.bottom: infoText.top
|
|
|
|
anchors.bottomMargin: Style.current.bigPadding
|
|
|
|
ScrollBar.horizontal.policy: ScrollBar.AlwaysOff
|
|
|
|
ScrollBar.vertical.policy: ScrollBar.AlwaysOn
|
|
|
|
clip: true
|
|
|
|
|
|
|
|
ListView {
|
|
|
|
id: sitesListView
|
|
|
|
anchors.fill: parent
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
model: previewableSites
|
|
|
|
spacing: 0
|
|
|
|
|
|
|
|
delegate: Component {
|
|
|
|
Rectangle {
|
|
|
|
property bool isHovered: false
|
|
|
|
id: linkRectangle
|
2021-01-18 20:25:20 +00:00
|
|
|
width: parent.width
|
2021-03-16 15:19:36 +00:00
|
|
|
height: 64
|
|
|
|
color: isHovered ? Style.current.backgroundHover : Style.current.transparent
|
|
|
|
radius: Style.current.radius
|
|
|
|
border.width: 0
|
|
|
|
|
|
|
|
function toggleSetting(newState) {
|
|
|
|
if (newState !== undefined) {
|
|
|
|
settingSwitch.checked = newState
|
|
|
|
return
|
|
|
|
}
|
|
|
|
settingSwitch.checked = !settingSwitch.checked
|
|
|
|
}
|
2021-01-18 20:25:20 +00:00
|
|
|
|
|
|
|
SVGImage {
|
|
|
|
id: thumbnail
|
|
|
|
width: 40
|
|
|
|
height: 40
|
2021-03-16 15:19:36 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
|
2021-01-18 20:25:20 +00:00
|
|
|
source: {
|
|
|
|
let filename;
|
|
|
|
switch (title.toLowerCase()) {
|
|
|
|
case "youtube":
|
|
|
|
case "youtube shortener":
|
2021-09-28 15:04:06 +00:00
|
|
|
filename = "youtube"; break;
|
2021-01-18 20:25:20 +00:00
|
|
|
case "github":
|
2021-09-28 15:04:06 +00:00
|
|
|
filename = "github"; break;
|
2021-03-16 15:19:36 +00:00
|
|
|
case "medium":
|
2021-09-28 15:04:06 +00:00
|
|
|
filename = "medium"; break;
|
2021-03-16 15:19:36 +00:00
|
|
|
case "tenor gifs":
|
2021-09-28 15:04:06 +00:00
|
|
|
filename = "tenor"; break;
|
2021-03-16 15:19:36 +00:00
|
|
|
case "giphy gifs":
|
|
|
|
case "giphy gifs shortener":
|
|
|
|
case "giphy gifs subdomain":
|
2021-09-28 15:04:06 +00:00
|
|
|
filename = "giphy"; break;
|
2021-03-16 15:19:36 +00:00
|
|
|
case "github":
|
2021-09-28 15:04:06 +00:00
|
|
|
filename = "github"; break;
|
2021-03-16 15:19:36 +00:00
|
|
|
case "status":
|
2021-09-28 15:04:06 +00:00
|
|
|
filename = "status"; break;
|
2021-03-16 15:19:36 +00:00
|
|
|
// TODO get a good default icon
|
2021-09-28 15:04:06 +00:00
|
|
|
default: filename = "../globe"
|
2021-01-18 20:25:20 +00:00
|
|
|
}
|
2021-09-28 15:04:06 +00:00
|
|
|
return Style.svg(`linkPreviewThumbnails/${filename}`)
|
2021-01-18 20:25:20 +00:00
|
|
|
}
|
2021-03-16 15:19:36 +00:00
|
|
|
|
|
|
|
Rectangle {
|
|
|
|
width: parent.width
|
|
|
|
height: parent.height
|
|
|
|
radius: width / 2
|
|
|
|
color: Style.current.transparent
|
|
|
|
border.color: Style.current.border
|
|
|
|
border.width: 1
|
|
|
|
}
|
2021-01-18 20:25:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
id: siteTitle
|
|
|
|
text: title
|
|
|
|
font.pixelSize: 15
|
|
|
|
font.weight: Font.Medium
|
|
|
|
anchors.top: thumbnail.top
|
|
|
|
anchors.left: thumbnail.right
|
|
|
|
anchors.leftMargin: Style.current.padding
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
|
|
|
text: address
|
|
|
|
font.pixelSize: 15
|
|
|
|
font.weight: Font.Thin
|
|
|
|
color: Style.current.secondaryText
|
|
|
|
anchors.top: siteTitle.bottom
|
|
|
|
anchors.left: siteTitle.left
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusSwitch {
|
|
|
|
id: settingSwitch
|
|
|
|
checked: !!isWhitelisted
|
2021-03-16 15:19:36 +00:00
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: Style.current.padding
|
2021-01-18 20:25:20 +00:00
|
|
|
onCheckedChanged: function () {
|
|
|
|
if (appSettings.whitelistedUnfurlingSites[address] === this.checked) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
const settings = appSettings.whitelistedUnfurlingSites
|
|
|
|
settings[address] = this.checked
|
|
|
|
appSettings.whitelistedUnfurlingSites = settings
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 15:19:36 +00:00
|
|
|
MouseArea {
|
|
|
|
anchors.fill: parent
|
|
|
|
cursorShape: Qt.PointingHandCursor
|
|
|
|
hoverEnabled: true
|
|
|
|
onEntered: linkRectangle.isHovered = true
|
|
|
|
onExited: linkRectangle.isHovered = false
|
|
|
|
onClicked: toggleSetting()
|
|
|
|
}
|
2021-01-18 20:25:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
StyledText {
|
2021-03-16 15:19:36 +00:00
|
|
|
id: infoText
|
2021-02-18 16:36:05 +00:00
|
|
|
//% "Previewing links from these websites may share your metadata with their owners."
|
|
|
|
text: qsTrId("previewing-links-from-these-websites-may-share-your-metadata-with-their-owners-")
|
2021-01-18 20:25:20 +00:00
|
|
|
width: parent.width
|
|
|
|
wrapMode: Text.WordWrap
|
|
|
|
font.weight: Font.Thin
|
|
|
|
color: Style.current.secondaryText
|
|
|
|
font.pixelSize: 15
|
2021-03-16 15:19:36 +00:00
|
|
|
anchors.bottom: parent.bottom
|
2021-01-18 20:25:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*##^##
|
|
|
|
Designer {
|
|
|
|
D{i:0;autoSize:true;height:480;width:640}
|
|
|
|
}
|
|
|
|
##^##*/
|