[libgepub/wip/cosimoc/api-rework: 13/13] widget: automatically reload chapter when current page changes
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [libgepub/wip/cosimoc/api-rework: 13/13] widget: automatically reload chapter when current page changes
- Date: Sat, 18 Jun 2016 21:13:47 +0000 (UTC)
commit 1495f30dc1d96d26533129b429e3f54d9de09123
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sat Jun 18 14:08:38 2016 -0700
widget: automatically reload chapter when current page changes
Instead of having the widget client manually call reload(), which has
now been made an internal method.
libgepub/gepub-widget.c | 52 ++++++++++++++++++++++++++--------------------
libgepub/gepub-widget.h | 2 -
tests/test-gepub.c | 2 -
3 files changed, 29 insertions(+), 27 deletions(-)
---
diff --git a/libgepub/gepub-widget.c b/libgepub/gepub-widget.c
index 9a3dfaa..7e7a239 100644
--- a/libgepub/gepub-widget.c
+++ b/libgepub/gepub-widget.c
@@ -183,6 +183,20 @@ gepub_widget_get_doc (GepubWidget *widget)
return widget->doc;
}
+static void
+reload_current_chapter (GepubWidget *widget)
+{
+ GBytes *current;
+
+ current = gepub_doc_get_current_with_epub_uris (widget->doc);
+ webkit_web_view_load_bytes (WEBKIT_WEB_VIEW (widget),
+ current,
+ gepub_doc_get_current_mime (widget->doc),
+ "UTF-8", NULL);
+
+ g_bytes_unref (current);
+}
+
/**
* gepub_widget_set_doc:
* @widget: a #GepubWidget
@@ -194,31 +208,23 @@ void
gepub_widget_set_doc (GepubWidget *widget,
GepubDoc *doc)
{
- if (g_set_object (&widget->doc, doc)) {
- gepub_widget_reload (widget);
- g_object_notify_by_pspec (G_OBJECT (widget), properties[PROP_DOC]);
- }
-}
+ if (widget->doc == doc)
+ return;
-/**
- * gepub_widget_reload:
- * @widget: a #GepubWidget
- *
- * This method reloads the data with the GepubDoc current chapter
- */
-void
-gepub_widget_reload (GepubWidget *widget)
-{
- GBytes *current;
+ if (widget->doc != NULL) {
+ g_signal_handlers_disconnect_by_func (widget->doc,
+ reload_current_chapter, widget);
+ g_object_unref (widget->doc);
+ }
- if (!widget->doc)
- return;
+ widget->doc = doc;
- current = gepub_doc_get_current_with_epub_uris (widget->doc);
- webkit_web_view_load_bytes (WEBKIT_WEB_VIEW (widget),
- current,
- gepub_doc_get_current_mime (widget->doc),
- "UTF-8", NULL);
+ if (widget->doc != NULL) {
+ g_object_ref (widget->doc);
+ reload_current_chapter (widget);
+ g_signal_connect_swapped (widget->doc, "notify::page",
+ G_CALLBACK (reload_current_chapter), widget);
+ }
- g_bytes_unref (current);
+ g_object_notify_by_pspec (G_OBJECT (widget), properties[PROP_DOC]);
}
diff --git a/libgepub/gepub-widget.h b/libgepub/gepub-widget.h
index 4be7585..b77cc6a 100644
--- a/libgepub/gepub-widget.h
+++ b/libgepub/gepub-widget.h
@@ -46,8 +46,6 @@ GepubDoc *gepub_widget_get_doc (GepubWidget *wid
void gepub_widget_set_doc (GepubWidget *widget,
GepubDoc *doc);
-void gepub_widget_reload (GepubWidget *widget);
-
G_END_DECLS
#endif /* __GEPUB_WIDGET_H__ */
diff --git a/tests/test-gepub.c b/tests/test-gepub.c
index ff78f49..20048d4 100644
--- a/tests/test-gepub.c
+++ b/tests/test-gepub.c
@@ -77,8 +77,6 @@ button_pressed (GtkButton *button, GepubWidget *widget)
}
update_text (doc);
print_replaced_text (doc);
-
- gepub_widget_reload (widget);
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]