[libgepub] Update the chapter number when the page changes
- From: Daniel Garcia Moreno <danigm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgepub] Update the chapter number when the page changes
- Date: Sat, 27 Apr 2019 13:00:41 +0000 (UTC)
commit a5f2952e2ea047e2fd90bc31e7270667de7d5978
Author: IBBoard <dev ibboard co uk>
Date: Sat Apr 27 11:29:04 2019 +0100
Update the chapter number when the page changes
This ensures that hyperlinks between pages trigger chapter number
change signals, which let UIs update their position
Note: This currently triggers a page reload, which breaks links
to anchors within pages
libgepub/gepub-doc.c | 10 +++++++++-
libgepub/gepub-widget.c | 24 ++++++++++++++++++++++++
2 files changed, 33 insertions(+), 1 deletion(-)
---
diff --git a/libgepub/gepub-doc.c b/libgepub/gepub-doc.c
index e486bf5..53c2734 100644
--- a/libgepub/gepub-doc.c
+++ b/libgepub/gepub-doc.c
@@ -966,13 +966,21 @@ gepub_doc_resource_uri_to_chapter (GepubDoc *doc,
gchar *key;
GepubResource *res;
gchar *id = NULL;
+ const gchar *_uri;
+
+ if (uri[0] == '/') {
+ _uri = uri + 1;
+ }
+ else {
+ _uri = uri;
+ }
g_return_val_if_fail (GEPUB_IS_DOC (doc), -1);
g_return_val_if_fail (doc->spine != NULL, -1);
g_hash_table_iter_init (&iter, doc->resources);
while (g_hash_table_iter_next (&iter, (gpointer *)&key, (gpointer *)&res)) {
- if (!g_strcmp0 (res->uri, uri)) {
+ if (!g_strcmp0 (res->uri, _uri)) {
id = key;
break;
}
diff --git a/libgepub/gepub-widget.c b/libgepub/gepub-widget.c
index fce91c5..25da498 100644
--- a/libgepub/gepub-widget.c
+++ b/libgepub/gepub-widget.c
@@ -226,6 +226,29 @@ reload_length_cb (GtkWidget *widget,
}
}
+static void
+set_current_chapter_by_uri (WebKitWebView *web_view)
+{
+ GepubWidget *widget = GEPUB_WIDGET (web_view);
+ const gchar *uri_string;
+ SoupURI *uri;
+ const gchar *path;
+ gint chapter;
+
+ uri_string = webkit_web_view_get_uri (web_view);
+
+ if (g_strcmp0 ("about:blank", uri_string)) {
+ uri = soup_uri_new (uri_string);
+ path = soup_uri_get_path (uri);
+ chapter = gepub_doc_resource_uri_to_chapter (widget->doc, path);
+ gepub_doc_set_chapter (widget->doc, chapter);
+ soup_uri_free (uri);
+ }
+ // Else we're on the cover or table of contents (and can't tell which)
+ // but we can only get there through setting the chapter number
+ // so we don't need to do anything here
+}
+
static void
docready_cb (WebKitWebView *web_view,
WebKitLoadEvent load_event,
@@ -235,6 +258,7 @@ docready_cb (WebKitWebView *web_view,
if (load_event == WEBKIT_LOAD_FINISHED) {
reload_length_cb (GTK_WIDGET (widget), NULL, NULL);
+ set_current_chapter_by_uri (web_view);
}
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]