Clean poppler_viewer.c switch warnings
[claws.git] / src / plugins / pdf_viewer / poppler_viewer.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright(C) 1999-2007 the Claws Mail Team
4  * This file Copyright (C) 2007 Salvatore De Paolis 
5  * <iwkse@claws-mail.org> 
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3 of the License, or
10  *(at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  */
21
22 #ifdef HAVE_CONFIG_H
23 #  include "config.h"
24 #include "claws-features.h"
25 #endif
26
27 #include <glib.h>
28 #include <glib/gi18n.h>
29
30 #include "poppler_viewer.h"
31 #include "printing.h"
32 #include "prefs_common.h"
33 #include "gtk/gtkutils.h"
34 #include "mimeview.h"
35 #ifndef POPPLER_WITH_GDK
36 #include "stdbool.h"
37 #endif
38
39 static FileType pdf_viewer_mimepart_get_type(MimeInfo *partinfo);
40 static MimeViewerFactory pdf_viewer_factory;
41
42 static void pdf_viewer_show_mimepart(MimeViewer *_viewer, const gchar *infile,
43                                 MimeInfo *partinfo);
44
45 static MimeViewer *pdf_viewer_create(void);
46 static void pdf_viewer_clear(MimeViewer *_viewer);
47 static void pdf_viewer_destroy(MimeViewer *_viewer);
48 static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int page_num);
49
50 static GtkWidget *pdf_viewer_get_widget(MimeViewer *_viewer);
51
52 static void pdf_viewer_hide_index_pane(PdfViewer *viewer);
53 static void pdf_viewer_set_index_button_sensitive(PdfViewer *viewer);
54 static void pdf_viewer_scroll_to(PdfViewer *viewer, gfloat x, gfloat y);
55
56 static void search_matches_free(PdfViewer *viewer);
57 static gboolean pdf_viewer_text_search(MimeViewer *_viewer, gboolean backward,
58                                      const gchar *str, gboolean case_sens);
59 static void pdf_viewer_render_selection(PdfViewer *viewer, PopplerRectangle *rect, PageResult *page_results);
60 static void pdf_viewer_render_page(PopplerPage *page, GtkWidget *view, double width, double height, double zoom, gint rotate);
61
62 static char * pdf_viewer_get_document_format_data(GTime utime);
63 static void pdf_viewer_get_document_index(PdfViewer *viewer, PopplerIndexIter *index_iter, GtkTreeIter *parentiter);
64 static void pdf_viewer_index_row_activated(GtkTreeView          *tree_view,
65                                         GtkTreePath             *path,
66                                         GtkTreeViewColumn       *column,
67                                         gpointer                 data);
68
69 static GtkTable * pdf_viewer_fill_info_table(PdfViewer *viewer);
70
71 /* Callbacks */
72 static void pdf_viewer_move_events_cb(GtkWidget *widget, GdkEventMotion *event, PdfViewer *viewer); 
73 static void pdf_viewer_button_press_events_cb(GtkWidget *widget, GdkEventButton *event, PdfViewer *viewer); 
74 static void pdf_viewer_mouse_scroll_destroy_cb(GtkWidget *widget, GdkEventButton *event, PdfViewer *viewer); 
75 static void pdf_viewer_button_first_page_cb(GtkButton *button, PdfViewer *viewer);
76 static void pdf_viewer_button_last_page_cb(GtkButton *button, PdfViewer *viewer);
77 static void pdf_viewer_button_zoom_in_cb(GtkButton *button, PdfViewer *viewer);
78 static void pdf_viewer_button_zoom_out_cb(GtkButton *button, PdfViewer *viewer);
79 static void pdf_viewer_button_zoom_fit_cb(GtkButton *button, PdfViewer *viewer);
80 static void pdf_viewer_button_zoom_width_cb(GtkButton *button, PdfViewer *viewer);
81 static void pdf_viewer_button_rotate_right_cb(GtkButton *button, PdfViewer *viewer);
82 static void pdf_viewer_button_rotate_left_cb(GtkButton *button, PdfViewer *viewer);
83 static void pdf_viewer_spin_change_page_cb(GtkSpinButton *button, PdfViewer *viewer);
84 static void pdf_viewer_spin_zoom_scroll_cb(GtkSpinButton *button, PdfViewer *viewer);
85 /* Show/Hide the index pane */
86 static void pdf_viewer_show_document_index_cb(GtkButton *button, PdfViewer *viewer);
87 static void pdf_viewer_button_document_info_cb(GtkButton *button, PdfViewer *viewer);
88
89 static void pdf_viewer_show_controls(PdfViewer *viewer, gboolean show);
90 static gboolean pdf_viewer_scroll_page(MimeViewer *_viewer, gboolean up);
91 static void pdf_viewer_scroll_one_line(MimeViewer *_viewer, gboolean up);
92
93 /** Claws-Mail Plugin functions*/
94 gint plugin_init(gchar **error);
95 const gchar *plugin_name(void);
96 const gchar *plugin_desc(void);
97 const gchar *plugin_type(void);
98 const gchar *plugin_licence(void);
99 const gchar *plugin_version(void);
100 struct PluginFeature *plugin_provides(void);
101
102 #ifndef POPPLER_WITH_GDK
103 static void
104 copy_cairo_surface_to_pixbuf (cairo_surface_t *surface,
105                               GdkPixbuf       *pixbuf)
106 {
107         int cairo_width, cairo_height, cairo_rowstride;
108         unsigned char *pixbuf_data, *dst, *cairo_data;
109         int pixbuf_rowstride, pixbuf_n_channels;
110         unsigned int *src;
111         int x, y;
112
113         cairo_width = cairo_image_surface_get_width (surface);
114         cairo_height = cairo_image_surface_get_height (surface);
115         cairo_rowstride = cairo_image_surface_get_stride (surface);
116         cairo_data = cairo_image_surface_get_data (surface);
117
118         pixbuf_data = gdk_pixbuf_get_pixels (pixbuf);
119         pixbuf_rowstride = gdk_pixbuf_get_rowstride (pixbuf);
120         pixbuf_n_channels = gdk_pixbuf_get_n_channels (pixbuf);
121
122         if (cairo_width > gdk_pixbuf_get_width (pixbuf))
123                 cairo_width = gdk_pixbuf_get_width (pixbuf);
124         if (cairo_height > gdk_pixbuf_get_height (pixbuf))
125                 cairo_height = gdk_pixbuf_get_height (pixbuf);
126         for (y = 0; y < cairo_height; y++) {
127                 src = (unsigned int *) (cairo_data + y * cairo_rowstride);
128                 dst = pixbuf_data + y * pixbuf_rowstride;
129                 for (x = 0; x < cairo_width; x++) {
130                         dst[0] = (*src >> 16) & 0xff;
131                         dst[1] = (*src >> 8) & 0xff; 
132                         dst[2] = (*src >> 0) & 0xff;
133                         if (pixbuf_n_channels == 4)
134                                 dst[3] = (*src >> 24) & 0xff;
135                         dst += pixbuf_n_channels;
136                         src++;
137                 }
138         }
139 }
140 static void
141 _poppler_page_render_to_pixbuf (PopplerPage *page,
142                                 int src_x, int src_y,
143                                 int src_width, int src_height,
144                                 double scale,
145                                 int rotation,
146                                 gboolean printing,
147                                 GdkPixbuf *pixbuf)
148 {
149         cairo_t *cr;
150         cairo_surface_t *surface;
151
152         surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32,
153                                         src_width, src_height);
154         cr = cairo_create (surface);
155         cairo_save (cr);
156         switch (rotation) {
157         case 90:
158                 cairo_translate (cr, src_x + src_width, -src_y);
159                 break;
160         case 180:
161                 cairo_translate (cr, src_x + src_width, src_y + src_height);
162                 break;
163         case 270:
164                 cairo_translate (cr, -src_x, src_y + src_height);
165                 break;
166         default:
167                 cairo_translate (cr, -src_x, -src_y);
168         }
169
170         if (scale != 1.0)
171                 cairo_scale (cr, scale, scale);
172
173         if (rotation != 0)
174                 cairo_rotate (cr, rotation * G_PI / 180.0);
175
176         if (printing)
177                 poppler_page_render_for_printing (page, cr);
178         else
179                 poppler_page_render (page, cr);
180         cairo_restore (cr);
181
182         cairo_set_operator (cr, CAIRO_OPERATOR_DEST_OVER);
183         cairo_set_source_rgb (cr, 1., 1., 1.);
184         cairo_paint (cr);
185
186         cairo_destroy (cr);
187
188         copy_cairo_surface_to_pixbuf (surface, pixbuf);
189         cairo_surface_destroy (surface);
190 }
191
192 /**
193  * poppler_page_render_to_pixbuf:
194  * @page: the page to render from
195  * @src_x: x coordinate of upper left corner  
196  * @src_y: y coordinate of upper left corner  
197  * @src_width: width of rectangle to render  
198  * @src_height: height of rectangle to render
199  * @scale: scale specified as pixels per point
200  * @rotation: rotate the document by the specified degree
201  * @pixbuf: pixbuf to render into
202  *
203  * First scale the document to match the specified pixels per point,
204  * then render the rectangle given by the upper left corner at
205  * (src_x, src_y) and src_width and src_height.
206  * This function is for rendering a page that will be displayed.
207  * If you want to render a page that will be printed use
208  * poppler_page_render_to_pixbuf_for_printing() instead
209  *
210  * Deprecated: 0.16
211  **/
212 static void
213 poppler_page_render_to_pixbuf (PopplerPage *page,
214                                int src_x, int src_y,
215                                int src_width, int src_height,
216                                double scale,
217                                int rotation,
218                                GdkPixbuf *pixbuf)
219 {
220         g_return_if_fail (POPPLER_IS_PAGE (page));
221         g_return_if_fail (scale > 0.0);
222         g_return_if_fail (pixbuf != NULL);
223
224         _poppler_page_render_to_pixbuf (page, src_x, src_y,
225                                   src_width, src_height,
226                                   scale, rotation,
227                                   FALSE,
228                                   pixbuf);
229 }
230 #endif
231 static GtkWidget *pdf_viewer_get_widget(MimeViewer *_viewer)
232 {
233         PdfViewer *viewer = (PdfViewer *) _viewer;
234         debug_print("pdf_viewer_get_widget: %p\n", viewer->vbox);
235
236         return GTK_WIDGET(viewer->vbox);
237 }
238 /** Hide the index panel */
239 static void pdf_viewer_hide_index_pane(PdfViewer *viewer)
240 {
241         if (viewer->pdf_index) {   
242                 poppler_index_iter_free(viewer->pdf_index);
243                 viewer->pdf_index = NULL;
244                 gtk_widget_hide(GTK_WIDGET(viewer->frame_index));
245         }
246 }
247
248 static void search_matches_free(PdfViewer *viewer)
249 {
250         GList *cur; 
251         for(cur = viewer->text_found; cur; cur = cur->next) {
252                 PageResult *res = (PageResult *)cur->data;
253                 g_list_free(res->results);
254                 g_free(res);
255         }
256         g_list_free(viewer->text_found);
257         viewer->text_found = NULL;
258         g_free(viewer->last_search);
259         viewer->last_search = NULL;
260         if (viewer->last_rect && viewer->last_page_result) {
261                 viewer->last_rect = NULL;
262                 viewer->last_page_result = NULL;
263                 pdf_viewer_update((MimeViewer *)viewer, 
264                         FALSE, 
265                         gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page)));
266         }
267 }
268
269 static void pdf_viewer_scroll_to(PdfViewer *viewer, gfloat x, gfloat y)
270 {
271         GtkAdjustment *vadj;
272         GtkAdjustment *hadj;
273         vadj = gtk_scrolled_window_get_vadjustment(
274                 GTK_SCROLLED_WINDOW(viewer->scrollwin));
275         
276         if (y < vadj->value) {
277                 vadj->value = y;
278         }
279         else {
280                 while(y > vadj->value + vadj->page_size) {
281                         vadj->value += vadj->page_size;
282                 }
283         }
284         
285         hadj = gtk_scrolled_window_get_hadjustment(
286                 GTK_SCROLLED_WINDOW(viewer->scrollwin));
287         
288         if (x < hadj->value) {
289                 hadj->value = x;
290         }
291         else {
292                 while(x > hadj->value + hadj->page_size) {
293                         hadj->value += hadj->page_size;
294                 }
295         }
296
297         g_signal_emit_by_name(G_OBJECT(hadj), "value-changed", 0);      
298         g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);      
299 }
300 static void pdf_viewer_render_page(PopplerPage *page, GtkWidget *view, double width, 
301                                    double height, double zoom, gint rotate)
302 {
303         GdkPixbuf *pb;
304         
305         debug_print("width: %f\n", width);
306         pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, 
307                                 FALSE, 8, 
308                                 (int)(width * zoom), 
309                                 (int)(height * zoom));  
310         
311                         poppler_page_render_to_pixbuf(page, 0, 0, 
312                                 (int)(width * zoom), 
313                                 (int)(height * zoom), 
314                                 zoom, rotate, pb);
315                 
316                         gtk_image_set_from_pixbuf(GTK_IMAGE(view), pb);
317                         g_object_unref(G_OBJECT(pb));
318 }
319 static void pdf_viewer_render_selection(PdfViewer *viewer, PopplerRectangle *rect, PageResult *page_results)
320 {
321         gint selw, selh;
322         double width_points, height_points;
323         gint width, height;
324         GdkPixbuf *sel_pb, *page_pb;
325         gfloat x1, x2, y1, y2;  
326         
327
328         gint cur_page_num = 
329                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page));
330         
331         viewer->last_match = viewer->res_cnt;
332         
333         viewer->last_rect = NULL;
334         viewer->last_page_result = NULL;
335         if (cur_page_num != page_results->page_num) {
336                 /* we changed page. update the view */
337                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->cur_page), 
338         (gdouble) page_results->page_num);
339         }
340                         
341         viewer->last_rect = rect;
342         viewer->last_page_result = page_results;
343
344         GTK_EVENTS_FLUSH();
345                                 
346         poppler_page_get_size(POPPLER_PAGE(viewer->pdf_page), &width_points, &height_points);
347         width = (int)((width_points * viewer->zoom) + 0.5);
348         height = (int)((height_points * viewer->zoom) + 0.5);
349
350         if (viewer->rotate == 90) {
351                 x1 = MIN(rect->y1,rect->y2) * viewer->zoom;
352                 x2 = MAX(rect->y1,rect->y2) * viewer->zoom;
353                 y1 = MAX(rect->x1,rect->x2) * viewer->zoom;
354                 y2 = MIN(rect->x1,rect->x2) * viewer->zoom;
355                 selw = (x2 - x1);
356                 selh = (y1 - y2);
357
358         } else if (viewer->rotate == 180) {
359                 x1 = width - rect->x2 * viewer->zoom;
360                 x2 = width - rect->x1 * viewer->zoom;
361                 y1 = height - rect->y2 * viewer->zoom;
362                 y2 = height - rect->y1 * viewer->zoom;
363                 selw = (x2 - x1);
364                 selh = (y2 - y1);
365                 y1 = height - y1;
366                 y2 = height - y2;
367
368         } else if (viewer->rotate == 270) {
369                 x1 = height - MAX(rect->y1,rect->y2) * viewer->zoom;
370                 x2 = height - MIN(rect->y1,rect->y2) * viewer->zoom;
371                 y1 = width - MIN(rect->x1,rect->x2) * viewer->zoom;
372                 y2 = width - MAX(rect->x1,rect->x2) * viewer->zoom;
373                 selw = (x2 - x1);
374                 selh = (y1 - y2);
375         } else {
376                 x1 = rect->x1 * viewer->zoom;
377                 x2 = rect->x2 * viewer->zoom;
378                 y1 = rect->y1 * viewer->zoom;
379                 y2 = rect->y2 * viewer->zoom;
380                 selw = (x2 - x1);
381                 selh = (y2 - y1);
382                 y1 = height - y1;
383                 y2 = height - y2;
384         }
385                                 
386         sel_pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, 
387                                                         selw, selh);
388
389         gdk_pixbuf_fill(sel_pb, SELECTION_COLOR);
390                                 
391         page_pb = gtk_image_get_pixbuf(GTK_IMAGE(viewer->pdf_view));
392                                 
393         page_pb = gdk_pixbuf_new(GDK_COLORSPACE_RGB, 
394                                         FALSE, 8, 
395                                 (int)(viewer->width * viewer->zoom), 
396                                 (int)(viewer->height * viewer->zoom));  
397         
398         poppler_page_render_to_pixbuf(viewer->pdf_page, 
399                                         0, 
400                                         0, 
401                                 (int)(viewer->width * viewer->zoom), 
402                                 (int)(viewer->height * viewer->zoom), 
403                                         viewer->zoom, 
404                                         viewer->rotate, 
405                                         page_pb);
406                                 
407         gdk_pixbuf_composite(sel_pb, page_pb, 
408                                         x1, y2, selw, selh, 0, 0, 
409                                         viewer->zoom, viewer->zoom, 
410                                         GDK_INTERP_BILINEAR, ALPHA_CHANNEL);
411                                 
412         gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->pdf_view), page_pb);
413         
414         pdf_viewer_scroll_to(viewer, MIN(x1,x2), MIN(y1,y2));
415
416         g_object_unref(G_OBJECT(sel_pb));
417         g_object_unref(G_OBJECT(page_pb));
418
419 }
420
421 static gboolean pdf_viewer_text_search(MimeViewer *_viewer, gboolean backward,
422                                      const gchar *str, gboolean case_sens)
423 {
424         PdfViewer *viewer = (PdfViewer *)_viewer;
425         GList *all_pages_results, *cur_page_results;
426         viewer->res_cnt = 0;
427
428         debug_print("pdf_viewer_text_search: %s\n", str);
429         main_window_cursor_wait(mainwindow_get_mainwindow());
430         
431         if (viewer->last_search && strcmp(str, viewer->last_search)) {
432                 search_matches_free(viewer);
433                 viewer->last_match = -1;
434                 viewer->num_matches = 0;
435         } else if (!viewer->last_search) {
436                 viewer->last_match = -1;
437                 viewer->num_matches = 0;
438         }
439         /* It's a new search, build list of matches 
440          * across all pages */
441         if (viewer->last_match == -1) {
442                 gint i; 
443                 
444                 for(i = 1; i <= viewer->num_pages; i++) {
445                         
446                         PopplerPage *pdf_page = poppler_document_get_page(viewer->pdf_doc, i - 1);
447                         viewer->page_results = poppler_page_find_text(pdf_page, str);
448                         
449                         if (viewer->page_results != NULL) {
450                                 debug_print("page_results %p\n", viewer->page_results);
451                                 /* store results for this page */
452                                 gint num_res = 0;
453                                 PageResult *res = g_new0(PageResult, 1);
454                                 res->results = viewer->page_results;
455                                 res->page_num = i;
456                                 /* found text, prepend this page(faster than append) */
457                                 viewer->text_found = g_list_prepend(viewer->text_found, res);
458                                 num_res = g_list_length(viewer->page_results);
459                                 debug_print("%d results on page %d\n", num_res, i);
460                                 viewer->num_matches += num_res;
461                         }
462                         g_object_unref(G_OBJECT(pdf_page));
463                 }
464
465                 if (viewer->text_found == NULL) {
466                         main_window_cursor_normal(mainwindow_get_mainwindow());
467                         return FALSE;
468                 }
469                 /* put back the list in the correct order */
470                 viewer->text_found = g_list_reverse(viewer->text_found);
471         } 
472         
473         if (!viewer->text_found) {
474                 main_window_cursor_normal(mainwindow_get_mainwindow());
475                 return FALSE;
476         } else {
477                 viewer->last_search = g_strdup(str);
478         }
479         
480         if (backward) {
481                 /* if backward, we have to initialize stuff to search 
482                  * from the end */
483                 viewer->res_cnt = viewer->num_matches-1;
484                 if (viewer->last_match == -1) {
485                         viewer->last_match = viewer->num_matches+1;
486                 }
487                 all_pages_results = g_list_last(viewer->text_found);
488         } 
489         else {
490                 all_pages_results = viewer->text_found;
491         }
492         
493         for(; all_pages_results; all_pages_results = (backward?all_pages_results->prev:all_pages_results->next)) {
494                 
495                 PageResult * page_results = (PageResult *)all_pages_results->data;
496
497                 if (backward) {
498                         cur_page_results = g_list_last(page_results->results);
499                 }
500                 else {
501                         cur_page_results = page_results->results;
502                 }
503
504                 for(; cur_page_results; cur_page_results = (backward?cur_page_results->prev:cur_page_results->next)) {
505
506                         gboolean valid = FALSE;
507                         /* first valid result is the last+1 if searching
508                          * forward, last-1 if searching backward */
509                         if (backward) {
510                                 valid = (viewer->res_cnt < viewer->last_match);
511                         }
512                         else {
513                                 valid = (viewer->res_cnt > viewer->last_match);
514                         }
515                         if (valid) {
516                                 pdf_viewer_render_selection(viewer, 
517                                         (PopplerRectangle *)cur_page_results->data,
518                                                 page_results);
519                                 main_window_cursor_normal(mainwindow_get_mainwindow());
520                                 return TRUE;
521                         }
522                         
523                         if (backward) {
524                                 viewer->res_cnt--;
525                         }
526                         else {
527                                 viewer->res_cnt++;
528                         }
529                 }
530         }
531         main_window_cursor_normal(mainwindow_get_mainwindow());
532         search_matches_free(viewer);
533         return FALSE;
534 }
535
536 static void pdf_viewer_get_document_index(PdfViewer *viewer, PopplerIndexIter *index_iter, GtkTreeIter *parentiter)
537 {
538         PopplerAction *action;
539         PopplerIndexIter *child;
540         GtkTreeIter childiter;
541
542         debug_print("get document index\n");
543         do      {
544                 gint page_num = 0;
545                 
546                 action = poppler_index_iter_get_action(index_iter);
547
548                 if (action->type != POPPLER_ACTION_GOTO_DEST) {
549                         poppler_action_free(action);
550                         continue;
551                 }
552
553                 if (action->goto_dest.dest->type == POPPLER_DEST_XYZ || action->goto_dest.dest->type == POPPLER_DEST_FITH) {
554                         page_num = action->goto_dest.dest->page_num;
555                 }
556 #ifdef HAVE_POPPLER_DEST_NAMED
557                 else if (action->goto_dest.dest->type == POPPLER_DEST_NAMED) {
558                         PopplerDest *dest = poppler_document_find_dest(
559                                         viewer->pdf_doc, action->goto_dest.dest->named_dest);
560                         if (dest->type != POPPLER_DEST_XYZ) {
561                                 g_warning("couldn't figure out link\n");
562                                 poppler_dest_free(dest);
563                                 continue;
564                         }
565                         page_num = dest->page_num;
566                         poppler_dest_free(dest);
567                 } 
568 #endif
569                 else {
570 #ifdef HAVE_POPPLER_DEST_NAMED
571                         g_warning("unhandled link type %d\nplease contact developers\n", action->goto_dest.dest->type);
572 #else
573                         g_warning("unhandled link type %d\nplease upgrade libpoppler-glib to 0.5.4\n", action->goto_dest.dest->type);
574 #endif
575                         continue;
576                 }
577                 gtk_tree_store_append(GTK_TREE_STORE(viewer->index_model), &childiter, parentiter);
578                 gtk_tree_store_set(GTK_TREE_STORE(viewer->index_model), &childiter,
579                                                 INDEX_NAME, action->named.title,
580                                                 INDEX_PAGE, page_num,
581                                                 INDEX_TOP, action->goto_dest.dest->top,
582                                                 -1);
583                 poppler_action_free(action);
584                 child = poppler_index_iter_get_child(index_iter);
585                 if (child) {
586                         pdf_viewer_get_document_index(viewer, child, &childiter);
587                         poppler_index_iter_free(child);
588                 }
589         }
590         while(poppler_index_iter_next(index_iter));
591 }
592
593 static void pdf_viewer_index_row_activated(GtkTreeView          *tree_view,
594                                         GtkTreePath             *path,
595                                         GtkTreeViewColumn       *column,
596                                         gpointer                 data)
597 {
598         GtkTreeIter iter;
599         GtkTreeModel *model = gtk_tree_view_get_model(tree_view);
600         PdfViewer *viewer = (PdfViewer *)data;
601         gint page_num = 0;
602         
603         debug_print("index_row_activated\n");
604         if (!gtk_tree_model_get_iter(model, &iter, path)) return;
605
606         gtk_tree_model_get(model, &iter, 
607                            INDEX_PAGE, &page_num,
608                            -1);
609
610         if (page_num > 0) {
611                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->cur_page),(gdouble)page_num);
612                 debug_print("Page num: %d\n", page_num);
613         }
614         GTK_EVENTS_FLUSH();
615 }
616
617 /** Disable the index button if the document doesn't have an index */
618 static void pdf_viewer_set_index_button_sensitive(PdfViewer *viewer)
619 {
620         viewer->pdf_index  = poppler_index_iter_new(viewer->pdf_doc);
621         if (viewer->pdf_index) {        
622                 if (!gtk_widget_is_sensitive(viewer->doc_index)) {
623                         gtk_widget_set_sensitive(viewer->doc_index, TRUE);
624                 }
625         }
626         else {
627                 gtk_widget_set_sensitive(viewer->doc_index, FALSE);
628         }
629
630     poppler_index_iter_free(viewer->pdf_index);
631     viewer->pdf_index = NULL;
632 }
633
634 static char * pdf_viewer_get_document_format_data(GTime utime) 
635 {
636         time_t time = (time_t) utime;
637         struct tm t;
638         char s[256];
639         const char *fmt_hack = "%c";
640         size_t len;
641
642         if (time == 0 || !localtime_r(&time, &t)) return NULL;
643
644         len = strftime(s, sizeof(s), fmt_hack, &t);
645         
646         if (len == 0 || s[0] == '\0') return NULL;
647
648         return g_locale_to_utf8(s, -1, NULL, NULL, NULL);
649 }
650
651 #define ADD_TO_TABLE(LABEL, VALUE) \
652         label = gtk_label_new(LABEL); \
653         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5); \
654         gtk_misc_set_padding(GTK_MISC(label), 4, 0); \
655         gtk_table_attach(viewer->table_doc_info, label, 0, 1, row, row+1, GTK_EXPAND | GTK_FILL, 0, 0, 0); \
656         \
657         label = gtk_label_new(VALUE); \
658         gtk_misc_set_alignment(GTK_MISC(label), 0, 0.5); \
659         gtk_misc_set_padding(GTK_MISC(label), 4, 0); \
660         gtk_table_attach(viewer->table_doc_info, label, 1, 2, row, row+1, GTK_EXPAND | GTK_FILL, 0, 0, 0); \
661         row++;
662
663         
664 static GtkTable * pdf_viewer_fill_info_table(PdfViewer *viewer)
665 {
666         GtkWidget *label;
667         const gchar *title, *format, *author, *subject, *keywords, *creator, *producer;
668         gboolean linearized;
669         gchar *tmp;
670         gint row = 0;
671
672         GTime creation_date, mod_date;
673
674         PopplerPageLayout layout;
675         PopplerPageMode mode;
676         PopplerPermissions permissions;
677         PopplerViewerPreferences view_prefs;
678
679         title = format = author = subject = keywords = creator = producer = tmp = 0;
680
681         g_object_get(viewer->pdf_doc,
682                                 "title", &title,
683                                 "format", &format,
684                                 "author", &author,
685                                 "subject", &subject,
686                                 "keywords", &keywords,
687                                 "creation-date", &creation_date,
688                                 "permissions", &permissions,
689                                 "mod-date", &mod_date,
690                                 "creator", &creator,
691                                 "producer", &producer,  
692                                 "linearized", &linearized,
693                                 "page-mode", &mode,
694                                 "page-layout", &layout,
695                                 "viewer-preferences", &view_prefs,
696                                 NULL);
697
698         viewer->table_doc_info = GTK_TABLE(gtk_table_new(13, 2, FALSE));
699
700         ADD_TO_TABLE(_("Filename:"), viewer->target_filename)
701         ADD_TO_TABLE(_("Size:"), to_human_readable(viewer->to_load->length))
702         ADD_TO_TABLE(NULL, NULL)
703         ADD_TO_TABLE(_("Title:"), title)
704         ADD_TO_TABLE(_("Subject:"), subject)
705         ADD_TO_TABLE(_("Author:"), author)
706         ADD_TO_TABLE(_("Keywords:"), keywords)
707         ADD_TO_TABLE(_("Creator:"), creator)
708         ADD_TO_TABLE(_("Producer:"), producer)
709
710         tmp = pdf_viewer_get_document_format_data(creation_date);
711         ADD_TO_TABLE(_("Created:"), tmp)
712         g_free(tmp);
713
714         tmp = pdf_viewer_get_document_format_data(mod_date);
715         ADD_TO_TABLE(_("Modified:"), tmp)
716         g_free(tmp);
717         
718         ADD_TO_TABLE(_("Format:"), format)
719         if (linearized) {
720                 ADD_TO_TABLE(_("Optimized:"), _("Yes"))
721         }
722         else {
723                 ADD_TO_TABLE(_("Optimized:"), _("No"))
724         }
725         //ADD_TO_TABLE(_("Page Mode:"), pdf_viewer_get_document_info_mode(mode)) 
726         //ADD_TO_TABLE(_("Page Layout:"), pdf_viewer_get_document_info_layout(layout))
727
728         return(GtkTable *) viewer->table_doc_info;
729 }
730 #undef ADD_TO_TABLE
731
732 static FileType pdf_viewer_mimepart_get_type(MimeInfo *partinfo)
733 {
734         gchar *content_type = NULL;
735         FileType type = TYPE_UNKNOWN;
736         debug_print("mimepart_get_type\n");
737         if ((partinfo->type == MIMETYPE_APPLICATION) &&
738         (!g_ascii_strcasecmp(partinfo->subtype, "octet-stream"))) {
739                 
740                 const gchar *filename;
741
742                 filename = procmime_mimeinfo_get_parameter(partinfo, "filename");
743                 
744                         if (filename == NULL)
745                                 filename = procmime_mimeinfo_get_parameter(partinfo, "name");
746                         if (filename != NULL)
747                                 content_type = procmime_get_mime_type(filename);
748         } 
749         else {
750                 content_type = procmime_get_content_type_str(partinfo->type, partinfo->subtype);
751         }
752
753         if (content_type == NULL) type = TYPE_UNKNOWN;
754         else if (!strcmp(content_type, "application/pdf")) type = TYPE_PDF;
755         else if (!strcmp(content_type, "application/postscript")) type = TYPE_PS;
756         else type = TYPE_UNKNOWN;
757         
758         g_free(content_type);
759         return type;
760 }
761
762 /* Callbacks */
763 static void pdf_viewer_button_first_page_cb(GtkButton *button, PdfViewer *viewer) 
764 {
765         
766         gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_HOME, 1);
767 }
768
769 static void pdf_viewer_button_prev_page_cb(GtkButton *button, PdfViewer *viewer) 
770 {
771         
772         gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_BACKWARD, 1);
773 }
774
775 static void pdf_viewer_button_next_page_cb(GtkButton *button, PdfViewer *viewer) 
776 {
777         
778         gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_FORWARD, 1);
779 }
780
781 static void pdf_viewer_button_last_page_cb(GtkButton *button, PdfViewer *viewer) 
782 {
783         
784         gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_END, 1);
785 }
786
787 static void pdf_viewer_spin_change_page_cb(GtkSpinButton *button, PdfViewer *viewer)
788 {
789         pdf_viewer_update((MimeViewer *)viewer, 
790                         FALSE, 
791                         gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page)));
792 }
793
794 static void pdf_viewer_button_zoom_in_cb(GtkButton *button, PdfViewer *viewer) 
795 {
796
797         gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->zoom_scroll), GTK_SPIN_STEP_FORWARD, ZOOM_FACTOR);
798 }
799
800 static void pdf_viewer_spin_zoom_scroll_cb(GtkSpinButton *button, PdfViewer *viewer)
801 {
802         viewer->zoom = gtk_spin_button_get_value(GTK_SPIN_BUTTON(viewer->zoom_scroll));
803         pdf_viewer_update((MimeViewer *)viewer,
804                         FALSE,
805                         gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page)));
806 }
807
808 static void pdf_viewer_button_zoom_out_cb(GtkButton *button, PdfViewer *viewer) 
809 {
810
811         gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->zoom_scroll), GTK_SPIN_STEP_BACKWARD, ZOOM_FACTOR);
812         
813 }
814
815 static void pdf_viewer_button_press_events_cb(GtkWidget *widget, GdkEventButton *event, PdfViewer *viewer) 
816 {
817         gchar *uri;
818         #ifdef HAVE_POPPLER_DEST_NAMED
819         PopplerDest *dest;
820         #endif
821         static GdkCursor *hand_cur = NULL;
822         
823         if (!hand_cur) hand_cur = gdk_cursor_new(GDK_FLEUR);
824
825         /* Execute Poppler Links */
826         if (event->button == 1 && viewer->in_link) {
827                 switch (viewer->link_action->type) {
828                 case POPPLER_ACTION_UNKNOWN:
829                         debug_print("action unknown\n");
830                         break;
831                 case POPPLER_ACTION_GOTO_DEST:
832                         if (viewer->link_action->goto_dest.dest->type == POPPLER_DEST_XYZ || 
833                                         viewer->link_action->goto_dest.dest->type == POPPLER_DEST_FITH) {
834                                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->cur_page), 
835                                                                           (gdouble)viewer->link_action->goto_dest.dest->page_num);
836                         }
837                 #ifdef HAVE_POPPLER_DEST_NAMED
838                         else if (viewer->link_action->goto_dest.dest->type == POPPLER_DEST_NAMED) {
839                                 dest = poppler_document_find_dest(
840                                         viewer->pdf_doc, viewer->link_action->goto_dest.dest->named_dest);
841                         if (dest->type != POPPLER_DEST_XYZ) {
842                                 g_warning("couldn't figure out link\n");
843                                 poppler_dest_free(dest);
844                                 break;
845                         }
846                         gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->cur_page), 
847                                                                           (gdouble)dest->page_num);
848                         poppler_dest_free(dest);
849                 } 
850                 #endif
851                         break;
852                 case POPPLER_ACTION_GOTO_REMOTE:
853                         #ifdef HAVE_POPPLER_DEST_NAMED
854                         dest = poppler_document_find_dest(
855                                         viewer->pdf_doc, viewer->link_action->goto_remote.dest->named_dest);
856                         if (dest->type != POPPLER_DEST_XYZ) {
857                                 g_warning ("couldn't figure out link\n");
858                                 poppler_dest_free(dest);
859                                 break;
860                         }
861                         gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->cur_page),
862                                                                           (gdouble)dest->page_num);
863                         poppler_dest_free(dest);
864                         #endif
865                         break;
866                 case POPPLER_ACTION_LAUNCH:
867                         debug_print("action launch not yet implemented\n");
868                         break;
869                 case POPPLER_ACTION_URI:
870                         uri = g_strdup(viewer->link_action->uri.uri);
871                         if (!g_ascii_strncasecmp(uri, "mailto:", 7)) 
872                                 compose_new(NULL, uri + 7, NULL);
873                         else 
874                                 open_uri(uri, prefs_common_get_uri_cmd());
875                         g_free(uri);
876                         break;
877                 case POPPLER_ACTION_NAMED:
878                         debug_print("action named not yet implemented\n");
879                         break;
880                 case POPPLER_ACTION_NONE:
881                         debug_print("action none does nothing, surprise!\n");
882                         break;
883 #if POPPLER_CHECK_VERSION(0,14,0)
884                 case POPPLER_ACTION_MOVIE:
885                         debug_print("yoyoyo ;-) a movie?\n");
886                         break;
887                 case POPPLER_ACTION_RENDITION:
888                         debug_print("yoyoyo ;-) multimedia?\n");
889                         break;
890                 case POPPLER_ACTION_OCG_STATE:
891                         debug_print("yoyoyo ;-) layer state?\n");
892                         break;
893 #if POPPLER_CHECK_VERSION(0,18,0)
894                 case POPPLER_ACTION_JAVASCRIPT:
895                         debug_print("yoyoyo ;-) javascript?\n");
896                         break;
897 #endif /* 0.18 */
898 #endif /* 0.14 */
899                 }
900                 if (((MimeViewer *)viewer)->mimeview && 
901                         ((MimeViewer *)viewer)->mimeview->messageview && 
902                         ((MimeViewer *)viewer)->mimeview->messageview->window && 
903                         ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
904                         gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, NULL);
905                 else
906                         gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, NULL);
907         }
908
909         /* Init document to be scrolled with left mouse click */
910         if (event->button == 1 && !viewer->in_link) {
911                 viewer->pdf_view_scroll = TRUE;
912                 if (((MimeViewer *)viewer)->mimeview && 
913                         ((MimeViewer *)viewer)->mimeview->messageview && 
914                         ((MimeViewer *)viewer)->mimeview->messageview->window && 
915                         ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
916                         gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, hand_cur);
917                 else
918                         gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, hand_cur);
919
920                 viewer->last_x = event->x;
921                 viewer->last_y = event->y;
922                 viewer->last_dir_x = 0;
923                 viewer->last_dir_y = 0;
924         }
925 }
926 /* Set the normal cursor*/
927 static void pdf_viewer_mouse_scroll_destroy_cb(GtkWidget *widget, GdkEventButton *event, PdfViewer *viewer) 
928 {
929         
930         if (event->button == 1) {
931                 viewer->pdf_view_scroll = FALSE;
932                 if (((MimeViewer *)viewer)->mimeview && 
933                         ((MimeViewer *)viewer)->mimeview->messageview && 
934                         ((MimeViewer *)viewer)->mimeview->messageview->window && 
935                         ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
936                         gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, NULL);
937                 else
938                         gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, NULL);
939         }
940 }
941
942 static void pdf_viewer_move_events_cb(GtkWidget *widget, GdkEventMotion *event, PdfViewer *viewer) 
943 {
944         /* Grab the document and scroll it with mouse */ 
945         if (viewer->pdf_view_scroll) {
946
947                 viewer->pdf_view_vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
948                 viewer->pdf_view_hadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
949                         
950                         if (event->x < viewer->last_x
951                                         && viewer->pdf_view_hadj->value < (viewer->pdf_view_hadj->upper - viewer->pdf_view_hadj->page_size)) {
952                                 if (viewer->last_dir_x == -1) {
953                                         viewer->pdf_view_hadj->value += viewer->last_x - event->x; 
954                                         g_signal_emit_by_name(G_OBJECT(viewer->pdf_view_hadj),
955                                                                 "value_changed", 0);
956                                 }
957                                 viewer->last_dir_x = -1;
958                         }
959                         else if (event->x > viewer->last_x
960                                         && viewer->pdf_view_hadj->value > 0.0)  {
961                                 if (viewer->last_dir_x == +1) {
962                                         viewer->pdf_view_hadj->value += viewer->last_x - event->x; 
963                                         g_signal_emit_by_name(G_OBJECT(viewer->pdf_view_hadj),
964                                                                 "value_changed", 0);
965                                 }
966                                 viewer->last_dir_x = +1;
967                         }
968
969                         if (event->y < viewer->last_y
970                                         && viewer->pdf_view_vadj->value < (viewer->pdf_view_vadj->upper - viewer->pdf_view_vadj->page_size)) {
971                                 if (viewer->last_dir_y == -1) {
972                                         viewer->pdf_view_vadj->value += viewer->last_y - event->y; 
973                                         g_signal_emit_by_name(G_OBJECT(viewer->pdf_view_vadj),
974                                                                 "value_changed", 0);
975                                 }
976                                 viewer->last_dir_y = -1;
977                         }
978                         else if (event->y > viewer->last_y
979                                         && viewer->pdf_view_vadj->value > 0.0)  {
980                                 if (viewer->last_dir_y == +1) {
981                                         viewer->pdf_view_vadj->value += viewer->last_y - event->y; 
982                                         g_signal_emit_by_name(G_OBJECT(viewer->pdf_view_vadj),
983                                                                 "value_changed", 0);
984                                 }
985                                 viewer->last_dir_y = +1;
986                         }
987                         viewer->last_x = event->x;
988                         viewer->last_y = event->y;
989                         GTK_EVENTS_FLUSH();
990                 } 
991         else {  
992         /* Link Mapping */
993         static GList *l;
994         static GdkCursor *link_cur = NULL;
995         static GtkRequisition size;
996         static gdouble x,y, x1, y1, x2, y2;
997         gboolean ccur;
998         
999         viewer->pdf_view_vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
1000         viewer->pdf_view_hadj = gtk_scrolled_window_get_hadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
1001         
1002         if (!link_cur) link_cur = gdk_cursor_new(GDK_HAND2);
1003
1004         ccur = FALSE;
1005         viewer->in_link = FALSE;        
1006         for (l = viewer->link_map; l; l = g_list_next (l)) {
1007                 PopplerLinkMapping *lmapping;
1008                 lmapping = (PopplerLinkMapping *)l->data;
1009
1010                 x1 = lmapping->area.x1;
1011                 y1 = lmapping->area.y1;
1012                 x2 = lmapping->area.x2;
1013                 y2 = lmapping->area.y2;
1014                 gtk_widget_size_request(viewer->pdf_view, &size);
1015                 
1016                 switch (viewer->rotate) {
1017                 case 0:
1018                 case 360:
1019                                 if (size.width != viewer->pdf_view_hadj->upper)
1020                                         x = (event->x - (viewer->pdf_view_hadj->upper - size.width) / 2) / viewer->zoom;
1021                                 else
1022                                         x = event->x / viewer->zoom;
1023
1024                                 y = (viewer->pdf_view_vadj->upper - event->y) / viewer->zoom;
1025                         break;
1026                 case 90:
1027                                 if (size.width != viewer->pdf_view_hadj->upper)
1028                                         y = (event->x - (viewer->pdf_view_hadj->upper - size.width) / 2) / viewer->zoom;
1029                                 else
1030                                         y = event->x / viewer->zoom;
1031
1032                                 x = (event->y) / viewer->zoom;
1033                         break;
1034                 case 180:
1035                                 if (size.width != viewer->pdf_view_hadj->upper)
1036                                         x = ((viewer->pdf_view_hadj->upper -  event->x) - ((viewer->pdf_view_hadj->upper - size.width) / 2)) / viewer->zoom;
1037                                 else
1038                                         x =  ((viewer->pdf_view_hadj->upper -  event->x) - (viewer->pdf_view_hadj->upper - size.width)) / viewer->zoom;
1039
1040                                 y = (event->y) / viewer->zoom;
1041                         break;
1042                 case 270:
1043                                 if (size.width != viewer->pdf_view_hadj->upper)
1044                                         y = ((viewer->pdf_view_hadj->upper -  event->x) - ((viewer->pdf_view_hadj->upper - size.width) / 2)) / viewer->zoom;
1045                                 else
1046                                         y =  ((viewer->pdf_view_hadj->upper -  event->x) - (viewer->pdf_view_hadj->upper - size.width)) / viewer->zoom;
1047
1048                                 x = (viewer->pdf_view_vadj->upper - event->y) / viewer->zoom;
1049                         break;
1050                 }
1051
1052                 if ( (x > x1 && x < x2) && (y > y1 && y < y2) ) {
1053                                 viewer->in_link = TRUE;
1054                         if (((MimeViewer *)viewer)->mimeview && 
1055                                 ((MimeViewer *)viewer)->mimeview->messageview && 
1056                                 ((MimeViewer *)viewer)->mimeview->messageview->window && 
1057                                 ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
1058                                         gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, link_cur);
1059                                 else
1060                                         gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, link_cur);
1061                                 
1062                                 viewer->link_action = lmapping->action; 
1063                                 ccur = TRUE;
1064                 }
1065                 if (!ccur) {
1066                         if (((MimeViewer *)viewer)->mimeview && 
1067                                 ((MimeViewer *)viewer)->mimeview->messageview && 
1068                                 ((MimeViewer *)viewer)->mimeview->messageview->window && 
1069                                 ((MimeViewer *)viewer)->mimeview->messageview->window->window) 
1070                                 gdk_window_set_cursor (((MimeViewer *)viewer)->mimeview->messageview->window->window, NULL);
1071                         else
1072                                 gdk_window_set_cursor (mainwindow_get_mainwindow()->window->window, NULL);
1073                 }
1074         }
1075         g_free(l);
1076         }
1077 }
1078 static gboolean pdf_viewer_scroll_cb(GtkWidget *widget, GdkEventScroll *event,
1079                                     PdfViewer *viewer)
1080 {
1081         GtkAdjustment *adj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
1082         static gboolean in_scroll_cb = FALSE;
1083         gboolean handled = FALSE;
1084         gint cur_p = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page));               
1085
1086         if (in_scroll_cb)
1087                 return FALSE;
1088
1089         in_scroll_cb = TRUE;
1090
1091         if (event->direction == GDK_SCROLL_UP &&
1092             adj->value == adj->lower && 
1093             cur_p > 1) {
1094                 gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_BACKWARD, 1);
1095                 adj->value = adj->upper - adj->page_size;
1096                 handled = TRUE;
1097         } else if (event->direction == GDK_SCROLL_DOWN &&
1098             adj->value + adj->page_size == adj->upper &&
1099             cur_p < viewer->num_pages) {
1100                 gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_FORWARD, 1);
1101                 adj->value = 0.0;
1102                 handled = TRUE;
1103         }
1104         in_scroll_cb = FALSE;
1105         return handled;
1106 }
1107
1108 static void pdf_viewer_button_zoom_fit_cb(GtkButton *button, PdfViewer *viewer)
1109 {
1110         GtkAllocation *allocation;
1111         double xratio, yratio;
1112         allocation = &(viewer->scrollwin->allocation);
1113         debug_print("width: %d\n", allocation->width);
1114         debug_print("height: %d\n", allocation->height);
1115         xratio = allocation->width / viewer->width;
1116         yratio = allocation->height / viewer->height;
1117
1118         if (xratio >= yratio) {
1119                 viewer->zoom = yratio;
1120                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->zoom_scroll),viewer->zoom);
1121         }
1122         else {
1123                 viewer->zoom = xratio;
1124                 gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->zoom_scroll),viewer->zoom);
1125         }
1126 }
1127
1128 static void pdf_viewer_button_zoom_width_cb(GtkButton *button, PdfViewer *viewer)
1129 {
1130         GtkAllocation *allocation;
1131         double xratio;
1132         allocation = &(viewer->scrollwin->allocation);
1133         debug_print("width: %d\n", allocation->width);
1134         xratio = allocation->width / viewer->width;
1135         gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->zoom_scroll), xratio);
1136 }
1137
1138 static void pdf_viewer_button_rotate_right_cb(GtkButton *button, PdfViewer *viewer)
1139 {
1140         if (viewer->rotate == 360) {
1141                 viewer->rotate = 0;
1142         }
1143         
1144         viewer->rotate += (gint) ROTATION;
1145         pdf_viewer_update((MimeViewer *)viewer, FALSE,
1146                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page)));
1147 }
1148
1149 static void pdf_viewer_button_rotate_left_cb(GtkButton *button, PdfViewer *viewer)
1150 {
1151         if (viewer->rotate == 0) {
1152                 viewer->rotate = 360;
1153         }
1154         
1155         viewer->rotate = abs(viewer->rotate -(gint) ROTATION);
1156         pdf_viewer_update((MimeViewer *)viewer, FALSE,
1157                 gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page)));
1158 }
1159
1160 /* Show/Hide the index pane */
1161 static void pdf_viewer_show_document_index_cb(GtkButton *button, PdfViewer *viewer)
1162 {
1163         if (!viewer->pdf_index) {
1164                 viewer->pdf_index = poppler_index_iter_new(viewer->pdf_doc);
1165         }
1166         
1167         gtk_tree_store_clear(GTK_TREE_STORE(viewer->index_model));
1168         
1169         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(viewer->doc_index))) {
1170                 pdf_viewer_get_document_index(viewer,(PopplerIndexIter *) viewer->pdf_index, NULL);
1171                 gtk_widget_show(GTK_WIDGET(viewer->frame_index));
1172         }
1173         else {
1174                 pdf_viewer_hide_index_pane(viewer);
1175         }
1176                 
1177 }
1178
1179 static void pdf_viewer_button_document_info_cb(GtkButton *button, PdfViewer *viewer)
1180 {
1181         alertpanel_full(_("PDF properties"), NULL, GTK_STOCK_CLOSE, NULL, NULL,
1182                         FALSE, (GtkWidget *) pdf_viewer_fill_info_table(viewer), 
1183                         ALERT_NOTICE, G_ALERTDEFAULT);
1184 }
1185
1186 /*
1187 static const char * poppler_get_document_info_mode(PopplerPageMode mode)
1188 {
1189         GEnumValue *enum_value;
1190
1191         enum_value = g_enum_get_value((GEnumClass *) g_type_class_peek(POPPLER_TYPE_PAGE_MODE), mode);
1192         return(gchar *) enum_value->value_name;
1193 }
1194 static const char * poppler_get_document_info_layout(PopplerPageLayout layout)
1195 {
1196
1197         GEnumValue *enum_value;
1198
1199         enum_value = g_enum_get_value((GEnumClass *) g_type_class_peek(POPPLER_TYPE_PAGE_LAYOUT), layout);
1200         return(gchar *) enum_value->value_name;
1201 }
1202 */
1203 static void pdf_viewer_show_controls(PdfViewer *viewer, gboolean show)
1204 {
1205         if (show) {
1206                 gtk_widget_show(viewer->first_page);
1207                 gtk_widget_show(viewer->cur_page);
1208                 gtk_widget_show(viewer->prev_page);
1209                 gtk_widget_show(viewer->next_page);
1210                 gtk_widget_show(viewer->last_page);
1211                 gtk_widget_show(viewer->zoom_in);
1212                 gtk_widget_show(viewer->zoom_out);
1213                 gtk_widget_show(viewer->zoom_fit);
1214                 gtk_widget_show(viewer->zoom_width);
1215                 gtk_widget_show(viewer->zoom_scroll);
1216                 gtk_widget_show(viewer->widgets_table);
1217                 gtk_widget_show(viewer->rotate_right);
1218                 gtk_widget_show(viewer->rotate_left);
1219                 gtk_widget_show(viewer->doc_info);
1220                 gtk_widget_show(viewer->doc_index);
1221         } else {
1222                 gtk_widget_hide(viewer->first_page);
1223                 gtk_widget_hide(viewer->cur_page);
1224                 gtk_widget_hide(viewer->prev_page);
1225                 gtk_widget_hide(viewer->next_page);
1226                 gtk_widget_hide(viewer->last_page);
1227                 gtk_widget_hide(viewer->zoom_in);
1228                 gtk_widget_hide(viewer->zoom_out);
1229                 gtk_widget_hide(viewer->zoom_fit);
1230                 gtk_widget_hide(viewer->zoom_width);
1231                 gtk_widget_hide(viewer->widgets_table);
1232                 gtk_widget_hide(viewer->rotate_right);
1233                 gtk_widget_hide(viewer->rotate_left);
1234                 gtk_widget_hide(viewer->doc_info);
1235                 gtk_widget_hide(viewer->doc_index);
1236                 gtk_widget_hide(viewer->zoom_scroll);
1237         }
1238 }
1239 /** Render the current page, page_num on the viewer */
1240 static void pdf_viewer_update(MimeViewer *_viewer, gboolean reload_file, int page_num) 
1241 {
1242
1243         PdfViewer *viewer = (PdfViewer *) _viewer;
1244         GError *error;
1245         gchar *tmpfile = NULL;
1246         gchar *tmp;
1247
1248         debug_print("pdf_viewer_update\n");
1249
1250         error = NULL;
1251         if (reload_file) {
1252                 if (viewer->pdf_doc) {
1253                         g_object_unref(G_OBJECT(viewer->pdf_doc));
1254                         viewer->pdf_doc = NULL;
1255                 }
1256                 
1257                 if (pdf_viewer_mimepart_get_type(viewer->to_load) == TYPE_PS) {
1258                         stock_pixbuf_gdk(viewer->hbox, 
1259                                         STOCK_PIXMAP_MIME_PS, 
1260                                         &viewer->icon_pixbuf);
1261                         gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type),
1262                                                                         viewer->icon_pixbuf);
1263                 } 
1264                 else if (pdf_viewer_mimepart_get_type(viewer->to_load) == TYPE_PDF) {
1265                         stock_pixbuf_gdk(viewer->hbox, 
1266                         STOCK_PIXMAP_MIME_PDF, 
1267                         &viewer->icon_pixbuf);
1268                         gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type), 
1269                                                                         viewer->icon_pixbuf);
1270                 } 
1271                 else {
1272                         stock_pixbuf_gdk(viewer->hbox, 
1273                         STOCK_PIXMAP_MIME_APPLICATION, 
1274                         &viewer->icon_pixbuf);
1275                         gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type), 
1276                                                                         viewer->icon_pixbuf);
1277                 }
1278
1279                 gtk_label_set_text(GTK_LABEL(viewer->doc_label), _("Loading..."));      
1280                 pdf_viewer_show_controls(viewer, FALSE);
1281                 main_window_cursor_wait(mainwindow_get_mainwindow());
1282
1283                 GTK_EVENTS_FLUSH();
1284
1285                 if (pdf_viewer_mimepart_get_type(viewer->to_load) == TYPE_PS) {
1286                         gchar *cmdline = NULL, *tmp = NULL, *gspath = NULL;
1287                         gint result = 0;
1288
1289                         if ((gspath = g_find_program_in_path("gs")) != NULL) {
1290                                 g_free(gspath);
1291                                 /* convert postscript to pdf */
1292                                 tmpfile = get_tmp_file();
1293                                 cmdline = g_strdup_printf(
1294                                         "gs -dSAFER -dCompatibilityLevel=1.2 -q -dNOPAUSE -dBATCH "
1295                                           "-sDEVICE=pdfwrite -sOutputFile=%s -c .setpdfwrite -f \"%s\"",
1296                                         tmpfile, viewer->filename);
1297                                 result = execute_command_line(cmdline, FALSE);
1298                                 if (result == 0) {
1299                                         tmp = g_filename_to_uri(tmpfile, NULL, NULL);
1300                                         viewer->pdf_doc = poppler_document_new_from_file( tmp, NULL, &error);
1301                                         g_free(tmp);
1302                                 } 
1303                                 else {
1304                                         g_warning("gs conversion failed: %s returned %d\n", cmdline, result);
1305                                         tmp = g_strdup_printf("gs: err %d", result);
1306                                         alertpanel_warning("%s", tmp);
1307                                         g_free(tmp);
1308                                 }
1309         
1310                                 g_free(cmdline);
1311                                 claws_unlink(tmpfile);
1312                                 g_free(tmpfile);
1313                         }
1314                         else {
1315                                 g_warning("gs conversion disabled: gs binary was not found\n");
1316                                 alertpanel_warning("PostScript view disabled: required gs program not found");
1317                                 result = 1;
1318                                         
1319                         }
1320                         if (result != 0) {
1321                                 main_window_cursor_normal(mainwindow_get_mainwindow());
1322                                 return;
1323                         }
1324                 }   
1325                 else {
1326                         viewer->pdf_doc = poppler_document_new_from_file( viewer->fsname, NULL, &error);
1327                 }
1328                 
1329                 viewer->num_pages = poppler_document_get_n_pages(viewer->pdf_doc);
1330
1331                 g_signal_handlers_block_by_func(G_OBJECT(viewer->cur_page), pdf_viewer_spin_change_page_cb,(gpointer *)viewer);
1332                 gtk_spin_button_set_range(GTK_SPIN_BUTTON(viewer->cur_page), 
1333                                                                         1, 
1334                                                                 (gdouble)viewer->num_pages );
1335
1336                 g_signal_handlers_unblock_by_func(G_OBJECT(viewer->cur_page), pdf_viewer_spin_change_page_cb,(gpointer *)viewer);
1337                 gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_HOME, 1);
1338                 tmp = g_strdup_printf(_("%s Document"),pdf_viewer_mimepart_get_type(viewer->to_load) == TYPE_PDF ? "PDF":"Postscript");
1339                 CLAWS_SET_TIP(
1340                                 GTK_WIDGET(viewer->icon_type_ebox),
1341                                 tmp);
1342                 g_free(tmp);
1343
1344                 tmp = g_strdup_printf(_("of %d"), viewer->num_pages);
1345                 gtk_label_set_text(GTK_LABEL(viewer->doc_label), tmp);
1346                 g_free(tmp);
1347
1348                 pdf_viewer_show_controls(viewer, TRUE);
1349                 main_window_cursor_normal(mainwindow_get_mainwindow());
1350         } 
1351         if (viewer->pdf_doc == NULL) {
1352                 strretchomp(error->message);
1353                 stock_pixbuf_gdk(viewer->hbox, 
1354                                 STOCK_PIXMAP_MIME_APPLICATION, 
1355                                 &viewer->icon_pixbuf);
1356
1357                 gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type), viewer->icon_pixbuf);
1358                 alertpanel_error("%s", error->message);
1359         
1360                 pdf_viewer_show_controls(viewer, FALSE);
1361                 g_error_free(error);
1362                 return;
1363         }
1364
1365         if (page_num == 1) { 
1366                 gtk_widget_set_sensitive(viewer->first_page, FALSE);
1367                 gtk_widget_set_sensitive(viewer->prev_page, FALSE);
1368         }
1369         else {
1370                 gtk_widget_set_sensitive(viewer->first_page, TRUE);
1371                 gtk_widget_set_sensitive(viewer->prev_page, TRUE);
1372         }
1373
1374         if (page_num == viewer->num_pages) { 
1375                 gtk_widget_set_sensitive(viewer->last_page, FALSE);
1376                 gtk_widget_set_sensitive(viewer->next_page, FALSE);
1377         }
1378         else {
1379                 gtk_widget_set_sensitive(viewer->last_page, TRUE);
1380                 gtk_widget_set_sensitive(viewer->next_page, TRUE);
1381         }
1382
1383         /* check for the index if exists */
1384         pdf_viewer_set_index_button_sensitive((PdfViewer *) viewer);
1385         
1386         if (page_num > 0 && page_num <= viewer->num_pages) {
1387
1388                 GTK_EVENTS_FLUSH();
1389                 
1390                 if (viewer->pdf_page) {
1391                         g_object_unref(G_OBJECT(viewer->pdf_page));
1392                 }
1393                         
1394                 viewer->pdf_page = poppler_document_get_page(viewer->pdf_doc, page_num - 1);
1395
1396                 if (viewer->pdf_page == NULL) {
1397                         g_warning("Page not found\n");
1398                         return;
1399                 }   
1400         
1401                 if (viewer->rotate == 90 || viewer->rotate == 270) {
1402                         poppler_page_get_size(viewer->pdf_page, &viewer->height, &viewer->width);
1403                 } 
1404                 else {
1405                         poppler_page_get_size(viewer->pdf_page, &viewer->width, &viewer->height);
1406                 }
1407
1408                 if (viewer->last_rect && viewer->last_page_result &&
1409                     viewer->last_page_result->page_num == page_num) {
1410                         pdf_viewer_render_selection(viewer, viewer->last_rect, viewer->last_page_result);
1411                 }
1412                 else {
1413                         pdf_viewer_render_page(viewer->pdf_page, viewer->pdf_view, viewer->width, 
1414                                                                         viewer->height, viewer->zoom, viewer->rotate);
1415
1416                 }
1417         
1418         /* Get Links Mapping */
1419         if (viewer->link_map) {
1420                 poppler_page_free_link_mapping(viewer->link_map);
1421         }
1422         viewer->link_map = poppler_page_get_link_mapping(viewer->pdf_page);
1423         
1424         }
1425 }
1426
1427
1428 static void pdf_viewer_show_mimepart(MimeViewer *_viewer, const gchar *infile,
1429                                 MimeInfo *partinfo)
1430 {
1431         PdfViewer *viewer = (PdfViewer *) _viewer;
1432         gchar buf[4096];
1433         const gchar *charset = NULL;
1434         MessageView *messageview = ((MimeViewer *)viewer)->mimeview 
1435                                         ?((MimeViewer *)viewer)->mimeview->messageview 
1436                                         : NULL;
1437
1438         viewer->rotate = 0;
1439         viewer->to_load = partinfo;
1440
1441         memset(buf, 0, sizeof(buf));
1442         messageview->updating = TRUE;
1443         debug_print("pdf_viewer_show_mimepart\n");
1444
1445         if (viewer->filename != NULL) {
1446                 claws_unlink(viewer->filename);
1447                 g_free(viewer->filename);
1448                 viewer->filename = NULL;
1449         }
1450         
1451         viewer->mimeinfo = NULL;
1452         
1453         if (partinfo) {
1454                 viewer->target_filename = procmime_get_part_file_name(partinfo);
1455                 viewer->filename = procmime_get_tmp_file_name(partinfo);
1456                 viewer->fsname = g_filename_to_uri(viewer->filename, NULL, NULL);
1457         }
1458         
1459         if (partinfo && !(procmime_get_part(viewer->filename, partinfo) < 0)) {
1460
1461                 if (_viewer && _viewer->mimeview && 
1462                                 _viewer->mimeview->messageview->forced_charset) {
1463                         charset = _viewer->mimeview->messageview->forced_charset;
1464                 }
1465                 else {
1466                         charset = procmime_mimeinfo_get_parameter(partinfo, "charset");
1467                 }
1468                 if (charset == NULL) {
1469                         charset = conv_get_locale_charset_str();
1470                 }
1471
1472                 debug_print("using charset %s\n", charset);
1473                 
1474                 viewer->mimeinfo = partinfo;
1475         }
1476         
1477         pdf_viewer_update((MimeViewer *)viewer, TRUE, 1);
1478         
1479         messageview->updating = FALSE;
1480 }
1481
1482 static void pdf_viewer_clear(MimeViewer *_viewer)
1483 {
1484         PdfViewer *viewer = (PdfViewer *) _viewer;
1485         GtkAdjustment *vadj;
1486                 
1487         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(viewer->doc_index), FALSE);
1488         gtk_widget_hide(viewer->frame_index);
1489
1490         debug_print("pdf_viewer_clear\n");
1491         viewer->to_load = NULL;
1492         
1493         if (viewer->pdf_doc) {
1494                 g_object_unref(G_OBJECT(viewer->pdf_doc));
1495                 viewer->pdf_doc = NULL;
1496         }
1497         
1498         vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
1499         vadj->value = 0.0;
1500         g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);
1501         vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin_index));
1502         vadj->value = 0.0;
1503         g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);
1504         gtk_tree_store_clear(GTK_TREE_STORE(viewer->index_model));
1505         gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->pdf_view), NULL);
1506 }
1507
1508 static void pdf_viewer_destroy(MimeViewer *_viewer)
1509 {
1510         PdfViewer *viewer = (PdfViewer *) _viewer;
1511
1512         debug_print("pdf_viewer_destroy\n");
1513         
1514         if (viewer->pdf_index) poppler_index_iter_free(viewer->pdf_index);
1515
1516         poppler_page_free_link_mapping (viewer->link_map);
1517         g_object_unref(GTK_WIDGET(viewer->vbox));
1518         g_object_unref(GTK_WIDGET(viewer->pdf_view));
1519         g_object_unref(GTK_WIDGET(viewer->doc_index_pane));
1520         g_object_unref(GTK_WIDGET(viewer->scrollwin));
1521         g_object_unref(GTK_WIDGET(viewer->scrollwin_index));
1522         claws_unlink(viewer->filename);
1523         g_free(viewer->filename);
1524         g_free(viewer);
1525 }
1526
1527 static gboolean pdf_viewer_scroll_page(MimeViewer *_viewer, gboolean up)
1528 {
1529         PdfViewer *viewer = (PdfViewer *)_viewer;
1530         GtkAdjustment *vadj = gtk_scrolled_window_get_vadjustment(
1531                                 GTK_SCROLLED_WINDOW(viewer->scrollwin));
1532         
1533         gint cur_p = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page));
1534         
1535         if (viewer->pdf_view == NULL) return FALSE;
1536
1537         if (!gtkutils_scroll_page(GTK_WIDGET(viewer->pdf_view), vadj, up)) {
1538                 if (!up && cur_p != viewer->num_pages) {
1539                         gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_FORWARD, 1);
1540                         vadj = gtk_scrolled_window_get_vadjustment(
1541                                         GTK_SCROLLED_WINDOW(viewer->scrollwin));
1542                         vadj->value = 0.0;
1543                         g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);
1544                         return TRUE;
1545                 } 
1546                 else if (up && cur_p != 1) {
1547                         gtk_spin_button_spin(GTK_SPIN_BUTTON(viewer->cur_page), GTK_SPIN_STEP_BACKWARD, 1);
1548                         vadj = gtk_scrolled_window_get_vadjustment(
1549                                         GTK_SCROLLED_WINDOW(viewer->scrollwin));
1550                         vadj->value = vadj->upper - vadj->page_size;
1551                         g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);
1552                         return TRUE;
1553                 } 
1554                 return FALSE;
1555         } 
1556         else return TRUE;
1557 }
1558
1559 static void pdf_viewer_scroll_one_line(MimeViewer *_viewer, gboolean up)
1560 {
1561         PdfViewer *viewer = (PdfViewer *)_viewer;
1562         GtkAdjustment *vadj = gtk_scrolled_window_get_vadjustment(
1563                                 GTK_SCROLLED_WINDOW(viewer->scrollwin));
1564         gint cur_p;
1565         cur_p = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(viewer->cur_page));
1566
1567         if (viewer->pdf_view == NULL) return; 
1568                 debug_print("up: %d\n", up);    
1569                 if (vadj->value <(vadj->upper - vadj->page_size))  {
1570                         gtkutils_scroll_one_line(GTK_WIDGET(viewer->pdf_view), vadj, up);
1571                 }
1572                 else {
1573                         if (cur_p != viewer->num_pages) {
1574                                 pdf_viewer_scroll_page((MimeViewer *)viewer, up);
1575                         }
1576                 }
1577
1578 }
1579
1580 #define BUTTON_H_PADDING 3
1581 #define ADD_BUTTON_TO_TABLE(widget, stock_image) \
1582         widget = gtk_button_new(); \
1583         img = gtk_image_new_from_stock(stock_image, GTK_ICON_SIZE_MENU); \
1584         gtk_button_set_image(GTK_BUTTON(widget), img); \
1585         gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(widget), \
1586                                 col, col+1, 0, 1, 0, 0, BUTTON_H_PADDING, 0); \
1587         col++;
1588
1589 #define ADD_SEP_TO_TABLE \
1590         sep = gtk_label_new(""); \
1591         gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(sep), \
1592                                         col, col+1, 0, 1, 0, 0, 0, 0); \
1593         gtk_table_set_col_spacing(GTK_TABLE(viewer->widgets_table), col, 3*BUTTON_H_PADDING); \
1594         col++;
1595
1596 #if GTK_CHECK_VERSION(2,10,0) && POPPLER_HAS_CAIRO && !USE_LIBGNOMEPRINT
1597 static PangoContext *pdf_viewer_get_pango_context(gpointer data)
1598 {
1599         return NULL;
1600 }
1601
1602 static gpointer pdf_viewer_get_data_to_print(gpointer data, gint sel_start, gint sel_end)
1603 {
1604         return NULL; /* we don't need it */
1605 }
1606
1607 static void pdf_viewer_cb_begin_print(GtkPrintOperation *op, GtkPrintContext *context,
1608                            gpointer user_data)
1609 {
1610   PrintData *print_data;
1611   PopplerDocument *pdf_doc;
1612   gint n_pages = 0;
1613   print_data = (PrintData*) user_data;
1614   pdf_doc = (PopplerDocument *)printing_get_renderer_data(print_data);
1615
1616   debug_print("Preparing print job...\n");
1617
1618   n_pages = poppler_document_get_n_pages(pdf_doc);
1619   printing_set_n_pages(print_data, n_pages);
1620   gtk_print_operation_set_n_pages(op, n_pages);
1621
1622   debug_print("Starting print job...\n");
1623 }
1624
1625 static void pdf_viewer_cb_draw_page(GtkPrintOperation *op, GtkPrintContext *context,
1626                          int page_nr, gpointer user_data)
1627 {
1628   cairo_t *cr;
1629   PrintData *print_data;
1630   PopplerDocument *pdf_doc;
1631   PopplerPage *pdf_page;
1632   
1633   print_data = (PrintData*) user_data;
1634   pdf_doc = (PopplerDocument *)printing_get_renderer_data(print_data);
1635   pdf_page = poppler_document_get_page(pdf_doc, page_nr);
1636
1637   cr = gtk_print_context_get_cairo_context(context);
1638   cairo_scale(cr, printing_get_zoom(print_data), printing_get_zoom(print_data));
1639   cairo_set_source_rgb(cr, 0., 0., 0.);
1640
1641   poppler_page_render_for_printing(pdf_page, cr);
1642
1643   g_object_unref(G_OBJECT(pdf_page));
1644
1645   debug_print("Sent page %d to printer\n", page_nr+1);
1646 }
1647
1648 static void pdf_viewer_print(MimeViewer *mviewer)
1649 {
1650         PdfViewer *viewer = (PdfViewer *)mviewer;
1651         PrintRenderer *pdf_renderer = g_new0(PrintRenderer, 1);
1652         MainWindow *mainwin = mainwindow_get_mainwindow();
1653         
1654         pdf_renderer->get_pango_context = pdf_viewer_get_pango_context;
1655         pdf_renderer->get_data_to_print = pdf_viewer_get_data_to_print;
1656         pdf_renderer->cb_begin_print    = pdf_viewer_cb_begin_print;
1657         pdf_renderer->cb_draw_page      = pdf_viewer_cb_draw_page;
1658
1659         printing_print_full(mainwin ? GTK_WINDOW(mainwin->window):NULL,
1660                         pdf_renderer, viewer->pdf_doc, -1, -1);
1661         
1662         g_free(pdf_renderer);
1663 }
1664 #endif
1665
1666 static MimeViewer *pdf_viewer_create(void)
1667 {
1668         PdfViewer *viewer;
1669         GtkTreeViewColumn *column;
1670         GtkCellRenderer *renderer;
1671         GtkTreeStore *tree_store;
1672         GtkWidget *sep;
1673         GtkWidget *img;
1674         gint col = 0;
1675
1676         viewer = g_new0(PdfViewer, 1);
1677         debug_print("pdf_viewer_create\n");
1678     
1679         viewer->last_x = 0;
1680         viewer->last_y = 0;
1681         viewer->mimeviewer.factory = &pdf_viewer_factory;
1682         viewer->mimeviewer.get_widget = pdf_viewer_get_widget;
1683         viewer->mimeviewer.show_mimepart = pdf_viewer_show_mimepart;
1684         viewer->mimeviewer.clear_viewer = pdf_viewer_clear;
1685         viewer->mimeviewer.destroy_viewer = pdf_viewer_destroy;
1686         viewer->mimeviewer.text_search = pdf_viewer_text_search;
1687         viewer->mimeviewer.scroll_page = pdf_viewer_scroll_page;
1688         viewer->mimeviewer.scroll_one_line = pdf_viewer_scroll_one_line;
1689 #if GTK_CHECK_VERSION(2,10,0) && POPPLER_HAS_CAIRO && !USE_LIBGNOMEPRINT
1690         viewer->mimeviewer.print = pdf_viewer_print;
1691 #endif
1692         viewer->scrollwin = gtk_scrolled_window_new(NULL, NULL);
1693         viewer->scrollwin_index = gtk_scrolled_window_new(NULL, NULL);
1694         viewer->pdf_view_ebox = gtk_event_box_new();
1695         gtk_event_box_set_visible_window(GTK_EVENT_BOX(viewer->pdf_view_ebox), FALSE);
1696                                                         
1697         viewer->mimeinfo  = NULL;
1698
1699         viewer->pdf_view = gtk_image_new();
1700         gtk_widget_set_events(viewer->pdf_view_ebox,
1701                                                 GDK_BUTTON_RELEASE_MASK
1702                                                 | GDK_POINTER_MOTION_MASK
1703                                                 | GDK_BUTTON_PRESS_MASK
1704                                                 | GDK_BUTTON_MOTION_MASK
1705                                             );
1706         gtk_container_add (GTK_CONTAINER(viewer->pdf_view_ebox), viewer->pdf_view);
1707         viewer->icon_type = gtk_image_new();
1708         viewer->icon_type_ebox = gtk_event_box_new();
1709
1710         gtk_container_add(GTK_CONTAINER(viewer->icon_type_ebox), viewer->icon_type);
1711
1712         viewer->doc_label = gtk_label_new("");
1713
1714         viewer->widgets_table = gtk_table_new(1, 1, FALSE);
1715
1716         viewer->doc_index_pane = gtk_hpaned_new();
1717
1718         viewer->frame_index = gtk_frame_new(NULL);
1719         gtk_frame_set_shadow_type(GTK_FRAME(viewer->frame_index), GTK_SHADOW_IN);
1720         gtk_widget_set_size_request(viewer->frame_index, 18, -1);
1721         gtk_frame_set_label(GTK_FRAME(viewer->frame_index), _("Document Index"));
1722
1723 #if !(GTK_CHECK_VERSION(2,12,0))
1724         viewer->button_bar_tips = tips;
1725 #endif
1726
1727         ADD_SEP_TO_TABLE
1728         ADD_BUTTON_TO_TABLE(viewer->first_page, GTK_STOCK_GOTO_FIRST)
1729         ADD_BUTTON_TO_TABLE(viewer->prev_page, GTK_STOCK_GO_BACK)
1730         viewer->cur_page = gtk_spin_button_new_with_range(0.0, 0.0, 1.0);
1731         viewer->zoom_scroll = gtk_spin_button_new_with_range(0.20, 8.0, 0.20);
1732         gtk_spin_button_set_value(GTK_SPIN_BUTTON(viewer->zoom_scroll), 1.0);
1733         viewer->zoom = 1.0;
1734         gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(viewer->cur_page), TRUE);
1735         gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(viewer->zoom_scroll), TRUE);
1736         gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(viewer->cur_page),
1737                                         col, col+1, 
1738                                         0, 1, 0, 0, 
1739                                         BUTTON_H_PADDING, 
1740                                         0);
1741         col++;
1742         gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(viewer->doc_label),
1743                                         col, col+1, 
1744                                         0, 1, 0, 0, 
1745                                         BUTTON_H_PADDING, 
1746                                         0);
1747         col++;
1748
1749         ADD_BUTTON_TO_TABLE(viewer->next_page, GTK_STOCK_GO_FORWARD)
1750         ADD_BUTTON_TO_TABLE(viewer->last_page, GTK_STOCK_GOTO_LAST)
1751         ADD_SEP_TO_TABLE
1752         ADD_BUTTON_TO_TABLE(viewer->zoom_fit, GTK_STOCK_ZOOM_FIT)
1753         ADD_BUTTON_TO_TABLE(viewer->zoom_in, GTK_STOCK_ZOOM_IN)
1754         gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(viewer->zoom_scroll),
1755                                         col, col+1, 
1756                                         0, 1, 0, 0, 
1757                                         BUTTON_H_PADDING, 
1758                                         0);
1759         col++;
1760         ADD_BUTTON_TO_TABLE(viewer->zoom_out, GTK_STOCK_ZOOM_OUT)
1761         ADD_BUTTON_TO_TABLE(viewer->zoom_width, GTK_STOCK_FULLSCREEN)
1762         ADD_SEP_TO_TABLE
1763         ADD_BUTTON_TO_TABLE(viewer->rotate_left, GTK_STOCK_UNDO)
1764         ADD_BUTTON_TO_TABLE(viewer->rotate_right, GTK_STOCK_REDO)
1765         ADD_SEP_TO_TABLE
1766         ADD_BUTTON_TO_TABLE(viewer->doc_info, GTK_STOCK_INFO)
1767
1768         viewer->doc_index = GTK_WIDGET(gtk_toggle_tool_button_new_from_stock(GTK_STOCK_INDEX));
1769         gtk_widget_set_size_request(GTK_WIDGET(viewer->doc_index), 26, 26);
1770         gtk_table_attach(GTK_TABLE(viewer->widgets_table), GTK_WIDGET(viewer->doc_index),
1771                                         col, col+1, 
1772                                         0, 1, 0, 0, 
1773                                         BUTTON_H_PADDING, 
1774                                         0);
1775         col++;
1776         
1777         gtk_scrolled_window_set_policy(
1778                         GTK_SCROLLED_WINDOW(viewer->scrollwin), 
1779                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1780
1781         gtk_scrolled_window_set_shadow_type(
1782                         GTK_SCROLLED_WINDOW(viewer->scrollwin),
1783                         GTK_SHADOW_IN);
1784
1785         gtk_scrolled_window_add_with_viewport(
1786                         GTK_SCROLLED_WINDOW(viewer->scrollwin),
1787                         viewer->pdf_view_ebox);
1788
1789         viewer->vbox = gtk_vbox_new(FALSE, 4);
1790         viewer->hbox = gtk_hbox_new(FALSE, 4);
1791
1792     /* treeview */
1793         tree_store = gtk_tree_store_new(N_INDEX_COLUMNS,
1794                                         G_TYPE_STRING,
1795                                         G_TYPE_INT,
1796                                         G_TYPE_DOUBLE);
1797
1798         viewer->index_list = gtk_tree_view_new_with_model(GTK_TREE_MODEL(tree_store));
1799         renderer = gtk_cell_renderer_text_new();
1800         column = gtk_tree_view_column_new_with_attributes(_("Name"),  renderer, "text", 0,  NULL);
1801         gtk_tree_view_append_column(GTK_TREE_VIEW(viewer->index_list), column);         
1802         gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(viewer->index_list), FALSE);
1803         
1804         viewer->index_model = GTK_TREE_MODEL(tree_store);
1805
1806         gtk_tree_selection_set_mode(gtk_tree_view_get_selection(GTK_TREE_VIEW(viewer->index_list)), 
1807                                                                 GTK_SELECTION_SINGLE);
1808
1809         g_signal_connect(G_OBJECT(viewer->index_list), "row_activated",
1810                          G_CALLBACK(pdf_viewer_index_row_activated),
1811                                          viewer);
1812
1813         gtk_scrolled_window_set_policy(
1814                         GTK_SCROLLED_WINDOW(viewer->scrollwin_index), 
1815                         GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1816
1817         gtk_scrolled_window_set_shadow_type(
1818                         GTK_SCROLLED_WINDOW(viewer->scrollwin_index),
1819                         GTK_SHADOW_IN);
1820
1821         gtk_scrolled_window_add_with_viewport(
1822                         GTK_SCROLLED_WINDOW(viewer->scrollwin_index),
1823                         viewer->index_list);
1824
1825         /* end treeview */
1826
1827         stock_pixbuf_gdk(viewer->hbox, 
1828                         STOCK_PIXMAP_MIME_TEXT_PLAIN, 
1829                         &viewer->icon_pixbuf);
1830
1831         gtk_image_set_from_pixbuf(GTK_IMAGE(viewer->icon_type), 
1832                                 viewer->icon_pixbuf);
1833
1834         /* pack widgets*/
1835         gtk_box_pack_start(GTK_BOX(viewer->hbox), viewer->icon_type_ebox, FALSE, FALSE, 0);
1836         gtk_box_pack_start(GTK_BOX(viewer->hbox), viewer->widgets_table, FALSE, FALSE, 0);
1837
1838         gtk_container_add(GTK_CONTAINER(viewer->frame_index), viewer->scrollwin_index);
1839
1840         gtk_paned_pack1(GTK_PANED(viewer->doc_index_pane), viewer->frame_index, FALSE, FALSE);
1841         gtk_paned_pack2(GTK_PANED(viewer->doc_index_pane), viewer->scrollwin, FALSE, FALSE);
1842
1843         gtk_box_pack_start(GTK_BOX(viewer->vbox), viewer->hbox, FALSE, FALSE, 0);
1844         gtk_box_pack_start(GTK_BOX(viewer->vbox), viewer->doc_index_pane, TRUE, TRUE, 0);
1845         /* show widgets */
1846         gtk_widget_show(GTK_WIDGET(viewer->doc_index_pane));
1847         g_object_ref(GTK_WIDGET(viewer->doc_index_pane));
1848         gtk_widget_show(GTK_WIDGET(viewer->scrollwin));
1849         g_object_ref(GTK_WIDGET(viewer->scrollwin));
1850         gtk_widget_show(GTK_WIDGET(viewer->icon_type_ebox));
1851         g_object_ref(GTK_WIDGET(viewer->icon_type_ebox));
1852         gtk_widget_show(GTK_WIDGET(viewer->pdf_view_ebox));
1853         g_object_ref(GTK_WIDGET(viewer->pdf_view_ebox));
1854         gtk_widget_show(GTK_WIDGET(viewer->scrollwin_index));
1855         g_object_ref(GTK_WIDGET(viewer->scrollwin_index));
1856         gtk_widget_show(GTK_WIDGET(viewer->hbox));
1857         g_object_ref(GTK_WIDGET(viewer->hbox)); 
1858         gtk_widget_show(GTK_WIDGET(viewer->vbox));
1859         g_object_ref(GTK_WIDGET(viewer->vbox));
1860
1861         gtk_widget_show(GTK_WIDGET(viewer->widgets_table));
1862         g_object_ref(GTK_WIDGET(viewer->widgets_table));
1863
1864         gtk_widget_show(GTK_WIDGET(viewer->cur_page));
1865         g_object_ref(GTK_WIDGET(viewer->cur_page));
1866
1867         gtk_widget_show(GTK_WIDGET(viewer->first_page));
1868         g_object_ref(GTK_WIDGET(viewer->first_page));
1869
1870         gtk_widget_show(GTK_WIDGET(viewer->last_page));
1871         g_object_ref(GTK_WIDGET(viewer->last_page));
1872
1873         gtk_widget_show(GTK_WIDGET(viewer->prev_page));
1874         g_object_ref(GTK_WIDGET(viewer->prev_page));
1875
1876         gtk_widget_show(GTK_WIDGET(viewer->next_page));
1877         g_object_ref(GTK_WIDGET(viewer->next_page));
1878
1879         gtk_widget_show(GTK_WIDGET(viewer->zoom_in));
1880         g_object_ref(GTK_WIDGET(viewer->zoom_in));
1881         gtk_widget_show(GTK_WIDGET(viewer->zoom_out));
1882         g_object_ref(GTK_WIDGET(viewer->zoom_out));
1883         gtk_widget_show(GTK_WIDGET(viewer->zoom_fit));
1884         g_object_ref(GTK_WIDGET(viewer->zoom_fit));
1885         gtk_widget_show(GTK_WIDGET(viewer->zoom_width));
1886         g_object_ref(GTK_WIDGET(viewer->zoom_width));
1887
1888         gtk_widget_show(GTK_WIDGET(viewer->rotate_right));
1889         g_object_ref(GTK_WIDGET(viewer->rotate_right));
1890         gtk_widget_show(GTK_WIDGET(viewer->rotate_left));
1891         g_object_ref(GTK_WIDGET(viewer->rotate_left));
1892         gtk_widget_show(GTK_WIDGET(viewer->doc_info));
1893         g_object_ref(GTK_WIDGET(viewer->doc_info));
1894         gtk_widget_show(GTK_WIDGET(viewer->doc_index));
1895         g_object_ref(GTK_WIDGET(viewer->doc_index));
1896
1897         gtk_widget_show(GTK_WIDGET(viewer->doc_label));
1898         g_object_ref(GTK_WIDGET(viewer->doc_label));
1899         gtk_widget_show(GTK_WIDGET(viewer->icon_type));
1900         g_object_ref(GTK_WIDGET(viewer->icon_type));    
1901         gtk_widget_show(GTK_WIDGET(viewer->pdf_view));
1902         g_object_ref(GTK_WIDGET(viewer->pdf_view));
1903         gtk_widget_show(GTK_WIDGET(viewer->zoom_scroll));
1904         g_object_ref(GTK_WIDGET(viewer->zoom_scroll));
1905
1906         gtk_widget_show(GTK_WIDGET(viewer->index_list));
1907         g_object_ref(GTK_WIDGET(viewer->index_list));
1908
1909         /* Set Tooltips*/
1910         CLAWS_SET_TIP(viewer->first_page,
1911                                 _("First Page"));
1912
1913         CLAWS_SET_TIP(viewer->prev_page,
1914                                 _("Previous Page"));
1915
1916         CLAWS_SET_TIP(viewer->next_page,
1917                                 _("Next Page"));
1918         
1919         CLAWS_SET_TIP(viewer->last_page,
1920                                 _("Last Page"));
1921
1922         CLAWS_SET_TIP(viewer->zoom_in,
1923                                 _("Zoom In"));
1924         CLAWS_SET_TIP(viewer->zoom_out,
1925                                 _("Zoom Out"));
1926
1927         CLAWS_SET_TIP(viewer->zoom_fit,
1928                                 _("Fit Page"));
1929
1930         CLAWS_SET_TIP(viewer->zoom_width,
1931                                 _("Fit Page Width"));
1932
1933         CLAWS_SET_TIP(viewer->rotate_left,
1934                                 _("Rotate Left"));
1935
1936         CLAWS_SET_TIP(viewer->rotate_right,
1937                                 _("Rotate Right"));
1938
1939         CLAWS_SET_TIP(viewer->doc_info,
1940                                 _("Document Info"));
1941
1942         CLAWS_SET_TIP(viewer->doc_index,
1943                                 _("Document Index"));
1944         CLAWS_SET_TIP(viewer->cur_page,
1945                                 _("Page Number"));
1946         CLAWS_SET_TIP(viewer->zoom_scroll,
1947                                 _("Zoom Factor"));
1948         /* Connect Signals */
1949         g_signal_connect(G_OBJECT(viewer->cur_page), 
1950                                     "value-changed", 
1951                                     G_CALLBACK(pdf_viewer_spin_change_page_cb), 
1952                                    (gpointer) viewer);
1953
1954         g_signal_connect(G_OBJECT(viewer->first_page), 
1955                                     "clicked", 
1956                                     G_CALLBACK(pdf_viewer_button_first_page_cb), 
1957                                    (gpointer) viewer);
1958         g_signal_connect(G_OBJECT(viewer->prev_page), 
1959                                     "clicked", 
1960                                     G_CALLBACK(pdf_viewer_button_prev_page_cb), 
1961                                    (gpointer) viewer);
1962         g_signal_connect(G_OBJECT(viewer->next_page), 
1963                                     "clicked", 
1964                                     G_CALLBACK(pdf_viewer_button_next_page_cb), 
1965                                    (gpointer) viewer);
1966         g_signal_connect(G_OBJECT(viewer->last_page), 
1967                                     "clicked", 
1968                                     G_CALLBACK(pdf_viewer_button_last_page_cb), 
1969                                    (gpointer) viewer);
1970         g_signal_connect(G_OBJECT(viewer->zoom_in), 
1971                                     "clicked", 
1972                                     G_CALLBACK(pdf_viewer_button_zoom_in_cb), 
1973                                    (gpointer) viewer);
1974         g_signal_connect(G_OBJECT(viewer->zoom_out), 
1975                                     "clicked", 
1976                                     G_CALLBACK(pdf_viewer_button_zoom_out_cb), 
1977                                    (gpointer) viewer);
1978         g_signal_connect(G_OBJECT(viewer->zoom_scroll), 
1979                                     "value-changed", 
1980                                     G_CALLBACK(pdf_viewer_spin_zoom_scroll_cb), 
1981                                    (gpointer) viewer);
1982
1983         g_signal_connect(G_OBJECT(viewer->zoom_fit), 
1984                                    "clicked", 
1985                                     G_CALLBACK(pdf_viewer_button_zoom_fit_cb), 
1986                                    (gpointer) viewer);
1987
1988         g_signal_connect(G_OBJECT(viewer->zoom_width), 
1989                                     "clicked", 
1990                                     G_CALLBACK(pdf_viewer_button_zoom_width_cb), 
1991                                    (gpointer) viewer);
1992
1993         g_signal_connect(G_OBJECT(viewer->rotate_right), 
1994                                     "clicked", 
1995                                     G_CALLBACK(pdf_viewer_button_rotate_right_cb), 
1996                                    (gpointer) viewer);
1997         
1998         g_signal_connect(G_OBJECT(viewer->rotate_left), 
1999                                     "clicked", 
2000                                     G_CALLBACK(pdf_viewer_button_rotate_left_cb), 
2001                                    (gpointer) viewer);
2002         
2003         g_signal_connect(G_OBJECT(viewer->doc_info), 
2004                                     "clicked", 
2005                                     G_CALLBACK(pdf_viewer_button_document_info_cb), 
2006                                    (gpointer) viewer);  
2007         
2008         g_signal_connect(G_OBJECT(viewer->doc_index), 
2009                                     "clicked", 
2010                                     G_CALLBACK(pdf_viewer_show_document_index_cb), 
2011                                    (gpointer) viewer);
2012         g_signal_connect(G_OBJECT(viewer->scrollwin), 
2013                                     "scroll-event", 
2014                                     G_CALLBACK(pdf_viewer_scroll_cb), 
2015                                    (gpointer) viewer);
2016         g_signal_connect(G_OBJECT(viewer->pdf_view_ebox), 
2017                                     "button_press_event", 
2018                                     G_CALLBACK(pdf_viewer_button_press_events_cb), 
2019                                    (gpointer) viewer);
2020         g_signal_connect(G_OBJECT(viewer->pdf_view_ebox), 
2021                                     "button_release_event", 
2022                                     G_CALLBACK(pdf_viewer_mouse_scroll_destroy_cb), 
2023                                    (gpointer) viewer);
2024         g_signal_connect(G_OBJECT(viewer->pdf_view_ebox), 
2025                                     "motion_notify_event", 
2026                                     G_CALLBACK(pdf_viewer_move_events_cb), 
2027                                    (gpointer) viewer);
2028
2029         viewer->target_filename = NULL;
2030         viewer->filename = NULL;
2031         viewer->fsname = NULL;
2032
2033         return(MimeViewer *) viewer;
2034 }
2035
2036 #undef ADD_BUTTON_TO_TABLE
2037 #undef ADD_SEP_TO_TABLE
2038 #undef BUTTON_H_PADDING
2039 #undef SEP_H_PADDING
2040                 
2041 static MimeViewerFactory pdf_viewer_factory =
2042 {
2043         content_types,
2044         0,
2045         pdf_viewer_create,
2046 };
2047
2048 gint plugin_init(gchar **error)
2049 {
2050         gchar *gspath = NULL;
2051
2052         msg = g_strdup_printf(_("This plugin enables the viewing of PDF and PostScript "
2053                                 "attachments using the Poppler %s Lib and the gs tool.\n\n"
2054                                 "Any feedback is welcome: iwkse@claws-mail.org"
2055                                 ), poppler_get_version());
2056
2057         if (!check_plugin_version(MAKE_NUMERIC_VERSION(3,8,1,46),
2058                     VERSION_NUMERIC, _("PDF Viewer"), error)) return -1;
2059
2060         if ((gspath = g_find_program_in_path("gs")) == NULL) {
2061                 gchar *pmsg = msg;
2062                 msg = g_strdup_printf(_("Warning: could not find ghostscript binary (gs) required "
2063                                         "for %s plugin to process PostScript attachments, only PDF "
2064                                         "attachments will be displayed. To enable PostScript "
2065                                         "support please install gs program.\n\n%s"
2066                                         ), _("PDF Viewer"), pmsg);
2067                 g_free(pmsg);
2068         }
2069         else {
2070                 g_free(gspath);
2071         }
2072         
2073         mimeview_register_viewer_factory(&pdf_viewer_factory);
2074         return 0;
2075 }
2076
2077 gboolean plugin_done(void)
2078 {
2079         g_free(msg);    
2080         mimeview_unregister_viewer_factory(&pdf_viewer_factory);
2081         return TRUE;
2082 }
2083
2084 const gchar *plugin_name(void)
2085 {
2086         return _("PDF Viewer");
2087 }
2088
2089 const gchar *plugin_desc(void)
2090 {
2091         return msg;
2092 }
2093
2094 const gchar *plugin_type(void)
2095 {
2096         return "GTK2";
2097 }
2098
2099 const gchar *plugin_licence(void)
2100 {
2101         return "GPL3+";
2102 }
2103
2104 const gchar *plugin_version(void)
2105 {
2106         return VERSION;
2107 }
2108
2109 struct PluginFeature *plugin_provides(void)
2110 {
2111         static struct PluginFeature features[] = 
2112                 { {PLUGIN_MIMEVIEWER, "application/pdf"},
2113                   {PLUGIN_MIMEVIEWER, "application/postscript"},
2114                   {PLUGIN_NOTHING, NULL} };
2115         return features;
2116 }
2117