2013-03-13 [colin] 3.9.0cvs116
[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.auto_load_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->auto_load_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->auto_load_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->auto_load_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 #if WEBKIT_CHECK_VERSION (1,1,14)
391 static void resource_request_starting_cb(WebKitWebView                  *view, 
392                                                                                  WebKitWebFrame                 *frame,
393                                                                                  WebKitWebResource              *resource,
394                                                                                  WebKitNetworkRequest   *request,
395                                                                                  WebKitNetworkResponse  *response,
396                                                                                  FancyViewer                    *viewer)
397 {
398         const gchar *uri = webkit_network_request_get_uri(request);
399         gchar *filename;
400         gchar *image;
401         gint err;
402         MimeInfo *partinfo = viewer->to_load;
403         
404         filename = viewer->filename;
405         if ((!g_ascii_strncasecmp(uri, "cid:", 4)) || (!g_ascii_strncasecmp(uri, "mid:", 4))) {
406                 image = g_strconcat("<", uri + 4, ">", NULL);
407                 while ((partinfo = procmime_mimeinfo_next(partinfo)) != NULL) {
408                         if (!g_ascii_strcasecmp(image, partinfo->id)) {
409                                 filename = procmime_get_tmp_file_name(partinfo);
410                                 if (!filename) {
411                                         g_free(image);
412                                         return;
413                                 }
414                                 if ((err = procmime_get_part(filename, partinfo)) < 0)
415                                         alertpanel_error(_("Couldn't save the part of multipart message: %s"),
416                                                                                 strerror(-err));
417                                 gchar *file_uri = g_strconcat("file://", filename, NULL);
418                                 webkit_network_request_set_uri(request, file_uri);
419                                 g_free(file_uri);
420                                 g_free(filename);
421                                 break;
422                         }
423                 }
424                 g_free(image);
425         }
426 }
427 #endif
428 static gboolean fancy_text_search(MimeViewer *_viewer, gboolean backward, 
429                                                                   const gchar *str, gboolean case_sens)
430 {
431         return webkit_web_view_search_text(((FancyViewer*)_viewer)->view, str,
432                                                                            case_sens, !backward, TRUE);
433 }
434
435 static gboolean fancy_prefs_cb(GtkWidget *widget, GdkEventButton *ev, FancyViewer *viewer)
436 {
437         if ((ev->button == 1) && (ev->type == GDK_BUTTON_PRESS)) {
438                 gtk_menu_popup(GTK_MENU(viewer->fancy_prefs_menu), NULL, NULL, NULL, NULL,
439                                            ev->button, ev->time);
440                 return TRUE;
441         }
442         return FALSE;
443 }
444
445 static void fancy_create_popup_prefs_menu(FancyViewer *viewer) {
446         GtkWidget *auto_load_images;
447         GtkWidget *enable_remote_content;
448         GtkWidget *enable_scripts;
449         GtkWidget *enable_plugins;
450         GtkWidget *enable_java;
451         GtkWidget *open_external;
452
453         auto_load_images = gtk_check_menu_item_new_with_label(_("Load images"));
454
455         enable_remote_content = gtk_check_menu_item_new_with_label(_("Enable remote content"));
456
457         enable_scripts = gtk_check_menu_item_new_with_label(_("Enable Javascript"));
458
459         enable_plugins = gtk_check_menu_item_new_with_label(_("Enable Plugins"));
460
461         enable_java = gtk_check_menu_item_new_with_label(_("Enable Java"));
462
463         open_external = gtk_check_menu_item_new_with_label(_("Open links with external browser"));
464
465         gtk_menu_shell_append(GTK_MENU_SHELL(viewer->fancy_prefs_menu), auto_load_images);
466         gtk_menu_shell_append(GTK_MENU_SHELL(viewer->fancy_prefs_menu), enable_remote_content);
467         gtk_menu_shell_append(GTK_MENU_SHELL(viewer->fancy_prefs_menu), enable_scripts);
468         gtk_menu_shell_append(GTK_MENU_SHELL(viewer->fancy_prefs_menu), enable_plugins);
469         gtk_menu_shell_append(GTK_MENU_SHELL(viewer->fancy_prefs_menu), enable_java);
470         gtk_menu_shell_append(GTK_MENU_SHELL(viewer->fancy_prefs_menu), open_external);
471
472         gtk_menu_attach_to_widget(GTK_MENU(viewer->fancy_prefs_menu), viewer->ev_fancy_prefs, NULL);
473         gtk_widget_show_all(viewer->fancy_prefs_menu);
474
475         viewer->auto_load_images = auto_load_images;
476         viewer->enable_scripts = enable_scripts;
477         viewer->enable_plugins = enable_plugins;
478         viewer->enable_java = enable_java;
479         viewer->enable_remote_content = enable_remote_content;
480         viewer->open_external = open_external;
481
482         /* Set sensitivity according to preferences and overrides */
483
484         g_signal_connect(G_OBJECT(auto_load_images), "toggled",
485                                          G_CALLBACK (fancy_auto_load_images_activated), viewer);
486         g_signal_connect(G_OBJECT(enable_remote_content), "toggled",
487                                          G_CALLBACK (fancy_enable_remote_content_activated), viewer);
488         g_signal_connect(G_OBJECT(enable_scripts), "toggled",
489                                          G_CALLBACK (fancy_enable_scripts_activated), viewer);
490         g_signal_connect(G_OBJECT(enable_plugins), "toggled",
491                                          G_CALLBACK (fancy_enable_plugins_activated), viewer);
492         g_signal_connect(G_OBJECT(enable_java), "toggled",
493                                          G_CALLBACK (fancy_enable_java_activated), viewer);
494         g_signal_connect(G_OBJECT(open_external), "toggled",
495                                          G_CALLBACK (fancy_open_external_activated), viewer);
496
497         fancy_apply_prefs(viewer);
498 }
499
500 static gboolean fancy_scroll_page(MimeViewer *_viewer, gboolean up)
501 {
502         FancyViewer *viewer = (FancyViewer *)_viewer;
503         GtkAdjustment *vadj = gtk_scrolled_window_get_vadjustment(
504                                                   GTK_SCROLLED_WINDOW(viewer->scrollwin));
505
506         if (viewer->view == NULL)
507                 return FALSE;
508
509         return gtkutils_scroll_page(GTK_WIDGET(viewer->view), vadj, up);
510 }
511
512 static void fancy_scroll_one_line(MimeViewer *_viewer, gboolean up)
513 {
514         FancyViewer *viewer = (FancyViewer *)_viewer;
515         GtkAdjustment *vadj = gtk_scrolled_window_get_vadjustment(
516                                                   GTK_SCROLLED_WINDOW(viewer->scrollwin));
517
518         if (viewer->view == NULL)
519                 return;
520
521         gtkutils_scroll_one_line(GTK_WIDGET(viewer->view), vadj, up);
522 }
523
524 static void load_start_cb(WebKitWebView *view, gint progress, 
525                           FancyViewer *viewer)
526 {
527         gtk_widget_show(viewer->progress);
528         gtk_widget_show(viewer->ev_stop_loading);
529 }
530
531 static void load_finished_cb(WebKitWebView *view, gint progress, 
532                                                          FancyViewer *viewer)
533 {
534         gtk_widget_hide(viewer->progress);
535         gtk_widget_hide(viewer->ev_stop_loading);
536         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(viewer->progress), 
537                                                                  (gdouble) 0.0);
538         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(viewer->progress), "");
539 }
540
541 static void over_link_cb(WebKitWebView *view, const gchar *wtf, 
542                                                  const gchar *link, FancyViewer *viewer, void *wtfa)
543 {
544         gtk_label_set_text(GTK_LABEL(viewer->l_link), link);
545         g_free(viewer->cur_link);
546         viewer->cur_link = NULL;
547         if(link) {
548                 viewer->cur_link = g_strdup(link);
549         }
550 }
551
552 static void load_progress_cb(WebKitWebView *view, gint progress, 
553                                                          FancyViewer *viewer)
554 {
555         gdouble pbar;
556         gchar *label = g_strdup_printf("%d%% Loading...", progress);
557         pbar = (gdouble) progress / 100;
558         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(viewer->progress), pbar);
559         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(viewer->progress), 
560                                                          (const gchar*)label);
561         g_free(label);
562 }
563 static void stop_loading_cb(GtkWidget *widget, GdkEvent *ev, 
564                                                         FancyViewer *viewer)
565 {
566         webkit_web_view_stop_loading (viewer->view);
567         gtk_widget_hide(viewer->progress);
568         gtk_widget_hide(viewer->ev_stop_loading);
569 }
570
571 static void search_the_web_cb(GtkWidget *widget, FancyViewer *viewer)
572 {
573         debug_print("Clicked on Search on Web\n");
574         if (webkit_web_view_has_selection(viewer->view)) {
575                 gchar *search;
576 #if WEBKIT_CHECK_VERSION(1,5,1)
577                 viewer->doc = webkit_web_view_get_dom_document(WEBKIT_WEB_VIEW(viewer->view));
578                 viewer->window = webkit_dom_document_get_default_view (viewer->doc);
579                 viewer->selection = webkit_dom_dom_window_get_selection (viewer->window);
580                 viewer->range = webkit_dom_dom_selection_get_range_at(viewer->selection, 0, NULL);
581                 gchar *tmp = webkit_dom_range_get_text (viewer->range);
582 #else
583                 gchar *tmp = webkit_web_view_get_selected_text(viewer->view);
584 #endif
585                 search = g_strconcat(GOOGLE_SEARCH, tmp, NULL);
586 #if WEBKIT_CHECK_VERSION(1,1,1)
587                 webkit_web_view_load_uri(viewer->view, search);
588 #else
589                 webkit_web_view_open(viewer->view, search);
590 #endif
591                 g_free(search);
592                 g_free(tmp);
593         }
594 }
595
596 static void open_in_browser_cb(GtkWidget *widget, FancyViewer *viewer)
597 {
598         debug_print("open outer: %s\n", viewer->cur_link);
599         if(viewer->cur_link)
600                 open_uri(viewer->cur_link, prefs_common_get_uri_cmd());
601 }
602
603 static size_t download_file_curl_write_cb(void *buffer, size_t size, 
604                                                                                   size_t nmemb, void *data)
605 {
606         FancyViewer *viewer = (FancyViewer *)data;
607         if (!viewer->stream) {
608                 viewer->stream = fopen(viewer->curlfile, "wb");
609                 if (!viewer->stream)
610                         return -1;
611         }
612         return fwrite(buffer, size, nmemb, viewer->stream);
613 }
614 static void *download_file_curl (void *data)
615 {
616         CURL *curl;
617         CURLcode res;
618         FancyViewer *viewer = (FancyViewer *)data;
619
620         curl_global_init(CURL_GLOBAL_DEFAULT);
621         curl = curl_easy_init();
622
623         if (curl) {
624                 curl_easy_setopt(curl, CURLOPT_URL, viewer->cur_link);
625                 curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, download_file_curl_write_cb);
626                 curl_easy_setopt(curl, CURLOPT_WRITEDATA, viewer);
627                 curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
628                 res = curl_easy_perform(curl);
629                 curl_easy_cleanup(curl);
630
631                 if (CURLE_OK != res)
632                         alertpanel_error(_("An error occurred: %d\n"), res);
633                 if (viewer->stream)
634                         fclose(viewer->stream);
635                 curl_global_cleanup();
636         }
637 #ifdef USE_PTHREAD
638         pthread_exit(NULL);
639 #else
640         return NULL;
641 #endif
642 }
643 static void download_file_cb(GtkWidget *widget, FancyViewer *viewer)
644 {
645 #ifdef USE_PTHREAD
646         pthread_t curljob;
647         gint result;
648 #endif
649         const gchar *link = (const gchar *)viewer->cur_link;
650         gchar *filename = g_utf8_strchr(link, -1, g_utf8_get_char("/"));
651         filename = g_strconcat(g_get_home_dir(), filename, NULL);
652         gchar *fname = filesel_select_file_save(_("Save as"), filename);
653
654         if (viewer->curlfile) viewer->curlfile = NULL;
655         if (viewer->stream) viewer->stream = NULL;
656         viewer->curlfile = (const gchar *)g_strdup(fname);
657         g_free(filename);
658         g_free(fname);
659
660         if (!viewer->curlfile) return;
661     
662 #ifdef USE_PTHREAD
663         result = pthread_create(&curljob, NULL, download_file_curl, (void *)viewer);
664         if (result)   
665                 alertpanel_error("ERROR; return code from pthread_create() is %d\n", result);
666 #else
667         download_file_curl((void *)viewer);
668 #endif
669 }
670
671 static void open_image_cb(GtkWidget *widget, FancyViewer *viewer)
672 {
673         debug_print("Not Yet Implemented\n");
674 }
675
676 static void copy_image_cb(GtkWidget *widget, FancyViewer *viewer)
677 {
678         debug_print("Not Yet Implemented\n");
679 }
680 static void import_feed_cb(GtkWidget *widget, FancyViewer *viewer)
681 {
682         if (!folder_subscribe(viewer->cur_link))
683                 alertpanel_error(_("%s is a malformed or not supported feed"), viewer->cur_link);
684 }
685 static void viewer_menu_handler(GtkWidget *menuitem, FancyViewer *viewer)
686 {
687         const gchar *g_name = gtk_widget_get_name(GTK_WIDGET(menuitem));
688         if (!g_ascii_strcasecmp(g_name, "GtkImageMenuItem")) {
689
690                 GtkWidget *menul = gtk_bin_get_child(GTK_BIN(menuitem));
691
692         if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)), 
693                                                                 "Search the Web")) {
694                         gtk_label_set_text(GTK_LABEL(menul), _("Search the Web"));
695                         viewer->cur_link = NULL;
696                         GtkImageMenuItem *m_search = GTK_IMAGE_MENU_ITEM(menuitem);
697                         g_signal_connect(G_OBJECT(m_search), "activate",
698                                                          G_CALLBACK(search_the_web_cb),
699                                                          (gpointer *) viewer);
700                 }
701
702                 if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)), 
703                                                                 "Open Link" )) {
704
705                         if (viewer->override_prefs_remote_content)
706                                 gtk_label_set_text(GTK_LABEL(menul), _("Open in Viewer"));
707                         else
708                                 gtk_label_set_text(GTK_LABEL(menul), _("Open in Viewer (enable remote content)"));
709
710                         GtkImageMenuItem *m_new = GTK_IMAGE_MENU_ITEM(menuitem);
711                         gtk_widget_set_sensitive(GTK_WIDGET(m_new), viewer->override_prefs_remote_content);
712                 }
713
714                 if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)), 
715                                                                 "Open Link in New Window" )) {
716
717                         gtk_label_set_text(GTK_LABEL(menul), _("Open in Browser"));
718
719                         GtkImageMenuItem *m_new = GTK_IMAGE_MENU_ITEM(menuitem);
720                         g_signal_connect(G_OBJECT(m_new), "activate",
721                                                          G_CALLBACK(open_in_browser_cb),
722                                                          (gpointer *) viewer);
723                 }
724
725                 if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)), 
726                                                                 "Open Image in New Window" )) {
727                         gtk_label_set_text(GTK_LABEL(menul), _("Open Image"));
728                         GtkImageMenuItem *m_image = GTK_IMAGE_MENU_ITEM(menuitem);
729                         g_signal_connect(G_OBJECT(m_image), "activate",
730                                                          G_CALLBACK(open_image_cb),
731                                                          (gpointer *) viewer);
732                 }
733
734                 if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)), 
735                                                                 "Copy Link Location" )) {
736                         gtk_label_set_text(GTK_LABEL(menul), _("Copy Link"));
737                 }
738         if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)), 
739                                                                 "Download Linked File" )) {
740                         gtk_label_set_text(GTK_LABEL(menul), _("Download Link"));
741
742                         GtkImageMenuItem *m_dlink = GTK_IMAGE_MENU_ITEM(menuitem);
743                         g_signal_connect(G_OBJECT(m_dlink), "activate",
744                                                          G_CALLBACK(download_file_cb),
745                                                          (gpointer *) viewer);
746                 }
747
748                 if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)), 
749                                                                 "Save Image As" )) {
750
751                         gtk_label_set_text(GTK_LABEL(menul), _("Save Image As"));
752
753                         GtkImageMenuItem *m_simage = GTK_IMAGE_MENU_ITEM(menuitem);
754                         g_signal_connect(G_OBJECT(m_simage), "activate", 
755                                                          G_CALLBACK(download_file_cb), (gpointer *) viewer);
756                 }
757
758                 if (!g_ascii_strcasecmp(gtk_label_get_text(GTK_LABEL(menul)), 
759                                                                 "Copy Image" )) {
760                         gtk_label_set_text(GTK_LABEL(menul), _("Copy Image"));
761                         GtkImageMenuItem *m_cimage = GTK_IMAGE_MENU_ITEM(menuitem);
762                         g_signal_connect(G_OBJECT(m_cimage), "activate",
763                                                          G_CALLBACK(copy_image_cb),
764                                                          (gpointer *) viewer);
765                 }
766
767         }
768 }
769
770 static gboolean populate_popup_cb (WebKitWebView *view, GtkWidget *menu, 
771                                                                    FancyViewer *viewer)
772 {
773         Plugin *plugin = plugin_get_loaded_by_name("RSSyl");
774         gtk_container_foreach(GTK_CONTAINER(menu), 
775                                                   (GtkCallback)viewer_menu_handler, 
776                                                   viewer);
777         if (plugin) {
778                 GtkWidget *rssyl = gtk_image_menu_item_new_with_label(_("Import feed"));
779                 GtkWidget *img = gtk_image_new_from_stock(GTK_STOCK_ADD, 
780                                                                                                   GTK_ICON_SIZE_MENU);
781                 gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(rssyl), img);
782                 gtk_widget_show(GTK_WIDGET(rssyl));
783                 gtk_menu_shell_append(GTK_MENU_SHELL(menu), rssyl);    
784                 g_signal_connect(G_OBJECT(rssyl), "activate",
785                                                  G_CALLBACK(import_feed_cb),
786                                                  (gpointer *) viewer);
787         }
788         return TRUE;
789 }
790
791 static gint keypress_events_cb (GtkWidget *widget, GdkEventKey *event,
792                                                                 FancyViewer *viewer)
793 {
794         if (event->state == CTRL_KEY) {
795                 switch (event->keyval) {
796                 case GDK_plus:
797                         zoom_in_cb(viewer->ev_zoom_in, NULL, viewer);
798                         break;
799                 case GDK_period:
800                         zoom_100_cb(viewer->ev_zoom_100, NULL, viewer);
801                         break;
802                 case GDK_minus:
803                         zoom_out_cb(viewer->ev_zoom_out, NULL, viewer);
804                         break;
805                 }
806         }
807         return FALSE;
808 }
809
810 static gboolean release_button_cb (WebKitWebView *view, GdkEvent *ev,
811                                    FancyViewer *viewer)
812 {
813         if (ev->button.button == 1 && viewer->cur_link && viewer->override_prefs_external) {
814                 open_uri(viewer->cur_link, prefs_common_get_uri_cmd());
815                 return TRUE;
816         }
817         return FALSE;
818 }
819 static void zoom_100_cb(GtkWidget *widget, GdkEvent *ev, FancyViewer *viewer)
820 {
821         gtk_widget_grab_focus(widget);
822         webkit_web_view_set_zoom_level(viewer->view, 1);
823 }
824
825 static void zoom_in_cb(GtkWidget *widget, GdkEvent *ev, FancyViewer *viewer)
826 {
827         gtk_widget_grab_focus(widget);
828         webkit_web_view_zoom_in(viewer->view);
829 }
830 static void zoom_out_cb(GtkWidget *widget, GdkEvent *ev, FancyViewer *viewer)
831 {
832         gtk_widget_grab_focus(widget);
833         webkit_web_view_zoom_out(viewer->view);
834 }
835
836 static MimeViewer *fancy_viewer_create(void)
837 {
838         FancyViewer    *viewer;
839         GtkWidget      *hbox;
840     
841         debug_print("fancy_viewer_create\n");
842
843         viewer = g_new0(FancyViewer, 1);
844         viewer->mimeviewer.factory = &fancy_viewer_factory;
845         viewer->mimeviewer.get_widget = fancy_get_widget;
846         viewer->mimeviewer.get_selection = fancy_get_selection;
847         viewer->mimeviewer.show_mimepart = fancy_show_mimepart;
848         viewer->mimeviewer.print = fancy_print;
849         viewer->mimeviewer.clear_viewer = fancy_clear_viewer;
850         viewer->mimeviewer.destroy_viewer = fancy_destroy_viewer;
851         viewer->mimeviewer.text_search = fancy_text_search;
852         viewer->mimeviewer.scroll_page = fancy_scroll_page;
853         viewer->mimeviewer.scroll_one_line = fancy_scroll_one_line;
854         viewer->view = WEBKIT_WEB_VIEW(webkit_web_view_new());
855
856 #ifdef HAVE_LIBSOUP_GNOME    
857  /* Use GNOME proxy settings through libproxy */
858         if (fancy_prefs.enable_gnome_proxy) {
859                 SoupSession *session = webkit_get_default_session();
860                 soup_session_add_feature_by_type (session, SOUP_TYPE_PROXY_RESOLVER_GNOME);
861         }
862 #endif
863         
864         if (fancy_prefs.enable_proxy) {
865                 SoupSession *session = webkit_get_default_session();
866                 SoupURI* pURI = soup_uri_new(fancy_prefs.proxy_str);
867                 g_object_set(session, "proxy-uri", pURI, NULL);
868         }
869     
870         viewer->settings = webkit_web_settings_new();    
871         g_object_set(viewer->settings, "user-agent", "Fancy Viewer", NULL);
872         viewer->scrollwin = gtk_scrolled_window_new(NULL, NULL);
873         viewer->tag = -1;
874         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(viewer->scrollwin), 
875                                                                    GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
876         gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(viewer->scrollwin),
877                                                                                 GTK_SHADOW_IN);
878         gtk_container_add(GTK_CONTAINER(viewer->scrollwin),
879                                           GTK_WIDGET(viewer->view));
880
881         viewer->vbox = gtk_vbox_new(FALSE, 0);
882         hbox = gtk_hbox_new(FALSE, 0);
883         viewer->progress = gtk_progress_bar_new();
884         /* Zoom Widgets */
885         viewer->zoom_100 = gtk_image_new_from_stock(GTK_STOCK_ZOOM_100,
886                                                                                                 GTK_ICON_SIZE_MENU);
887         viewer->zoom_in = gtk_image_new_from_stock(GTK_STOCK_ZOOM_IN, 
888                                                                                            GTK_ICON_SIZE_MENU);
889         viewer->zoom_out = gtk_image_new_from_stock(GTK_STOCK_ZOOM_OUT, 
890                                                                                                 GTK_ICON_SIZE_MENU);
891         viewer->stop_loading = gtk_image_new_from_stock(GTK_STOCK_CANCEL, 
892                                                                                                         GTK_ICON_SIZE_MENU);
893         /* Event Widgets for the Zoom Widgets  */
894         viewer->ev_zoom_100 = gtk_event_box_new();
895         viewer->ev_zoom_in = gtk_event_box_new();
896         viewer->ev_zoom_out = gtk_event_box_new();
897         viewer->ev_stop_loading = gtk_event_box_new();
898    
899         /* Link Label */
900         viewer->l_link = gtk_label_new("");
901
902         /* Preferences Widgets to override preferences on the fly  */
903         viewer->fancy_prefs = gtk_image_new_from_stock(GTK_STOCK_PREFERENCES,
904                                                                                                    GTK_ICON_SIZE_MENU);
905         viewer->ev_fancy_prefs = gtk_event_box_new();
906
907         /* Popup Menu for preferences  */
908         viewer->fancy_prefs_menu = gtk_menu_new();
909         fancy_create_popup_prefs_menu(viewer);
910
911         gtk_event_box_set_visible_window(GTK_EVENT_BOX(viewer->ev_zoom_100), FALSE);
912         gtk_event_box_set_visible_window(GTK_EVENT_BOX(viewer->ev_zoom_in), FALSE);
913         gtk_event_box_set_visible_window(GTK_EVENT_BOX(viewer->ev_zoom_out), FALSE);
914         gtk_event_box_set_visible_window(GTK_EVENT_BOX(viewer->ev_fancy_prefs), FALSE);
915         gtk_event_box_set_visible_window(GTK_EVENT_BOX(viewer->ev_stop_loading), FALSE);
916
917         gtk_container_add(GTK_CONTAINER(viewer->ev_zoom_100), viewer->zoom_100);
918         gtk_container_add(GTK_CONTAINER(viewer->ev_zoom_in), viewer->zoom_in);
919         gtk_container_add(GTK_CONTAINER(viewer->ev_zoom_out), viewer->zoom_out);
920         gtk_container_add(GTK_CONTAINER(viewer->ev_fancy_prefs), viewer->fancy_prefs);
921         gtk_container_add(GTK_CONTAINER(viewer->ev_stop_loading), viewer->stop_loading);
922
923         gtk_box_pack_start(GTK_BOX(hbox), viewer->ev_zoom_100, FALSE, FALSE, 1);
924         gtk_box_pack_start(GTK_BOX(hbox), viewer->ev_zoom_in, FALSE, FALSE, 2);
925         gtk_box_pack_start(GTK_BOX(hbox), viewer->ev_zoom_out, FALSE, FALSE, 2);
926         gtk_box_pack_start(GTK_BOX(hbox), viewer->ev_fancy_prefs, FALSE, FALSE, 2);
927         gtk_box_pack_start(GTK_BOX(hbox), viewer->l_link, FALSE, FALSE, 8);
928         gtk_box_pack_end(GTK_BOX(hbox), viewer->progress, FALSE, FALSE, 0);
929         gtk_box_pack_end(GTK_BOX(hbox), viewer->ev_stop_loading, FALSE, FALSE, 0);
930
931         gtk_box_pack_start(GTK_BOX(viewer->vbox), viewer->scrollwin, TRUE, TRUE, 
932                        1);
933         gtk_box_pack_start(GTK_BOX(viewer->vbox), hbox, FALSE, FALSE, 0);
934
935         gtk_widget_show(viewer->ev_zoom_100);
936         gtk_widget_show(viewer->ev_zoom_in);
937         gtk_widget_show(viewer->ev_zoom_out);
938         gtk_widget_show(viewer->ev_fancy_prefs);
939
940         gtk_widget_show(viewer->scrollwin);
941         gtk_widget_show(viewer->zoom_100);
942         gtk_widget_show(viewer->zoom_in);
943         gtk_widget_show(viewer->zoom_out);
944         gtk_widget_show(viewer->fancy_prefs);
945         gtk_widget_show(viewer->stop_loading);
946
947         gtk_widget_show(viewer->l_link);
948         gtk_widget_show(viewer->vbox);
949         gtk_widget_show(hbox);
950         gtk_widget_show(GTK_WIDGET(viewer->view));
951
952         g_signal_connect(G_OBJECT(viewer->view), "load-started", 
953                                          G_CALLBACK(load_start_cb), viewer);
954         g_signal_connect(G_OBJECT(viewer->view), "load-finished", 
955                                          G_CALLBACK(load_finished_cb), viewer);
956         g_signal_connect(G_OBJECT(viewer->view), "hovering-over-link", 
957                                          G_CALLBACK(over_link_cb), viewer);
958         g_signal_connect(G_OBJECT(viewer->view), "load-progress-changed", 
959                                          G_CALLBACK(load_progress_cb), viewer);
960         g_signal_connect(G_OBJECT(viewer->view), "navigation-requested",
961                                          G_CALLBACK(navigation_requested_cb), viewer);
962         g_signal_connect(G_OBJECT(viewer->view), "resource-request-starting",
963                         G_CALLBACK(resource_request_starting_cb), viewer);
964         g_signal_connect(G_OBJECT(viewer->view), "populate-popup",
965                                          G_CALLBACK(populate_popup_cb), viewer);
966         g_signal_connect(G_OBJECT(viewer->view), "button-release-event",
967                                         G_CALLBACK(release_button_cb), viewer);
968         g_signal_connect(G_OBJECT(viewer->ev_zoom_100), "button-press-event",
969                                          G_CALLBACK(zoom_100_cb), (gpointer*)viewer);
970         g_signal_connect(G_OBJECT(viewer->ev_zoom_in), "button-press-event",
971                                          G_CALLBACK(zoom_in_cb), (gpointer *)viewer);
972         g_signal_connect(G_OBJECT(viewer->ev_zoom_out), "button-press-event",
973                                          G_CALLBACK(zoom_out_cb), (gpointer *)viewer);
974         g_signal_connect(G_OBJECT(viewer->ev_fancy_prefs), "button-press-event",
975                                          G_CALLBACK(fancy_prefs_cb), (gpointer *)viewer);
976         g_signal_connect(G_OBJECT(viewer->ev_stop_loading), "button-press-event",
977                                          G_CALLBACK(stop_loading_cb), viewer);
978         g_signal_connect(G_OBJECT(viewer->view), "key_press_event",
979                                          G_CALLBACK(keypress_events_cb), viewer);
980
981         viewer->filename = NULL;
982         return (MimeViewer *) viewer;
983 }
984
985 static gchar *content_types[] = {"text/html", NULL};
986
987 static MimeViewerFactory fancy_viewer_factory =
988 {
989         content_types,
990         0,
991         fancy_viewer_create,
992 };
993
994 gint plugin_init(gchar **error)
995 {
996         if (!check_plugin_version(MAKE_NUMERIC_VERSION(2,9,2,72),
997                                                           VERSION_NUMERIC, _("Fancy"), error))
998                 return -1;
999         gchar *directory = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
1000                                 "fancy", NULL);
1001         if (!is_dir_exist(directory))
1002                 make_dir (directory);
1003         g_free(directory);
1004
1005         fancy_prefs_init();
1006     
1007         mimeview_register_viewer_factory(&fancy_viewer_factory);
1008
1009         return 0;
1010 }
1011
1012 gboolean plugin_done(void)
1013 {
1014         mimeview_unregister_viewer_factory(&fancy_viewer_factory);
1015         fancy_prefs_done();
1016         return FALSE;
1017 }
1018
1019 const gchar *plugin_name(void)
1020 {
1021         /* i18n: 'Fancy' here is name of the plugin, not the english word. */
1022         return _("Fancy HTML Viewer");
1023 }
1024
1025 const gchar *plugin_desc(void)
1026 {
1027         return g_strdup_printf(_("This plugin renders HTML mail using the WebKit " 
1028                                                    "%d.%d.%d library.\nBy default all remote content is "
1029                                                    "blocked and images are not automatically loaded. Options "
1030                                                    "can be found in /Configuration/Preferences/Plugins/Fancy"), 
1031                                                    WEBKIT_MAJOR_VERSION, WEBKIT_MINOR_VERSION, 
1032                                                    WEBKIT_MICRO_VERSION);
1033 }
1034
1035 const gchar *plugin_type(void)
1036 {
1037         return "GTK2";
1038 }
1039
1040 const gchar *plugin_licence(void)
1041 {
1042         return "GPL3";
1043 }
1044
1045 const gchar *plugin_version(void)
1046 {
1047         return VERSION;
1048 }
1049
1050 struct PluginFeature *plugin_provides(void)
1051 {
1052         static struct PluginFeature features[] = {
1053                                         {PLUGIN_MIMEVIEWER, "text/html"},
1054                                 {PLUGIN_NOTHING, NULL}
1055         };
1056         return features;
1057 }