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