github.com/jonasnick/go-ethereum@v0.7.12-0.20150216215225-22176f05d387/cmd/mist/assets/qml/views/catalog.qml (about) 1 import QtQuick 2.0 2 import QtQuick.Controls 1.0; 3 import QtQuick.Controls.Styles 1.0 4 import QtQuick.Layouts 1.0; 5 import QtWebEngine 1.0 6 //import QtWebEngine.experimental 1.0 7 import QtQuick.Window 2.0; 8 9 10 Rectangle { 11 id: window 12 anchors.fill: parent 13 color: "#00000000" 14 15 property var title: "Catalog" 16 property var iconSource: "" 17 property var menuItem 18 property var hideUrl: true 19 20 property alias url: webview.url 21 property alias windowTitle: webview.title 22 property alias webView: webview 23 24 25 26 property var cleanPath: false 27 property var open: function(url) { 28 if(!window.cleanPath) { 29 var uri = url; 30 if(!/.*\:\/\/.*/.test(uri)) { 31 uri = "http://" + uri; 32 } 33 34 var reg = /(^https?\:\/\/(?:www\.)?)([a-zA-Z0-9_\-]*\.eth)(.*)/ 35 36 if(reg.test(uri)) { 37 uri.replace(reg, function(match, pre, domain, path) { 38 uri = pre; 39 40 var lookup = eth.lookupDomain(domain.substring(0, domain.length - 4)); 41 var ip = []; 42 for(var i = 0, l = lookup.length; i < l; i++) { 43 ip.push(lookup.charCodeAt(i)) 44 } 45 46 if(ip.length != 0) { 47 uri += lookup; 48 } else { 49 uri += domain; 50 } 51 52 uri += path; 53 }); 54 } 55 56 window.cleanPath = true; 57 58 webview.url = uri; 59 60 //uriNav.text = uri.text.replace(/(^https?\:\/\/(?:www\.)?)([a-zA-Z0-9_\-]*\.\w{2,3})(.*)/, "$1$2<span style='color:#CCC'>$3</span>"); 61 uriNav.text = uri; 62 63 } else { 64 // Prevent inf loop. 65 window.cleanPath = false; 66 } 67 } 68 69 Component.onCompleted: { 70 } 71 72 Item { 73 objectName: "root" 74 id: root 75 anchors.fill: parent 76 state: "inspectorShown" 77 78 WebEngineView { 79 objectName: "webView" 80 id: webview 81 anchors.fill: parent 82 83 property var protocol: "http://" 84 //property var domain: "localhost:3000" 85 property var domain: "ethereum-dapp-catalog.meteor.com" 86 url: protocol + domain 87 88 //navigationRequest: WebEngineView.IgnoreRequest 89 // onLoadingChanged: { 90 // if (loadRequest.status == WebEngineView.LoadSucceededStatus) { 91 // webview.runJavaScript(eth.readFile("bignumber.min.js")); 92 // webview.runJavaScript(eth.readFile("ethereum.js/dist/ethereum.js")); 93 // } 94 // } 95 96 //onNavigationRequested: { 97 // detect URL scheme prefix, most likely an external link 98 //var schemaRE = /^\w+:/; 99 //if (schemaRE.test(request.url)) { 100 // request.action = WebView.AcceptRequest; 101 //} else { 102 //request.action = WebView.IgnoreRequest; 103 // delegate request.url here 104 //} 105 //} 106 107 onJavaScriptConsoleMessage: { 108 console.log(sourceID + ":" + lineNumber + ":" + JSON.stringify(message)); 109 } 110 111 onNavigationRequested: { 112 var cleanTitle = request.url.toString() 113 var matches = cleanTitle.match(/^[a-z]*\:\/\/([^\/?#]+)(?:[\/?#]|$)/i); 114 var requestedDomain = matches && matches[1]; 115 116 console.debug ("NavigationRequested: " + request.url + " navigationType=" + request.navigationType) 117 118 if(request.navigationType==0){ 119 120 if (requestedDomain === this.domain){ 121 request.action = WebEngineView.AcceptRequest; 122 } else { 123 request.action = WebEngineView.IgnoreRequest; 124 newBrowserTab(request.url); 125 } 126 127 } 128 } 129 } 130 131 132 133 WebEngineView { 134 id: inspector 135 visible: false 136 z:10 137 anchors { 138 left: root.left 139 right: root.right 140 bottom: root.bottom 141 } 142 143 } 144 145 states: [ 146 State { 147 name: "inspectorShown" 148 PropertyChanges { 149 target: inspector 150 } 151 } 152 ] 153 } 154 }