]> www.fi.muni.cz Git - evince.git/commitdiff
Do not crash opening documents with no pages and show a warning message in
authorCarlos Garcia Campos <carlosgc@gnome.org>
Mon, 16 Jun 2008 17:52:59 +0000 (17:52 +0000)
committerCarlos Garcia Campos <carlosgc@src.gnome.org>
Mon, 16 Jun 2008 17:52:59 +0000 (17:52 +0000)
2008-06-16  Carlos Garcia Campos  <carlosgc@gnome.org>

* 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
backend/pdf/ev-poppler.cc
shell/ev-sidebar-thumbnails.c
shell/ev-window.c

index 072b0e72cf77521a6c4cf7f4b5f5985e516b6c48..411a9fa23082b0c9a09072cfe2466aac9dd5fb87 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,16 @@
+2008-06-16  Carlos Garcia Campos  <carlosgc@gnome.org>
+
+       * 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  <carlosgc@gnome.org>
 
        * shell/Makefile.am:
index 2b6d41597bc4a11fe2c2a4513956c9634d06ed91..04f4c650a22f9a4a12088ec3bdf67dfaeacd53d8 100644 (file)
@@ -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"));
index 25b1b838e0820f49eae06733aba20264b9a9bd55..74b4ab73d00b1609f8fc28674e0a892c9dda10d4 100644 (file)
@@ -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);
index dd2947fff01d5a44a701c5dddce167b9a0a89ef9..81efe3d78b83bfc0573b79cebbcf335ac8f22d90 100644 (file)
@@ -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);