mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-16 05:51:07 +02:00
working within webview to access url
This commit is contained in:
parent
76a847d34f
commit
eab7714d70
5 changed files with 109 additions and 6 deletions
|
@ -223,6 +223,7 @@ ScrollingWindow {
|
|||
var newWindow = component.createObject(desktop);
|
||||
request.openIn(newWindow.webView)
|
||||
}
|
||||
|
||||
//profile: desktop.browserProfile
|
||||
}
|
||||
|
||||
|
|
|
@ -49,6 +49,7 @@ WebEngineView {
|
|||
|
||||
onLoadingChanged: {
|
||||
// Required to support clicking on "hifi://" links
|
||||
console.log("loading change requested url");
|
||||
if (WebEngineView.LoadStartedStatus == loadRequest.status) {
|
||||
var url = loadRequest.url.toString();
|
||||
if (urlHandler.canHandleUrl(url)) {
|
||||
|
@ -59,12 +60,19 @@ WebEngineView {
|
|||
}
|
||||
}
|
||||
|
||||
onNewViewRequested:{
|
||||
var component = Qt.createComponent("../Browser.qml");
|
||||
var newWindow = component.createObject(desktop);
|
||||
request.openIn(newWindow.webView)
|
||||
onNewViewRequested: {
|
||||
console.log("new view requested url");
|
||||
console.log(request.url.toString());
|
||||
//if (toString(request.url) )
|
||||
var component = Qt.createComponent("../Browser.qml");
|
||||
var newWindow = component.createObject(desktop);
|
||||
request.openIn(newWindow.webView);
|
||||
}
|
||||
|
||||
onLinkHovered: {
|
||||
console.log(hoveredUrl);
|
||||
}
|
||||
|
||||
// This breaks the webchannel used for passing messages. Fixed in Qt 5.6
|
||||
// See https://bugreports.qt.io/browse/QTBUG-49521
|
||||
//profile: desktop.browserProfile
|
||||
|
|
|
@ -354,6 +354,7 @@ public:
|
|||
|
||||
if (message->message == WM_COPYDATA) {
|
||||
COPYDATASTRUCT* pcds = (COPYDATASTRUCT*)(message->lParam);
|
||||
qDebug() << "os windows url for some reason";
|
||||
QUrl url = QUrl((const char*)(pcds->lpData));
|
||||
if (url.isValid() && url.scheme() == HIFI_URL_SCHEME) {
|
||||
DependencyManager::get<AddressManager>()->handleLookupString(url.toString());
|
||||
|
@ -2157,6 +2158,10 @@ bool Application::event(QEvent* event) {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (event->type() == QEvent::None) {
|
||||
qDebug() << "this url just didn't click";
|
||||
}
|
||||
|
||||
if (HFActionEvent::types().contains(event->type())) {
|
||||
_controllerScriptingInterface->handleMetaEvent(static_cast<HFMetaEvent*>(event));
|
||||
}
|
||||
|
@ -3180,6 +3185,7 @@ void Application::saveSettings() const {
|
|||
}
|
||||
|
||||
bool Application::importEntities(const QString& urlOrFilename) {
|
||||
qDebug() << "import entities url";
|
||||
bool success = false;
|
||||
_entityClipboard->withWriteLock([&] {
|
||||
_entityClipboard->eraseAllOctreeElements();
|
||||
|
@ -4789,6 +4795,7 @@ void Application::registerScriptEngineWithApplicationServices(ScriptEngine* scri
|
|||
}
|
||||
|
||||
bool Application::canAcceptURL(const QString& urlString) const {
|
||||
qDebug() << "stepping through 'canAcceptURL'";
|
||||
QUrl url(urlString);
|
||||
if (urlString.startsWith(HIFI_URL_SCHEME)) {
|
||||
return true;
|
||||
|
@ -4805,6 +4812,7 @@ bool Application::canAcceptURL(const QString& urlString) const {
|
|||
}
|
||||
|
||||
bool Application::acceptURL(const QString& urlString, bool defaultUpload) {
|
||||
qDebug() << "stepping through 'acceptURL'";
|
||||
if (urlString.startsWith(HIFI_URL_SCHEME)) {
|
||||
// this is a hifi URL - have the AddressManager handle it
|
||||
QMetaObject::invokeMethod(DependencyManager::get<AddressManager>().data(), "handleLookupString",
|
||||
|
@ -4834,6 +4842,7 @@ void Application::setSessionUUID(const QUuid& sessionUUID) const {
|
|||
}
|
||||
|
||||
bool Application::askToSetAvatarUrl(const QString& url) {
|
||||
qDebug() << "setting avatar url";
|
||||
QUrl realUrl(url);
|
||||
if (realUrl.isLocalFile()) {
|
||||
OffscreenUi::warning("", "You can not use local files for avatar components.");
|
||||
|
@ -4890,6 +4899,7 @@ bool Application::askToSetAvatarUrl(const QString& url) {
|
|||
|
||||
|
||||
bool Application::askToLoadScript(const QString& scriptFilenameOrURL) {
|
||||
qDebug() << "setting script url";
|
||||
QMessageBox::StandardButton reply;
|
||||
|
||||
QString shortName = scriptFilenameOrURL;
|
||||
|
@ -4914,7 +4924,7 @@ bool Application::askToLoadScript(const QString& scriptFilenameOrURL) {
|
|||
}
|
||||
|
||||
bool Application::askToWearAvatarAttachmentUrl(const QString& url) {
|
||||
|
||||
qDebug() << "setting avatar attachment url";
|
||||
QNetworkAccessManager& networkAccessManager = NetworkAccessManager::getInstance();
|
||||
QNetworkRequest networkRequest = QNetworkRequest(url);
|
||||
networkRequest.setHeader(QNetworkRequest::UserAgentHeader, HIGH_FIDELITY_USER_AGENT);
|
||||
|
@ -4996,6 +5006,7 @@ bool Application::displayAvatarAttachmentConfirmationDialog(const QString& name)
|
|||
}
|
||||
|
||||
void Application::toggleRunningScriptsWidget() const {
|
||||
qDebug() << "toggle running scripts url";
|
||||
static const QUrl url("hifi/dialogs/RunningScripts.qml");
|
||||
DependencyManager::get<OffscreenUi>()->show(url, "RunningScripts");
|
||||
//if (_runningScriptsWidget->isVisible()) {
|
||||
|
@ -5013,10 +5024,11 @@ void Application::toggleRunningScriptsWidget() const {
|
|||
}
|
||||
|
||||
void Application::toggleAssetServerWidget(QString filePath) {
|
||||
qDebug() << "toggle asset before if";
|
||||
if (!DependencyManager::get<NodeList>()->getThisNodeCanWriteAssets()) {
|
||||
return;
|
||||
}
|
||||
|
||||
qDebug() << "toggle asset after if";
|
||||
static const QUrl url { "AssetServer.qml" };
|
||||
|
||||
auto startUpload = [=](QQmlContext* context, QObject* newObject){
|
||||
|
@ -5033,6 +5045,7 @@ void Application::packageModel() {
|
|||
}
|
||||
|
||||
void Application::openUrl(const QUrl& url) const {
|
||||
qDebug() << "open url";
|
||||
if (!url.isEmpty()) {
|
||||
if (url.scheme() == HIFI_URL_SCHEME) {
|
||||
DependencyManager::get<AddressManager>()->handleLookupString(url.toString());
|
||||
|
@ -5063,6 +5076,7 @@ void Application::setPreviousScriptLocation(const QString& location) {
|
|||
}
|
||||
|
||||
void Application::loadScriptURLDialog() const {
|
||||
qDebug() << "load script url dialog";
|
||||
auto newScript = OffscreenUi::getText(nullptr, "Open and Run Script", "Script URL");
|
||||
if (!newScript.isEmpty()) {
|
||||
DependencyManager::get<ScriptEngines>()->loadScript(newScript);
|
||||
|
|
|
@ -78,17 +78,20 @@ class UrlHandler : public QObject {
|
|||
Q_OBJECT
|
||||
public:
|
||||
Q_INVOKABLE bool canHandleUrl(const QString& url) {
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
static auto handler = dynamic_cast<AbstractUriHandler*>(qApp);
|
||||
return handler->canAcceptURL(url);
|
||||
}
|
||||
|
||||
Q_INVOKABLE bool handleUrl(const QString& url) {
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
static auto handler = dynamic_cast<AbstractUriHandler*>(qApp);
|
||||
return handler->acceptURL(url);
|
||||
}
|
||||
|
||||
// FIXME hack for authentication, remove when we migrate to Qt 5.6
|
||||
Q_INVOKABLE QString fixupUrl(const QString& originalUrl) {
|
||||
qDebug() << Q_FUNC_INFO;
|
||||
return fixupHifiUrl(originalUrl);
|
||||
}
|
||||
};
|
||||
|
|
77
scripts/system/examples.js
Normal file
77
scripts/system/examples.js
Normal file
|
@ -0,0 +1,77 @@
|
|||
//
|
||||
// examples.js
|
||||
// examples
|
||||
//
|
||||
// Created by Eric Levin on 8 Jan 2016
|
||||
// Copyright 2016 High Fidelity, Inc.
|
||||
//
|
||||
// Distributed under the Apache License, Version 2.0.
|
||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||
//
|
||||
|
||||
var toolIconUrl = Script.resolvePath("assets/images/tools/");
|
||||
|
||||
var EXAMPLES_URL = "https://metaverse.highfidelity.com/examples";
|
||||
//var EXAMPLES_URL = "https://clara.io/view/c1c4d926-5648-4fd3-9673-6d9018ad4627";
|
||||
//var EXAMPLES_URL = "http://s3.amazonaws.com/DreamingContent/test.html";
|
||||
|
||||
var examplesWindow = new OverlayWebWindow({
|
||||
title: 'Examples',
|
||||
source: "about:blank",
|
||||
width: 900,
|
||||
height: 700,
|
||||
visible: false
|
||||
});
|
||||
|
||||
var toolHeight = 50;
|
||||
var toolWidth = 50;
|
||||
var TOOLBAR_MARGIN_Y = 0;
|
||||
|
||||
|
||||
function showExamples(marketplaceID) {
|
||||
var url = EXAMPLES_URL;
|
||||
if (marketplaceID) {
|
||||
url = url + "/items/" + marketplaceID;
|
||||
}
|
||||
print("setting examples URL to " + url);
|
||||
examplesWindow.setURL(url);
|
||||
examplesWindow.setVisible(true);
|
||||
|
||||
UserActivityLogger.openedMarketplace();
|
||||
}
|
||||
|
||||
function hideExamples() {
|
||||
examplesWindow.setVisible(false);
|
||||
examplesWindow.setURL("about:blank");
|
||||
}
|
||||
|
||||
function toggleExamples() {
|
||||
if (examplesWindow.visible) {
|
||||
hideExamples();
|
||||
} else {
|
||||
showExamples();
|
||||
}
|
||||
}
|
||||
|
||||
var toolBar = Toolbars.getToolbar("com.highfidelity.interface.toolbar.system");
|
||||
|
||||
var browseExamplesButton = toolBar.addButton({
|
||||
imageURL: toolIconUrl + "market.svg",
|
||||
objectName: "examples",
|
||||
buttonState: 1,
|
||||
alpha: 0.9
|
||||
});
|
||||
|
||||
function onExamplesWindowVisibilityChanged() {
|
||||
browseExamplesButton.writeProperty('buttonState', examplesWindow.visible ? 0 : 1);
|
||||
}
|
||||
function onClick() {
|
||||
toggleExamples();
|
||||
}
|
||||
browseExamplesButton.clicked.connect(onClick);
|
||||
examplesWindow.visibleChanged.connect(onExamplesWindowVisibilityChanged);
|
||||
|
||||
Script.scriptEnding.connect(function () {
|
||||
browseExamplesButton.clicked.disconnect(onClick);
|
||||
examplesWindow.visibleChanged.disconnect(onExamplesWindowVisibilityChanged);
|
||||
});
|
Loading…
Reference in a new issue