fix invalid cast runtime warning
[claws.git] / src / plugins / pdf_viewer / poppler_viewer.c
index df66fa5..5df4661 100644 (file)
@@ -1,13 +1,11 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright(C) 1999-2007 the Claws Mail Team
- * This file Copyright (C) 2007 Salvatore De Paolis 
- * <iwkse@claws-mail.org> 
+ * Copyright (C) 1999-2016 Salvatore De Paolis & the Claws Mail Team
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * the Free Software Foundation; either version 3 of the License, or
- *(at your option) any later version.
+ * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -15,8 +13,7 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
  */
 
 #ifdef HAVE_CONFIG_H
 #include "printing.h"
 #include "prefs_common.h"
 #include "gtk/gtkutils.h"
+#include "gtk/inputdialog.h"
 #include "mimeview.h"
+#include "summaryview.h"
+#include "file-utils.h"
 #ifndef POPPLER_WITH_GDK
 #include "stdbool.h"
 #endif
@@ -83,14 +83,15 @@ static void pdf_viewer_button_rotate_left_cb(GtkButton *button, PdfViewer *viewe
 static void pdf_viewer_spin_change_page_cb(GtkSpinButton *button, PdfViewer *viewer);
 static void pdf_viewer_spin_zoom_scroll_cb(GtkSpinButton *button, PdfViewer *viewer);
 /* Show/Hide the index pane */
-static void pdf_viewer_show_document_index_cb(GtkButton *button, PdfViewer *viewer);
+static void pdf_viewer_show_document_index_cb(GtkToggleButton *button, PdfViewer *viewer);
+static void pdf_viewer_button_print_cb(GtkButton *button, PdfViewer *viewer);
 static void pdf_viewer_button_document_info_cb(GtkButton *button, PdfViewer *viewer);
 
 static void pdf_viewer_show_controls(PdfViewer *viewer, gboolean show);
 static gboolean pdf_viewer_scroll_page(MimeViewer *_viewer, gboolean up);
 static void pdf_viewer_scroll_one_line(MimeViewer *_viewer, gboolean up);
 
-/** Claws-Mail Plugin functions*/
+/** Claws Mail Plugin functions */
 gint plugin_init(gchar **error);
 const gchar *plugin_name(void);
 const gchar *plugin_desc(void);
@@ -273,24 +274,26 @@ static void pdf_viewer_scroll_to(PdfViewer *viewer, gfloat x, gfloat y)
        vadj = gtk_scrolled_window_get_vadjustment(
                GTK_SCROLLED_WINDOW(viewer->scrollwin));
 
-       if (y < vadj->value) {
-               vadj->value = y;
+       if (y < gtk_adjustment_get_value(vadj)) {
+               gtk_adjustment_set_value(vadj, y);
        }
        else {
-               while(y > vadj->value + vadj->page_size) {
-                       vadj->value += vadj->page_size;
+               while(y > gtk_adjustment_get_value(vadj) + gtk_adjustment_get_page_size(vadj)) {
+                       gtk_adjustment_set_value(vadj,
+                                       gtk_adjustment_get_value(vadj) + gtk_adjustment_get_page_size(vadj));
                }
        }
 
        hadj = gtk_scrolled_window_get_hadjustment(
                GTK_SCROLLED_WINDOW(viewer->scrollwin));
 
-       if (x < hadj->value) {
-               hadj->value = x;
+       if (x < gtk_adjustment_get_value(hadj)) {
+               gtk_adjustment_set_value(hadj, x);
        }
        else {
-               while(x > hadj->value + hadj->page_size) {
-                       hadj->value += hadj->page_size;
+               while(x > gtk_adjustment_get_value(hadj) + gtk_adjustment_get_page_size(hadj)) {
+                       gtk_adjustment_set_value(hadj,
+                                       gtk_adjustment_get_value(hadj) + gtk_adjustment_get_page_size(hadj));
                }
        }
 
@@ -447,7 +450,7 @@ static gboolean     pdf_viewer_text_search(MimeViewer *_viewer, gboolean backward,
                        if (viewer->page_results != NULL) {
                                debug_print("page_results %p\n", viewer->page_results);
                                /* store results for this page */
-                               gint num_res = 0;
+                               guint num_res = 0;
                                PageResult *res = g_new0(PageResult, 1);
                                res->results = viewer->page_results;
                                res->page_num = i;
@@ -556,7 +559,7 @@ static void pdf_viewer_get_document_index(PdfViewer *viewer, PopplerIndexIter *i
                        PopplerDest *dest = poppler_document_find_dest(
                                        viewer->pdf_doc, action->goto_dest.dest->named_dest);
                        if (dest->type != POPPLER_DEST_XYZ) {
-                               g_warning("couldn't figure out link\n");
+                               g_warning("couldn't figure out link");
                                poppler_dest_free(dest);
                                continue;
                        }
@@ -566,9 +569,9 @@ static void pdf_viewer_get_document_index(PdfViewer *viewer, PopplerIndexIter *i
 #endif
                else {
 #ifdef HAVE_POPPLER_DEST_NAMED
-                       g_warning("unhandled link type %d\nplease contact developers\n", action->goto_dest.dest->type);
+                       g_warning("unhandled link type %d. please contact developers", action->goto_dest.dest->type);
 #else
-                       g_warning("unhandled link type %d\nplease upgrade libpoppler-glib to 0.5.4\n", action->goto_dest.dest->type);
+                       g_warning("unhandled link type %d. please upgrade libpoppler-glib to 0.5.4", action->goto_dest.dest->type);
 #endif
                        continue;
                }
@@ -813,6 +816,7 @@ static void pdf_viewer_button_zoom_out_cb(GtkButton *button, PdfViewer *viewer)
 static void pdf_viewer_button_press_events_cb(GtkWidget *widget, GdkEventButton *event, PdfViewer *viewer) 
 {
        gchar *uri;
+       GdkWindow *gdkwin;
        #ifdef HAVE_POPPLER_DEST_NAMED
        PopplerDest *dest;
        #endif
@@ -837,7 +841,7 @@ static void pdf_viewer_button_press_events_cb(GtkWidget *widget, GdkEventButton
                                dest = poppler_document_find_dest(
                                        viewer->pdf_doc, viewer->link_action->goto_dest.dest->named_dest);
                        if (dest->type != POPPLER_DEST_XYZ) {
-                               g_warning("couldn't figure out link\n");
+                               g_warning("couldn't figure out link");
                                poppler_dest_free(dest);
                                break;
                        }
@@ -852,7 +856,7 @@ static void pdf_viewer_button_press_events_cb(GtkWidget *widget, GdkEventButton
                        dest = poppler_document_find_dest(
                                        viewer->pdf_doc, viewer->link_action->goto_remote.dest->named_dest);
                        if (dest->type != POPPLER_DEST_XYZ) {
-                               g_warning ("couldn't figure out link\n");
+                               g_warning ("couldn't figure out link");
                                poppler_dest_free(dest);
                                break;
                        }
@@ -878,10 +882,10 @@ static void pdf_viewer_button_press_events_cb(GtkWidget *widget, GdkEventButton
                case POPPLER_ACTION_NONE:
                        debug_print("action none does nothing, surprise!\n");
                        break;
-#if POPPLER_CHECK_VERSION(0,14,0)
                case POPPLER_ACTION_MOVIE:
                        debug_print("yoyoyo ;-) a movie?\n");
                        break;
+#if POPPLER_CHECK_VERSION(0,14,0)
                case POPPLER_ACTION_RENDITION:
                        debug_print("yoyoyo ;-) multimedia?\n");
                        break;
@@ -898,10 +902,10 @@ static void pdf_viewer_button_press_events_cb(GtkWidget *widget, GdkEventButton
                if (((MimeViewer *)viewer)->mimeview && 
                        ((MimeViewer *)viewer)->mimeview->messageview && 
                        ((MimeViewer *)viewer)->mimeview->messageview->window && 
-                       ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
-                       gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, NULL);
+                       (gdkwin = gtk_widget_get_window(((MimeViewer *)viewer)->mimeview->messageview->window)) != NULL)
+                       gdk_window_set_cursor (gdkwin, NULL);
                else
-                       gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, NULL);
+                       gdk_window_set_cursor (gtk_widget_get_window(mainwindow_get_mainwindow()->window), NULL);
        }
 
        /* Init document to be scrolled with left mouse click */
@@ -910,10 +914,10 @@ static void pdf_viewer_button_press_events_cb(GtkWidget *widget, GdkEventButton
                if (((MimeViewer *)viewer)->mimeview && 
                        ((MimeViewer *)viewer)->mimeview->messageview && 
                        ((MimeViewer *)viewer)->mimeview->messageview->window && 
-                       ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
-                       gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, hand_cur);
+                       (gdkwin = gtk_widget_get_window(((MimeViewer *)viewer)->mimeview->messageview->window)) != NULL)
+                       gdk_window_set_cursor (gdkwin, hand_cur);
                else
-                       gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, hand_cur);
+                       gdk_window_set_cursor (gtk_widget_get_window(mainwindow_get_mainwindow()->window), hand_cur);
 
                viewer->last_x = event->x;
                viewer->last_y = event->y;
@@ -924,21 +928,24 @@ static void pdf_viewer_button_press_events_cb(GtkWidget *widget, GdkEventButton
 /* Set the normal cursor*/
 static void pdf_viewer_mouse_scroll_destroy_cb(GtkWidget *widget, GdkEventButton *event, PdfViewer *viewer) 
 {
+       GdkWindow *gdkwin;
 
        if (event->button == 1) {
                viewer->pdf_view_scroll = FALSE;
                if (((MimeViewer *)viewer)->mimeview && 
                        ((MimeViewer *)viewer)->mimeview->messageview && 
                        ((MimeViewer *)viewer)->mimeview->messageview->window && 
-                       ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
-                       gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, NULL);
+                       (gdkwin = gtk_widget_get_window(((MimeViewer *)viewer)->mimeview->messageview->window)) != NULL)
+                       gdk_window_set_cursor (gdkwin, NULL);
                else
-                       gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, NULL);
+                       gdk_window_set_cursor (gtk_widget_get_window(mainwindow_get_mainwindow()->window), NULL);
        }
 }
 
 static void pdf_viewer_move_events_cb(GtkWidget *widget, GdkEventMotion *event, PdfViewer *viewer) 
 {
+       GdkWindow *gdkwin;
+
        /* Grab the document and scroll it with mouse */ 
        if (viewer->pdf_view_scroll) {
 
@@ -946,18 +953,24 @@ static void pdf_viewer_move_events_cb(GtkWidget *widget, GdkEventMotion *event,
                viewer->pdf_view_hadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
 
                        if (event->x < viewer->last_x
-                                       && viewer->pdf_view_hadj->value < (viewer->pdf_view_hadj->upper - viewer->pdf_view_hadj->page_size)) {
+                                       && gtk_adjustment_get_value(viewer->pdf_view_hadj) < (gtk_adjustment_get_upper(viewer->pdf_view_hadj) - gtk_adjustment_get_page_size(viewer->pdf_view_hadj))) {
                                if (viewer->last_dir_x == -1) {
-                                       viewer->pdf_view_hadj->value += viewer->last_x - event->x; 
+                                       gtk_adjustment_set_value(viewer->pdf_view_hadj,
+                                                       gtk_adjustment_get_value(viewer->pdf_view_hadj)
+                                                       + viewer->last_x
+                                                       - event->x);
                                        g_signal_emit_by_name(G_OBJECT(viewer->pdf_view_hadj),
                                                                "value_changed", 0);
                                }
                                viewer->last_dir_x = -1;
                        }
                        else if (event->x > viewer->last_x
-                                       && viewer->pdf_view_hadj->value > 0.0)  {
+                                       && gtk_adjustment_get_value(viewer->pdf_view_hadj) > 0.0)  {
                                if (viewer->last_dir_x == +1) {
-                                       viewer->pdf_view_hadj->value += viewer->last_x - event->x; 
+                                       gtk_adjustment_set_value(viewer->pdf_view_hadj,
+                                                       gtk_adjustment_get_value(viewer->pdf_view_hadj)
+                                                       + viewer->last_x
+                                                       - event->x);
                                        g_signal_emit_by_name(G_OBJECT(viewer->pdf_view_hadj),
                                                                "value_changed", 0);
                                }
@@ -965,18 +978,24 @@ static void pdf_viewer_move_events_cb(GtkWidget *widget, GdkEventMotion *event,
                        }
 
                        if (event->y < viewer->last_y
-                                       && viewer->pdf_view_vadj->value < (viewer->pdf_view_vadj->upper - viewer->pdf_view_vadj->page_size)) {
+                                       && gtk_adjustment_get_value(viewer->pdf_view_vadj) < (gtk_adjustment_get_upper(viewer->pdf_view_vadj) - gtk_adjustment_get_page_size(viewer->pdf_view_vadj))) {
                                if (viewer->last_dir_y == -1) {
-                                       viewer->pdf_view_vadj->value += viewer->last_y - event->y; 
+                                       gtk_adjustment_set_value(viewer->pdf_view_vadj,
+                                                       gtk_adjustment_get_value(viewer->pdf_view_vadj)
+                                                       + viewer->last_y
+                                                       - event->y);
                                        g_signal_emit_by_name(G_OBJECT(viewer->pdf_view_vadj),
                                                                "value_changed", 0);
                                }
                                viewer->last_dir_y = -1;
                        }
                        else if (event->y > viewer->last_y
-                                       && viewer->pdf_view_vadj->value > 0.0)  {
+                                       && gtk_adjustment_get_value(viewer->pdf_view_vadj) > 0.0)  {
                                if (viewer->last_dir_y == +1) {
-                                       viewer->pdf_view_vadj->value += viewer->last_y - event->y; 
+                                       gtk_adjustment_set_value(viewer->pdf_view_vadj,
+                                                       gtk_adjustment_get_value(viewer->pdf_view_vadj)
+                                                       + viewer->last_y
+                                                       - event->y);
                                        g_signal_emit_by_name(G_OBJECT(viewer->pdf_view_vadj),
                                                                "value_changed", 0);
                                }
@@ -1002,6 +1021,7 @@ static void pdf_viewer_move_events_cb(GtkWidget *widget, GdkEventMotion *event,
        ccur = FALSE;
        viewer->in_link = FALSE;        
        for (l = viewer->link_map; l; l = g_list_next (l)) {
+               gint upper;
                PopplerLinkMapping *lmapping;
                lmapping = (PopplerLinkMapping *)l->data;
 
@@ -1011,39 +1031,40 @@ static void pdf_viewer_move_events_cb(GtkWidget *widget, GdkEventMotion *event,
                y2 = lmapping->area.y2;
                gtk_widget_size_request(viewer->pdf_view, &size);
 
+               upper = gtk_adjustment_get_upper(viewer->pdf_view_hadj);
                switch (viewer->rotate) {
                case 0:
                case 360:
-                               if (size.width != viewer->pdf_view_hadj->upper)
-                                       x = (event->x - (viewer->pdf_view_hadj->upper - size.width) / 2) / viewer->zoom;
+                               if (size.width != upper)
+                                       x = (event->x - (upper - size.width) / 2) / viewer->zoom;
                                else
                                        x = event->x / viewer->zoom;
 
-                               y = (viewer->pdf_view_vadj->upper - event->y) / viewer->zoom;
+                               y = (upper - event->y) / viewer->zoom;
                        break;
                case 90:
-                               if (size.width != viewer->pdf_view_hadj->upper)
-                                       y = (event->x - (viewer->pdf_view_hadj->upper - size.width) / 2) / viewer->zoom;
+                               if (size.width != upper)
+                                       y = (event->x - (upper - size.width) / 2) / viewer->zoom;
                                else
                                        y = event->x / viewer->zoom;
 
                                x = (event->y) / viewer->zoom;
                        break;
                case 180:
-                               if (size.width != viewer->pdf_view_hadj->upper)
-                                       x = ((viewer->pdf_view_hadj->upper -  event->x) - ((viewer->pdf_view_hadj->upper - size.width) / 2)) / viewer->zoom;
+                               if (size.width != upper)
+                                       x = ((upper -  event->x) - ((upper - size.width) / 2)) / viewer->zoom;
                                else
-                                       x =  ((viewer->pdf_view_hadj->upper -  event->x) - (viewer->pdf_view_hadj->upper - size.width)) / viewer->zoom;
+                                       x =  ((upper -  event->x) - (upper - size.width)) / viewer->zoom;
 
                                y = (event->y) / viewer->zoom;
                        break;
                case 270:
-                               if (size.width != viewer->pdf_view_hadj->upper)
-                                       y = ((viewer->pdf_view_hadj->upper -  event->x) - ((viewer->pdf_view_hadj->upper - size.width) / 2)) / viewer->zoom;
+                               if (size.width != upper)
+                                       y = ((upper -  event->x) - ((upper - size.width) / 2)) / viewer->zoom;
                                else
-                                       y =  ((viewer->pdf_view_hadj->upper -  event->x) - (viewer->pdf_view_hadj->upper - size.width)) / viewer->zoom;
+                                       y =  ((upper -  event->x) - (upper - size.width)) / viewer->zoom;
 
-                               x = (viewer->pdf_view_vadj->upper - event->y) / viewer->zoom;
+                               x = (upper - event->y) / viewer->zoom;
                        break;
                }
 
@@ -1052,10 +1073,10 @@ static void pdf_viewer_move_events_cb(GtkWidget *widget, GdkEventMotion *event,
                        if (((MimeViewer *)viewer)->mimeview && 
                                ((MimeViewer *)viewer)->mimeview->messageview && 
                                ((MimeViewer *)viewer)->mimeview->messageview->window && 
-                               ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
-                                       gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, link_cur);
+                               (gdkwin = gtk_widget_get_window(((MimeViewer *)viewer)->mimeview->messageview->window)) != NULL)
+                                       gdk_window_set_cursor (gdkwin, link_cur);
                                else
-                                       gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, link_cur);
+                                       gdk_window_set_cursor (gtk_widget_get_window(mainwindow_get_mainwindow()->window), link_cur);
 
                                viewer->link_action = lmapping->action; 
                                ccur = TRUE;
@@ -1064,10 +1085,10 @@ static void pdf_viewer_move_events_cb(GtkWidget *widget, GdkEventMotion *event,
                        if (((MimeViewer *)viewer)->mimeview && 
                                ((MimeViewer *)viewer)->mimeview->messageview && 
                                ((MimeViewer *)viewer)->mimeview->messageview->window && 
-                               ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
-                               gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, NULL);
+                               (gdkwin = gtk_widget_get_window(((MimeViewer *)viewer)->mimeview->messageview->window)) != NULL)
+                               gdk_window_set_cursor (gdkwin, NULL);
                        else
-                               gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, NULL);
+                               gdk_window_set_cursor (gtk_widget_get_window(mainwindow_get_mainwindow()->window), NULL);
                }
        }
        g_free(l);
@@ -1086,17 +1107,28 @@ static gboolean pdf_viewer_scroll_cb(GtkWidget *widget, GdkEventScroll *event,
 
        in_scroll_cb = TRUE;
 
+       if ((event->state & GDK_CONTROL_MASK) == GDK_CONTROL_MASK) {
+               if (event->direction == GDK_SCROLL_UP) {
+                       pdf_viewer_button_zoom_in_cb(NULL, viewer);
+               } else {
+                       pdf_viewer_button_zoom_out_cb(NULL, viewer);
+               }
+               in_scroll_cb = FALSE;
+               return TRUE;
+       }
+
        if (event->direction == GDK_SCROLL_UP &&
-           adj->value == adj->lower && 
+           gtk_adjustment_get_value(adj) == gtk_adjustment_get_lower(adj) &&
            cur_p > 1) {
                gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_BACKWARD, 1);
-               adj->value = adj->upper - adj->page_size;
+               gtk_adjustment_set_value(adj,
+                               gtk_adjustment_get_upper(adj) - gtk_adjustment_get_page_size(adj));
                handled = TRUE;
        } else if (event->direction == GDK_SCROLL_DOWN &&
-           adj->value + adj->page_size == adj->upper &&
+           gtk_adjustment_get_value(adj) + gtk_adjustment_get_page_size(adj) == gtk_adjustment_get_upper(adj) &&
            cur_p < viewer->num_pages) {
                gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_FORWARD, 1);
-               adj->value = 0.0;
+               gtk_adjustment_set_value(adj, 0.0);
                handled = TRUE;
        }
        in_scroll_cb = FALSE;
@@ -1105,13 +1137,13 @@ static gboolean pdf_viewer_scroll_cb(GtkWidget *widget, GdkEventScroll *event,
 
 static void pdf_viewer_button_zoom_fit_cb(GtkButton *button, PdfViewer *viewer)
 {
-       GtkAllocation *allocation;
+       GtkAllocation allocation;
        double xratio, yratio;
-       allocation = &(viewer->scrollwin->allocation);
-       debug_print("width: %d\n", allocation->width);
-       debug_print("height: %d\n", allocation->height);
-       xratio = allocation->width / viewer->width;
-       yratio = allocation->height / viewer->height;
+       gtk_widget_get_allocation(viewer->scrollwin, &allocation);
+       debug_print("width: %d\n", allocation.width);
+       debug_print("height: %d\n", allocation.height);
+       xratio = allocation.width / viewer->width;
+       yratio = allocation.height / viewer->height;
 
        if (xratio >= yratio) {
                viewer->zoom = yratio;
@@ -1125,11 +1157,11 @@ static void pdf_viewer_button_zoom_fit_cb(GtkButton *button, PdfViewer *viewer)
 
 static void pdf_viewer_button_zoom_width_cb(GtkButton *button, PdfViewer *viewer)
 {
-       GtkAllocation *allocation;
+       GtkAllocation allocation;
        double xratio;
-       allocation = &(viewer->scrollwin->allocation);
-       debug_print("width: %d\n", allocation->width);
-       xratio = allocation->width / viewer->width;
+       gtk_widget_get_allocation(viewer->scrollwin, &allocation);
+       debug_print("width: %d\n", allocation.width);
+       xratio = allocation.width / viewer->width;
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->zoom_scroll), xratio);
 }
 
@@ -1156,7 +1188,7 @@ static void pdf_viewer_button_rotate_left_cb(GtkButton *button, PdfViewer *viewe
 }
 
 /* Show/Hide the index pane */
-static void pdf_viewer_show_document_index_cb(GtkButton *button, PdfViewer *viewer)
+static void pdf_viewer_show_document_index_cb(GtkToggleButton *button, PdfViewer *viewer)
 {
        if (!viewer->pdf_index) {
                viewer->pdf_index = poppler_index_iter_new(viewer->pdf_doc);
@@ -1174,11 +1206,18 @@ static void pdf_viewer_show_document_index_cb(GtkButton *button, PdfViewer *view
 
 }
 
+static void pdf_viewer_button_print_cb(GtkButton *button, PdfViewer *viewer)
+{
+       MainWindow *mainwin = mainwindow_get_mainwindow();
+       summary_print(mainwin->summaryview);
+}
+
 static void pdf_viewer_button_document_info_cb(GtkButton *button, PdfViewer *viewer)
 {
        alertpanel_full(_("PDF properties"), NULL, GTK_STOCK_CLOSE, NULL, NULL,
-                       FALSE, (GtkWidget *) pdf_viewer_fill_info_table(viewer), 
-                       ALERT_NOTICE, G_ALERTDEFAULT);
+                       ALERTFOCUS_FIRST, FALSE,
+                       GTK_WIDGET(pdf_viewer_fill_info_table(viewer)), 
+                       ALERT_NOTICE);
 }
 
 /*
@@ -1214,6 +1253,7 @@ static void pdf_viewer_show_controls(PdfViewer *viewer, gboolean show)
                gtk_widget_show(viewer->widgets_table);
                gtk_widget_show(viewer->rotate_right);
                gtk_widget_show(viewer->rotate_left);
+               gtk_widget_show(viewer->print);
                gtk_widget_show(viewer->doc_info);
                gtk_widget_show(viewer->doc_index);
        } else {
@@ -1226,12 +1266,13 @@ static void pdf_viewer_show_controls(PdfViewer *viewer, gboolean show)
                gtk_widget_hide(viewer->zoom_out);
                gtk_widget_hide(viewer->zoom_fit);
                gtk_widget_hide(viewer->zoom_width);
+               gtk_widget_hide(viewer->zoom_scroll);
                gtk_widget_hide(viewer->widgets_table);
                gtk_widget_hide(viewer->rotate_right);
                gtk_widget_hide(viewer->rotate_left);
+               gtk_widget_hide(viewer->print);
                gtk_widget_hide(viewer->doc_info);
                gtk_widget_hide(viewer->doc_index);
-               gtk_widget_hide(viewer->zoom_scroll);
        }
 }
 /** Render the current page, page_num on the viewer */
@@ -1239,13 +1280,13 @@ static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int pag
 {
 
        PdfViewer *viewer = (PdfViewer *) _viewer;
-       GError *error;
+       GError *error = NULL;
        gchar *tmpfile = NULL;
        gchar *tmp;
+       gchar *password = NULL;
 
        debug_print("pdf_viewer_update\n");
 
-       error = NULL;
        if (reload_file) {
                if (viewer->pdf_doc) {
                        g_object_unref(G_OBJECT(viewer->pdf_doc));
@@ -1253,22 +1294,19 @@ static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int pag
                }
 
                if (pdf_viewer_mimepart_get_type(viewer->to_load) == TYPE_PS) {
-                       stock_pixbuf_gdk(viewer->hbox, 
-                                       STOCK_PIXMAP_MIME_PS, 
+                       stock_pixbuf_gdk(STOCK_PIXMAP_MIME_PS, 
                                        &viewer->icon_pixbuf);
                        gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type),
                                                                        viewer->icon_pixbuf);
                } 
                else if (pdf_viewer_mimepart_get_type(viewer->to_load) == TYPE_PDF) {
-                       stock_pixbuf_gdk(viewer->hbox, 
-                       STOCK_PIXMAP_MIME_PDF, 
+                       stock_pixbuf_gdk(STOCK_PIXMAP_MIME_PDF, 
                        &viewer->icon_pixbuf);
                        gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type), 
                                                                        viewer->icon_pixbuf);
                } 
                else {
-                       stock_pixbuf_gdk(viewer->hbox, 
-                       STOCK_PIXMAP_MIME_APPLICATION, 
+                       stock_pixbuf_gdk(STOCK_PIXMAP_MIME_APPLICATION, 
                        &viewer->icon_pixbuf);
                        gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type), 
                                                                        viewer->icon_pixbuf);
@@ -1292,14 +1330,14 @@ static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int pag
                                        "gs -dSAFER -dCompatibilityLevel=1.2 -q -dNOPAUSE -dBATCH "
                                          "-sDEVICE=pdfwrite -sOutputFile=%s -c .setpdfwrite -f \"%s\"",
                                        tmpfile, viewer->filename);
-                               result = execute_command_line(cmdline, FALSE);
+                               result = execute_command_line(cmdline, FALSE, NULL);
                                if (result == 0) {
                                        tmp = g_filename_to_uri(tmpfile, NULL, NULL);
                                        viewer->pdf_doc = poppler_document_new_from_file( tmp, NULL, &error);
                                        g_free(tmp);
                                } 
                                else {
-                                       g_warning("gs conversion failed: %s returned %d\n", cmdline, result);
+                                       g_warning("gs conversion failed: %s returned %d", cmdline, result);
                                        tmp = g_strdup_printf("gs: err %d", result);
                                        alertpanel_warning("%s", tmp);
                                        g_free(tmp);
@@ -1310,7 +1348,7 @@ static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int pag
                                g_free(tmpfile);
                        }
                        else {
-                               g_warning("gs conversion disabled: gs binary was not found\n");
+                               g_warning("gs conversion disabled: gs binary was not found");
                                alertpanel_warning("PostScript view disabled: required gs program not found");
                                result = 1;
 
@@ -1323,6 +1361,14 @@ static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int pag
                else {
                        viewer->pdf_doc = poppler_document_new_from_file( viewer->fsname, NULL, &error);
                }
+               if (error && g_error_matches(error, POPPLER_ERROR, POPPLER_ERROR_ENCRYPTED)) {
+                       g_clear_error(&error);
+                       password = input_dialog_with_invisible(_("Enter password"),
+                                       _("This document is locked and requires a password before it can be opened."),
+                                       "");
+                       viewer->pdf_doc = poppler_document_new_from_file(viewer->fsname, password, &error);
+                       g_free(password);
+               }
 
                viewer->num_pages = poppler_document_get_n_pages(viewer->pdf_doc);
 
@@ -1347,8 +1393,7 @@ static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int pag
                main_window_cursor_normal(mainwindow_get_mainwindow());
        } 
        if (viewer->pdf_doc == NULL) {
-               stock_pixbuf_gdk(viewer->hbox, 
-                               STOCK_PIXMAP_MIME_APPLICATION, 
+               stock_pixbuf_gdk(STOCK_PIXMAP_MIME_APPLICATION, 
                                &viewer->icon_pixbuf);
 
                gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type), viewer->icon_pixbuf);
@@ -1395,7 +1440,7 @@ static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int pag
                viewer->pdf_page = poppler_document_get_page(viewer->pdf_doc, page_num - 1);
 
                if (viewer->pdf_page == NULL) {
-                       g_warning("Page not found\n");
+                       g_warning("Page not found");
                        return;
                }   
 
@@ -1477,7 +1522,8 @@ static void pdf_viewer_show_mimepart(MimeViewer *_viewer, const gchar *infile,
 
        pdf_viewer_update((MimeViewer *)viewer, TRUE, 1);
 
-       messageview->updating = FALSE;
+       if (messageview)
+               messageview->updating = FALSE;
 }
 
 static void pdf_viewer_clear(MimeViewer *_viewer)
@@ -1497,10 +1543,10 @@ static void pdf_viewer_clear(MimeViewer *_viewer)
        }
 
        vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
-       vadj->value = 0.0;
+       gtk_adjustment_set_value(vadj, 0.0);
        g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);
        vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin_index));
-       vadj->value = 0.0;
+       gtk_adjustment_set_value(vadj, 0.0);
        g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);
        gtk_tree_store_clear(GTK_TREE_STORE(viewer->index_model));
        gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->pdf_view), NULL);
@@ -1540,7 +1586,7 @@ static gboolean pdf_viewer_scroll_page(MimeViewer *_viewer, gboolean up)
                        gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_FORWARD, 1);
                        vadj = gtk_scrolled_window_get_vadjustment(
                                        GTK_SCROLLED_WINDOW(viewer->scrollwin));
-                       vadj->value = 0.0;
+                       gtk_adjustment_set_value(vadj, 0.0);
                        g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);
                        return TRUE;
                } 
@@ -1548,7 +1594,8 @@ static gboolean pdf_viewer_scroll_page(MimeViewer *_viewer, gboolean up)
                        gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_BACKWARD, 1);
                        vadj = gtk_scrolled_window_get_vadjustment(
                                        GTK_SCROLLED_WINDOW(viewer->scrollwin));
-                       vadj->value = vadj->upper - vadj->page_size;
+                       gtk_adjustment_set_value(vadj,
+                                       gtk_adjustment_get_upper(vadj) - gtk_adjustment_get_page_size(vadj));
                        g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);
                        return TRUE;
                } 
@@ -1567,7 +1614,7 @@ static void pdf_viewer_scroll_one_line(MimeViewer *_viewer, gboolean up)
 
        if (viewer->pdf_view == NULL) return; 
                debug_print("up: %d\n", up);    
-               if (vadj->value <(vadj->upper - vadj->page_size))  {
+               if (gtk_adjustment_get_value(vadj) < (gtk_adjustment_get_upper(vadj) - gtk_adjustment_get_page_size(vadj)))  {
                        gtkutils_scroll_one_line(GTK_WIDGET(viewer->pdf_view), vadj, up);
                }
                else {
@@ -1581,7 +1628,14 @@ static void pdf_viewer_scroll_one_line(MimeViewer *_viewer, gboolean up)
 #define BUTTON_H_PADDING 3
 #define ADD_BUTTON_TO_TABLE(widget, stock_image) \
        widget = gtk_button_new(); \
-       img = gtk_image_new_from_stock(stock_image, GTK_ICON_SIZE_MENU); \
+       img = stock_pixmap_widget(stock_image); \
+       gtk_button_set_image(GTK_BUTTON(widget), img); \
+       gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(widget), \
+                               col, col+1, 0, 1, 0, 0, BUTTON_H_PADDING, 0); \
+       col++;
+#define ADD_TOGGLE_BUTTON_TO_TABLE(widget, stock_image) \
+       widget = gtk_toggle_button_new(); \
+       img = stock_pixmap_widget(stock_image); \
        gtk_button_set_image(GTK_BUTTON(widget), img); \
        gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(widget), \
                                col, col+1, 0, 1, 0, 0, BUTTON_H_PADDING, 0); \
@@ -1722,8 +1776,8 @@ static MimeViewer *pdf_viewer_create(void)
        gtk_frame_set_label(GTK_FRAME(viewer->frame_index), _("Document Index"));
 
        ADD_SEP_TO_TABLE
-       ADD_BUTTON_TO_TABLE(viewer->first_page, GTK_STOCK_GOTO_FIRST)
-       ADD_BUTTON_TO_TABLE(viewer->prev_page, GTK_STOCK_GO_BACK)
+       ADD_BUTTON_TO_TABLE(viewer->first_page, STOCK_PIXMAP_FIRST_ARROW)
+       ADD_BUTTON_TO_TABLE(viewer->prev_page, STOCK_PIXMAP_LEFT_ARROW)
        viewer->cur_page = gtk_spin_button_new_with_range(0.0, 0.0, 1.0);
        viewer->zoom_scroll = gtk_spin_button_new_with_range(0.20, 8.0, 0.20);
        gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->zoom_scroll), 1.0);
@@ -1743,33 +1797,26 @@ static MimeViewer *pdf_viewer_create(void)
                                        0);
        col++;
 
-       ADD_BUTTON_TO_TABLE(viewer->next_page, GTK_STOCK_GO_FORWARD)
-       ADD_BUTTON_TO_TABLE(viewer->last_page, GTK_STOCK_GOTO_LAST)
+       ADD_BUTTON_TO_TABLE(viewer->next_page, STOCK_PIXMAP_RIGHT_ARROW)
+       ADD_BUTTON_TO_TABLE(viewer->last_page, STOCK_PIXMAP_LAST_ARROW)
        ADD_SEP_TO_TABLE
-       ADD_BUTTON_TO_TABLE(viewer->zoom_fit, GTK_STOCK_ZOOM_FIT)
-       ADD_BUTTON_TO_TABLE(viewer->zoom_in, GTK_STOCK_ZOOM_IN)
+       ADD_BUTTON_TO_TABLE(viewer->zoom_fit, STOCK_PIXMAP_ZOOM_FIT)
+       ADD_BUTTON_TO_TABLE(viewer->zoom_in, STOCK_PIXMAP_ZOOM_IN)
        gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(viewer->zoom_scroll),
                                        col, col+1, 
                                        0, 1, 0, 0, 
                                        BUTTON_H_PADDING, 
                                        0);
        col++;
-       ADD_BUTTON_TO_TABLE(viewer->zoom_out, GTK_STOCK_ZOOM_OUT)
-       ADD_BUTTON_TO_TABLE(viewer->zoom_width, GTK_STOCK_FULLSCREEN)
+       ADD_BUTTON_TO_TABLE(viewer->zoom_out, STOCK_PIXMAP_ZOOM_OUT)
+       ADD_BUTTON_TO_TABLE(viewer->zoom_width, STOCK_PIXMAP_ZOOM_WIDTH)
        ADD_SEP_TO_TABLE
-       ADD_BUTTON_TO_TABLE(viewer->rotate_left, GTK_STOCK_UNDO)
-       ADD_BUTTON_TO_TABLE(viewer->rotate_right, GTK_STOCK_REDO)
+       ADD_BUTTON_TO_TABLE(viewer->rotate_left, STOCK_PIXMAP_ROTATE_LEFT)
+       ADD_BUTTON_TO_TABLE(viewer->rotate_right, STOCK_PIXMAP_ROTATE_RIGHT)
        ADD_SEP_TO_TABLE
-       ADD_BUTTON_TO_TABLE(viewer->doc_info, GTK_STOCK_INFO)
-
-       viewer->doc_index = GTK_WIDGET(gtk_toggle_tool_button_new_from_stock(GTK_STOCK_INDEX));
-       gtk_widget_set_size_request(GTK_WIDGET(viewer->doc_index), 26, 26);
-       gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(viewer->doc_index),
-                                       col, col+1, 
-                                       0, 1, 0, 0, 
-                                       BUTTON_H_PADDING, 
-                                       0);
-       col++;
+       ADD_BUTTON_TO_TABLE(viewer->print, STOCK_PIXMAP_PRINTER)
+       ADD_BUTTON_TO_TABLE(viewer->doc_info, STOCK_PIXMAP_DOC_INFO)
+       ADD_TOGGLE_BUTTON_TO_TABLE(viewer->doc_index, STOCK_PIXMAP_DOC_INDEX)
 
        gtk_scrolled_window_set_policy(
                        GTK_SCROLLED_WINDOW(viewer->scrollwin), 
@@ -1793,6 +1840,8 @@ static MimeViewer *pdf_viewer_create(void)
                                        G_TYPE_DOUBLE);
 
        viewer->index_list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(tree_store));
+       g_object_unref(tree_store);
+
        renderer = gtk_cell_renderer_text_new();
        column = gtk_tree_view_column_new_with_attributes(_("Name"),  renderer, "text", 0,  NULL);
        gtk_tree_view_append_column(GTK_TREE_VIEW(viewer->index_list), column);         
@@ -1821,8 +1870,7 @@ static MimeViewer *pdf_viewer_create(void)
 
        /* end treeview */
 
-       stock_pixbuf_gdk(viewer->hbox, 
-                       STOCK_PIXMAP_MIME_TEXT_PLAIN, 
+       stock_pixbuf_gdk(STOCK_PIXMAP_MIME_TEXT_PLAIN, 
                        &viewer->icon_pixbuf);
 
        gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type), 
@@ -1886,6 +1934,8 @@ static MimeViewer *pdf_viewer_create(void)
        g_object_ref(GTK_WIDGET(viewer->rotate_right));
        gtk_widget_show(GTK_WIDGET(viewer->rotate_left));
        g_object_ref(GTK_WIDGET(viewer->rotate_left));
+       gtk_widget_show(GTK_WIDGET(viewer->print));
+       g_object_ref(GTK_WIDGET(viewer->print));
        gtk_widget_show(GTK_WIDGET(viewer->doc_info));
        g_object_ref(GTK_WIDGET(viewer->doc_info));
        gtk_widget_show(GTK_WIDGET(viewer->doc_index));
@@ -1933,6 +1983,9 @@ static MimeViewer *pdf_viewer_create(void)
        CLAWS_SET_TIP(viewer->rotate_right,
                                _("Rotate Right"));
 
+       CLAWS_SET_TIP(viewer->print,
+                               _("Print Document"));
+
        CLAWS_SET_TIP(viewer->doc_info,
                                _("Document Info"));
 
@@ -1997,6 +2050,11 @@ static MimeViewer *pdf_viewer_create(void)
                                    G_CALLBACK(pdf_viewer_button_rotate_left_cb), 
                                   (gpointer) viewer);
 
+       g_signal_connect(G_OBJECT(viewer->print), 
+                                   "clicked", 
+                                   G_CALLBACK(pdf_viewer_button_print_cb), 
+                                  (gpointer) viewer);
+
        g_signal_connect(G_OBJECT(viewer->doc_info), 
                                    "clicked", 
                                    G_CALLBACK(pdf_viewer_button_document_info_cb), 
@@ -2031,6 +2089,7 @@ static MimeViewer *pdf_viewer_create(void)
 }
 
 #undef ADD_BUTTON_TO_TABLE
+#undef ADD_TOGGLE_BUTTON_TO_TABLE
 #undef ADD_SEP_TO_TABLE
 #undef BUTTON_H_PADDING
 #undef SEP_H_PADDING