Skip to content

Commit

Permalink
ev-window.c: Don't create the epub webview until the doc type
Browse files Browse the repository at this point in the history
is known.

The EvWebView widget was being created and model set, only
to be destroyed later without being used if it turned out not
to be an epub document.

The model, when updated once the document was fully loaded, was
notifying the EvWebView as well as the EvView, with the former
throwing exceptions if the document wasn't compatible.
  • Loading branch information
mtwebster committed Dec 11, 2023
1 parent ffdad92 commit be4400f
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
4 changes: 4 additions & 0 deletions libview/ev-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -7431,6 +7431,10 @@ ev_view_previous_page (EvView *view)
void
ev_view_disconnect_handlers(EvView *view)
{
if (view->model == NULL) {
return;
}

g_signal_handlers_disconnect_by_func(view->model,
G_CALLBACK (ev_view_rotation_changed_cb),
view);
Expand Down
4 changes: 4 additions & 0 deletions libview/ev-web-view.c
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,10 @@ ev_web_view_zoom_reset(EvWebView *webview)
void
ev_web_view_disconnect_handlers(EvWebView *webview)
{
if (webview->model == NULL) {
return;
}

g_signal_handlers_disconnect_by_func(webview->model,
ev_web_view_document_changed_cb,
webview);
Expand Down
43 changes: 24 additions & 19 deletions shell/ev-window.c
Original file line number Diff line number Diff line change
Expand Up @@ -1516,22 +1516,32 @@ ev_window_set_document (EvWindow *ev_window,
gtk_widget_show (ev_window->priv->toolbar);

#if ENABLE_EPUB
if (document->iswebdocument == TRUE && ev_window->priv->view != NULL)
{
/*We have encountered a web document, replace the xreader view with a web view, if the web view is not already loaded.*/
gtk_container_remove (GTK_CONTAINER(ev_window->priv->scrolled_window), ev_window->priv->view);
ev_view_disconnect_handlers(EV_VIEW(ev_window->priv->view));
g_object_unref(ev_window->priv->view);
ev_window->priv->view = NULL;
if (document->iswebdocument) {
ev_window->priv->webview = ev_web_view_new();
ev_web_view_set_model(EV_WEB_VIEW(ev_window->priv->webview),ev_window->priv->model);

if (ev_window->priv->view != NULL)
{
/*We have encountered a web document, replace the xreader view with a web view, if the web view is not already loaded.*/
gtk_container_remove (GTK_CONTAINER(ev_window->priv->scrolled_window), ev_window->priv->view);
ev_view_disconnect_handlers(EV_VIEW(ev_window->priv->view));
g_object_unref(ev_window->priv->view);
ev_window->priv->view = NULL;
}

gtk_container_add (GTK_CONTAINER (ev_window->priv->scrolled_window), ev_window->priv->webview);
gtk_widget_show(ev_window->priv->webview);
}
else if(ev_window->priv->webview != NULL && document->iswebdocument == FALSE) {
/*Since the document is not a webdocument might as well get rid of the webview now*/
ev_web_view_disconnect_handlers(EV_WEB_VIEW(ev_window->priv->webview));
g_object_ref_sink(ev_window->priv->webview);
g_object_unref(ev_window->priv->webview);
ev_window->priv->webview = NULL;
} else
{
ev_view_set_model (EV_VIEW (ev_window->priv->view), ev_window->priv->model);

if (ev_window->priv->webview != NULL) {
/*Since the document is not a webdocument might as well get rid of the webview now*/
ev_web_view_disconnect_handlers(EV_WEB_VIEW(ev_window->priv->webview));
g_object_ref_sink(ev_window->priv->webview);
g_object_unref(ev_window->priv->webview);
ev_window->priv->webview = NULL;
}
}
#endif
if (EV_WINDOW_IS_PRESENTATION (ev_window) && document->iswebdocument == FALSE) {
Expand Down Expand Up @@ -7864,15 +7874,10 @@ ev_window_init (EvWindow *ev_window)

ev_window->priv->view = ev_view_new ();

#if ENABLE_EPUB /*The webview, we won't add it now but it will replace the xreader-view if a web(epub) document is encountered.*/
ev_window->priv->webview = ev_web_view_new();
ev_web_view_set_model(EV_WEB_VIEW(ev_window->priv->webview),ev_window->priv->model);
#endif
page_cache_mb = g_settings_get_uint (ev_window_ensure_settings (ev_window),
GS_PAGE_CACHE_SIZE);
ev_view_set_page_cache_size (EV_VIEW (ev_window->priv->view),
page_cache_mb * 1024 * 1024);
ev_view_set_model (EV_VIEW (ev_window->priv->view), ev_window->priv->model);

ev_window->priv->password_view = ev_password_view_new (GTK_WINDOW (ev_window));
g_signal_connect_swapped (ev_window->priv->password_view,
Expand Down

0 comments on commit be4400f

Please sign in to comment.