From 31a1e800e5d6b24d8833ba28746b7ff6f2fbe6a9 Mon Sep 17 00:00:00 2001 From: Carlos Garcia Campos Date: Mon, 16 Jun 2008 17:52:59 +0000 Subject: [PATCH] Do not crash opening documents with no pages and show a warning message in 2008-06-16 Carlos Garcia Campos * backend/pdf/ev-poppler.cc: (pdf_document_get_info): * shell/ev-sidebar-thumbnails.c: (ev_sidebar_thumbnails_set_loading_icon), (ev_sidebar_thumbnails_refresh): * shell/ev-window.c: (ev_window_error_message), (ev_window_warning_message), (ev_window_refresh_window_thumbnail), (ev_window_set_document): Do not crash opening documents with no pages and show a warning message in the message area. Fixes bugs #537574 and #171588. svn path=/trunk/; revision=3052 --- ChangeLog | 13 +++++++++++++ backend/pdf/ev-poppler.cc | 23 +++++++++++++---------- shell/ev-sidebar-thumbnails.c | 6 ++++-- shell/ev-window.c | 35 ++++++++++++++++++++++++++++++----- 4 files changed, 60 insertions(+), 17 deletions(-) diff --git a/ChangeLog b/ChangeLog index 072b0e72..411a9fa2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2008-06-16 Carlos Garcia Campos + + * backend/pdf/ev-poppler.cc: (pdf_document_get_info): + * shell/ev-sidebar-thumbnails.c: + (ev_sidebar_thumbnails_set_loading_icon), + (ev_sidebar_thumbnails_refresh): + * shell/ev-window.c: (ev_window_error_message), + (ev_window_warning_message), (ev_window_refresh_window_thumbnail), + (ev_window_set_document): + + Do not crash opening documents with no pages and show a warning + message in the message area. Fixes bugs #537574 and #171588. + 2008-06-15 Carlos Garcia Campos * shell/Makefile.am: diff --git a/backend/pdf/ev-poppler.cc b/backend/pdf/ev-poppler.cc index 2b6d4159..04f4c650 100644 --- a/backend/pdf/ev-poppler.cc +++ b/backend/pdf/ev-poppler.cc @@ -590,15 +590,20 @@ pdf_document_get_info (EvDocument *document) "linearized", &(info->linearized), NULL); - page = ev_document_get_page (document, 0); - ev_document_get_page_size (document, page, - &(info->paper_width), - &(info->paper_height)); - g_object_unref (page); + info->n_pages = ev_document_get_n_pages (document); - // Convert to mm. - info->paper_width = info->paper_width / 72.0f * 25.4f; - info->paper_height = info->paper_height / 72.0f * 25.4f; + if (info->n_pages > 0) { + page = ev_document_get_page (document, 0); + ev_document_get_page_size (document, page, + &(info->paper_width), + &(info->paper_height)); + g_object_unref (page); + + + // Convert to mm. + info->paper_width = info->paper_width / 72.0f * 25.4f; + info->paper_height = info->paper_height / 72.0f * 25.4f; + } switch (layout) { case POPPLER_PAGE_LAYOUT_SINGLE_PAGE: @@ -678,8 +683,6 @@ pdf_document_get_info (EvDocument *document) info->permissions |= EV_DOCUMENT_PERMISSIONS_OK_TO_ADD_NOTES; } - info->n_pages = ev_document_get_n_pages (document); - if (ev_document_security_has_document_security (EV_DOCUMENT_SECURITY (document))) { /* translators: this is the document security state */ info->security = g_strdup (_("Yes")); diff --git a/shell/ev-sidebar-thumbnails.c b/shell/ev-sidebar-thumbnails.c index 25b1b838..74b4ab73 100644 --- a/shell/ev-sidebar-thumbnails.c +++ b/shell/ev-sidebar-thumbnails.c @@ -403,7 +403,8 @@ ev_sidebar_thumbnails_set_loading_icon (EvSidebarThumbnails *sidebar_thumbnails) if (sidebar_thumbnails->priv->loading_icon) g_object_unref (sidebar_thumbnails->priv->loading_icon); - if (sidebar_thumbnails->priv->document) { + if (sidebar_thumbnails->priv->document && + sidebar_thumbnails->priv->n_pages > 0) { gint width, height; /* We get the dimensions of the first page so that we can make a blank @@ -434,7 +435,8 @@ ev_sidebar_thumbnails_refresh (EvSidebarThumbnails *sidebar_thumbnails, sidebar_thumbnails->priv->rotation = rotation; ev_sidebar_thumbnails_set_loading_icon (sidebar_thumbnails); - if (sidebar_thumbnails->priv->document == NULL) + if (sidebar_thumbnails->priv->document == NULL || + sidebar_thumbnails->priv->n_pages <= 0) return; ev_sidebar_thumbnails_clear_model (sidebar_thumbnails); diff --git a/shell/ev-window.c b/shell/ev-window.c index dd2947ff..81efe3d7 100644 --- a/shell/ev-window.c +++ b/shell/ev-window.c @@ -631,9 +631,9 @@ ev_window_set_message_area (EvWindow *window, } static void -ev_window_error_message_response_cb (EvMessageArea *area, - gint response_id, - EvWindow *window) +ev_window_message_area_response_cb (EvMessageArea *area, + gint response_id, + EvWindow *window) { ev_window_set_message_area (window, NULL); } @@ -654,7 +654,28 @@ ev_window_error_message (GtkWindow *window, const gchar *msg, GError *error) if (error) ev_message_area_set_secondary_text (EV_MESSAGE_AREA (area), error->message); g_signal_connect (area, "response", - G_CALLBACK (ev_window_error_message_response_cb), + G_CALLBACK (ev_window_message_area_response_cb), + window); + gtk_widget_show (area); + ev_window_set_message_area (EV_WINDOW (window), area); +} + +static void +ev_window_warning_message (GtkWindow *window, const gchar *msg) +{ + GtkWidget *area; + + if (EV_WINDOW (window)->priv->message_area) + return; + + area = ev_message_area_new (GTK_MESSAGE_WARNING, + msg, + GTK_STOCK_CLOSE, + GTK_RESPONSE_CANCEL, + NULL); + + g_signal_connect (area, "response", + G_CALLBACK (ev_window_message_area_response_cb), window); gtk_widget_show (area); ev_window_set_message_area (EV_WINDOW (window), area); @@ -1085,7 +1106,8 @@ ev_window_refresh_window_thumbnail (EvWindow *ev_window, int rotation) gdouble scale; EvDocument *document = ev_window->priv->document; - if (!EV_IS_DOCUMENT_THUMBNAILS (document)) { + if (!EV_IS_DOCUMENT_THUMBNAILS (document) || + ev_page_cache_get_n_pages (ev_window->priv->page_cache) <= 0) { return; } @@ -1170,6 +1192,9 @@ ev_window_set_document (EvWindow *ev_window, EvDocument *document) if (ev_page_cache_get_n_pages (ev_window->priv->page_cache) > 0) { ev_view_set_document (view, document); + } else { + ev_window_warning_message (GTK_WINDOW (ev_window), + _("The document contains no pages")); } g_idle_add ((GSourceFunc)ev_window_setup_document, ev_window); -- 2.43.5