[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Gavin D. Smith |
Date: |
Wed, 30 Nov 2022 13:36:38 -0500 (EST) |
branch: old/qt-info
commit e004934debc5c1569ae374aa92a9805a80df961a
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Thu Apr 11 21:52:00 2019 +0100
concatenate contents of qtinfo.js with that of info.js
---
js/docbrowser/mainwindow.cpp | 30 ++++++++++--
js/docbrowser/qtinfo.js | 113 +++++++++++++++++++++++++++++++++++++++++++
2 files changed, 138 insertions(+), 5 deletions(-)
diff --git a/js/docbrowser/mainwindow.cpp b/js/docbrowser/mainwindow.cpp
index c31968094d..1a14ce8dfb 100644
--- a/js/docbrowser/mainwindow.cpp
+++ b/js/docbrowser/mainwindow.cpp
@@ -96,12 +96,30 @@ MainWindow::setup_profile (QWebEngineProfile *profile)
{
#define INFO_JS "info.js"
+#define QTINFO_JS "docbrowser/qtinfo.js"
- info_js = inject_js_file (INFO_JS, profile);
- /* We need the files to be loaded in a particular order.
- Using QWebEngineProfile appears to work. Calling runJavaScript
- after the page is loaded doesn't work this is too late for
- DOMContentLoaded event handlers in info.js to fire. */
+ QString script;
+ QFile file;
+ file.setFileName (QString(this->datadir)
+ + "/" + INFO_JS);
+ file.open(QIODevice::ReadOnly);
+ QByteArray b = file.readAll();
+ script = QString(b);
+
+ QString script2;
+ QFile file2;
+ file2.setFileName (QString(this->datadir)
+ + "/" + QTINFO_JS);
+ file2.open(QIODevice::ReadOnly);
+ QByteArray b2 = file2.readAll();
+ script2 = QString(b2);
+
+ QWebEngineScript s1;
+ s1.setSourceCode(script + script2);
+ // s1.setRunsOnSubFrames(true);
+ s1.setInjectionPoint(QWebEngineScript::DocumentCreation);
+ s1.setWorldId(QWebEngineScript::MainWorld);
+ profile->scripts()->insert(s1);
#define MODERNIZR_JS "modernizr.js"
@@ -140,11 +158,13 @@ MainWindow::setup_profile (QWebEngineProfile *profile)
/* This needs to run after the <head> element is accessible, but before
the DOMContentLoaded event handlers in info.js fire. */
+#if 0
QWebEngineScript s2;
s2.setSourceCode("if (typeof wc_init == 'function') { wc_init(); }");
s2.setInjectionPoint(QWebEngineScript::DocumentCreation);
s2.setWorldId(QWebEngineScript::MainWorld);
profile->scripts()->insert(s2);
+#endif
}
diff --git a/js/docbrowser/qtinfo.js b/js/docbrowser/qtinfo.js
new file mode 100644
index 0000000000..2c00163b21
--- /dev/null
+++ b/js/docbrowser/qtinfo.js
@@ -0,0 +1,113 @@
+/* qtinfo.js - Qt/Javascript UI for Texinfo manuals
+ Copyright (C) 2019 Free Software Foundation, Inc.
+
+ This file is part of GNU Texinfo.
+
+ GNU Texinfo is free software: you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
+
+ GNU Texinfo is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU Texinfo. If not, see <http://www.gnu.org/licenses/>. */
+
+/*----------------------------------.
+| For communication with Qt process |
+`----------------------------------*/
+
+/* object shared with controlling Qt/C++ process */
+var core;
+
+/* Whether we are being controlled via a QWebChannel, and the JavaScript is
+ being injected into the HTML pages. Try to keep the use of this
conditional
+ to a minimum. */
+var wc_controlled = 0;
+
+/* For use with QWebChannel. To be called after qwebchannel.js has been
+ loaded. */
+function wc_init()
+{
+ wc_controlled = 1;
+
+ if (location.search != "")
+ var baseUrl
+ =
(/[?&]webChannelBaseUrl=([A-Za-z0-9\-:/\.]+)/.exec(location.search)[1]);
+ else
+ var baseUrl = "ws://localhost:12345";
+
+ var socket = new WebSocket(baseUrl);
+
+ socket.onclose = function()
+ {
+ console.error("web channel closed");
+ };
+
+ socket.onerror = function(error)
+ {
+ console.error("web channel error: " + error);
+ };
+
+ socket.onopen = function()
+ {
+ new QWebChannel(socket, function(channel)
+ {
+ window.core = channel.objects.core;
+
+ /* Receive signals from Qt/C++ side.
+
+ We don't have code to receive "actions" from the C++ side:
+ the action message-passing architecture is only used to
+ circumvent same-origin policy restrictions on some browsers for
+ file: URI's. */
+
+ channel.objects.core.setUrl.connect(function(url) {
+ alert("asked to go to " + url);
+ });
+
+ channel.objects.core.set_current_url.connect(function(linkid) {
+ store.dispatch (actions.set_current_url (linkid));
+ });
+ });
+ };
+
+ var store_dispatch = Store.prototype.dispatch;
+ Store.prototype.dispatch = function (action)
+ {
+ if (!web_channel_override (this, action))
+ store_dispatch.call (this, action);
+ };
+ /* Overriding just the dispatch function works better than
+ assigining 'store' to a different object, as store.state
+ is used as well. */
+}
+
+
+/* Return true if the standard function doesn't need to be called. */
+function web_channel_override (store, action)
+{
+ switch (action.type)
+ {
+ case "external-manual":
+ {
+ window.core.external_manual (action.url);
+ return 1;
+ }
+ case "input":
+ {
+ if (action.input == "index")
+ window.core.show_text_input (action.input, store.state.index);
+ return 1;
+ }
+ default:
+ {
+ return 0;
+ }
+ }
+}
+
+wc_init();
- branch old/qt-info created (now e2d72c0f4f), Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject],
Gavin D. Smith <=
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30
- [no subject], Gavin D. Smith, 2022/11/30