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

0001 /*
0002     SPDX-FileCopyrightText: 2022 Aditya Mehra <aix.m@outlook.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 import QtQuick 2.12
0008 import QtQuick.Controls 2.12
0009 import QtQuick.Window 2.12
0010 import QtWebEngine 1.7
0011 import QtWebChannel 1.0
0012 import QtQuick.Layouts 1.12
0013 import QtQuick.LocalStorage 2.12
0014 import "code/RecentStorage.js" as RecentStorage
0015 import "code/Utils.js" as Utils
0016 import Aura 1.0 as Aura
0017 import QtQuick.VirtualKeyboard 2.4
0018 import Qt5Compat.GraphicalEffects
0019 import org.kde.kirigami as Kirigami
0020 
0021 Popup {
0022     id: webpageUrlEntryDrawer
0023     width: parent.width * 0.8
0024     height: parent.height * 0.8
0025     x: (parent.width - width) / 2
0026     y: (parent.height - height) / 2
0027     padding: Kirigami.Units.largeSpacing
0028     modal: true
0029     dim: true
0030 
0031     Overlay.modal: Rectangle {
0032         Kirigami.Theme.colorSet: Kirigami.Theme.View
0033         color: Qt.rgba(Kirigami.Theme.backgroundColor.r, Kirigami.Theme.backgroundColor.g, Kirigami.Theme.backgroundColor.b, 0.9)
0034     }
0035 
0036     background: Rectangle {
0037         color: Kirigami.Theme.backgroundColor
0038         layer.enabled: true
0039         layer.effect: DropShadow {
0040             horizontalOffset: 0
0041             verticalOffset: 2
0042             radius: 8.0
0043             samples: 17
0044             color: Qt.rgba(0,0,0,0.6)
0045         }
0046     }
0047 
0048     function autoAppend(model, getinputstring, setinputstring) {
0049         for(var i = 0; i < model.count; ++i)
0050             if (getinputstring(model.get(i))){
0051                 return true
0052             }
0053         return null
0054     }
0055 
0056     function evalAutoLogic() {
0057         if (suggestionsBox.currentIndex === -1) {
0058         } else {
0059             suggestionsBox.complete(suggestionsBox.currentItem)
0060         }
0061     }
0062 
0063     onOpened: {
0064         localurlEntrie.forceActiveFocus()
0065     }
0066 
0067     ListModel {
0068         id: completionItems
0069     }
0070 
0071     contentItem: Item {
0072         id: entryLayout
0073 
0074         RowLayout {
0075             id: localHeaderAreaURLandSearchField
0076             anchors.top: parent.top
0077             anchors.left: parent.left
0078             anchors.right: parent.right
0079             anchors.margins: Kirigami.Units.smallSpacing
0080 
0081             Kirigami.Heading {
0082                 id: localUrlSearchFieldLabel
0083                 level: 1
0084                 text: i18n("Enter URL / Search Term")
0085                 color: Kirigami.Theme.textColor
0086                 width: parent.width
0087                 horizontalAlignment: Qt.AlignLeft
0088                 Layout.alignment: Qt.AlignLeft
0089             }
0090 
0091             Label {
0092                 id: localUrlSearchFieldBackBtnLabel
0093                 text: i18n("Press 'esc' or the [←] Back button to close")
0094                 Layout.alignment: Qt.AlignRight
0095                 color: Kirigami.Theme.textColor
0096             }
0097         }
0098 
0099         Kirigami.Separator {
0100             id: localUrlSearchFieldheaderSept
0101             anchors.top: localHeaderAreaURLandSearchField.bottom
0102             width: parent.width
0103             height: 1
0104         }
0105 
0106         TextField {
0107             id: localurlEntrie
0108             width: parent.width
0109             anchors.top: localUrlSearchFieldheaderSept.bottom
0110             anchors.topMargin: Kirigami.Units.largeSpacing
0111             height: Kirigami.Units.gridUnit * 5
0112             placeholderText: i18n("Enter Search Term or URL")
0113             color: Kirigami.Theme.textColor
0114             inputMethodHints: Qt.ImhNoAutoUppercase | Qt.ImhNoPredictiveText
0115             background: Rectangle {
0116                 color: Qt.lighter(Kirigami.Theme.backgroundColor, 1.2)
0117                 border.color: localurlEntrie.activeFocus ? Kirigami.Theme.highlightColor : Kirigami.Theme.disabledTextColor
0118                 border.width: 1
0119             }
0120 
0121             onAccepted: {
0122                 var evaluateExist = webpageUrlEntryDrawer.autoAppend(completionItems, function(item) { return item.name === localurlEntrie.text }, localurlEntrie.text)
0123                 if(evaluateExist === null){
0124                     completionItems.append({"name": localurlEntrie.text, "randcolor": Utils.genRandomColor().toString()});
0125                 }
0126                 var setUrl = Utils.checkURL(localurlEntrie.text)
0127                 if(setUrl){
0128                     webView.url = localurlEntrie.text
0129                 } else {
0130                     var searchTypeUrl
0131                     if(Aura.GlobalSettings.defaultSearchEngine == "Google"){
0132                         searchTypeUrl = "https://www.google.com/search?q=" + localurlEntrie.text
0133                     } else if (Aura.GlobalSettings.defaultSearchEngine == "DDG") {
0134                         searchTypeUrl = "https://duckduckgo.com/?q=" + localurlEntrie.text
0135                     }
0136                     webView.url = searchTypeUrl
0137                 }
0138                 webpageUrlEntryDrawer.close()
0139             }
0140 
0141             onTextChanged: {
0142                 webpageUrlEntryDrawer.evalAutoLogic();
0143             }
0144 
0145             Keys.onDownPressed: (event)=> {
0146                 if(!inputPanel.active && suggestionsBox.visible){
0147                     suggestionsBox.forceActiveFocus()
0148                 }
0149             }
0150         }
0151 
0152         SuggestionsBox {
0153             id: suggestionsBox
0154             model: completionItems
0155             width: parent.width
0156             anchors.top: localurlEntrie.bottom
0157             anchors.bottom: parent.bottom
0158             anchors.left: parent.left
0159             anchors.right: parent.right
0160             filter: localurlEntrie.text
0161             property: "name"
0162             onItemSelected: complete(item)
0163 
0164             function complete(item) {
0165                 if (item !== undefined) {
0166                     localurlEntrie.text = item.name
0167                 }
0168             }
0169         }
0170     }
0171 }