2020-10-07 20:14:55 +00:00
|
|
|
import QtQuick 2.13
|
|
|
|
import QtQuick.Controls 2.13
|
|
|
|
import QtQuick.Layouts 1.13
|
|
|
|
import Qt.labs.settings 1.0
|
|
|
|
import QtQuick.Controls.Styles 1.0
|
2020-10-08 15:31:53 +00:00
|
|
|
import QtWebEngine 1.10
|
2020-10-07 20:14:55 +00:00
|
|
|
import "../../../shared"
|
2020-10-08 15:31:53 +00:00
|
|
|
import "../../../shared/status"
|
2020-10-07 20:14:55 +00:00
|
|
|
import "../../../imports"
|
|
|
|
|
2020-10-08 15:31:53 +00:00
|
|
|
Rectangle {
|
2020-10-08 18:08:50 +00:00
|
|
|
property alias addressBar: addressBar
|
2020-10-08 15:31:53 +00:00
|
|
|
readonly property int innerMargin: 12
|
2020-10-09 17:56:42 +00:00
|
|
|
property var addNewTab: function () {}
|
2020-10-07 20:14:55 +00:00
|
|
|
|
|
|
|
id: root
|
|
|
|
width: parent.width
|
2020-12-29 17:10:22 +00:00
|
|
|
height: barRow.height + favoritesBarLoader.height
|
2020-10-08 15:31:53 +00:00
|
|
|
color: Style.current.background
|
|
|
|
border.width: 0
|
2020-10-07 20:14:55 +00:00
|
|
|
|
|
|
|
RowLayout {
|
2020-12-29 17:10:22 +00:00
|
|
|
id: barRow
|
|
|
|
width: parent.width
|
|
|
|
height: 45
|
2020-10-08 15:31:53 +00:00
|
|
|
spacing: root.innerMargin
|
2020-10-07 20:14:55 +00:00
|
|
|
|
|
|
|
Menu {
|
|
|
|
id: historyMenu
|
|
|
|
Instantiator {
|
|
|
|
model: currentWebView && currentWebView.navigationHistory.items
|
|
|
|
MenuItem {
|
|
|
|
text: model.title
|
|
|
|
onTriggered: currentWebView.goBackOrForward(model.offset)
|
|
|
|
checkable: !enabled
|
|
|
|
checked: !enabled
|
|
|
|
enabled: model.offset
|
|
|
|
}
|
|
|
|
onObjectAdded: function(index, object) {
|
|
|
|
historyMenu.insertItem(index, object)
|
|
|
|
}
|
|
|
|
onObjectRemoved: function(index, object) {
|
|
|
|
historyMenu.removeItem(object)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-08 15:31:53 +00:00
|
|
|
StatusIconButton {
|
2020-10-07 20:14:55 +00:00
|
|
|
id: backButton
|
2020-10-08 15:31:53 +00:00
|
|
|
icon.name: "leave_chat"
|
|
|
|
disabledColor: Style.current.lightGrey
|
2020-10-07 20:14:55 +00:00
|
|
|
onClicked: currentWebView.goBack()
|
|
|
|
onPressAndHold: {
|
|
|
|
if (currentWebView && (currentWebView.canGoBack || currentWebView.canGoForward)){
|
|
|
|
historyMenu.popup(backButton.x, backButton.y + backButton.height)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
enabled: currentWebView && currentWebView.canGoBack
|
2020-10-08 15:31:53 +00:00
|
|
|
width: 24
|
|
|
|
height: 24
|
|
|
|
Layout.leftMargin: root.innerMargin
|
|
|
|
padding: 6
|
2020-10-07 20:14:55 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 15:31:53 +00:00
|
|
|
StatusIconButton {
|
2020-10-07 20:14:55 +00:00
|
|
|
id: forwardButton
|
2020-10-08 15:31:53 +00:00
|
|
|
icon.name: "leave_chat"
|
|
|
|
iconRotation: 180
|
|
|
|
disabledColor: Style.current.lightGrey
|
2020-10-07 20:14:55 +00:00
|
|
|
onClicked: currentWebView.goForward()
|
|
|
|
onPressAndHold: {
|
|
|
|
if (currentWebView && (currentWebView.canGoBack || currentWebView.canGoForward)){
|
|
|
|
historyMenu.popup(forwardButton.x, forwardButton.y + forwardButton.height)
|
|
|
|
}
|
|
|
|
}
|
2020-10-08 15:31:53 +00:00
|
|
|
enabled: currentWebView && currentWebView.canGoForward
|
|
|
|
width: 24
|
|
|
|
height: 24
|
|
|
|
Layout.leftMargin: -root.innerMargin/2
|
2020-10-07 20:14:55 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 19:02:32 +00:00
|
|
|
Connections {
|
|
|
|
target: browserModel
|
|
|
|
onBookmarksChanged: {
|
2020-11-02 19:20:39 +00:00
|
|
|
addressBar.currentFavorite = Qt.binding(function () {return getCurrentFavorite(currentWebView.url)})
|
2020-10-29 19:02:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-07 20:14:55 +00:00
|
|
|
StyledTextField {
|
2020-10-29 20:07:52 +00:00
|
|
|
property var currentFavorite: currentWebView && getCurrentFavorite(currentWebView.url)
|
2020-10-29 19:02:32 +00:00
|
|
|
|
2020-10-07 20:14:55 +00:00
|
|
|
id: addressBar
|
2020-10-08 15:31:53 +00:00
|
|
|
height: 40
|
2020-10-07 20:14:55 +00:00
|
|
|
Layout.fillWidth: true
|
|
|
|
background: Rectangle {
|
2020-10-08 15:31:53 +00:00
|
|
|
color: Style.current.inputBackground
|
|
|
|
border.color: Style.current.inputBorderFocus
|
|
|
|
border.width: activeFocus ? 1 : 0
|
|
|
|
radius: 20
|
2020-10-07 20:14:55 +00:00
|
|
|
}
|
2020-10-08 15:31:53 +00:00
|
|
|
leftPadding: Style.current.padding
|
2021-02-18 16:36:05 +00:00
|
|
|
//% "Enter URL"
|
|
|
|
placeholderText: qsTrId("enter-url")
|
2020-10-07 20:14:55 +00:00
|
|
|
focus: true
|
|
|
|
text: ""
|
2020-10-08 15:31:53 +00:00
|
|
|
color: Style.current.textColor
|
2021-04-19 14:02:59 +00:00
|
|
|
onActiveFocusChanged: {
|
|
|
|
if (activeFocus) {
|
|
|
|
addressBar.selectAll()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-07 20:14:55 +00:00
|
|
|
Keys.onPressed: {
|
|
|
|
// TODO: disable browsing local files? file://
|
2021-01-04 21:32:36 +00:00
|
|
|
if (event.key === Qt.Key_Enter || event.key === Qt.Key_Return) {
|
2021-03-16 16:24:35 +00:00
|
|
|
if (appSettings.useBrowserEthereumExplorer !== Constants.browserEthereumExplorerNone && text.startsWith("0x")) {
|
|
|
|
switch (appSettings.useBrowserEthereumExplorer) {
|
2021-01-04 21:32:36 +00:00
|
|
|
case Constants.browserEthereumExplorerEtherscan:
|
|
|
|
if (text.length > 42) {
|
|
|
|
currentWebView.url = "https://etherscan.io/tx/" + text; break;
|
|
|
|
} else {
|
|
|
|
currentWebView.url = "https://etherscan.io/address/" + text; break;
|
|
|
|
}
|
|
|
|
case Constants.browserEthereumExplorerEthplorer:
|
|
|
|
if (text.length > 42) {
|
|
|
|
currentWebView.url = "https://ethplorer.io/tx/" + text; break;
|
|
|
|
} else {
|
|
|
|
currentWebView.url = "https://ethplorer.io/address/" + text; break;
|
|
|
|
}
|
|
|
|
case Constants.browserEthereumExplorerBlockchair:
|
|
|
|
if (text.length > 42) {
|
|
|
|
currentWebView.url = "https://blockchair.com/ethereum/transaction/" + text; break;
|
|
|
|
} else {
|
|
|
|
currentWebView.url = "https://blockchair.com/ethereum/address/" + text; break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return
|
|
|
|
}
|
2021-04-19 10:34:03 +00:00
|
|
|
if (appSettings.shouldShowBrowserSearchEngine !== Constants.browserSearchEngineNone && !Utils.isURL(text) && !Utils.isURLWithOptionalProtocol(text)) {
|
2021-03-16 16:24:35 +00:00
|
|
|
switch (appSettings.shouldShowBrowserSearchEngine) {
|
2021-01-04 21:13:41 +00:00
|
|
|
case Constants.browserSearchEngineGoogle: currentWebView.url = "https://www.google.com/search?q=" + text; break;
|
|
|
|
case Constants.browserSearchEngineYahoo: currentWebView.url = "https://search.yahoo.com/search?p=" + text; break;
|
|
|
|
case Constants.browserSearchEngineDuckDuckGo: currentWebView.url = "https://duckduckgo.com/?q=" + text; break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
2021-04-19 10:34:03 +00:00
|
|
|
} else if (Utils.isURLWithOptionalProtocol(text)) {
|
|
|
|
text = "https://" + text
|
2021-01-04 21:13:41 +00:00
|
|
|
}
|
|
|
|
|
2020-10-07 20:14:55 +00:00
|
|
|
currentWebView.url = determineRealURL(text);
|
|
|
|
}
|
|
|
|
}
|
2020-10-08 15:31:53 +00:00
|
|
|
|
|
|
|
StatusIconButton {
|
2020-10-29 19:02:32 +00:00
|
|
|
id: addFavoriteBtn
|
|
|
|
visible: !!currentWebView && !!currentWebView.url
|
|
|
|
icon.name: !!addressBar.currentFavorite ? "browser/favoriteActive" : "browser/favorite"
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.right: reloadBtn.left
|
|
|
|
anchors.rightMargin: Style.current.halfPadding
|
|
|
|
onClicked: {
|
|
|
|
if (!addressBar.currentFavorite) {
|
2021-08-17 17:03:03 +00:00
|
|
|
// remove "add favorite" button at the end, add new bookmark, add "add favorite" button back
|
|
|
|
browserModel.removeBookmark("")
|
2020-10-29 19:02:32 +00:00
|
|
|
browserModel.addBookmark(currentWebView.url, currentWebView.title)
|
2021-08-17 17:03:03 +00:00
|
|
|
browserModel.addBookmark("", qsTr("Add Favorite"))
|
2020-10-29 19:02:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
addFavoriteModal.modifiyModal = true
|
2020-10-29 20:07:52 +00:00
|
|
|
addFavoriteModal.toolbarMode = true
|
2020-10-29 19:02:32 +00:00
|
|
|
addFavoriteModal.x = addFavoriteBtn.x + addFavoriteBtn.width / 2 - addFavoriteBtn.width / 2
|
|
|
|
addFavoriteModal.y = root.y + root.height + 4
|
|
|
|
addFavoriteModal.ogUrl = addressBar.currentFavorite ? addressBar.currentFavorite.url : currentWebView.url
|
|
|
|
addFavoriteModal.ogName = addressBar.currentFavorite ? addressBar.currentFavorite.name : currentWebView.title
|
|
|
|
addFavoriteModal.open()
|
|
|
|
}
|
|
|
|
width: 24
|
|
|
|
height: 24
|
|
|
|
}
|
|
|
|
|
|
|
|
StatusIconButton {
|
|
|
|
id: reloadBtn
|
2020-10-08 15:31:53 +00:00
|
|
|
icon.name: currentWebView && currentWebView.loading ? "close" : "browser/refresh"
|
|
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: Style.current.halfPadding
|
|
|
|
onClicked: currentWebView && currentWebView.loading ? currentWebView.stop() : currentWebView.reload()
|
|
|
|
width: 24
|
|
|
|
height: 24
|
|
|
|
}
|
2020-10-07 20:14:55 +00:00
|
|
|
}
|
|
|
|
|
2020-10-15 17:05:34 +00:00
|
|
|
BrowserWalletMenu {
|
|
|
|
id: browserWalletMenu
|
|
|
|
y: root.height + root.anchors.topMargin
|
|
|
|
x: parent.width - width - Style.current.halfPadding
|
|
|
|
}
|
|
|
|
|
2020-10-19 20:26:16 +00:00
|
|
|
Loader {
|
|
|
|
active: true
|
|
|
|
sourceComponent: currentTabConnected ? connectedBtnComponent : notConnectedBtnCompoent
|
|
|
|
}
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: notConnectedBtnCompoent
|
|
|
|
StatusIconButton {
|
|
|
|
id: accountBtn
|
|
|
|
icon.name: "walletIcon"
|
|
|
|
onClicked: {
|
|
|
|
if (browserWalletMenu.opened) {
|
|
|
|
browserWalletMenu.close()
|
|
|
|
} else {
|
|
|
|
browserWalletMenu.open()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
width: 24
|
|
|
|
height: 24
|
|
|
|
padding: 6
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Component {
|
|
|
|
id: connectedBtnComponent
|
|
|
|
StatusButton {
|
|
|
|
id: accountBtnConnected
|
|
|
|
icon.source: "../../img/walletIcon.svg"
|
|
|
|
icon.width: 18
|
|
|
|
icon.height: 18
|
2021-06-22 16:59:11 +00:00
|
|
|
icon.color: walletModel.dappBrowserView.dappBrowserAccount.iconColor
|
|
|
|
text: walletModel.dappBrowserView.dappBrowserAccount.name
|
2020-10-19 20:26:16 +00:00
|
|
|
implicitHeight: 32
|
|
|
|
type: "secondary"
|
|
|
|
onClicked: {
|
|
|
|
if (browserWalletMenu.opened) {
|
|
|
|
browserWalletMenu.close()
|
|
|
|
} else {
|
|
|
|
browserWalletMenu.open()
|
|
|
|
}
|
2020-10-15 17:05:34 +00:00
|
|
|
}
|
|
|
|
}
|
2020-10-07 20:14:55 +00:00
|
|
|
}
|
|
|
|
|
2020-10-09 17:56:42 +00:00
|
|
|
BrowserSettingsMenu {
|
|
|
|
id: settingsMenu
|
|
|
|
addNewTab: root.addNewTab
|
|
|
|
x: parent.width - width
|
|
|
|
y: parent.height
|
|
|
|
}
|
|
|
|
|
2020-10-08 15:31:53 +00:00
|
|
|
StatusIconButton {
|
2020-10-07 20:14:55 +00:00
|
|
|
id: settingsMenuButton
|
2020-10-08 15:31:53 +00:00
|
|
|
icon.name: "dots-icon"
|
2020-10-09 17:56:42 +00:00
|
|
|
onClicked: {
|
|
|
|
if (settingsMenu.opened) {
|
|
|
|
settingsMenu.close()
|
|
|
|
} else {
|
|
|
|
settingsMenu.open()
|
|
|
|
}
|
|
|
|
}
|
2020-10-08 15:31:53 +00:00
|
|
|
width: 24
|
|
|
|
height: 24
|
|
|
|
Layout.rightMargin: root.innerMargin
|
|
|
|
padding: 6
|
2020-10-07 20:14:55 +00:00
|
|
|
}
|
|
|
|
}
|
2020-12-29 17:10:22 +00:00
|
|
|
|
|
|
|
Loader {
|
|
|
|
id: favoritesBarLoader
|
2021-03-16 16:13:25 +00:00
|
|
|
active: appSettings.shouldShowFavoritesBar
|
2020-12-29 17:10:22 +00:00
|
|
|
height: active ? item.height : 0
|
|
|
|
anchors.top: barRow.bottom
|
|
|
|
anchors.left: parent.left
|
|
|
|
anchors.leftMargin: Style.current.smallPadding
|
|
|
|
anchors.right: parent.right
|
|
|
|
anchors.rightMargin: Style.current.smallPadding
|
|
|
|
|
|
|
|
sourceComponent: Component {
|
|
|
|
FavoritesBar {}
|
|
|
|
}
|
|
|
|
}
|
2020-10-07 20:14:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2020-10-08 15:31:53 +00:00
|
|
|
|
|
|
|
/*##^##
|
|
|
|
Designer {
|
|
|
|
D{i:0;width:700}
|
|
|
|
}
|
|
|
|
##^##*/
|