Warning, /plasma/aura-browser/app/qml/UrlEntryBox.qml is written in an unsupported language. File is not indexed.

0001 /*
0002     SPDX-FileCopyrightText: 2022 Aditya Mehra <aix.m@outlook.com>
0003     SPDX-License-Identifier: GPL-2.0-or-later
0004 */
0005 
0006 import QtQuick 2.12
0007 import QtQuick.Window 2.12
0008 import QtQuick.Layouts 1.12
0009 import QtQuick.Controls 2.12 as Controls
0010 import Aura 1.0 as Aura
0011 import Qt5Compat.GraphicalEffects
0012 import org.kde.kirigami as Kirigami
0013 
0014 Controls.Popup {
0015     id: urlEntryDrawer
0016     width: parent.width * 0.8
0017     height: parent.height * 0.8
0018     x: (parent.width - width) / 2
0019     y: (parent.height - height) / 2
0020     modal: false
0021     dim: true
0022     padding: Kirigami.Units.largeSpacing
0023     z: 2
0024 
0025     function checkURL(value) {
0026         var urlregex = new RegExp("^(http|https|ftp)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&amp;%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{2}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&amp;%\$#\=~_\-]+))*$");
0027         if (urlregex.test(value)) {
0028             return (true);
0029         }
0030         return (false);
0031     }
0032 
0033     onOpened: {
0034         urlEntrie.forceActiveFocus()
0035     }
0036 
0037     Controls.Overlay.modeless: Rectangle {
0038         Kirigami.Theme.colorSet: Kirigami.Theme.View
0039         color: Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.9)
0040     }
0041 
0042     background: Rectangle {
0043         color: Kirigami.Theme.backgroundColor
0044         layer.enabled: true
0045         layer.effect: DropShadow {
0046             horizontalOffset: 0
0047             verticalOffset: 2
0048             radius: 8.0
0049             samples: 17
0050             color: Qt.rgba(0,0,0,0.6)
0051         }
0052     }
0053     
0054     contentItem: FocusScope {
0055         id: entryLayout
0056 
0057         RowLayout {
0058             id: headerAreaURLandSearchField
0059             anchors.top: parent.top
0060             anchors.left: parent.left
0061             anchors.right: parent.right                
0062             anchors.margins: Kirigami.Units.smallSpacing
0063 
0064             Kirigami.Heading {
0065                 id: urlSearchFieldLabel
0066                 level: 1
0067                 text: i18n("Enter URL / Search Term")
0068                 width: parent.width
0069                 horizontalAlignment: Qt.AlignLeft
0070                 Layout.alignment: Qt.AlignLeft
0071                 color: Kirigami.Theme.textColor
0072             }
0073 
0074             Controls.Label {
0075                 id: urlSearchFieldBackBtnLabel
0076                 text: i18n("Press 'esc' or the [←] Back button to close")
0077                 Layout.alignment: Qt.AlignRight
0078                 color: Kirigami.Theme.textColor
0079             }
0080         }
0081 
0082         Kirigami.Separator {
0083             id: urlSearchFieldheaderSept
0084             anchors.top: headerAreaURLandSearchField.bottom
0085             width: parent.width
0086             height: 1
0087         }
0088 
0089         Controls.TextField {
0090             id: urlEntrie
0091             anchors.top: urlSearchFieldheaderSept.bottom
0092             anchors.topMargin: Kirigami.Units.largeSpacing
0093             width: parent.width
0094             height: Kirigami.Units.gridUnit * 5
0095             inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
0096             placeholderText: i18n("Enter Search Term or URL")
0097             color: Kirigami.Theme.textColor
0098             focus: true
0099             background: Rectangle {
0100                 color: Qt.lighter(Kirigami.Theme.backgroundColor, 1.2)
0101                 border.color: urlEntrie.activeFocus ? Kirigami.Theme.highlightColor : Kirigami.Theme.disabledTextColor
0102                 border.width: 1
0103             }
0104 
0105             onAccepted: {
0106                 Aura.NavigationSoundEffects.playClickedSound();
0107                 var setUrl = checkURL(urlEntrie.text)
0108                 if(setUrl){
0109                     createTab(urlEntrie.text)
0110                 } else {
0111                     var searchTypeUrl
0112                     if(Aura.GlobalSettings.defaultSearchEngine == "Google"){
0113                         searchTypeUrl = "https://www.google.com/search?q=" + urlEntrie.text
0114                     } else if (Aura.GlobalSettings.defaultSearchEngine == "DDG") {
0115                         searchTypeUrl = "https://duckduckgo.com/?q=" + urlEntrie.text
0116                     }
0117                     createTab(searchTypeUrl)
0118                 }
0119                 urlEntryDrawer.close()
0120             }
0121         }
0122     }
0123 }