2020-10-29 15:19:27 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
2020-10-29 19:02:32 +00:00
|
|
|
import QtGraphicalEffects 1.13
|
2020-10-29 15:19:27 +00:00
|
|
|
import "../../../imports"
|
|
|
|
import "../../../shared"
|
2020-10-29 19:02:32 +00:00
|
|
|
import "../../../shared/status"
|
2020-10-29 15:19:27 +00:00
|
|
|
|
|
|
|
ModalPopup {
|
|
|
|
property string urlError: ""
|
|
|
|
property string nameError: ""
|
2020-10-29 19:02:32 +00:00
|
|
|
property string ogUrl
|
|
|
|
property string ogName
|
|
|
|
property bool modifiyModal: false
|
2020-10-29 20:07:52 +00:00
|
|
|
property bool toolbarMode: false
|
2020-10-29 15:19:27 +00:00
|
|
|
|
|
|
|
id: popup
|
2020-10-29 20:07:52 +00:00
|
|
|
width: toolbarMode ? 345 : 480
|
|
|
|
height: toolbarMode ? 345 : 480
|
2020-10-29 19:02:32 +00:00
|
|
|
|
2020-10-29 20:07:52 +00:00
|
|
|
modal: !toolbarMode
|
2020-10-29 19:02:32 +00:00
|
|
|
|
|
|
|
background: Rectangle {
|
|
|
|
id: bgPopup
|
|
|
|
color: Style.current.background
|
|
|
|
radius: Style.current.radius
|
|
|
|
layer.enabled: true
|
|
|
|
layer.effect: DropShadow{
|
|
|
|
width: bgPopup.width
|
|
|
|
height: bgPopup.height
|
|
|
|
x: bgPopup.x
|
|
|
|
y: bgPopup.y + 10
|
|
|
|
visible: bgPopup.visible
|
|
|
|
source: bgPopup
|
|
|
|
horizontalOffset: 0
|
|
|
|
verticalOffset: 5
|
|
|
|
radius: 10
|
|
|
|
samples: 15
|
|
|
|
color: "#22000000"
|
|
|
|
}
|
|
|
|
}
|
2020-10-29 15:19:27 +00:00
|
|
|
|
|
|
|
onOpened: {
|
|
|
|
urlInput.forceActiveFocus(Qt.MouseFocusReason)
|
|
|
|
}
|
|
|
|
|
2020-10-29 19:02:32 +00:00
|
|
|
onClosed: {
|
|
|
|
reset()
|
|
|
|
}
|
|
|
|
|
2020-10-29 15:19:27 +00:00
|
|
|
function validate() {
|
|
|
|
urlError = ""
|
|
|
|
if (!urlInput.text) {
|
|
|
|
urlError = qsTr("Please enter a URL")
|
|
|
|
} else if (!Utils.isURL(urlInput.text)) {
|
|
|
|
urlError = qsTr("This fields needs to be a valid URL")
|
|
|
|
}
|
|
|
|
|
|
|
|
nameError = !nameInput.text ? qsTr("Please enter a Name") : ""
|
|
|
|
|
|
|
|
return !urlError && !nameError
|
|
|
|
}
|
|
|
|
|
2020-10-29 19:02:32 +00:00
|
|
|
function reset() {
|
|
|
|
modifiyModal = false
|
2020-10-29 20:07:52 +00:00
|
|
|
toolbarMode = false
|
2020-10-29 19:02:32 +00:00
|
|
|
urlError = ""
|
|
|
|
nameError = ""
|
|
|
|
ogUrl = ""
|
|
|
|
ogName = ""
|
|
|
|
x = Math.round(((parent ? parent.width : 0) - width) / 2)
|
|
|
|
y = Math.round(((parent ? parent.height : 0) - height) / 2)
|
|
|
|
}
|
|
|
|
|
|
|
|
title: modifiyModal ?
|
2020-10-29 20:07:52 +00:00
|
|
|
toolbarMode ?
|
|
|
|
qsTr("Favorite added") :
|
|
|
|
qsTr("Edit")
|
|
|
|
: qsTr("Add favorite")
|
2020-10-29 15:19:27 +00:00
|
|
|
|
|
|
|
Column {
|
|
|
|
width: parent.width
|
|
|
|
spacing: Style.current.padding
|
|
|
|
|
|
|
|
Input {
|
|
|
|
id: urlInput
|
|
|
|
label: qsTr("URL")
|
|
|
|
placeholderText: qsTr("Paste URL")
|
|
|
|
pasteFromClipboard: true
|
|
|
|
validationError: popup.urlError
|
2020-10-29 19:02:32 +00:00
|
|
|
text: popup.ogUrl
|
2020-10-29 15:19:27 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Input {
|
|
|
|
id: nameInput
|
|
|
|
label: qsTr("Name")
|
|
|
|
placeholderText: qsTr("Name the website")
|
|
|
|
validationError: popup.nameError
|
2020-10-29 19:02:32 +00:00
|
|
|
text: popup.ogName
|
2020-10-29 15:19:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-29 19:02:32 +00:00
|
|
|
footer: Item {
|
|
|
|
width: parent.width
|
2021-01-13 19:15:52 +00:00
|
|
|
height: removeBtn.height
|
2020-10-29 19:02:32 +00:00
|
|
|
|
|
|
|
StatusButton {
|
|
|
|
id: removeBtn
|
|
|
|
anchors.right: addBtn.left
|
|
|
|
anchors.rightMargin: Style.current.padding
|
|
|
|
visible: popup.modifiyModal
|
|
|
|
text: qsTr("Remove")
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
color: Style.current.danger
|
|
|
|
bgColor: Utils.setColorAlpha(Style.current.danger, 0.1)
|
|
|
|
bgHoverColor: Utils.setColorAlpha(Style.current.danger, 0.2)
|
|
|
|
onClicked: {
|
|
|
|
browserModel.removeBookmark(popup.ogUrl)
|
|
|
|
popup.close()
|
2020-10-29 15:19:27 +00:00
|
|
|
}
|
2020-10-29 19:02:32 +00:00
|
|
|
}
|
2020-10-29 15:19:27 +00:00
|
|
|
|
2020-10-29 19:02:32 +00:00
|
|
|
StatusButton {
|
|
|
|
id: addBtn
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: Style.current.smallPadding
|
|
|
|
text: popup.modifiyModal ?
|
|
|
|
qsTr("Done") :
|
|
|
|
qsTr("Add")
|
|
|
|
anchors.bottom: parent.bottom
|
|
|
|
onClicked: {
|
|
|
|
if (!validate()) {
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!popup.modifiyModal) {
|
|
|
|
browserModel.addBookmark(urlInput.text, nameInput.text)
|
|
|
|
} else if (popup.ogName !== nameInput.text || popup.ogUrl !== urlInput.text) {
|
|
|
|
browserModel.modifyBookmark(popup.ogUrl, urlInput.text, nameInput.text)
|
|
|
|
}
|
|
|
|
|
|
|
|
popup.close()
|
|
|
|
}
|
2020-10-29 15:19:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|