[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[no subject]
From: |
Gavin D. Smith |
Date: |
Sun, 20 Mar 2022 04:55:14 -0400 (EDT) |
branch: master
commit d6c40e216041ef1b6227af75d55a12435b2c9a61
Author: Gavin Smith <gavinsmith0123@gmail.com>
AuthorDate: Sun May 26 12:20:48 2019 +0100
find index nodes and send to main process
---
js/wkinfo/extension.c | 81 +++++++++++++++++++++++++++++++++++++++++++++++++++
js/wkinfo/main.c | 35 ++++++++++++++++++++--
2 files changed, 114 insertions(+), 2 deletions(-)
diff --git a/js/wkinfo/extension.c b/js/wkinfo/extension.c
index d6f9da464d..3f86d0ddd7 100644
--- a/js/wkinfo/extension.c
+++ b/js/wkinfo/extension.c
@@ -54,6 +54,7 @@ send_datagram (GString *s)
}
static char *current_manual;
+static char *current_manual_dir;
/* Called from request_callback. */
void
@@ -103,6 +104,12 @@ request_callback (WebKitWebPage *web_page,
g_print ("Intercepting link <%s>\n", uri);
+ /* Clear flags on WebKitWebPage object. */
+ g_object_set_data (G_OBJECT(web_page), "top-node",
+ GINT_TO_POINTER(0));
+ g_object_set_data (G_OBJECT(web_page), "send-index",
+ GINT_TO_POINTER(0));
+
const char *p = strchr (uri, '?');
if (p)
{
@@ -119,6 +126,11 @@ request_callback (WebKitWebPage *web_page,
g_object_set_data (G_OBJECT(web_page), "send-index",
GINT_TO_POINTER(1));
}
+ else if (!strcmp (p, "top-node"))
+ {
+ g_object_set_data (G_OBJECT(web_page), "top-node",
+ GINT_TO_POINTER(1));
+ }
return FALSE;
}
@@ -142,6 +154,65 @@ request_callback (WebKitWebPage *web_page,
return FALSE;
}
+/* Given the main index.html Top node in the document, find the nodes
+ containing indices. */
+void
+find_indices (WebKitDOMHTMLCollection *links, gulong num_links)
+{
+ g_print ("looking for indices\n");
+
+ gulong i = 0;
+ GString *s = g_string_new (NULL);
+
+ g_string_assign (s, "index-nodes\n");
+
+ for (; i < num_links; i++)
+ {
+ WebKitDOMNode *node
+ = webkit_dom_html_collection_item (links, i);
+ if (!node)
+ {
+ g_print ("No node\n");
+ return;
+ }
+
+ WebKitDOMElement *element;
+ if (WEBKIT_DOM_IS_ELEMENT(node))
+ {
+ element = WEBKIT_DOM_ELEMENT(node);
+ }
+ else
+ {
+ /* When would this happen? */
+ g_print ("Not an DOM element\n");
+ continue;
+ }
+
+ gchar *href = webkit_dom_element_get_attribute (element, "href");
+
+
+ char *rel = webkit_dom_element_get_attribute (element, "rel");
+ char *id = webkit_dom_element_get_attribute (element, "id");
+
+ /* Look for links to index nodes in the main menu.
+ This is not the best way to check for index nodes. We should
+ have <a rel="index"> on the links instead. */
+ if (href && !*rel && !*id
+ && (strstr (href, "-Index.html")
+ || strstr (href, "-index.html")
+ || strstr (href, "/Index.html")))
+ {
+ g_string_append (s, href);
+ g_string_append (s, "\n");
+ }
+ free (rel); free (id);
+ }
+
+ g_print ("found index nodes %s\n", s->str);
+ send_datagram (s);
+ g_string_free (s, TRUE);
+}
+
void
send_index (WebKitDOMHTMLCollection *links, gulong num_links)
{
@@ -241,12 +312,22 @@ document_loaded_callback (WebKitWebPage *web_page,
gint send_index_p
= GPOINTER_TO_INT(g_object_get_data(G_OBJECT(web_page), "send-index"));
+ gint top_node_p
+ = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(web_page), "top-node"));
+
if (send_index_p)
{
send_index (links, num_links);
return;
}
+ if (top_node_p)
+ {
+ find_indices (links, num_links);
+ return;
+ }
+
+ /* Find and send the Next, Prev and Up links to the main process. */
gulong i;
for (i = 0; i < num_links; i++)
{
diff --git a/js/wkinfo/main.c b/js/wkinfo/main.c
index ee94577cf0..2df2548c0e 100644
--- a/js/wkinfo/main.c
+++ b/js/wkinfo/main.c
@@ -173,6 +173,28 @@ save_completions (char *p)
}
}
+void
+load_index_nodes (char *p)
+{
+ GString *s;
+ char *q;
+
+ s = g_string_new (NULL);
+
+ while ((q = strchr (p, '\n')))
+ {
+ *q = '\0';
+ g_string_assign (s, "file:");
+ g_string_append (s, p);
+ g_string_append (s, "?send-index");
+
+ g_print ("load index node %s\n", s->str);
+
+ p = q + 1;
+ }
+ g_string_free (s, TRUE);
+}
+
gboolean
socket_cb (GSocket *socket,
GIOCondition condition,
@@ -228,10 +250,19 @@ socket_cb (GSocket *socket,
else if (!strcmp (buffer, "new-manual"))
{
g_print ("NEW MANUAL %s\n", p + 1);
+
+ GString *s = g_string_new (NULL);
+ g_string_append (s, p + 1);
+ g_string_append (s, "?top-node");
+ webkit_web_view_load_uri (hiddenWebView, s->str);
+ g_string_free (s, TRUE);
+
}
- else if (!strcmp (buffer, "index-node"))
+ else if (!strcmp (buffer, "index-nodes"))
{
- /* Receive URL of file containing an index. */
+ /* Receive URL of files containing an index. */
+ p++;
+ load_index_nodes (p);
}
else
{
- [no subject], (continued)
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject],
Gavin D. Smith <=
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20
- [no subject], Gavin D. Smith, 2022/03/20