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