2013-03-13 [colin] 3.9.0cvs119
[claws.git] / src / plugins / fancy / fancy_viewer.c
1 /* 
2  * Claws Mail -- A GTK+ based, lightweight, and fast e-mail client
3  * == Fancy Plugin ==
4  * Copyright(C) 1999-2013 the Claws Mail Team
5  * This file Copyright (C) 2009-2013 Salvatore De Paolis
6  * <iwkse@claws-mail.org> and the Claws Mail Team
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  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write tothe Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #include "claws-features.h"
24 #endif
25
26 #include <fancy_viewer.h>
27 #include <fancy_prefs.h>
28 #include <alertpanel.h>
29
30 #include <printing.h>
31
32
33 static void 
34 load_start_cb (WebKitWebView *view, gint progress, FancyViewer *viewer);
35
36 static void 
37 load_finished_cb (WebKitWebView *view, gint progress, FancyViewer *viewer);
38
39 static void 
40 over_link_cb (WebKitWebView *view, const gchar *wtf, const gchar *link, 
41                           FancyViewer *viewer, void *wtfa);
42
43 static void 
44 load_progress_cb (WebKitWebView *view, gint progress, FancyViewer *viewer);
45
46 static WebKitNavigationResponse 
47 navigation_requested_cb (WebKitWebView *view, WebKitWebFrame *frame, 
48                                                  WebKitNetworkRequest *netreq, FancyViewer *viewer);
49
50 static MimeViewerFactory fancy_viewer_factory;
51
52 static gboolean
53 fancy_text_search(MimeViewer *_viewer, gboolean backward, const gchar *str, 
54                                   gboolean case_sens);
55
56 static void 
57 viewer_menu_handler(GtkWidget *menuitem, FancyViewer *viewer);
58
59 static gint keypress_events_cb (GtkWidget *widget, GdkEventKey *event,
60                                                                 FancyViewer *viewer);
61 static void zoom_in_cb(GtkWidget *widget, GdkEvent *ev, FancyViewer *viewer);
62 static void zoom_out_cb(GtkWidget *widget, GdkEvent *ev, FancyViewer *viewer);
63 static gboolean fancy_prefs_cb(GtkWidget *widget, GdkEventButton *ev, FancyViewer *viewer);
64 static void zoom_100_cb(GtkWidget *widget, GdkEvent *ev, FancyViewer *viewer);
65 static void open_in_browser_cb(GtkWidget *widget, FancyViewer *viewer);
66 static void fancy_create_popup_prefs_menu(FancyViewer *viewer);
67 static void fancy_show_notice(FancyViewer *viewer, const gchar *message);
68 static size_t download_file_curl_write_cb(void *buffer, size_t size, 
69                                                                                   size_t nmemb, void *data);
70 static void *download_file_curl (void *data);
71 static void download_file_cb(GtkWidget *widget, FancyViewer *viewer);
72
73 #if !WEBKIT_CHECK_VERSION (1,5,1)
74 gchar* webkit_web_view_get_selected_text(WebKitWebView* web_view);
75 #endif
76
77 /*------*/
78 static GtkWidget *fancy_get_widget(MimeViewer *_viewer)
79 {
80         FancyViewer *viewer = (FancyViewer *) _viewer;
81         debug_print("fancy_get_widget: %p\n", viewer->vbox);
82
83         return GTK_WIDGET(viewer->vbox);
84 }
85
86 static void fancy_apply_prefs(FancyViewer *viewer)
87 {
88         g_object_set(viewer->settings, "auto-load-images",
89                 viewer->override_prefs_images, NULL);
90         g_object_set(viewer->settings, "enable-scripts",
91                 viewer->override_prefs_scripts, NULL);
92         g_object_set(viewer->settings, "enable-plugins",
93                 viewer->override_prefs_plugins, NULL);
94         g_object_set(viewer->settings, "enable-java-applet",
95                 viewer->override_prefs_java, NULL);
96
97         webkit_web_view_set_settings(viewer->view, viewer->settings);
98 }
99
100 static void fancy_auto_load_images_activated(GtkCheckMenuItem *item, FancyViewer *viewer) {
101         viewer->override_prefs_images = gtk_check_menu_item_get_active(item);
102         fancy_apply_prefs(viewer);
103         webkit_web_view_reload (viewer->view);
104 }
105
106 static void fancy_enable_remote_content_activated(GtkCheckMenuItem *item, FancyViewer *viewer) {
107         viewer->override_prefs_remote_content = gtk_check_menu_item_get_active(item);
108         fancy_apply_prefs(viewer);
109         webkit_web_view_reload (viewer->view);
110 }
111
112 static void fancy_enable_scripts_activated(GtkCheckMenuItem *item, FancyViewer *viewer) {
113         viewer->override_prefs_scripts = gtk_check_menu_item_get_active(item);
114         fancy_apply_prefs(viewer);
115         webkit_web_view_reload (viewer->view);
116 }
117
118 static void fancy_enable_plugins_activated(GtkCheckMenuItem *item, FancyViewer *viewer) {
119         viewer->override_prefs_plugins = gtk_check_menu_item_get_active(item);
120         fancy_apply_prefs(viewer);
121         webkit_web_view_reload (viewer->view);
122 }
123
124 static void fancy_enable_java_activated(GtkCheckMenuItem *item, FancyViewer *viewer) {
125         viewer->override_prefs_java = gtk_check_menu_item_get_active(item);
126         fancy_apply_prefs(viewer);
127         webkit_web_view_reload (viewer->view);
128 }
129
130 static void fancy_open_external_activated(GtkCheckMenuItem *item, FancyViewer *viewer) {
131         viewer->override_prefs_external = gtk_check_menu_item_get_active(item);
132         fancy_apply_prefs(viewer);
133 }
134
135 static void fancy_set_defaults(FancyViewer *viewer)
136 {
137         viewer->override_prefs_remote_content = fancy_prefs.enable_remote_content;
138         viewer->override_prefs_external = fancy_prefs.open_external;
139         viewer->override_prefs_images = fancy_prefs.enable_images;
140         viewer->override_prefs_scripts = fancy_prefs.enable_scripts;
141         viewer->override_prefs_plugins = fancy_prefs.enable_plugins;
142         viewer->override_prefs_java = fancy_prefs.enable_java;
143
144         g_signal_handlers_block_by_func(G_OBJECT(viewer->enable_images),
145                 fancy_auto_load_images_activated, viewer);
146         g_signal_handlers_block_by_func(G_OBJECT(viewer->enable_remote_content),
147                 fancy_enable_remote_content_activated, viewer);
148         g_signal_handlers_block_by_func(G_OBJECT(viewer->enable_scripts),
149                 fancy_enable_scripts_activated, viewer);
150         g_signal_handlers_block_by_func(G_OBJECT(viewer->enable_plugins),
151                 fancy_enable_plugins_activated, viewer);
152         g_signal_handlers_block_by_func(G_OBJECT(viewer->enable_java),
153                 fancy_enable_java_activated, viewer);
154         g_signal_handlers_block_by_func(G_OBJECT(viewer->open_external),
155                 fancy_open_external_activated, viewer);
156
157         gtk_check_menu_item_set_active(
158                 GTK_CHECK_MENU_ITEM(viewer->enable_images),
159                 viewer->override_prefs_images);
160         gtk_check_menu_item_set_active(
161                 GTK_CHECK_MENU_ITEM(viewer->enable_scripts),
162                 viewer->override_prefs_scripts);
163         gtk_check_menu_item_set_active(
164                 GTK_CHECK_MENU_ITEM(viewer->enable_plugins),
165                 viewer->override_prefs_plugins);
166         gtk_check_menu_item_set_active(
167                 GTK_CHECK_MENU_ITEM(viewer->enable_java),
168                 viewer->override_prefs_java);
169         gtk_check_menu_item_set_active(
170                 GTK_CHECK_MENU_ITEM(viewer->enable_remote_content),
171                 viewer->override_prefs_remote_content);
172         gtk_check_menu_item_set_active(
173                 GTK_CHECK_MENU_ITEM(viewer->open_external),
174                 viewer->override_prefs_external);
175
176         g_signal_handlers_unblock_by_func(G_OBJECT(viewer->enable_images),
177                 fancy_auto_load_images_activated, viewer);
178         g_signal_handlers_unblock_by_func(G_OBJECT(viewer->enable_remote_content),
179                 fancy_enable_remote_content_activated, viewer);
180         g_signal_handlers_unblock_by_func(G_OBJECT(viewer->enable_scripts),
181                 fancy_enable_scripts_activated, viewer);
182         g_signal_handlers_unblock_by_func(G_OBJECT(viewer->enable_plugins),
183                 fancy_enable_plugins_activated, viewer);
184         g_signal_handlers_unblock_by_func(G_OBJECT(viewer->enable_java),
185                 fancy_enable_java_activated, viewer);
186         g_signal_handlers_unblock_by_func(G_OBJECT(viewer->open_external),
187                 fancy_open_external_activated, viewer);
188
189         fancy_apply_prefs(viewer);
190 }
191
192 static void fancy_load_uri(FancyViewer *viewer, const gchar *uri)
193 {
194 #if WEBKIT_CHECK_VERSION(1,1,1)
195         webkit_web_view_load_uri(viewer->view, uri);
196 #else
197         webkit_web_view_open(viewer->view, uri);
198 #endif
199 }
200
201 static gboolean fancy_show_mimepart_real(MimeViewer *_viewer)
202 {
203         FancyViewer *viewer = (FancyViewer *) _viewer;
204         MessageView *messageview = ((MimeViewer *)viewer)->mimeview 
205                                         ? ((MimeViewer *)viewer)->mimeview->messageview 
206                                         : NULL;
207         MimeInfo *partinfo = viewer->to_load;
208     
209         messageview->updating = TRUE;
210
211         if (viewer->filename != NULL) {
212                 g_unlink(viewer->filename);
213                 g_free(viewer->filename);
214                 viewer->filename = NULL;
215         }
216
217         if (messageview) {
218                 NoticeView *noticeview = messageview->noticeview;
219                 noticeview_hide(noticeview);
220         }
221         if (partinfo) 
222                 viewer->filename = procmime_get_tmp_file_name(partinfo);
223         debug_print("filename: %s\n", viewer->filename);
224         if (!viewer->filename) {    
225                 return FALSE;
226         }
227         if (procmime_get_part(viewer->filename, partinfo) < 0) {
228                 g_free(viewer->filename);
229                 viewer->filename = NULL;
230         } 
231         else {
232                 const gchar *charset = NULL;
233                 if (_viewer && _viewer->mimeview &&
234                         _viewer->mimeview->messageview->forced_charset)
235                         charset = _viewer->mimeview->messageview->forced_charset;
236                 else
237                         charset = procmime_mimeinfo_get_parameter(partinfo, "charset");
238                 if (!charset)
239                         charset = conv_get_locale_charset_str();
240                 debug_print("using %s charset\n", charset);
241                 g_object_set(viewer->settings, "default-encoding", charset, NULL);
242                 gchar *tmp = g_filename_to_uri(viewer->filename, NULL, NULL);
243                 debug_print("zoom_level: %i\n", fancy_prefs.zoom_level);
244                 webkit_web_view_set_zoom_level(viewer->view, (fancy_prefs.zoom_level / 100.0));
245
246                 fancy_set_defaults(viewer);
247                 fancy_load_uri(viewer, tmp);
248
249                 g_free(tmp);
250         }
251         viewer->loading = FALSE;
252         return FALSE;
253 }
254 static void fancy_show_notice(FancyViewer *viewer, const gchar *message)
255 {
256         gtk_label_set_text(GTK_LABEL(viewer->l_link), message);
257 }
258 static gint fancy_show_mimepart_prepare(MimeViewer *_viewer)
259 {
260         FancyViewer *viewer = (FancyViewer *) _viewer;
261
262         if (viewer->tag > 0) {
263                 gtk_timeout_remove(viewer->tag);
264                 viewer->tag = -1;
265                 if (viewer->loading) {
266                         viewer->stop_previous = TRUE;
267                 }
268         }
269     
270         viewer->tag = g_timeout_add(5, (GSourceFunc)fancy_show_mimepart_real, viewer);
271         return FALSE;
272 }
273
274 static void fancy_show_mimepart(MimeViewer *_viewer, const gchar *infile,
275                                                                 MimeInfo *partinfo)
276 {
277         FancyViewer *viewer = (FancyViewer *) _viewer;
278         viewer->to_load = partinfo;
279         viewer->loading = TRUE;
280         g_timeout_add(5, (GtkFunction)fancy_show_mimepart_prepare, viewer);
281 }
282
283 static void fancy_print(MimeViewer *_viewer)
284 {
285         FancyViewer *viewer = (FancyViewer *) _viewer;
286         GtkPrintOperationResult res;
287         GError *error = NULL;
288         GtkPrintOperation *op;
289
290         gtk_widget_realize(GTK_WIDGET(viewer->view));
291     
292         while (viewer->loading)
293                 claws_do_idle();
294
295         op = gtk_print_operation_new();
296
297         /* Config for printing */
298         gtk_print_operation_set_print_settings(op, printing_get_settings());
299         gtk_print_operation_set_default_page_setup(op, printing_get_page_setup());
300 #if GTK_CHECK_VERSION(2,18,0)
301         /* enable Page Size and Orientation in the print dialog */
302         gtk_print_operation_set_embed_page_setup(op, TRUE);
303 #endif
304
305         /* Start printing process */
306         res = webkit_web_frame_print_full(webkit_web_view_get_main_frame(viewer->view),
307                                           op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG,
308                                           &error);
309
310         if (res == GTK_PRINT_OPERATION_RESULT_ERROR) {
311                 gtk_print_operation_get_error(op, &error);
312                 debug_print("Error printing message: %s\n",
313                             error ? error->message : "no details");
314         } else if (res == GTK_PRINT_OPERATION_RESULT_APPLY) {
315                 /* store settings for next printing session */
316                 printing_store_settings(gtk_print_operation_get_print_settings(op));
317         }
318 }
319
320 static gchar *fancy_get_selection (MimeViewer *_viewer)
321 {
322         debug_print("fancy_get_selection\n");
323         FancyViewer *viewer = (FancyViewer *) _viewer;
324 #if WEBKIT_CHECK_VERSION(1,5,1)
325         viewer->doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(viewer->view));
326         viewer->window = webkit_dom_document_get_default_view (viewer->doc);
327         viewer->selection = webkit_dom_dom_window_get_selection (viewer->window);
328         if (viewer->selection == NULL)
329                 return NULL;
330         viewer->range = webkit_dom_dom_selection_get_range_at(viewer->selection, 0, NULL);
331         if (viewer->range == NULL)
332                 return NULL;
333         gchar *sel = webkit_dom_range_get_text (viewer->range);
334 #else
335         gchar *sel = webkit_web_view_get_selected_text(viewer->view);
336 #endif
337         if (!viewer->view || strlen(sel) == 0) {
338                 g_free(sel);
339                 return NULL;
340         }
341         return sel; 
342 }
343
344 static void fancy_clear_viewer(MimeViewer *_viewer)
345 {
346         FancyViewer *viewer = (FancyViewer *) _viewer;
347         GtkAdjustment *vadj;
348         viewer->cur_link = NULL;
349         fancy_set_defaults(viewer);
350
351         fancy_load_uri(viewer, "about:blank");
352
353         debug_print("fancy_clear_viewer\n");
354         fancy_prefs.zoom_level = webkit_web_view_get_zoom_level(viewer->view) * 100;
355         viewer->to_load = NULL;
356         vadj = gtk_scrolled_window_get_vadjustment(GTK_SCROLLED_WINDOW(viewer->scrollwin));
357         gtk_adjustment_set_value(vadj, 0.0);
358         g_signal_emit_by_name(G_OBJECT(vadj), "value-changed", 0);
359 }
360
361 static void fancy_destroy_viewer(MimeViewer *_viewer)
362 {
363         FancyViewer *viewer = (FancyViewer *) _viewer;
364         fancy_prefs.zoom_level = webkit_web_view_get_zoom_level(viewer->view) * 100;
365         debug_print("fancy_destroy_viewer\n");
366         g_free(viewer->filename);
367         g_free(viewer);
368 }
369
370 static WebKitNavigationResponse 
371 navigation_requested_cb(WebKitWebView *view, WebKitWebFrame *frame, 
372                                                 WebKitNetworkRequest *netreq, FancyViewer *viewer)
373 {
374         const gchar *uri = webkit_network_request_get_uri(netreq);
375         debug_print("navigation requested to %s\n", uri);
376
377         if (!strncmp(uri, "mailto:", 7)) {
378                 compose_new(NULL, uri + 7, NULL);
379                 return WEBKIT_NAVIGATION_RESPONSE_IGNORE;
380         } else if (!strncmp(uri, "file://", 7)) {
381                 return WEBKIT_NAVIGATION_RESPONSE_ACCEPT;
382         } else if (viewer->override_prefs_remote_content)
383                 return WEBKIT_NAVIGATION_RESPONSE_ACCEPT;
384         else {
385                 fancy_show_notice(viewer, _("Remote content loading is disabled."));
386                 return WEBKIT_NAVIGATION_RESPONSE_IGNORE;
387         }
388 }
389
390 static void resource_request_starting_cb(WebKitWebView                  *view, 
391                                                                                  WebKitWebFrame                 *frame,
392                                                                                  WebKitWebResource              *resource,
393                                                                                  WebKitNetworkRequest   *request,
394                                                                                  WebKitNetworkResponse  *response,
395                                                                                  FancyViewer                    *viewer)
396 {
397         const gchar *uri = webkit_network_request_get_uri(request);
398         gchar *filename;
399         gchar *image;
400         gint err;
401         MimeInfo *partinfo = viewer->to_load;
402         
403         filename = viewer->filename;
404         if ((!g_ascii_strncasecmp(uri, "cid:", 4)) || (!g_ascii_strncasecmp(uri, "mid:", 4))) {
405                 image = g_strconcat("<", uri + 4, ">", NULL);
406                 while ((partinfo = procmime_mimeinfo_next(partinfo)) != NULL) {
407                         if (!g_ascii_strcasecmp(image, partinfo->id)) {
408                                 filename = procmime_get_tmp_file_name(partinfo);
409                                 if (!filename) {
410                                         g_free(image);
411                                         return;
412                                 }
413                                 if ((err = procmime_get_part(filename, partinfo)) < 0)
414                                         alertpanel_error(_("Couldn't save the part of multipart message: %s"),
415                                                                                 strerror(-err));
416                                 gchar *file_uri = g_strconcat("file://", filename, NULL);
417                                 webkit_network_request_set_uri(request, file_uri);
418                                 g_free(file_uri);
419                                 g_free(filename);
420                                 break;
421                         }
422                 }
423                 g_free(image);
424         }
425         
426         /* refresh URI that may have changed */
427         uri = webkit_network_request_get_uri(request);
428         if (!viewer->override_prefs_remote_content
429             && strncmp(uri, "file://", 7)) {
430                 debug_print("Preventing load of %s\n", uri);
431                 webkit_network_request_set_uri(request, "about:blank");
432         } else
433                 debug_print("Starting request of %s\n", uri);
434 }
435
436 static gboolean fancy_text_search(MimeViewer *_viewer, gboolean backward, 
437                                                                   const gchar *str, gboolean case_sens)
438 {
439         return webkit_web_view_search_text(((FancyViewer*)_viewer)->view, str,
440                                                                            case_sens, !backward, TRUE);
441 }
442
443 static gboolean fancy_prefs_cb(GtkWidget *widget, GdkEventButton *ev, FancyViewer *viewer)
444 {
445         if ((ev->button == 1) && (ev->type == GDK_BUTTON_PRESS)) {
446                 gtk_menu_popup(GTK_MENU(viewer->fancy_prefs_menu), NULL, NULL, NULL, NULL,
447                                            ev->button, ev->time);
448                 return TRUE;
449         }
450         return FALSE;
451 }
452
453 static void fancy_create_popup_prefs_menu(FancyViewer *viewer) {
454         GtkWidget *enable_images;
455         GtkWidget *enable_remote_content;
456         GtkWidget *enable_scripts;
457         GtkWidget *enable_plugins;
458         GtkWidget *enable_java;
459         GtkWidget *open_external;
460
461         enable_images = gtk_check_menu_item_new_with_label(_("Load images"));
462
463         enable_remote_content = gtk_check_menu_item_new_with_label(_("Enable remote content"));
464
465         enable_scripts = gtk_check_menu_item_new_with_label(_("Enable Javascript"));
466
467         enable_plugins = gtk_check_menu_item_new_with_label(_("Enable Plugins"));
468
469         enable_java = gtk_check_menu_item_new_with_label(_("Enable Java"));
470
471         open_external = gtk_check_menu_item_new_with_label(_("Open links with external browser"));
472
473         gtk_menu_shell_append(GTK_MENU_SHELL(viewer->fancy_prefs_menu), enable_images);
474         gtk_menu_shell_append(GTK_MENU_SHELL(viewer->fancy_prefs_menu), enable_remote_content);
475         gtk_menu_shell_append(GTK_MENU_SHELL(viewer->fancy_prefs_menu), enable_scripts);
476         gtk_menu_shell_append(GTK_MENU_SHELL(viewer->fancy_prefs_menu), enable_plugins);
477         gtk_menu_shell_append(GTK_MENU_SHELL(viewer->fancy_prefs_menu), enable_java);
478         gtk_menu_shell_append(GTK_MENU_SHELL(viewer->fancy_prefs_menu), open_external);
479
480         gtk_menu_attach_to_widget(GTK_MENU(viewer->fancy_prefs_menu), viewer->ev_fancy_prefs, NULL);
481         gtk_widget_show_all(viewer->fancy_prefs_menu);
482
483         viewer->enable_images = enable_images;
484         viewer->enable_scripts = enable_scripts;
485         viewer->enable_plugins = enable_plugins;
486         viewer->enable_java = enable_java;
487         viewer->enable_remote_content = enable_remote_content;
488         viewer->open_external = open_external;
489
490         /* Set sensitivity according to preferences and overrides */
491
492         g_signal_connect(G_OBJECT(enable_images), "toggled",
493                                          G_CALLBACK (fancy_auto_load_images_activated), viewer);
494         g_signal_connect(G_OBJECT(enable_remote_content), "toggled",
495                                          G_CALLBACK (fancy_enable_remote_content_activated), viewer);
496         g_signal_connect(G_OBJECT(enable_scripts), "toggled",
497                                          G_CALLBACK (fancy_enable_scripts_activated), viewer);
498         g_signal_connect(G_OBJECT(enable_plugins), "toggled",
499                                          G_CALLBACK (fancy_enable_plugins_activated), viewer);
500         g_signal_connect(G_OBJECT(enable_java), "toggled",
501                                          G_CALLBACK (fancy_enable_java_activated), viewer);
502         g_signal_connect(G_OBJECT(open_external), "toggled",
503                                          G_CALLBACK (fancy_open_external_activated), viewer);
504
505         fancy_apply_prefs(viewer);
506 }
507
508 static gboolean fancy_scroll_page(MimeViewer *_viewer, gboolean up)
509 {
510         FancyViewer *viewer = (FancyViewer *)_viewer;
511         GtkAdjustment *vadj = gtk_scrolled_window_get_vadjustment(
512                                                   GTK_SCROLLED_WINDOW(viewer->scrollwin));
513
514         if (viewer->view == NULL)
515                 return FALSE;
516
517         return gtkutils_scroll_page(GTK_WIDGET(viewer->view), vadj, up);
518 }
519
520 static void fancy_scroll_one_line(MimeViewer *_viewer, gboolean up)
521 {
522         FancyViewer *viewer = (FancyViewer *)_viewer;
523         GtkAdjustment *vadj = gtk_scrolled_window_get_vadjustment(
524                                                   GTK_SCROLLED_WINDOW(viewer->scrollwin));
525
526         if (viewer->view == NULL)
527                 return;
528
529         gtkutils_scroll_one_line(GTK_WIDGET(viewer->view), vadj, up);
530 }
531
532 static void load_start_cb(WebKitWebView *view, gint progress, 
533                           FancyViewer *viewer)
534 {
535         gtk_widget_show(viewer->progress);
536         gtk_widget_show(viewer->ev_stop_loading);
537 }
538
539 static void load_finished_cb(WebKitWebView *view, gint progress, 
540                                                          FancyViewer *viewer)
541 {
542         gtk_widget_hide(viewer->progress);
543         gtk_widget_hide(viewer->ev_stop_loading);
544         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(viewer->progress), 
545                                                                  (gdouble) 0.0);
546         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(viewer->progress), "");
547 }
548
549 static void over_link_cb(WebKitWebView *view, const gchar *wtf, 
550                                                  const gchar *link, FancyViewer *viewer, void *wtfa)
551 {
552         gtk_label_set_text(GTK_LABEL(viewer->l_link), link);
553         g_free(viewer->cur_link);
554         viewer->cur_link = NULL;
555         if(link) {
556                 viewer->cur_link = g_strdup(link);
557         }
558 }
559
560 static void load_progress_cb(WebKitWebView *view, gint progress, 
561                                                          FancyViewer *viewer)
562 {
563         gdouble pbar;
564         gchar *label = g_strdup_printf("%d%% Loading...", progress);
565         pbar = (gdouble) progress / 100;
566         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(viewer->progress), pbar);
567         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(viewer->progress), 
568                                                          (const gchar*)label);
569         g_free(label);
570 }
571 static void stop_loading_cb(GtkWidget *widget, GdkEvent *ev, 
572                                                         FancyViewer *viewer)
573 {
574         webkit_web_view_stop_loading (viewer->view);
575         gtk_widget_hide(viewer->progress);
576         gtk_widget_hide(viewer->ev_stop_loading);
577 }
578
579 static void search_the_web_cb(GtkWidget *widget, FancyViewer *viewer)
580 {
581         debug_print("Clicked on Search on Web\n");
582         if (webkit_web_view_has_selection(viewer->view)) {
583                 gchar *search;
584 #if WEBKIT_CHECK_VERSION(1,5,1)
585                 viewer->doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(viewer->view));
586                 viewer->window = webkit_dom_document_get_default_view (viewer->doc);
587                 viewer->selection = webkit_dom_dom_window_get_selection (viewer->window);
588                 viewer->range = webkit_dom_dom_selection_get_range_at(viewer->selection, 0, NULL);
589                 gchar *tmp = webkit_dom_range_get_text (viewer->range);
590 #else
591                 gchar *tmp = webkit_web_view_get_selected_text(viewer->view);
592 #endif
593                 search = g_strconcat(GOOGLE_SEARCH, tmp, NULL);
594 #if WEBKIT_CHECK_VERSION(1,1,1)
595                 webkit_web_view_load_uri(viewer->view, search);
596 #else
597                 webkit_web_view_open(viewer->view, search);
598 #endif
599                 g_free(search);
600                 g_free(tmp);
601         }
602 }
603
604 static void open_in_browser_cb(GtkWidget *widget, FancyViewer *viewer)
605 {
606         debug_print("open outer: %s\n", viewer->cur_link);
607         if(viewer->cur_link)
608                 open_uri(viewer->cur_link, prefs_common_get_uri_cmd());
609 }
610
611 static size_t download_file_curl_write_cb(void *buffer, size_t size, 
612                                                                                   size_t nmemb, void *data)
613 {
614         FancyViewer *viewer = (FancyViewer *)data;
615         if (!viewer->stream) {
616                 viewer->stream = fopen(viewer->curlfile, "wb");
617                 if (!viewer->stream)
618                         return -1;
619         }
620         return fwrite(buffer, size, nmemb, viewer->stream);
621 }
622 static void *download_file_curl (void *data)
623 {
624         CURL *curl;
625         CURLcode res;
626         FancyViewer *viewer = (FancyViewer *)data;
627
628         curl_global_init(CURL_GLOBAL_DEFAULT);
629         curl = curl_easy_init();
630
631         if (curl) {
632                 curl_easy_setopt(curl, CURLOPT_URL, viewer->cur_link);
633                 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, download_file_curl_write_cb);
634                 curl_easy_setopt(curl, CURLOPT_WRITEDATA, viewer);
635                 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
636                 res = curl_easy_perform(curl);
637                 curl_easy_cleanup(curl);
638
639                 if (CURLE_OK != res)
640                         alertpanel_error(_("An error occurred: %d\n"), res);
641                 if (viewer->stream)
642                         fclose(viewer->stream);
643                 curl_global_cleanup();
644         }
645 #ifdef USE_PTHREAD
646         pthread_exit(NULL);
647 #else
648         return NULL;
649 #endif
650 }
651 static void download_file_cb(GtkWidget *widget, FancyViewer *viewer)
652 {
653 #ifdef USE_PTHREAD
654         pthread_t curljob;
655         gint result;
656 #endif
657         const gchar *link = (const gchar *)viewer->cur_link;
658         gchar *filename = g_utf8_strchr(link, -1, g_utf8_get_char("/"));
659         filename = g_strconcat(g_get_home_dir(), filename, NULL);
660         gchar *fname = filesel_select_file_save(_("Save as"), filename);
661
662         if (viewer->curlfile) viewer->curlfile = NULL;
663         if (viewer->stream) viewer->stream = NULL;
664         viewer->curlfile = (const gchar *)g_strdup(fname);
665         g_free(filename);
666         g_free(fname);
667
668         if (!viewer->curlfile) return;
669     
670 #ifdef USE_PTHREAD
671         result = pthread_create(&curljob, NULL, download_file_curl, (void *)viewer);
672         if (result)   
673                 alertpanel_error("ERROR; return code from pthread_create() is %d\n", result);
674 #else
675         download_file_curl((void *)viewer);
676 #endif
677 }
678
679 static void open_image_cb(GtkWidget *widget, FancyViewer *viewer)
680 {
681         debug_print("Not Yet Implemented\n");
682 }
683
684 static void copy_image_cb(GtkWidget *widget, FancyViewer *viewer)
685 {
686         debug_print("Not Yet Implemented\n");
687 }
688 static void import_feed_cb(GtkWidget *widget, FancyViewer *viewer)
689 {
690         if (!folder_subscribe(viewer->cur_link))
691                 alertpanel_error(_("%s is a malformed or not supported feed"), viewer->cur_link);
692 }
693 static void viewer_menu_handler(GtkWidget *menuitem, FancyViewer *viewer)
694 {
695         const gchar *g_name = gtk_widget_get_name(GTK_WIDGET(menuitem));
696         if (!g_ascii_strcasecmp(g_name, "GtkImageMenuItem")) {
697
698                 GtkWidget *menul = gtk_bin_get_child(GTK_BIN(menuitem));
699
700         if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)), 
701                                                                 "Search the Web")) {
702                         gtk_label_set_text(GTK_LABEL(menul), _("Search the Web"));
703                         viewer->cur_link = NULL;
704                         GtkImageMenuItem *m_search = GTK_IMAGE_MENU_ITEM(menuitem);
705                         g_signal_connect(G_OBJECT(m_search), "activate",
706                                                          G_CALLBACK(search_the_web_cb),
707                                                          (gpointer *) viewer);
708                 }
709
710                 if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)), 
711                                                                 "Open Link" )) {
712
713                         if (viewer->override_prefs_remote_content)
714                                 gtk_label_set_text(GTK_LABEL(menul), _("Open in Viewer"));
715                         else
716                                 gtk_label_set_text(GTK_LABEL(menul), _("Open in Viewer (enable remote content)"));
717
718                         GtkImageMenuItem *m_new = GTK_IMAGE_MENU_ITEM(menuitem);
719                         gtk_widget_set_sensitive(GTK_WIDGET(m_new), viewer->override_prefs_remote_content);
720                 }
721
722                 if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)), 
723                                                                 "Open Link in New Window" )) {
724
725                         gtk_label_set_text(GTK_LABEL(menul), _("Open in Browser"));
726
727                         GtkImageMenuItem *m_new = GTK_IMAGE_MENU_ITEM(menuitem);
728                         g_signal_connect(G_OBJECT(m_new), "activate",
729                                                          G_CALLBACK(open_in_browser_cb),
730                                                          (gpointer *) viewer);
731                 }
732
733                 if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)), 
734                                                                 "Open Image in New Window" )) {
735                         gtk_label_set_text(GTK_LABEL(menul), _("Open Image"));
736                         GtkImageMenuItem *m_image = GTK_IMAGE_MENU_ITEM(menuitem);
737                         g_signal_connect(G_OBJECT(m_image), "activate",
738                                                          G_CALLBACK(open_image_cb),
739                                                          (gpointer *) viewer);
740                 }
741
742                 if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)), 
743                                                                 "Copy Link Location" )) {
744                         gtk_label_set_text(GTK_LABEL(menul), _("Copy Link"));
745                 }
746         if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)), 
747                                                                 "Download Linked File" )) {
748                         gtk_label_set_text(GTK_LABEL(menul), _("Download Link"));
749
750                         GtkImageMenuItem *m_dlink = GTK_IMAGE_MENU_ITEM(menuitem);
751                         g_signal_connect(G_OBJECT(m_dlink), "activate",
752                                                          G_CALLBACK(download_file_cb),
753                                                          (gpointer *) viewer);
754                 }
755
756                 if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)), 
757                                                                 "Save Image As" )) {
758
759                         gtk_label_set_text(GTK_LABEL(menul), _("Save Image As"));
760
761                         GtkImageMenuItem *m_simage = GTK_IMAGE_MENU_ITEM(menuitem);
762                         g_signal_connect(G_OBJECT(m_simage), "activate", 
763                                                          G_CALLBACK(download_file_cb), (gpointer *) viewer);
764                 }
765
766                 if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)), 
767                                                                 "Copy Image" )) {
768                         gtk_label_set_text(GTK_LABEL(menul), _("Copy Image"));
769                         GtkImageMenuItem *m_cimage = GTK_IMAGE_MENU_ITEM(menuitem);
770                         g_signal_connect(G_OBJECT(m_cimage), "activate",
771                                                          G_CALLBACK(copy_image_cb),
772                                                          (gpointer *) viewer);
773                 }
774
775         }
776 }
777
778 static gboolean populate_popup_cb (WebKitWebView *view, GtkWidget *menu, 
779                                                                    FancyViewer *viewer)
780 {
781         Plugin *plugin = plugin_get_loaded_by_name("RSSyl");
782         gtk_container_foreach(GTK_CONTAINER(menu), 
783                                                   (GtkCallback)viewer_menu_handler, 
784                                                   viewer);
785         if (plugin) {
786                 GtkWidget *rssyl = gtk_image_menu_item_new_with_label(_("Import feed"));
787                 GtkWidget *img = gtk_image_new_from_stock(GTK_STOCK_ADD, 
788                                                                                                   GTK_ICON_SIZE_MENU);
789                 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(rssyl), img);
790                 gtk_widget_show(GTK_WIDGET(rssyl));
791                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), rssyl);    
792                 g_signal_connect(G_OBJECT(rssyl), "activate",
793                                                  G_CALLBACK(import_feed_cb),
794                                                  (gpointer *) viewer);
795         }
796         return TRUE;
797 }
798
799 static gint keypress_events_cb (GtkWidget *widget, GdkEventKey *event,
800                                                                 FancyViewer *viewer)
801 {
802         if (event->state == CTRL_KEY) {
803                 switch (event->keyval) {
804                 case GDK_plus:
805                         zoom_in_cb(viewer->ev_zoom_in, NULL, viewer);
806                         break;
807                 case GDK_period:
808                         zoom_100_cb(viewer->ev_zoom_100, NULL, viewer);
809                         break;
810                 case GDK_minus:
811                         zoom_out_cb(viewer->ev_zoom_out, NULL, viewer);
812                         break;
813                 }
814         }
815         return FALSE;
816 }
817
818 static gboolean release_button_cb (WebKitWebView *view, GdkEvent *ev,
819                                    FancyViewer *viewer)
820 {
821         if (ev->button.button == 1 && viewer->cur_link && viewer->override_prefs_external) {
822                 open_uri(viewer->cur_link, prefs_common_get_uri_cmd());
823                 return TRUE;
824         }
825         return FALSE;
826 }
827 static void zoom_100_cb(GtkWidget *widget, GdkEvent *ev, FancyViewer *viewer)
828 {
829         gtk_widget_grab_focus(widget);
830         webkit_web_view_set_zoom_level(viewer->view, 1);
831 }
832
833 static void zoom_in_cb(GtkWidget *widget, GdkEvent *ev, FancyViewer *viewer)
834 {
835         gtk_widget_grab_focus(widget);
836         webkit_web_view_zoom_in(viewer->view);
837 }
838 static void zoom_out_cb(GtkWidget *widget, GdkEvent *ev, FancyViewer *viewer)
839 {
840         gtk_widget_grab_focus(widget);
841         webkit_web_view_zoom_out(viewer->view);
842 }
843
844 static MimeViewer *fancy_viewer_create(void)
845 {
846         FancyViewer    *viewer;
847         GtkWidget      *hbox;
848     
849         debug_print("fancy_viewer_create\n");
850
851         viewer = g_new0(FancyViewer, 1);
852         viewer->mimeviewer.factory = &fancy_viewer_factory;
853         viewer->mimeviewer.get_widget = fancy_get_widget;
854         viewer->mimeviewer.get_selection = fancy_get_selection;
855         viewer->mimeviewer.show_mimepart = fancy_show_mimepart;
856         viewer->mimeviewer.print = fancy_print;
857         viewer->mimeviewer.clear_viewer = fancy_clear_viewer;
858         viewer->mimeviewer.destroy_viewer = fancy_destroy_viewer;
859         viewer->mimeviewer.text_search = fancy_text_search;
860         viewer->mimeviewer.scroll_page = fancy_scroll_page;
861         viewer->mimeviewer.scroll_one_line = fancy_scroll_one_line;
862         viewer->view = WEBKIT_WEB_VIEW(webkit_web_view_new());
863
864 #ifdef HAVE_LIBSOUP_GNOME    
865  /* Use GNOME proxy settings through libproxy */
866         if (fancy_prefs.enable_gnome_proxy) {
867                 SoupSession *session = webkit_get_default_session();
868                 soup_session_add_feature_by_type (session, SOUP_TYPE_PROXY_RESOLVER_GNOME);
869         }
870 #endif
871         
872         if (fancy_prefs.enable_proxy) {
873                 SoupSession *session = webkit_get_default_session();
874                 SoupURI* pURI = soup_uri_new(fancy_prefs.proxy_str);
875                 g_object_set(session, "proxy-uri", pURI, NULL);
876         }
877     
878         viewer->settings = webkit_web_settings_new();    
879         g_object_set(viewer->settings, "user-agent", "Fancy Viewer", NULL);
880         viewer->scrollwin = gtk_scrolled_window_new(NULL, NULL);
881         viewer->tag = -1;
882         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(viewer->scrollwin), 
883                                                                    GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
884         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(viewer->scrollwin),
885                                                                                 GTK_SHADOW_IN);
886         gtk_container_add(GTK_CONTAINER(viewer->scrollwin),
887                                           GTK_WIDGET(viewer->view));
888
889         viewer->vbox = gtk_vbox_new(FALSE, 0);
890         hbox = gtk_hbox_new(FALSE, 0);
891         viewer->progress = gtk_progress_bar_new();
892         /* Zoom Widgets */
893         viewer->zoom_100 = gtk_image_new_from_stock(GTK_STOCK_ZOOM_100,
894                                                                                                 GTK_ICON_SIZE_MENU);
895         viewer->zoom_in = gtk_image_new_from_stock(GTK_STOCK_ZOOM_IN, 
896                                                                                            GTK_ICON_SIZE_MENU);
897         viewer->zoom_out = gtk_image_new_from_stock(GTK_STOCK_ZOOM_OUT, 
898                                                                                                 GTK_ICON_SIZE_MENU);
899         viewer->stop_loading = gtk_image_new_from_stock(GTK_STOCK_CANCEL, 
900                                                                                                         GTK_ICON_SIZE_MENU);
901         /* Event Widgets for the Zoom Widgets  */
902         viewer->ev_zoom_100 = gtk_event_box_new();
903         viewer->ev_zoom_in = gtk_event_box_new();
904         viewer->ev_zoom_out = gtk_event_box_new();
905         viewer->ev_stop_loading = gtk_event_box_new();
906    
907         /* Link Label */
908         viewer->l_link = gtk_label_new("");
909
910         /* Preferences Widgets to override preferences on the fly  */
911         viewer->fancy_prefs = gtk_image_new_from_stock(GTK_STOCK_PREFERENCES,
912                                                                                                    GTK_ICON_SIZE_MENU);
913         viewer->ev_fancy_prefs = gtk_event_box_new();
914
915         /* Popup Menu for preferences  */
916         viewer->fancy_prefs_menu = gtk_menu_new();
917         fancy_create_popup_prefs_menu(viewer);
918
919         gtk_event_box_set_visible_window(GTK_EVENT_BOX(viewer->ev_zoom_100), FALSE);
920         gtk_event_box_set_visible_window(GTK_EVENT_BOX(viewer->ev_zoom_in), FALSE);
921         gtk_event_box_set_visible_window(GTK_EVENT_BOX(viewer->ev_zoom_out), FALSE);
922         gtk_event_box_set_visible_window(GTK_EVENT_BOX(viewer->ev_fancy_prefs), FALSE);
923         gtk_event_box_set_visible_window(GTK_EVENT_BOX(viewer->ev_stop_loading), FALSE);
924
925         gtk_container_add(GTK_CONTAINER(viewer->ev_zoom_100), viewer->zoom_100);
926         gtk_container_add(GTK_CONTAINER(viewer->ev_zoom_in), viewer->zoom_in);
927         gtk_container_add(GTK_CONTAINER(viewer->ev_zoom_out), viewer->zoom_out);
928         gtk_container_add(GTK_CONTAINER(viewer->ev_fancy_prefs), viewer->fancy_prefs);
929         gtk_container_add(GTK_CONTAINER(viewer->ev_stop_loading), viewer->stop_loading);
930
931         gtk_box_pack_start(GTK_BOX(hbox), viewer->ev_zoom_100, FALSE, FALSE, 1);
932         gtk_box_pack_start(GTK_BOX(hbox), viewer->ev_zoom_in, FALSE, FALSE, 2);
933         gtk_box_pack_start(GTK_BOX(hbox), viewer->ev_zoom_out, FALSE, FALSE, 2);
934         gtk_box_pack_start(GTK_BOX(hbox), viewer->ev_fancy_prefs, FALSE, FALSE, 2);
935         gtk_box_pack_start(GTK_BOX(hbox), viewer->l_link, FALSE, FALSE, 8);
936         gtk_box_pack_end(GTK_BOX(hbox), viewer->progress, FALSE, FALSE, 0);
937         gtk_box_pack_end(GTK_BOX(hbox), viewer->ev_stop_loading, FALSE, FALSE, 0);
938
939         gtk_box_pack_start(GTK_BOX(viewer->vbox), viewer->scrollwin, TRUE, TRUE, 
940                        1);
941         gtk_box_pack_start(GTK_BOX(viewer->vbox), hbox, FALSE, FALSE, 0);
942
943         gtk_widget_show(viewer->ev_zoom_100);
944         gtk_widget_show(viewer->ev_zoom_in);
945         gtk_widget_show(viewer->ev_zoom_out);
946         gtk_widget_show(viewer->ev_fancy_prefs);
947
948         gtk_widget_show(viewer->scrollwin);
949         gtk_widget_show(viewer->zoom_100);
950         gtk_widget_show(viewer->zoom_in);
951         gtk_widget_show(viewer->zoom_out);
952         gtk_widget_show(viewer->fancy_prefs);
953         gtk_widget_show(viewer->stop_loading);
954
955         gtk_widget_show(viewer->l_link);
956         gtk_widget_show(viewer->vbox);
957         gtk_widget_show(hbox);
958         gtk_widget_show(GTK_WIDGET(viewer->view));
959
960         g_signal_connect(G_OBJECT(viewer->view), "load-started", 
961                                          G_CALLBACK(load_start_cb), viewer);
962         g_signal_connect(G_OBJECT(viewer->view), "load-finished", 
963                                          G_CALLBACK(load_finished_cb), viewer);
964         g_signal_connect(G_OBJECT(viewer->view), "hovering-over-link", 
965                                          G_CALLBACK(over_link_cb), viewer);
966         g_signal_connect(G_OBJECT(viewer->view), "load-progress-changed", 
967                                          G_CALLBACK(load_progress_cb), viewer);
968         g_signal_connect(G_OBJECT(viewer->view), "navigation-requested",
969                                          G_CALLBACK(navigation_requested_cb), viewer);
970         g_signal_connect(G_OBJECT(viewer->view), "resource-request-starting",
971                         G_CALLBACK(resource_request_starting_cb), viewer);
972         g_signal_connect(G_OBJECT(viewer->view), "populate-popup",
973                                          G_CALLBACK(populate_popup_cb), viewer);
974         g_signal_connect(G_OBJECT(viewer->view), "button-release-event",
975                                         G_CALLBACK(release_button_cb), viewer);
976         g_signal_connect(G_OBJECT(viewer->ev_zoom_100), "button-press-event",
977                                          G_CALLBACK(zoom_100_cb), (gpointer*)viewer);
978         g_signal_connect(G_OBJECT(viewer->ev_zoom_in), "button-press-event",
979                                          G_CALLBACK(zoom_in_cb), (gpointer *)viewer);
980         g_signal_connect(G_OBJECT(viewer->ev_zoom_out), "button-press-event",
981                                          G_CALLBACK(zoom_out_cb), (gpointer *)viewer);
982         g_signal_connect(G_OBJECT(viewer->ev_fancy_prefs), "button-press-event",
983                                          G_CALLBACK(fancy_prefs_cb), (gpointer *)viewer);
984         g_signal_connect(G_OBJECT(viewer->ev_stop_loading), "button-press-event",
985                                          G_CALLBACK(stop_loading_cb), viewer);
986         g_signal_connect(G_OBJECT(viewer->view), "key_press_event",
987                                          G_CALLBACK(keypress_events_cb), viewer);
988
989         viewer->filename = NULL;
990         return (MimeViewer *) viewer;
991 }
992
993 static gchar *content_types[] = {"text/html", NULL};
994
995 static MimeViewerFactory fancy_viewer_factory =
996 {
997         content_types,
998         0,
999         fancy_viewer_create,
1000 };
1001
1002 gint plugin_init(gchar **error)
1003 {
1004         if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
1005                                                           VERSION_NUMERIC, _("Fancy"), error))
1006                 return -1;
1007         gchar *directory = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
1008                                 "fancy", NULL);
1009         if (!is_dir_exist(directory))
1010                 make_dir (directory);
1011         g_free(directory);
1012
1013         fancy_prefs_init();
1014     
1015         mimeview_register_viewer_factory(&fancy_viewer_factory);
1016
1017         return 0;
1018 }
1019
1020 gboolean plugin_done(void)
1021 {
1022         mimeview_unregister_viewer_factory(&fancy_viewer_factory);
1023         fancy_prefs_done();
1024         return FALSE;
1025 }
1026
1027 const gchar *plugin_name(void)
1028 {
1029         /* i18n: 'Fancy' here is name of the plugin, not the english word. */
1030         return _("Fancy HTML Viewer");
1031 }
1032
1033 const gchar *plugin_desc(void)
1034 {
1035         return g_strdup_printf(_("This plugin renders HTML mail using the WebKit " 
1036                                                    "%d.%d.%d library.\nBy default all remote content is "
1037                                                    "blocked and images are not automatically loaded. Options "
1038                                                    "can be found in /Configuration/Preferences/Plugins/Fancy"), 
1039                                                    WEBKIT_MAJOR_VERSION, WEBKIT_MINOR_VERSION, 
1040                                                    WEBKIT_MICRO_VERSION);
1041 }
1042
1043 const gchar *plugin_type(void)
1044 {
1045         return "GTK2";
1046 }
1047
1048 const gchar *plugin_licence(void)
1049 {
1050         return "GPL3";
1051 }
1052
1053 const gchar *plugin_version(void)
1054 {
1055         return VERSION;
1056 }
1057
1058 struct PluginFeature *plugin_provides(void)
1059 {
1060         static struct PluginFeature features[] = {
1061                                         {PLUGIN_MIMEVIEWER, "text/html"},
1062                                 {PLUGIN_NOTHING, NULL}
1063         };
1064         return features;
1065 }